@angular-devkit/build-angular 14.1.0 → 14.1.3

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.0",
3
+ "version": "14.1.3",
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.0",
11
- "@angular-devkit/build-webpack": "0.1401.0",
12
- "@angular-devkit/core": "14.1.0",
10
+ "@angular-devkit/architect": "0.1401.3",
11
+ "@angular-devkit/build-webpack": "0.1401.3",
12
+ "@angular-devkit/core": "14.1.3",
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.0",
23
+ "@ngtools/webpack": "14.1.3",
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;
@@ -124,7 +124,11 @@ async function buildEsbuildBrowser(options, context) {
124
124
  // Process global stylesheets
125
125
  if (options.styles) {
126
126
  // resolveGlobalStyles is temporarily reused from the Webpack builder code
127
- const { entryPoints: stylesheetEntrypoints, noInjectNames } = (0, configs_1.resolveGlobalStyles)(options.styles, workspaceRoot, !!options.preserveSymlinks);
127
+ const { entryPoints: stylesheetEntrypoints, noInjectNames } = (0, configs_1.resolveGlobalStyles)(options.styles, workspaceRoot,
128
+ // preserveSymlinks is always true here to allow the bundler to handle the option
129
+ true,
130
+ // skipResolution to leverage the bundler's more comprehensive resolution
131
+ true);
128
132
  for (const [name, files] of Object.entries(stylesheetEntrypoints)) {
129
133
  const virtualEntryData = files
130
134
  .map((file) => `@import '${file.replace(/\\/g, '/')}';`)
@@ -135,6 +139,8 @@ async function buildEsbuildBrowser(options, context) {
135
139
  sourcemap: !!sourcemapOptions.styles && (sourcemapOptions.hidden ? 'external' : true),
136
140
  outputNames: noInjectNames.includes(name) ? { media: outputNames.media } : outputNames,
137
141
  includePaths: (_e = options.stylePreprocessorOptions) === null || _e === void 0 ? void 0 : _e.includePaths,
142
+ preserveSymlinks: options.preserveSymlinks,
143
+ externalDependencies: options.externalDependencies,
138
144
  });
139
145
  await (0, esbuild_1.logMessages)(context, sheetResult);
140
146
  if (!sheetResult.path) {
@@ -239,6 +245,18 @@ async function bundleCode(workspaceRoot, entryPoints, outputNames, options, opti
239
245
  entryNames: outputNames.bundles,
240
246
  assetNames: outputNames.media,
241
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
+ },
242
260
  mainFields: ['es2020', 'browser', 'module', 'main'],
243
261
  conditions: ['es2020', 'es2015', 'module'],
244
262
  resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
@@ -274,10 +292,11 @@ async function bundleCode(workspaceRoot, entryPoints, outputNames, options, opti
274
292
  !!sourcemapOptions.styles && (sourcemapOptions.hidden ? false : 'inline'),
275
293
  outputNames,
276
294
  includePaths: (_a = options.stylePreprocessorOptions) === null || _a === void 0 ? void 0 : _a.includePaths,
295
+ externalDependencies: options.externalDependencies,
277
296
  }),
278
297
  ],
279
298
  define: {
280
- 'ngDevMode': optimizationOptions.scripts ? 'false' : 'true',
299
+ ...(optimizationOptions.scripts ? { 'ngDevMode': 'false' } : undefined),
281
300
  'ngJitMode': 'false',
282
301
  },
283
302
  });
@@ -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,
53
- conditions: ['style'],
54
- mainFields: ['style'],
54
+ external: options.externalDependencies,
55
+ conditions: ['style', 'sass'],
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
@@ -13,6 +13,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.assertIsError = void 0;
14
14
  const assert_1 = __importDefault(require("assert"));
15
15
  function assertIsError(value) {
16
- (0, assert_1.default)(value instanceof Error, 'catch clause variable is not an Error instance');
16
+ const isError = value instanceof Error ||
17
+ // The following is needing to identify errors coming from RxJs.
18
+ (typeof value === 'object' && value && 'name' in value && 'message' in value);
19
+ (0, assert_1.default)(isError, 'catch clause variable is not an Error instance');
17
20
  }
18
21
  exports.assertIsError = assertIsError;
