Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Commit

Permalink
fix(@schematics/angular): Add budget configuration to update logic
Browse files Browse the repository at this point in the history
fixes #10616
  • Loading branch information
Brocco authored and hansl committed May 9, 2018
1 parent 9665df7 commit 9d2f636
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/schematics/angular/migrations/update-6/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {
JsonArray,
JsonObject,
JsonParseMode,
Path,
Expand Down Expand Up @@ -327,6 +328,7 @@ function extractProjectsConfig(config: CliConfig, tree: Tree): JsonObject {
: {}
),
...(isProduction && swConfig ? swConfig : {}),
...(isProduction && app.budgets ? { budgets: app.budgets as JsonArray } : {}),
fileReplacements: [
{
replace: `${app.root}/${source}`,
Expand Down
17 changes: 17 additions & 0 deletions packages/schematics/angular/migrations/update-6/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,23 @@ describe('Migration to v6', () => {
.toEqual(['src/tsconfig.app.json', 'src/tsconfig.spec.json']);
expect(tslint.options.exclude).toEqual([ '**/node_modules/**' ]);
});

it('should set the budgets configuration', () => {
baseConfig.apps[0].budgets = [{
type: 'bundle',
name: 'main',
error: '123kb',
}];

tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const config = getConfig(tree);
const budgets = config.projects.foo.architect.build.configurations.production.budgets;
expect(budgets.length).toEqual(1);
expect(budgets[0].type).toEqual('bundle');
expect(budgets[0].name).toEqual('main');
expect(budgets[0].error).toEqual('123kb');
});
});

describe('e2e projects', () => {
Expand Down
38 changes: 38 additions & 0 deletions packages/schematics/angular/utility/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,44 @@ export interface AppConfig {
app: string;
route: string;
};
budgets?: {
/**
* The type of budget
*/
type?: ('bundle' | 'initial' | 'allScript' | 'all' | 'anyScript' | 'any');
/**
* The name of the bundle
*/
name?: string;
/**
* The baseline size for comparison.
*/
baseline?: string;
/**
* The maximum threshold for warning relative to the baseline.
*/
maximumWarning?: string;
/**
* The maximum threshold for error relative to the baseline.
*/
maximumError?: string;
/**
* The minimum threshold for warning relative to the baseline.
*/
minimumWarning?: string;
/**
* The minimum threshold for error relative to the baseline.
*/
minimumError?: string;
/**
* The threshold for warning relative to the baseline (min & max).
*/
warning?: string;
/**
* The threshold for error relative to the baseline (min & max).
*/
error?: string;
}[];
}

export interface CliConfig {
Expand Down

0 comments on commit 9d2f636

Please sign in to comment.