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

Commit

Permalink
prevent false positive with namedExports (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jan 31, 2016
1 parent 9ee01e0 commit e47b253
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default function commonjs ( options = {} ) {
const sources = Object.keys( required );

if ( !sources.length && !uses.module && !uses.exports && !uses.global ) {
if ( Object.keys( customNamedExports ).length ) {
if ( Object.keys( namedExports ).length ) {
throw new Error( `Custom named exports were specified for ${id} but it does not appear to be a CommonJS module` );
}
return null; // not a CommonJS module
Expand Down
2 changes: 2 additions & 0 deletions test/samples/custom-named-exports-false-positive/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { thing } from './other.js';
assert.equal( thing, 'yes' );
2 changes: 2 additions & 0 deletions test/samples/custom-named-exports-false-positive/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* require (https://github.com/rollup/rollup-plugin-commonjs/issues/36) */
export const thing = 'yes';
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ describe( 'rollup-plugin-commonjs', () => {
}).then( executeBundle );
});

it( 'ignores false positives with namedExports (#36)', () => {
return rollup({
entry: 'samples/custom-named-exports-false-positive/main.js',
plugins: [
npm({ main: true }),
commonjs({
namedExports: {
'irrelevant': [ 'lol' ]
}
})
]
}).then( executeBundle );
});

it( 'converts a CommonJS module with custom file extension', () => {
return rollup({
entry: 'samples/extension/main.coffee',
Expand Down

0 comments on commit e47b253

Please sign in to comment.