@@ -98,6 +98,23 @@ async function getDevServerConfig(wco) {
98
98
  publicPath: servePath,
99
99
  stats: false,
100
100
  },
101
+ setupMiddlewares: (middlewares, _devServer) => {
102
+ // Temporary workaround for https://github.com/webpack/webpack-dev-server/issues/4180
103
+ middlewares.push({
104
+ name: 'options-request-response',
105
+ path: '*',
106
+ middleware: (req, res, next) => {
107
+ if (req.method === 'OPTIONS') {
108
+ res.statusCode = 204;
109
+ res.setHeader('Content-Length', 0);
110
+ res.end();
111
+ return;
112
+ }
113
+ next();
114
+ },
115
+ });
116
+ return middlewares;
117
+ },
101
118
  liveReload,
102
119
  hot: hmr && !liveReload ? 'only' : hmr,
103
120
  proxy: await addProxyConfig(root, proxyConfig),
@@ -8,7 +8,7 @@
8
8
  import { Configuration } from 'webpack';
9
9
  import { StyleElement } from '../../builders/browser/schema';
10
10
  import { WebpackConfigOptions } from '../../utils/build-options';
11
- export declare function resolveGlobalStyles(styleEntrypoints: StyleElement[], root: string, preserveSymlinks: boolean): {
11
+ export declare function resolveGlobalStyles(styleEntrypoints: StyleElement[], root: string, preserveSymlinks: boolean, skipResolution?: boolean): {
12
12
  entryPoints: Record<string, string[]>;
13
13
  noInjectNames: string[];
14
14
  paths: string[];
@@ -41,7 +41,7 @@ const sass_service_1 = require("../../sass/sass-service");
41
41
  const plugins_1 = require("../plugins");
42
42
  const css_optimizer_plugin_1 = require("../plugins/css-optimizer-plugin");
43
43
  const helpers_1 = require("../utils/helpers");
44
- function resolveGlobalStyles(styleEntrypoints, root, preserveSymlinks) {
44
+ function resolveGlobalStyles(styleEntrypoints, root, preserveSymlinks, skipResolution = false) {
45
45
  const entryPoints = {};
46
46
  const noInjectNames = [];
47
47
  const paths = [];
@@ -49,29 +49,32 @@ function resolveGlobalStyles(styleEntrypoints, root, preserveSymlinks) {
49
49
  return { entryPoints, noInjectNames, paths };
50
50
  }
51
51
  for (const style of (0, helpers_1.normalizeExtraEntryPoints)(styleEntrypoints, 'styles')) {
52
- let resolvedPath = path.resolve(root, style.input);
53
- if (!fs.existsSync(resolvedPath)) {
54
- try {
55
- resolvedPath = require.resolve(style.input, { paths: [root] });
52
+ let stylesheetPath = style.input;
53
+ if (!skipResolution) {
54
+ stylesheetPath = path.resolve(root, stylesheetPath);
55
+ if (!fs.existsSync(stylesheetPath)) {
56
+ try {
57
+ stylesheetPath = require.resolve(style.input, { paths: [root] });
58
+ }
59
+ catch { }
56
60
  }
57
- catch { }
58
61
  }
59
62
  if (!preserveSymlinks) {
60
- resolvedPath = fs.realpathSync(resolvedPath);
63
+ stylesheetPath = fs.realpathSync(stylesheetPath);
61
64
  }
62
65
  // Add style entry points.
63
66
  if (entryPoints[style.bundleName]) {
64
- entryPoints[style.bundleName].push(resolvedPath);
67
+ entryPoints[style.bundleName].push(stylesheetPath);
65
68
  }
66
69
  else {
67
- entryPoints[style.bundleName] = [resolvedPath];
70
+ entryPoints[style.bundleName] = [stylesheetPath];
68
71
  }
69
72
  // Add non injected styles to the list.
70
73
  if (!style.inject) {
71
74
  noInjectNames.push(style.bundleName);
72
75
  }
73
76
  // Add global css paths.
74
- paths.push(resolvedPath);
77
+ paths.push(stylesheetPath);
75
78
  }
76
79
  return { entryPoints, noInjectNames, paths };
77
80
  }
@@ -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);