From 5b8079d7db309de7654b9da62b727d096ed46152 Mon Sep 17 00:00:00 2001 From: Dmitry Fuks Date: Fri, 21 Jun 2024 04:24:51 +0300 Subject: [PATCH] support typescript 5.4+ for IDE --- .vscode/settings.json | 2 +- package.json | 3 -- packages/example/package.json | 2 +- packages/plugin/package.json | 2 +- packages/plugin/src/ide/index.ts | 53 +++++++++++++++----------------- yarn.lock | 45 +++++++++++---------------- 6 files changed, 46 insertions(+), 61 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7629b32..d755c70 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,6 @@ "**/.yarn": true, "**/.pnp.*": true }, - "typescript.tsdk": ".yarn/sdks/typescript/lib", + "typescript.tsdk": "node_modules/typescript/lib", "typescript.enablePromptUseWorkspaceTsdk": true } diff --git a/package.json b/package.json index a629b02..1935d6f 100644 --- a/package.json +++ b/package.json @@ -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": "yarn@4.3.0" } diff --git a/packages/example/package.json b/packages/example/package.json index 3fec653..d03526d 100644 --- a/packages/example/package.json +++ b/packages/example/package.json @@ -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" }, diff --git a/packages/plugin/package.json b/packages/plugin/package.json index 14a433f..ec87789 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -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", diff --git a/packages/plugin/src/ide/index.ts b/packages/plugin/src/ide/index.ts index bd4da8e..3874f72 100644 --- a/packages/plugin/src/ide/index.ts +++ b/packages/plugin/src/ide/index.ts @@ -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'; @@ -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, diff --git a/yarn.lock b/yarn.lock index 3900e93..c5d893d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -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" @@ -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 @@ -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" @@ -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: @@ -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: @@ -6097,7 +6090,7 @@ __metadata: languageName: node linkType: hard -"resolve@patch:resolve@npm%3A^1.14.2#optional!builtin, resolve@patch:resolve@npm%3A^1.20.0#optional!builtin, resolve@patch:resolve@npm%3A^1.22.2#optional!builtin": +"resolve@patch:resolve@npm%3A^1.14.2#optional!builtin, resolve@patch:resolve@npm%3A^1.20.0#optional!builtin": version: 1.22.8 resolution: "resolve@patch:resolve@npm%3A1.22.8#optional!builtin::version=1.22.8&hash=c3c19d" dependencies: @@ -6110,7 +6103,7 @@ __metadata: languageName: node linkType: hard -"resolve@patch:resolve@npm%3A^1.22.4#optional!builtin": +"resolve@patch:resolve@npm%3A^1.22.2#optional!builtin, resolve@patch:resolve@npm%3A^1.22.4#optional!builtin": 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::version=1.22.8&hash=c3c19d" dependencies: @@ -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 @@ -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 @@ -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": - 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::version=5.5.1-rc&hash=b45daf" +"typescript@patch:typescript@npm%3A5.5.2#optional!builtin": + 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::version=5.5.2&hash=b45daf" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10c0/2bdee8341050466230dfd9c2202981062bbf50644d40452e8d164b5e8daa85a53bffc60ebca21d3d984fe2b752c63fcca33a7ddac67acf0d609ccab5b34847e0 + checksum: 10c0/6721ac8933a70c252d7b640b345792e103d881811ff660355617c1836526dbb71c2044e2e77a8823fb3570b469f33276875a4cab6d3c4de4ae7d7ee1c3074ae4 languageName: node linkType: hard @@ -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: