[6a3a178] | 1 | "use strict";
|
---|
| 2 | /**
|
---|
| 3 | * @license
|
---|
| 4 | * Copyright Google LLC All Rights Reserved.
|
---|
| 5 | *
|
---|
| 6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 7 | * found in the LICENSE file at https://angular.io/license
|
---|
| 8 | */
|
---|
| 9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 10 | exports.updateWorkspaceConfig = exports.ANY_COMPONENT_STYLE_BUDGET = void 0;
|
---|
| 11 | const workspace_1 = require("../../utility/workspace");
|
---|
| 12 | const workspace_models_1 = require("../../utility/workspace-models");
|
---|
| 13 | const utils_1 = require("./utils");
|
---|
| 14 | exports.ANY_COMPONENT_STYLE_BUDGET = {
|
---|
| 15 | type: 'anyComponentStyle',
|
---|
| 16 | maximumWarning: '6kb',
|
---|
| 17 | };
|
---|
| 18 | function updateWorkspaceConfig() {
|
---|
| 19 | return (tree) => workspace_1.updateWorkspace((workspace) => {
|
---|
| 20 | for (const [targetName, target] of workspace_1.allWorkspaceTargets(workspace)) {
|
---|
| 21 | switch (targetName) {
|
---|
| 22 | case 'build':
|
---|
| 23 | if (target.builder !== workspace_models_1.Builders.Browser) {
|
---|
| 24 | break;
|
---|
| 25 | }
|
---|
| 26 | updateStyleOrScriptOption('styles', target);
|
---|
| 27 | updateStyleOrScriptOption('scripts', target);
|
---|
| 28 | addAnyComponentStyleBudget(target);
|
---|
| 29 | updateAotOption(tree, target);
|
---|
| 30 | break;
|
---|
| 31 | case 'test':
|
---|
| 32 | if (target.builder !== workspace_models_1.Builders.Karma) {
|
---|
| 33 | break;
|
---|
| 34 | }
|
---|
| 35 | updateStyleOrScriptOption('styles', target);
|
---|
| 36 | updateStyleOrScriptOption('scripts', target);
|
---|
| 37 | break;
|
---|
| 38 | case 'server':
|
---|
| 39 | if (target.builder !== workspace_models_1.Builders.Server) {
|
---|
| 40 | break;
|
---|
| 41 | }
|
---|
| 42 | updateOptimizationOption(target);
|
---|
| 43 | break;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | });
|
---|
| 47 | }
|
---|
| 48 | exports.updateWorkspaceConfig = updateWorkspaceConfig;
|
---|
| 49 | function updateAotOption(tree, builderConfig) {
|
---|
| 50 | if (!builderConfig.options) {
|
---|
| 51 | return;
|
---|
| 52 | }
|
---|
| 53 | const tsConfig = builderConfig.options.tsConfig;
|
---|
| 54 | // Do not add aot option if the users already opted out from Ivy
|
---|
| 55 | if (tsConfig && typeof tsConfig === 'string' && !utils_1.isIvyEnabled(tree, tsConfig)) {
|
---|
| 56 | return;
|
---|
| 57 | }
|
---|
| 58 | // Add aot to options
|
---|
| 59 | const aotOption = builderConfig.options.aot;
|
---|
| 60 | if (aotOption === undefined || aotOption === false) {
|
---|
| 61 | builderConfig.options.aot = true;
|
---|
| 62 | }
|
---|
| 63 | if (!builderConfig.configurations) {
|
---|
| 64 | return;
|
---|
| 65 | }
|
---|
| 66 | for (const configurationOptions of Object.values(builderConfig.configurations)) {
|
---|
| 67 | configurationOptions === null || configurationOptions === void 0 ? true : delete configurationOptions.aot;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | function updateStyleOrScriptOption(property, builderConfig) {
|
---|
| 71 | for (const [, options] of workspace_1.allTargetOptions(builderConfig)) {
|
---|
| 72 | const propertyOption = options[property];
|
---|
| 73 | if (!propertyOption || !Array.isArray(propertyOption)) {
|
---|
| 74 | continue;
|
---|
| 75 | }
|
---|
| 76 | for (const node of propertyOption) {
|
---|
| 77 | if (!node || typeof node !== 'object' || Array.isArray(node)) {
|
---|
| 78 | // skip non complex objects
|
---|
| 79 | continue;
|
---|
| 80 | }
|
---|
| 81 | const lazy = node.lazy;
|
---|
| 82 | if (lazy !== undefined) {
|
---|
| 83 | delete node.lazy;
|
---|
| 84 | // if lazy was not true, it is redundant hence, don't add it
|
---|
| 85 | if (lazy) {
|
---|
| 86 | node.inject = false;
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | function addAnyComponentStyleBudget(builderConfig) {
|
---|
| 93 | for (const [, options] of workspace_1.allTargetOptions(builderConfig, /* skipBaseOptions */ true)) {
|
---|
| 94 | if (options.budgets === undefined) {
|
---|
| 95 | options.budgets = [exports.ANY_COMPONENT_STYLE_BUDGET];
|
---|
| 96 | continue;
|
---|
| 97 | }
|
---|
| 98 | if (!Array.isArray(options.budgets)) {
|
---|
| 99 | continue;
|
---|
| 100 | }
|
---|
| 101 | // If 'anyComponentStyle' budget already exists, don't add
|
---|
| 102 | const hasAnyComponentStyle = options.budgets.some((node) => {
|
---|
| 103 | if (!node || typeof node !== 'object' || Array.isArray(node)) {
|
---|
| 104 | // skip non complex objects
|
---|
| 105 | return false;
|
---|
| 106 | }
|
---|
| 107 | return node.type === 'anyComponentStyle';
|
---|
| 108 | });
|
---|
| 109 | if (!hasAnyComponentStyle) {
|
---|
| 110 | options.budgets.push(exports.ANY_COMPONENT_STYLE_BUDGET);
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | function updateOptimizationOption(builderConfig) {
|
---|
| 115 | for (const [, options] of workspace_1.allTargetOptions(builderConfig, /* skipBaseOptions */ true)) {
|
---|
| 116 | if (options.optimization !== true) {
|
---|
| 117 | options.optimization = true;
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|