@angular-devkit/build-angular 12.0.0 → 12.0.4

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 (46) hide show
  1. package/package.json +21 -21
  2. package/src/browser/index.js +1 -3
  3. package/src/browser/schema.d.ts +1 -1
  4. package/src/browser/schema.json +1 -1
  5. package/src/dev-server/index.js +38 -37
  6. package/src/dev-server/schema.d.ts +2 -1
  7. package/src/dev-server/schema.json +1 -1
  8. package/src/extract-i18n/index.js +6 -3
  9. package/src/karma/index.js +1 -0
  10. package/src/karma/schema.d.ts +1 -1
  11. package/src/karma/schema.json +1 -1
  12. package/src/karma/tests/setup.d.ts +18 -0
  13. package/src/karma/tests/setup.js +29 -0
  14. package/src/sass/sass-service.d.ts +50 -0
  15. package/src/sass/sass-service.js +185 -0
  16. package/src/sass/worker.d.ts +8 -0
  17. package/src/sass/worker.js +49 -0
  18. package/src/server/schema.d.ts +1 -1
  19. package/src/server/schema.json +1 -1
  20. package/src/utils/action-executor.js +2 -2
  21. package/src/utils/environment-options.d.ts +1 -0
  22. package/src/utils/environment-options.js +12 -1
  23. package/src/utils/index.d.ts +0 -1
  24. package/src/utils/index.js +0 -1
  25. package/src/utils/service-worker.js +1 -1
  26. package/src/utils/spinner.d.ts +2 -0
  27. package/src/utils/spinner.js +14 -0
  28. package/src/webpack/configs/common.js +36 -44
  29. package/src/webpack/configs/server.js +8 -0
  30. package/src/webpack/configs/stats.d.ts +6 -14
  31. package/src/webpack/configs/stats.js +5 -8
  32. package/src/webpack/configs/styles.js +54 -7
  33. package/src/webpack/plugins/index-html-webpack-plugin.js +1 -1
  34. package/src/webpack/plugins/index.d.ts +0 -1
  35. package/src/webpack/plugins/index.js +1 -3
  36. package/src/webpack/plugins/karma/karma-context.html +1 -1
  37. package/src/webpack/plugins/karma/karma-debug.html +1 -1
  38. package/src/webpack/plugins/karma/karma.js +1 -1
  39. package/src/webpack/plugins/postcss-cli-resources.js +1 -1
  40. package/src/webpack/utils/async-chunks.js +11 -11
  41. package/src/webpack/utils/stats.d.ts +2 -2
  42. package/src/webpack/utils/stats.js +16 -9
  43. package/src/utils/workers.d.ts +0 -22
  44. package/src/utils/workers.js +0 -26
  45. package/src/webpack/plugins/optimize-css-webpack-plugin.d.ts +0 -17
  46. package/src/webpack/plugins/optimize-css-webpack-plugin.js +0 -106
@@ -22,24 +22,24 @@ function markAsyncChunksNonInitial(webpackStats, extraEntryPoints) {
22
22
  // **cannot** be loaded in main bundle.
23
23
  const asyncChunkIds = extraEntryPoints
24
24
  .filter((entryPoint) => !entryPoint.inject)
25
- .flatMap((entryPoint) => entryPoints[entryPoint.bundleName].chunks);
25
+ .flatMap((entryPoint) => { var _a; return (_a = entryPoints[entryPoint.bundleName].chunks) === null || _a === void 0 ? void 0 : _a.filter((n) => n !== 'runtime'); });
26
26
  // Find chunks for each ID.
27
- const asyncChunks = asyncChunkIds
28
- .map((chunkId) => {
27
+ const asyncChunks = asyncChunkIds.map((chunkId) => {
29
28
  const chunk = chunks.find((chunk) => chunk.id === chunkId);
30
29
  if (!chunk) {
31
30
  throw new Error(`Failed to find chunk (${chunkId}) in set:\n${JSON.stringify(chunks)}`);
32
31
  }
33
32
  return chunk;
34
- })
35
- // All Webpack chunks are dependent on `runtime`, which is never an async
36
- // entry point, simply ignore this one.
37
- .filter((chunk) => { var _a; return !!((_a = chunk.names) === null || _a === void 0 ? void 0 : _a.includes('runtime')); });
33
+ });
38
34
  // A chunk is considered `initial` only if Webpack already belives it to be initial
39
35
  // and the application developer did not mark it async via an extra entry point.
40
- return chunks.map((chunk) => ({
41
- ...chunk,
42
- initial: chunk.initial && !asyncChunks.find((asyncChunk) => asyncChunk === chunk),
43
- }));
36
+ return chunks.map((chunk) => {
37
+ return asyncChunks.find((asyncChunk) => asyncChunk === chunk)
38
+ ? {
39
+ ...chunk,
40
+ initial: false,
41
+ }
42
+ : chunk;
43
+ });
44
44
  }
