@ngtools/webpack 13.1.0 → 13.2.0-next.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngtools/webpack",
3
- "version": "13.1.0",
3
+ "version": "13.2.0-next.1",
4
4
  "description": "Webpack plugin that AoT compiles your Angular components and modules.",
5
5
  "main": "./src/index.js",
6
6
  "typings": "src/index.d.ts",
@@ -5,9 +5,9 @@
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
- import type { Diagnostics } from '@angular/compiler-cli';
8
+ import { Diagnostic } from 'typescript';
9
9
  import type { Compilation } from 'webpack';
10
- export declare type DiagnosticsReporter = (diagnostics: Diagnostics) => void;
11
- export declare function createDiagnosticsReporter(compilation: Compilation, formatter: (diagnostic: Diagnostics[number]) => string): DiagnosticsReporter;
10
+ export declare type DiagnosticsReporter = (diagnostics: readonly Diagnostic[]) => void;
11
+ export declare function createDiagnosticsReporter(compilation: Compilation, formatter: (diagnostic: Diagnostic) => string): DiagnosticsReporter;
12
12
  export declare function addWarning(compilation: Compilation, message: string): void;
13
13
  export declare function addError(compilation: Compilation, message: string): void;
@@ -26,6 +26,7 @@ export declare class AngularWebpackPlugin {
26
26
  private ngtscNextProgram?;
27
27
  private builder?;
28
28
  private sourceFileCache?;
29
+ private webpackCache?;
29
30
  private readonly fileDependencies;
30
31
  private readonly requiredFilesToEmit;
31
32
  private readonly requiredFilesToEmitCache;
@@ -42,4 +43,6 @@ export declare class AngularWebpackPlugin {
42
43
  private updateJitProgram;
43
44
  private createFileEmitter;
44
45
  private initializeCompilerCli;
46
+ private addFileEmitHistory;
47
+ private getFileEmitHistory;
45
48
  }
package/src/ivy/plugin.js CHANGED
@@ -65,9 +65,6 @@ function initializeNgccProcessor(compiler, tsconfig, compilerNgccModule) {
65
65
  const processor = new ngcc_processor_1.NgccProcessor(compilerNgccModule, mainFields, warnings, errors, compiler.context, tsconfig, inputFileSystem, resolver);
66
66
  return { processor, errors, warnings };
67
67
  }
68
- function hashContent(content) {
69
- return (0, crypto_1.createHash)('md5').update(content).digest();
70
- }
71
68
  const PLUGIN_NAME = 'angular-compiler';
72
69
  const compilationFileEmitters = new WeakMap();
73
70
  class AngularWebpackPlugin {
@@ -97,6 +94,7 @@ class AngularWebpackPlugin {
97
94
  get options() {
98
95
  return this.pluginOptions;
99
96
  }
97
+ // eslint-disable-next-line max-lines-per-function
100
98
  apply(compiler) {
101
99
  const { NormalModuleReplacementPlugin, util } = compiler.webpack;
102
100
  // Setup file replacements with webpack
@@ -131,6 +129,10 @@ class AngularWebpackPlugin {
131
129
  // Register plugin to ensure deterministic emit order in multi-plugin usage
132
130
  const emitRegistration = this.registerWithCompilation(compilation);
133
131
  this.watchMode = compiler.watchMode;
132
+ // Initialize webpack cache
133
+ if (!this.webpackCache && compilation.options.cache) {
134
+ this.webpackCache = compilation.getCache(PLUGIN_NAME);
135
+ }
134
136
  // Initialize the resource loader if not already setup
135
137
  if (!resourceLoader) {
136
138
  resourceLoader = new resource_loader_1.WebpackResourceLoader(this.watchMode);
@@ -270,7 +272,7 @@ class AngularWebpackPlugin {
270
272
  }
271
273
  const filesToRebuild = new Set();
272
274
  for (const requiredFile of this.requiredFilesToEmit) {
273
- const history = this.fileEmitHistory.get(requiredFile);
275
+ const history = await this.getFileEmitHistory(requiredFile);
274
276
  if (history) {
275
277
  const emitResult = await fileEmitter(requiredFile);
276
278
  if ((emitResult === null || emitResult === void 0 ? void 0 : emitResult.content) === undefined ||
@@ -503,12 +505,8 @@ class AngularWebpackPlugin {
503
505
  }
504
506
  }, undefined, undefined, transformers);
505
507
  onAfterEmit === null || onAfterEmit === void 0 ? void 0 : onAfterEmit(sourceFile);
506
- let hash;
507
- if (content !== undefined && this.watchMode) {
508
- // Capture emit history info for Angular rebuild analysis
509
- hash = hashContent(content);
510
- this.fileEmitHistory.set(filePath, { length: content.length, hash });
511
- }
508
+ // Capture emit history info for Angular rebuild analysis
509
+ const hash = content ? (await this.addFileEmitHistory(filePath, content)).hash : undefined;
512
510
  const dependencies = [
513
511
  ...(this.fileDependencies.get(filePath) || []),
514
512
  ...getExtraDependencies(sourceFile),
@@ -530,5 +528,28 @@ class AngularWebpackPlugin {
530
528
  this.compilerCliModule = await new Function(`return import('@angular/compiler-cli');`)();
531
529
  this.compilerNgccModule = await new Function(`return import('@angular/compiler-cli/ngcc');`)();
532
530
  }
531
+ async addFileEmitHistory(filePath, content) {
532
+ const historyData = {
533
+ length: content.length,
534
+ hash: (0, crypto_1.createHash)('md5').update(content).digest(),
535
+ };
536
+ if (this.webpackCache) {
537
+ const history = await this.getFileEmitHistory(filePath);
538
+ if (!history || Buffer.compare(history.hash, historyData.hash) !== 0) {
539
+ // Hash doesn't match or item doesn't exist.
540
+ await this.webpackCache.storePromise(filePath, null, historyData);
541
+ }
542
+ }
543
+ else if (this.watchMode) {
544
+ // The in memory file emit history is only required during watch mode.
545
+ this.fileEmitHistory.set(filePath, historyData);
546
+ }
547
+ return historyData;
548
+ }
549
+ async getFileEmitHistory(filePath) {
550
+ return this.webpackCache
551
+ ? this.webpackCache.getPromise(filePath, null)
552
+ : this.fileEmitHistory.get(filePath);
553
+ }
533
554
  }
534
555
  exports.AngularWebpackPlugin = AngularWebpackPlugin;