Skip to content

Commit

Permalink
Always warn when no name is provided for a global module (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 authored and lukastaegert committed Jul 31, 2018
1 parent 489477d commit d07d5bf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Chunk.ts
Expand Up @@ -68,8 +68,17 @@ function getGlobalName(
graph: Graph,
hasExports: boolean
) {
if (typeof globals === 'function') return globals(module.id);
if (globals) return globals[module.id];
let globalName: string | undefined;
if (typeof globals === 'function') {
globalName = globals(module.id);
} else if (globals) {
globalName = globals[module.id];
}

if (globalName) {
return globalName;
}

if (hasExports) {
graph.warn({
code: 'MISSING_GLOBAL_NAME',
Expand Down
32 changes: 32 additions & 0 deletions test/misc/index.js
Expand Up @@ -543,4 +543,36 @@ describe('misc', () => {
);
});
});

it('warns when globals option is specified and a global module name is guessed in a UMD bundle (#2358)', () => {
const warnings = [];

return rollup
.rollup({
input: 'input',
plugins: [
loader({
input: `import * as _ from 'lodash'`
})
],
onwarn: warning => warnings.push(warning)
})
.then(bundle =>
bundle.generate({
format: 'umd',
globals: [],
name: 'myBundle'
})
)
.then(() => {
const relevantWarnings = warnings.filter(
warning => warning.code === 'MISSING_GLOBAL_NAME'
);
assert.equal(relevantWarnings.length, 1);
assert.equal(
relevantWarnings[0].message,
`No name was provided for external module 'lodash' in output.globals – guessing 'lodash'`
);
});
});
});

0 comments on commit d07d5bf

Please sign in to comment.