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

Commit

Permalink
fix up successive build handling
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Apr 30, 2018
1 parent 95b5f70 commit c95b06b
Show file tree
Hide file tree
Showing 2 changed files with 27 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 @@ -114,7 +114,7 @@ export default function commonjs ( options = {} ) {
function setIsCjsPromise ( id, promise ) {
const isCjsPromise = isCjsPromises[id];
if (isCjsPromise) {
if (!isCjsPromise.resolve) {
if (isCjsPromise.resolve) {
isCjsPromise.resolve(promise);
isCjsPromise.resolve = undefined;
}
Expand Down
26 changes: 26 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,32 @@ describe( 'rollup-plugin-commonjs', () => {
assert.equal( module.exports, 'foobar', generated.code );
});

it( 'handles successive builds', async () => {
const plugin = commonjs()
let bundle = await rollup({
input: 'samples/corejs/literal-with-default.js',
plugins: [ plugin ]
});
await bundle.generate({
format: 'cjs'
});

bundle = await rollup({
input: 'samples/corejs/literal-with-default.js',
plugins: [ plugin ]
});
const generated = await bundle.generate({
format: 'cjs'
});

const module = { exports: {} };

const fn = new Function ( 'module', 'exports', generated.code );
fn( module, module.exports );

assert.equal( module.exports, 'foobar', generated.code );
});

it( 'allows named exports to be added explicitly via config', async () => {
const bundle = await rollup({
input: 'samples/custom-named-exports/main.js',
Expand Down

0 comments on commit c95b06b

Please sign in to comment.