@angular-devkit/build-angular 14.1.1 → 14.1.2

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,15 +1,15 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-angular",
3
- "version": "14.1.1",
3
+ "version": "14.1.2",
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
9
  "@ampproject/remapping": "2.2.0",
10
- "@angular-devkit/architect": "0.1401.1",
11
- "@angular-devkit/build-webpack": "0.1401.1",
12
- "@angular-devkit/core": "14.1.1",
10
+ "@angular-devkit/architect": "0.1401.2",
11
+ "@angular-devkit/build-webpack": "0.1401.2",
12
+ "@angular-devkit/core": "14.1.2",
13
13
  "@babel/core": "7.18.6",
14
14
  "@babel/generator": "7.18.7",
15
15
  "@babel/helper-annotate-as-pure": "7.18.6",
@@ -20,7 +20,7 @@
20
20
  "@babel/runtime": "7.18.6",
21
21
  "@babel/template": "7.18.6",
22
22
  "@discoveryjs/json-ext": "0.5.7",
23
- "@ngtools/webpack": "14.1.1",
23
+ "@ngtools/webpack": "14.1.2",
24
24
  "ansi-colors": "4.1.3",
25
25
  "babel-loader": "8.2.5",
26
26
  "babel-plugin-istanbul": "6.1.1",
@@ -162,9 +162,13 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
162
162
  }
163
163
  // The file emitter created during `onStart` that will be used during the build in `onLoad` callbacks for TS files
164
164
  let fileEmitter;
165
+ // The stylesheet resources from component stylesheets that will be added to the build results output files
166
+ let stylesheetResourceFiles;
165
167
  build.onStart(async () => {
166
168
  var _a, _b;
167
169
  const result = {};
170
+ // Reset stylesheet resource output files
171
+ stylesheetResourceFiles = [];
168
172
  // Create TypeScript compiler host
169
173
  const host = typescript_1.default.createIncrementalCompilerHost(compilerOptions);
170
174
  // Temporarily process external resources via readResource.
@@ -176,9 +180,10 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
176
180
  if (fileName.endsWith('.html')) {
177
181
  return (_a = this.readFile(fileName)) !== null && _a !== void 0 ? _a : '';
178
182
  }
179
- const { contents, errors, warnings } = await (0, stylesheets_1.bundleStylesheetFile)(fileName, styleOptions);
183
+ const { contents, resourceFiles, errors, warnings } = await (0, stylesheets_1.bundleStylesheetFile)(fileName, styleOptions);
180
184
  ((_b = result.errors) !== null && _b !== void 0 ? _b : (result.errors = [])).push(...errors);
181
185
  ((_c = result.warnings) !== null && _c !== void 0 ? _c : (result.warnings = [])).push(...warnings);
186
+ stylesheetResourceFiles.push(...resourceFiles);
182
187
  return contents;
183
188
  };
184
189
  // Add an AOT compiler resource transform hook
@@ -191,12 +196,13 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
191
196
  // The file with the resource content will either be an actual file (resourceFile)
192
197
  // or the file containing the inline component style text (containingFile).
193
198
  const file = (_a = context.resourceFile) !== null && _a !== void 0 ? _a : context.containingFile;
194
- const { contents, errors, warnings } = await (0, stylesheets_1.bundleStylesheetText)(data, {
199
+ const { contents, resourceFiles, errors, warnings } = await (0, stylesheets_1.bundleStylesheetText)(data, {
195
200
  resolvePath: path.dirname(file),
196
201
  virtualName: file,
197
202
  }, styleOptions);
198
203
  ((_b = result.errors) !== null && _b !== void 0 ? _b : (result.errors = [])).push(...errors);
199
204
  ((_c = result.warnings) !== null && _c !== void 0 ? _c : (result.warnings = [])).push(...warnings);
205
+ stylesheetResourceFiles.push(...resourceFiles);
200
206
  return { content: contents };
201
207
  };
202
208
  // Create the Angular specific program that contains the Angular compiler
@@ -263,9 +269,20 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
263
269
  ],
264
270
  };
