@angular-devkit/build-angular 12.2.0-next.0 → 12.2.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.
Files changed (40) hide show
  1. package/package.json +33 -32
  2. package/src/app-shell/index.js +3 -5
  3. package/src/babel/plugins/adjust-static-class-members.js +22 -1
  4. package/src/babel/presets/application.d.ts +0 -1
  5. package/src/babel/presets/application.js +3 -2
  6. package/src/babel/webpack-loader.js +0 -9
  7. package/src/browser/index.js +13 -3
  8. package/src/browser/schema.d.ts +1 -1
  9. package/src/browser/schema.json +1 -1
  10. package/src/dev-server/index.js +2 -2
  11. package/src/extract-i18n/index.js +1 -1
  12. package/src/extract-i18n/ivy-extract-loader.d.ts +6 -1
  13. package/src/extract-i18n/ivy-extract-loader.js +8 -12
  14. package/src/karma/index.js +1 -1
  15. package/src/server/index.js +1 -1
  16. package/src/server/tests/setup.d.ts +18 -0
  17. package/src/server/tests/setup.js +27 -0
  18. package/src/utils/action-executor.d.ts +3 -8
  19. package/src/utils/action-executor.js +19 -73
  20. package/src/utils/delete-output-dir.js +28 -2
  21. package/src/utils/index-file/inline-fonts.d.ts +3 -1
  22. package/src/utils/index-file/inline-fonts.js +112 -55
  23. package/src/utils/process-bundle.d.ts +0 -5
  24. package/src/utils/process-bundle.js +50 -140
  25. package/src/utils/version.d.ts +1 -2
  26. package/src/utils/version.js +5 -4
  27. package/src/webpack/configs/browser.js +0 -16
  28. package/src/webpack/configs/common.js +56 -67
  29. package/src/webpack/configs/server.js +0 -1
  30. package/src/webpack/configs/styles.js +92 -75
  31. package/src/webpack/plugins/builder-watch-plugin.d.ts +1 -26
  32. package/src/webpack/plugins/hmr/hmr-accept.js +1 -0
  33. package/src/webpack/plugins/javascript-optimizer-plugin.d.ts +59 -0
  34. package/src/webpack/plugins/javascript-optimizer-plugin.js +150 -0
  35. package/src/webpack/plugins/javascript-optimizer-worker.d.ts +37 -0
  36. package/src/webpack/plugins/javascript-optimizer-worker.js +74 -0
  37. package/src/webpack/plugins/postcss-cli-resources.d.ts +1 -1
  38. package/src/webpack/plugins/postcss-cli-resources.js +2 -1
  39. package/src/webpack/plugins/single-test-transform.d.ts +1 -1
  40. package/src/webpack/plugins/single-test-transform.js +1 -2
@@ -6,9 +6,28 @@
6
6
  * Use of this source code is governed by an MIT-style license that can be
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
9
28
  Object.defineProperty(exports, "__esModule", { value: true });
10
29
  exports.deleteOutputDir = void 0;
11
- const fs_1 = require("fs");
30
+ const fs = __importStar(require("fs"));
12
31
  const path_1 = require("path");
