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..2bbe4eef7 100644 --- a/src/cli/tsconfig.ts +++ b/src/cli/tsconfig.ts @@ -58,13 +58,33 @@ export function parseConfigFileWithSystem( return updateParsedConfigFile(parsedConfigFile); } +function resolveNpmModuleConfig( + 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 = ts.pathIsAbsolute(configFilePath) + ? configFilePath + : ts.pathIsRelative(configFilePath) + ? path.resolve(configRootDir, configFilePath) + : resolveNpmModuleConfig(configFilePath, configRootDir, system); // if a path is neither relative nor absolute, it is probably a npm module + + 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..253bcade8 100644 --- a/src/typescript-internal.d.ts +++ b/src/typescript-internal.d.ts @@ -50,4 +50,13 @@ 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; + + export function pathIsAbsolute(path: string): boolean; + export function pathIsRelative(path: string): boolean; }