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

Allow named entrypoints #329

Merged
merged 2 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
111 changes: 11 additions & 100 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"locate-character": "^2.0.5",
"mocha": "^5.0.1",
"require-relative": "^0.8.7",
"rollup": "^0.57.0",
"rollup": "^0.63.2",
"rollup-plugin-buble": "^0.19.2",
"rollup-plugin-node-resolve": "^3.0.3",
"shx": "^0.2.2",
Expand Down
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export default function commonjs ( options = {} ) {
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 );

return resolveUsingOtherResolvers( importee, importer ).then( resolved => {
if ( resolved ) return isProxyModule ? PREFIX + resolved : resolved;

Expand Down Expand Up @@ -159,8 +159,11 @@ export default function commonjs ( options = {} ) {
resolvers.unshift( id => isExternal( id ) ? false : null );

resolveUsingOtherResolvers = first( resolvers );

const entryModules = [].concat( options.input || options.entry );
let input = options.input || options.entry;
if(!Array.isArray(input)&&typeof input === "object") {
input = Object.values(input);
}
const entryModules = [].concat( input );
entryModuleIdsPromise = Promise.all(
entryModules.map( entry => resolveId( entry ))
);
Expand Down
39 changes: 30 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,24 @@ describe( 'rollup-plugin-commonjs', () => {
plugins: [ commonjs({ sourceMap: true }) ]
});

const generated = await bundle.generate({
const {code, map} = await bundle.generate({
format: 'cjs',
sourcemap: true,
sourcemapFile: path.resolve( 'bundle.js' )
});

const smc = new SourceMapConsumer( generated.map );
const locator = getLocator( generated.code, { offsetLine: 1 });
const smc = new SourceMapConsumer( map );
const locator = getLocator( code, { offsetLine: 1 });

let generatedLoc = locator( '42' );
let loc = smc.originalPositionFor( generatedLoc ); // 42
assert.equal( loc.source, 'foo.js' );
assert.equal( loc.source, 'samples/sourcemap/foo.js' );
assert.equal( loc.line, 1 );
assert.equal( loc.column, 15 );

generatedLoc = locator( 'log' );
loc = smc.originalPositionFor( generatedLoc ); // log
assert.equal( loc.source, 'main.js' );
assert.equal( loc.source, 'samples/sourcemap/main.js' );
assert.equal( loc.line, 2 );
assert.equal( loc.column, 8 );
});
Expand All @@ -160,13 +160,34 @@ describe( 'rollup-plugin-commonjs', () => {
plugins: [ commonjs() ]
});

const generated = await bundle.generate({
const {output} = await bundle.generate({
format: 'cjs',
chunkFileNames: '[name].js'
});
//console.log(bundle);
assert.equal(Object.keys(output).length, 3);
assert.equal('b.js' in output, true);
assert.equal('c.js' in output, true);
});

it( 'supports multiple entry points as object for experimentalCodeSplitting', async () => {
const bundle = await rollup({
input: {
b: require.resolve('./samples/multiple-entry-points/b.js'),
c: require.resolve('./samples/multiple-entry-points/c.js')
},
experimentalCodeSplitting: true,
plugins: [ resolve(), commonjs() ]
});

const {output} = await bundle.generate({
format: 'cjs',
chunkFileNames: '[name].js'
});

assert.equal(Object.keys(generated).length, 3);
assert.equal(generated.hasOwnProperty('./b.js'), true);
assert.equal(generated.hasOwnProperty('./c.js'), true);
assert.equal(Object.keys(output).length, 3);
assert.equal('b.js' in output, true);
assert.equal('c.js' in output, true);
});

it( 'handles references to `global`', async () => {
Expand Down