Skip to content

Commit 6692c40

Browse files
authored
fix: improve detection of Angular core version in monorepo setup (#2106)
* 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 * fixup! fix: improve detection of Angular core version in monorepo setup Feedback
1 parent 54ba623 commit 6692c40

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

client/src/client.ts

+18-9
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,8 +317,8 @@ export class AngularLanguageClient implements vscode.Disposable {
317317
}
318318

319319
// Sort the versions from oldest to newest.
320-
const angularVersions = getAngularVersionsInWorkspace().sort(
321-
(a, b) => a.version.greaterThanOrEqual(b.version) ? 1 : -1);
320+
const angularVersions = (await getAngularVersionsInWorkspace(this.outputChannel))
321+
.sort((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
324324
// block syntax
@@ -552,13 +552,22 @@ function extensionVersionCompatibleWithAllProjects(serverModuleLocation: string)
552552
}
553553

554554
/**
555-
* Returns true if any project in the workspace supports block syntax (v17+).
555+
* Traverses through the currently open VSCode workspace (i.e. all open folders)
556+
* and finds all `@angular/core` versions installed based on `package.json` files.
556557
*/
557-
function getAngularVersionsInWorkspace(): NodeModule[] {
558+
async function getAngularVersionsInWorkspace(outputChannel: vscode.OutputChannel):
559+
Promise<NodeModule[]> {
560+
const packageJsonFiles = await vscode.workspace.findFiles(
561+
'**/package.json',
562+
// Skip looking inside `node_module` folders as those contain irrelevant files.
563+
'**/node_modules/**');
564+
const packageJsonRoots = packageJsonFiles.map(f => path.dirname(f.fsPath));
558565
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);
566+
567+
outputChannel.appendLine(`package.json roots detected: ${packageJsonRoots.join(',\n ')}`);
568+
569+
for (const packageJsonRoot of packageJsonRoots) {
570+
const angularCore = resolve('@angular/core', packageJsonRoot);
562571
if (angularCore === undefined) {
563572
continue;
564573
}

0 commit comments

Comments
 (0)