265
271
  }
272
+ const data = (_a = typescriptResult.content) !== null && _a !== void 0 ? _a : '';
273
+ const forceAsyncTransformation = /for\s+await\s*\(|async\s+function\s*\*/.test(data);
266
274
  const useInputSourcemap = pluginOptions.sourcemap &&
267
275
  (!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(args.path));
268
- const data = (_a = typescriptResult.content) !== null && _a !== void 0 ? _a : '';
276
+ // If no additional transformations are needed, return the TypeScript output directly
277
+ if (!forceAsyncTransformation && !pluginOptions.advancedOptimizations) {
278
+ return {
279
+ // Strip sourcemaps if they should not be used
280
+ contents: useInputSourcemap
281
+ ? data
282
+ : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''),
283
+ loader: 'js',
284
+ };
285
+ }
269
286
  const babelResult = await (0, core_1.transformAsync)(data, {
270
287
  filename: args.path,
271
288
  inputSourceMap: (useInputSourcemap ? undefined : false),
@@ -279,7 +296,7 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
279
296
  [
280
297
  application_1.default,
281
298
  {
282
- forceAsyncTransformation: data.includes('async'),
299
+ forceAsyncTransformation,
283
300
  optimize: pluginOptions.advancedOptimizations && {},
284
301
  },
285
302
  ],
@@ -292,11 +309,24 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
292
309
  });
