@angular-devkit/build-angular 18.0.0-next.3 → 18.0.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builders.json +1 -5
- package/package.json +14 -13
- package/src/builders/app-shell/index.js +3 -5
- package/src/builders/browser/index.d.ts +1 -1
- package/src/builders/browser/index.js +8 -12
- package/src/builders/browser-esbuild/index.d.ts +2 -2
- package/src/builders/browser-esbuild/index.js +6 -9
- package/src/builders/dev-server/builder.d.ts +2 -2
- package/src/builders/dev-server/builder.js +11 -6
- package/src/builders/dev-server/index.d.ts +1 -1
- package/src/builders/dev-server/webpack-server.d.ts +1 -1
- package/src/builders/dev-server/webpack-server.js +3 -4
- package/src/builders/extract-i18n/application-extraction.js +2 -2
- package/src/builders/extract-i18n/builder.js +3 -4
- package/src/builders/extract-i18n/options.d.ts +1 -1
- package/src/builders/extract-i18n/options.js +2 -2
- package/src/builders/jest/index.js +2 -2
- package/src/builders/karma/index.js +3 -4
- package/src/builders/ng-packagr/index.js +8 -7
- package/src/builders/ng-packagr/schema.d.ts +4 -0
- package/src/builders/ng-packagr/schema.json +4 -0
- package/src/builders/prerender/index.js +2 -2
- package/src/builders/prerender/render-worker.js +1 -1
- package/src/builders/server/index.js +3 -4
- package/src/builders/server/platform-server-exports-loader.js +2 -1
- package/src/builders/ssr-dev-server/index.js +7 -7
- package/src/builders/web-test-runner/index.js +2 -2
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -2
- package/src/tools/babel/presets/application.js +1 -1
- package/src/tools/webpack/configs/styles.js +2 -2
- package/src/tools/webpack/plugins/any-component-style-budget-checker.d.ts +1 -1
- package/src/tools/webpack/plugins/any-component-style-budget-checker.js +5 -5
- package/src/tools/webpack/plugins/css-optimizer-plugin.js +2 -2
- package/src/tools/webpack/plugins/index-html-webpack-plugin.d.ts +1 -1
- package/src/tools/webpack/plugins/index-html-webpack-plugin.js +2 -2
- package/src/tools/webpack/plugins/javascript-optimizer-plugin.js +2 -2
- package/src/tools/webpack/plugins/service-worker-plugin.js +2 -2
- package/src/tools/webpack/utils/stats.d.ts +1 -1
- package/src/tools/webpack/utils/stats.js +2 -2
- package/src/utils/i18n-webpack.d.ts +1 -1
- package/src/utils/i18n-webpack.js +5 -6
- package/src/utils/index.d.ts +1 -2
- package/src/utils/index.js +4 -2
- package/src/utils/normalize-builder-schema.js +2 -2
- package/src/utils/normalize-cache.js +1 -1
- package/src/utils/normalize-optimization.d.ts +1 -1
- package/src/utils/normalize-optimization.js +0 -2
- package/src/builders/application/build-action.d.ts +0 -33
- package/src/builders/application/build-action.js +0 -183
- package/src/builders/application/execute-build.d.ts +0 -11
- package/src/builders/application/execute-build.js +0 -125
- package/src/builders/application/execute-post-bundle.d.ts +0 -25
- package/src/builders/application/execute-post-bundle.js +0 -93
- package/src/builders/application/i18n.d.ts +0 -29
- package/src/builders/application/i18n.js +0 -128
- package/src/builders/application/index.d.ts +0 -57
- package/src/builders/application/index.js +0 -121
- package/src/builders/application/options.d.ts +0 -149
- package/src/builders/application/options.js +0 -369
- package/src/builders/application/schema.d.ts +0 -512
- package/src/builders/application/schema.js +0 -58
- package/src/builders/application/schema.json +0 -635
- package/src/builders/application/setup-bundling.d.ts +0 -19
- package/src/builders/application/setup-bundling.js +0 -71
- package/src/builders/dev-server/vite-server.d.ts +0 -30
- package/src/builders/dev-server/vite-server.js +0 -502
- package/src/tools/babel/plugins/adjust-static-class-members.d.ts +0 -27
- package/src/tools/babel/plugins/adjust-static-class-members.js +0 -351
- package/src/tools/babel/plugins/adjust-typescript-enums.d.ts +0 -23
- package/src/tools/babel/plugins/adjust-typescript-enums.js +0 -113
- package/src/tools/babel/plugins/elide-angular-metadata.d.ts +0 -23
- package/src/tools/babel/plugins/elide-angular-metadata.js +0 -110
- package/src/tools/babel/plugins/index.d.ts +0 -11
- package/src/tools/babel/plugins/index.js +0 -21
- package/src/tools/babel/plugins/pure-toplevel-functions.d.ts +0 -16
- package/src/tools/babel/plugins/pure-toplevel-functions.js +0 -90
- package/src/tools/esbuild/angular/angular-host.d.ts +0 -26
- package/src/tools/esbuild/angular/angular-host.js +0 -72
- package/src/tools/esbuild/angular/compilation/angular-compilation.d.ts +0 -42
- package/src/tools/esbuild/angular/compilation/angular-compilation.js +0 -94
- package/src/tools/esbuild/angular/compilation/aot-compilation.d.ts +0 -21
- package/src/tools/esbuild/angular/compilation/aot-compilation.js +0 -228
- package/src/tools/esbuild/angular/compilation/factory.d.ts +0 -16
- package/src/tools/esbuild/angular/compilation/factory.js +0 -56
- package/src/tools/esbuild/angular/compilation/index.d.ts +0 -10
- package/src/tools/esbuild/angular/compilation/index.js +0 -17
- package/src/tools/esbuild/angular/compilation/jit-compilation.d.ts +0 -21
- package/src/tools/esbuild/angular/compilation/jit-compilation.js +0 -106
- package/src/tools/esbuild/angular/compilation/noop-compilation.d.ts +0 -20
- package/src/tools/esbuild/angular/compilation/noop-compilation.js +0 -26
- package/src/tools/esbuild/angular/compilation/parallel-compilation.d.ts +0 -42
- package/src/tools/esbuild/angular/compilation/parallel-compilation.js +0 -123
- package/src/tools/esbuild/angular/compilation/parallel-worker.d.ts +0 -33
- package/src/tools/esbuild/angular/compilation/parallel-worker.js +0 -90
- package/src/tools/esbuild/angular/compilation-state.d.ts +0 -15
- package/src/tools/esbuild/angular/compilation-state.js +0 -44
- package/src/tools/esbuild/angular/compiler-plugin.d.ts +0 -27
- package/src/tools/esbuild/angular/compiler-plugin.js +0 -441
- package/src/tools/esbuild/angular/component-stylesheets.d.ts +0 -44
- package/src/tools/esbuild/angular/component-stylesheets.js +0 -150
- package/src/tools/esbuild/angular/diagnostics.d.ts +0 -15
- package/src/tools/esbuild/angular/diagnostics.js +0 -69
- package/src/tools/esbuild/angular/file-reference-tracker.d.ts +0 -17
- package/src/tools/esbuild/angular/file-reference-tracker.js +0 -57
- package/src/tools/esbuild/angular/jit-plugin-callbacks.d.ts +0 -23
- package/src/tools/esbuild/angular/jit-plugin-callbacks.js +0 -117
- package/src/tools/esbuild/angular/jit-resource-transformer.d.ts +0 -17
- package/src/tools/esbuild/angular/jit-resource-transformer.js +0 -186
- package/src/tools/esbuild/angular/source-file-cache.d.ts +0 -18
- package/src/tools/esbuild/angular/source-file-cache.js +0 -65
- package/src/tools/esbuild/angular/uri.d.ts +0 -54
- package/src/tools/esbuild/angular/uri.js +0 -74
- package/src/tools/esbuild/angular/web-worker-transformer.d.ts +0 -17
- package/src/tools/esbuild/angular/web-worker-transformer.js +0 -94
- package/src/tools/esbuild/application-code-bundle.d.ts +0 -20
- package/src/tools/esbuild/application-code-bundle.js +0 -368
- package/src/tools/esbuild/budget-stats.d.ts +0 -19
- package/src/tools/esbuild/budget-stats.js +0 -59
- package/src/tools/esbuild/bundler-context.d.ts +0 -75
- package/src/tools/esbuild/bundler-context.js +0 -366
- package/src/tools/esbuild/bundler-execution-result.d.ts +0 -71
- package/src/tools/esbuild/bundler-execution-result.js +0 -131
- package/src/tools/esbuild/cache.d.ts +0 -88
- package/src/tools/esbuild/cache.js +0 -92
- package/src/tools/esbuild/commonjs-checker.d.ts +0 -28
- package/src/tools/esbuild/commonjs-checker.js +0 -151
- package/src/tools/esbuild/compiler-plugin-options.d.ts +0 -16
- package/src/tools/esbuild/compiler-plugin-options.js +0 -49
- package/src/tools/esbuild/external-packages-plugin.d.ts +0 -18
- package/src/tools/esbuild/external-packages-plugin.js +0 -70
- package/src/tools/esbuild/global-scripts.d.ts +0 -16
- package/src/tools/esbuild/global-scripts.js +0 -142
- package/src/tools/esbuild/global-styles.d.ts +0 -10
- package/src/tools/esbuild/global-styles.js +0 -74
- package/src/tools/esbuild/i18n-inliner-worker.d.ts +0 -42
- package/src/tools/esbuild/i18n-inliner-worker.js +0 -136
- package/src/tools/esbuild/i18n-inliner.d.ts +0 -44
- package/src/tools/esbuild/i18n-inliner.js +0 -150
- package/src/tools/esbuild/i18n-locale-plugin.d.ts +0 -22
- package/src/tools/esbuild/i18n-locale-plugin.js +0 -120
- package/src/tools/esbuild/index-html-generator.d.ts +0 -15
- package/src/tools/esbuild/index-html-generator.js +0 -81
- package/src/tools/esbuild/javascript-transformer-worker.d.ts +0 -19
- package/src/tools/esbuild/javascript-transformer-worker.js +0 -154
- package/src/tools/esbuild/javascript-transformer.d.ts +0 -54
- package/src/tools/esbuild/javascript-transformer.js +0 -147
- package/src/tools/esbuild/license-extractor.d.ts +0 -25
- package/src/tools/esbuild/license-extractor.js +0 -158
- package/src/tools/esbuild/load-result-cache.d.ts +0 -21
- package/src/tools/esbuild/load-result-cache.js +0 -75
- package/src/tools/esbuild/profiling.d.ts +0 -11
- package/src/tools/esbuild/profiling.js +0 -78
- package/src/tools/esbuild/rxjs-esm-resolution-plugin.d.ts +0 -18
- package/src/tools/esbuild/rxjs-esm-resolution-plugin.js +0 -44
- package/src/tools/esbuild/sourcemap-ignorelist-plugin.d.ts +0 -17
- package/src/tools/esbuild/sourcemap-ignorelist-plugin.js +0 -73
- package/src/tools/esbuild/stylesheets/bundle-options.d.ts +0 -35
- package/src/tools/esbuild/stylesheets/bundle-options.js +0 -64
- package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.d.ts +0 -25
- package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.js +0 -57
- package/src/tools/esbuild/stylesheets/css-language.d.ts +0 -9
- package/src/tools/esbuild/stylesheets/css-language.js +0 -15
- package/src/tools/esbuild/stylesheets/css-resource-plugin.d.ts +0 -18
- package/src/tools/esbuild/stylesheets/css-resource-plugin.js +0 -114
- package/src/tools/esbuild/stylesheets/less-language.d.ts +0 -9
- package/src/tools/esbuild/stylesheets/less-language.js +0 -155
- package/src/tools/esbuild/stylesheets/sass-language.d.ts +0 -10
- package/src/tools/esbuild/stylesheets/sass-language.js +0 -185
- package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.d.ts +0 -58
- package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.js +0 -282
- package/src/tools/esbuild/utils.d.ts +0 -41
- package/src/tools/esbuild/utils.js +0 -378
- package/src/tools/esbuild/virtual-module-plugin.d.ts +0 -33
- package/src/tools/esbuild/virtual-module-plugin.js +0 -43
- package/src/tools/esbuild/watcher.d.ts +0 -25
- package/src/tools/esbuild/watcher.js +0 -118
- package/src/tools/sass/lexer.d.ts +0 -18
- package/src/tools/sass/lexer.js +0 -161
- package/src/tools/sass/rebasing-importer.d.ts +0 -101
- package/src/tools/sass/rebasing-importer.js +0 -334
- package/src/tools/sass/sass-service.d.ts +0 -72
- package/src/tools/sass/sass-service.js +0 -213
- package/src/tools/sass/worker.d.ts +0 -8
- package/src/tools/sass/worker.js +0 -192
- package/src/tools/vite/angular-memory-plugin.d.ts +0 -24
- package/src/tools/vite/angular-memory-plugin.js +0 -268
- package/src/tools/vite/i18n-locale-plugin.d.ts +0 -18
- package/src/tools/vite/i18n-locale-plugin.js +0 -55
- package/src/typings.d.ts +0 -21
- package/src/utils/bundle-calculator.d.ts +0 -44
- package/src/utils/bundle-calculator.js +0 -303
- package/src/utils/check-port.d.ts +0 -8
- package/src/utils/check-port.js +0 -58
- package/src/utils/delete-output-dir.d.ts +0 -11
- package/src/utils/delete-output-dir.js +0 -46
- package/src/utils/format-bytes.d.ts +0 -8
- package/src/utils/format-bytes.js +0 -22
- package/src/utils/i18n-options.d.ts +0 -33
- package/src/utils/i18n-options.js +0 -161
- package/src/utils/index-file/add-event-dispatch-contract.d.ts +0 -8
- package/src/utils/index-file/add-event-dispatch-contract.js +0 -28
- package/src/utils/index-file/augment-index-html.d.ts +0 -40
- package/src/utils/index-file/augment-index-html.js +0 -239
- package/src/utils/index-file/html-rewriting-stream.d.ts +0 -11
- package/src/utils/index-file/html-rewriting-stream.js +0 -28
- package/src/utils/index-file/index-html-generator.d.ts +0 -57
- package/src/utils/index-file/index-html-generator.js +0 -135
- package/src/utils/index-file/inline-critical-css.d.ts +0 -24
- package/src/utils/index-file/inline-critical-css.js +0 -179
- package/src/utils/index-file/inline-fonts.d.ts +0 -23
- package/src/utils/index-file/inline-fonts.js +0 -267
- package/src/utils/index-file/nonce.d.ts +0 -12
- package/src/utils/index-file/nonce.js +0 -55
- package/src/utils/load-proxy-config.d.ts +0 -8
- package/src/utils/load-proxy-config.js +0 -189
- package/src/utils/load-translations.d.ts +0 -16
- package/src/utils/load-translations.js +0 -84
- package/src/utils/postcss-configuration.d.ts +0 -17
- package/src/utils/postcss-configuration.js +0 -86
- package/src/utils/purge-cache.d.ts +0 -10
- package/src/utils/purge-cache.js +0 -40
- package/src/utils/resolve-assets.d.ts +0 -18
- package/src/utils/resolve-assets.js +0 -35
- package/src/utils/routes-extractor/extractor.d.ts +0 -15
- package/src/utils/routes-extractor/extractor.js +0 -97
- package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.d.ts +0 -18
- package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +0 -129
- package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.d.ts +0 -8
- package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.js +0 -13
- package/src/utils/server-rendering/fetch-patch.d.ts +0 -8
- package/src/utils/server-rendering/fetch-patch.js +0 -66
- package/src/utils/server-rendering/load-esm-from-memory.d.ts +0 -10
- package/src/utils/server-rendering/load-esm-from-memory.js +0 -26
- package/src/utils/server-rendering/main-bundle-exports.d.ts +0 -27
- package/src/utils/server-rendering/main-bundle-exports.js +0 -9
- package/src/utils/server-rendering/prerender.d.ts +0 -23
- package/src/utils/server-rendering/prerender.js +0 -192
- package/src/utils/server-rendering/render-page.d.ts +0 -26
- package/src/utils/server-rendering/render-page.js +0 -110
- package/src/utils/server-rendering/render-worker.d.ts +0 -22
- package/src/utils/server-rendering/render-worker.js +0 -30
- package/src/utils/server-rendering/routes-extractor-worker.d.ts +0 -21
- package/src/utils/server-rendering/routes-extractor-worker.js +0 -53
- package/src/utils/service-worker.d.ts +0 -25
- package/src/utils/service-worker.js +0 -211
- package/src/utils/stats-table.d.ts +0 -20
- package/src/utils/stats-table.js +0 -205
- package/src/utils/supported-browsers.d.ts +0 -10
- package/src/utils/supported-browsers.js +0 -42
- package/src/utils/version.d.ts +0 -8
- package/src/utils/version.js +0 -59
|
@@ -1,303 +0,0 @@
|
|
|
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.checkThresholds = exports.checkBudgets = exports.calculateThresholds = exports.ThresholdSeverity = exports.BudgetType = void 0;
|
|
11
|
-
const schema_1 = require("../builders/application/schema");
|
|
12
|
-
Object.defineProperty(exports, "BudgetType", { enumerable: true, get: function () { return schema_1.Type; } });
|
|
13
|
-
const format_bytes_1 = require("./format-bytes");
|
|
14
|
-
var ThresholdType;
|
|
15
|
-
(function (ThresholdType) {
|
|
16
|
-
ThresholdType["Max"] = "maximum";
|
|
17
|
-
ThresholdType["Min"] = "minimum";
|
|
18
|
-
})(ThresholdType || (ThresholdType = {}));
|
|
19
|
-
var ThresholdSeverity;
|
|
20
|
-
(function (ThresholdSeverity) {
|
|
21
|
-
ThresholdSeverity["Warning"] = "warning";
|
|
22
|
-
ThresholdSeverity["Error"] = "error";
|
|
23
|
-
})(ThresholdSeverity || (exports.ThresholdSeverity = ThresholdSeverity = {}));
|
|
24
|
-
function* calculateThresholds(budget) {
|
|
25
|
-
if (budget.maximumWarning) {
|
|
26
|
-
yield {
|
|
27
|
-
limit: calculateBytes(budget.maximumWarning, budget.baseline, 1),
|
|
28
|
-
type: ThresholdType.Max,
|
|
29
|
-
severity: ThresholdSeverity.Warning,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (budget.maximumError) {
|
|
33
|
-
yield {
|
|
34
|
-
limit: calculateBytes(budget.maximumError, budget.baseline, 1),
|
|
35
|
-
type: ThresholdType.Max,
|
|
36
|
-
severity: ThresholdSeverity.Error,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if (budget.minimumWarning) {
|
|
40
|
-
yield {
|
|
41
|
-
limit: calculateBytes(budget.minimumWarning, budget.baseline, -1),
|
|
42
|
-
type: ThresholdType.Min,
|
|
43
|
-
severity: ThresholdSeverity.Warning,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
if (budget.minimumError) {
|
|
47
|
-
yield {
|
|
48
|
-
limit: calculateBytes(budget.minimumError, budget.baseline, -1),
|
|
49
|
-
type: ThresholdType.Min,
|
|
50
|
-
severity: ThresholdSeverity.Error,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
if (budget.warning) {
|
|
54
|
-
yield {
|
|
55
|
-
limit: calculateBytes(budget.warning, budget.baseline, -1),
|
|
56
|
-
type: ThresholdType.Min,
|
|
57
|
-
severity: ThresholdSeverity.Warning,
|
|
58
|
-
};
|
|
59
|
-
yield {
|
|
60
|
-
limit: calculateBytes(budget.warning, budget.baseline, 1),
|
|
61
|
-
type: ThresholdType.Max,
|
|
62
|
-
severity: ThresholdSeverity.Warning,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
if (budget.error) {
|
|
66
|
-
yield {
|
|
67
|
-
limit: calculateBytes(budget.error, budget.baseline, -1),
|
|
68
|
-
type: ThresholdType.Min,
|
|
69
|
-
severity: ThresholdSeverity.Error,
|
|
70
|
-
};
|
|
71
|
-
yield {
|
|
72
|
-
limit: calculateBytes(budget.error, budget.baseline, 1),
|
|
73
|
-
type: ThresholdType.Max,
|
|
74
|
-
severity: ThresholdSeverity.Error,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.calculateThresholds = calculateThresholds;
|
|
79
|
-
/**
|
|
80
|
-
* Calculates the sizes for bundles in the budget type provided.
|
|
81
|
-
*/
|
|
82
|
-
function calculateSizes(budget, stats) {
|
|
83
|
-
const calculatorMap = {
|
|
84
|
-
all: AllCalculator,
|
|
85
|
-
allScript: AllScriptCalculator,
|
|
86
|
-
any: AnyCalculator,
|
|
87
|
-
anyScript: AnyScriptCalculator,
|
|
88
|
-
anyComponentStyle: AnyComponentStyleCalculator,
|
|
89
|
-
bundle: BundleCalculator,
|
|
90
|
-
initial: InitialCalculator,
|
|
91
|
-
};
|
|
92
|
-
const ctor = calculatorMap[budget.type];
|
|
93
|
-
const { chunks, assets } = stats;
|
|
94
|
-
if (!chunks) {
|
|
95
|
-
throw new Error('Webpack stats output did not include chunk information.');
|
|
96
|
-
}
|
|
97
|
-
if (!assets) {
|
|
98
|
-
throw new Error('Webpack stats output did not include asset information.');
|
|
99
|
-
}
|
|
100
|
-
const calculator = new ctor(budget, chunks, assets);
|
|
101
|
-
return calculator.calculate();
|
|
102
|
-
}
|
|
103
|
-
class Calculator {
|
|
104
|
-
budget;
|
|
105
|
-
chunks;
|
|
106
|
-
assets;
|
|
107
|
-
constructor(budget, chunks, assets) {
|
|
108
|
-
this.budget = budget;
|
|
109
|
-
this.chunks = chunks;
|
|
110
|
-
this.assets = assets;
|
|
111
|
-
}
|
|
112
|
-
/** Calculates the size of the given chunk for the provided build type. */
|
|
113
|
-
calculateChunkSize(chunk) {
|
|
114
|
-
// No differential builds, get the chunk size by summing its assets.
|
|
115
|
-
if (!chunk.files) {
|
|
116
|
-
return 0;
|
|
117
|
-
}
|
|
118
|
-
return chunk.files
|
|
119
|
-
.filter((file) => !file.endsWith('.map'))
|
|
120
|
-
.map((file) => {
|
|
121
|
-
const asset = this.assets.find((asset) => asset.name === file);
|
|
122
|
-
if (!asset) {
|
|
123
|
-
throw new Error(`Could not find asset for file: ${file}`);
|
|
124
|
-
}
|
|
125
|
-
return asset.size;
|
|
126
|
-
})
|
|
127
|
-
.reduce((l, r) => l + r, 0);
|
|
128
|
-
}
|
|
129
|
-
getAssetSize(asset) {
|
|
130
|
-
return asset.size;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* A named bundle.
|
|
135
|
-
*/
|
|
136
|
-
class BundleCalculator extends Calculator {
|
|
137
|
-
calculate() {
|
|
138
|
-
const budgetName = this.budget.name;
|
|
139
|
-
if (!budgetName) {
|
|
140
|
-
return [];
|
|
141
|
-
}
|
|
142
|
-
const size = this.chunks
|
|
143
|
-
.filter((chunk) => chunk?.names?.includes(budgetName))
|
|
144
|
-
.map((chunk) => this.calculateChunkSize(chunk))
|
|
145
|
-
.reduce((l, r) => l + r, 0);
|
|
146
|
-
return [{ size, label: this.budget.name }];
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* The sum of all initial chunks (marked as initial).
|
|
151
|
-
*/
|
|
152
|
-
class InitialCalculator extends Calculator {
|
|
153
|
-
calculate() {
|
|
154
|
-
return [
|
|
155
|
-
{
|
|
156
|
-
label: `bundle initial`,
|
|
157
|
-
size: this.chunks
|
|
158
|
-
.filter((chunk) => chunk.initial)
|
|
159
|
-
.map((chunk) => this.calculateChunkSize(chunk))
|
|
160
|
-
.reduce((l, r) => l + r, 0),
|
|
161
|
-
},
|
|
162
|
-
];
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* The sum of all the scripts portions.
|
|
167
|
-
*/
|
|
168
|
-
class AllScriptCalculator extends Calculator {
|
|
169
|
-
calculate() {
|
|
170
|
-
const size = this.assets
|
|
171
|
-
.filter((asset) => asset.name.endsWith('.js'))
|
|
172
|
-
.map((asset) => this.getAssetSize(asset))
|
|
173
|
-
.reduce((total, size) => total + size, 0);
|
|
174
|
-
return [{ size, label: 'total scripts' }];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* All scripts and assets added together.
|
|
179
|
-
*/
|
|
180
|
-
class AllCalculator extends Calculator {
|
|
181
|
-
calculate() {
|
|
182
|
-
const size = this.assets
|
|
183
|
-
.filter((asset) => !asset.name.endsWith('.map'))
|
|
184
|
-
.map((asset) => this.getAssetSize(asset))
|
|
185
|
-
.reduce((total, size) => total + size, 0);
|
|
186
|
-
return [{ size, label: 'total' }];
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Any script, individually.
|
|
191
|
-
*/
|
|
192
|
-
class AnyScriptCalculator extends Calculator {
|
|
193
|
-
calculate() {
|
|
194
|
-
return this.assets
|
|
195
|
-
.filter((asset) => asset.name.endsWith('.js'))
|
|
196
|
-
.map((asset) => ({
|
|
197
|
-
size: this.getAssetSize(asset),
|
|
198
|
-
label: asset.name,
|
|
199
|
-
}));
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Any script or asset (images, css, etc).
|
|
204
|
-
*/
|
|
205
|
-
class AnyCalculator extends Calculator {
|
|
206
|
-
calculate() {
|
|
207
|
-
return this.assets
|
|
208
|
-
.filter((asset) => !asset.name.endsWith('.map'))
|
|
209
|
-
.map((asset) => ({
|
|
210
|
-
size: this.getAssetSize(asset),
|
|
211
|
-
label: asset.name,
|
|
212
|
-
}));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Any compoonent stylesheet
|
|
217
|
-
*/
|
|
218
|
-
class AnyComponentStyleCalculator extends Calculator {
|
|
219
|
-
calculate() {
|
|
220
|
-
return this.assets
|
|
221
|
-
.filter((asset) => asset.componentStyle)
|
|
222
|
-
.map((asset) => ({
|
|
223
|
-
size: this.getAssetSize(asset),
|
|
224
|
-
label: asset.name,
|
|
225
|
-
}));
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Calculate the bytes given a string value.
|
|
230
|
-
*/
|
|
231
|
-
function calculateBytes(input, baseline, factor = 1) {
|
|
232
|
-
const matches = input.trim().match(/^(\d+(?:\.\d+)?)[ \t]*(%|[kmg]?b)?$/i);
|
|
233
|
-
if (!matches) {
|
|
234
|
-
return NaN;
|
|
235
|
-
}
|
|
236
|
-
const baselineBytes = (baseline && calculateBytes(baseline)) || 0;
|
|
237
|
-
let value = Number(matches[1]);
|
|
238
|
-
switch (matches[2] && matches[2].toLowerCase()) {
|
|
239
|
-
case '%':
|
|
240
|
-
value = (baselineBytes * value) / 100;
|
|
241
|
-
break;
|
|
242
|
-
case 'kb':
|
|
243
|
-
value *= 1024;
|
|
244
|
-
break;
|
|
245
|
-
case 'mb':
|
|
246
|
-
value *= 1024 * 1024;
|
|
247
|
-
break;
|
|
248
|
-
case 'gb':
|
|
249
|
-
value *= 1024 * 1024 * 1024;
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
if (baselineBytes === 0) {
|
|
253
|
-
return value;
|
|
254
|
-
}
|
|
255
|
-
return baselineBytes + value * factor;
|
|
256
|
-
}
|
|
257
|
-
function* checkBudgets(budgets, stats, checkComponentStyles) {
|
|
258
|
-
// Ignore AnyComponentStyle budgets as these are handled in `AnyComponentStyleBudgetChecker` unless requested
|
|
259
|
-
const computableBudgets = checkComponentStyles
|
|
260
|
-
? budgets
|
|
261
|
-
: budgets.filter((budget) => budget.type !== schema_1.Type.AnyComponentStyle);
|
|
262
|
-
for (const budget of computableBudgets) {
|
|
263
|
-
const sizes = calculateSizes(budget, stats);
|
|
264
|
-
for (const { size, label } of sizes) {
|
|
265
|
-
yield* checkThresholds(calculateThresholds(budget), size, label);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
exports.checkBudgets = checkBudgets;
|
|
270
|
-
function* checkThresholds(thresholds, size, label) {
|
|
271
|
-
for (const threshold of thresholds) {
|
|
272
|
-
switch (threshold.type) {
|
|
273
|
-
case ThresholdType.Max: {
|
|
274
|
-
if (size <= threshold.limit) {
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
|
-
const sizeDifference = (0, format_bytes_1.formatSize)(size - threshold.limit);
|
|
278
|
-
yield {
|
|
279
|
-
severity: threshold.severity,
|
|
280
|
-
label,
|
|
281
|
-
message: `${label} exceeded maximum budget. Budget ${(0, format_bytes_1.formatSize)(threshold.limit)} was not met by ${sizeDifference} with a total of ${(0, format_bytes_1.formatSize)(size)}.`,
|
|
282
|
-
};
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
case ThresholdType.Min: {
|
|
286
|
-
if (size >= threshold.limit) {
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
const sizeDifference = (0, format_bytes_1.formatSize)(threshold.limit - size);
|
|
290
|
-
yield {
|
|
291
|
-
severity: threshold.severity,
|
|
292
|
-
label,
|
|
293
|
-
message: `${label} failed to meet minimum budget. Budget ${(0, format_bytes_1.formatSize)(threshold.limit)} was not met by ${sizeDifference} with a total of ${(0, format_bytes_1.formatSize)(size)}.`,
|
|
294
|
-
};
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
default: {
|
|
298
|
-
throw new Error(`Unexpected threshold type: ${ThresholdType[threshold.type]}`);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
exports.checkThresholds = checkThresholds;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
export declare function checkPort(port: number, host: string): Promise<number>;
|
package/src/utils/check-port.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.checkPort = void 0;
|
|
14
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
15
|
-
const node_net_1 = require("node:net");
|
|
16
|
-
const load_esm_1 = require("./load-esm");
|
|
17
|
-
const tty_1 = require("./tty");
|
|
18
|
-
function createInUseError(port) {
|
|
19
|
-
return new Error(`Port ${port} is already in use. Use '--port' to specify a different port.`);
|
|
20
|
-
}
|
|
21
|
-
async function checkPort(port, host) {
|
|
22
|
-
// Disabled due to Vite not handling port 0 and instead always using the default value (5173)
|
|
23
|
-
// TODO: Enable this again once Vite is fixed
|
|
24
|
-
// if (port === 0) {
|
|
25
|
-
// return 0;
|
|
26
|
-
// }
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
const server = (0, node_net_1.createServer)();
|
|
29
|
-
server
|
|
30
|
-
.once('error', (err) => {
|
|
31
|
-
if (err.code !== 'EADDRINUSE') {
|
|
32
|
-
reject(err);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if (!tty_1.isTTY) {
|
|
36
|
-
reject(createInUseError(port));
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
(0, load_esm_1.loadEsmModule)('inquirer')
|
|
40
|
-
.then(({ default: { prompt } }) => prompt({
|
|
41
|
-
type: 'confirm',
|
|
42
|
-
name: 'useDifferent',
|
|
43
|
-
message: `Port ${port} is already in use.\nWould you like to use a different port?`,
|
|
44
|
-
default: true,
|
|
45
|
-
}))
|
|
46
|
-
.then((answers) => answers.useDifferent ? resolve(checkPort(0, host)) : reject(createInUseError(port)), () => reject(createInUseError(port)));
|
|
47
|
-
})
|
|
48
|
-
.once('listening', () => {
|
|
49
|
-
// Get the actual address from the listening server instance
|
|
50
|
-
const address = server.address();
|
|
51
|
-
(0, node_assert_1.default)(address && typeof address !== 'string', 'Port check server address should always be an object.');
|
|
52
|
-
server.close();
|
|
53
|
-
resolve(address.port);
|
|
54
|
-
})
|
|
55
|
-
.listen(port, host);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
exports.checkPort = checkPort;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Delete an output directory, but error out if it's the root of the project.
|
|
10
|
-
*/
|
|
11
|
-
export declare function deleteOutputDir(root: string, outputPath: string, emptyOnlyDirectories?: string[]): Promise<void>;
|
|
@@ -1,46 +0,0 @@
|
|
|
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.deleteOutputDir = void 0;
|
|
11
|
-
const promises_1 = require("node:fs/promises");
|
|
12
|
-
const node_path_1 = require("node:path");
|
|
13
|
-
/**
|
|
14
|
-
* Delete an output directory, but error out if it's the root of the project.
|
|
15
|
-
*/
|
|
16
|
-
async function deleteOutputDir(root, outputPath, emptyOnlyDirectories) {
|
|
17
|
-
const resolvedOutputPath = (0, node_path_1.resolve)(root, outputPath);
|
|
18
|
-
if (resolvedOutputPath === root) {
|
|
19
|
-
throw new Error('Output path MUST not be project root directory!');
|
|
20
|
-
}
|
|
21
|
-
const directoriesToEmpty = emptyOnlyDirectories
|
|
22
|
-
? new Set(emptyOnlyDirectories.map((directory) => (0, node_path_1.join)(resolvedOutputPath, directory)))
|
|
23
|
-
: undefined;
|
|
24
|
-
// Avoid removing the actual directory to avoid errors in cases where the output
|
|
25
|
-
// directory is mounted or symlinked. Instead the contents are removed.
|
|
26
|
-
let entries;
|
|
27
|
-
try {
|
|
28
|
-
entries = await (0, promises_1.readdir)(resolvedOutputPath);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
for (const entry of entries) {
|
|
37
|
-
const fullEntry = (0, node_path_1.join)(resolvedOutputPath, entry);
|
|
38
|
-
// Leave requested directories. This allows symlinks to continue to function.
|
|
39
|
-
if (directoriesToEmpty?.has(fullEntry)) {
|
|
40
|
-
await deleteOutputDir(resolvedOutputPath, fullEntry);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
await (0, promises_1.rm)(fullEntry, { force: true, recursive: true, maxRetries: 3 });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.deleteOutputDir = deleteOutputDir;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
export declare function formatSize(size: number): string;
|
|
@@ -1,22 +0,0 @@
|
|
|
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.formatSize = void 0;
|
|
11
|
-
function formatSize(size) {
|
|
12
|
-
if (size <= 0) {
|
|
13
|
-
return '0 bytes';
|
|
14
|
-
}
|
|
15
|
-
const abbreviations = ['bytes', 'kB', 'MB', 'GB'];
|
|
16
|
-
const index = Math.floor(Math.log(size) / Math.log(1024));
|
|
17
|
-
const roundedSize = size / Math.pow(1024, index);
|
|
18
|
-
// bytes don't have a fraction
|
|
19
|
-
const fractionDigits = index === 0 ? 0 : 2;
|
|
20
|
-
return `${roundedSize.toFixed(fractionDigits)} ${abbreviations[index]}`;
|
|
21
|
-
}
|
|
22
|
-
exports.formatSize = formatSize;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import type { TranslationLoader } from './load-translations';
|
|
9
|
-
export interface LocaleDescription {
|
|
10
|
-
files: {
|
|
11
|
-
path: string;
|
|
12
|
-
integrity?: string;
|
|
13
|
-
format?: string;
|
|
14
|
-
}[];
|
|
15
|
-
translation?: Record<string, unknown>;
|
|
16
|
-
dataPath?: string;
|
|
17
|
-
baseHref?: string;
|
|
18
|
-
}
|
|
19
|
-
export interface I18nOptions {
|
|
20
|
-
inlineLocales: Set<string>;
|
|
21
|
-
sourceLocale: string;
|
|
22
|
-
locales: Record<string, LocaleDescription>;
|
|
23
|
-
flatOutput?: boolean;
|
|
24
|
-
readonly shouldInline: boolean;
|
|
25
|
-
hasDefinedSourceLocale?: boolean;
|
|
26
|
-
}
|
|
27
|
-
export declare function createI18nOptions(projectMetadata: {
|
|
28
|
-
i18n?: unknown;
|
|
29
|
-
}, inline?: boolean | string[]): I18nOptions;
|
|
30
|
-
export declare function loadTranslations(locale: string, desc: LocaleDescription, workspaceRoot: string, loader: TranslationLoader, logger: {
|
|
31
|
-
warn: (message: string) => void;
|
|
32
|
-
error: (message: string) => void;
|
|
33
|
-
}, usedFormats?: Set<string>, duplicateTranslation?: 'ignore' | 'error' | 'warning'): void;
|
|
@@ -1,161 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.loadTranslations = exports.createI18nOptions = void 0;
|
|
14
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
15
|
-
function normalizeTranslationFileOption(option, locale, expectObjectInError) {
|
|
16
|
-
if (typeof option === 'string') {
|
|
17
|
-
return [option];
|
|
18
|
-
}
|
|
19
|
-
if (Array.isArray(option) && option.every((element) => typeof element === 'string')) {
|
|
20
|
-
return option;
|
|
21
|
-
}
|
|
22
|
-
let errorMessage = `Project i18n locales translation field value for '${locale}' is malformed. `;
|
|
23
|
-
if (expectObjectInError) {
|
|
24
|
-
errorMessage += 'Expected a string, array of strings, or object.';
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
errorMessage += 'Expected a string or array of strings.';
|
|
28
|
-
}
|
|
29
|
-
throw new Error(errorMessage);
|
|
30
|
-
}
|
|
31
|
-
function ensureObject(value, name) {
|
|
32
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
33
|
-
throw new Error(`Project ${name} field is malformed. Expected an object.`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function ensureString(value, name) {
|
|
37
|
-
if (typeof value !== 'string') {
|
|
38
|
-
throw new Error(`Project ${name} field is malformed. Expected a string.`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function createI18nOptions(projectMetadata, inline) {
|
|
42
|
-
const { i18n: metadata = {} } = projectMetadata;
|
|
43
|
-
ensureObject(metadata, 'i18n');
|
|
44
|
-
const i18n = {
|
|
45
|
-
inlineLocales: new Set(),
|
|
46
|
-
// en-US is the default locale added to Angular applications (https://angular.io/guide/i18n#i18n-pipes)
|
|
47
|
-
sourceLocale: 'en-US',
|
|
48
|
-
locales: {},
|
|
49
|
-
get shouldInline() {
|
|
50
|
-
return this.inlineLocales.size > 0;
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
let rawSourceLocale;
|
|
54
|
-
let rawSourceLocaleBaseHref;
|
|
55
|
-
if (typeof metadata.sourceLocale === 'string') {
|
|
56
|
-
rawSourceLocale = metadata.sourceLocale;
|
|
57
|
-
}
|
|
58
|
-
else if (metadata.sourceLocale !== undefined) {
|
|
59
|
-
ensureObject(metadata.sourceLocale, 'i18n sourceLocale');
|
|
60
|
-
if (metadata.sourceLocale.code !== undefined) {
|
|
61
|
-
ensureString(metadata.sourceLocale.code, 'i18n sourceLocale code');
|
|
62
|
-
rawSourceLocale = metadata.sourceLocale.code;
|
|
63
|
-
}
|
|
64
|
-
if (metadata.sourceLocale.baseHref !== undefined) {
|
|
65
|
-
ensureString(metadata.sourceLocale.baseHref, 'i18n sourceLocale baseHref');
|
|
66
|
-
rawSourceLocaleBaseHref = metadata.sourceLocale.baseHref;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (rawSourceLocale !== undefined) {
|
|
70
|
-
i18n.sourceLocale = rawSourceLocale;
|
|
71
|
-
i18n.hasDefinedSourceLocale = true;
|
|
72
|
-
}
|
|
73
|
-
i18n.locales[i18n.sourceLocale] = {
|
|
74
|
-
files: [],
|
|
75
|
-
baseHref: rawSourceLocaleBaseHref,
|
|
76
|
-
};
|
|
77
|
-
if (metadata.locales !== undefined) {
|
|
78
|
-
ensureObject(metadata.locales, 'i18n locales');
|
|
79
|
-
for (const [locale, options] of Object.entries(metadata.locales)) {
|
|
80
|
-
let translationFiles;
|
|
81
|
-
let baseHref;
|
|
82
|
-
if (options && typeof options === 'object' && 'translation' in options) {
|
|
83
|
-
translationFiles = normalizeTranslationFileOption(options.translation, locale, false);
|
|
84
|
-
if ('baseHref' in options) {
|
|
85
|
-
ensureString(options.baseHref, `i18n locales ${locale} baseHref`);
|
|
86
|
-
baseHref = options.baseHref;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
translationFiles = normalizeTranslationFileOption(options, locale, true);
|
|
91
|
-
}
|
|
92
|
-
if (locale === i18n.sourceLocale) {
|
|
93
|
-
throw new Error(`An i18n locale ('${locale}') cannot both be a source locale and provide a translation.`);
|
|
94
|
-
}
|
|
95
|
-
i18n.locales[locale] = {
|
|
96
|
-
files: translationFiles.map((file) => ({ path: file })),
|
|
97
|
-
baseHref,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (inline === true) {
|
|
102
|
-
i18n.inlineLocales.add(i18n.sourceLocale);
|
|
103
|
-
Object.keys(i18n.locales).forEach((locale) => i18n.inlineLocales.add(locale));
|
|
104
|
-
}
|
|
105
|
-
else if (inline) {
|
|
106
|
-
for (const locale of inline) {
|
|
107
|
-
if (!i18n.locales[locale] && i18n.sourceLocale !== locale) {
|
|
108
|
-
throw new Error(`Requested locale '${locale}' is not defined for the project.`);
|
|
109
|
-
}
|
|
110
|
-
i18n.inlineLocales.add(locale);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return i18n;
|
|
114
|
-
}
|
|
115
|
-
exports.createI18nOptions = createI18nOptions;
|
|
116
|
-
function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedFormats, duplicateTranslation) {
|
|
117
|
-
let translations = undefined;
|
|
118
|
-
for (const file of desc.files) {
|
|
119
|
-
const loadResult = loader(node_path_1.default.join(workspaceRoot, file.path));
|
|
120
|
-
for (const diagnostics of loadResult.diagnostics.messages) {
|
|
121
|
-
if (diagnostics.type === 'error') {
|
|
122
|
-
logger.error(`Error parsing translation file '${file.path}': ${diagnostics.message}`);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
logger.warn(`WARNING [${file.path}]: ${diagnostics.message}`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (loadResult.locale !== undefined && loadResult.locale !== locale) {
|
|
129
|
-
logger.warn(`WARNING [${file.path}]: File target locale ('${loadResult.locale}') does not match configured locale ('${locale}')`);
|
|
130
|
-
}
|
|
131
|
-
usedFormats?.add(loadResult.format);
|
|
132
|
-
file.format = loadResult.format;
|
|
133
|
-
file.integrity = loadResult.integrity;
|
|
134
|
-
if (translations) {
|
|
135
|
-
// Merge translations
|
|
136
|
-
for (const [id, message] of Object.entries(loadResult.translations)) {
|
|
137
|
-
if (translations[id] !== undefined) {
|
|
138
|
-
const duplicateTranslationMessage = `[${file.path}]: Duplicate translations for message '${id}' when merging.`;
|
|
139
|
-
switch (duplicateTranslation) {
|
|
140
|
-
case 'ignore':
|
|
141
|
-
break;
|
|
142
|
-
case 'error':
|
|
143
|
-
logger.error(`ERROR ${duplicateTranslationMessage}`);
|
|
144
|
-
break;
|
|
145
|
-
case 'warning':
|
|
146
|
-
default:
|
|
147
|
-
logger.warn(`WARNING ${duplicateTranslationMessage}`);
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
translations[id] = message;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
// First or only translation file
|
|
156
|
-
translations = loadResult.translations;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
desc.translation = translations;
|
|
160
|
-
}
|
|
161
|
-
exports.loadTranslations = loadTranslations;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
export declare function addEventDispatchContract(html: string): Promise<string>;
|