Skip to content

Commit

Permalink
Remove the need to provide an output name for IIFE bundles (#3181)
Browse files Browse the repository at this point in the history
* Remove the need to provide an output name for IIFE bundles

* Add test for IIFE warning

Also migrate UMD test and remove some unused folders
  • Loading branch information
bterrier authored and lukastaegert committed Oct 27, 2019
1 parent b4c8b43 commit 2f7e064
Show file tree
Hide file tree
Showing 26 changed files with 24 additions and 179 deletions.
9 changes: 4 additions & 5 deletions src/finalisers/iife.ts
Expand Up @@ -48,9 +48,8 @@ export default function iife(
const args = external.map(m => m.name);

if (hasExports && !name) {
error({
code: 'INVALID_OPTION',
message: `You must supply "output.name" for IIFE bundles.`
warn({
message: `If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.`
});
}

Expand All @@ -68,9 +67,9 @@ export default function iife(

let wrapperIntro = `(function${_}(${args.join(`,${_}`)})${_}{${n}${useStrict}`;

if (hasExports && (!extend || !namedExportsMode)) {
if (hasExports && (!extend || !namedExportsMode) && name) {
wrapperIntro =
(useVariableAssignment ? `${varOrConst} ${name}` : thisProp(name as string)) +
(useVariableAssignment ? `${varOrConst} ${name}` : thisProp(name)) +
`${_}=${_}${wrapperIntro}`;
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions test/function/samples/dynamic-import-name/_expected/system/main.js

This file was deleted.

8 changes: 8 additions & 0 deletions test/function/samples/error-missing-umd-name/_config.js
@@ -0,0 +1,8 @@
module.exports = {
description: 'throws an error if no name is provided for a UMD bundle',
options: { output: { format: 'umd' } },
generateError: {
code: 'INVALID_OPTION',
message: 'You must supply "output.name" for UMD bundles.'
}
};
1 change: 1 addition & 0 deletions test/function/samples/error-missing-umd-name/main.js
@@ -0,0 +1 @@
export const x = 42;

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 10 additions & 0 deletions test/function/samples/warn-missing-iife-name/_config.js
@@ -0,0 +1,10 @@
module.exports = {
description: 'warns if no name is provided for an IIFE bundle',
options: { output: { format: 'iife' } },
warnings: [
{
message:
'If you do not supply "output.name", you may not be able to access the exports of an IIFE bundle.'
}
]
};
1 change: 1 addition & 0 deletions test/function/samples/warn-missing-iife-name/main.js
@@ -0,0 +1 @@
export const x = 42;
36 changes: 0 additions & 36 deletions test/misc/write-bundle.js
Expand Up @@ -25,42 +25,6 @@ describe('bundle.write()', () => {
});
});

it('expects output.name for IIFE and UMD bundles', () => {
let bundle;

return rollup
.rollup({
input: 'x',
plugins: [
{
resolveId: () => 'test',
load: () => 'export var foo = 42;'
}
]
})
.then(rollupInstance => {
bundle = rollupInstance;
return bundle.generate({
format: 'umd'
});
})
.catch(err => {
assert.throws(() => {
throw err;
}, /You must supply "output\.name" for UMD bundles/);
})
.then(() => {
return bundle.generate({
format: 'iife'
});
})
.catch(err => {
assert.throws(() => {
throw err;
}, /You must supply "output\.name" for IIFE bundles/);
});
});

it('throws on es6 format', () => {
return rollup
.rollup({
Expand Down

0 comments on commit 2f7e064

Please sign in to comment.