@angular-devkit/build-angular 0.1000.0-rc.5 → 0.1000.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,16 +1,16 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-angular",
3
- "version": "0.1000.0-rc.5",
3
+ "version": "0.1000.3",
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.1000.0-rc.5",
11
- "@angular-devkit/build-optimizer": "0.1000.0-rc.5",
12
- "@angular-devkit/build-webpack": "0.1000.0-rc.5",
13
- "@angular-devkit/core": "10.0.0-rc.5",
10
+ "@angular-devkit/architect": "0.1000.3",
11
+ "@angular-devkit/build-optimizer": "0.1000.3",
12
+ "@angular-devkit/build-webpack": "0.1000.3",
13
+ "@angular-devkit/core": "10.0.3",
14
14
  "@babel/core": "7.9.6",
15
15
  "@babel/generator": "7.9.6",
16
16
  "@babel/plugin-transform-runtime": "7.9.6",
@@ -18,7 +18,7 @@
18
18
  "@babel/runtime": "7.9.6",
19
19
  "@babel/template": "7.8.6",
20
20
  "@jsdevtools/coverage-istanbul-loader": "3.0.3",
21
- "@ngtools/webpack": "10.0.0-rc.5",
21
+ "@ngtools/webpack": "10.0.3",
22
22
  "ajv": "6.12.2",
23
23
  "autoprefixer": "9.8.0",
24
24
  "babel-loader": "8.1.0",
@@ -26,7 +26,7 @@
26
26
  "cacache": "15.0.3",
27
27
  "caniuse-lite": "^1.0.30001032",
28
28
  "circular-dependency-plugin": "5.2.0",
29
- "copy-webpack-plugin": "6.0.2",
29
+ "copy-webpack-plugin": "6.0.3",
30
30
  "core-js": "3.6.4",
31
31
  "css-loader": "3.5.3",
32
32
  "cssnano": "4.1.10",
