diff --git a/test/node_modules/isomorphic-object-with-false/lib/client/http-tracker.js b/test/node_modules/isomorphic-object-with-false/lib/client/http-tracker.js new file mode 100644 index 0000000..75e80bd --- /dev/null +++ b/test/node_modules/isomorphic-object-with-false/lib/client/http-tracker.js @@ -0,0 +1,4 @@ + +module.exports = function(client, announceUrl) { + this.name = 'http-tracker' +} diff --git a/test/node_modules/isomorphic-object-with-false/lib/client/udp-tracker.js b/test/node_modules/isomorphic-object-with-false/lib/client/udp-tracker.js new file mode 100644 index 0000000..bb2c98b --- /dev/null +++ b/test/node_modules/isomorphic-object-with-false/lib/client/udp-tracker.js @@ -0,0 +1,4 @@ + +module.exports = function(client, announceUrl) { + this.name = 'udp-tracker' +} diff --git a/test/node_modules/isomorphic-object-with-false/lib/client/websocket-tracker.js b/test/node_modules/isomorphic-object-with-false/lib/client/websocket-tracker.js new file mode 100644 index 0000000..c7a38e4 --- /dev/null +++ b/test/node_modules/isomorphic-object-with-false/lib/client/websocket-tracker.js @@ -0,0 +1,4 @@ + +module.exports = function(client, announceUrl) { + this.name = 'websocket-tracker' +} diff --git a/test/node_modules/isomorphic-object-with-false/lib/index.js b/test/node_modules/isomorphic-object-with-false/lib/index.js new file mode 100644 index 0000000..073ab9f --- /dev/null +++ b/test/node_modules/isomorphic-object-with-false/lib/index.js @@ -0,0 +1,20 @@ +// sample code inspired by npm: bittorrent-tracker-client + +var HTTPTracker = require('./client/http-tracker') // empty object in browser +var UDPTracker = require('./client/udp-tracker') // empty object in browser +var WebSocketTracker = require('./client/websocket-tracker') + +function Client(protocol, announceUrl) { + var self = this; + if ((protocol === 'http:' || protocol === 'https:') && + typeof HTTPTracker === 'function') { + return new HTTPTracker(self, announceUrl) + } else if (protocol === 'udp:' && typeof UDPTracker === 'function') { + return new UDPTracker(self, announceUrl) + } else if ((protocol === 'ws:' || protocol === 'wss:')) { + return new WebSocketTracker(self, announceUrl) + } + this.name = 'NULL'; +} + +module.exports = Client diff --git a/test/node_modules/isomorphic-object-with-false/package.json b/test/node_modules/isomorphic-object-with-false/package.json new file mode 100644 index 0000000..6b9be50 --- /dev/null +++ b/test/node_modules/isomorphic-object-with-false/package.json @@ -0,0 +1,8 @@ +{ + "main": "./lib/index.js", + "browser": { + "./lib/common.js": "./lib/common-browser.js", + "./lib/client/http-tracker.js": false, + "./lib/client/udp-tracker.js": false + } +} diff --git a/test/samples/browser-object-with-false/main.js b/test/samples/browser-object-with-false/main.js new file mode 100644 index 0000000..4f04bb6 --- /dev/null +++ b/test/samples/browser-object-with-false/main.js @@ -0,0 +1,13 @@ +import Client from 'isomorphic-object-with-false'; +import HTTPTracker from 'isomorphic-object-with-false/lib/client/http-tracker'; +import ES6_BROWSER_EMPTY from '../../../src/empty'; + +// do some assert + +assert.deepEqual(new Client('ws:'), { name: 'websocket-tracker' }) +assert.deepEqual(new Client('http:'), { name: 'NULL' }) +assert.equal(HTTPTracker, ES6_BROWSER_EMPTY); + + +// expose +export default "ok" diff --git a/test/test.js b/test/test.js index fbf6c2f..815d677 100644 --- a/test/test.js +++ b/test/test.js @@ -657,4 +657,17 @@ describe( 'rollup-plugin-node-resolve', function () { }).then(executeBundle) .then(({exports}) => exports.then(result => assert.equal(result.default, 42))); }); + + it( 'pkg.browser with mapping to prevent bundle by specifying a value of false', () => { + return rollup.rollup({ + input: 'samples/browser-object-with-false/main.js', + plugins: [ + nodeResolve({ browser: true }), + commonjs() + ] + }).then( executeBundle ).then( module => { + assert.equal( module.exports, 'ok' ); + }); + }); + });