@angular-devkit/build-angular 14.1.0-next.1 → 14.1.0-next.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.
@@ -175,13 +175,15 @@ async function configureI18nBuild(context, options) {
175
175
  }
176
176
  // If inlining store the output in a temporary location to facilitate post-processing
177
177
  if (i18n.shouldInline) {
178
+ // TODO: we should likely save these in the .angular directory in the next major version.
179
+ // We'd need to do a migration to add the temp directory to gitignore.
178
180
  const tempPath = fs_1.default.mkdtempSync(path_1.default.join(fs_1.default.realpathSync(os_1.default.tmpdir()), 'angular-cli-i18n-'));
179
181
  buildOptions.outputPath = tempPath;
180
- process.on('exit', () => deleteTempDirectory(tempPath));
181
- process.once('SIGINT', () => {
182
- deleteTempDirectory(tempPath);
183
- // Needed due to `ora` as otherwise process will not terminate.
184
- process.kill(process.pid, 'SIGINT');
182
+ process.on('exit', () => {
183
+ try {
184
+ fs_1.default.rmSync(tempPath, { force: true, recursive: true, maxRetries: 3 });
185
+ }
186
+ catch { }
185
187
  });
186
188
  }
187
189
  return { buildOptions, i18n };
@@ -198,13 +200,6 @@ function findLocaleDataPath(locale, resolver) {
198
200
  return scrubbedLocale === 'en-US' ? findLocaleDataPath('en', resolver) : null;
199
201
  }
200
202
  }
201
- /** Remove temporary directory used for i18n processing. */
202
- function deleteTempDirectory(tempPath) {
203
- try {
204
- fs_1.default.rmSync(tempPath, { force: true, recursive: true, maxRetries: 3 });
205
- }
206
- catch { }
207
- }
208
203
  function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedFormats, duplicateTranslation) {
209
204
  let translations = undefined;
210
205
  for (const file of desc.files) {
@@ -86,6 +86,10 @@ async function getDevServerConfig(wco) {
86
86
  },
87
87
  ],
88
88
  },
89
+ // When setupExitSignals is enabled webpack-dev-server will shutdown gracefully which would
90
+ // require CTRL+C to be pressed multiple times to exit.
91
+ // See: https://github.com/webpack/webpack-dev-server/blob/c76b6d11a3821436c5e20207c8a38deb6ab7e33c/lib/Server.js#L1801-L1827
92
+ setupExitSignals: false,
89
93
  compress: false,
90
94
  static: false,
91
95
  server: getServerConfig(root, wco.buildOptions),
@@ -12,7 +12,9 @@ const path_1 = require("path");
12
12
  const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
13
13
  // Webpack doesn't export these so the deep imports can potentially break.
14
14
  const AMDDefineDependency = require('webpack/lib/dependencies/AMDDefineDependency');
15
+ const CommonJsExportsDependency = require('webpack/lib/dependencies/CommonJsExportsDependency');
15
16
  const CommonJsRequireDependency = require('webpack/lib/dependencies/CommonJsRequireDependency');
