diff --git a/extensions/vscode/scripts/build.js b/extensions/vscode/scripts/build.js index 39acc64a1f..5521269430 100644 --- a/extensions/vscode/scripts/build.js +++ b/extensions/vscode/scripts/build.js @@ -1,6 +1,6 @@ // @ts-check -const path = require('path'); -const fs = require('fs'); +const fs = require('node:fs'); +const path = require('node:path'); require('esbuild').context({ entryPoints: { diff --git a/package.json b/package.json index b761c8a242..d71d85e855 100644 --- a/package.json +++ b/package.json @@ -26,5 +26,10 @@ "@tsslint/config": "latest", "typescript": "latest", "vitest": "latest" + }, + "pnpm": { + "patchedDependencies": { + "pathe": "patches/pathe.patch" + } } } diff --git a/packages/component-meta/README.md b/packages/component-meta/README.md index 040e638b8e..ef77794846 100644 --- a/packages/component-meta/README.md +++ b/packages/component-meta/README.md @@ -7,8 +7,8 @@ First of all, you need to create a component meta checker using `createChecker`: ```ts -import * as url from 'url' -import path from 'path' +import * as path from 'node:path' +import * as url from 'node:url' import type { MetaCheckerOptions } from 'vue-component-meta' import { createChecker } from 'vue-component-meta' @@ -31,8 +31,8 @@ const tsconfigChecker = createChecker( Now, you can extract the component meta using `getComponentMeta` method of checker: ```ts -import * as url from 'url' -import path from 'path' +import * as path from 'node:path' +import * as url from 'node:url' const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) diff --git a/packages/component-meta/lib/base.ts b/packages/component-meta/lib/base.ts index c65a7cf43d..447c20734a 100644 --- a/packages/component-meta/lib/base.ts +++ b/packages/component-meta/lib/base.ts @@ -1,6 +1,6 @@ import { TypeScriptProjectHost, createLanguageServiceHost, resolveFileLanguageId } from '@volar/typescript'; import * as vue from '@vue/language-core'; -import { posix as path } from 'path-browserify'; +import path from 'pathe'; import type * as ts from 'typescript'; import { code as typeHelpersCode } from 'vue-component-type-helpers'; import { code as vue2TypeHelpersCode } from 'vue-component-type-helpers/vue2'; @@ -18,15 +18,13 @@ import type { export * from './types'; -const windowsPathReg = /\\/g; - export function createCheckerByJsonConfigBase( ts: typeof import('typescript'), rootDir: string, json: any, checkerOptions: MetaCheckerOptions = {} ) { - rootDir = rootDir.replace(windowsPathReg, '/'); + rootDir = path.normalize(rootDir); return baseCreate( ts, () => vue.createParsedCommandLineByJson(ts, ts.sys, rootDir, json, undefined, true), @@ -41,7 +39,7 @@ export function createCheckerBase( tsconfig: string, checkerOptions: MetaCheckerOptions = {} ) { - tsconfig = tsconfig.replace(windowsPathReg, '/'); + tsconfig = path.normalize(tsconfig); return baseCreate( ts, () => vue.createParsedCommandLine(ts, ts.sys, tsconfig, true), @@ -59,7 +57,7 @@ export function baseCreate( globalComponentName: string ) { let commandLine = getCommandLine(); - let fileNames = commandLine.fileNames.map(path => path.replace(windowsPathReg, '/')); + let fileNames = commandLine.fileNames.map(path.normalize); let projectVersion = 0; const projectHost: TypeScriptProjectHost = { @@ -188,18 +186,18 @@ export function baseCreate( getExportNames, getComponentMeta, updateFile(fileName: string, text: string) { - fileName = fileName.replace(windowsPathReg, '/'); + fileName = path.normalize(fileName); scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text)); projectVersion++; }, deleteFile(fileName: string) { - fileName = fileName.replace(windowsPathReg, '/'); + fileName = path.normalize(fileName); fileNames = fileNames.filter(f => f !== fileName); projectVersion++; }, reload() { commandLine = getCommandLine(); - fileNames = commandLine.fileNames.map(path => path.replace(windowsPathReg, '/')); + fileNames = commandLine.fileNames.map(path.normalize); this.clearCache(); }, clearCache() { diff --git a/packages/component-meta/package.json b/packages/component-meta/package.json index 8030b51e6d..c32b483b6a 100644 --- a/packages/component-meta/package.json +++ b/packages/component-meta/package.json @@ -15,7 +15,7 @@ "dependencies": { "@volar/typescript": "~2.4.11", "@vue/language-core": "2.2.0", - "path-browserify": "^1.0.1", + "pathe": "^1.1.2", "vue-component-type-helpers": "2.2.0" }, "peerDependencies": { @@ -27,7 +27,6 @@ } }, "devDependencies": { - "@types/node": "latest", - "@types/path-browserify": "latest" + "@types/node": "latest" } } diff --git a/packages/language-core/lib/codegen/script/componentSelf.ts b/packages/language-core/lib/codegen/script/componentSelf.ts index 331c21d823..3b9d3634df 100644 --- a/packages/language-core/lib/codegen/script/componentSelf.ts +++ b/packages/language-core/lib/codegen/script/componentSelf.ts @@ -1,4 +1,4 @@ -import * as path from 'path-browserify'; +import path from 'pathe'; import type { Code } from '../../types'; import type { TemplateCodegenContext } from '../template/context'; import { endOfLine, generateSfcBlockSection, newLine } from '../utils'; diff --git a/packages/language-core/lib/codegen/script/index.ts b/packages/language-core/lib/codegen/script/index.ts index 9c975f325d..78091c3933 100644 --- a/packages/language-core/lib/codegen/script/index.ts +++ b/packages/language-core/lib/codegen/script/index.ts @@ -1,5 +1,5 @@ import type { Mapping } from '@volar/language-core'; -import * as path from 'path-browserify'; +import path from 'pathe'; import type * as ts from 'typescript'; import type { ScriptRanges } from '../../parsers/scriptRanges'; import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges'; diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index 982e37a909..4d261770a2 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -1,4 +1,4 @@ -import * as path from 'path-browserify'; +import path from 'pathe'; import type { Code } from '../../types'; import { getSlotsPropertyName, hyphenateTag } from '../../utils/shared'; import { TemplateCodegenContext, createTemplateCodegenContext } from '../template/context'; diff --git a/packages/language-core/lib/utils/ts.ts b/packages/language-core/lib/utils/ts.ts index ff9e3471a1..390e56294d 100644 --- a/packages/language-core/lib/utils/ts.ts +++ b/packages/language-core/lib/utils/ts.ts @@ -1,5 +1,5 @@ import { camelize } from '@vue/shared'; -import { posix as path } from 'path-browserify'; +import path from 'pathe'; import type * as ts from 'typescript'; import { generateGlobalTypes } from '../codegen/globalTypes'; import { getAllExtensions } from '../languagePlugin'; diff --git a/packages/language-core/package.json b/packages/language-core/package.json index ef9a69958c..0a66e46be4 100644 --- a/packages/language-core/package.json +++ b/packages/language-core/package.json @@ -20,12 +20,11 @@ "alien-signals": "^0.4.9", "minimatch": "^9.0.3", "muggle-string": "^0.4.1", - "path-browserify": "^1.0.1" + "pathe": "^1.1.2" }, "devDependencies": { "@types/minimatch": "^5.1.2", "@types/node": "latest", - "@types/path-browserify": "^1.0.1", "@volar/typescript": "~2.4.11", "@vue/compiler-sfc": "^3.5.0" }, diff --git a/packages/language-server/lib/hybridModeProject.ts b/packages/language-server/lib/hybridModeProject.ts index e9747126bd..2f546409d1 100644 --- a/packages/language-server/lib/hybridModeProject.ts +++ b/packages/language-server/lib/hybridModeProject.ts @@ -3,6 +3,7 @@ import { createLanguageServiceEnvironment } from '@volar/language-server/lib/pro import { createLanguage } from '@vue/language-core'; import { createLanguageService, createUriMap, LanguageService } from '@vue/language-service'; import { configuredServers, getBestServer, inferredServers, onServerReady } from '@vue/typescript-plugin/lib/utils'; +import path from 'pathe'; import { URI } from 'vscode-uri'; export function createHybridModeProject( @@ -86,7 +87,7 @@ export function createHybridModeProject( return project; function asFileName(uri: URI) { - return uri.fsPath.replace(/\\/g, '/'); + return path.normalize(uri.fsPath); } async function createLs(server: LanguageServer, tsconfig: string | undefined) { diff --git a/packages/language-server/package.json b/packages/language-server/package.json index c29ccbf7d7..4d16152c33 100644 --- a/packages/language-server/package.json +++ b/packages/language-server/package.json @@ -22,6 +22,7 @@ "@vue/language-core": "2.2.0", "@vue/language-service": "2.2.0", "@vue/typescript-plugin": "2.2.0", + "pathe": "^1.1.2", "vscode-languageserver-protocol": "^3.17.5", "vscode-uri": "^3.0.8" } diff --git a/packages/language-service/lib/plugins/vue-autoinsert-dotvalue.ts b/packages/language-service/lib/plugins/vue-autoinsert-dotvalue.ts index 6d0265545c..db3a5477c3 100644 --- a/packages/language-service/lib/plugins/vue-autoinsert-dotvalue.ts +++ b/packages/language-service/lib/plugins/vue-autoinsert-dotvalue.ts @@ -1,5 +1,6 @@ import type { LanguageServiceContext, LanguageServicePlugin } from '@volar/language-service'; import { hyphenateAttr } from '@vue/language-core'; +import path from 'pathe'; import type * as ts from 'typescript'; import type { TextDocument } from 'vscode-languageserver-textdocument'; import { URI } from 'vscode-uri'; @@ -69,7 +70,7 @@ export function create( let sourceCodeOffset = document.offsetAt(selection); const fileName = context.project.typescript?.uriConverter.asFileName(sourceScript.id) - ?? sourceScript.id.fsPath.replace(/\\/g, '/'); + ?? path.normalize(sourceScript.id.fsPath); if (sourceScript.generated) { const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root); diff --git a/packages/language-service/lib/plugins/vue-document-drop.ts b/packages/language-service/lib/plugins/vue-document-drop.ts index 79fbb2d67b..5d9f908ca0 100644 --- a/packages/language-service/lib/plugins/vue-document-drop.ts +++ b/packages/language-service/lib/plugins/vue-document-drop.ts @@ -1,6 +1,6 @@ import { VueVirtualCode, forEachEmbeddedCode } from '@vue/language-core'; import { camelize, capitalize, hyphenate } from '@vue/shared'; -import { posix as path } from 'path-browserify'; +import path from 'pathe'; import { getUserPreferences } from 'volar-service-typescript/lib/configs/getUserPreferences'; import type * as vscode from 'vscode-languageserver-protocol'; import { URI } from 'vscode-uri'; @@ -70,7 +70,7 @@ export function create( const code = [...forEachEmbeddedCode(root)].find(code => code.id === (sfc.scriptSetup ? 'scriptsetup_raw' : 'script_raw'))!; const lastImportNode = getLastImportNode(ts, script.ast); const incomingFileName = context.project.typescript?.uriConverter.asFileName(URI.parse(importUri)) - ?? URI.parse(importUri).fsPath.replace(/\\/g, '/'); + ?? path.normalize(URI.parse(importUri).fsPath); let importPath: string | undefined; diff --git a/packages/language-service/package.json b/packages/language-service/package.json index 6a4e20ab0b..cb2c2321f9 100644 --- a/packages/language-service/package.json +++ b/packages/language-service/package.json @@ -25,7 +25,7 @@ "@vue/shared": "^3.5.0", "@vue/typescript-plugin": "2.2.0", "alien-signals": "^0.4.9", - "path-browserify": "^1.0.1", + "pathe": "^1.1.2", "volar-service-css": "0.0.62", "volar-service-emmet": "0.0.62", "volar-service-html": "0.0.62", @@ -40,7 +40,6 @@ }, "devDependencies": { "@types/node": "latest", - "@types/path-browserify": "latest", "@volar/kit": "~2.4.11", "vscode-languageserver-protocol": "^3.17.5" } diff --git a/packages/language-service/scripts/update-html-data.js b/packages/language-service/scripts/update-html-data.js index d54a2c518b..aa30a2ab98 100644 --- a/packages/language-service/scripts/update-html-data.js +++ b/packages/language-service/scripts/update-html-data.js @@ -1,6 +1,6 @@ // @ts-check -const fs = require('fs'); -const path = require('path'); +const fs = require('node:fs'); +const path = require('node:path'); const langs = [ { name: 'en', diff --git a/patches/pathe.patch b/patches/pathe.patch new file mode 100644 index 0000000000..1abecd61a3 --- /dev/null +++ b/patches/pathe.patch @@ -0,0 +1,10 @@ +diff --git a/dist/index.d.ts b/dist/index.d.ts +index 531b6906507206b4594ff0ff830d605c4cf6a16a..a7419c0c83af0880c6a41180f46581c5922bc947 100644 +--- a/dist/index.d.ts ++++ b/dist/index.d.ts +@@ -1,4 +1,4 @@ +-import path$1 from 'node:path'; ++import * as path$1 from 'node:path'; + + declare const sep = "/"; + declare const delimiter = ":"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 798a4265fb..033d3db239 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,11 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +patchedDependencies: + pathe: + hash: tzb4ikqzvp65igqqf3ehxc5e4q + path: patches/pathe.patch + importers: .: @@ -77,9 +82,9 @@ importers: '@vue/language-core': specifier: 2.2.0 version: link:../language-core - path-browserify: - specifier: ^1.0.1 - version: 1.0.1 + pathe: + specifier: ^1.1.2 + version: 1.1.2(patch_hash=tzb4ikqzvp65igqqf3ehxc5e4q) typescript: specifier: '*' version: 5.7.2 @@ -90,9 +95,6 @@ importers: '@types/node': specifier: latest version: 22.10.2 - '@types/path-browserify': - specifier: latest - version: 1.0.3 packages/component-type-helpers: {} @@ -119,9 +121,9 @@ importers: muggle-string: specifier: ^0.4.1 version: 0.4.1 - path-browserify: - specifier: ^1.0.1 - version: 1.0.1 + pathe: + specifier: ^1.1.2 + version: 1.1.2(patch_hash=tzb4ikqzvp65igqqf3ehxc5e4q) typescript: specifier: '*' version: 5.7.2 @@ -132,9 +134,6 @@ importers: '@types/node': specifier: latest version: 22.10.2 - '@types/path-browserify': - specifier: ^1.0.1 - version: 1.0.3 '@volar/typescript': specifier: ~2.4.11 version: 2.4.11 @@ -178,6 +177,9 @@ importers: '@vue/typescript-plugin': specifier: 2.2.0 version: link:../typescript-plugin + pathe: + specifier: ^1.1.2 + version: 1.1.2(patch_hash=tzb4ikqzvp65igqqf3ehxc5e4q) vscode-languageserver-protocol: specifier: ^3.17.5 version: 3.17.5 @@ -211,9 +213,9 @@ importers: alien-signals: specifier: ^0.4.9 version: 0.4.9 - path-browserify: - specifier: ^1.0.1 - version: 1.0.1 + pathe: + specifier: ^1.1.2 + version: 1.1.2(patch_hash=tzb4ikqzvp65igqqf3ehxc5e4q) volar-service-css: specifier: 0.0.62 version: 0.0.62(@volar/language-service@2.4.11) @@ -251,9 +253,6 @@ importers: '@types/node': specifier: latest version: 22.10.2 - '@types/path-browserify': - specifier: latest - version: 1.0.3 '@volar/kit': specifier: ~2.4.11 version: 2.4.11(typescript@5.7.2) @@ -944,51 +943,61 @@ packages: resolution: {integrity: sha512-QAg11ZIt6mcmzpNE6JZBpKfJaKkqTm1A9+y9O+frdZJEuhQxiugM05gnCWiANHj4RmbgeVJpTdmKRmH/a+0QbA==} cpu: [arm] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.28.1': resolution: {integrity: sha512-dRP9PEBfolq1dmMcFqbEPSd9VlRuVWEGSmbxVEfiq2cs2jlZAl0YNxFzAQS2OrQmsLBLAATDMb3Z6MFv5vOcXg==} cpu: [arm] os: [linux] + libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.28.1': resolution: {integrity: sha512-uGr8khxO+CKT4XU8ZUH1TTEUtlktK6Kgtv0+6bIFSeiSlnGJHG1tSFSjm41uQ9sAO/5ULx9mWOz70jYLyv1QkA==} cpu: [arm64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.28.1': resolution: {integrity: sha512-QF54q8MYGAqMLrX2t7tNpi01nvq5RI59UBNx+3+37zoKX5KViPo/gk2QLhsuqok05sSCRluj0D00LzCwBikb0A==} cpu: [arm64] os: [linux] + libc: [musl] '@rollup/rollup-linux-loongarch64-gnu@4.28.1': resolution: {integrity: sha512-vPul4uodvWvLhRco2w0GcyZcdyBfpfDRgNKU+p35AWEbJ/HPs1tOUrkSueVbBS0RQHAf/A+nNtDpvw95PeVKOA==} cpu: [loong64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-powerpc64le-gnu@4.28.1': resolution: {integrity: sha512-pTnTdBuC2+pt1Rmm2SV7JWRqzhYpEILML4PKODqLz+C7Ou2apEV52h19CR7es+u04KlqplggmN9sqZlekg3R1A==} cpu: [ppc64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.28.1': resolution: {integrity: sha512-vWXy1Nfg7TPBSuAncfInmAI/WZDd5vOklyLJDdIRKABcZWojNDY0NJwruY2AcnCLnRJKSaBgf/GiJfauu8cQZA==} cpu: [riscv64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-s390x-gnu@4.28.1': resolution: {integrity: sha512-/yqC2Y53oZjb0yz8PVuGOQQNOTwxcizudunl/tFs1aLvObTclTwZ0JhXF2XcPT/zuaymemCDSuuUPXJJyqeDOg==} cpu: [s390x] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.28.1': resolution: {integrity: sha512-fzgeABz7rrAlKYB0y2kSEiURrI0691CSL0+KXwKwhxvj92VULEDQLpBYLHpF49MSiPG4sq5CK3qHMnb9tlCjBw==} cpu: [x64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-musl@4.28.1': resolution: {integrity: sha512-xQTDVzSGiMlSshpJCtudbWyRfLaNiVPXt1WgdWTwWz9n0U12cI2ZVtWe/Jgwyv/6wjL7b66uu61Vg0POWVfz4g==} cpu: [x64] os: [linux] + libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.28.1': resolution: {integrity: sha512-wSXmDRVupJstFP7elGMgv+2HqXelQhuNf+IS4V+nUpNVi/GUiBgDmfwD0UGN3pcAnWsgKG3I52wMOBnk1VHr/A==} @@ -1070,9 +1079,6 @@ packages: '@types/parse-path@7.0.3': resolution: {integrity: sha512-LriObC2+KYZD3FzCrgWGv/qufdUy4eXrxcLgQMfYXgPbLIecKIsVBaQgUPmxSSLcjmYbDTQbMgr6qr6l/eb7Bg==} - '@types/path-browserify@1.0.3': - resolution: {integrity: sha512-ZmHivEbNCBtAfcrFeBCiTjdIc2dey0l7oCGNGpSuRTy8jP6UVND7oUowlvDujBy8r2Hoa8bfFUOCiPWfmtkfxw==} - '@types/semver@7.5.8': resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==} @@ -4211,8 +4217,6 @@ snapshots: '@types/parse-path@7.0.3': {} - '@types/path-browserify@1.0.3': {} - '@types/semver@7.5.8': {} '@types/vscode@1.96.0': {} @@ -4239,13 +4243,13 @@ snapshots: '@vitest/runner@2.1.8': dependencies: '@vitest/utils': 2.1.8 - pathe: 1.1.2 + pathe: 1.1.2(patch_hash=tzb4ikqzvp65igqqf3ehxc5e4q) '@vitest/snapshot@2.1.8': dependencies: '@vitest/pretty-format': 2.1.8 magic-string: 0.30.17 - pathe: 1.1.2 + pathe: 1.1.2(patch_hash=tzb4ikqzvp65igqqf3ehxc5e4q) '@vitest/spy@2.1.8': dependencies: @@ -5883,7 +5887,7 @@ snapshots: lru-cache: 11.0.2 minipass: 7.1.2 - pathe@1.1.2: {} + pathe@1.1.2(patch_hash=tzb4ikqzvp65igqqf3ehxc5e4q): {} pathval@2.0.0: {} @@ -6395,7 +6399,7 @@ snapshots: cac: 6.7.14 debug: 4.4.0 es-module-lexer: 1.5.4 - pathe: 1.1.2 + pathe: 1.1.2(patch_hash=tzb4ikqzvp65igqqf3ehxc5e4q) vite: 5.4.11(@types/node@22.10.2) transitivePeerDependencies: - '@types/node' @@ -6430,7 +6434,7 @@ snapshots: debug: 4.4.0 expect-type: 1.1.0 magic-string: 0.30.17 - pathe: 1.1.2 + pathe: 1.1.2(patch_hash=tzb4ikqzvp65igqqf3ehxc5e4q) std-env: 3.8.0 tinybench: 2.9.0 tinyexec: 0.3.1