From 82b071d96ce4af30aad5f910feb37450f4ecf4e8 Mon Sep 17 00:00:00 2001 From: Thijs Koerselman Date: Sat, 11 Jan 2025 14:56:07 +0100 Subject: [PATCH] Use get-tsconfig to resolve tsconfig settings --- package.json | 1 + pnpm-lock.yaml | 15 +++++++++++++++ src/lib/output/get-build-output-dir.ts | 13 +++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index c4df420..1dce332 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@pnpm/types": "^9.4.2", "chalk": "^5.3.0", "fs-extra": "^11.2.0", + "get-tsconfig": "^4.8.1", "glob": "^10.4.5", "outdent": "^0.8.0", "pnpm_lockfile_file_v8": "npm:@pnpm/lockfile-file@8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7aa03f1..bc5388f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: fs-extra: specifier: ^11.2.0 version: 11.2.0 + get-tsconfig: + specifier: ^4.8.1 + version: 4.8.1 glob: specifier: ^10.4.5 version: 10.4.5 @@ -1485,6 +1488,9 @@ packages: resolution: {integrity: sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==} engines: {node: '>=16'} + get-tsconfig@4.8.1: + resolution: {integrity: sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==} + glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} @@ -2248,6 +2254,9 @@ packages: resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} engines: {node: '>=8'} + resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + retry@0.12.0: resolution: {integrity: sha512-9LkiTwjUh6rT555DtE9rTX+BKByPfrMzEAtnlEtdEwr3Nkffwiihqe2bWADg+OQRjt9gl6ICdmB/ZFDCGAtSow==} engines: {node: '>= 4'} @@ -4139,6 +4148,10 @@ snapshots: get-stream@8.0.1: {} + get-tsconfig@4.8.1: + dependencies: + resolve-pkg-maps: 1.0.0 + glob-parent@5.1.2: dependencies: is-glob: 4.0.3 @@ -4970,6 +4983,8 @@ snapshots: resolve-from@5.0.0: {} + resolve-pkg-maps@1.0.0: {} + retry@0.12.0: {} reusify@1.0.4: {} diff --git a/src/lib/output/get-build-output-dir.ts b/src/lib/output/get-build-output-dir.ts index 9de52e5..55485de 100644 --- a/src/lib/output/get-build-output-dir.ts +++ b/src/lib/output/get-build-output-dir.ts @@ -1,9 +1,8 @@ -import fs from "fs-extra"; +import { getTsconfig } from "get-tsconfig"; import path from "node:path"; import outdent from "outdent"; import { useConfig } from "../config"; import { useLogger } from "../logger"; -import { readTypedJson } from "../utils"; export async function getBuildOutputDir(targetPackageDir: string) { const config = useConfig(); @@ -16,14 +15,12 @@ export async function getBuildOutputDir(targetPackageDir: string) { const tsconfigPath = path.join(targetPackageDir, config.tsconfigPath); - if (fs.existsSync(tsconfigPath)) { - log.debug("Found tsconfig at:", config.tsconfigPath); + const tsconfig = getTsconfig(tsconfigPath); - const tsconfig = await readTypedJson<{ - compilerOptions?: { outDir?: string }; - }>(tsconfigPath); + if (tsconfig) { + log.debug("Found tsconfig at:", tsconfig.path); - const outDir = tsconfig.compilerOptions?.outDir; + const outDir = tsconfig.config.compilerOptions?.outDir; if (outDir) { return path.join(targetPackageDir, outDir);