Skip to content

Commit

Permalink
fix: revert to old logic for scanning workspaces, also fix checking f…
Browse files Browse the repository at this point in the history
…or paths of undefined (#1199)
  • Loading branch information
Cammisuli authored Dec 16, 2021
1 parent d0ad47e commit 039c24e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
24 changes: 21 additions & 3 deletions apps/vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
teardownTelemetry,
watchFile,
directoryExists,
fileExists,
} from '@nx-console/server';
import {
GlobalConfigurationStore,
Expand Down Expand Up @@ -118,7 +119,7 @@ export async function activate(c: ExtensionContext) {
workspace.workspaceFolders && workspace.workspaceFolders[0].uri.fsPath;

if (vscodeWorkspacePath) {
scanForWorkspace(vscodeWorkspacePath);
await scanForWorkspace(vscodeWorkspacePath);
}

context.subscriptions.push(
Expand Down Expand Up @@ -179,9 +180,11 @@ function manuallySelectWorkspaceDefinition() {
}
}

function scanForWorkspace(vscodeWorkspacePath: string) {
async function scanForWorkspace(vscodeWorkspacePath: string) {
let currentDirectory = vscodeWorkspacePath;

const { root } = parse(vscodeWorkspacePath);

const workspacePath = WorkspaceConfigurationStore.instance.get(
'nxWorkspacePath',
''
Expand All @@ -191,10 +194,25 @@ function scanForWorkspace(vscodeWorkspacePath: string) {
currentDirectory = workspacePath;
}

setWorkspace(currentDirectory);
while (currentDirectory !== root) {
if (await fileExists(join(currentDirectory, 'angular.json'))) {
return setWorkspace(currentDirectory);
}
if (await fileExists(join(currentDirectory, 'workspace.json'))) {
return setWorkspace(currentDirectory);
}
if (await fileExists(join(currentDirectory, 'nx.json'))) {
return setWorkspace(currentDirectory);
}
currentDirectory = dirname(currentDirectory);
}
}

async function setWorkspace(workspacePath: string) {
if (workspacePath.match(/(workspace|angular)\.json$/)) {
workspacePath = dirname(workspacePath);
}

WorkspaceConfigurationStore.instance.set('nxWorkspacePath', workspacePath);
const { verifyWorkspace } = await import('@nx-console/vscode/nx-workspace');

Expand Down
15 changes: 11 additions & 4 deletions libs/typescript-plugin/src/lib/typescript-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,18 @@ async function configurePlugin(workspaceRoot: string, api: any) {
async function getExternalFiles(
workspaceRoot: string
): Promise<{ mainFile: string; directory: string }[]> {
const baseTsConfig = (
await readAndCacheJsonFile(TSCONFIG_BASE, workspaceRoot)
).json;
let tsconfig = (await readAndCacheJsonFile(TSCONFIG_BASE, workspaceRoot))
.json;

if (!('compilerOptions' in tsconfig)) {
tsconfig = (await readAndCacheJsonFile('tsconfig.json', workspaceRoot))
.json;
if (!('compilerOptions' in tsconfig)) {
return [];
}
}

const paths = baseTsConfig.compilerOptions.paths;
const paths = tsconfig.compilerOptions.paths ?? {};

const externals: { mainFile: string; directory: string }[] = [];

Expand Down

0 comments on commit 039c24e

Please sign in to comment.