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

fix(@angular-devkit/build-angular): generate correct filenames when targeting ESNext #16937

Merged
merged 1 commit into from Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -110,9 +110,15 @@ export function getEsVersionForFileName(
scriptTargetOverride: ScriptTarget | undefined,
esVersionInFileName = false,
): string {
return scriptTargetOverride && esVersionInFileName
? '-' + ScriptTarget[scriptTargetOverride].toLowerCase()
: '';
if (!esVersionInFileName || scriptTargetOverride === undefined) {
return '';
}

if (scriptTargetOverride === ScriptTarget.ESNext) {
return '-esnext';
}

return '-' + ScriptTarget[scriptTargetOverride].toLowerCase();
}

export function isPolyfillsEntry(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions packages/angular_devkit/build_angular/src/browser/index.ts
Expand Up @@ -352,7 +352,7 @@ export function buildWebpackBrowser(
}
workerReplacements.push([
file.file,
file.file.replace(/\-es20\d{2}/, '-es5'),
file.file.replace(/\-(es20\d{2}|esnext)/, '-es5'),
]);
} else {
continue;
Expand Down Expand Up @@ -435,7 +435,7 @@ export function buildWebpackBrowser(
// Add the newly created ES5 bundles to the index as nomodule scripts
const newFilename = es5Polyfills
? file.file.replace(/\-es20\d{2}/, '')
: file.file.replace(/\-es20\d{2}/, '-es5');
: file.file.replace(/\-(es20\d{2}|esnext)/, '-es5');
noModuleFiles.push({ ...file, file: newFilename });
}

Expand Down
Expand Up @@ -154,7 +154,7 @@ export class BundleActionCache {
cacheEntry = entries[CacheKey.DownlevelCode];
if (cacheEntry) {
result.downlevel = {
filename: action.filename.replace(/\-es20\d{2}/, '-es5'),
filename: action.filename.replace(/\-(es20\d{2}|esnext)/, '-es5'),
size: cacheEntry.size,
integrity: cacheEntry.integrity,
};
Expand All @@ -164,7 +164,7 @@ export class BundleActionCache {
cacheEntry = entries[CacheKey.DownlevelMap];
if (cacheEntry) {
result.downlevel.map = {
filename: action.filename.replace(/\-es20\d{2}/, '-es5') + '.map',
filename: action.filename.replace(/\-(es20\d{2}|esnext)/, '-es5') + '.map',
size: cacheEntry.size,
};

Expand Down
Expand Up @@ -110,7 +110,7 @@ export async function process(options: ProcessBundleOptions): Promise<ProcessBun

const basePath = path.dirname(options.filename);
const filename = path.basename(options.filename);
const downlevelFilename = filename.replace(/\-es20\d{2}/, '-es5');
const downlevelFilename = filename.replace(/\-(es20\d{2}|esnext)/, '-es5');
const downlevel = !options.optimizeOnly;
const sourceCode = options.code;
const sourceMap = options.map ? JSON.parse(options.map) : undefined;
Expand Down Expand Up @@ -440,7 +440,7 @@ async function processRuntime(

// Adjust lazy loaded scripts to point to the proper variant
// Extra spacing is intentional to align source line positions
downlevelCode = downlevelCode.replace(/"\-es20\d{2}\./, ' "-es5.');
downlevelCode = downlevelCode.replace(/"\-(es20\d{2}|esnext)\./, ' "-es5.');

return {
original: await processBundle({
Expand All @@ -451,7 +451,7 @@ async function processRuntime(
downlevel: await processBundle({
...options,
code: downlevelCode,
filename: options.filename.replace(/\-es20\d{2}/, '-es5'),
filename: options.filename.replace(/\-(es20\d{2}|esnext)/, '-es5'),
isOriginal: false,
}),
};
Expand Down
Expand Up @@ -104,6 +104,48 @@ describe('Browser Builder with differential loading', () => {
expect(Object.keys(files)).toEqual(jasmine.arrayWithExactContents(expectedOutputs));
});

it('emits all the neccessary files for target of ESNext', async () => {
host.replaceInFile(
'tsconfig.json',
'"target": "es2015",',
`"target": "esnext",`,
);

const { files } = await browserBuild(architect, host, target);

const expectedOutputs = [
'favicon.ico',
'index.html',

'main-esnext.js',
'main-esnext.js.map',
'main-es5.js',
'main-es5.js.map',

'polyfills-esnext.js',
'polyfills-esnext.js.map',
'polyfills-es5.js',
'polyfills-es5.js.map',

'runtime-esnext.js',
'runtime-esnext.js.map',
'runtime-es5.js',
'runtime-es5.js.map',

'styles-esnext.js',
'styles-esnext.js.map',
'styles-es5.js',
'styles-es5.js.map',

'vendor-esnext.js',
'vendor-esnext.js.map',
'vendor-es5.js',
'vendor-es5.js.map',
] as PathFragment[];

expect(Object.keys(files)).toEqual(jasmine.arrayWithExactContents(expectedOutputs));
});

it('deactivates differential loading for watch mode', async () => {
const { files } = await browserBuild(architect, host, target, { watch: true });

Expand Down