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

Clearer empty chunk warning #3244

Merged
merged 7 commits into from Nov 20, 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
18 changes: 14 additions & 4 deletions cli/run/batchWarnings.ts
Expand Up @@ -110,10 +110,6 @@ const immediateHandlers: {
stderr(
`Consumers of your bundle will have to use bundle['default'] to access the default export, which may not be what you want. Use \`output.exports: 'named'\` to disable this warning`
);
},

EMPTY_BUNDLE: () => {
title(`Generated an empty bundle`);
}
};

Expand Down Expand Up @@ -270,6 +266,20 @@ const deferredHandlers: {
});
},
priority: 1
},

EMPTY_BUNDLE: {
fn: warnings => {
title(
`Generated${warnings.length === 1 ? ' an' : ''} empty ${
warnings.length > 1 ? 'chunks' : 'chunk'
}`
);
warnings.forEach(warning => {
stderr(warning.chunkName as string);
});
},
priority: 1
tjenkinson marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/Chunk.ts
Expand Up @@ -620,9 +620,11 @@ export default class Chunk {
this.renderedHash = undefined as any;

if (this.getExportNames().length === 0 && this.getImportIds().length === 0 && this.isEmpty) {
const chunkName = this.getChunkName();
this.graph.warn({
chunkName,
code: 'EMPTY_BUNDLE',
message: 'Generated an empty bundle'
message: `Generated an empty chunk: "${chunkName}"`
});
}

Expand Down
1 change: 1 addition & 0 deletions src/rollup/types.d.ts
Expand Up @@ -10,6 +10,7 @@ export interface RollupError extends RollupLogProps {
}

export interface RollupWarning extends RollupLogProps {
chunkName?: string;
exporter?: string;
exportName?: string;
guess?: string;
Expand Down
3 changes: 2 additions & 1 deletion test/function/samples/assign-namespace-to-var/_config.js
Expand Up @@ -2,8 +2,9 @@ module.exports = {
description: 'allows a namespace to be assigned to a variable',
warnings: [
{
chunkName: 'main',
code: 'EMPTY_BUNDLE',
message: 'Generated an empty bundle'
message: 'Generated an empty chunk: "main"'
}
]
};
3 changes: 2 additions & 1 deletion test/function/samples/can-import-self-treeshake/_config.js
Expand Up @@ -7,8 +7,9 @@ module.exports = {
message: 'Circular dependency: lib.js -> lib.js'
},
{
chunkName: 'main',
code: 'EMPTY_BUNDLE',
message: `Generated an empty bundle`
message: `Generated an empty chunk: "main"`
}
]
};
3 changes: 2 additions & 1 deletion test/function/samples/module-tree/_config.js
Expand Up @@ -34,8 +34,9 @@ module.exports = {
},
warnings: [
{
chunkName: 'main',
code: 'EMPTY_BUNDLE',
message: 'Generated an empty bundle'
message: 'Generated an empty chunk: "main"'
}
]
};
Expand Up @@ -2,8 +2,9 @@ module.exports = {
description: 'handles vars with init in dead branch (#1198)',
warnings: [
{
chunkName: 'main',
code: 'EMPTY_BUNDLE',
message: 'Generated an empty bundle'
message: 'Generated an empty chunk: "main"'
}
]
};
3 changes: 2 additions & 1 deletion test/function/samples/warn-on-empty-bundle/_config.js
Expand Up @@ -2,8 +2,9 @@ module.exports = {
description: 'warns if empty bundle is generated (#444)',
warnings: [
{
chunkName: 'main',
code: 'EMPTY_BUNDLE',
message: 'Generated an empty bundle'
message: 'Generated an empty chunk: "main"'
}
]
};
2 changes: 1 addition & 1 deletion test/function/samples/warnings-to-string/_config.js
Expand Up @@ -13,7 +13,7 @@ module.exports = {
warnings(warnings) {
assert.deepStrictEqual(warnings.map(String), [
'(test-plugin plugin) main.js (1:6) This might be removed',
'Generated an empty bundle'
'Generated an empty chunk: "main"'
]);
}
};