@angular-devkit/build-angular 13.1.0-next.1 → 13.1.0

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/package.json CHANGED
@@ -1,77 +1,78 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-angular",
3
- "version": "13.1.0-next.1",
3
+ "version": "13.1.0",
4
4
  "description": "Angular Webpack Build Facade",
5
5
  "main": "src/index.js",
6
6
  "typings": "src/index.d.ts",
7
7
  "builders": "builders.json",
8
8
  "dependencies": {
9
- "@ampproject/remapping": "1.0.1",
10
- "@angular-devkit/architect": "0.1301.0-next.1",
11
- "@angular-devkit/build-webpack": "0.1301.0-next.1",
12
- "@angular-devkit/core": "13.1.0-next.1",
9
+ "@ampproject/remapping": "1.0.2",
10
+ "@angular-devkit/architect": "0.1301.0",
11
+ "@angular-devkit/build-webpack": "0.1301.0",
12
+ "@angular-devkit/core": "13.1.0",
13
13
  "@babel/core": "7.16.0",
14
14
  "@babel/generator": "7.16.0",
15
15
  "@babel/helper-annotate-as-pure": "7.16.0",
16
- "@babel/plugin-proposal-async-generator-functions": "7.16.0",
16
+ "@babel/plugin-proposal-async-generator-functions": "7.16.4",
17
17
  "@babel/plugin-transform-async-to-generator": "7.16.0",
18
- "@babel/plugin-transform-runtime": "7.16.0",
19
- "@babel/preset-env": "7.16.0",
18
+ "@babel/plugin-transform-runtime": "7.16.4",
19
+ "@babel/preset-env": "7.16.4",
20
20
  "@babel/runtime": "7.16.3",
21
21
  "@babel/template": "7.16.0",
22
- "@discoveryjs/json-ext": "0.5.5",
23
- "@ngtools/webpack": "13.1.0-next.1",
22
+ "@discoveryjs/json-ext": "0.5.6",
23
+ "@ngtools/webpack": "13.1.0",
24
24
  "ansi-colors": "4.1.1",
25
25
  "babel-loader": "8.2.3",
26
26
  "babel-plugin-istanbul": "6.1.1",
27
27
  "browserslist": "^4.9.1",
28
28
  "cacache": "15.3.0",
29
29
  "circular-dependency-plugin": "5.2.2",
30
- "copy-webpack-plugin": "9.0.1",
31
- "core-js": "3.19.1",
32
- "critters": "0.0.14",
30
+ "copy-webpack-plugin": "10.0.0",
31
+ "core-js": "3.19.3",
32
+ "critters": "0.0.15",
33
33
  "css-loader": "6.5.1",
34
- "esbuild-wasm": "0.13.13",
34
+ "esbuild-wasm": "0.14.2",
35
35
  "glob": "7.2.0",
36
36
  "https-proxy-agent": "5.0.0",
37
37
  "inquirer": "8.2.0",
38
+ "jsonc-parser": "3.0.0",
38
39
  "karma-source-map-support": "1.4.0",
39
40
  "less": "4.1.2",
40
41
  "less-loader": "10.2.0",
41
- "license-webpack-plugin": "3.0.0",
42
- "loader-utils": "3.1.3",
43
- "mini-css-extract-plugin": "2.4.4",
42
+ "license-webpack-plugin": "4.0.0",
43
+ "loader-utils": "3.2.0",
44
+ "mini-css-extract-plugin": "2.4.5",
44
45
  "minimatch": "3.0.4",
45
46
  "open": "8.4.0",
46
47
  "ora": "5.4.1",
47
48
  "parse5-html-rewriting-stream": "6.0.1",
48
49
  "piscina": "3.1.0",
49
- "postcss": "8.3.11",
50
+ "postcss": "8.4.4",
50
51
  "postcss-import": "14.0.2",
51
- "postcss-loader": "6.2.0",
52
+ "postcss-loader": "6.2.1",
52
53
  "postcss-preset-env": "6.7.0",
53
54
  "regenerator-runtime": "0.13.9",
54
55
  "resolve-url-loader": "4.0.0",
55
56
  "rxjs": "6.6.7",
56
- "sass": "1.43.4",
57
- "sass-loader": "12.3.0",
57
+ "sass": "1.44.0",
58
+ "sass-loader": "12.4.0",
58
59
  "semver": "7.3.5",
59
60
  "source-map-loader": "3.0.0",
60
- "source-map-support": "0.5.20",
61
+ "source-map-support": "0.5.21",
61
62
  "stylus": "0.55.0",
62
63
  "stylus-loader": "6.2.0",
63
- "terser": "5.9.0",
64
+ "terser": "5.10.0",
64
65
  "text-table": "0.2.0",
65
66
  "tree-kill": "1.2.2",
66
67
  "tslib": "2.3.1",
67
- "webpack": "5.63.0",
68
- "webpack-dev-middleware": "5.2.1",
69
- "webpack-dev-server": "4.4.0",
68
+ "webpack": "5.65.0",
69
+ "webpack-dev-middleware": "5.2.2",
70
+ "webpack-dev-server": "4.6.0",
70
71
  "webpack-merge": "5.8.0",
71
72
  "webpack-subresource-integrity": "5.0.0"
72
73
  },