17
+ const CommonJsSelfReferenceDependency = require('webpack/lib/dependencies/CommonJsSelfReferenceDependency');
16
18
  class CommonJsUsageWarnPlugin {
17
19
  constructor(options = {}) {
18
20
  this.options = options;
@@ -81,7 +83,10 @@ class CommonJsUsageWarnPlugin {
81
83
  }
82
84
  hasCommonJsDependencies(compilation, dependencies, checkParentModules = false) {
83
85
  for (const dep of dependencies) {
84
- if (dep instanceof CommonJsRequireDependency || dep instanceof AMDDefineDependency) {
86
+ if (dep instanceof CommonJsRequireDependency ||
87
+ dep instanceof CommonJsExportsDependency ||
88
+ dep instanceof CommonJsSelfReferenceDependency ||
89
+ dep instanceof AMDDefineDependency) {
85
90
  return true;
86
91
  }
87
92
  if (checkParentModules) {
@@ -20,7 +20,6 @@ function ensureIvy(wco) {
20
20
  '\nFor additional information or if the build fails, please see https://angular.io/guide/ivy');
21
21
  wco.tsConfig.options.enableIvy = true;
22
22
  }
23
- let es5TargetWarningsShown = false;
24
23
  function createIvyPlugin(wco, aot, tsconfig) {
25
24
  if (aot) {
26
25
  ensureIvy(wco);
@@ -40,10 +39,7 @@ function createIvyPlugin(wco, aot, tsconfig) {
40
39
  // as for third-party libraries. This greatly reduces the complexity of static analysis.
41
40
  if (wco.scriptTarget < typescript_1.ScriptTarget.ES2015) {
42
41
  compilerOptions.target = typescript_1.ScriptTarget.ES2015;
43
- if (!es5TargetWarningsShown) {
44
- wco.logger.warn('DEPRECATED: ES5 output is deprecated. Please update TypeScript `target` compiler option to ES2015 or later.');
45
- es5TargetWarningsShown = true;
46
- }
42
+ wco.logger.warn('DEPRECATED: ES5 output is deprecated. Please update TypeScript `target` compiler option to ES2015 or later.');
47
43
  }
48
44
  const fileReplacements = {};
49
45
  if (buildOptions.fileReplacements) {
@@ -16,11 +16,12 @@ export interface HashFormat {
16
16
  file: string;
17
17
  script: string;
18
18
  }
19
+ export declare type WebpackStatsOptions = Exclude<Configuration['stats'], string | boolean | undefined>;
19
20
  export declare function getOutputHashFormat(outputHashing?: OutputHashing, length?: number): HashFormat;
20
21
  export declare type NormalizedEntryPoint = Required<Exclude<ScriptElement | StyleElement, string>>;
21
22
  export declare function normalizeExtraEntryPoints(extraEntryPoints: (ScriptElement | StyleElement)[], defaultBundleName: string): NormalizedEntryPoint[];
22
23
  export declare function assetNameTemplateFactory(hashFormat: HashFormat): (resourcePath: string) => string;
23
- export declare function getInstrumentationExcludedPaths(sourceRoot: string, excludedPaths: string[]): Set<string>;
24
+ export declare function getInstrumentationExcludedPaths(root: string, excludedPaths: string[]): Set<string>;
24
25
  export declare function getCacheSettings(wco: WebpackConfigOptions, angularVersion: string): WebpackOptionsNormalized['cache'];
25
26
  export declare function globalScriptsByBundleName(root: string, scripts: ScriptElement[]): {
26
27
  bundleName: string;
@@ -29,7 +30,5 @@ export declare function globalScriptsByBundleName(root: string, scripts: ScriptE
29
30
  }[];
30
31
  export declare function assetPatterns(root: string, assets: AssetPatternClass[]): ObjectPattern[];
31
32
  export declare function externalizePackages(context: string, request: string | undefined, callback: (error?: Error, result?: string) => void): void;
32
- declare type WebpackStatsOptions = Exclude<Configuration['stats'], string | boolean>;
33
33
  export declare function getStatsOptions(verbose?: boolean): WebpackStatsOptions;
34
34
  export declare function getMainFieldsAndConditionNames(target: ScriptTarget, platformServer: boolean): Pick<WebpackOptionsNormalized['resolve'], 'mainFields' | 'conditionNames'>;
35
- export {};
@@ -121,12 +121,12 @@ function assetNameTemplateFactory(hashFormat) {
121
121
  };
122
122
  }
123
123
  exports.assetNameTemplateFactory = assetNameTemplateFactory;
124
- function getInstrumentationExcludedPaths(sourceRoot, excludedPaths) {
124
+ function getInstrumentationExcludedPaths(root, excludedPaths) {
125
125
  const excluded = new Set();
126
126
  for (const excludeGlob of excludedPaths) {
127
127
  glob_1.default
128
- .sync(path.join(sourceRoot, excludeGlob), { nodir: true })
129
- .forEach((p) => excluded.add(path.normalize(p)));
128
+ .sync(excludeGlob, { nodir: true, cwd: root, root, nomount: true })
129
+ .forEach((p) => excluded.add(path.join(root, p)));
130
130
  }
131
131
  return excluded;
132
132
  }
@@ -278,6 +278,7 @@ function getStatsOptions(verbose = false) {
278
278
  version: true,
279
279
  chunkModules: true,
280
280
  errorDetails: true,
281
+ errorStack: true,
281
282
  moduleTrace: true,
282
283
  logging: 'verbose',
283
284
  modulesSpace: Infinity,
@@ -10,6 +10,7 @@ import { logging } from '@angular-devkit/core';
10
10
  import { Configuration, StatsCompilation } from 'webpack';
11
11
  import { Schema as BrowserBuilderOptions } from '../../builders/browser/schema';
12
12
  import { BudgetCalculatorResult } from '../../utils/bundle-calculator';
13
+ import { WebpackStatsOptions } from './helpers';
13
14
  export declare function formatSize(size: number): string;
14
15
  export declare type BundleStatsData = [
15
16
  files: string,
@@ -29,8 +30,8 @@ export declare function generateBundleStats(info: {
29
30
  initial?: boolean;
30
31
  rendered?: boolean;
31
32
  }): BundleStats;
32
- export declare function statsWarningsToString(json: StatsCompilation, statsConfig: any): string;
33
- export declare function statsErrorsToString(json: StatsCompilation, statsConfig: any): string;
33
+ export declare function statsWarningsToString(json: StatsCompilation, statsConfig: WebpackStatsOptions): string;
34
+ export declare function statsErrorsToString(json: StatsCompilation, statsConfig: WebpackStatsOptions): string;
34
35
  export declare function statsHasErrors(json: StatsCompilation): boolean;
35
36
  export declare function statsHasWarnings(json: StatsCompilation): boolean;
36
37
  export declare function createWebpackLoggingCallback(options: BrowserBuilderOptions, logger: logging.LoggerApi): WebpackLoggingCallback;
@@ -261,7 +261,6 @@ statsConfig, budgetFailures) {
261
261
  `));
262
262
  }
263
263
  }
264
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
265
264
  function statsWarningsToString(json, statsConfig) {
266
265
  const colors = statsConfig.colors;
267
266
  const c = (x) => (colors ? color_1.colors.reset.cyan(x) : x);
@@ -294,8 +293,8 @@ function statsWarningsToString(json, statsConfig) {
294
293
  return output ? '\n' + output : output;
295
294
  }
296
295
  exports.statsWarningsToString = statsWarningsToString;
297
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
298
296
  function statsErrorsToString(json, statsConfig) {
297
+ var _a, _b;
299
298
  const colors = statsConfig.colors;
300
299
  const c = (x) => (colors ? color_1.colors.reset.cyan(x) : x);
301
300
  const yb = (x) => (colors ? color_1.colors.reset.yellowBright(x) : x);
@@ -310,7 +309,16 @@ function statsErrorsToString(json, statsConfig) {
310
309
  output += r(`Error: ${error}\n\n`);
311
310
  }
312
311
  else {
313
- const file = error.file || error.moduleName;
312
+ let file = error.file || error.moduleName;
313
+ // Clean up error paths
314
+ // Ex: ./src/app/styles.scss.webpack[javascript/auto]!=!./node_modules/css-loader/dist/cjs.js....
315
+ // to ./src/app/styles.scss.webpack
316
+ if (file && !statsConfig.errorDetails) {
317
+ const webpackPathIndex = file.indexOf('.webpack[');
318
+ if (webpackPathIndex !== -1) {
319
+ file = file.substring(0, webpackPathIndex);
320
+ }
321
+ }
314
322
  if (file) {
315
323
  output += c(file);
316
324
  if (error.loc) {
@@ -318,10 +326,16 @@ function statsErrorsToString(json, statsConfig) {
318
326
  }
319
327
  output += ' - ';
320
328
  }
321
- if (!/^error/i.test(error.message)) {
329
+ // In most cases webpack will add stack traces to error messages.
330
+ // This below cleans up the error from stacks.
331
+ // See: https://github.com/webpack/webpack/issues/15980
332
+ const message = statsConfig.errorStack
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;
335
+ if (!/^error/i.test(message)) {
322
336
  output += r('Error: ');
323
337
  }
324
- output += `${error.message}\n\n`;
338
+ output += `${message}\n\n`;
325
339
  }
326
340
  }
327
341
  return output ? '\n' + output : output;
@@ -358,6 +372,9 @@ function createWebpackLoggingCallback(options, logger) {
358
372
  exports.createWebpackLoggingCallback = createWebpackLoggingCallback;
359
373
  function webpackStatsLogger(logger, json, config, budgetFailures) {
360
374
  logger.info(statsToString(json, config.stats, budgetFailures));
375
+ if (typeof config.stats !== 'object') {
376
+ throw new Error('Invalid Webpack stats configuration.');
377
+ }
361
378
  if (statsHasWarnings(json)) {
362
379
  logger.warn(statsWarningsToString(json, config.stats));
363
380
  }