Skip to content

Commit

Permalink
clean up scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Apr 9, 2024
1 parent 83f5617 commit 9fd7391
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 65 deletions.
2 changes: 1 addition & 1 deletion apps/nxls/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ async function reconfigureAndSendNotificationWithBackoff(workingPath: string) {
const workspace = await reconfigure(workingPath);
await connection.sendNotification(NxWorkspaceRefreshNotification.method);

if (!workspace?.error) {
if (!workspace?.errors) {
reconfigureAttempts = 0;
return;
}
Expand Down
60 changes: 38 additions & 22 deletions libs/language-server/workspace/src/lib/get-nx-workspace-config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { lspLogger } from '@nx-console/language-server/utils';
import { readAndCacheJsonFile } from '@nx-console/shared/file-system';
import { Logger } from '@nx-console/shared/schema';
import { NxVersion, NxWorkspaceConfiguration } from '@nx-console/shared/types';
import type {
NxJsonConfiguration,
ProjectFileMap,
ProjectGraph,
ProjectsConfigurations,
} from 'nx/src/devkit-exports';
import { lspLogger } from '@nx-console/language-server/utils';
import { readAndCacheJsonFile } from '@nx-console/shared/file-system';
import { Logger } from '@nx-console/shared/schema';
import { NxVersion, NxWorkspaceConfiguration } from '@nx-console/shared/types';
import { join } from 'path';
import { SemVer, coerce, gte } from 'semver';
import { performance } from 'perf_hooks';
import { gte } from 'semver';
import {
getNxDaemonClient,
getNxOutput,
getNxProjectGraph,
getNxProjectGraphUtils,
getNxWorkspacePackageFileUtils,
} from './get-nx-workspace-package';
import { performance } from 'perf_hooks';
import { WriteStream } from 'node:fs';

export async function getNxWorkspaceConfig(
workspacePath: string,
Expand All @@ -27,13 +26,15 @@ export async function getNxWorkspaceConfig(
): Promise<{
workspaceConfiguration: NxWorkspaceConfiguration;
daemonEnabled?: boolean;
error?: string;
errors?: string[];
isPartialProjectGraph?: boolean;
}> {
let projectGraph: ProjectGraph | null = null;
let sourceMaps: Record<string, Record<string, string[]>> | undefined =
undefined;

let error: string | undefined;
let errors: string[] | undefined;
let isPartialProjectGraph = false;

const start = performance.now();
logger.log('Retrieving workspace configuration');
Expand Down Expand Up @@ -74,7 +75,7 @@ export async function getNxWorkspaceConfig(
logger.log('Unable to read workspace config from nx workspace package');
workspaceConfiguration = (await readWorkspaceConfigs(workspacePath))
.workspaceConfiguration;
error = `${e.stack}`;
errors = [`${e.stack}`];
}
} else {
workspaceConfiguration = (await readWorkspaceConfigs(workspacePath))
Expand All @@ -97,15 +98,29 @@ export async function getNxWorkspaceConfig(
if (nxVersion.major < 13) {
projectGraph = (nxProjectGraph as any).createProjectGraph();
} else if (gte(nxVersion.full, '17.2.0')) {
lspLogger.log('createProjectGraphAndSourceMapsAsync');
const projectGraphAndSourceMaps = await (
nxProjectGraph as any
).createProjectGraphAndSourceMapsAsync({
exitOnError: false,
});
projectGraph = projectGraphAndSourceMaps.projectGraph;
sourceMaps = projectGraphAndSourceMaps.sourceMaps;
lspLogger.log('createProjectGraphAndSourceMapsAsync successful');
try {
lspLogger.log('createProjectGraphAndSourceMapsAsync');
const projectGraphAndSourceMaps = await (
nxProjectGraph as any
).createProjectGraphAndSourceMapsAsync({
exitOnError: false,
});
projectGraph = projectGraphAndSourceMaps.projectGraph;
sourceMaps = projectGraphAndSourceMaps.sourceMaps;
lspLogger.log('createProjectGraphAndSourceMapsAsync successful');
} catch (e) {
lspLogger.log(
`Error creating project graph and source maps, ${JSON.stringify(e)}`
);
if (e.name === 'ProjectGraphError') {
projectGraph = e.getPartialProjectGraph();
sourceMaps = e.getPartialSourcemaps();
errors = e
.getErrors()
.map((error: any) => `${error.message} \n ${error.stack}`);
isPartialProjectGraph = true;
}
}
} else {
lspLogger.log('createProjectGraphAsync');
projectGraph = await nxProjectGraph.createProjectGraphAsync({
Expand All @@ -116,7 +131,7 @@ export async function getNxWorkspaceConfig(
} catch (e) {
lspLogger.log('Unable to get project graph');
lspLogger.log(e.stack);
error = `${e.stack}`;
errors = [`${e.stack}`];
}

let projectFileMap: ProjectFileMap = {};
Expand Down Expand Up @@ -158,12 +173,13 @@ export async function getNxWorkspaceConfig(

return {
workspaceConfiguration,
error,
errors,
isPartialProjectGraph,
};
} catch (e) {
lspLogger.log(`Unable to get nx workspace configuration: ${e}`);
const config = await readWorkspaceConfigs(workspacePath);
return { ...config, error: `${e}` };
return { ...config, errors: [`${e}`] };
}
}

Expand Down
2 changes: 1 addition & 1 deletion libs/language-server/workspace/src/lib/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function _workspace(
appsDir: config.workspaceConfiguration.workspaceLayout?.appsDir,
libsDir: config.workspaceConfiguration.workspaceLayout?.libsDir,
},
error: config.error,
errors: config.errors,
nxVersion,
workspacePath,
};
Expand Down
2 changes: 1 addition & 1 deletion libs/shared/types/src/lib/nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface NxWorkspace {
isLerna: boolean;
nxVersion: NxVersion;
isEncapsulatedNx: boolean;
error?: string;
errors?: string[];
workspaceLayout: {
appsDir?: string;
libsDir?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export class ProjectDetailsCodelensProvider implements NxCodeLensProvider {
): Promise<ProjectDetailsCodeLens | undefined> {
const project = await getProjectByPath(codeLens.filePath);
if (!project) {
const error = (await getNxWorkspace()).error;
if (error) {
const errors = (await getNxWorkspace()).errors;
if (errors && errors.length) {
return {
...codeLens,
command: {
Expand Down
22 changes: 12 additions & 10 deletions libs/vscode/project-details/src/lib/project-details-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ export class ProjectDetailsPreview {
}

private async loadHtml() {
let error = (await getNxWorkspace()).error;
let errors = (await getNxWorkspace()).errors;
const project = await getProjectByPath(this.path);

if (!project) {
if (!error) {
error = `No project found at path ${this.path}`;
if (!errors) {
errors = [`No project found at path ${this.path}`];
}
} else {
this.projectRoot = project.root;
}

let html: string;
if (error) {
html = await this.loadErrorHtml(error);
if (errors) {
html = await this.loadErrorHtml(errors);
this.isShowingErrorHtml = true;
} else {
html = await loadGraphBaseHtml(this.webviewPanel.webview);
Expand Down Expand Up @@ -146,7 +146,7 @@ export class ProjectDetailsPreview {
this.webviewPanel.webview.html = html;
}

private loadErrorHtml(error: string): string {
private loadErrorHtml(errors: string[]): string {
return /*html*/ `
<style>
pre {
Expand All @@ -156,8 +156,10 @@ export class ProjectDetailsPreview {
padding: 20px;
}
</style>
<p>Unable to load the project graph. The following error occurred:</p>
<pre>${error}</pre>
<p>Unable to load the project graph. The following errors occurred:</p>
${errors
.map((error) => '<pre>' + JSON.stringify(error) + '</pre>')
.join('')}
`;
}

Expand Down Expand Up @@ -239,8 +241,8 @@ export class ProjectDetailsPreview {
}

private debouncedRefresh = debounce(async () => {
const error = (await getNxWorkspace()).error;
if (error) {
const errors = (await getNxWorkspace()).errors;
if (errors) {
this.loadHtml();
} else if (this.isShowingErrorHtml) {
this.loadHtml();
Expand Down
26 changes: 0 additions & 26 deletions tools/scripts/copy-cloud-webview-deps.mjs

This file was deleted.

2 changes: 0 additions & 2 deletions tools/scripts/copy-to-vscode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const fs = require('fs-extra');

fs.copySync('./dist/apps/nxls', './dist/apps/vscode/nxls');
// TODO: ONLY ONE COPY
fs.copySync('./dist/apps/generate-ui', './dist/apps/vscode/generate-ui');
fs.copySync('./dist/apps/generate-ui-v2', './dist/apps/vscode/generate-ui-v2');

0 comments on commit 9fd7391

Please sign in to comment.