-
Notifications
You must be signed in to change notification settings - Fork 11.9k
feat(@angular/build): Support splitting browser and server stats jsonfiles for easier consumption #32989
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
Open
tsteuwer-accesso
wants to merge
12
commits into
angular:main
Choose a base branch
from
tsteuwer-accesso:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(@angular/build): Support splitting browser and server stats jsonfiles for easier consumption #32989
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9545676
feat(@angular/build): Support splitting browser and server stats json…
tsteuwer-accesso 24c509f
fix(@angular/build): Fixing the missing browser initial stats file th…
tsteuwer-accesso eab4b3a
Reverting these changes per Alans recommendation
tsteuwer-accesso dd80e0f
type(fix)
tsteuwer-accesso 72ef689
Updating per code review instructions and adding more unit tests
tsteuwer-accesso 7e770b0
Revert "Updating per code review instructions and adding more unit te…
tsteuwer-accesso 00d9d60
Revert "type(fix)"
tsteuwer-accesso 8d5d1c3
Revert "Reverting these changes per Alans recommendation"
tsteuwer-accesso 6f7da7f
Revert "fix(@angular/build): Fixing the missing browser initial stats…
tsteuwer-accesso f1d1a88
Revert "feat(@angular/build): Support splitting browser and server st…
tsteuwer-accesso b62ea5d
Updating changes to be more inline with the code review requests. Rev…
tsteuwer-accesso 41219f3
Adding unit tests
tsteuwer-accesso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
185 changes: 185 additions & 0 deletions
185
packages/angular/build/src/builders/application/tests/options/stats-json_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import { buildApplication } from '../../index'; | ||
| import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; | ||
|
|
||
| /** Minimal subset of an esbuild metafile used by stats assertions. */ | ||
| interface StatsMetafile { | ||
| inputs: Record<string, unknown>; | ||
| outputs: Record<string, { inputs: Record<string, unknown> }>; | ||
| } | ||
|
|
||
| describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { | ||
| describe('Option: "statsJson"', () => { | ||
| describe('browser-only build', () => { | ||
| beforeEach(() => { | ||
| harness.useTarget('build', { | ||
| ...BASE_OPTIONS, | ||
| statsJson: true, | ||
| }); | ||
| }); | ||
|
|
||
| it('generates browser-stats.json and browser-initial-stats.json', async () => { | ||
| const { result } = await harness.executeOnce(); | ||
|
|
||
| expect(result?.success).toBeTrue(); | ||
| harness.expectFile('dist/browser-stats.json').toExist(); | ||
| harness.expectFile('dist/browser-initial-stats.json').toExist(); | ||
| }); | ||
|
|
||
| it('does not generate server stats files when SSR is disabled', async () => { | ||
| const { result } = await harness.executeOnce(); | ||
|
|
||
| expect(result?.success).toBeTrue(); | ||
| harness.expectFile('dist/server-stats.json').toNotExist(); | ||
| harness.expectFile('dist/server-initial-stats.json').toNotExist(); | ||
| }); | ||
|
|
||
| it('does not generate the legacy stats.json file', async () => { | ||
| const { result } = await harness.executeOnce(); | ||
|
|
||
| expect(result?.success).toBeTrue(); | ||
| harness.expectFile('dist/stats.json').toNotExist(); | ||
| }); | ||
|
|
||
| it('stats files contain valid esbuild metafile structure', async () => { | ||
| const { result } = await harness.executeOnce(); | ||
|
|
||
| expect(result?.success).toBeTrue(); | ||
|
|
||
| for (const filename of ['dist/browser-stats.json', 'dist/browser-initial-stats.json']) { | ||
| const stats = JSON.parse(harness.readFile(filename)) as StatsMetafile; | ||
| expect(stats.inputs).withContext(`${filename} must have an inputs field`).toBeDefined(); | ||
| expect(stats.outputs).withContext(`${filename} must have an outputs field`).toBeDefined(); | ||
| } | ||
| }); | ||
|
|
||
| it('output paths do not overlap between browser-stats.json and browser-initial-stats.json', async () => { | ||
| const { result } = await harness.executeOnce(); | ||
|
|
||
| expect(result?.success).toBeTrue(); | ||
|
|
||
| const nonInitialPaths = new Set( | ||
| Object.keys( | ||
| (JSON.parse(harness.readFile('dist/browser-stats.json')) as StatsMetafile).outputs, | ||
| ), | ||
| ); | ||
| const initialPaths = Object.keys( | ||
| (JSON.parse(harness.readFile('dist/browser-initial-stats.json')) as StatsMetafile) | ||
| .outputs, | ||
| ); | ||
|
|
||
| for (const outputPath of initialPaths) { | ||
| expect(nonInitialPaths.has(outputPath)) | ||
| .withContext(`Output '${outputPath}' must not appear in both stats files`) | ||
| .toBeFalse(); | ||
| } | ||
| }); | ||
|
|
||
| it('inputs in each stats file are only those referenced by included outputs', async () => { | ||
| const { result } = await harness.executeOnce(); | ||
|
|
||
| expect(result?.success).toBeTrue(); | ||
|
|
||
| for (const filename of ['dist/browser-stats.json', 'dist/browser-initial-stats.json']) { | ||
| const stats = JSON.parse(harness.readFile(filename)) as StatsMetafile; | ||
| const referencedInputs = new Set( | ||
| Object.values(stats.outputs).flatMap((output) => Object.keys(output.inputs)), | ||
| ); | ||
|
|
||
| for (const inputPath of Object.keys(stats.inputs)) { | ||
| expect(referencedInputs.has(inputPath)) | ||
| .withContext( | ||
| `Input '${inputPath}' in '${filename}' is not referenced by any included output`, | ||
| ) | ||
| .toBeTrue(); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe('when statsJson is false', () => { | ||
| it('does not generate any stats files', async () => { | ||
| harness.useTarget('build', { | ||
| ...BASE_OPTIONS, | ||
| statsJson: false, | ||
| }); | ||
|
|
||
| const { result } = await harness.executeOnce(); | ||
|
|
||
| expect(result?.success).toBeTrue(); | ||
| harness.expectFile('dist/browser-stats.json').toNotExist(); | ||
| harness.expectFile('dist/browser-initial-stats.json').toNotExist(); | ||
| harness.expectFile('dist/stats.json').toNotExist(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('SSR build', () => { | ||
| beforeEach(async () => { | ||
| await harness.modifyFile('src/tsconfig.app.json', (content) => { | ||
| const tsConfig = JSON.parse(content) as { files?: string[] }; | ||
| tsConfig.files ??= []; | ||
| tsConfig.files.push('main.server.ts'); | ||
|
|
||
| return JSON.stringify(tsConfig); | ||
| }); | ||
|
|
||
| harness.useTarget('build', { | ||
| ...BASE_OPTIONS, | ||
| statsJson: true, | ||
| server: 'src/main.server.ts', | ||
| ssr: true, | ||
| }); | ||
| }); | ||
|
|
||
| it('generates all four stats files', async () => { | ||
| const { result } = await harness.executeOnce(); | ||
|
|
||
| expect(result?.success).toBeTrue(); | ||
| harness.expectFile('dist/browser-stats.json').toExist(); | ||
| harness.expectFile('dist/browser-initial-stats.json').toExist(); | ||
| harness.expectFile('dist/server-stats.json').toExist(); | ||
| harness.expectFile('dist/server-initial-stats.json').toExist(); | ||
| }); | ||
|
|
||
| it('server stats files contain valid esbuild metafile structure', async () => { | ||
| const { result } = await harness.executeOnce(); | ||
|
|
||
| expect(result?.success).toBeTrue(); | ||
|
|
||
| for (const filename of ['dist/server-stats.json', 'dist/server-initial-stats.json']) { | ||
| const stats = JSON.parse(harness.readFile(filename)) as StatsMetafile; | ||
| expect(stats.inputs).withContext(`${filename} must have an inputs field`).toBeDefined(); | ||
| expect(stats.outputs).withContext(`${filename} must have an outputs field`).toBeDefined(); | ||
| } | ||
| }); | ||
|
|
||
| it('server output paths do not overlap between server-stats.json and server-initial-stats.json', async () => { | ||
| const { result } = await harness.executeOnce(); | ||
|
|
||
| expect(result?.success).toBeTrue(); | ||
|
|
||
| const nonInitialPaths = new Set( | ||
| Object.keys( | ||
| (JSON.parse(harness.readFile('dist/server-stats.json')) as StatsMetafile).outputs, | ||
| ), | ||
| ); | ||
| const initialPaths = Object.keys( | ||
| (JSON.parse(harness.readFile('dist/server-initial-stats.json')) as StatsMetafile).outputs, | ||
| ); | ||
|
|
||
| for (const outputPath of initialPaths) { | ||
| expect(nonInitialPaths.has(outputPath)) | ||
| .withContext(`Output '${outputPath}' must not appear in both server stats files`) | ||
| .toBeFalse(); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.