Skip to content

Commit 6009030

Browse files
clydindgp1130
authored andcommitted
fix(@angular/cli): ensure dependencies are resolved correctly for node modules directory check
This commit updates the check for installed node packages in the Architect base command module. Instead of relying on the presence of a 'node_modules' directory or checking for Yarn PnP specifically, it now attempts to resolve '@angular/core' using 'createRequire'. This provides a more robust and agnostic way to verify if dependencies are installed, supporting various package managers and installation strategies.
1 parent 09e5e32 commit 6009030

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

packages/angular/cli/src/command-builder/architect-base-command-module.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import {
1212
WorkspaceNodeModulesArchitectHost,
1313
} from '@angular-devkit/architect/node';
1414
import { json } from '@angular-devkit/core';
15-
import { existsSync } from 'node:fs';
16-
import { resolve } from 'node:path';
15+
import { createRequire } from 'node:module';
1716
import { isPackageNameSafeForAnalytics } from '../analytics/analytics';
1817
import { EventCustomDimension, EventCustomMetric } from '../analytics/analytics-parameters';
1918
import { assertIsError } from '../utilities/error';
@@ -210,15 +209,13 @@ export abstract class ArchitectBaseCommandModule<T extends object>
210209
return;
211210
}
212211

213-
// Check if yarn PnP is used. https://yarnpkg.com/advanced/pnpapi#processversionspnp
214-
if (process.versions.pnp) {
215-
return;
216-
}
212+
const workspaceResolve = createRequire(basePath + '/').resolve;
213+
214+
try {
215+
workspaceResolve('@angular/core');
217216

218-
// Check for a `node_modules` directory (npm, yarn non-PnP, etc.)
219-
if (existsSync(resolve(basePath, 'node_modules'))) {
220217
return;
221-
}
218+
} catch {}
222219

223220
this.context.logger.warn(
224221
`Node packages may not be installed. Try installing with '${this.context.packageManager.name} install'.`,

0 commit comments

Comments
 (0)