diff --git a/apps/nxls/.babelrc b/apps/nxls/.babelrc new file mode 100644 index 0000000000..fd4cbcdef1 --- /dev/null +++ b/apps/nxls/.babelrc @@ -0,0 +1,10 @@ +{ + "presets": [ + [ + "@nx/js/babel", + { + "useBuiltIns": "usage" + } + ] + ] +} diff --git a/apps/nxls/project.json b/apps/nxls/project.json index a45891ffc4..13297d76f9 100644 --- a/apps/nxls/project.json +++ b/apps/nxls/project.json @@ -24,6 +24,12 @@ "optimization": true, "extractLicenses": true, "webpackConfig": "apps/nxls/webpack.config.js" + }, + "configurations": { + "debug": { + "sourceMap": true, + "optimization": false + } } }, "build": { diff --git a/apps/nxls/src/main.ts b/apps/nxls/src/main.ts index e53cf49beb..4e1a519222 100644 --- a/apps/nxls/src/main.ts +++ b/apps/nxls/src/main.ts @@ -109,6 +109,8 @@ import { URI } from 'vscode-uri'; import { ensureOnlyJsonRpcStdout } from './ensureOnlyJsonRpcStdout'; import { NativeWatcher } from '@nx-console/shared-watcher'; +const connection = createConnection(ProposedFeatures.all); + process.on('unhandledRejection', (e: any) => { connection.console.error(formatError(`Unhandled exception`, e)); }); @@ -124,8 +126,6 @@ let unregisterFileWatcher: () => Promise = async () => { }; let reconfigureAttempts = 0; -const connection = createConnection(ProposedFeatures.all); - // Create a text document manager. const documents = new TextDocuments(TextDocument); @@ -138,12 +138,13 @@ connection.onInitialize(async (params) => { lspLogger.log('Initializing Nx Language Server'); const { workspacePath } = params.initializationOptions ?? {}; + const extractFsPath = (p: string | undefined) => p && URI.parse(p).fsPath; try { WORKING_PATH = - workspacePath || - params.workspaceFolders?.[0]?.uri || + extractFsPath(workspacePath) || + extractFsPath(params.workspaceFolders?.[0]?.uri) || params.rootPath || - URI.parse(params.rootUri ?? '').fsPath; + extractFsPath(params.rootUri ?? ''); if (!WORKING_PATH) { throw 'Unable to determine workspace path'; diff --git a/apps/nxls/webpack.config.js b/apps/nxls/webpack.config.js index 0be4f4f03c..ae6a21386f 100644 --- a/apps/nxls/webpack.config.js +++ b/apps/nxls/webpack.config.js @@ -4,5 +4,22 @@ const { composePlugins, withNx } = require('@nx/webpack'); module.exports = composePlugins(withNx(), (config) => { // Note: This was added by an Nx migration. Webpack builds are required to have a corresponding Webpack config file. // See: https://nx.dev/recipes/webpack/webpack-config-setup - return config; + return { + ...config, + module: { + ...config.module, + rules: [ + { + test: /libs\/shared\/npm\/src\/lib\/[^/]+-dependencies/, + loader: 'string-replace-loader', + options: { + search: 'require[(]([^\'"])', + replace: '__non_webpack_require__($1', + flags: 'g', + }, + }, + ...config.module?.rules, + ], + }, + }; }); diff --git a/libs/language-server/workspace/src/lib/get-project-graph-output.ts b/libs/language-server/workspace/src/lib/get-project-graph-output.ts index 53c6193e87..24cf890300 100644 --- a/libs/language-server/workspace/src/lib/get-project-graph-output.ts +++ b/libs/language-server/workspace/src/lib/get-project-graph-output.ts @@ -20,12 +20,12 @@ export async function getProjectGraphOutput(workspacePath: string) { async function getCacheDir(workspacePath: string): Promise { const importPath = await findNxPackagePath( workspacePath, - join('src', 'utils', 'cache-directory.js') + join('src', 'utils', 'cache-directory.js'), ); if (!importPath) { lspLogger.log( - `Unable to load the "nx" package from the workspace. Please ensure that the proper dependencies are installed locally.` + `Unable to load the "nx" package from the workspace. Please ensure that the proper dependencies are installed locally.`, ); throw 'local Nx dependency not found'; } diff --git a/libs/shared/file-system/src/lib/directory-exists.ts b/libs/shared/file-system/src/lib/directory-exists.ts index eff690f7eb..a43ec90e05 100644 --- a/libs/shared/file-system/src/lib/directory-exists.ts +++ b/libs/shared/file-system/src/lib/directory-exists.ts @@ -1,8 +1,9 @@ +import { URI } from 'vscode-uri'; import { stat } from 'fs/promises'; export async function directoryExists(filePath: string): Promise { try { - return (await stat(filePath)).isDirectory(); + return (await stat(URI.parse(filePath).fsPath)).isDirectory(); } catch { return false; } diff --git a/package.json b/package.json index d169c106b2..3fecb3dcf4 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,7 @@ "prettier-plugin-tailwindcss": "^0.6.11", "rimraf": "^3.0.2", "storybook": "9.0.9", + "string-replace-loader": "^3.2.0", "tailwindcss": "^3.3.2", "ts-jest": "29.4.0", "ts-node": "10.9.1", diff --git a/yarn.lock b/yarn.lock index e9f454d07c..97f7e59f0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16645,6 +16645,7 @@ __metadata: rxjs: 7.5.6 semver: ^7.7.1 storybook: 9.0.9 + string-replace-loader: ^3.2.0 tailwindcss: ^3.3.2 tar-stream: ^3.1.7 ts-jest: 29.4.0 @@ -19439,7 +19440,7 @@ __metadata: languageName: node linkType: hard -"schema-utils@npm:^4.0.0, schema-utils@npm:^4.0.1, schema-utils@npm:^4.2.0, schema-utils@npm:^4.3.0, schema-utils@npm:^4.3.2": +"schema-utils@npm:^4, schema-utils@npm:^4.0.0, schema-utils@npm:^4.0.1, schema-utils@npm:^4.2.0, schema-utils@npm:^4.3.0, schema-utils@npm:^4.3.2": version: 4.3.2 resolution: "schema-utils@npm:4.3.2" dependencies: @@ -20255,6 +20256,17 @@ __metadata: languageName: node linkType: hard +"string-replace-loader@npm:^3.2.0": + version: 3.2.0 + resolution: "string-replace-loader@npm:3.2.0" + dependencies: + schema-utils: ^4 + peerDependencies: + webpack: ^5 + checksum: da0fe6ad577465840986e56c5af1a357532b606d76e2bc93d560be99fe88b06b6d0b91857702e1c9ab31d15fe66c5ce266469fca24cd1cba3f3236348fea5824 + languageName: node + linkType: hard + "string-width-cjs@npm:string-width@^4.2.0, string-width@npm:^1.0.2 || 2 || 3 || 4, string-width@npm:^4.1.0, string-width@npm:^4.2.0, string-width@npm:^4.2.3": version: 4.2.3 resolution: "string-width@npm:4.2.3"