@angular-devkit/build-angular 14.2.1 → 14.2.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.2.1",
3
+ "version": "14.2.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.1402.1",
11
- "@angular-devkit/build-webpack": "0.1402.1",
12
- "@angular-devkit/core": "14.2.1",
10
+ "@angular-devkit/architect": "0.1402.3",
11
+ "@angular-devkit/build-webpack": "0.1402.3",
12
+ "@angular-devkit/core": "14.2.3",
13
13
  "@babel/core": "7.18.10",
14
14
  "@babel/generator": "7.18.12",
15
15
  "@babel/helper-annotate-as-pure": "7.18.6",
@@ -20,7 +20,7 @@
20
20
  "@babel/runtime": "7.18.9",
21
21
  "@babel/template": "7.18.10",
22
22
  "@discoveryjs/json-ext": "0.5.7",
23
- "@ngtools/webpack": "14.2.1",
23
+ "@ngtools/webpack": "14.2.3",
24
24
  "ansi-colors": "4.1.3",
25
25
  "babel-loader": "8.2.5",
26
26
  "babel-plugin-istanbul": "6.1.1",
@@ -46,7 +46,7 @@
46
46
  "parse5-html-rewriting-stream": "6.0.1",
47
47
  "piscina": "3.2.0",
48
48
  "postcss": "8.4.16",
49
- "postcss-import": "14.1.0",
49
+ "postcss-import": "15.0.0",
50
50
  "postcss-loader": "7.0.1",
51
51
  "postcss-preset-env": "7.8.0",
52
52
  "regenerator-runtime": "0.13.9",
@@ -65,7 +65,7 @@
65
65
  "tslib": "2.4.0",
66
66
  "webpack": "5.74.0",
67
67
  "webpack-dev-middleware": "5.3.3",
68
- "webpack-dev-server": "4.10.0",
68
+ "webpack-dev-server": "4.11.0",
69
69
  "webpack-merge": "5.8.0",
70
70
  "webpack-subresource-integrity": "5.1.0"
71
71
  },
