Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 9d2f636

Browse files
Broccohansl
authored andcommitted
fix(@schematics/angular): Add budget configuration to update logic
fixes #10616
1 parent 9665df7 commit 9d2f636

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

packages/schematics/angular/migrations/update-6/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {
9+
JsonArray,
910
JsonObject,
1011
JsonParseMode,
1112
Path,
@@ -327,6 +328,7 @@ function extractProjectsConfig(config: CliConfig, tree: Tree): JsonObject {
327328
: {}
328329
),
329330
...(isProduction && swConfig ? swConfig : {}),
331+
...(isProduction && app.budgets ? { budgets: app.budgets as JsonArray } : {}),
330332
fileReplacements: [
331333
{
332334
replace: `${app.root}/${source}`,

packages/schematics/angular/migrations/update-6/index_spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,23 @@ describe('Migration to v6', () => {
602602
.toEqual(['src/tsconfig.app.json', 'src/tsconfig.spec.json']);
603603
expect(tslint.options.exclude).toEqual([ '**/node_modules/**' ]);
604604
});
605+
606+
it('should set the budgets configuration', () => {
607+
baseConfig.apps[0].budgets = [{
608+
type: 'bundle',
609+
name: 'main',
610+
error: '123kb',
611+
}];
612+
613+
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
614+
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
615+
const config = getConfig(tree);
616+
const budgets = config.projects.foo.architect.build.configurations.production.budgets;
617+
expect(budgets.length).toEqual(1);
618+
expect(budgets[0].type).toEqual('bundle');
619+
expect(budgets[0].name).toEqual('main');
620+
expect(budgets[0].error).toEqual('123kb');
621+
});
605622
});
606623

607624
describe('e2e projects', () => {

packages/schematics/angular/utility/config.ts

+38
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,44 @@ export interface AppConfig {
126126
app: string;
127127
route: string;
128128
};
129+
budgets?: {
130+
/**
131+
* The type of budget
132+
*/
133+
type?: ('bundle' | 'initial' | 'allScript' | 'all' | 'anyScript' | 'any');
134+
/**
135+
* The name of the bundle
136+
*/
137+
name?: string;
138+
/**
139+
* The baseline size for comparison.
140+
*/
141+
baseline?: string;
142+
/**
143+
* The maximum threshold for warning relative to the baseline.
144+
*/
145+
maximumWarning?: string;
146+
/**
147+
* The maximum threshold for error relative to the baseline.
148+
*/
149+
maximumError?: string;
150+
/**
151+
* The minimum threshold for warning relative to the baseline.
152+
*/
153+
minimumWarning?: string;
154+
/**
155+
* The minimum threshold for error relative to the baseline.
156+
*/
157+
minimumError?: string;
158+
/**
159+
* The threshold for warning relative to the baseline (min & max).
160+
*/
161+
warning?: string;
162+
/**
163+
* The threshold for error relative to the baseline (min & max).
164+
*/
165+
error?: string;
166+
}[];
129167
}
130168

131169
export interface CliConfig {

0 commit comments

Comments
 (0)