Skip to content

Commit 3cd2fd4

Browse files
fix: Avoid downstream need node polyfill for browser (#3696)
1 parent f5141bd commit 3cd2fd4

File tree

18 files changed

+65
-29
lines changed

18 files changed

+65
-29
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"chrome": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=./extensions/vscode ../volar-starter"
2222
},
2323
"devDependencies": {
24-
"@types/node": "latest",
2524
"@volar/language-service": "~1.10.9",
2625
"typescript": "latest",
2726
"vite": "latest",

packages/component-meta/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@
2525
"typescript": {
2626
"optional": true
2727
}
28+
},
29+
"devDependencies": {
30+
"@types/node": "latest"
2831
}
2932
}

packages/component-meta/src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ export type ComponentMetaChecker = ReturnType<typeof baseCreate>;
2222
const windowsPathReg = /\\/g;
2323

2424
export function createComponentMetaCheckerByJsonConfig(
25-
root: string,
25+
_rootPath: string,
2626
json: any,
2727
checkerOptions: MetaCheckerOptions = {},
2828
ts: typeof import('typescript/lib/tsserverlibrary') = require('typescript'),
2929
) {
30-
const rootPath = (root as path.OsPath).replace(windowsPathReg, '/') as path.PosixPath;
30+
const rootPath = _rootPath.replace(windowsPathReg, '/') as path.PosixPath;
3131
return createComponentMetaCheckerWorker(
32-
() => vue.createParsedCommandLineByJson(ts, ts.sys, root, json),
32+
() => vue.createParsedCommandLineByJson(ts, ts.sys, rootPath, json),
3333
checkerOptions,
3434
rootPath,
3535
path.join(rootPath, 'jsconfig.json.global.vue' as path.PosixPath),
@@ -38,13 +38,13 @@ export function createComponentMetaCheckerByJsonConfig(
3838
}
3939

4040
export function createComponentMetaChecker(
41-
tsconfigPath: string,
41+
_tsconfig: string,
4242
checkerOptions: MetaCheckerOptions = {},
4343
ts: typeof import('typescript/lib/tsserverlibrary') = require('typescript'),
4444
) {
45-
const tsconfig = (tsconfigPath as path.OsPath).replace(windowsPathReg, '/') as path.PosixPath;
45+
const tsconfig = _tsconfig.replace(windowsPathReg, '/') as path.PosixPath;
4646
return createComponentMetaCheckerWorker(
47-
() => vue.createParsedCommandLine(ts, ts.sys, tsconfigPath),
47+
() => vue.createParsedCommandLine(ts, ts.sys, tsconfig),
4848
checkerOptions,
4949
path.dirname(tsconfig),
5050
tsconfig + '.global.vue',
@@ -152,11 +152,11 @@ export function baseCreate(
152152
return _host[prop as keyof typeof _host];
153153
},
154154
}) as vue.TypeScriptLanguageHost;
155-
const vueLanguages = ts ? vue.createLanguages(
155+
const vueLanguages = vue.createLanguages(
156+
ts,
156157
host.getCompilationSettings(),
157158
vueCompilerOptions,
158-
ts,
159-
) : [];
159+
);
160160
const core = vue.createLanguageContext(host, vueLanguages);
161161
const tsLsHost = createLanguageServiceHost(core, ts, ts.sys);
162162
const tsLs = ts.createLanguageService(tsLsHost);

packages/language-core/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
"computeds": "^0.0.1",
2121
"minimatch": "^9.0.3",
2222
"muggle-string": "^0.3.1",
23+
"path-browserify": "^1.0.1",
2324
"vue-template-compiler": "^2.7.14"
2425
},
2526
"devDependencies": {
2627
"@types/minimatch": "^5.1.2",
28+
"@types/node": "latest",
29+
"@types/path-browserify": "^1.0.1",
2730
"@vue/compiler-sfc": "^3.3.0"
2831
},
2932
"peerDependencies": {

packages/language-core/src/generators/script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FileRangeCapabilities, MirrorBehaviorCapabilities } from '@volar/langua
22
import * as SourceMaps from '@volar/source-map';
33
import { Segment, getLength } from '@volar/source-map';
44
import * as muggle from 'muggle-string';
5-
import { posix as path } from 'path';
5+
import * as path from 'path-browserify';
66
import type * as ts from 'typescript/lib/tsserverlibrary';
77
import type * as templateGen from '../generators/template';
88
import type { ScriptRanges } from '../parsers/scriptRanges';

packages/language-core/src/languageModule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Language } from '@volar/language-core';
2-
import { posix as path } from 'path';
2+
import * as path from 'path-browserify';
33
import { getDefaultVueLanguagePlugins } from './plugins';
44
import { VueFile } from './virtualFile/vueFile';
55
import { VueCompilerOptions, VueLanguagePlugin } from './types';
@@ -118,9 +118,9 @@ export function createVueLanguage(
118118
* @deprecated planed to remove in 2.0, please use createVueLanguage instead of
119119
*/
120120
export function createLanguages(
121+
ts: typeof import('typescript/lib/tsserverlibrary'),
121122
compilerOptions: ts.CompilerOptions = {},
122123
vueCompilerOptions: Partial<VueCompilerOptions> = {},
123-
ts: typeof import('typescript/lib/tsserverlibrary') = require('typescript'),
124124
codegenStack: boolean = false,
125125
): Language[] {
126126
return [

packages/language-core/src/utils/ts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type * as ts from 'typescript/lib/tsserverlibrary';
2-
import * as path from 'path';
2+
import * as path from 'path-browserify';
33
import type { RawVueCompilerOptions, VueCompilerOptions, VueLanguagePlugin } from '../types';
44

55
export type ParsedCommandLine = ts.ParsedCommandLine & {

packages/language-plugin-pug/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"directory": "packages/language-plugin-pug"
1414
},
1515
"devDependencies": {
16+
"@types/node": "latest",
1617
"@vue/language-core": "1.8.22"
1718
},
1819
"dependencies": {

packages/language-server/src/languageServerPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export function createServerPlugin(connection: Connection) {
4141
}
4242

4343
return vue.resolveConfig(
44+
ts,
4445
config,
4546
ctx?.host.getCompilationSettings() ?? {},
4647
vueOptions,
47-
ts,
4848
initOptions.codegenStack,
4949
);
5050

packages/language-service/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"vscode-languageserver-textdocument": "^1.0.11"
3737
},
3838
"devDependencies": {
39+
"@types/node": "latest",
3940
"@volar/kit": "~1.10.9",
4041
"vscode-languageserver-protocol": "^3.17.5",
4142
"vscode-uri": "^3.0.8"

0 commit comments

Comments
 (0)