Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the need to provide an output name for IIFE bundles #3181

Merged
merged 3 commits into from Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
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