Skip to content

Commit

Permalink
Change extension name to forceJsExtensionForImports
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Aug 30, 2022
1 parent d27fd4e commit 3ede154
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cli/help.md
Expand Up @@ -23,7 +23,7 @@ Basic options:
--amd.autoId Generate the AMD ID based off the chunk name
--amd.basePath <prefix> Path to prepend to auto generated AMD ID
--amd.define <name> Function to use in place of `define`
--amd.keepExtension Add `.js` extension for generated chunks and local AMD modules
--amd.forceJsExtensionForImports Use `.js` extension in AMD imports
--assetFileNames <pattern> Name pattern for emitted assets
--banner <text> Code to insert at top of bundle (outside wrapper)
--chunkFileNames <pattern> Name pattern for emitted secondary chunks
Expand Down
2 changes: 1 addition & 1 deletion docs/01-command-line-reference.md
Expand Up @@ -358,7 +358,7 @@ Many options have command line equivalents. In those cases, any arguments passed
--amd.autoId Generate the AMD ID based off the chunk name
--amd.basePath <prefix> Path to prepend to auto generated AMD ID
--amd.define <name> Function to use in place of `define`
--amd.keepExtension Add `.js` extension for generated chunks and local AMD modules
--amd.forceJsExtensionForImports Use `.js` extension in AMD imports
--assetFileNames <pattern> Name pattern for emitted assets
--banner <text> Code to insert at top of bundle (outside wrapper)
--chunkFileNames <pattern> Name pattern for emitted secondary chunks
Expand Down
4 changes: 2 additions & 2 deletions docs/999-big-list-of-options.md
Expand Up @@ -1331,7 +1331,7 @@ export default {
// -> def(['dependency'],...
```

**output.amd.keepExtension**<br> Type: `boolean`<br> CLI: `--amd.keepExtension`<br> Default: `false`
**output.amd.forceJsExtensionForImports**<br> Type: `boolean`<br> CLI: `--amd.forceJsExtensionForImports`<br> Default: `false`

Add `.js` extension for imports of generated chunks and local AMD modules:

Expand All @@ -1341,7 +1341,7 @@ export default {
...,
format: 'amd',
amd: {
keepExtension: true
forceJsExtensionForImports: true
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/Chunk.ts
Expand Up @@ -938,7 +938,8 @@ export default class Chunk {
options: NormalizedOutputOptions,
snippets: GenerateCodeSnippets
): void {
const stripKnownJsExtensions = options.format === 'amd' && !options.amd.keepExtension;
const stripKnownJsExtensions =
options.format === 'amd' && !options.amd.forceJsExtensionForImports;
for (const [module, code] of this.renderedModuleSources) {
for (const { node, resolution } of module.dynamicImports) {
const chunk = this.chunkByModule.get(resolution as Module);
Expand Down
4 changes: 2 additions & 2 deletions src/finalisers/shared/updateExtensionForRelativeAmdId.ts
Expand Up @@ -6,11 +6,11 @@ import removeJsExtension from './removeJsExtension';
// https://requirejs.org/docs/api.html#jsfiles
export default function updateExtensionForRelativeAmdId(
id: string,
keepExtension: boolean
forceJsExtensionForImports: boolean
): string {
if (id[0] !== '.') {
return id;
}

return keepExtension ? addJsExtension(id) : removeJsExtension(id);
return forceJsExtensionForImports ? addJsExtension(id) : removeJsExtension(id);
}
6 changes: 2 additions & 4 deletions src/rollup/types.d.ts
Expand Up @@ -631,8 +631,7 @@ export type AmdOptions = (
}
) & {
define?: string;
} & {
keepExtension?: boolean;
forceJsExtensionForImports?: boolean;
};

export type NormalizedAmdOptions = (
Expand All @@ -646,8 +645,7 @@ export type NormalizedAmdOptions = (
}
) & {
define: string;
} & {
keepExtension: boolean;
forceJsExtensionForImports: boolean;
};

export interface OutputOptions {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/options/normalizeOutputOptions.ts
Expand Up @@ -229,13 +229,13 @@ const getAmd = (config: OutputOptions): NormalizedOutputOptions['amd'] => {
autoId: boolean;
basePath: string;
define: string;
forceJsExtensionForImports: boolean;
id?: string;
keepExtension: boolean;
} = {
autoId: false,
basePath: '',
define: 'define',
keepExtension: false,
forceJsExtensionForImports: false,
...config.amd
};

Expand Down Expand Up @@ -264,14 +264,14 @@ const getAmd = (config: OutputOptions): NormalizedOutputOptions['amd'] => {
autoId: true,
basePath: mergedOption.basePath,
define: mergedOption.define,
keepExtension: mergedOption.keepExtension
forceJsExtensionForImports: mergedOption.forceJsExtensionForImports
};
} else {
normalized = {
autoId: false,
define: mergedOption.define,
id: mergedOption.id,
keepExtension: mergedOption.keepExtension
forceJsExtensionForImports: mergedOption.forceJsExtensionForImports,
id: mergedOption.id
};
}
return normalized;
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/amd-keep-extension/_config.js
Expand Up @@ -2,6 +2,6 @@ module.exports = {
description: 'keep extension for AMD modules',
options: {
external: ['./foo', 'baz/quux'],
output: { interop: 'default', amd: { keepExtension: true } }
output: { interop: 'default', amd: { forceJsExtensionForImports: true } }
}
};
2 changes: 1 addition & 1 deletion test/function/samples/output-options-hook/_config.js
Expand Up @@ -19,7 +19,7 @@ module.exports = {
amd: {
define: 'define',
autoId: false,
keepExtension: false
forceJsExtensionForImports: false
},
assetFileNames: 'assets/[name]-[hash][extname]',
chunkFileNames: '[name]-[hash].js',
Expand Down

0 comments on commit 3ede154

Please sign in to comment.