13
32
  /**
14
33
  * Delete an output directory, but error out if it's the root of the project.
@@ -18,6 +37,13 @@ function deleteOutputDir(root, outputPath) {
18
37
  if (resolvedOutputPath === root) {
19
38
  throw new Error('Output path MUST not be project root directory!');
20
39
  }
21
- fs_1.rmdirSync(resolvedOutputPath, { recursive: true, maxRetries: 3 });
40
+ // The below should be removed and replace with just `rmSync` when support for Node.Js 12 is removed.
41
+ const { rmSync, rmdirSync } = fs;
42
+ if (rmSync) {
43
+ rmSync(resolvedOutputPath, { force: true, recursive: true, maxRetries: 3 });
44
+ }
45
+ else {
46
+ rmdirSync(resolvedOutputPath, { recursive: true, maxRetries: 3 });
47
+ }
22
48
  }
23
49
  exports.deleteOutputDir = deleteOutputDir;
@@ -14,5 +14,7 @@ export declare class InlineFontsProcessor {
14
14
  constructor(options: InlineFontsOptions);
15
15
  process(content: string): Promise<string>;
16
16
  private getResponse;
17
- private processHrefs;
17
+ private processHref;
18
+ private getFontProviderDetails;
19
+ private createNormalizedUrl;
18
20
  }
@@ -42,31 +42,77 @@ const cacheFontsPath = environment_options_1.cachingDisabled
42
42
  ? undefined
43
43
  : cache_path_1.findCachePath('angular-build-fonts');
44
44
  const packageVersion = require('../../../package.json').version;
45
- const SUPPORTED_PROVIDERS = ['fonts.googleapis.com'];
45
+ const SUPPORTED_PROVIDERS = {
46
+ 'fonts.googleapis.com': {
47
+ seperateRequestForWOFF: true,
48
+ preconnectUrl: 'https://fonts.gstatic.com',
49
+ },
50
+ 'use.typekit.net': {
51
+ seperateRequestForWOFF: false,
52
+ preconnectUrl: 'https://use.typekit.net',
53
+ },
54
+ };
46
55
  class InlineFontsProcessor {
47
56
  constructor(options) {
48
57
  this.options = options;
49
58
  }
50
59
  async process(content) {
60
+ var _a;
51
61
  const hrefList = [];
62
+ const existingPreconnect = new Set();
52
63
  // Collector link tags with href
53
64
  const { rewriter: collectorStream } = await html_rewriting_stream_1.htmlRewritingStream(content);
54
65
  collectorStream.on('startTag', (tag) => {
55
- var _a;
56
66
  const { tagName, attrs } = tag;
57
67
  if (tagName !== 'link') {
58
68
  return;
59
69
  }
60
- // <link tag with rel="stylesheet" and a href.
61
- const href = attrs.find(({ name, value }) => name === 'rel' && value === 'stylesheet') &&
62
- ((_a = attrs.find(({ name }) => name === 'href')) === null || _a === void 0 ? void 0 : _a.value);
63
- if (href) {
64
- hrefList.push(href);
70
+ let hrefValue;
71
+ let relValue;
72
+ for (const { name, value } of attrs) {
73
+ switch (name) {
74
+ case 'rel':
75
+ relValue = value;
76
+ break;
77
+ case 'href':
78
+ hrefValue = value;
79
+ break;
80
+ }
81
+ if (hrefValue && relValue) {
82
+ switch (relValue) {
83
+ case 'stylesheet':
84
+ // <link rel="stylesheet" href="https://example.com/main.css">
85
+ hrefList.push(hrefValue);
86
+ break;
87
+ case 'preconnect':
88
+ // <link rel="preconnect" href="https://example.com">
89
+ existingPreconnect.add(hrefValue.replace(/\/$/, ''));
90
+ break;
91
+ }
92
+ return;
93
+ }
65
94
  }
66
95
  });
67
96
  await new Promise((resolve) => collectorStream.on('finish', resolve));
68
97
  // Download stylesheets
69
- const hrefsContent = await this.processHrefs(hrefList);
98
+ const hrefsContent = new Map();
99
+ const newPreconnectUrls = new Set();
100
+ for (const hrefItem of hrefList) {
101
+ const url = this.createNormalizedUrl(hrefItem);
102
+ if (!url) {
103
+ continue;
104
+ }
105
+ const content = await this.processHref(url);
106
+ if (content === undefined) {
107
+ continue;
108
+ }
109
+ hrefsContent.set(hrefItem, content);
110
+ // Add preconnect
111
+ const preconnectUrl = (_a = this.getFontProviderDetails(url)) === null || _a === void 0 ? void 0 : _a.preconnectUrl;
112
+ if (preconnectUrl && !existingPreconnect.has(preconnectUrl)) {
113
+ newPreconnectUrls.add(preconnectUrl);
114
+ }
115
+ }
70
116
  if (hrefsContent.size === 0) {
71
117
  return content;
72
118
  }
@@ -74,19 +120,28 @@ class InlineFontsProcessor {
74
120
  const { rewriter, transformedContent } = await html_rewriting_stream_1.htmlRewritingStream(content);
75
121
  rewriter.on('startTag', (tag) => {
76
122
  const { tagName, attrs } = tag;
77
- if (tagName !== 'link') {
78
- rewriter.emitStartTag(tag);
79
- return;
80
- }
81
- const hrefAttr = attrs.some(({ name, value }) => name === 'rel' && value === 'stylesheet') &&
82
- attrs.find(({ name, value }) => name === 'href' && hrefsContent.has(value));
83
- if (hrefAttr) {
84
- const href = hrefAttr.value;
85
- const cssContent = hrefsContent.get(href);
86
- rewriter.emitRaw(`<style type="text/css">${cssContent}</style>`);
87
- }
88
- else {
89
- rewriter.emitStartTag(tag);
123
+ switch (tagName) {
124
+ case 'head':
125
+ rewriter.emitStartTag(tag);
126
+ for (const url of newPreconnectUrls) {
127
+ rewriter.emitRaw(`<link rel="preconnect" href="${url}" crossorigin>`);
128
+ }
129
+ break;
130
+ case 'link':
131
+ const hrefAttr = attrs.some(({ name, value }) => name === 'rel' && value === 'stylesheet') &&
132
+ attrs.find(({ name, value }) => name === 'href' && hrefsContent.has(value));
133
+ if (hrefAttr) {
134
+ const href = hrefAttr.value;
135
+ const cssContent = hrefsContent.get(href);
136
+ rewriter.emitRaw(`<style type="text/css">${cssContent}</style>`);
137
+ }
138
+ else {
139
+ rewriter.emitStartTag(tag);
140
+ }
141
+ break;
142
+ default:
143
+ rewriter.emitStartTag(tag);
144
+ break;
90
145
  }
91
146
  });
92
147
  return transformedContent;
@@ -129,41 +184,43 @@ class InlineFontsProcessor {
129
184
  }
130
185
  return data;
131
186
  }
132
- async processHrefs(hrefList) {
133
- const hrefsContent = new Map();
134
- for (const hrefPath of hrefList) {
135
- // Need to convert '//' to 'https://' because the URL parser will fail with '//'.
136
- const normalizedHref = hrefPath.startsWith('//') ? `https:${hrefPath}` : hrefPath;
137
- if (!normalizedHref.startsWith('http')) {
138
- // Non valid URL.
139
- // Example: relative path styles.css.
140
- continue;
141
- }
142
- const url = new url_1.URL(normalizedHref);
143
- // Force HTTPS protocol
144
- url.protocol = 'https:';
145
- if (!SUPPORTED_PROVIDERS.includes(url.hostname)) {
146
- // Provider not supported.
147
- continue;
148
- }
149
- // The order IE -> Chrome is important as otherwise Chrome will load woff1.
150
- let cssContent = '';
151
- if (this.options.WOFFSupportNeeded) {
152
- cssContent += await this.getResponse(url, "Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11. 0) like Gecko" /* IE */);
153
- }
154
- cssContent += await this.getResponse(url, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" /* Chrome */);
155
- if (this.options.minify) {
156
- cssContent = cssContent
157
- // Comments.
158
- .replace(/\/\*([\s\S]*?)\*\//g, '')
159
- // New lines.
160
- .replace(/\n/g, '')
161
- // Safe spaces.
162
- .replace(/\s?[\{\:\;]\s+/g, (s) => s.trim());
163
- }
164
- hrefsContent.set(hrefPath, cssContent);
187
+ async processHref(url) {
188
+ const provider = this.getFontProviderDetails(url);
189
+ if (!provider) {
190
+ return undefined;
191
+ }
192
+ // The order IE -> Chrome is important as otherwise Chrome will load woff1.
193
+ let cssContent = '';
194
+ if (this.options.WOFFSupportNeeded && provider.seperateRequestForWOFF) {
195
+ cssContent += await this.getResponse(url, "Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11. 0) like Gecko" /* IE */);
196
+ }
197
+ cssContent += await this.getResponse(url, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" /* Chrome */);
198
+ if (this.options.minify) {
199
+ cssContent = cssContent
200
+ // Comments.
201
+ .replace(/\/\*([\s\S]*?)\*\//g, '')
202
+ // New lines.
203
+ .replace(/\n/g, '')
204
+ // Safe spaces.
205
+ .replace(/\s?[\{\:\;]\s+/g, (s) => s.trim());
206
+ }
207
+ return cssContent;
208
+ }
209
+ getFontProviderDetails(url) {
210
+ return SUPPORTED_PROVIDERS[url.hostname];
211
+ }
212
+ createNormalizedUrl(value) {
213
+ // Need to convert '//' to 'https://' because the URL parser will fail with '//'.
214
+ const normalizedHref = value.startsWith('//') ? `https:${value}` : value;
215
+ if (!normalizedHref.startsWith('http')) {
216
+ // Non valid URL.
217
+ // Example: relative path styles.css.
218
+ return undefined;
165
219
  }
166
- return hrefsContent;
220
+ const url = new url_1.URL(normalizedHref);
221
+ // Force HTTPS protocol
222
+ url.protocol = 'https:';
223
+ return url;
167
224
  }
168
225
  }
169
226
  exports.InlineFontsProcessor = InlineFontsProcessor;
@@ -7,7 +7,6 @@
7
7
  */
8
8
  /// <reference types="packages/angular_devkit/build_angular/src/babel-bazel" />
9
9
  import { PluginObj } from '@babel/core';
10
- import { I18nOptions } from './i18n-options';
11
10
  export interface ProcessBundleOptions {
12
11
  filename: string;
13
12
  code: string;
@@ -47,10 +46,6 @@ export declare const enum CacheKey {
47
46
  DownlevelCode = 2,
48
47
  DownlevelMap = 3
49
48
  }
50
- export declare function setup(data: number[] | {
51
- cachePath: string;
52
- i18n: I18nOptions;
53
- }): void;
54
49
  export declare function process(options: ProcessBundleOptions): Promise<ProcessBundleResult>;
55
50
  export declare function createI18nPlugins(locale: string, translation: unknown | undefined, missingTranslation: 'error' | 'warning' | 'ignore', shouldInline: boolean, localeDataContent?: string): Promise<{
56
51
  diagnostics: import("@angular/localize/src/tools/src/diagnostics").Diagnostics;
@@ -29,31 +29,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.inlineLocales = exports.createI18nPlugins = exports.process = exports.setup = void 0;
32
+ exports.inlineLocales = exports.createI18nPlugins = exports.process = void 0;
33
+ const remapping_1 = __importDefault(require("@ampproject/remapping"));
33
34
  const core_1 = require("@babel/core");
34
35
  const template_1 = __importDefault(require("@babel/template"));
35
36
  const cacache = __importStar(require("cacache"));
36
37
  const crypto_1 = require("crypto");
37
38
  const fs = __importStar(require("fs"));
38
39
  const path = __importStar(require("path"));
39
- const source_map_1 = require("source-map");
40
40
  const terser_1 = require("terser");
41
- const v8 = __importStar(require("v8"));
42
- const webpack_1 = require("webpack");
41
+ const worker_threads_1 = require("worker_threads");
43
42
  const environment_options_1 = require("./environment-options");
44
- const { ConcatSource, OriginalSource, ReplaceSource, SourceMapSource } = webpack_1.sources;
43
+ // Lazy loaded webpack-sources object
44
+ // Webpack is only imported if needed during the processing
45
+ let webpackSources;
45
46
  // If code size is larger than 500KB, consider lower fidelity but faster sourcemap merge
46
47
  const FAST_SOURCEMAP_THRESHOLD = 500 * 1024;
47
- let cachePath;
48
- let i18n;
49
- function setup(data) {
50
- const options = Array.isArray(data)
51
- ? v8.deserialize(Buffer.from(data))
52
- : data;
53
- cachePath = options.cachePath;
54
- i18n = options.i18n;
55
- }
56
- exports.setup = setup;
48
+ const { cachePath, i18n } = (worker_threads_1.workerData || {});
57
49
  async function cachePut(content, key, integrity) {
58
50
  if (cachePath && key) {
59
51
  await cacache.put(cachePath, key, content, {
@@ -62,6 +54,7 @@ async function cachePut(content, key, integrity) {
62
54
  }
63
55
  }
64
56
  async function process(options) {
57
+ var _a;
65
58
  if (!options.cacheKeys) {
66
59
  options.cacheKeys = [];
67
60
  }
@@ -79,9 +72,6 @@ async function process(options) {
79
72
  const downlevelFilename = filename.replace(/\-(es20\d{2}|esnext)/, '-es5');
80
73
  const downlevel = !options.optimizeOnly;
81
74
  const sourceCode = options.code;
82
- const sourceMap = options.map ? JSON.parse(options.map) : undefined;
83
- let downlevelCode;
84
- let downlevelMap;
85
75
  if (downlevel) {
86
76
  const { supportedBrowsers: targets = [] } = options;
87
77
  // todo: revisit this in version 10, when we update our defaults browserslist
@@ -121,26 +111,15 @@ async function process(options) {
121
111
  ],
122
112
  minified: environment_options_1.allowMinify && !!options.optimize,
123
113
  compact: !environment_options_1.shouldBeautify && !!options.optimize,
124
- sourceMaps: !!sourceMap,
114
+ sourceMaps: !!options.map,
125
115
  });
126
116
  if (!transformResult || !transformResult.code) {
127
117
  throw new Error(`Unknown error occurred processing bundle for "${options.filename}".`);
128
118
  }
129
- downlevelCode = transformResult.code;
130
- if (sourceMap && transformResult.map) {
131
- // String length is used as an estimate for byte length
132
- const fastSourceMaps = sourceCode.length > FAST_SOURCEMAP_THRESHOLD;
133
- downlevelMap = await mergeSourceMaps(sourceCode, sourceMap, downlevelCode, transformResult.map, filename,
134
- // When not optimizing, the sourcemaps are significantly less complex
135
- // and can use the higher fidelity merge
136
- !!options.optimize && fastSourceMaps);
137
- }
138
- }
139
- if (downlevelCode) {
140
119
  result.downlevel = await processBundle({
141
120
  ...options,
142
- code: downlevelCode,
143
- map: downlevelMap,
121
+ code: transformResult.code,
122
+ downlevelMap: (_a = transformResult.map) !== null && _a !== void 0 ? _a : undefined,
144
123
  filename: path.join(basePath, downlevelFilename),
145
124
  isOriginal: false,
146
125
  });
@@ -154,113 +133,46 @@ async function process(options) {
154
133
  return result;
155
134
  }
156
135
  exports.process = process;
157
- async function mergeSourceMaps(inputCode, inputSourceMap, resultCode, resultSourceMap, filename, fast = false) {
158
- // Webpack 5 terser sourcemaps currently fail merging with the high-quality method
159
- if (fast) {
160
- return mergeSourceMapsFast(inputSourceMap, resultSourceMap);
161
- }
162
- // SourceMapSource produces high-quality sourcemaps
163
- // Final sourcemap will always be available when providing the input sourcemaps
164
- const finalSourceMap = new SourceMapSource(resultCode, filename, resultSourceMap, inputCode, inputSourceMap, true).map();
165
- return finalSourceMap;
166
- }
167
- async function mergeSourceMapsFast(first, second) {
168
- const sourceRoot = first.sourceRoot;
169
- const generator = new source_map_1.SourceMapGenerator();
170
- // sourcemap package adds the sourceRoot to all position source paths if not removed
171
- delete first.sourceRoot;
172
- await source_map_1.SourceMapConsumer.with(first, null, (originalConsumer) => {
173
- return source_map_1.SourceMapConsumer.with(second, null, (newConsumer) => {
174
- newConsumer.eachMapping((mapping) => {
175
- if (mapping.originalLine === null) {
176
- return;
177
- }
178
- const originalPosition = originalConsumer.originalPositionFor({
179
- line: mapping.originalLine,
180
- column: mapping.originalColumn,
181
- });
182
- if (originalPosition.line === null ||
183
- originalPosition.column === null ||
184
- originalPosition.source === null) {
185
- return;
186
- }
187
- generator.addMapping({
188
- generated: {
189
- line: mapping.generatedLine,
190
- column: mapping.generatedColumn,
191
- },
192
- name: originalPosition.name || undefined,
193
- original: {
194
- line: originalPosition.line,
195
- column: originalPosition.column,
196
- },
197
- source: originalPosition.source,
198
- });
199
- });
200
- });
201
- });
202
- const map = generator.toJSON();
203
- map.file = second.file;
204
- map.sourceRoot = sourceRoot;
205
- // Add source content if present
206
- if (first.sourcesContent) {
207
- // Source content array is based on index of sources
208
- const sourceContentMap = new Map();
209
- for (let i = 0; i < first.sources.length; i++) {
210
- // make paths "absolute" so they can be compared (`./a.js` and `a.js` are equivalent)
211
- sourceContentMap.set(path.resolve('/', first.sources[i]), i);
212
- }
213
- map.sourcesContent = [];
214
- for (let i = 0; i < map.sources.length; i++) {
215
- const contentIndex = sourceContentMap.get(path.resolve('/', map.sources[i]));
216
- if (contentIndex === undefined) {
217
- map.sourcesContent.push('');
218
- }
219
- else {
220
- map.sourcesContent.push(first.sourcesContent[contentIndex]);
221
- }
222
- }
223
- }
224
- // Put the sourceRoot back
225
- if (sourceRoot) {
226
- first.sourceRoot = sourceRoot;
227
- }
228
- return map;
229
- }
230
136
  async function processBundle(options) {
231
- const { optimize, isOriginal, code, map, filename: filepath, hiddenSourceMaps, cacheKeys = [], integrityAlgorithm, } = options;
232
- const rawMap = typeof map === 'string' ? JSON.parse(map) : map;
137
+ const { optimize, isOriginal, code, map, downlevelMap, filename: filepath, hiddenSourceMaps, cacheKeys = [], integrityAlgorithm, } = options;
233
138
  const filename = path.basename(filepath);
234
- let result;
235
- if (rawMap) {
236
- rawMap.file = filename;
237
- }
139
+ let resultCode = code;
140
+ let optimizeResult;
238
141
  if (optimize) {
239
- result = await terserMangle(code, {
142
+ optimizeResult = await terserMangle(code, {
240
143
  filename,
241
- map: rawMap,
144
+ sourcemap: !!map,
242
145
  compress: !isOriginal,
243
146
  ecma: isOriginal ? 2015 : 5,
244
147
  });
245
- }
246
- else {
247
- result = {
248
- map: rawMap,
249
- code,
250
- };
148
+ resultCode = optimizeResult.code;
251
149
  }
252
150
  let mapContent;
253
- if (result.map) {
151
+ if (map) {
254
152
  if (!hiddenSourceMaps) {
255
- result.code += `\n//# sourceMappingURL=${filename}.map`;
153
+ resultCode += `\n//# sourceMappingURL=${filename}.map`;
154
+ }
155
+ const partialSourcemaps = [];
156
+ if (optimizeResult && optimizeResult.map) {
157
+ partialSourcemaps.push(optimizeResult.map);
158
+ }
159
+ if (downlevelMap) {
160
+ partialSourcemaps.push(downlevelMap);
161
+ }
162
+ if (partialSourcemaps.length > 0) {
163
+ partialSourcemaps.push(map);
164
+ const fullSourcemap = remapping_1.default(partialSourcemaps, () => null);
165
+ mapContent = JSON.stringify(fullSourcemap);
166
+ }
167
+ else {
168
+ mapContent = map;
256
169
  }
257
- mapContent = JSON.stringify(result.map);
258
170
  await cachePut(mapContent, cacheKeys[isOriginal ? 1 /* OriginalMap */ : 3 /* DownlevelMap */]);
259
171
  fs.writeFileSync(filepath + '.map', mapContent);
260
172
  }
261
- const fileResult = createFileEntry(filepath, result.code, mapContent, integrityAlgorithm);
262
- await cachePut(result.code, cacheKeys[isOriginal ? 0 /* OriginalCode */ : 2 /* DownlevelCode */], fileResult.integrity);
263
- fs.writeFileSync(filepath, result.code);
173
+ const fileResult = createFileEntry(filepath, resultCode, mapContent, integrityAlgorithm);
174
+ await cachePut(resultCode, cacheKeys[isOriginal ? 0 /* OriginalCode */ : 2 /* DownlevelCode */], fileResult.integrity);
175
+ fs.writeFileSync(filepath, resultCode);
264
176
  return fileResult;
265
177
  }
266
178
  async function terserMangle(code, options = {}) {
@@ -278,7 +190,7 @@ async function terserMangle(code, options = {}) {
278
190
  beautify: environment_options_1.shouldBeautify,
279
191
  wrap_func_args: false,
280
192
  },
281
- sourceMap: !!options.map &&
193
+ sourceMap: !!options.sourcemap &&
282
194
  {
283
195
  asObject: true,
284
196
  // typings don't include asObject option
@@ -286,12 +198,7 @@ async function terserMangle(code, options = {}) {
286
198
  },
287
199
  });
288
200
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
289
- const outputCode = minifyOutput.code;
290
- let outputMap;
291
- if (options.map && minifyOutput.map) {
292
- outputMap = await mergeSourceMaps(code, options.map, outputCode, minifyOutput.map, options.filename || '0', code.length > FAST_SOURCEMAP_THRESHOLD);
293
- }
294
- return { code: outputCode, map: outputMap };
201
+ return { code: minifyOutput.code, map: minifyOutput.map };
295
202
  }
296
203
  function createFileEntry(filename, code, map, integrityAlgorithm) {
297
204
  return {
@@ -450,7 +357,6 @@ async function inlineLocales(options) {
450
357
  return inlineLocalesDirect(ast, options);
451
358
  }
452
359
  const diagnostics = [];
453
- const inputMap = options.map && JSON.parse(options.map);
454
360
  for (const locale of i18n.inlineLocales) {
455
361
  const isSourceLocale = locale === i18n.sourceLocale;
456
362
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -474,7 +380,7 @@ async function inlineLocales(options) {
474
380
  configFile: false,
475
381
  plugins,
476
382
  compact: !environment_options_1.shouldBeautify,
477
- sourceMaps: !!inputMap,
383
+ sourceMaps: !!options.map,
478
384
  });
479
385
  diagnostics.push(...localeDiagnostics.messages);
480
386
  if (!transformResult || !transformResult.code) {
@@ -482,8 +388,8 @@ async function inlineLocales(options) {
482
388
  }
483
389
  const outputPath = path.join(options.outputPath, i18n.flatOutput ? '' : locale, options.filename);
484
390
  fs.writeFileSync(outputPath, transformResult.code);
485
- if (inputMap && transformResult.map) {
486
- const outputMap = await mergeSourceMaps(options.code, inputMap, transformResult.code, transformResult.map, options.filename, options.code.length > FAST_SOURCEMAP_THRESHOLD);
391
+ if (options.map && transformResult.map) {
392
+ const outputMap = remapping_1.default([transformResult.map, options.map], () => null);
487
393
  fs.writeFileSync(outputPath + '.map', JSON.stringify(outputMap));
488
394
  }
489
395
  }
@@ -502,16 +408,20 @@ async function inlineLocalesDirect(ast, options) {
502
408
  if (positions.length === 0 && !options.setLocale) {
503
409
  return inlineCopyOnly(options);
504
410
  }
505
- const inputMap = options.map && JSON.parse(options.map);
411
+ const inputMap = !!options.map && JSON.parse(options.map);
506
412
  // Cleanup source root otherwise it will be added to each source entry
507
413
  const mapSourceRoot = inputMap && inputMap.sourceRoot;
508
414
  if (inputMap) {
509
415
  delete inputMap.sourceRoot;
510
416
  }
417
+ // Load Webpack only when needed
418
+ if (webpackSources === undefined) {
419
+ webpackSources = (await Promise.resolve().then(() => __importStar(require('webpack')))).sources;
420
+ }
421
+ const { ConcatSource, OriginalSource, ReplaceSource, SourceMapSource } = webpackSources;
511
422
  for (const locale of i18n.inlineLocales) {
512
423
  const content = new ReplaceSource(inputMap
513
- ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
514
- new SourceMapSource(options.code, options.filename, inputMap)
424
+ ? new SourceMapSource(options.code, options.filename, inputMap)
515
425
  : new OriginalSource(options.code, options.filename));
516
426
  const isSourceLocale = locale === i18n.sourceLocale;
517
427
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -526,7 +436,7 @@ async function inlineLocalesDirect(ast, options) {
526
436
  if (options.setLocale) {
527
437
  const setLocaleText = `var $localize=Object.assign(void 0===$localize?{}:$localize,{locale:"${locale}"});\n`;
528
438
  // If locale data is provided, load it and prepend to file
529
- let localeDataSource = null;
439
+ let localeDataSource;
530
440
  const localeDataPath = i18n.locales[locale] && i18n.locales[locale].dataPath;
531
441
  if (localeDataPath) {
532
442
  const localeDataContent = await loadLocaleData(localeDataPath, true, options.es5);
@@ -5,5 +5,4 @@
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 { logging } from '@angular-devkit/core';
9
- export declare function assertCompatibleAngularVersion(projectRoot: string, logger: logging.LoggerApi): void;
8
+ export declare function assertCompatibleAngularVersion(projectRoot: string): void | never;
@@ -8,9 +8,10 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.assertCompatibleAngularVersion = void 0;
11
+ /* eslint-disable no-console */
11
12
  const core_1 = require("@angular-devkit/core");
12
13
  const semver_1 = require("semver");
13
- function assertCompatibleAngularVersion(projectRoot, logger) {
14
+ function assertCompatibleAngularVersion(projectRoot) {
14
15
  let angularCliPkgJson;
15
16
  let angularPkgJson;
16
17
  let rxjsPkgJson;
@@ -22,13 +23,13 @@ function assertCompatibleAngularVersion(projectRoot, logger) {
22
23
  rxjsPkgJson = require(rxjsPackagePath);
23
24
  }
24
25
  catch {
25
- logger.error(core_1.tags.stripIndents `
26
+ console.error(core_1.tags.stripIndents `
26
27
  You seem to not be depending on "@angular/core" and/or "rxjs". This is an error.
27
28
  `);
28
29
  process.exit(2);
29
30
  }
30
31
  if (!(angularPkgJson && angularPkgJson['version'] && rxjsPkgJson && rxjsPkgJson['version'])) {
31
- logger.error(core_1.tags.stripIndents `
32
+ console.error(core_1.tags.stripIndents `
32
33
  Cannot determine versions of "@angular/core" and/or "rxjs".
33
34
  This likely means your local installation is broken. Please reinstall your packages.
34
35
  `);
@@ -57,7 +58,7 @@ function assertCompatibleAngularVersion(projectRoot, logger) {
57
58
  // of both 8 and 9.
58
59
  const supportedAngularSemver = `^${cliMajor}.0.0-next || >=${cliMajor}.0.0 <${cliMajor + 1}.0.0`;
59
60
  if (!semver_1.satisfies(angularVersion, supportedAngularSemver, { includePrerelease: true })) {
60
- logger.error(core_1.tags.stripIndents `
61
+ console.error(core_1.tags.stripIndents `
61
62
  This version of CLI is only compatible with Angular versions ${supportedAngularSemver},
62
63
  but Angular version ${angularVersion} was found instead.
63
64