Skip to content

Commit

Permalink
Merge pull request #3 from DiFuks/fix-ts-5.4
Browse files Browse the repository at this point in the history
support typescript 5.4+ for IDE
  • Loading branch information
DiFuks authored Jun 21, 2024
2 parents ca2ddbd + a661d17 commit bdef114
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"**/.yarn": true,
"**/.pnp.*": true
},
"typescript.tsdk": ".yarn/sdks/typescript/lib",
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
2 changes: 2 additions & 0 deletions .yarn/versions/e433a33d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
ts-overrides-plugin: patch
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@
"watch:ts-loader": "yarn workspace example watch:ts-loader",
"watch:fork-ts": "yarn workspace example watch:fork-ts"
},
"devDependencies": {
"typescript": "5.5.1-rc"
},
"packageManager": "[email protected]"
}
2 changes: 1 addition & 1 deletion packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ts-node": "^10.9.2",
"ts-overrides-plugin": "workspce:*",
"ts-patch": "3.2.0",
"typescript": "5.5.1-rc",
"typescript": "5.5.2",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"eslint": "8.57.0",
"eslint-config-fuks": "^2.0.0",
"ts-patch": "3.2.0",
"typescript": "5.5.1-rc"
"typescript": "5.5.2"
},
"peerDependencies": {
"ts-patch": "^3.0.0",
Expand Down
53 changes: 25 additions & 28 deletions packages/plugin/src/ide/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import outmatch from 'outmatch';
import * as path from 'path';
import { relative } from 'path';
import type ts from 'typescript/lib/tsserverlibrary';

import { type Override } from '../types/Override';
Expand All @@ -14,34 +14,31 @@ const getOverrideLanguageServices = (
languageServiceHost: ts.LanguageServiceHost,
docRegistry: ts.DocumentRegistry,
): ts.LanguageService[] =>
[...overridesFromConfig].reverse().map(override =>
typescript.createLanguageService(
new Proxy(languageServiceHost, {
get: (target, property: keyof ts.LanguageServiceHost) => {
if (property === `getScriptFileNames`) {
return (() => {
const originalFiles = target.getScriptFileNames();
const isMatch = outmatch(override.files);

return originalFiles.filter(fileName =>
isMatch(path.relative(target.getCurrentDirectory(), fileName)),
);
}) as ts.LanguageServiceHost['getScriptFileNames'];
}

if (property === `getCompilationSettings`) {
return (() => ({
...target.getCompilationSettings(),
...override.compilerOptions,
})) as ts.LanguageServiceHost['getCompilationSettings'];
}

return target[property as keyof ts.LanguageServiceHost];
},
[...overridesFromConfig].reverse().map(override => {
const overrideLanguageServiceHost: ts.LanguageServiceHost = {
fileExists: path => languageServiceHost.fileExists(path),
getCurrentDirectory: (): string => languageServiceHost.getCurrentDirectory(),
getDefaultLibFileName: (options: ts.CompilerOptions): string =>
languageServiceHost.getDefaultLibFileName(options),
getScriptSnapshot: fileName => languageServiceHost.getScriptSnapshot(fileName),
getScriptVersion: fileName => languageServiceHost.getScriptVersion(fileName),
readFile: (path, encoding) => languageServiceHost.readFile(path, encoding),
getCompilationSettings: () => ({
...languageServiceHost.getCompilationSettings(),
...override.compilerOptions,
}),
docRegistry,
),
);
getScriptFileNames: () => {
const originalFiles = languageServiceHost.getScriptFileNames();
const isMatch = outmatch(override.files);

return originalFiles.filter(fileName =>
isMatch(relative(languageServiceHost.getCurrentDirectory(), fileName)),
);
},
};

return typescript.createLanguageService(overrideLanguageServiceHost, docRegistry);
});

const getLanguageServiceForFile = (
fileName: string,
Expand Down
45 changes: 18 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3921,7 +3921,7 @@ __metadata:
ts-node: "npm:^10.9.2"
ts-overrides-plugin: "workspce:*"
ts-patch: "npm:3.2.0"
typescript: "npm:5.5.1-rc"
typescript: "npm:5.5.2"
webpack: "npm:^5.89.0"
webpack-cli: "npm:^5.1.4"
languageName: unknown
Expand Down Expand Up @@ -4311,7 +4311,7 @@ __metadata:

"global-prefix@npm:^3.0.0":
version: 3.0.0
resolution: "global-prefix@npm:3.0.0"
resolution: "global-prefix@npm:3.0.0::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2Fglobal-prefix%2F-%2Fglobal-prefix-3.0.0.tgz"
dependencies:
ini: "npm:^1.3.5"
kind-of: "npm:^6.0.2"
Expand Down Expand Up @@ -4562,7 +4562,7 @@ __metadata:

"ini@npm:^1.3.5":
version: 1.3.8
resolution: "ini@npm:1.3.8"
resolution: "ini@npm:1.3.8::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2Fini%2F-%2Fini-1.3.8.tgz"
checksum: 10c0/ec93838d2328b619532e4f1ff05df7909760b6f66d9c9e2ded11e5c1897d6f2f9980c54dd638f88654b00919ce31e827040631eab0a3969e4d1abefa0719516a
languageName: node
linkType: hard
Expand Down Expand Up @@ -5318,20 +5318,13 @@ __metadata:
languageName: node
linkType: hard

"minimist@npm:^1.2.0, minimist@npm:^1.2.6":
"minimist@npm:^1.2.0, minimist@npm:^1.2.6, minimist@npm:^1.2.8":
version: 1.2.8
resolution: "minimist@npm:1.2.8::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2Fminimist%2F-%2Fminimist-1.2.8.tgz"
checksum: 10c0/19d3fcdca050087b84c2029841a093691a91259a47def2f18222f41e7645a0b7c44ef4b40e88a1e58a40c84d2ef0ee6047c55594d298146d0eb3f6b737c20ce6
languageName: node
linkType: hard

"minimist@npm:^1.2.8":
version: 1.2.8
resolution: "minimist@npm:1.2.8"
checksum: 10c0/19d3fcdca050087b84c2029841a093691a91259a47def2f18222f41e7645a0b7c44ef4b40e88a1e58a40c84d2ef0ee6047c55594d298146d0eb3f6b737c20ce6
languageName: node
linkType: hard

"minipass-collect@npm:^2.0.1":
version: 2.0.1
resolution: "minipass-collect@npm:2.0.1"
Expand Down Expand Up @@ -6058,7 +6051,7 @@ __metadata:
languageName: node
linkType: hard

"resolve@npm:^1.14.2, resolve@npm:^1.20.0, resolve@npm:^1.22.2":
"resolve@npm:^1.14.2, resolve@npm:^1.20.0":
version: 1.22.8
resolution: "resolve@npm:1.22.8"
dependencies:
Expand All @@ -6071,7 +6064,7 @@ __metadata:
languageName: node
linkType: hard

"resolve@npm:^1.22.4":
"resolve@npm:^1.22.2, resolve@npm:^1.22.4":
version: 1.22.8
resolution: "resolve@npm:1.22.8::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2Fresolve%2F-%2Fresolve-1.22.8.tgz"
dependencies:
Expand All @@ -6097,7 +6090,7 @@ __metadata:
languageName: node
linkType: hard

"resolve@patch:resolve@npm%3A^1.14.2#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A^1.20.0#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A^1.22.2#optional!builtin<compat/resolve>":
"resolve@patch:resolve@npm%3A^1.14.2#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A^1.20.0#optional!builtin<compat/resolve>":
version: 1.22.8
resolution: "resolve@patch:resolve@npm%3A1.22.8#optional!builtin<compat/resolve>::version=1.22.8&hash=c3c19d"
dependencies:
Expand All @@ -6110,7 +6103,7 @@ __metadata:
languageName: node
linkType: hard

"resolve@patch:resolve@npm%3A^1.22.4#optional!builtin<compat/resolve>":
"resolve@patch:resolve@npm%3A^1.22.2#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A^1.22.4#optional!builtin<compat/resolve>":
version: 1.22.8
resolution: "resolve@patch:resolve@npm%3A1.22.8%3A%3A__archiveUrl=https%253A%252F%252Fregistry.npmjs.org%252Fresolve%252F-%252Fresolve-1.22.8.tgz#optional!builtin<compat/resolve>::version=1.22.8&hash=c3c19d"
dependencies:
Expand Down Expand Up @@ -6720,8 +6713,6 @@ __metadata:
"ts-overrides-plugin-sample@workspace:.":
version: 0.0.0-use.local
resolution: "ts-overrides-plugin-sample@workspace:."
dependencies:
typescript: "npm:5.5.1-rc"
languageName: unknown
linkType: soft

Expand All @@ -6736,7 +6727,7 @@ __metadata:
eslint-config-fuks: "npm:^2.0.0"
outmatch: "npm:^1.0.0"
ts-patch: "npm:3.2.0"
typescript: "npm:5.5.1-rc"
typescript: "npm:5.5.2"
peerDependencies:
ts-patch: ^3.0.0
typescript: ^5.0.0
Expand Down Expand Up @@ -6865,23 +6856,23 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:5.5.1-rc":
version: 5.5.1-rc
resolution: "typescript@npm:5.5.1-rc::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2Ftypescript%2F-%2Ftypescript-5.5.1-rc.tgz"
"typescript@npm:5.5.2":
version: 5.5.2
resolution: "typescript@npm:5.5.2::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2Ftypescript%2F-%2Ftypescript-5.5.2.tgz"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/c098e0a2c90472003bf5e4cb9548f2298beb7930cfdf65d529a7ca6e688bbf5ee77d00184a9de18921e13022000120740ff56fb109976d09eb4c5202b4cd343b
checksum: 10c0/8ca39b27b5f9bd7f32db795045933ab5247897660627251e8254180b792a395bf061ea7231947d5d7ffa5cb4cc771970fd4ef543275f9b559f08c9325cccfce3
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A5.5.1-rc#optional!builtin<compat/typescript>":
version: 5.5.1-rc
resolution: "typescript@patch:typescript@npm%3A5.5.1-rc%3A%3A__archiveUrl=https%253A%252F%252Fregistry.npmjs.org%252Ftypescript%252F-%252Ftypescript-5.5.1-rc.tgz#optional!builtin<compat/typescript>::version=5.5.1-rc&hash=b45daf"
"typescript@patch:typescript@npm%3A5.5.2#optional!builtin<compat/typescript>":
version: 5.5.2
resolution: "typescript@patch:typescript@npm%3A5.5.2%3A%3A__archiveUrl=https%253A%252F%252Fregistry.npmjs.org%252Ftypescript%252F-%252Ftypescript-5.5.2.tgz#optional!builtin<compat/typescript>::version=5.5.2&hash=b45daf"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/2bdee8341050466230dfd9c2202981062bbf50644d40452e8d164b5e8daa85a53bffc60ebca21d3d984fe2b752c63fcca33a7ddac67acf0d609ccab5b34847e0
checksum: 10c0/6721ac8933a70c252d7b640b345792e103d881811ff660355617c1836526dbb71c2044e2e77a8823fb3570b469f33276875a4cab6d3c4de4ae7d7ee1c3074ae4
languageName: node
linkType: hard

Expand Down Expand Up @@ -7188,7 +7179,7 @@ __metadata:

"which@npm:^1.3.1":
version: 1.3.1
resolution: "which@npm:1.3.1"
resolution: "which@npm:1.3.1::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2Fwhich%2F-%2Fwhich-1.3.1.tgz"
dependencies:
isexe: "npm:^2.0.0"
bin:
Expand Down

0 comments on commit bdef114

Please sign in to comment.