@angular-devkit/build-angular 0.1102.4 → 0.1102.8

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,16 +1,16 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-angular",
3
- "version": "0.1102.4",
3
+ "version": "0.1102.8",
4
4
  "description": "Angular Webpack Build Facade",
5
5
  "experimental": true,
6
6
  "main": "src/index.js",
7
7
  "typings": "src/index.d.ts",
8
8
  "builders": "builders.json",
9
9
  "dependencies": {
10
- "@angular-devkit/architect": "0.1102.4",
11
- "@angular-devkit/build-optimizer": "0.1102.4",
12
- "@angular-devkit/build-webpack": "0.1102.4",
13
- "@angular-devkit/core": "11.2.4",
10
+ "@angular-devkit/architect": "0.1102.8",
11
+ "@angular-devkit/build-optimizer": "0.1102.8",
12
+ "@angular-devkit/build-webpack": "0.1102.8",
13
+ "@angular-devkit/core": "11.2.8",
14
14
  "@babel/core": "7.12.10",
15
15
  "@babel/generator": "7.12.11",
16
16
  "@babel/plugin-transform-async-to-generator": "7.12.1",
@@ -18,8 +18,9 @@
18
18
  "@babel/preset-env": "7.12.11",
19
19
  "@babel/runtime": "7.12.5",
20
20
  "@babel/template": "7.12.7",
21
+ "@discoveryjs/json-ext": "0.5.2",
21
22
  "@jsdevtools/coverage-istanbul-loader": "3.0.5",
22
- "@ngtools/webpack": "11.2.4",
23
+ "@ngtools/webpack": "11.2.8",
23
24
  "ansi-colors": "4.1.1",
24
25
  "autoprefixer": "10.2.4",
25
26
  "babel-loader": "8.2.2",
@@ -31,7 +32,7 @@
31
32
  "core-js": "3.8.3",
32
33
  "critters": "0.0.7",
33
34
  "css-loader": "5.0.1",
34
- "cssnano": "4.1.10",
35
+ "cssnano": "4.1.11",
35
36
  "file-loader": "6.2.0",
36
37
  "find-cache-dir": "3.3.1",
37
38
  "glob": "7.1.6",
@@ -49,6 +49,7 @@ exports.default = babel_loader_1.custom(() => {
49
49
  compact: false,
50
50
  cacheCompression: false,
51
51
  sourceType: 'unambiguous',
52
+ inputSourceMap: false,
52
53
  });
53
54
  return {
54
55
  async customOptions({ i18n, scriptTarget, ...rawOptions }, { source }) {
@@ -78,7 +79,7 @@ exports.default = babel_loader_1.custom(() => {
78
79
  customOptions.forceES5 = !/\.tsx?$/.test(this.resourcePath);
79
80
  }
80
81
  else if (esTarget >= typescript_1.ScriptTarget.ES2017) {
81
- customOptions.forceAsyncTransformation = source.includes('async');
82
+ customOptions.forceAsyncTransformation = !/[\\\/]fesm2015[\\\/]/.test(this.resourcePath) && source.includes('async');
82
83
  }
83
84
  shouldProcess || (shouldProcess = customOptions.forceAsyncTransformation || customOptions.forceES5);
84
85
  }
@@ -110,6 +111,9 @@ exports.default = babel_loader_1.custom(() => {
110
111
  config(configuration, { customOptions }) {
111
112
  return {
112
113
  ...configuration.options,
114
+ // Workaround for https://github.com/babel/babel-loader/pull/896 is available
115
+ // Delete once the above PR is released
116
+ inputSourceMap: (configuration.options.inputSourceMap || false),
113
117
  presets: [
114
118
  ...(configuration.options.presets || []),
115
119
  [
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google Inc. 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
+ // Workaround for https://github.com/bazelbuild/rules_nodejs/issues/1033
10
+ // Alternative approach instead of https://github.com/angular/angular/pull/33226
11
+ declare module '@babel/core' {
12
+ export * from '@types/babel__core';
13
+ }
14
+ declare module '@babel/generator' {
15
+ export { default } from '@types/babel__generator';
16
+ }
17
+ declare module '@babel/traverse' {
18
+ export { default } from '@types/babel__traverse';
19
+ }
20
+ declare module '@babel/template' {
21
+ export { default } from '@types/babel__template';
22
+ }
@@ -499,6 +499,7 @@
499
499
  },
500
500
  "bundleName": {
501
501
  "type": "string",
502
+ "pattern": "^[\\w\\-.]*$",
502
503
  "description": "The bundle name for this extra entry point."
503
504
  },
504
505
  "inject": {
@@ -238,6 +238,7 @@
238
238
  },
239
239
  "bundleName": {
240
240
  "type": "string",
241
+ "pattern": "^[\\w\\-.]*$",
241
242
  "description": "The bundle name for this extra entry point."
242
243
  },
243
244
  "inject": {
package/src/test-utils.js CHANGED
@@ -47,6 +47,13 @@ async function browserBuild(architect, host, target, overrides, scheduleOptions)
47
47
  const run = await architect.scheduleTarget(target, overrides, scheduleOptions);
48
48
  const output = (await run.result);
49
49
  expect(output.success).toBe(true);
50
+ if (!output.success) {
51
+ await run.stop();
52
+ return {
53
+ output,
54
+ files: {},
55
+ };
56
+ }
50
57
  expect(output.outputPaths[0]).not.toBeUndefined();
51
58
  const outputPath = core_1.normalize(output.outputPaths[0]);
52
59
  const fileNames = await host.list(outputPath).toPromise();
package/src/typings.d.ts CHANGED
@@ -5,18 +5,6 @@
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
-
9
- // Workaround for https://github.com/bazelbuild/rules_nodejs/issues/1033
10
- // Alternative approach instead of https://github.com/angular/angular/pull/33226
11
- declare module '@babel/core' {
12
- export * from '@types/babel__core';
13
- }
14
- declare module '@babel/generator' {
15
- export { default } from '@types/babel__generator';
16
- }
17
- declare module '@babel/traverse' {
18
- export { default } from '@types/babel__traverse';
19
- }
20
- declare module '@babel/template' {
21
- export { default } from '@types/babel__template';
8
+ declare module '@discoveryjs/json-ext' {
9
+ export function stringifyStream(value: unknown): import('stream').Readable;
22
10
  }
@@ -23,9 +23,8 @@ var ThresholdSeverity;
23
23
  })(ThresholdSeverity = exports.ThresholdSeverity || (exports.ThresholdSeverity = {}));
24
24
  var DifferentialBuildType;
25
25
  (function (DifferentialBuildType) {
26
- // FIXME: this should match the actual file suffix and not hardcoded.
27
- DifferentialBuildType["ORIGINAL"] = "es2015";
28
- DifferentialBuildType["DOWNLEVEL"] = "es5";
26
+ DifferentialBuildType["ORIGINAL"] = "original";
27
+ DifferentialBuildType["DOWNLEVEL"] = "downlevel";
29
28
  })(DifferentialBuildType || (DifferentialBuildType = {}));
30
29
  function* calculateThresholds(budget) {
31
30
  if (budget.maximumWarning) {
@@ -161,14 +160,15 @@ class BundleCalculator extends Calculator {
161
160
  if (!budgetName) {
162
161
  return [];
163
162
  }
163
+ const buildTypeLabels = getBuildTypeLabels(this.processResults);
164
164
  // The chunk may or may not have differential builds. Compute the size for
165
165
  // each then check afterwards if they are all the same.
166
166
  const buildSizes = Object.values(DifferentialBuildType).map((buildType) => {
167
167
  const size = this.chunks
168
- .filter(chunk => chunk.names.indexOf(budgetName) !== -1)
168
+ .filter(chunk => chunk.names.includes(budgetName))
169
169
  .map(chunk => this.calculateChunkSize(chunk, buildType))
170
170
  .reduce((l, r) => l + r, 0);
171
- return { size, label: `bundle ${this.budget.name}-${buildType}` };
171
+ return { size, label: `bundle ${this.budget.name}-${buildTypeLabels[buildType]}` };
172
172
  });
173
173
  // If this bundle was not actually generated by a differential build, then
174
174
  // merge the results into a single value.
@@ -185,9 +185,10 @@ class BundleCalculator extends Calculator {
185
185
  */
186
186
  class InitialCalculator extends Calculator {
187
187
  calculate() {
188
+ const buildTypeLabels = getBuildTypeLabels(this.processResults);
188
189
  const buildSizes = Object.values(DifferentialBuildType).map((buildType) => {
189
190
  return {
190
- label: `bundle initial-${buildType}`,
191
+ label: `bundle initial-${buildTypeLabels[buildType]}`,
191
192
  size: this.chunks
192
193
  .filter(chunk => chunk.initial)
193
194
  .map(chunk => this.calculateChunkSize(chunk, buildType))
@@ -353,3 +354,17 @@ function mergeDifferentialBuildSizes(buildSizes, mergeLabel) {
353
354
  function allEquivalent(items) {
354
355
  return new Set(items).size < 2;
355
356
  }
357
+ function getBuildTypeLabels(processResults) {
358
+ var _a, _b, _c;
359
+ const fileNameSuffixRegExp = /\-(es20\d{2}|esnext)\./;
360
+ const originalFileName = (_b = (_a = processResults
361
+ .find(({ original }) => (original === null || original === void 0 ? void 0 : original.filename) && fileNameSuffixRegExp.test(original.filename))) === null || _a === void 0 ? void 0 : _a.original) === null || _b === void 0 ? void 0 : _b.filename;
362
+ let originalSuffix;
363
+ if (originalFileName) {
364
+ originalSuffix = (_c = fileNameSuffixRegExp.exec(originalFileName)) === null || _c === void 0 ? void 0 : _c[1];
365
+ }
366
+ return {
367
+ [DifferentialBuildType.DOWNLEVEL]: 'es5',
368
+ [DifferentialBuildType.ORIGINAL]: originalSuffix || 'es2015',
369
+ };
370
+ }
@@ -1,3 +1,4 @@
1
+ /// <reference types="packages/angular_devkit/build_angular/src/babel-bazel" />
1
2
  /**
2
3
  * @license
3
4
  * Copyright Google Inc. All Rights Reserved.
@@ -14,12 +14,12 @@ const fs_1 = require("fs");
14
14
  const path = require("path");
15
15
  const typescript_1 = require("typescript");
16
16
  const webpack_1 = require("webpack");
17
- const webpack_sources_1 = require("webpack-sources");
18
17
  const utils_1 = require("../../utils");
19
18
  const cache_path_1 = require("../../utils/cache-path");
20
19
  const environment_options_1 = require("../../utils/environment-options");
21
20
  const find_up_1 = require("../../utils/find-up");
22
21
  const spinner_1 = require("../../utils/spinner");
22
+ const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
23
23
  const webpack_version_1 = require("../../utils/webpack-version");
24
24
  const plugins_1 = require("../plugins");
25
25
  const helpers_1 = require("../utils/helpers");
@@ -257,9 +257,20 @@ function getCommonConfig(wco) {
257
257
  if (buildOptions.statsJson) {
258
258
  extraPlugins.push(new (class {
259
259
  apply(compiler) {
260
- compiler.hooks.emit.tap('angular-cli-stats', compilation => {
261
- const data = JSON.stringify(compilation.getStats().toJson('verbose'), undefined, 2);
262
- compilation.assets['stats.json'] = new webpack_sources_1.RawSource(data);
260
+ compiler.hooks.done.tapPromise('angular-cli-stats', async (stats) => {
261
+ const { stringifyStream } = await Promise.resolve().then(() => require('@discoveryjs/json-ext'));
262
+ const data = stats.toJson('verbose');
263
+ const statsOutputPath = path.join(stats.compilation.outputOptions.path, 'stats.json');
264
+ try {
265
+ await fs_1.promises.mkdir(path.dirname(statsOutputPath), { recursive: true });
266
+ await new Promise((resolve, reject) => stringifyStream(data)
267
+ .pipe(fs_1.createWriteStream(statsOutputPath))
268
+ .on('close', resolve)
269
+ .on('error', reject));
270
+ }
271
+ catch (error) {
272
+ webpack_diagnostics_1.addError(stats.compilation, `Unable to write stats file: ${error.message || 'unknown error'}`);
273
+ }
263
274
  });
264
275
  }
265
276
  })());
@@ -58,7 +58,7 @@ export declare class NgBuildAnalyticsPlugin {
58
58
  protected _checkTsNormalModule(module: NormalModule): void;
59
59
  protected _checkNgFactoryNormalModule(module: NormalModule): void;
60
60
  protected _collectErrors(stats: Stats): void;
61
- protected _collectBundleStats(json: any): void;
61
+ protected _collectBundleStats(compilation: compilation.Compilation): void;
62
62
  /************************************************************************************************
63
63
  * The next section is all the different Webpack hooks for this plugin.
64
64
  */
@@ -164,15 +164,15 @@ class NgBuildAnalyticsPlugin {
164
164
  }
165
165
  }
166
166
  }
167
- // We can safely disable no any here since we know the format of the JSON output from webpack.
168
- // tslint:disable-next-line:no-any
169
- _collectBundleStats(json) {
170
- json.chunks
167
+ _collectBundleStats(compilation) {
168
+ // `compilation.chunks` is a Set in Webpack 5
169
+ const chunks = Array.from(compilation.chunks);
170
+ chunks
171
171
  .filter((chunk) => chunk.rendered)
172
172
  .forEach((chunk) => {
173
- const asset = json.assets.find((x) => x.name == chunk.files[0]);
174
- const size = asset ? asset.size : 0;
175
- if (chunk.entry || chunk.initial) {
173
+ const asset = compilation.assets[chunk.files[0]];
174
+ const size = asset ? asset.size() : 0;
175
+ if (chunk.canBeInitial()) {
176
176
  this._stats.initialChunkSize += size;
177
177
  }
178
178
  else {
@@ -182,23 +182,25 @@ class NgBuildAnalyticsPlugin {
182
182
  this._stats.totalChunkCount++;
183
183
  this._stats.totalChunkSize += size;
184
184
  });
185
- json.assets
185
+ Object.entries(compilation.assets)
186
186
  // Filter out chunks. We only count assets that are not JS.
187
- .filter((a) => {
188
- return json.chunks.every((chunk) => chunk.files[0] != a.name);
187
+ .filter(([name]) => {
188
+ return chunks.every((chunk) => chunk.files[0] != name);
189
189
  })
190
- .forEach((a) => {
191
- this._stats.assetSize += (a.size || 0);
190
+ .forEach(([, asset]) => {
191
+ this._stats.assetSize += asset.size();
192
192
  this._stats.assetCount++;
193
193
  });
194
- for (const asset of json.assets) {
195
- if (asset.name == 'polyfill') {
196
- this._stats.polyfillSize += asset.size || 0;
194
+ for (const [name, asset] of Object.entries(compilation.assets)) {
195
+ if (name == 'polyfill') {
196
+ this._stats.polyfillSize += asset.size();
197
197
  }
198
198
  }
199
- for (const chunk of json.chunks) {
199
+ for (const chunk of compilation.chunks) {
200
200
  if (chunk.files[0] && chunk.files[0].endsWith('.css')) {
201
- this._stats.cssSize += chunk.size || 0;
201
+ const asset = compilation.assets[chunk.files[0]];
202
+ const size = asset ? asset.size() : 0;
203
+ this._stats.cssSize += size;
202
204
  }
203
205
  }
204
206
  }
@@ -237,7 +239,7 @@ class NgBuildAnalyticsPlugin {
237
239
  }
238
240
  _done(stats) {
239
241
  this._collectErrors(stats);
240
- this._collectBundleStats(stats.toJson());
242
+ this._collectBundleStats(stats.compilation);
241
243
  if (this._built) {
242
244
  this._reportRebuildMetrics(stats);
243
245
  }
@@ -164,10 +164,9 @@ const init = (config, emitter) => {
164
164
  let lastCompilationHash;
165
165
  const statsConfig = stats_2.getWebpackStatsConfig();
166
166
  compiler.hooks.done.tap('karma', (stats) => {
167
- if (stats.compilation.errors.length > 0) {
168
- const json = stats.toJson(config.stats);
167
+ if (stats.hasErrors()) {
169
168
  // Print compilation errors.
170
- logger.error(stats_1.statsErrorsToString(json, statsConfig));
169
+ logger.error(stats_1.statsErrorsToString(stats.compilation, statsConfig));
171
170
  lastCompilationHash = undefined;
172
171
  // Emit a failure build event if there are compilation errors.
173
172
  failureCb();