293
310
  build.onLoad({ filter: /\.[cm]?js$/ }, async (args) => {
294
311
  var _a;
295
- const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(args.path);
296
- const linkerPluginCreator = (await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker/babel')).createEs2015LinkerPlugin;
312
+ const data = await fs_1.promises.readFile(args.path, 'utf-8');
313
+ const forceAsyncTransformation = !/[\\/][_f]?esm2015[\\/]/.test(args.path) &&
314
+ /for\s+await\s*\(|async\s+function\s*\*/.test(data);
315
+ const shouldLink = await (0, webpack_loader_1.requiresLinking)(args.path, data);
297
316
  const useInputSourcemap = pluginOptions.sourcemap &&
298
317
  (!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(args.path));
299
- const data = await fs_1.promises.readFile(args.path, 'utf-8');
318
+ // If no additional transformations are needed, return the TypeScript output directly
319
+ if (!forceAsyncTransformation && !pluginOptions.advancedOptimizations && !shouldLink) {
320
+ return {
321
+ // Strip sourcemaps if they should not be used
322
+ contents: useInputSourcemap
323
+ ? data
324
+ : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''),
325
+ loader: 'js',
326
+ };
327
+ }
328
+ const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(args.path);
329
+ const linkerPluginCreator = (await (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker/babel')).createEs2015LinkerPlugin;
300
330
  const result = await (0, core_1.transformAsync)(data, {
301
331
  filename: args.path,
302
332
  inputSourceMap: (useInputSourcemap ? undefined : false),
@@ -311,11 +341,11 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
311
341
  application_1.default,
312
342
  {
313
343
  angularLinker: {
314
- shouldLink: await (0, webpack_loader_1.requiresLinking)(args.path, data),
344
+ shouldLink,
315
345
  jitMode: false,
316
346
  linkerPluginCreator,
317
347
  },
318
- forceAsyncTransformation: !/[\\/][_f]?esm2015[\\/]/.test(args.path) && data.includes('async'),
348
+ forceAsyncTransformation,
319
349
  optimize: pluginOptions.advancedOptimizations && {
320
350
  looseEnums: angularPackage,
321
351
  pureTopLevel: angularPackage,
@@ -329,6 +359,12 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
329
359
  loader: 'js',
330
360
  };
331
361
  });
362
+ build.onEnd((result) => {
363
+ var _a;
364
+ if (stylesheetResourceFiles.length) {
365
+ (_a = result.outputFiles) === null || _a === void 0 ? void 0 : _a.push(...stylesheetResourceFiles);
366
+ }
367
+ });
332
368
  },
333
369
  };
334
370
  }
@@ -0,0 +1,17 @@
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 { Plugin } from 'esbuild';
9
+ /**
10
+ * Creates an esbuild {@link Plugin} that loads all CSS url token references using the
11
+ * built-in esbuild `file` loader. A plugin is used to allow for all file extensions
12
+ * and types to be supported without needing to manually specify all extensions
13
+ * within the build configuration.
14
+ *
15
+ * @returns An esbuild {@link Plugin} instance.
16
+ */
17
+ export declare function createCssResourcePlugin(): Plugin;
@@ -0,0 +1,59 @@
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.createCssResourcePlugin = void 0;
11
+ const promises_1 = require("fs/promises");
12
+ /**
13
+ * Symbol marker used to indicate CSS resource resolution is being attempted.
14
+ * This is used to prevent an infinite loop within the plugin's resolve hook.
15
+ */
16
+ const CSS_RESOURCE_RESOLUTION = Symbol('CSS_RESOURCE_RESOLUTION');
17
+ /**
18
+ * Creates an esbuild {@link Plugin} that loads all CSS url token references using the
19
+ * built-in esbuild `file` loader. A plugin is used to allow for all file extensions
20
+ * and types to be supported without needing to manually specify all extensions
21
+ * within the build configuration.
22
+ *
23
+ * @returns An esbuild {@link Plugin} instance.
24
+ */
25
+ function createCssResourcePlugin() {
26
+ return {
27
+ name: 'angular-css-resource',
28
+ setup(build) {
29
+ build.onResolve({ filter: /.*/ }, async (args) => {
30
+ var _a;
31
+ // Only attempt to resolve url tokens which only exist inside CSS.
32
+ // Also, skip this plugin if already attempting to resolve the url-token.
33
+ if (args.kind !== 'url-token' || ((_a = args.pluginData) === null || _a === void 0 ? void 0 : _a[CSS_RESOURCE_RESOLUTION])) {
34
+ return null;
35
+ }
36
+ const { importer, kind, resolveDir, namespace, pluginData = {} } = args;
37
+ pluginData[CSS_RESOURCE_RESOLUTION] = true;
38
+ const result = await build.resolve(args.path, {
39
+ importer,
40
+ kind,
41
+ namespace,
42
+ pluginData,
43
+ resolveDir,
44
+ });
45
+ return {
46
+ ...result,
47
+ namespace: 'css-resource',
48
+ };
49
+ });
50
+ build.onLoad({ filter: /.*/, namespace: 'css-resource' }, async (args) => {
51
+ return {
52
+ contents: await (0, promises_1.readFile)(args.path),
53
+ loader: 'file',
54
+ };
55
+ });
56
+ },
57
+ };
58
+ }
59
+ exports.createCssResourcePlugin = createCssResourcePlugin;
@@ -140,6 +140,7 @@ async function buildEsbuildBrowser(options, context) {
140
140
  outputNames: noInjectNames.includes(name) ? { media: outputNames.media } : outputNames,
141
141
  includePaths: (_e = options.stylePreprocessorOptions) === null || _e === void 0 ? void 0 : _e.includePaths,
142
142
  preserveSymlinks: options.preserveSymlinks,
143
+ externalDependencies: options.externalDependencies,
143
144
  });
144
145
  await (0, esbuild_1.logMessages)(context, sheetResult);
145
146
  if (!sheetResult.path) {
@@ -244,6 +245,18 @@ async function bundleCode(workspaceRoot, entryPoints, outputNames, options, opti
244
245
  entryNames: outputNames.bundles,
245
246
  assetNames: outputNames.media,
246
247
  target: 'es2020',
248
+ supported: {
249
+ // Native async/await is not supported with Zone.js. Disabling support here will cause
250
+ // esbuild to downlevel async/await to a Zone.js supported form.
251
+ 'async-await': false,
252
+ // Zone.js also does not support async generators or async iterators. However, esbuild does
253
+ // not currently support downleveling either of them. Instead babel is used within the JS/TS
254
+ // loader to perform the downlevel transformation. They are both disabled here to allow
255
+ // esbuild to handle them in the future if support is ever added.
256
+ // NOTE: If esbuild adds support in the future, the babel support for these can be disabled.
257
+ 'async-generator': false,
258
+ 'for-await': false,
259
+ },
247
260
  mainFields: ['es2020', 'browser', 'module', 'main'],
248
261
  conditions: ['es2020', 'es2015', 'module'],
249
262
  resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
@@ -279,6 +292,7 @@ async function bundleCode(workspaceRoot, entryPoints, outputNames, options, opti
279
292
  !!sourcemapOptions.styles && (sourcemapOptions.hidden ? false : 'inline'),
280
293
  outputNames,
281
294
  includePaths: (_a = options.stylePreprocessorOptions) === null || _a === void 0 ? void 0 : _a.includePaths,
295
+ externalDependencies: options.externalDependencies,
282
296
  }),
283
297
  ],
284
298
  define: {
@@ -16,6 +16,7 @@ export interface BundleStylesheetOptions {
16
16
  media?: string;
17
17
  };
18
18
  includePaths?: string[];
19
+ externalDependencies?: string[];
19
20
  }
20
21
  /**
21
22
  * Bundle a stylesheet that exists as a file on the filesystem.
@@ -32,6 +32,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
33
  exports.bundleStylesheetText = exports.bundleStylesheetFile = void 0;
34
34
  const path = __importStar(require("path"));
35
+ const css_resource_plugin_1 = require("./css-resource-plugin");
35
36
  const esbuild_1 = require("./esbuild");
36
37
  const sass_plugin_1 = require("./sass-plugin");
37
38
  async function bundleStylesheet(entry, options) {
@@ -50,10 +51,12 @@ async function bundleStylesheet(entry, options) {
50
51
  write: false,
51
52
  platform: 'browser',
52
53
  preserveSymlinks: options.preserveSymlinks,
54
+ external: options.externalDependencies,
53
55
  conditions: ['style', 'sass'],
54
56
  mainFields: ['style', 'sass'],
55
57
  plugins: [
56
58
  (0, sass_plugin_1.createSassPlugin)({ sourcemap: !!options.sourcemap, includePaths: options.includePaths }),
59
+ (0, css_resource_plugin_1.createCssResourcePlugin)(),
57
60
  ],
58
61
  });
59
62
  // Extract the result of the bundling from the output files
@@ -157,7 +157,7 @@ class NgBuildAnalyticsPlugin {
157
157
  var _a, _b;
158
158
  const chunkAssets = new Set();
159
159
  for (const chunk of compilation.chunks) {
160
- if (!chunk.rendered) {
160
+ if (!chunk.rendered || chunk.files.size === 0) {
161
161
  continue;
162
162
  }
163
163
  const firstFile = Array.from(chunk.files)[0];
@@ -131,7 +131,7 @@ function default_1(options) {
131
131
  return;
132
132
  }
133
133
  const value = decl.value;
134
- const urlRegex = /url\(\s*(?:"([^"]+)"|'([^']+)'|(.+?))\s*\)/g;
134
+ const urlRegex = /url(?:\(\s*['"]?)(.*?)(?:['"]?\s*\))/g;
135
135
  const segments = [];
136
136
  let match;
137
137
  let lastIndex = 0;
@@ -141,7 +141,7 @@ function default_1(options) {
141
141
  const context = (inputFile && path.dirname(inputFile)) || loader.context;
142
142
  // eslint-disable-next-line no-cond-assign
143
143
  while ((match = urlRegex.exec(value))) {
144
- const originalUrl = match[1] || match[2] || match[3];
144
+ const originalUrl = match[1];
145
145
  let processedUrl;
146
146
  try {
147
147
  processedUrl = await process(originalUrl, context, resourceCache);