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

Commit

Permalink
Merge branch 'mister-what-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Aug 9, 2018
2 parents 8ce5e71 + b1cd440 commit 81bea94
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 112 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# rollup-plugin-commonjs changelog

## 9.1.5
*2018-08-09*
* Handle object form of input ([#329](https://github.com/rollup/rollup-plugin-commonjs/issues/329))

## 9.1.4
*2018-07-27*
* Make "from" a reserved word ([#320](https://github.com/rollup/rollup-plugin-commonjs/issues/320))
Expand Down
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
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
8 changes: 6 additions & 2 deletions src/index.js
Expand Up @@ -159,8 +159,12 @@ export default function commonjs ( options = {} ) {
resolvers.unshift( id => isExternal( id ) ? false : null );

resolveUsingOtherResolvers = first( resolvers );

const entryModules = [].concat( options.input || options.entry );
const input = options.input || options.entry;
const entryModules = Array.isArray(input) ?
input :
typeof input === 'object' && input !== null ?
Object.values(input) :
[input];
entryModuleIdsPromise = Promise.all(
entryModules.map( entry => resolveId( entry ))
);
Expand Down
39 changes: 30 additions & 9 deletions test/test.js
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

0 comments on commit 81bea94

Please sign in to comment.