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

fix(@schematics/angular): Add budget configuration to update logic #843

Merged
merged 1 commit into from
May 8, 2018
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
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