@@ -105,12 +105,26 @@ function buildWebpackBrowser(options, context, transforms = {}) {
105
105
  // Check Angular version.
106
106
  (0, version_1.assertCompatibleAngularVersion)(context.workspaceRoot);
107
107
  return (0, rxjs_1.from)(context.getProjectMetadata(projectName)).pipe((0, operators_1.switchMap)(async (projectMetadata) => {
108
+ var _a;
109
+ var _b;
108
110
  // Purge old build disk cache.
109
111
  await (0, purge_cache_1.purgeStaleBuildCache)(context);
110
112
  // Initialize builder
111
113
  const initialization = await initialize(options, context, transforms.webpackConfiguration);
112
114
  // Check and warn about IE browser support
113
115
  checkInternetExplorerSupport(initialization.projectRoot, context.logger);
116
+ // Add index file to watched files.
117
+ if (options.watch) {
118
+ const indexInputFile = path.join(context.workspaceRoot, (0, webpack_browser_config_1.getIndexInputFile)(options.index));
119
+ (_a = (_b = initialization.config).plugins) !== null && _a !== void 0 ? _a : (_b.plugins = []);
120
+ initialization.config.plugins.push({
121
+ apply: (compiler) => {
122
+ compiler.hooks.thisCompilation.tap('build-angular', (compilation) => {
123
+ compilation.fileDependencies.add(indexInputFile);
124
+ });
125
+ },
126
+ });
127
+ }
114
128
  return {
115
129
  ...initialization,
116
130
  cacheOptions: (0, normalize_cache_1.normalizeCacheOptions)(projectMetadata, context.workspaceRoot),
@@ -176,8 +176,8 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
176
176
  // Once the AOT compiler allows only a transformResource hook, this can be reevaluated.
177
177
  host.readResource = async function (fileName) {
178
178
  var _a, _b, _c;
179
- // Template resources (.html) files are not bundled or transformed
180
- if (fileName.endsWith('.html')) {
179
+ // Template resources (.html/.svg) files are not bundled or transformed
180
+ if (fileName.endsWith('.html') || fileName.endsWith('.svg')) {
181
181
  return (_a = this.readFile(fileName)) !== null && _a !== void 0 ? _a : '';
182
182
  }
183
183
  const { contents, resourceFiles, errors, warnings } = await (0, stylesheets_1.bundleStylesheetFile)(fileName, styleOptions);
@@ -191,7 +191,6 @@ function serveWebpackBrowser(options, context, transforms = {}) {
191
191
  baseHref: browserOptions.baseHref,
192
192
  root: context.workspaceRoot,
193
193
  projectRoot,
194
- outputPath: path.join(context.workspaceRoot, browserOptions.outputPath),
195
194
  ngswConfigPath: browserOptions.ngswConfigPath,
196
195
  }));
197
196
  }
@@ -253,8 +253,17 @@ async function getCommonConfig(wco) {
253
253
  watch: buildOptions.watch,
254
254
  watchOptions: {
255
255
  poll,
256
+ // The below is needed as when preserveSymlinks is enabled we disable `resolve.symlinks`.
257
+ followSymlinks: buildOptions.preserveSymlinks,
256
258
  ignored: poll === undefined ? undefined : '**/node_modules/**',
257
259
  },
260
+ snapshot: {
261
+ module: {
262
+ // Use hash of content instead of timestamp because the timestamp of the symlink will be used
263
+ // instead of the referenced files which causes changes in symlinks not to be picked up.
264
+ hash: buildOptions.preserveSymlinks,
265
+ },
266
+ },
258
267
  performance: {
259
268
  hints: false,
260
269
  },
@@ -37,6 +37,7 @@ exports.getStylesConfig = exports.resolveGlobalStyles = void 0;
37
37
  const fs = __importStar(require("fs"));
38
38
  const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
39
39
  const path = __importStar(require("path"));
40
+ const webpack_1 = require("webpack");
40
41
  const sass_service_1 = require("../../sass/sass-service");
41
42
  const plugins_1 = require("../plugins");
42
43
  const css_optimizer_plugin_1 = require("../plugins/css-optimizer-plugin");
@@ -103,11 +104,18 @@ function getStylesConfig(wco) {
103
104
  'To opt-out of the deprecated behaviour, please migrate to another stylesheet language.');
104
105
  }
105
106
  const sassImplementation = new sass_service_1.SassWorkerImplementation();
107
+ const sassTildeUsageMessage = new Set();
106
108
  extraPlugins.push({
107
109
  apply(compiler) {
108
110
  compiler.hooks.shutdown.tap('sass-worker', () => {
109
111
  sassImplementation.close();
110
112
  });
113
+ compiler.hooks.afterCompile.tap('sass-worker', (compilation) => {
114
+ for (const message of sassTildeUsageMessage) {
115
+ compilation.warnings.push(new webpack_1.WebpackError(message));
116
+ }
117
+ sassTildeUsageMessage.clear();
118
+ });
111
119
  },
112
120
  });
113
121
  const assetNameTemplate = (0, helpers_1.assetNameTemplateFactory)(hashFormat);
@@ -245,6 +253,12 @@ function getStylesConfig(wco) {
245
253
  implementation: sassImplementation,
246
254
  sourceMap: true,
247
255
  sassOptions: {
256
+ importer: (url, from) => {
257
+ if (url.charAt(0) === '~') {
258
+ sassTildeUsageMessage.add(`'${from}' imports '${url}' with a tilde. Usage of '~' in imports is deprecated.`);
259
+ }
260
+ return null;
261
+ },
248
262
  // Prevent use of `fibers` package as it no longer works in newer Node.js versions
249
263
  fiber: false,
250
264
  // bootstrap-sass requires a minimum precision of 8
@@ -277,6 +291,12 @@ function getStylesConfig(wco) {
277
291
  implementation: sassImplementation,
278
292
  sourceMap: true,
279
293
  sassOptions: {
294
+ importer: (url, from) => {
295
+ if (url.charAt(0) === '~') {
296
+ sassTildeUsageMessage.add(`'${from}' imports '${url}' with a tilde. Usage of '~' in imports is deprecated.`);
297
+ }
298
+ return null;
299
+ },
280
300
  // Prevent use of `fibers` package as it no longer works in newer Node.js versions
281
301
  fiber: false,
282
302
  indentedSyntax: true,
@@ -9,7 +9,6 @@ import type { Compiler } from 'webpack';
9
9
  export interface ServiceWorkerPluginOptions {
10
10
  projectRoot: string;
11
11
  root: string;
12
- outputPath: string;
13
12
  baseHref?: string;
14
13
  ngswConfigPath?: string;
15
14
  }
@@ -14,13 +14,31 @@ class ServiceWorkerPlugin {
14
14
  this.options = options;
15
15
  }
16
16
  apply(compiler) {
17
- compiler.hooks.done.tapPromise('angular-service-worker', async (_compilation) => {
18
- const { projectRoot, root, baseHref = '', ngswConfigPath, outputPath } = this.options;
19
- await (0, service_worker_1.augmentAppWithServiceWorker)(projectRoot, root, outputPath, baseHref, ngswConfigPath,
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- compiler.inputFileSystem.promises,
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- compiler.outputFileSystem.promises);
17
+ compiler.hooks.done.tapPromise('angular-service-worker', async (stats) => {
18
+ if (stats.hasErrors()) {
19
+ // Don't generate a service worker if the compilation has errors.
20
+ // When there are errors some files will not be emitted which would cause other errors down the line such as readdir failures.
21
+ return;
22
+ }
23
+ const { projectRoot, root, baseHref = '', ngswConfigPath } = this.options;
24
+ const { compilation } = stats;
25
+ // We use the output path from the compilation instead of build options since during
26
+ // localization the output path is modified to a temp directory.
27
+ // See: https://github.com/angular/angular-cli/blob/7e64b1537d54fadb650559214fbb12707324cd75/packages/angular_devkit/build_angular/src/utils/i18n-options.ts#L251-L252
28
+ const outputPath = compilation.outputOptions.path;
29
+ if (!outputPath) {
30
+ throw new Error('Compilation output path cannot be empty.');
31
+ }
32
+ try {
33
+ await (0, service_worker_1.augmentAppWithServiceWorker)(projectRoot, root, outputPath, baseHref, ngswConfigPath,
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ compiler.inputFileSystem.promises,
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ compiler.outputFileSystem.promises);
38
+ }
39
+ catch (error) {
40
+ compilation.errors.push(new compilation.compiler.webpack.WebpackError(`Failed to generate service worker - ${error instanceof Error ? error.message : error}`));
41
+ }
24
42
  });
25
43
  }
26
44
  }
@@ -331,7 +331,7 @@ function statsErrorsToString(json, statsConfig) {
331
331
  // See: https://github.com/webpack/webpack/issues/15980
332
332
  const message = statsConfig.errorStack
333
333
  ? error.message
334
- : (_b = (_a = /[\s\S]+?(?=[\n\s]+at)/.exec(error.message)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : error.message;
334
+ : (_b = (_a = /[\s\S]+?(?=\n+\s+at\s)/.exec(error.message)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : error.message;
335
335
  if (!/^error/i.test(message)) {
336
336
  output += r('Error: ');
337
337
  }