Skip to content

Commit

Permalink
warn when both eager mode and chunk name is used
Browse files Browse the repository at this point in the history
  • Loading branch information
amsardesai committed May 1, 2024
1 parent f05a9e5 commit 7c488a3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
8 changes: 8 additions & 0 deletions src/rules/dynamic-import-chunkname.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ module.exports = {
}
}

if (isChunknamePresent && isEagerModePresent) {
context.report({
node,
message:
`dynamic imports should not have both webpackChunkName and webpackMode: "eager"`,
});
}

if (!isChunknamePresent && !allowEmpty && !isEagerModePresent) {
context.report({
node,
Expand Down
67 changes: 47 additions & 20 deletions tests/src/rules/dynamic-import-chunkname.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const invalidSyntaxCommentError = 'dynamic imports require a "webpack" comment w
const commentFormatError = `dynamic imports require a "webpack" comment with valid syntax`;
const chunkNameFormatError = `dynamic imports require a leading comment in the form /* webpackChunkName: ["']${commentFormat}["'],? */`;
const pickyChunkNameFormatError = `dynamic imports require a leading comment in the form /* webpackChunkName: ["']${pickyCommentFormat}["'],? */`;
const eagerModeError = `dynamic imports should not have both webpackChunkName and webpackMode: "eager"`;

ruleTester.run('dynamic-import-chunkname', rule, {
valid: [
Expand Down Expand Up @@ -352,15 +353,6 @@ ruleTester.run('dynamic-import-chunkname', rule, {
options,
parser,
},
{
code: `import(
/* webpackChunkName: "someModule" */
/* webpackMode: "eager" */
'someModule'
)`,
options,
parser,
},
{
code: `import(
/* webpackChunkName: "someModule" */
Expand Down Expand Up @@ -412,7 +404,7 @@ ruleTester.run('dynamic-import-chunkname', rule, {
/* webpackPrefetch: true */
/* webpackPreload: true */
/* webpackIgnore: false */
/* webpackMode: "eager" */
/* webpackMode: "lazy" */
/* webpackExports: ["default", "named"] */
'someModule'
)`,
Expand Down Expand Up @@ -989,6 +981,24 @@ ruleTester.run('dynamic-import-chunkname', rule, {
type: 'CallExpression',
}],
},
{
code: `import(
/* webpackChunkName: "someModule" */
/* webpackMode: "eager" */
'someModule'
)`,
options,
parser,
output: `import(
/* webpackChunkName: "someModule" */
/* webpackMode: "eager" */
'someModule'
)`,
errors: [{
message: eagerModeError,
type: 'CallExpression',
}],
},
],
});

Expand Down Expand Up @@ -1247,15 +1257,6 @@ context('TypeScript', () => {
options,
parser: typescriptParser,
},
{
code: `import(
/* webpackChunkName: "someModule" */
/* webpackMode: "eager" */
'someModule'
)`,
options,
parser: typescriptParser,
},
{
code: `import(
/* webpackChunkName: "someModule" */
Expand Down Expand Up @@ -1307,13 +1308,21 @@ context('TypeScript', () => {
/* webpackPrefetch: true */
/* webpackPreload: true */
/* webpackIgnore: false */
/* webpackMode: "eager" */
/* webpackMode: "lazy" */
/* webpackExports: ["default", "named"] */
'someModule'
)`,
options,
parser: typescriptParser,
},
{
code: `import(
/* webpackMode: 'eager' */
'someModule'
)`,
options,
parser: typescriptParser,
},
],
invalid: [
{
Expand Down Expand Up @@ -1760,6 +1769,24 @@ context('TypeScript', () => {
type: nodeType,
}],
},
{
code: `import(
/* webpackChunkName: "someModule" */
/* webpackMode: "eager" */
'someModule'
)`,
options,
parser: typescriptParser,
output: `import(
/* webpackChunkName: "someModule" */
/* webpackMode: "eager" */
'someModule'
)`,
errors: [{
message: eagerModeError,
type: nodeType,
}],
},
],
});
});
Expand Down

0 comments on commit 7c488a3

Please sign in to comment.