Skip to content

Commit 4f9df9f

Browse files
committed
refactor(@ngtools/webpack): remove usage of enhanced-resolve dependency
The types used from the `enhanced-resolve` package are available from the `webpack` package and the `getInnerRequest` helper function used in the TypeScript paths resolver plugin is not actually needed. Webpack's `AliasPlugin` which has similar behavior also does not use the `getInnerRequest` helper function.
1 parent d055597 commit 4f9df9f

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
"css-loader": "6.2.0",
149149
"css-minimizer-webpack-plugin": "3.0.2",
150150
"debug": "^4.1.1",
151-
"enhanced-resolve": "5.8.2",
152151
"esbuild": "0.12.16",
153152
"eslint": "7.31.0",
154153
"eslint-config-prettier": "8.3.0",

packages/ngtools/webpack/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ ts_library(
3838
deps = [
3939
"@npm//@angular/compiler-cli",
4040
"@npm//@types/node",
41-
"@npm//enhanced-resolve",
4241
"@npm//typescript",
4342
"@npm//webpack",
4443
],

packages/ngtools/webpack/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
"url": "https://github.com/angular/angular-cli/issues"
2121
},
2222
"homepage": "https://github.com/angular/angular-cli/tree/master/packages/@ngtools/webpack",
23-
"dependencies": {
24-
"enhanced-resolve": "5.8.2"
25-
},
23+
"dependencies": {},
2624
"peerDependencies": {
2725
"@angular/compiler-cli": "^12.0.0 || ^12.2.0-next",
2826
"typescript": "~4.2.3 || ~4.3.2",

packages/ngtools/webpack/src/ngcc_processor.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
import { LogLevel, Logger, process as mainNgcc } from '@angular/compiler-cli/ngcc';
1010
import { spawnSync } from 'child_process';
1111
import { createHash } from 'crypto';
12-
import { Resolver } from 'enhanced-resolve';
1312
import { accessSync, constants, existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
1413
import * as path from 'path';
1514
import * as ts from 'typescript';
15+
import type { Compiler } from 'webpack';
1616
import { time, timeEnd } from './benchmark';
1717
import { InputFileSystem } from './ivy/system';
1818

19+
// Extract Resolver type from Webpack types since it is not directly exported
20+
type ResolverWithOptions = ReturnType<Compiler['resolverFactory']['get']>;
21+
1922
// We cannot create a plugin for this, because NGTSC requires addition type
2023
// information which ngcc creates when processing a package which was compiled with NGC.
2124

@@ -38,7 +41,7 @@ export class NgccProcessor {
3841
private readonly basePath: string,
3942
private readonly tsConfigPath: string,
4043
private readonly inputFileSystem: InputFileSystem,
41-
private readonly resolver: Resolver,
44+
private readonly resolver: ResolverWithOptions,
4245
) {
4346
this._logger = new NgccLogger(this.compilationWarnings, this.compilationErrors);
4447
this._nodeModulesDirectory = this.findNodeModulesDirectory(this.basePath);

packages/ngtools/webpack/src/paths-plugin.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@
88

99
import * as path from 'path';
1010
import { CompilerOptions, MapLike } from 'typescript';
11-
12-
const getInnerRequest = require('enhanced-resolve/lib/getInnerRequest');
11+
import type { Configuration } from 'webpack';
1312

1413
// eslint-disable-next-line @typescript-eslint/no-empty-interface
1514
export interface TypeScriptPathsPluginOptions extends Pick<CompilerOptions, 'paths' | 'baseUrl'> {}
1615

16+
// Extract Resolver type from Webpack types since it is not directly exported
17+
type Resolver = Exclude<Exclude<Configuration['resolve'], undefined>['resolver'], undefined>;
18+
1719
export class TypeScriptPathsPlugin {
1820
constructor(private options?: TypeScriptPathsPluginOptions) {}
1921

2022
update(options: TypeScriptPathsPluginOptions): void {
2123
this.options = options;
2224
}
2325

24-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
25-
apply(resolver: import('enhanced-resolve').Resolver) {
26+
apply(resolver: Resolver): void {
2627
const target = resolver.ensureHook('resolve');
2728

2829
resolver.getHook('described-resolve').tapAsync(
@@ -41,7 +42,7 @@ export class TypeScriptPathsPlugin {
4142
return;
4243
}
4344

44-
const originalRequest = getInnerRequest(resolver, request);
45+
const originalRequest = request.request || request.path;
4546
if (!originalRequest) {
4647
callback();
4748

yarn.lock

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494

9595
"@angular/dev-infra-private@https://github.com/angular/dev-infra-private-builds.git#5fa832317b3d2ca4f743079c7b3ae747c375db31":
9696
version "0.0.0"
97-
uid "5fa832317b3d2ca4f743079c7b3ae747c375db31"
9897
resolved "https://github.com/angular/dev-infra-private-builds.git#5fa832317b3d2ca4f743079c7b3ae747c375db31"
9998
dependencies:
10099
"@angular/benchpress" "0.2.1"
@@ -4473,7 +4472,7 @@ engine.io@~4.1.0:
44734472
engine.io-parser "~4.0.0"
44744473
ws "~7.4.2"
44754474

4476-
enhanced-resolve@5.8.2, enhanced-resolve@^5.8.0:
4475+
enhanced-resolve@^5.8.0:
44774476
version "5.8.2"
44784477
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.8.2.tgz#15ddc779345cbb73e97c611cd00c01c1e7bf4d8b"
44794478
integrity sha512-F27oB3WuHDzvR2DOGNTaYy0D5o0cnrv8TeI482VM4kYgQd/FT9lUQwuNsJ0oOHtBUq7eiW5ytqzp7nBFknL+GA==
@@ -9942,7 +9941,6 @@ [email protected], sass@^1.32.8:
99429941

99439942
"sauce-connect-proxy@https://saucelabs.com/downloads/sc-4.6.4-linux.tar.gz":
99449943
version "0.0.0"
9945-
uid "992e2cb0d91e54b27a4f5bbd2049f3b774718115"
99469944
resolved "https://saucelabs.com/downloads/sc-4.6.4-linux.tar.gz#992e2cb0d91e54b27a4f5bbd2049f3b774718115"
99479945

99489946
saucelabs@^1.5.0:

0 commit comments

Comments
 (0)