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

feat: add option to keep extensions for amd #4607

Merged
merged 9 commits into from Aug 31, 2022
4 changes: 3 additions & 1 deletion src/finalisers/amd.ts
Expand Up @@ -35,7 +35,9 @@ export default function amd(
}: NormalizedOutputOptions
): Bundle {
warnOnBuiltins(warn, dependencies);
const deps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`);
const deps = dependencies.map(
m => `'${amd.keepExtension ? m.id : removeExtensionFromRelativeAmdId(m.id)}'`
);
const args = dependencies.map(m => m.name);
const { n, getNonArrowFunctionIntro, _ } = snippets;

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

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

export interface OutputOptions {
Expand Down
15 changes: 12 additions & 3 deletions src/utils/options/normalizeOutputOptions.ts
Expand Up @@ -225,10 +225,17 @@ const getPreserveModulesRoot = (
};

const getAmd = (config: OutputOptions): NormalizedOutputOptions['amd'] => {
const mergedOption: { autoId: boolean; basePath: string; define: string; id?: string } = {
const mergedOption: {
autoId: boolean;
basePath: string;
define: string;
id?: string;
keepExtension: boolean;
} = {
autoId: false,
basePath: '',
define: 'define',
keepExtension: false,
...config.amd
};

Expand Down Expand Up @@ -256,13 +263,15 @@ const getAmd = (config: OutputOptions): NormalizedOutputOptions['amd'] => {
normalized = {
autoId: true,
basePath: mergedOption.basePath,
define: mergedOption.define
define: mergedOption.define,
keepExtension: mergedOption.keepExtension
};
} else {
normalized = {
autoId: false,
define: mergedOption.define,
id: mergedOption.id
id: mergedOption.id,
keepExtension: mergedOption.keepExtension
};
}
return normalized;
Expand Down