diff --git a/packages/schematics/angular/migrations/update-6/index.ts b/packages/schematics/angular/migrations/update-6/index.ts index 83a8235950..16f6e43320 100644 --- a/packages/schematics/angular/migrations/update-6/index.ts +++ b/packages/schematics/angular/migrations/update-6/index.ts @@ -6,6 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ import { + JsonArray, JsonObject, JsonParseMode, Path, @@ -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}`, diff --git a/packages/schematics/angular/migrations/update-6/index_spec.ts b/packages/schematics/angular/migrations/update-6/index_spec.ts index efa4eb2083..7d53cee269 100644 --- a/packages/schematics/angular/migrations/update-6/index_spec.ts +++ b/packages/schematics/angular/migrations/update-6/index_spec.ts @@ -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', () => { diff --git a/packages/schematics/angular/utility/config.ts b/packages/schematics/angular/utility/config.ts index 90d2a2de3f..730427963c 100644 --- a/packages/schematics/angular/utility/config.ts +++ b/packages/schematics/angular/utility/config.ts @@ -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 {