From 9f3b013a8254c718ee6d29cddd7204ce87aaa361 Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Thu, 19 Dec 2024 13:27:42 -0700 Subject: [PATCH] fix(core): Update logic to handle when outDir and rootDir are the same --- packages/js/src/plugins/typescript/plugin.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/js/src/plugins/typescript/plugin.ts b/packages/js/src/plugins/typescript/plugin.ts index d7957081b41c1..19b48c81804e0 100644 --- a/packages/js/src/plugins/typescript/plugin.ts +++ b/packages/js/src/plugins/typescript/plugin.ts @@ -22,6 +22,7 @@ import { existsSync, readdirSync, statSync } from 'node:fs'; import { basename, dirname, + extname, join, normalize, relative, @@ -622,6 +623,9 @@ function isValidPackageJsonBuildConfig( joinPathFragments(projectRoot, 'package.json') ); + const rootDir = tsConfig.options.rootDir ?? 'src'; + const resolvedRootDir = resolve(workspaceRoot, projectRoot, rootDir); + const outDir = tsConfig.options.outDir ? tsConfig.options.outDir : tsConfig.options.outFile @@ -629,18 +633,23 @@ function isValidPackageJsonBuildConfig( : false; const isPathSourceFile = (path: string): boolean => { + const ext = extname(path); if (!outDir) { // If `outDir` is not defined either from tsconfig.json or outFile the transpiled files will be in the same directory as the source files. // In this case, we assume that the source files are `.ts`, `.cts`, or `.mts`. - return ( - path.endsWith('.ts') || path.endsWith('.cts') || path.endsWith('.mts') - ); + // TODO: check/handle if the project is `.js` only + return ['.ts', '.cts', '.mts'].includes(ext); } const resolvedOutDir = resolve(workspaceRoot, projectRoot, outDir); const pathToCheck = resolve(workspaceRoot, projectRoot, path); - return !pathToCheck.startsWith(resolvedOutDir); + // If path is outside of the outDir, if the outDir and the root dir is same check the file type. + return ( + !pathToCheck.startsWith(resolvedOutDir) || + (pathToCheck.startsWith(resolvedRootDir) && + ['.ts', '.cts', '.mts'].includes(ext)) + ); }; // If `outFile` is defined, check the validity of the path.