@@ -226,7 +226,7 @@ function getCommonConfig(wco) {
226
226
  extraPlugins.push(new (class {
227
227
  apply(compiler) {
228
228
  compiler.hooks.emit.tap('angular-cli-stats', compilation => {
229
- const data = JSON.stringify(compilation.getStats().toJson('verbose'));
229
+ const data = JSON.stringify(compilation.getStats().toJson('verbose'), undefined, 2);
230
230
  compilation.assets['stats.json'] = new webpack_sources_1.RawSource(data);
231
231
  });
232
232
  }
@@ -17,4 +17,5 @@ export declare class CommonJsUsageWarnPlugin {
17
17
  constructor(options?: CommonJsUsageWarnPluginOptions);
18
18
  apply(compiler: Compiler): void;
19
19
  private hasCommonJsDependencies;
20
+ private rawRequestToPackageName;
20
21
  }
@@ -12,40 +12,43 @@ const path_1 = require("path");
12
12
  // Webpack doesn't export these so the deep imports can potentially break.
13
13
  const CommonJsRequireDependency = require('webpack/lib/dependencies/CommonJsRequireDependency');
14
14
  const AMDDefineDependency = require('webpack/lib/dependencies/AMDDefineDependency');
15
+ const STYLES_TEMPLATE_URL_REGEXP = /\.(html|svg|css|sass|less|styl|scss)$/;
15
16
  class CommonJsUsageWarnPlugin {
16
17
  constructor(options = {}) {
18
+ var _a;
17
19
  this.options = options;
18
20
  this.shownWarnings = new Set();
19
21
  // Allow the below depedency for HMR
20
22
  // tslint:disable-next-line: max-line-length
21
23
  // https://github.com/angular/angular-cli/blob/1e258317b1f6ec1e957ee3559cc3b28ba602f3ba/packages/angular_devkit/build_angular/src/dev-server/index.ts#L605-L638
22
- this.allowedDepedencies = [
23
- 'webpack/hot/dev-server',
24
- ];
25
- if (this.options.allowedDepedencies) {
26
- this.allowedDepedencies.push(...this.options.allowedDepedencies);
27
- }
24
+ this.allowedDepedencies = new Set(['webpack/hot/dev-server']);
25
+ (_a = this.options.allowedDepedencies) === null || _a === void 0 ? void 0 : _a.forEach(d => this.allowedDepedencies.add(d));
28
26
  }
29
27
  apply(compiler) {
30
28
  compiler.hooks.compilation.tap('CommonJsUsageWarnPlugin', compilation => {
31
29
  compilation.hooks.finishModules.tap('CommonJsUsageWarnPlugin', modules => {
32
- var _a, _b, _c, _d;
30
+ var _a, _b;
33
31
  for (const { dependencies, rawRequest, issuer } of modules) {
34
32
  if (!rawRequest ||
35
33
  rawRequest.startsWith('.') ||
36
- path_1.isAbsolute(rawRequest)) {
37
- // Skip if module is absolute or relative.
38
- continue;
39
- }
40
- if ((_a = this.allowedDepedencies) === null || _a === void 0 ? void 0 : _a.includes(rawRequest)) {
41
- // Skip as this module is allowed even if it's a CommonJS.
34
+ path_1.isAbsolute(rawRequest) ||
35
+ this.allowedDepedencies.has(rawRequest) ||
36
+ this.allowedDepedencies.has(this.rawRequestToPackageName(rawRequest)) ||
37
+ rawRequest.startsWith('@angular/common/locales/')) {
38
+ /**
39
+ * Skip when:
40
+ * - module is absolute or relative.
41
+ * - module is allowed even if it's a CommonJS.
42
+ * - module is a locale imported from '@angular/common'.
43
+ */
42
44
  continue;
43
45
  }
44
- if (this.hasCommonJsDependencies(dependencies)) {
46
+ if (this.hasCommonJsDependencies(dependencies, true)) {
45
47
  // Dependency is CommonsJS or AMD.
46
48
  // Check if it's parent issuer is also a CommonJS dependency.
47
49
  // In case it is skip as an warning will be show for the parent CommonJS dependency.
48
- if (this.hasCommonJsDependencies((_c = (_b = issuer === null || issuer === void 0 ? void 0 : issuer.issuer) === null || _b === void 0 ? void 0 : _b.dependencies) !== null && _c !== void 0 ? _c : [])) {
50
+ const parentDependencies = (_a = issuer === null || issuer === void 0 ? void 0 : issuer.issuer) === null || _a === void 0 ? void 0 : _a.dependencies;
51
+ if (parentDependencies && this.hasCommonJsDependencies(parentDependencies)) {
49
52
  continue;
50
53
  }
51
54
  // Find the main issuer (entry-point).
@@ -56,10 +59,10 @@ class CommonJsUsageWarnPlugin {
56
59
  // Only show warnings for modules from main entrypoint.
57
60
  // And if the issuer request is not from 'webpack-dev-server', as 'webpack-dev-server'
58
61
  // will require CommonJS libraries for live reloading such as 'sockjs-node'.
59
- if ((mainIssuer === null || mainIssuer === void 0 ? void 0 : mainIssuer.name) === 'main' && !((_d = issuer === null || issuer === void 0 ? void 0 : issuer.userRequest) === null || _d === void 0 ? void 0 : _d.includes('webpack-dev-server'))) {
60
- const warning = `${issuer === null || issuer === void 0 ? void 0 : issuer.userRequest} depends on ${rawRequest}. CommonJS or AMD dependencies can cause optimization bailouts.\n` +
61
- 'For more info see: https://web.dev/commonjs-larger-bundles\n' +
62
- `To disable this warning add "${rawRequest}" to the "allowedCommonJsDependencies" option under "build" options in "angular.json".`;
62
+ if ((mainIssuer === null || mainIssuer === void 0 ? void 0 : mainIssuer.name) === 'main' && !((_b = issuer === null || issuer === void 0 ? void 0 : issuer.userRequest) === null || _b === void 0 ? void 0 : _b.includes('webpack-dev-server'))) {
63
+ const warning = `${issuer === null || issuer === void 0 ? void 0 : issuer.userRequest} depends on '${rawRequest}'. ` +
64
+ 'CommonJS or AMD dependencies can cause optimization bailouts.\n' +
65
+ 'For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies';
63
66
  // Avoid showing the same warning multiple times when in 'watch' mode.
64
67
  if (!this.shownWarnings.has(warning)) {
65
68
  compilation.warnings.push(warning);
@@ -71,8 +74,27 @@ class CommonJsUsageWarnPlugin {
71
74
  });
72
75
  });
73
76
  }
74
- hasCommonJsDependencies(dependencies) {
75
- return dependencies.some(d => d instanceof CommonJsRequireDependency || d instanceof AMDDefineDependency);
77
+ hasCommonJsDependencies(dependencies, checkForStylesAndTemplatesCJS = false) {
78
+ for (const dep of dependencies) {
79
+ if (dep instanceof CommonJsRequireDependency) {
80
+ if (checkForStylesAndTemplatesCJS && STYLES_TEMPLATE_URL_REGEXP.test(dep.request)) {
81
+ // Skip in case it's a template or stylesheet
82
+ continue;
83
+ }
84
+ return true;
85
+ }
86
+ if (dep instanceof AMDDefineDependency) {
87
+ return true;
88
+ }
89
+ }
90
+ return false;
91
+ }
92
+ rawRequestToPackageName(rawRequest) {
93
+ return rawRequest.startsWith('@')
94
+ // Scoped request ex: @angular/common/locale/en -> @angular/common
95
+ ? rawRequest.split('/', 2).join('/')
96
+ // Non-scoped request ex: lodash/isEmpty -> lodash
97
+ : rawRequest.split('/', 1)[0];
76
98
  }
77
99
  }
78
100
  exports.CommonJsUsageWarnPlugin = CommonJsUsageWarnPlugin;
@@ -13,11 +13,13 @@ interface NormalModuleFactoryRequest {
13
13
  relativePath: string;
14
14
  path: string;
15
15
  descriptionFileData: {
16
- name: string;
17
- version: string;
16
+ name?: string;
17
+ version?: string;
18
18
  };
19
19
  descriptionFileRoot: string;
20
20
  descriptionFilePath: string;
21
+ directory?: boolean;
22
+ file?: boolean;
21
23
  }
22
24
  export interface DedupeModuleResolvePluginOptions {
23
25
  verbose?: boolean;
@@ -28,6 +28,15 @@ class DedupeModuleResolvePlugin {
28
28
  if (request.relativePath !== '.') {
29
29
  return;
30
30
  }
31
+ // When either of these properties is undefined. It typically means it's a link.
32
+ // In which case we shouldn't try to dedupe it.
33
+ if (request.file === undefined || request.directory === undefined) {
34
+ return;
35
+ }
36
+ // Empty name or versions are no valid primary entrypoints of a library
37
+ if (!request.descriptionFileData.name || !request.descriptionFileData.version) {
38
+ return;
39
+ }
31
40
  const moduleId = request.descriptionFileData.name + '@' + request.descriptionFileData.version;
32
41
  const prevResolvedModule = this.modules.get(moduleId);
33
42
  if (!prevResolvedModule) {
@@ -12,3 +12,5 @@ export declare function generateBuildStats(hash: string, time: number, colors: b
12
12
  export declare function statsToString(json: any, statsConfig: any): string;
13
13
  export declare function statsWarningsToString(json: any, statsConfig: any): string;
14
14
  export declare function statsErrorsToString(json: any, statsConfig: any): string;
15
+ export declare function statsHasErrors(json: any): boolean;
16
+ export declare function statsHasWarnings(json: any): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.statsErrorsToString = exports.statsWarningsToString = exports.statsToString = exports.generateBuildStats = exports.generateBundleStats = exports.formatSize = void 0;
3
+ exports.statsHasWarnings = exports.statsHasErrors = exports.statsErrorsToString = exports.statsWarningsToString = exports.statsToString = exports.generateBuildStats = exports.generateBundleStats = exports.formatSize = void 0;
4
4
  /**
5
5
  * @license
6
6
  * Copyright Google Inc. All Rights Reserved.
@@ -77,7 +77,12 @@ function statsWarningsToString(json, statsConfig) {
77
77
  const colors = statsConfig.colors;
78
78
  const rs = (x) => colors ? reset(x) : x;
79
79
  const y = (x) => colors ? bold(yellow(x)) : x;
80
- return rs('\n' + json.warnings
80
+ const warnings = [...json.warnings];
81
+ if (json.children) {
82
+ warnings.push(...json.children.map((c) => c.warnings));
83
+ }
84
+ return rs('\n' + warnings
85
+ .filter(m => !!m)
81
86
  .map((warning) => `${warning}`)
82
87
  .filter((warning) => !ERRONEOUS_WARNINGS.some((erroneous) => erroneous.test(warning)))
83
88
  .map((warning) => y(`WARNING in ${warning}`))
@@ -88,6 +93,23 @@ function statsErrorsToString(json, statsConfig) {
88
93
  const colors = statsConfig.colors;
89
94
  const rs = (x) => colors ? reset(x) : x;
90
95
  const r = (x) => colors ? bold(red(x)) : x;
91
- return rs('\n' + json.errors.map((error) => r(`ERROR in ${error}`)).join('\n'));
96
+ const errors = [...json.errors];
97
+ if (json.children) {
98
+ errors.push(...json.children.map((c) => c.errors));
99
+ }
100
+ return rs('\n' + errors
101
+ .filter(m => !!m)
102
+ .map((error) => r(`ERROR in ${error}`))
103
+ .join('\n\n'));
92
104
  }
93
105
  exports.statsErrorsToString = statsErrorsToString;
106
+ function statsHasErrors(json) {
107
+ var _a;
108
+ return json.errors.length > 0 || !!((_a = json.children) === null || _a === void 0 ? void 0 : _a.some((c) => c.errors.length));
109
+ }
110
+ exports.statsHasErrors = statsHasErrors;
111
+ function statsHasWarnings(json) {
112
+ var _a;
113
+ return json.warnings.length > 0 || !!((_a = json.children) === null || _a === void 0 ? void 0 : _a.some((c) => c.warnings.length));
114
+ }
115
+ exports.statsHasWarnings = statsHasWarnings;
@@ -93,8 +93,19 @@ function getCompilerConfig(wco) {
93
93
  return {};
94
94
  }
95
95
  async function initialize(options, context, host, webpackConfigurationTransform) {
96
+ var _a, _b;
96
97
  const originalOutputPath = options.outputPath;
97
- const { config, projectRoot, projectSourceRoot, i18n, } = await buildBrowserWebpackConfigFromContext(options, context, host, true);
98
+ // Assets are processed directly by the builder except when watching
99
+ const adjustedOptions = options.watch ? options : { ...options, assets: [] };
100
+ const { config, projectRoot, projectSourceRoot, i18n, } = await buildBrowserWebpackConfigFromContext(adjustedOptions, context, host, true);
101
+ // Validate asset option values if processed directly
102
+ if (((_a = options.assets) === null || _a === void 0 ? void 0 : _a.length) && !((_b = adjustedOptions.assets) === null || _b === void 0 ? void 0 : _b.length)) {
103
+ utils_1.normalizeAssetPatterns(options.assets, new core_1.virtualFs.SyncDelegateHost(host), core_1.normalize(context.workspaceRoot), core_1.normalize(projectRoot), projectSourceRoot === undefined ? undefined : core_1.normalize(projectSourceRoot)).forEach(({ output }) => {
104
+ if (output.startsWith('..')) {
105
+ throw new Error('An asset cannot be written to a location outside of the output path.');
106
+ }
107
+ });
108
+ }
98
109
  let transformedConfig;
99
110
  if (webpackConfigurationTransform) {
100
111
  transformedConfig = await webpackConfigurationTransform(config);
@@ -152,10 +163,10 @@ function buildWebpackBrowser(options, context, transforms = {}) {
152
163
  if (!success && useBundleDownleveling) {
153
164
  // If using bundle downleveling then there is only one build
154
165
  // If it fails show any diagnostic messages and bail
155
- if (webpackStats && webpackStats.warnings.length > 0) {
166
+ if (stats_1.statsHasWarnings(webpackStats)) {
156
167
  context.logger.warn(stats_1.statsWarningsToString(webpackStats, { colors: true }));
157
168
  }
158
- if (webpackStats && webpackStats.errors.length > 0) {
169
+ if (stats_1.statsHasErrors(webpackStats)) {
159
170
  context.logger.error(stats_1.statsErrorsToString(webpackStats, { colors: true }));
160
171
  }
161
172
  return { success };
@@ -388,16 +399,6 @@ function buildWebpackBrowser(options, context, transforms = {}) {
388
399
  finally {
389
400
  executor.stop();
390
401
  }
391
- // Copy assets
392
- if (options.assets) {
393
- try {
394
- await copy_assets_1.copyAssets(utils_1.normalizeAssetPatterns(options.assets, new core_1.virtualFs.SyncDelegateHost(host), root, core_1.normalize(projectRoot), projectSourceRoot === undefined ? undefined : core_1.normalize(projectSourceRoot)), Array.from(outputPaths.values()), context.workspaceRoot);
395
- }
396
- catch (err) {
397
- context.logger.error('Unable to copy assets: ' + err.message);
398
- return { success: false };
399
- }
400
- }
401
402
  function generateBundleInfoStats(id, bundle, chunk) {
402
403
  return stats_1.generateBundleStats({
403
404
  id,
@@ -448,13 +449,12 @@ function buildWebpackBrowser(options, context, transforms = {}) {
448
449
  break;
449
450
  default:
450
451
  assertNever(severity);
451
- break;
452
452
  }
453
453
  }
454
- if (webpackStats && webpackStats.warnings.length > 0) {
454
+ if (stats_1.statsHasWarnings(webpackStats)) {
455
455
  context.logger.warn(stats_1.statsWarningsToString(webpackStats, { colors: true }));
456
456
  }
457
- if (webpackStats && webpackStats.errors.length > 0) {
457
+ if (stats_1.statsHasErrors(webpackStats)) {
458
458
  context.logger.error(stats_1.statsErrorsToString(webpackStats, { colors: true }));
459
459
  return { success: false };
460
460
  }
@@ -471,6 +471,16 @@ function buildWebpackBrowser(options, context, transforms = {}) {
471
471
  }
472
472
  }
473
473
  }
474
+ // Copy assets
475
+ if (!options.watch && options.assets) {
476
+ try {
477
+ await copy_assets_1.copyAssets(utils_1.normalizeAssetPatterns(options.assets, new core_1.virtualFs.SyncDelegateHost(host), root, core_1.normalize(projectRoot), projectSourceRoot === undefined ? undefined : core_1.normalize(projectSourceRoot)), Array.from(outputPaths.values()), context.workspaceRoot);
478
+ }
479
+ catch (err) {
480
+ context.logger.error('Unable to copy assets: ' + err.message);
481
+ return { success: false };
482
+ }
483
+ }
474
484
  if (options.index) {
475
485
  for (const [locale, outputPath] of outputPaths.entries()) {
476
486
  let localeBaseHref;
@@ -91,7 +91,10 @@ async function process(options) {
91
91
  exclude: ['transform-typeof-symbol'],
92
92
  },
93
93
  ]],
94
- plugins: options.replacements ? [createReplacePlugin(options.replacements)] : [],
94
+ plugins: [
95
+ createIifeWrapperPlugin(),
96
+ ...(options.replacements ? [createReplacePlugin(options.replacements)] : []),
97
+ ],
95
98
  minified: environment_options_1.allowMinify && !!options.optimize,
96
99
  compact: !environment_options_1.shouldBeautify && !!options.optimize,
97
100
  sourceMaps: !!sourceMap,
@@ -335,6 +338,25 @@ function createReplacePlugin(replacements) {
335
338
  },
336
339
  };
337
340
  }
341
+ function createIifeWrapperPlugin() {
342
+ return {
343
+ visitor: {
344
+ Program: {
345
+ exit(path) {
346
+ // Save existing body and directives
347
+ const { body, directives } = path.node;
348
+ // Clear out body and directives for wrapper
349
+ path.node.body = [];
350
+ path.node.directives = [];
351
+ // Create the wrapper - "(function() { ... })();"
352
+ const wrapper = core_1.types.expressionStatement(core_1.types.callExpression(core_1.types.parenthesizedExpression(core_1.types.functionExpression(undefined, [], core_1.types.blockStatement(body, directives))), []));
353
+ // Insert the wrapper
354
+ path.pushContainer('body', wrapper);
355
+ },
356
+ },
357
+ },
358
+ };
359
+ }
338
360
  const USE_LOCALIZE_PLUGINS = false;
339
361
  async function createI18nPlugins(locale, translation, missingTranslation, localeDataContent) {
340
362
  const plugins = [];