Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export function buildWebpackBrowser(
if (actionOptions.sourceMaps) {
try {
map = fs.readFileSync(filename + '.map', 'utf8');
if (es5Polyfills) {
if (es5Polyfills || i18n.shouldInline) {
fs.unlinkSync(filename + '.map');
}
} catch {}
Expand All @@ -374,6 +374,10 @@ export function buildWebpackBrowser(
if (es5Polyfills) {
fs.unlinkSync(filename);
filename = filename.replace(/\-es20\d{2}/, '');
} else if (i18n.shouldInline) {
// Original files must be deleted with i18n to avoid the original files from
// being copied over the translated files when copying the project assets.
fs.unlinkSync(filename);
}

const es2015Polyfills = file.file.startsWith('polyfills-es20');
Expand All @@ -391,6 +395,8 @@ export function buildWebpackBrowser(
runtime: file.file.startsWith('runtime'),
ignoreOriginal: es5Polyfills,
optimizeOnly: es2015Polyfills,
// When using i18n, file results are kept in memory for further processing
memoryMode: i18n.shouldInline,
});

// ES2015 polyfills are only optimized; optimization check was performed above
Expand Down Expand Up @@ -451,41 +457,32 @@ export function buildWebpackBrowser(
if (i18n.shouldInline) {
spinner.start('Generating localized bundles...');
const inlineActions: InlineOptions[] = [];
const processedFiles = new Set<string>();
for (const result of processResults) {
if (result.original) {
inlineActions.push({
filename: path.basename(result.original.filename),
code: fs.readFileSync(result.original.filename, 'utf8'),
map:
result.original.map &&
fs.readFileSync(result.original.map.filename, 'utf8'),
// Memory mode is always enabled for i18n
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
code: result.original.content!,
map: result.original.map?.content,
outputPath: baseOutputPath,
es5: false,
missingTranslation: options.i18nMissingTranslation,
setLocale: result.name === mainChunkId,
});
processedFiles.add(result.original.filename);
if (result.original.map) {
processedFiles.add(result.original.map.filename);
}
}
if (result.downlevel) {
inlineActions.push({
filename: path.basename(result.downlevel.filename),
code: fs.readFileSync(result.downlevel.filename, 'utf8'),
map:
result.downlevel.map &&
fs.readFileSync(result.downlevel.map.filename, 'utf8'),
// Memory mode is always enabled for i18n
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
code: result.downlevel.content!,
map: result.downlevel.map?.content,
outputPath: baseOutputPath,
es5: true,
missingTranslation: options.i18nMissingTranslation,
setLocale: result.name === mainChunkId,
});
processedFiles.add(result.downlevel.filename);
if (result.downlevel.map) {
processedFiles.add(result.downlevel.map.filename);
}
}
}

Expand Down Expand Up @@ -520,9 +517,6 @@ export function buildWebpackBrowser(
glob: '**/*',
input: webpackOutputPath,
output: '',
ignore: [...processedFiles].map((f) =>
path.relative(webpackOutputPath, f),
),
},
],
Array.from(outputPaths.values()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,19 @@ export class BundleActionExecutor {
actions: Iterable<I>,
executor: (action: I) => Promise<O>,
): AsyncIterable<O> {
const executions = new Map<Promise<O>, Promise<O>>();
const executions = new Map<Promise<O>, Promise<[Promise<O>, O]>>();
for (const action of actions) {
const execution = executor(action);
executions.set(
execution,
execution.then((result) => {
executions.delete(execution);

return result;
}),
execution.then((result) => [execution, result]),
);
}

while (executions.size > 0) {
yield Promise.race(executions.values());
const [execution, result] = await Promise.race(executions.values());
executions.delete(execution);
yield result;
}
}

Expand Down
23 changes: 20 additions & 3 deletions packages/angular_devkit/build_angular/src/utils/process-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface ProcessBundleOptions {
runtimeData?: ProcessBundleResult[];
replacements?: [string, string][];
supportedBrowsers?: string[] | Record<string, string>;
memoryMode?: boolean;
}

export interface ProcessBundleResult {
Expand All @@ -69,9 +70,11 @@ export interface ProcessBundleFile {
filename: string;
size: number;
integrity?: string;
content?: string;
map?: {
filename: string;
size: number;
content?: string;
};
}

Expand Down Expand Up @@ -200,6 +203,7 @@ async function processBundle(
hiddenSourceMaps,
cacheKeys = [],
integrityAlgorithm,
memoryMode,
} = options;

const filename = path.basename(filepath);
Expand Down Expand Up @@ -242,17 +246,27 @@ async function processBundle(
mapContent,
cacheKeys[isOriginal ? CacheKey.OriginalMap : CacheKey.DownlevelMap],
);
fs.writeFileSync(filepath + '.map', mapContent);
if (!memoryMode) {
fs.writeFileSync(filepath + '.map', mapContent);
}
}

const fileResult = createFileEntry(filepath, resultCode, mapContent, integrityAlgorithm);
const fileResult = createFileEntry(
filepath,
resultCode,
mapContent,
memoryMode,
integrityAlgorithm,
);

await cachePut(
resultCode,
cacheKeys[isOriginal ? CacheKey.OriginalCode : CacheKey.DownlevelCode],
fileResult.integrity,
);
fs.writeFileSync(filepath, resultCode);
if (!memoryMode) {
fs.writeFileSync(filepath, resultCode);
}

return fileResult;
}
Expand Down Expand Up @@ -293,17 +307,20 @@ function createFileEntry(
filename: string,
code: string,
map: string | undefined,
memoryMode?: boolean,
integrityAlgorithm?: string,
): ProcessBundleFile {
return {
filename: filename,
size: Buffer.byteLength(code),
integrity: integrityAlgorithm && generateIntegrityValue(integrityAlgorithm, code),
content: memoryMode ? code : undefined,
map: !map
? undefined
: {
filename: filename + '.map',
size: Buffer.byteLength(map),
content: memoryMode ? map : undefined,
},
};
}
Expand Down