@ngtools/webpack 11.0.1 → 11.0.2

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": "11.0.1",
3
+ "version": "11.0.2",
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",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "homepage": "https://github.com/angular/angular-cli",
27
27
  "dependencies": {
28
- "@angular-devkit/core": "11.0.1",
28
+ "@angular-devkit/core": "11.0.2",
29
29
  "enhanced-resolve": "5.3.1",
30
30
  "webpack-sources": "2.0.1"
31
31
  },
@@ -560,6 +560,7 @@ class AngularCompilerPlugin {
560
560
  // Decorate inputFileSystem to serve contents of CompilerHost.
561
561
  // Use decorated inputFileSystem in watchFileSystem.
562
562
  compiler.hooks.environment.tap('angular-compiler', () => {
563
+ var _a;
563
564
  // The webpack types currently do not include these
564
565
  const compilerWithFileSystems = compiler;
565
566
  let host = this._options.host || webpack_input_host_1.createWebpackInputHost(compilerWithFileSystems.inputFileSystem);
@@ -588,14 +589,7 @@ class AngularCompilerPlugin {
588
589
  }
589
590
  let ngccProcessor;
590
591
  if (this._compilerOptions.enableIvy) {
591
- const fileWatchPurger = (path) => {
592
- // tslint:disable-next-line: no-any
593
- if (compilerWithFileSystems.inputFileSystem.purge) {
594
- // tslint:disable-next-line: no-any
595
- compilerWithFileSystems.inputFileSystem.purge(path);
596
- }
597
- };
598
- ngccProcessor = new ngcc_processor_1.NgccProcessor(this._mainFields, fileWatchPurger, this._warnings, this._errors, this._basePath, this._tsConfigPath);
592
+ ngccProcessor = new ngcc_processor_1.NgccProcessor(this._mainFields, this._warnings, this._errors, this._basePath, this._tsConfigPath, compilerWithFileSystems.inputFileSystem, (_a = compiler.options.resolve) === null || _a === void 0 ? void 0 : _a.symlinks);
599
593
  ngccProcessor.process();
600
594
  }
601
595
  // Use an identity function as all our paths are absolute already.
@@ -6,17 +6,20 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import * as ts from 'typescript';
9
+ import { InputFileSystem } from 'webpack';
9
10
  export declare class NgccProcessor {
10
11
  private readonly propertiesToConsider;
11
- private readonly fileWatchPurger;
12
12
  private readonly compilationWarnings;
13
13
  private readonly compilationErrors;
14
14
  private readonly basePath;
15
15
  private readonly tsConfigPath;
16
+ private readonly inputFileSystem;
17
+ private readonly symlinks;
16
18
  private _processedModules;
17
19
  private _logger;
18
20
  private _nodeModulesDirectory;
19
- constructor(propertiesToConsider: string[], fileWatchPurger: (path: string) => void, compilationWarnings: (Error | string)[], compilationErrors: (Error | string)[], basePath: string, tsConfigPath: string);
21
+ private _resolver;
22
+ constructor(propertiesToConsider: string[], compilationWarnings: (Error | string)[], compilationErrors: (Error | string)[], basePath: string, tsConfigPath: string, inputFileSystem: InputFileSystem, symlinks: boolean | undefined);
20
23
  /** Process the entire node modules tree. */
21
24
  process(): void;
22
25
  /** Process a module and it's depedencies. */
@@ -11,6 +11,7 @@ exports.NgccProcessor = void 0;
11
11
  const ngcc_1 = require("@angular/compiler-cli/ngcc");
12
12
  const child_process_1 = require("child_process");
13
13
  const crypto_1 = require("crypto");
14
+ const enhanced_resolve_1 = require("enhanced-resolve");
14
15
  const fs_1 = require("fs");
15
16
  const path = require("path");
16
17
  const benchmark_1 = require("./benchmark");
@@ -22,16 +23,25 @@ const benchmark_1 = require("./benchmark");
22
23
  // but could not be resolved to an NgModule class
23
24
  // We now transform a package and it's typings when NGTSC is resolving a module.
24
25
  class NgccProcessor {
25
- constructor(propertiesToConsider, fileWatchPurger, compilationWarnings, compilationErrors, basePath, tsConfigPath) {
26
+ constructor(propertiesToConsider, compilationWarnings, compilationErrors, basePath, tsConfigPath, inputFileSystem, symlinks) {
26
27
  this.propertiesToConsider = propertiesToConsider;
27
- this.fileWatchPurger = fileWatchPurger;
28
28
  this.compilationWarnings = compilationWarnings;
29
29
  this.compilationErrors = compilationErrors;
30
30
  this.basePath = basePath;
31
31
  this.tsConfigPath = tsConfigPath;
32
+ this.inputFileSystem = inputFileSystem;
33
+ this.symlinks = symlinks;
32
34
  this._processedModules = new Set();
33
35
  this._logger = new NgccLogger(this.compilationWarnings, this.compilationErrors);
34
36
  this._nodeModulesDirectory = this.findNodeModulesDirectory(this.basePath);
37
+ this._resolver = enhanced_resolve_1.ResolverFactory.createResolver({
38
+ // NOTE: @types/webpack InputFileSystem is missing some methods
39
+ // tslint:disable-next-line: no-any
40
+ fileSystem: this.inputFileSystem,
41
+ extensions: ['.json'],
42
+ useSyncFileSystemCalls: true,
43
+ symlinks,
44
+ });
35
45
  }
36
46
  /** Process the entire node modules tree. */
37
47
  process() {
@@ -162,7 +172,10 @@ class NgccProcessor {
162
172
  benchmark_1.timeEnd(timeLabel);
163
173
  // Purge this file from cache, since NGCC add new mainFields. Ex: module_ivy_ngcc
164
174
  // which are unknown in the cached file.
165
- this.fileWatchPurger(packageJsonPath);
175
+ if (this.inputFileSystem.purge) {
176
+ // tslint:disable-next-line: no-any
177
+ this.inputFileSystem.purge(packageJsonPath);
178
+ }
166
179
  this._processedModules.add(resolvedFileName);
167
180
  }
168
181
  invalidate(fileName) {
@@ -173,15 +186,10 @@ class NgccProcessor {
173
186
  */
174
187
  tryResolvePackage(moduleName, resolvedFileName) {
175
188
  try {
176
- // This is based on the logic in the NGCC compiler
177
- // tslint:disable-next-line:max-line-length
178
- // See: https://github.com/angular/angular/blob/b93c1dffa17e4e6900b3ab1b9e554b6da92be0de/packages/compiler-cli/src/ngcc/src/packages/dependency_host.ts#L85-L121
179
- return require.resolve(`${moduleName}/package.json`, {
180
- paths: [resolvedFileName],
181
- });
189
+ const resolvedPath = this._resolver.resolveSync({}, resolvedFileName, `${moduleName}/package.json`);
190
+ return resolvedPath || undefined;
182
191
  }
183
192
  catch (_a) {
184
- // if it fails this might be a deep import which doesn't have a package.json
185
193
  // Ex: @angular/compiler/src/i18n/i18n_ast/package.json
186
194
  // or local libraries which don't reside in node_modules
187
195
  const packageJsonPath = path.resolve(resolvedFileName, '../package.json');