From 2813e663a06a5ac446d7519625c8dc111a10df8d Mon Sep 17 00:00:00 2001 From: pilaoda <793493083@qq.com> Date: Thu, 4 May 2023 09:21:16 +0800 Subject: [PATCH 1/4] support extends "tstl" object tsconfig.json in node_modules upgrade typescript to 5.0.4 to fix extends resolving. https://github.com/microsoft/TypeScript/pull/53443 --- package-lock.json | 14 +++++++------- package.json | 2 +- src/cli/tsconfig.ts | 18 +++++++++++++++++- src/typescript-internal.d.ts | 6 ++++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 61ee008ee..2b3dd2987 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,7 +37,7 @@ "prettier": "^2.8.4", "ts-jest": "^29.1.0", "ts-node": "^10.9.1", - "typescript": "^5.0.2" + "typescript": "^5.0.4" }, "engines": { "node": ">=16.10.0" @@ -6090,9 +6090,9 @@ } }, "node_modules/typescript": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.2.tgz", - "integrity": "sha512-wVORMBGO/FAs/++blGNeAVdbNKtIh1rbBL2EyQ1+J9lClJ93KiiKe8PmFIVdXhHcyv44SL9oglmfeSsndo0jRw==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -10840,9 +10840,9 @@ } }, "typescript": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.2.tgz", - "integrity": "sha512-wVORMBGO/FAs/++blGNeAVdbNKtIh1rbBL2EyQ1+J9lClJ93KiiKe8PmFIVdXhHcyv44SL9oglmfeSsndo0jRw==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", "dev": true }, "unbox-primitive": { diff --git a/package.json b/package.json index c41cb7abc..96cbd3876 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,6 @@ "prettier": "^2.8.4", "ts-jest": "^29.1.0", "ts-node": "^10.9.1", - "typescript": "^5.0.2" + "typescript": "^5.0.4" } } diff --git a/src/cli/tsconfig.ts b/src/cli/tsconfig.ts index dd6c4e9aa..dcf8bce99 100644 --- a/src/cli/tsconfig.ts +++ b/src/cli/tsconfig.ts @@ -58,13 +58,29 @@ export function parseConfigFileWithSystem( return updateParsedConfigFile(parsedConfigFile); } +function resolveJsonConfig( + moduleName: string, + configRootDir: string, + host: ts.ModuleResolutionHost +): string | undefined { + const resolved = ts.nodeNextJsonConfigResolver(moduleName, path.join(configRootDir, "tsconfig.json"), host); + if (resolved.resolvedModule) { + return resolved.resolvedModule.resolvedFileName; + } +} + function getExtendedTstlOptions( configFilePath: string, configRootDir: string, cycleCache: Set, system: ts.System ): TypeScriptToLuaOptions { - const absolutePath = path.isAbsolute(configFilePath) ? configFilePath : path.resolve(configRootDir, configFilePath); + const absolutePath = resolveJsonConfig(configFilePath, configRootDir, system); + + if (!absolutePath) { + return {}; + } + const newConfigRoot = path.dirname(absolutePath); if (cycleCache.has(absolutePath)) { diff --git a/src/typescript-internal.d.ts b/src/typescript-internal.d.ts index 59995ebce..073438e99 100644 --- a/src/typescript-internal.d.ts +++ b/src/typescript-internal.d.ts @@ -50,4 +50,10 @@ declare module "typescript" { function skipOuterExpressions(node: Expression, kinds?: OuterExpressionKinds): Expression; export function isOuterExpression(node: Node, kinds?: OuterExpressionKinds): node is OuterExpression; + + export function nodeNextJsonConfigResolver( + moduleName: string, + containingFile: string, + host: ModuleResolutionHost + ): ResolvedModuleWithFailedLookupLocations; } From a05933464521720f665aede955a761ca4642b1a7 Mon Sep 17 00:00:00 2001 From: pilaoda <793493083@qq.com> Date: Thu, 4 May 2023 09:25:07 +0800 Subject: [PATCH 2/4] support extends "tstl" object tsconfig.json in node_modules upgrade typescript to 5.0.4 to fix extends resolving. https://github.com/microsoft/TypeScript/pull/53443 --- src/cli/tsconfig.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cli/tsconfig.ts b/src/cli/tsconfig.ts index dcf8bce99..e538f8b2f 100644 --- a/src/cli/tsconfig.ts +++ b/src/cli/tsconfig.ts @@ -58,7 +58,11 @@ export function parseConfigFileWithSystem( return updateParsedConfigFile(parsedConfigFile); } -function resolveJsonConfig( +function pathIsRelative(path: string): boolean { + return /^\.\.?($|[\\/])/.test(path); +} + +function resolveModuleConfig( moduleName: string, configRootDir: string, host: ts.ModuleResolutionHost @@ -75,7 +79,11 @@ function getExtendedTstlOptions( cycleCache: Set, system: ts.System ): TypeScriptToLuaOptions { - const absolutePath = resolveJsonConfig(configFilePath, configRootDir, system); + const absolutePath = path.isAbsolute(configFilePath) + ? configFilePath + : pathIsRelative(configFilePath) + ? path.resolve(configRootDir, configFilePath) + : resolveModuleConfig(configFilePath, configRootDir, system); if (!absolutePath) { return {}; From a8ee334da794c6f138867960e9f29bb430602be9 Mon Sep 17 00:00:00 2001 From: pilaoda <793493083@qq.com> Date: Fri, 5 May 2023 09:23:38 +0800 Subject: [PATCH 3/4] using pathIsAbsolute and pathIsRelative from ts export with declaration. --- src/cli/tsconfig.ts | 8 ++------ src/typescript-internal.d.ts | 3 +++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cli/tsconfig.ts b/src/cli/tsconfig.ts index e538f8b2f..ce64608c6 100644 --- a/src/cli/tsconfig.ts +++ b/src/cli/tsconfig.ts @@ -58,10 +58,6 @@ export function parseConfigFileWithSystem( return updateParsedConfigFile(parsedConfigFile); } -function pathIsRelative(path: string): boolean { - return /^\.\.?($|[\\/])/.test(path); -} - function resolveModuleConfig( moduleName: string, configRootDir: string, @@ -79,9 +75,9 @@ function getExtendedTstlOptions( cycleCache: Set, system: ts.System ): TypeScriptToLuaOptions { - const absolutePath = path.isAbsolute(configFilePath) + const absolutePath = ts.pathIsAbsolute(configFilePath) ? configFilePath - : pathIsRelative(configFilePath) + : ts.pathIsRelative(configFilePath) ? path.resolve(configRootDir, configFilePath) : resolveModuleConfig(configFilePath, configRootDir, system); diff --git a/src/typescript-internal.d.ts b/src/typescript-internal.d.ts index 073438e99..253bcade8 100644 --- a/src/typescript-internal.d.ts +++ b/src/typescript-internal.d.ts @@ -56,4 +56,7 @@ declare module "typescript" { containingFile: string, host: ModuleResolutionHost ): ResolvedModuleWithFailedLookupLocations; + + export function pathIsAbsolute(path: string): boolean; + export function pathIsRelative(path: string): boolean; } From 36ef59357c95cb07b007c98c598cefa1160fffd6 Mon Sep 17 00:00:00 2001 From: pilaoda <793493083@qq.com> Date: Fri, 5 May 2023 17:14:11 +0800 Subject: [PATCH 4/4] add a comment in code explaining that if a path is not absolute and not relative that it is then a module path that needs to be resolved --- src/cli/tsconfig.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/tsconfig.ts b/src/cli/tsconfig.ts index ce64608c6..2bbe4eef7 100644 --- a/src/cli/tsconfig.ts +++ b/src/cli/tsconfig.ts @@ -58,7 +58,7 @@ export function parseConfigFileWithSystem( return updateParsedConfigFile(parsedConfigFile); } -function resolveModuleConfig( +function resolveNpmModuleConfig( moduleName: string, configRootDir: string, host: ts.ModuleResolutionHost @@ -79,7 +79,7 @@ function getExtendedTstlOptions( ? configFilePath : ts.pathIsRelative(configFilePath) ? path.resolve(configRootDir, configFilePath) - : resolveModuleConfig(configFilePath, configRootDir, system); + : resolveNpmModuleConfig(configFilePath, configRootDir, system); // if a path is neither relative nor absolute, it is probably a npm module if (!absolutePath) { return {};