Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
fix: ignore virtual modules from other plugins (#327)
Browse files Browse the repository at this point in the history
* fix: ignore virtual modules from other plugins

Closes #315

* Add test that virtual modules are ignored
  • Loading branch information
aleclarson authored and lukastaegert committed Sep 18, 2018
1 parent 5936873 commit e6063ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ export default function commonjs ( options = {} ) {
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;
Expand Down
1 change: 1 addition & 0 deletions test/samples/ignore-virtual-modules/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('\0virtual');
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,5 +576,19 @@ describe( 'rollup-plugin-commonjs', () => {
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' );
});
});
});

0 comments on commit e6063ea

Please sign in to comment.