45
45
  exports.markAsyncChunksNonInitial = markAsyncChunksNonInitial;
@@ -8,6 +8,7 @@
8
8
  import { WebpackLoggingCallback } from '@angular-devkit/build-webpack';
9
9
  import { logging } from '@angular-devkit/core';
10
10
  import { Configuration, StatsCompilation } from 'webpack';
11
+ import { Schema as BrowserBuilderOptions } from '../../browser/schema';
11
12
  export declare function formatSize(size: number): string;
12
13
  export declare type BundleStatsData = [files: string, names: string, size: number | string];
13
14
  export declare type ChunkType = 'modern' | 'legacy' | 'unknown';
@@ -20,7 +21,6 @@ export declare function generateBundleStats(info: {
20
21
  size?: number;
21
22
  files?: string[];
22
23
  names?: string[];
23
- entry?: boolean;
24
24
  initial?: boolean;
25
25
  rendered?: boolean;
26
26
  chunkType?: ChunkType;
@@ -30,5 +30,5 @@ export declare function statsWarningsToString(json: StatsCompilation, statsConfi
30
30
  export declare function statsErrorsToString(json: StatsCompilation, statsConfig: any): string;
31
31
  export declare function statsHasErrors(json: StatsCompilation): boolean;
32
32
  export declare function statsHasWarnings(json: StatsCompilation): boolean;
33
- export declare function createWebpackLoggingCallback(verbose: boolean, logger: logging.LoggerApi): WebpackLoggingCallback;
33
+ export declare function createWebpackLoggingCallback(options: BrowserBuilderOptions, logger: logging.LoggerApi): WebpackLoggingCallback;
34
34
  export declare function webpackStatsLogger(logger: logging.LoggerApi, json: StatsCompilation, config: Configuration, bundleStats?: BundleStats[]): void;
@@ -12,6 +12,9 @@ const core_1 = require("@angular-devkit/core");
12
12
  const path = require("path");
13
13
  const textTable = require("text-table");
14
14
  const color_1 = require("../../utils/color");
15
+ const stats_1 = require("../configs/stats");
16
+ const async_chunks_1 = require("./async-chunks");
17
+ const helpers_1 = require("./helpers");
15
18
  function formatSize(size) {
16
19
  if (size <= 0) {
17
20
  return '0 bytes';
@@ -29,7 +32,7 @@ function generateBundleStats(info) {
29
32
  const size = typeof info.size === 'number' ? info.size : '-';
30
33
  const files = (_b = (_a = info.files) === null || _a === void 0 ? void 0 : _a.filter((f) => !f.endsWith('.map')).map((f) => path.basename(f)).join(', ')) !== null && _b !== void 0 ? _b : '';
31
34
  const names = ((_c = info.names) === null || _c === void 0 ? void 0 : _c.length) ? info.names.join(', ') : '-';
32
- const initial = !!(info.entry || info.initial);
35
+ const initial = !!info.initial;
33
36
  const chunkType = info.chunkType || 'unknown';
34
37
  return {
35
38
  chunkType,
@@ -254,18 +257,22 @@ function statsHasWarnings(json) {
254
257
  return !!(((_a = json.warnings) === null || _a === void 0 ? void 0 : _a.length) || ((_b = json.children) === null || _b === void 0 ? void 0 : _b.some((c) => { var _a; return (_a = c.warnings) === null || _a === void 0 ? void 0 : _a.length; })));
255
258
  }
256
259
  exports.statsHasWarnings = statsHasWarnings;
257
- function createWebpackLoggingCallback(verbose, logger) {
260
+ function createWebpackLoggingCallback(options, logger) {
261
+ const { verbose = false, scripts = [], styles = [] } = options;
262
+ const extraEntryPoints = [
263
+ ...helpers_1.normalizeExtraEntryPoints(styles, 'styles'),
264
+ ...helpers_1.normalizeExtraEntryPoints(scripts, 'scripts'),
265
+ ];
258
266
  return (stats, config) => {
259
267
  if (verbose) {
260
268
  logger.info(stats.toString(config.stats));
261
269
  }
262
- webpackStatsLogger(logger, stats.toJson({
263
- errors: true,
264
- warnings: true,
265
- builtAt: true,
266
- assets: true,
267
- chunks: true,
268
- }), config);
270
+ const rawStats = stats.toJson(stats_1.getWebpackStatsConfig(false));
271
+ const webpackStats = {
272
+ ...rawStats,
273
+ chunks: async_chunks_1.markAsyncChunksNonInitial(rawStats, extraEntryPoints),
274
+ };
275
+ webpackStatsLogger(logger, webpackStats, config);
269
276
  };
270
277
  }
271
278
  exports.createWebpackLoggingCallback = createWebpackLoggingCallback;
@@ -1,22 +0,0 @@
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
- /**
9
- * Use CPU count -1 with limit to 7 for workers not to clog the system.
10
- * Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available.
11
- * This cause `Error: Call retries were exceeded` errors when trying to use them.
12
- *
13
- * See:
14
- *
15
- * https://github.com/nodejs/node/issues/28762
16
- *
17
- * https://github.com/webpack-contrib/terser-webpack-plugin/issues/143
18
- *
19
- * https://github.com/angular/angular-cli/issues/16860#issuecomment-588828079
20
- *
21
- */
22
- export declare const maxWorkers: number;
@@ -1,26 +0,0 @@
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.maxWorkers = void 0;
11
- const os_1 = require("os");
12
- /**
13
- * Use CPU count -1 with limit to 7 for workers not to clog the system.
14
- * Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available.
15
- * This cause `Error: Call retries were exceeded` errors when trying to use them.
16
- *
17
- * See:
18
- *
19
- * https://github.com/nodejs/node/issues/28762
20
- *
21
- * https://github.com/webpack-contrib/terser-webpack-plugin/issues/143
22
- *
23
- * https://github.com/angular/angular-cli/issues/16860#issuecomment-588828079
24
- *
25
- */
26
- exports.maxWorkers = Math.max(Math.min(os_1.cpus().length, 8) - 1, 1);
@@ -1,17 +0,0 @@
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 { Compiler } from 'webpack';
9
- export interface OptimizeCssWebpackPluginOptions {
10
- sourceMap: boolean;
11
- test: (file: string) => boolean;
12
- }
13
- export declare class OptimizeCssWebpackPlugin {
14
- private readonly _options;
15
- constructor(options: Partial<OptimizeCssWebpackPluginOptions>);
16
- apply(compiler: Compiler): void;
17
- }
@@ -1,106 +0,0 @@
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.OptimizeCssWebpackPlugin = void 0;
11
- const cssNano = require("cssnano");
12
- const webpack_1 = require("webpack");
13
- const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
14
- const PLUGIN_NAME = 'optimize-css-webpack-plugin';
15
- function hook(compiler, action) {
16
- compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
17
- compilation.hooks.processAssets.tapPromise({
18
- name: PLUGIN_NAME,
19
- stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
20
- }, (assets) => action(compilation, Object.keys(assets)));
21
- });
22
- }
23
- class OptimizeCssWebpackPlugin {
24
- constructor(options) {
25
- this._options = {
26
- sourceMap: false,
27
- test: (file) => file.endsWith('.css'),
28
- ...options,
29
- };
30
- }
31
- apply(compiler) {
32
- hook(compiler, (compilation, assetsURI) => {
33
- const files = [...compilation.additionalChunkAssets, ...assetsURI];
34
- const actions = files
35
- .filter((file) => this._options.test(file))
36
- .map(async (file) => {
37
- const asset = compilation.assets[file];
38
- if (!asset) {
39
- return;
40
- }
41
- let content;
42
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- let map;
44
- if (this._options.sourceMap && asset.sourceAndMap) {
45
- const sourceAndMap = asset.sourceAndMap({});
46
- content = sourceAndMap.source;
47
- map = sourceAndMap.map;
48
- }
49
- else {
50
- content = asset.source();
51
- }
52
- if (typeof content !== 'string') {
53
- content = content.toString();
54
- }
55
- if (content.length === 0) {
56
- return;
57
- }
58
- const cssNanoOptions = {
59
- preset: [
60
- 'default',
61
- {
62
- // Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.
63
- svgo: false,
64
- // Disable `calc` optimizations, due to several issues. #16910, #16875, #17890
65
- calc: false,
66
- // Disable CSS rules sorted due to several issues #20693, https://github.com/ionic-team/ionic-framework/issues/23266 and https://github.com/cssnano/cssnano/issues/1054
67
- cssDeclarationSorter: false,
68
- },
69
- ],
70
- };
71
- const postCssOptions = {
72
- from: file,
73
- map: map && { annotation: false, prev: map },
74
- };
75
- try {
76
- const output = await new Promise((resolve, reject) => {
77
- // @types/cssnano are not up to date with version 5.
78
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
- cssNano(cssNanoOptions)
80
- .process(content, postCssOptions)
81
- .then(resolve)
82
- .catch((err) => reject(err));
83
- });
84
- for (const { text } of output.warnings()) {
85
- webpack_diagnostics_1.addWarning(compilation, text);
86
- }
87
- let newSource;
88
- if (output.map) {
89
- newSource = new webpack_1.sources.SourceMapSource(output.css, file, output.map.toString(), content, map);
90
- }
91
- else {
92
- newSource = new webpack_1.sources.RawSource(output.css);
93
- }
94
- compilation.assets[file] = newSource;
95
- }
96
- catch (error) {
97
- webpack_diagnostics_1.addError(compilation, error.message);
98
- return;
99
- }
100
- });
101
- // eslint-disable-next-line @typescript-eslint/no-empty-function
102
- return Promise.all(actions).then(() => { });
103
- });
104
- }
105
- }
106
- exports.OptimizeCssWebpackPlugin = OptimizeCssWebpackPlugin;