Skip to content

Commit 2f0599a

Browse files
committed
refactor(@angular/cli): remove resolve dependency and use native require.resolve
This commit removes the `resolve` dependency from `@angular/cli` and replaces its usage with native `require.resolve` via `createRequire`. The `findPackageJson` utility is now only used in migration-only scenarios where the Node.js module caching behavior that prompted the original use of `resolve` is no longer a concern. This reduces the package dependency footprint.
1 parent 8ba6967 commit 2f0599a

File tree

5 files changed

+3
-18
lines changed

5 files changed

+3
-18
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"@types/pacote": "^11.1.3",
8585
"@types/picomatch": "^4.0.0",
8686
"@types/progress": "^2.0.3",
87-
"@types/resolve": "^1.17.1",
8887
"@types/semver": "^7.3.12",
8988
"@types/watchpack": "^2.4.4",
9089
"@types/yargs": "^17.0.20",

packages/angular/cli/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,13 @@ ts_project(
7272
":node_modules/npm-package-arg",
7373
":node_modules/pacote",
7474
":node_modules/parse5-html-rewriting-stream",
75-
":node_modules/resolve",
7675
":node_modules/yargs",
7776
":node_modules/zod",
7877
"//:node_modules/@angular/core",
7978
"//:node_modules/@types/ini",
8079
"//:node_modules/@types/node",
8180
"//:node_modules/@types/npm-package-arg",
8281
"//:node_modules/@types/pacote",
83-
"//:node_modules/@types/resolve",
8482
"//:node_modules/@types/semver",
8583
"//:node_modules/@types/yargs",
8684
"//:node_modules/@types/yarnpkg__lockfile",

packages/angular/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"npm-package-arg": "13.0.2",
3838
"pacote": "21.0.4",
3939
"parse5-html-rewriting-stream": "8.0.0",
40-
"resolve": "1.22.11",
4140
"semver": "7.7.3",
4241
"yargs": "18.0.0",
4342
"zod": "4.3.5"

packages/angular/cli/src/utilities/package-tree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88

99
import * as fs from 'node:fs';
10+
import { createRequire } from 'node:module';
1011
import { dirname, join } from 'node:path';
11-
import * as resolve from 'resolve';
1212
import { NgAddSaveDependency } from './package-metadata';
1313

1414
interface PackageJson {
@@ -52,8 +52,8 @@ export async function readPackageJson(packageJsonPath: string): Promise<PackageJ
5252

5353
export function findPackageJson(workspaceDir: string, packageName: string): string | undefined {
5454
try {
55-
// avoid require.resolve here, see: https://github.com/angular/angular-cli/pull/18610#issuecomment-681980185
56-
const packageJsonPath = resolve.sync(`${packageName}/package.json`, { basedir: workspaceDir });
55+
const projectRequire = createRequire(join(workspaceDir, 'package.json'));
56+
const packageJsonPath = projectRequire.resolve(`${packageName}/package.json`);
5757

5858
return packageJsonPath;
5959
} catch {

pnpm-lock.yaml

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)