Skip to content

Commit

Permalink
fix: Avoid downstream need node polyfill for browser (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk authored Oct 27, 2023
1 parent 4ce05a1 commit bd9f1bd
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 11 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"test": "vitest run"
},
"devDependencies": {
"@types/node": "latest",
"typescript": "latest",
"vite": "latest",
"vitest": "latest"
Expand Down
3 changes: 3 additions & 0 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"vscode-languageserver-textdocument": "^1.0.11",
"vscode-uri": "^3.0.8"
},
"devDependencies": {
"@types/node": "latest"
},
"peerDependencies": {
"typescript": "*"
}
Expand Down
1 change: 1 addition & 0 deletions packages/labs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions packages/monaco/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)),
Expand Down
4 changes: 3 additions & 1 deletion packages/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion packages/typescript/src/languageServiceHost.ts
Original file line number Diff line number Diff line change
@@ -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<string, { lastVersion: number; snapshotVersions: WeakMap<ts.IScriptSnapshot, number>; }>();
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript/src/sys.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 { }
}
Expand Down
1 change: 1 addition & 0 deletions packages/typescript/src/typescript/corePublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"vscode-nls": "^5.2.0"
},
"devDependencies": {
"@types/node": "latest",
"@types/vscode": "^1.82.0",
"vscode-languageclient": "^9.0.1"
},
Expand Down
27 changes: 24 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd9f1bd

Please sign in to comment.