diff --git a/test/node_modules/browser-remapping-module/lib/client/http-tracker.js b/test/node_modules/browser-remapping-module/lib/client/http-tracker.js new file mode 100644 index 0000000..75e80bd --- /dev/null +++ b/test/node_modules/browser-remapping-module/lib/client/http-tracker.js @@ -0,0 +1,4 @@ + +module.exports = function(client, announceUrl) { + this.name = 'http-tracker' +} diff --git a/test/node_modules/browser-remapping-module/lib/client/udp-tracker.js b/test/node_modules/browser-remapping-module/lib/client/udp-tracker.js new file mode 100644 index 0000000..bb2c98b --- /dev/null +++ b/test/node_modules/browser-remapping-module/lib/client/udp-tracker.js @@ -0,0 +1,4 @@ + +module.exports = function(client, announceUrl) { + this.name = 'udp-tracker' +} diff --git a/test/node_modules/browser-remapping-module/lib/client/websocket-tracker.js b/test/node_modules/browser-remapping-module/lib/client/websocket-tracker.js new file mode 100644 index 0000000..c7a38e4 --- /dev/null +++ b/test/node_modules/browser-remapping-module/lib/client/websocket-tracker.js @@ -0,0 +1,4 @@ + +module.exports = function(client, announceUrl) { + this.name = 'websocket-tracker' +} diff --git a/test/node_modules/browser-remapping-module/lib/index.js b/test/node_modules/browser-remapping-module/lib/index.js new file mode 100644 index 0000000..073ab9f --- /dev/null +++ b/test/node_modules/browser-remapping-module/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/browser-remapping-module/package.json b/test/node_modules/browser-remapping-module/package.json new file mode 100644 index 0000000..4b340ce --- /dev/null +++ b/test/node_modules/browser-remapping-module/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-remapping/main.js b/test/samples/browser-remapping/main.js new file mode 100644 index 0000000..68fbd12 --- /dev/null +++ b/test/samples/browser-remapping/main.js @@ -0,0 +1,13 @@ +import Client from 'browser-remapping-module'; +import HTTPTracker from 'browser-remapping-module/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 47d44b8..f8e1f68 100644 --- a/test/test.js +++ b/test/test.js @@ -626,4 +626,16 @@ describe( 'rollup-plugin-node-resolve', function () { assert.deepEqual( bundle.imports, [ 'foo/deep' ] ); }); }); + + it( 'pkg.browser with mapping to prevent bundle by specifying a value of false', () => { + return rollup.rollup({ + input: 'samples/browser-remapping/main.js', + plugins: [ + nodeResolve({ browser: true }), + commonjs() + ] + }).then( executeBundle ).then( module => { + assert.equal( module.exports, 'ok' ); + }); + }); });