Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.

Commit 8fb7829

Browse files
committed
fix: improve detection of Angular core version in monorepo setup
Angular may not be installed at the project root. We should look for `package.json` roots and determine the `@angular/core` version based on these folders. Related to: angular/angular#58546
1 parent 54ba623 commit 8fb7829

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

client/src/client.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export class AngularLanguageClient implements vscode.Disposable {
227227
}
228228

229229
// Node module for the language server
230-
const args = this.constructArgs();
230+
const args = await this.constructArgs();
231231
const prodBundle = this.context.asAbsolutePath('server');
232232
const devBundle =
233233
this.context.asAbsolutePath(path.join('bazel-bin', 'server', 'src', 'server.js'));
@@ -289,7 +289,7 @@ export class AngularLanguageClient implements vscode.Disposable {
289289
* Construct the arguments that's used to spawn the server process.
290290
* @param ctx vscode extension context
291291
*/
292-
private constructArgs(): string[] {
292+
private async constructArgs(): Promise<string[]> {
293293
const config = vscode.workspace.getConfiguration();
294294
const args: string[] = ['--logToConsole'];
295295

@@ -317,7 +317,7 @@ export class AngularLanguageClient implements vscode.Disposable {
317317
}
318318

319319
// Sort the versions from oldest to newest.
320-
const angularVersions = getAngularVersionsInWorkspace().sort(
320+
const angularVersions = (await getAngularVersionsInWorkspace(this.outputChannel)).sort(
321321
(a, b) => a.version.greaterThanOrEqual(b.version) ? 1 : -1);
322322

323323
// Only disable block syntax if we find angular/core and every one we find does not support
@@ -554,11 +554,15 @@ function extensionVersionCompatibleWithAllProjects(serverModuleLocation: string)
554554
/**
555555
* Returns true if any project in the workspace supports block syntax (v17+).
556556
*/
557-
function getAngularVersionsInWorkspace(): NodeModule[] {
557+
async function getAngularVersionsInWorkspace(outputChannel: vscode.OutputChannel): Promise<NodeModule[]> {
558+
const packageJsonFiles = await vscode.workspace.findFiles("**/package.json", "**/node_modules/**");
559+
const packageJsonRoots = packageJsonFiles.map(f => path.dirname(f.fsPath));
558560
const angularCoreModules = new Set<NodeModule>();
559-
const workspaceFolders = vscode.workspace.workspaceFolders || [];
560-
for (const workspaceFolder of workspaceFolders) {
561-
const angularCore = resolve('@angular/core', workspaceFolder.uri.fsPath);
561+
562+
outputChannel.appendLine(`package.json roots detected: ${packageJsonRoots.join(',\n ')}`);
563+
564+
for (const packageJsonRoot of packageJsonRoots) {
565+
const angularCore = resolve('@angular/core', packageJsonRoot);
562566
if (angularCore === undefined) {
563567
continue;
564568
}

0 commit comments

Comments
 (0)