diff --git a/CHANGELOG.md b/CHANGELOG.md index f2041ef..a8e673b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,13 @@ # rollup-plugin-commonjs changelog + +## 9.1.8 +*2018-09-18* +* Ignore virtual modules created by other plugins ([#327](https://github.com/rollup/rollup-plugin-commonjs/issues/327)) +* Add "location" and "process" to reserved words ([#330](https://github.com/rollup/rollup-plugin-commonjs/issues/330)) + +## 9.1.6 +*2018-08-24* +* Keep commonJS detection between instantiations ([#338](https://github.com/rollup/rollup-plugin-commonjs/issues/338)) ## 9.1.5 *2018-08-09* diff --git a/package-lock.json b/package-lock.json index 4dc1a10..852768d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "rollup-plugin-commonjs", - "version": "9.1.5", + "version": "9.1.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index d862523..8f5bd03 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup-plugin-commonjs", - "version": "9.1.6", + "version": "9.1.8", "description": "Convert CommonJS modules to ES2015", "main": "dist/rollup-plugin-commonjs.cjs.js", "module": "dist/rollup-plugin-commonjs.es.js", diff --git a/src/index.js b/src/index.js index d15344b..64a3991 100644 --- a/src/index.js +++ b/src/index.js @@ -71,12 +71,17 @@ let entryModuleIdsPromise = null; function resolveId ( importee, importer ) { - if ( importee === HELPERS_ID ) return importee; - - if ( importer && startsWith( importer, PREFIX ) ) importer = importer.slice( PREFIX.length ); - const isProxyModule = startsWith( importee, PREFIX ); - if ( isProxyModule ) importee = importee.slice( PREFIX.length ); + if ( isProxyModule ) { + importee = importee.slice( PREFIX.length ); + } + else if ( startsWith( importee, '\0' ) ) { + return importee; + } + + if ( importer && startsWith( importer, PREFIX ) ) { + importer = importer.slice( PREFIX.length ); + } return resolveUsingOtherResolvers( importee, importer ).then( resolved => { if ( resolved ) return isProxyModule ? PREFIX + resolved : resolved; diff --git a/src/transform.js b/src/transform.js index a2a64cc..6eaf7bd 100644 --- a/src/transform.js +++ b/src/transform.js @@ -5,7 +5,7 @@ import { PREFIX, HELPERS_ID } from './helpers.js'; import { getName } from './utils.js'; -const reserved = 'abstract arguments boolean break byte case catch char class const continue debugger default delete do double else enum eval export extends false final finally float for from function goto if implements import in instanceof int interface let long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with yield'.split( ' ' ); +const reserved = 'process location abstract arguments boolean break byte case catch char class const continue debugger default delete do double else enum eval export extends false final finally float for from function goto if implements import in instanceof int interface let long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with yield'.split( ' ' ); const blacklist = { __esModule: true }; reserved.forEach( word => blacklist[ word ] = true ); diff --git a/test/samples/ignore-virtual-modules/main.js b/test/samples/ignore-virtual-modules/main.js new file mode 100644 index 0000000..bd7683e --- /dev/null +++ b/test/samples/ignore-virtual-modules/main.js @@ -0,0 +1 @@ +module.exports = require('\0virtual'); diff --git a/test/test.js b/test/test.js index a7e2115..58995f8 100644 --- a/test/test.js +++ b/test/test.js @@ -576,5 +576,19 @@ assert.equal( error.frame, '1: export const foo = 2,\n ^' ); } }); + + it('ignores virtual modules', async () => { + const bundle = await rollup({ + input: 'samples/ignore-virtual-modules/main.js', + plugins: [ commonjs(), { + load (id) { + if (id === '\0virtual') { + return 'export default "Virtual export"'; + } + } + } ] + }); + assert.equal( (await executeBundle( bundle )).exports, 'Virtual export' ); + }); }); });