From 29381de7d98fb25b2186bb6daa5c4af543f48e1b Mon Sep 17 00:00:00 2001 From: trikadin Date: Wed, 11 Sep 2024 17:28:42 +0400 Subject: [PATCH] added tests + fixed missing declarationDir in excludes --- src/parse-tsconfig/index.ts | 31 ++++++++++++------- .../parse-tsconfig/extends/merges.spec.ts | 7 +++++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/parse-tsconfig/index.ts b/src/parse-tsconfig/index.ts index a2f7373..ce4829c 100644 --- a/src/parse-tsconfig/index.ts +++ b/src/parse-tsconfig/index.ts @@ -176,20 +176,29 @@ const _parseTsconfig = ( } } - let { outDir } = compilerOptions; - if (outDir) { - if (!Array.isArray(config.exclude)) { - config.exclude = []; - } + const outputFields = [ + 'outDir', + 'declarationDir' + ] as const satisfies Array>; - if (!config.exclude.includes(outDir)) { - config.exclude.push(outDir); - } + for (const outputField of outputFields) { + let outputPath = compilerOptions[outputField]; - if (!outDir.startsWith(configDirPlaceholder)) { - outDir = normalizeRelativePath(outDir); + if (outputPath) { + if (!Array.isArray(config.exclude)) { + config.exclude = []; + } + + if (!config.exclude.includes(outputPath)) { + config.exclude.push(outputPath); + } + + if (!outputPath.startsWith(configDirPlaceholder)) { + outputPath = normalizeRelativePath(outputPath); + } + + compilerOptions[outputField] = outputPath; } - compilerOptions.outDir = outDir; } } else { config.compilerOptions = {}; diff --git a/tests/specs/parse-tsconfig/extends/merges.spec.ts b/tests/specs/parse-tsconfig/extends/merges.spec.ts index c9008bf..6e71fd2 100644 --- a/tests/specs/parse-tsconfig/extends/merges.spec.ts +++ b/tests/specs/parse-tsconfig/extends/merges.spec.ts @@ -492,6 +492,13 @@ export default testSuite(({ describe }) => { 'tsconfig.json': createTsconfigJson({ compilerOptions: { outDir: '${configDir}-asdf/dist', + declarationDir: '${configDir}/dist/declaration', + outFile: '${configDir}/dist/outfile.js', + rootDir: '${configDir}/dist/src', + baseUrl: '${configDir}/dist/src', + tsBuildInfoFile: '${configDir}/dist/dist.tsbuildinfo', + rootDirs: ['${configDir}/src', '${configDir}/static'], + typeRoots: ['${configDir}/src/type', '${configDir}/types'], paths: { a: ['${configDir}_a/*'], b: ['ignores/${configDir}/*'],