|
17 | 17 | * but semantic features will not return until the bridge is in place. |
18 | 18 | */ |
19 | 19 |
|
20 | | -import path, { dirname } from "node:path"; |
| 20 | +import path from "node:path"; |
21 | 21 | import type { LspCompanionSpec, LspServerSpec } from "./server-factory.js"; |
22 | 22 |
|
23 | 23 | export type VueBridgeMode = "auto" | "off"; |
@@ -64,9 +64,10 @@ export function inferVueLanguageServerLocation(vueExecutablePath: string): strin |
64 | 64 | return null; |
65 | 65 | } |
66 | 66 |
|
67 | | - const binDir = dirname(vueExecutablePath); // <root>/node_modules/.bin |
68 | | - const nodeModulesDir = dirname(binDir); // <root>/node_modules |
69 | | - return joinPathOnPlatform(nodeModulesDir, "@vue", "language-server"); |
| 67 | + const pathApi = getPathApi(vueExecutablePath); |
| 68 | + const binDir = pathApi.dirname(vueExecutablePath); // <root>/node_modules/.bin |
| 69 | + const nodeModulesDir = pathApi.dirname(binDir); // <root>/node_modules |
| 70 | + return pathApi.join(nodeModulesDir, "@vue", "language-server"); |
70 | 71 | } |
71 | 72 |
|
72 | 73 | export function buildVueSpecParts(inputs: VueSpecInputs): VueSpecParts { |
@@ -118,18 +119,20 @@ export function parseVueBridgeMode(value: string | undefined): VueBridgeMode { |
118 | 119 | return value.toLowerCase() === "off" ? "off" : "auto"; |
119 | 120 | } |
120 | 121 |
|
121 | | -function joinPathOnPlatform(...segments: string[]): string { |
122 | | - // Pick the path style based on the input that produced these segments by |
123 | | - // letting node:path decide via `path.join`. Tests can still pass either |
124 | | - // separator style. |
125 | | - return path.join(...segments); |
126 | | -} |
127 | | - |
128 | 122 | function deriveTsdk(vueLanguageServerLocation: string): string { |
129 | 123 | // typescript is installed at the sibling of @vue/language-server: |
130 | 124 | // <root>/node_modules/@vue/language-server <- location |
131 | 125 | // <root>/node_modules/typescript/lib <- tsdk |
132 | | - const vueAtDir = dirname(vueLanguageServerLocation); // <root>/node_modules/@vue |
133 | | - const nodeModulesDir = dirname(vueAtDir); // <root>/node_modules |
134 | | - return joinPathOnPlatform(nodeModulesDir, "typescript", "lib"); |
| 126 | + const pathApi = getPathApi(vueLanguageServerLocation); |
| 127 | + const vueAtDir = pathApi.dirname(vueLanguageServerLocation); // <root>/node_modules/@vue |
| 128 | + const nodeModulesDir = pathApi.dirname(vueAtDir); // <root>/node_modules |
| 129 | + return pathApi.join(nodeModulesDir, "typescript", "lib"); |
| 130 | +} |
| 131 | + |
| 132 | +function getPathApi(value: string) { |
| 133 | + return isWindowsStylePath(value) ? path.win32 : path.posix; |
| 134 | +} |
| 135 | + |
| 136 | +function isWindowsStylePath(value: string) { |
| 137 | + return /^[A-Za-z]:[\\/]/.test(value) || value.includes("\\"); |
135 | 138 | } |
0 commit comments