73
74
  "optionalDependencies": {
74
- "esbuild": "0.13.13"
75
+ "esbuild": "0.14.2"
75
76
  },
76
77
  "peerDependencies": {
77
78
  "@angular/compiler-cli": "^13.0.0 || ^13.1.0-next",
@@ -81,7 +82,7 @@
81
82
  "ng-packagr": "^13.0.0 || ^13.1.0-next",
82
83
  "protractor": "^7.0.0",
83
84
  "tailwindcss": "^2.0.0",
84
- "typescript": "~4.4.3"
85
+ "typescript": ">=4.4.3 <4.6"
85
86
  },
86
87
  "peerDependenciesMeta": {
87
88
  "@angular/localize": {
@@ -5,6 +5,7 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
+ import type { ɵParsedTranslation } from '@angular/localize/private';
8
9
  import type { makeEs2015TranslatePlugin, makeEs5TranslatePlugin, makeLocalePlugin } from '@angular/localize/tools';
9
10
  export declare type DiagnosticReporter = (type: 'error' | 'warning' | 'info', message: string) => void;
10
11
  /**
@@ -22,8 +23,9 @@ export interface ApplicationPresetOptions {
22
23
  i18n?: {
23
24
  locale: string;
24
25
  missingTranslationBehavior?: 'error' | 'warning' | 'ignore';
25
- translation?: unknown;
26
- pluginCreators?: I18nPluginCreators;
26
+ translation?: Record<string, ɵParsedTranslation>;
27
+ translationFiles?: string[];
28
+ pluginCreators: I18nPluginCreators;
27
29
  };
28
30
  angularLinker?: {
29
31
  shouldLink: boolean;
@@ -60,28 +60,18 @@ function createI18nDiagnostics(reporter) {
60
60
  })();
61
61
  return diagnostics;
62
62
  }
63
- function createI18nPlugins(locale, translation, missingTranslationBehavior, diagnosticReporter,
64
- // TODO_ESM: Make `pluginCreators` required once `@angular/localize` is published with the `tools` entry point
65
- pluginCreators) {
63
+ function createI18nPlugins(locale, translation, missingTranslationBehavior, diagnosticReporter, pluginCreators) {
66
64
  const diagnostics = createI18nDiagnostics(diagnosticReporter);
67
65
  const plugins = [];
66
+ const { makeEs5TranslatePlugin, makeEs2015TranslatePlugin, makeLocalePlugin } = pluginCreators;
68
67
  if (translation) {
69
- const { makeEs2015TranslatePlugin,
70
- // TODO_ESM: Remove all deep imports once `@angular/localize` is published with the `tools` entry point
71
- } = pluginCreators !== null && pluginCreators !== void 0 ? pluginCreators : require('@angular/localize/src/tools/src/translate/source_files/es2015_translate_plugin');
72
68
  plugins.push(makeEs2015TranslatePlugin(diagnostics, translation, {
73
69
  missingTranslation: missingTranslationBehavior,
74
70
  }));
75
- const { makeEs5TranslatePlugin,
76
- // TODO_ESM: Remove all deep imports once `@angular/localize` is published with the `tools` entry point
77
- } = pluginCreators !== null && pluginCreators !== void 0 ? pluginCreators : require('@angular/localize/src/tools/src/translate/source_files/es5_translate_plugin');
78
71
  plugins.push(makeEs5TranslatePlugin(diagnostics, translation, {
79
72
  missingTranslation: missingTranslationBehavior,
80
73
  }));
81
74
  }
82
- const { makeLocalePlugin,
83
- // TODO_ESM: Remove all deep imports once `@angular/localize` is published with the `tools` entry point
84
- } = pluginCreators !== null && pluginCreators !== void 0 ? pluginCreators : require('@angular/localize/src/tools/src/translate/source_files/locale_plugin');
85
75
  plugins.push(makeLocalePlugin(locale));
86
76
  return plugins;
87
77
  }
@@ -41,6 +41,7 @@ async function requiresLinking(path, source) {
41
41
  }
42
42
  return needsLinking(path, source);
43
43
  }
44
+ // eslint-disable-next-line max-lines-per-function
44
45
  exports.default = (0, babel_loader_1.custom)(() => {
45
46
  const baseOptions = Object.freeze({
46
47
  babelrc: false,
@@ -65,13 +66,10 @@ exports.default = (0, babel_loader_1.custom)(() => {
65
66
  };
66
67
  // Analyze file for linking
67
68
  if (await requiresLinking(this.resourcePath, source)) {
68
- if (!linkerPluginCreator) {
69
- // Load ESM `@angular/compiler-cli/linker/babel` using the TypeScript dynamic import workaround.
70
- // Once TypeScript provides support for keeping the dynamic import this workaround can be
71
- // changed to a direct dynamic import.
72
- const linkerBabelModule = await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker/babel');
73
- linkerPluginCreator = linkerBabelModule.createEs2015LinkerPlugin;
74
- }
69
+ // Load ESM `@angular/compiler-cli/linker/babel` using the TypeScript dynamic import workaround.
70
+ // Once TypeScript provides support for keeping the dynamic import this workaround can be
71
+ // changed to a direct dynamic import.
72
+ linkerPluginCreator !== null && linkerPluginCreator !== void 0 ? linkerPluginCreator : (linkerPluginCreator = (await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker/babel')).createEs2015LinkerPlugin);
75
73
  customOptions.angularLinker = {
76
74
  shouldLink: true,
77
75
  jitMode: aot !== true,
@@ -104,20 +102,24 @@ exports.default = (0, babel_loader_1.custom)(() => {
104
102
  // During the transition, this will always attempt to load the entry point for each file.
105
103
  // This will only occur during prerelease and will be automatically corrected once the new
106
104
  // entry point exists.
107
- // TODO_ESM: Make import failure an error once the `tools` entry point exists.
108
105
  if (i18nPluginCreators === undefined) {
109
106
  // Load ESM `@angular/localize/tools` using the TypeScript dynamic import workaround.
110
107
  // Once TypeScript provides support for keeping the dynamic import this workaround can be
111
108
  // changed to a direct dynamic import.
112
- try {
113
- i18nPluginCreators = await (0, load_esm_1.loadEsmModule)('@angular/localize/tools');
114
- }
115
- catch { }
109
+ i18nPluginCreators = await (0, load_esm_1.loadEsmModule)('@angular/localize/tools');
116
110
  }
117
111
  customOptions.i18n = {
118
112
  ...i18n,
119
113
  pluginCreators: i18nPluginCreators,
120
114
  };
115
+ // Add translation files as dependencies of the file to support rebuilds
116
+ // Except for `@angular/core` which needs locale injection but has no translations
117
+ if (customOptions.i18n.translationFiles &&
118
+ !/[\\/]@angular[\\/]core/.test(this.resourcePath)) {
119
+ for (const file of customOptions.i18n.translationFiles) {
120
+ this.addDependency(file);
121
+ }
122
+ }
121
123
  shouldProcess = true;
122
124
  }
123
125
  if (optimize) {
@@ -199,7 +201,13 @@ exports.default = (0, babel_loader_1.custom)(() => {
199
201
  // `@ampproject/remapping` source map objects but both are compatible with Webpack.
200
202
  // This method for merging is used because it provides more accurate output
201
203
  // and is faster while using less memory.
202
- result.map = (0, remapping_1.default)([result.map, inputSourceMap], () => null);
204
+ result.map = {
205
+ // Convert the SourceMap back to simple plain object.
206
+ // This is needed because otherwise code-coverage will fail with `don't know how to turn this value into a node`
207
+ // Which is thrown by Babel if it is invoked again from `istanbul-lib-instrument`.
208
+ // https://github.com/babel/babel/blob/780aa48d2a34dc55f556843074b6aed45e7eabeb/packages/babel-types/src/converters/valueToNode.ts#L115-L130
209
+ ...(0, remapping_1.default)([result.map, inputSourceMap], () => null),
210
+ };
203
211
  }
204
212
  return result;
205
213
  },
@@ -155,8 +155,9 @@ function buildWebpackBrowser(options, context, transforms = {}) {
155
155
  }
156
156
  // Check for budget errors and display them to the user.
157
157
  const budgets = options.budgets;
158
+ let budgetFailures;
158
159
  if (budgets === null || budgets === void 0 ? void 0 : budgets.length) {
159
- const budgetFailures = (0, bundle_calculator_1.checkBudgets)(budgets, webpackStats);
160
+ budgetFailures = [...(0, bundle_calculator_1.checkBudgets)(budgets, webpackStats)];
160
161
  for (const { severity, message } of budgetFailures) {
161
162
  switch (severity) {
162
163
  case bundle_calculator_1.ThresholdSeverity.Warning:
@@ -250,7 +251,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
250
251
  spinner.succeed('Service worker generation complete.');
251
252
  }
252
253
  }
253
- (0, stats_1.webpackStatsLogger)(context.logger, webpackStats, config);
254
+ (0, stats_1.webpackStatsLogger)(context.logger, webpackStats, config, budgetFailures);
254
255
  return { success: buildSuccess };
255
256
  }
256
257
  }), (0, operators_1.map)((event) => ({
@@ -37,10 +37,13 @@ const url = __importStar(require("url"));
37
37
  const utils_1 = require("../../utils");
38
38
  const check_port_1 = require("../../utils/check-port");
39
39
  const color_1 = require("../../utils/color");
40
+ const i18n_options_1 = require("../../utils/i18n-options");
41
+ const load_translations_1 = require("../../utils/load-translations");
40
42
  const normalize_cache_1 = require("../../utils/normalize-cache");
41
43
  const package_chunk_sort_1 = require("../../utils/package-chunk-sort");
42
44
  const version_1 = require("../../utils/version");
43
45
  const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
46
+ const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
44
47
  const configs_1 = require("../../webpack/configs");
45
48
  const index_html_webpack_plugin_1 = require("../../webpack/plugins/index-html-webpack-plugin");
46
49
  const stats_1 = require("../../webpack/utils/stats");
@@ -145,7 +148,7 @@ function serveWebpackBrowser(options, context, transforms = {}) {
145
148
  if (i18n.inlineLocales.size > 1) {
146
149
  throw new Error('The development server only supports localizing a single locale per build.');
147
150
  }
148
- await setupLocalize(locale, i18n, browserOptions, webpackConfig, cacheOptions);
151
+ await setupLocalize(locale, i18n, browserOptions, webpackConfig, cacheOptions, context);
149
152
  }
150
153
  if (transforms.webpackConfiguration) {
151
154
  webpackConfig = await transforms.webpackConfiguration(webpackConfig);
@@ -220,7 +223,7 @@ function serveWebpackBrowser(options, context, transforms = {}) {
220
223
  }));
221
224
  }
222
225
  exports.serveWebpackBrowser = serveWebpackBrowser;
223
- async function setupLocalize(locale, i18n, browserOptions, webpackConfig, cacheOptions) {
226
+ async function setupLocalize(locale, i18n, browserOptions, webpackConfig, cacheOptions, context) {
224
227
  var _a;
225
228
  const localeDescription = i18n.locales[locale];
226
229
  // Modify main entrypoint to include locale data
@@ -248,6 +251,7 @@ async function setupLocalize(locale, i18n, browserOptions, webpackConfig, cacheO
248
251
  locale,
249
252
  missingTranslationBehavior,
250
253
  translation: i18n.shouldInline ? translation : undefined,
254
+ translationFiles: localeDescription === null || localeDescription === void 0 ? void 0 : localeDescription.files.map((file) => path.resolve(context.workspaceRoot, file.path)),
251
255
  };
252
256
  const i18nRule = {
253
257
  test: /\.[cm]?[tj]sx?$/,
@@ -276,5 +280,30 @@ async function setupLocalize(locale, i18n, browserOptions, webpackConfig, cacheO
276
280
  webpackConfig.module.rules = rules;
277
281
  }
278
282
  rules.push(i18nRule);
283
+ // Add a plugin to reload translation files on rebuilds
284
+ const loader = await (0, load_translations_1.createTranslationLoader)();
285
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
286
+ webpackConfig.plugins.push({
287
+ apply: (compiler) => {
288
+ compiler.hooks.thisCompilation.tap('build-angular', (compilation) => {
289
+ if (i18n.shouldInline && i18nLoaderOptions.translation === undefined) {
290
+ // Reload translations
291
+ (0, i18n_options_1.loadTranslations)(locale, localeDescription, context.workspaceRoot, loader, {
292
+ warn(message) {
293
+ (0, webpack_diagnostics_1.addWarning)(compilation, message);
294
+ },
295
+ error(message) {
296
+ (0, webpack_diagnostics_1.addError)(compilation, message);
297
+ },
298
+ });
299
+ i18nLoaderOptions.translation = localeDescription.translation;
300
+ }
301
+ compilation.hooks.finishModules.tap('build-angular', () => {
302
+ // After loaders are finished, clear out the now unneeded translations
303
+ i18nLoaderOptions.translation = undefined;
304
+ });
305
+ });
306
+ },
307
+ });
279
308
  }
280
309
  exports.default = (0, architect_1.createBuilder)(serveWebpackBrowser);
@@ -29,6 +29,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const nodePath = __importStar(require("path"));
30
30
  const load_esm_1 = require("../../utils/load-esm");
31
31
  function localizeExtractLoader(content, map) {
32
+ // This loader is not cacheable due to how message extraction works.
33
+ // Extracted messages are not part of webpack pipeline and hence they cannot be retrieved from cache.
34
+ // TODO: We should investigate in the future on making this deterministic and more cacheable.
35
+ this.cacheable(false);
32
36
  const options = this.getOptions();
33
37
  const callback = this.async();
34
38
  extract(this, content, map, options).then(() => {
@@ -43,7 +47,6 @@ async function extract(loaderContext, content, map, options) {
43
47
  // Try to load the `@angular/localize` message extractor.
44
48
  // All the localize usages are setup to first try the ESM entry point then fallback to the deep imports.
45
49
  // This provides interim compatibility while the framework is transitioned to bundled ESM packages.
46
- // TODO_ESM: Remove all deep imports once `@angular/localize` is published with the `tools` entry point
47
50
  let MessageExtractor;
48
51
  try {
49
52
  // Load ESM `@angular/localize/tools` using the TypeScript dynamic import workaround.
@@ -20,13 +20,12 @@ export declare enum ThresholdSeverity {
20
20
  Warning = "warning",
21
21
  Error = "error"
22
22
  }
23
- export declare function calculateThresholds(budget: Budget): IterableIterator<Threshold>;
24
- export declare function checkBudgets(budgets: Budget[], webpackStats: StatsCompilation): IterableIterator<{
25
- severity: ThresholdSeverity;
26
- message: string;
27
- }>;
28
- export declare function checkThresholds(thresholds: IterableIterator<Threshold>, size: number, label?: string): IterableIterator<{
23
+ export interface BudgetCalculatorResult {
29
24
  severity: ThresholdSeverity;
30
25
  message: string;
31
- }>;
26
+ label?: string;
27
+ }
28
+ export declare function calculateThresholds(budget: Budget): IterableIterator<Threshold>;
29
+ export declare function checkBudgets(budgets: Budget[], webpackStats: StatsCompilation): IterableIterator<BudgetCalculatorResult>;
30
+ export declare function checkThresholds(thresholds: IterableIterator<Threshold>, size: number, label?: string): IterableIterator<BudgetCalculatorResult>;
32
31
  export {};
@@ -143,7 +143,7 @@ class BundleCalculator extends Calculator {
143
143
  .filter((chunk) => { var _a; return (_a = chunk === null || chunk === void 0 ? void 0 : chunk.names) === null || _a === void 0 ? void 0 : _a.includes(budgetName); })
144
144
  .map((chunk) => this.calculateChunkSize(chunk))
145
145
  .reduce((l, r) => l + r, 0);
146
- return [{ size, label: `bundle ${this.budget.name}` }];
146
+ return [{ size, label: this.budget.name }];
147
147
  }
148
148
  }
149
149
  /**
@@ -262,6 +262,7 @@ function* checkThresholds(thresholds, size, label) {
262
262
  const sizeDifference = (0, stats_1.formatSize)(size - threshold.limit);
263
263
  yield {
264
264
  severity: threshold.severity,
265
+ label,
265
266
  message: `${label} exceeded maximum budget. Budget ${(0, stats_1.formatSize)(threshold.limit)} was not met by ${sizeDifference} with a total of ${(0, stats_1.formatSize)(size)}.`,
266
267
  };
267
268
  break;
@@ -273,6 +274,7 @@ function* checkThresholds(thresholds, size, label) {
273
274
  const sizeDifference = (0, stats_1.formatSize)(threshold.limit - size);
274
275
  yield {
275
276
  severity: threshold.severity,
277
+ label,
276
278
  message: `${label} failed to meet minimum budget. Budget ${(0, stats_1.formatSize)(threshold.limit)} was not met by ${sizeDifference} with a total of ${(0, stats_1.formatSize)(size)}.`,
277
279
  };
278
280
  break;
@@ -8,6 +8,5 @@
8
8
  export declare const allowMangle: boolean;
9
9
  export declare const shouldBeautify: boolean;
10
10
  export declare const allowMinify: boolean;
11
- export declare const profilingEnabled: boolean;
12
11
  export declare const maxWorkers: number;
13
12
  export declare const cachingDisabled: boolean | null;
@@ -7,7 +7,7 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.cachingDisabled = exports.maxWorkers = exports.profilingEnabled = exports.allowMinify = exports.shouldBeautify = exports.allowMangle = void 0;
10
+ exports.cachingDisabled = exports.maxWorkers = exports.allowMinify = exports.shouldBeautify = exports.allowMangle = void 0;
11
11
  const color_1 = require("./color");
12
12
  function isDisabled(variable) {
13
13
  return variable === '0' || variable.toLowerCase() === 'false';
@@ -57,9 +57,6 @@ exports.allowMangle = isPresent(mangleVariable)
57
57
  : debugOptimize.mangle;
58
58
  exports.shouldBeautify = debugOptimize.beautify;
59
59
  exports.allowMinify = debugOptimize.minify;
60
- // Build profiling
61
- const profilingVariable = process.env['NG_BUILD_PROFILING'];
62
- exports.profilingEnabled = isPresent(profilingVariable) && isEnabled(profilingVariable);
63
60
  /**
64
61
  * Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available.
65
62
  * This cause `Error: Call retries were exceeded` errors when trying to use them.
@@ -9,19 +9,21 @@ import { BuilderContext } from '@angular-devkit/architect';
9
9
  import { json } from '@angular-devkit/core';
10
10
  import { Schema as BrowserBuilderSchema } from '../builders/browser/schema';
11
11
  import { Schema as ServerBuilderSchema } from '../builders/server/schema';
12
+ import { TranslationLoader } from './load-translations';
13
+ export interface LocaleDescription {
14
+ files: {
15
+ path: string;
16
+ integrity?: string;
17
+ format?: string;
18
+ }[];
19
+ translation?: Record<string, unknown>;
20
+ dataPath?: string;
21
+ baseHref?: string;
22
+ }
12
23
  export interface I18nOptions {
13
24
  inlineLocales: Set<string>;
14
25
  sourceLocale: string;
15
- locales: Record<string, {
16
- files: {
17
- path: string;
18
- integrity?: string;
19
- format?: string;
20
- }[];
21
- translation?: Record<string, unknown>;
22
- dataPath?: string;
23
- baseHref?: string;
24
- }>;
26
+ locales: Record<string, LocaleDescription>;
25
27
  flatOutput?: boolean;
26
28
  readonly shouldInline: boolean;
27
29
  hasDefinedSourceLocale?: boolean;
@@ -31,3 +33,7 @@ export declare function configureI18nBuild<T extends BrowserBuilderSchema | Serv
31
33
  buildOptions: T;
32
34
  i18n: I18nOptions;
33
35
  }>;
36
+ export declare function loadTranslations(locale: string, desc: LocaleDescription, workspaceRoot: string, loader: TranslationLoader, logger: {
37
+ warn: (message: string) => void;
38
+ error: (message: string) => void;
39
+ }, usedFormats?: Set<string>): void;
@@ -10,7 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.configureI18nBuild = exports.createI18nOptions = void 0;
13
+ exports.loadTranslations = exports.configureI18nBuild = exports.createI18nOptions = void 0;
14
14
  const core_1 = require("@angular-devkit/core");
15
15
  const fs_1 = __importDefault(require("fs"));
16
16
  const module_1 = __importDefault(require("module"));
@@ -158,42 +158,18 @@ async function configureI18nBuild(context, options) {
158
158
  if (!desc.files.length) {
159
159
  continue;
160
160
  }
161
- if (!loader) {
162
- loader = await (0, load_translations_1.createTranslationLoader)();
163
- }
164
- for (const file of desc.files) {
165
- const loadResult = loader(path_1.default.join(context.workspaceRoot, file.path));
166
- for (const diagnostics of loadResult.diagnostics.messages) {
167
- if (diagnostics.type === 'error') {
168
- throw new Error(`Error parsing translation file '${file.path}': ${diagnostics.message}`);
169
- }
170
- else {
171
- context.logger.warn(`WARNING [${file.path}]: ${diagnostics.message}`);
172
- }
173
- }
174
- if (loadResult.locale !== undefined && loadResult.locale !== locale) {
175
- context.logger.warn(`WARNING [${file.path}]: File target locale ('${loadResult.locale}') does not match configured locale ('${locale}')`);
176
- }
177
- usedFormats.add(loadResult.format);
178
- if (usedFormats.size > 1 && tsConfig.options.enableI18nLegacyMessageIdFormat !== false) {
179
- // This limitation is only for legacy message id support (defaults to true as of 9.0)
180
- throw new Error('Localization currently only supports using one type of translation file format for the entire application.');
181
- }
182
- file.format = loadResult.format;
183
- file.integrity = loadResult.integrity;
184
- if (desc.translation) {
185
- // Merge translations
186
- for (const [id, message] of Object.entries(loadResult.translations)) {
187
- if (desc.translation[id] !== undefined) {
188
- context.logger.warn(`WARNING [${file.path}]: Duplicate translations for message '${id}' when merging`);
189
- }
190
- desc.translation[id] = message;
191
- }
192
- }
193
- else {
194
- // First or only translation file
195
- desc.translation = loadResult.translations;
196
- }
161
+ loader !== null && loader !== void 0 ? loader : (loader = await (0, load_translations_1.createTranslationLoader)());
162
+ loadTranslations(locale, desc, context.workspaceRoot, loader, {
163
+ warn(message) {
164
+ context.logger.warn(message);
165
+ },
166
+ error(message) {
167
+ throw new Error(message);
168
+ },
169
+ }, usedFormats);
170
+ if (usedFormats.size > 1 && tsConfig.options.enableI18nLegacyMessageIdFormat !== false) {
171
+ // This limitation is only for legacy message id support (defaults to true as of 9.0)
172
+ throw new Error('Localization currently only supports using one type of translation file format for the entire application.');
197
173
  }
198
174
  }
199
175
  // If inlining store the output in a temporary location to facilitate post-processing
@@ -225,3 +201,36 @@ function findLocaleDataPath(locale, resolver) {
225
201
  return null;
226
202
  }
227
203
  }
204
+ function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedFormats) {
205
+ for (const file of desc.files) {
206
+ const loadResult = loader(path_1.default.join(workspaceRoot, file.path));
207
+ for (const diagnostics of loadResult.diagnostics.messages) {
208
+ if (diagnostics.type === 'error') {
209
+ logger.error(`Error parsing translation file '${file.path}': ${diagnostics.message}`);
210
+ }
211
+ else {
212
+ logger.warn(`WARNING [${file.path}]: ${diagnostics.message}`);
213
+ }
214
+ }
215
+ if (loadResult.locale !== undefined && loadResult.locale !== locale) {
216
+ logger.warn(`WARNING [${file.path}]: File target locale ('${loadResult.locale}') does not match configured locale ('${locale}')`);
217
+ }
218
+ usedFormats === null || usedFormats === void 0 ? void 0 : usedFormats.add(loadResult.format);
219
+ file.format = loadResult.format;
220
+ file.integrity = loadResult.integrity;
221
+ if (desc.translation) {
222
+ // Merge translations
223
+ for (const [id, message] of Object.entries(loadResult.translations)) {
224
+ if (desc.translation[id] !== undefined) {
225
+ logger.warn(`WARNING [${file.path}]: Duplicate translations for message '${id}' when merging`);
226
+ }
227
+ desc.translation[id] = message;
228
+ }
229
+ }
230
+ else {
231
+ // First or only translation file
232
+ desc.translation = loadResult.translations;
233
+ }
234
+ }
235
+ }
236
+ exports.loadTranslations = loadTranslations;
@@ -27,4 +27,8 @@ export interface FileInfo {
27
27
  name: string;
28
28
  extension: string;
29
29
  }
30
- export declare function augmentIndexHtml(params: AugmentIndexHtmlOptions): Promise<string>;
30
+ export declare function augmentIndexHtml(params: AugmentIndexHtmlOptions): Promise<{
31
+ content: string;
32
+ warnings: string[];
33
+ errors: string[];
34
+ }>;