From a99f5e3aa4633e9373cce3558786d826ed43320c Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Fri, 27 Oct 2023 17:11:22 +0800 Subject: [PATCH 1/2] fix: avoid downstream need node polyfill --- package.json | 1 - packages/kit/package.json | 3 +++ .../src/languageFeatures/callHierarchy.ts | 5 +++-- packages/monaco/src/editor.ts | 4 ++-- packages/typescript/package.json | 4 +++- .../typescript/src/languageServiceHost.ts | 2 +- packages/typescript/src/sys.ts | 3 ++- .../typescript/src/typescript/corePublic.ts | 1 + pnpm-lock.yaml | 21 ++++++++++++++++--- 9 files changed, 33 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index be68e4b2..9f6b87a2 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "test": "vitest run" }, "devDependencies": { - "@types/node": "latest", "typescript": "latest", "vite": "latest", "vitest": "latest" diff --git a/packages/kit/package.json b/packages/kit/package.json index 000a1876..b2cf29ae 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -18,6 +18,9 @@ "vscode-languageserver-textdocument": "^1.0.11", "vscode-uri": "^3.0.8" }, + "devDependencies": { + "@types/node": "latest" + }, "peerDependencies": { "typescript": "*" } diff --git a/packages/language-service/src/languageFeatures/callHierarchy.ts b/packages/language-service/src/languageFeatures/callHierarchy.ts index 64031702..0cdc52e4 100644 --- a/packages/language-service/src/languageFeatures/callHierarchy.ts +++ b/packages/language-service/src/languageFeatures/callHierarchy.ts @@ -1,4 +1,3 @@ -import { posix as path } from 'path'; import type * as vscode from 'vscode-languageserver-protocol'; import type { ServiceContext } from '../types'; import { notEmpty } from '../utils/common'; @@ -187,7 +186,9 @@ export function register(context: ServiceContext) { const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(notEmpty); const vueItem: vscode.CallHierarchyItem = { ...tsItem, - name: tsItem.name === path.basename(context.env.uriToFileName(map.virtualFileDocument.uri)) ? path.basename(context.env.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name, + name: tsItem.name === map.virtualFileDocument.uri.substring(map.virtualFileDocument.uri.lastIndexOf('/') + 1) + ? map.sourceFileDocument.uri.substring(map.sourceFileDocument.uri.lastIndexOf('/') + 1) + : tsItem.name, uri: map.sourceFileDocument.uri, // TS Bug: `range: range` not works range: { diff --git a/packages/monaco/src/editor.ts b/packages/monaco/src/editor.ts index c901e6e2..0e437afd 100644 --- a/packages/monaco/src/editor.ts +++ b/packages/monaco/src/editor.ts @@ -58,7 +58,7 @@ export namespace editor { return; } - let timer: NodeJS.Timeout | undefined; + let timer: number | undefined; const changeSubscription = model.onDidChangeContent(() => { clearTimeout(timer); timer = setTimeout(() => doValidation(model), 250); @@ -122,7 +122,7 @@ export namespace editor { const disposables: IDisposable[] = []; const listener = new Map<_editor.IModel, IDisposable>(); - let timeout: NodeJS.Timeout | undefined; + let timeout: number | undefined; disposables.push( editor.onDidCreateModel((model) => hostingAutoInsertion(model)), diff --git a/packages/typescript/package.json b/packages/typescript/package.json index d7f856f2..5e14b383 100644 --- a/packages/typescript/package.json +++ b/packages/typescript/package.json @@ -13,9 +13,11 @@ "directory": "packages/typescript" }, "dependencies": { - "@volar/language-core": "1.10.6" + "@volar/language-core": "1.10.6", + "path-browserify": "^1.0.1" }, "devDependencies": { + "@types/path-browserify": "^1.0.1", "@volar/language-service": "1.10.6" } } diff --git a/packages/typescript/src/languageServiceHost.ts b/packages/typescript/src/languageServiceHost.ts index 5bf24a18..145f0ab3 100644 --- a/packages/typescript/src/languageServiceHost.ts +++ b/packages/typescript/src/languageServiceHost.ts @@ -1,6 +1,6 @@ import type { FileKind, VirtualFile, LanguageContext } from '@volar/language-core'; import type * as ts from 'typescript/lib/tsserverlibrary'; -import { posix as path } from 'path'; +import * as path from 'path-browserify'; import { matchFiles } from './typescript/utilities'; const fileVersions = new Map; }>(); diff --git a/packages/typescript/src/sys.ts b/packages/typescript/src/sys.ts index d98a3b3b..28a45e10 100644 --- a/packages/typescript/src/sys.ts +++ b/packages/typescript/src/sys.ts @@ -1,6 +1,6 @@ import type { FileChangeType, FileType, ServiceEnvironment, Disposable, FileStat } from '@volar/language-service'; import type * as ts from 'typescript/lib/tsserverlibrary'; -import { posix as path } from 'path'; +import * as path from 'path-browserify'; import { matchFiles } from './typescript/utilities'; interface File { @@ -109,6 +109,7 @@ export function createSys( if (sys.directoryExists(rootPath)) { // https://github.com/vuejs/language-tools/issues/2480 try { + // @ts-expect-error process.chdir(rootPath); } catch { } } diff --git a/packages/typescript/src/typescript/corePublic.ts b/packages/typescript/src/typescript/corePublic.ts index 9bdc464b..1790ad03 100644 --- a/packages/typescript/src/typescript/corePublic.ts +++ b/packages/typescript/src/typescript/corePublic.ts @@ -116,6 +116,7 @@ namespace NativeCollections { declare const self: any; const globals = typeof globalThis !== "undefined" ? globalThis : + // @ts-expect-error node global typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : undefined; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e19da0a8..ad39bb9c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,9 +15,6 @@ importers: specifier: latest version: 2.6.0(typescript@5.2.2) devDependencies: - '@types/node': - specifier: latest - version: 20.8.9 typescript: specifier: latest version: 5.2.2 @@ -48,6 +45,10 @@ importers: vscode-uri: specifier: ^3.0.8 version: 3.0.8 + devDependencies: + '@types/node': + specifier: latest + version: 20.8.9 packages/labs: devDependencies: @@ -167,7 +168,13 @@ importers: '@volar/language-core': specifier: 1.10.6 version: link:../language-core + path-browserify: + specifier: ^1.0.1 + version: 1.0.1 devDependencies: + '@types/path-browserify': + specifier: ^1.0.1 + version: 1.0.1 '@volar/language-service': specifier: 1.10.6 version: link:../language-service @@ -1142,6 +1149,10 @@ packages: dev: false optional: true + /@types/path-browserify@1.0.1: + resolution: {integrity: sha512-rUSqIy7fAfK6sRasdFCukWO4S77pXcTxViURlLdo1VKuekTDS8ASMdX1LA0TFlbzT3fZgFlgQTCrqmJBuTHpxA==} + dev: true + /@types/vscode@1.83.0: resolution: {integrity: sha512-3mUtHqLAVz9hegut9au4xehuBrzRE3UJiQMpoEHkNl6XHliihO7eATx2BMHs0odsmmrwjJrlixx/Pte6M3ygDQ==} dev: true @@ -4511,6 +4522,10 @@ packages: entities: 4.5.0 dev: true + /path-browserify@1.0.1: + resolution: {integrity: sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==} + dev: false + /path-exists@3.0.0: resolution: {integrity: sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==} engines: {node: '>=4'} From 620df5e5bcec569ca9d1a8628ce858e25036116a Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Fri, 27 Oct 2023 17:15:25 +0800 Subject: [PATCH 2/2] add @types/node for extensions --- packages/labs/package.json | 1 + packages/vscode/package.json | 1 + pnpm-lock.yaml | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/packages/labs/package.json b/packages/labs/package.json index c87bc676..d4bc3cc4 100644 --- a/packages/labs/package.json +++ b/packages/labs/package.json @@ -81,6 +81,7 @@ "size": "npm run prepack -- --metafile && esbuild-visualizer --metadata ./meta.json && open ./stats.html" }, "devDependencies": { + "@types/node": "latest", "@types/vscode": "^1.82.0", "@volar/language-server": "1.10.6", "@volar/source-map": "1.10.6", diff --git a/packages/vscode/package.json b/packages/vscode/package.json index 7aca2d6b..f543857f 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -18,6 +18,7 @@ "vscode-nls": "^5.2.0" }, "devDependencies": { + "@types/node": "latest", "@types/vscode": "^1.82.0", "vscode-languageclient": "^9.0.1" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad39bb9c..52396d28 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -52,6 +52,9 @@ importers: packages/labs: devDependencies: + '@types/node': + specifier: latest + version: 20.8.9 '@types/vscode': specifier: ^1.82.0 version: 1.83.0 @@ -191,6 +194,9 @@ importers: specifier: ^5.2.0 version: 5.2.0 devDependencies: + '@types/node': + specifier: latest + version: 20.8.9 '@types/vscode': specifier: ^1.82.0 version: 1.83.0