Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): non injected styles should not co…
Browse files Browse the repository at this point in the history
…unt as initial

Closes #20781

(cherry picked from commit 2643fb1)
  • Loading branch information
alan-agius4 committed May 14, 2021
1 parent a817592 commit 4ac556b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ export function markAsyncChunksNonInitial(
.flatMap((entryPoint) => entryPoints[entryPoint.bundleName].chunks);

// Find chunks for each ID.
const asyncChunks = asyncChunkIds
.map((chunkId) => {
const chunk = chunks.find((chunk) => chunk.id === chunkId);
if (!chunk) {
throw new Error(`Failed to find chunk (${chunkId}) in set:\n${JSON.stringify(chunks)}`);
}
const asyncChunks = asyncChunkIds.map((chunkId) => {
const chunk = chunks.find((chunk) => chunk.id === chunkId);
if (!chunk) {
throw new Error(`Failed to find chunk (${chunkId}) in set:\n${JSON.stringify(chunks)}`);
}

return chunk;
})
// All Webpack chunks are dependent on `runtime`, which is never an async
// entry point, simply ignore this one.
.filter((chunk) => !!chunk.names?.includes('runtime'));
return chunk;
});

// A chunk is considered `initial` only if Webpack already belives it to be initial
// and the application developer did not mark it async via an extra entry point.
Expand Down

This file was deleted.

11 changes: 8 additions & 3 deletions tests/legacy-cli/e2e/tests/basic/styles-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expectFileToMatch, writeMultipleFiles } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';

export default async function() {
export default async function () {
await writeMultipleFiles({
'src/string-style.css': '.string-style { color: red }',
'src/input-style.css': '.input-style { color: red }',
Expand All @@ -12,7 +12,7 @@ export default async function() {
'src/pre-rename-lazy-style.css': '.pre-rename-lazy-style { color: red }',
});

await updateJsonFile('angular.json', workspaceJson => {
await updateJsonFile('angular.json', (workspaceJson) => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect.build.options.styles = [
{ input: 'src/string-style.css' },
Expand All @@ -27,7 +27,7 @@ export default async function() {
];
});

await ng('build', '--extract-css', '--configuration=development');
const { stdout } = await ng('build', '--extract-css', '--configuration=development');

await expectFileToMatch('dist/test-project/styles.css', '.string-style');
await expectFileToMatch('dist/test-project/styles.css', '.input-style');
Expand All @@ -41,4 +41,9 @@ export default async function() {
<link rel="stylesheet" href="renamed-style.css">
`,
);

// Non injected styles should be listed under lazy chunk files
if (!/Lazy Chunk Files.*\srenamed-lazy-style\.css/m.test(stdout)) {
throw new Error(`Expected "renamed-lazy-style.css" to be listed under "Lazy Chunk Files".`);
}
}

0 comments on commit 4ac556b

Please sign in to comment.