From 88444e835ff1efc7aa720e98d8305769daa68923 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sun, 27 Oct 2024 13:35:54 +0100 Subject: [PATCH] fix(compiler): Improve path handling in compiler options --- changelog.md | 6 ++++++ ts/00_commitinfo_data.ts | 2 +- ts/tsbuild.classes.compiler.ts | 16 ++++++++++++++++ ts/tsbuild.cli.ts | 12 ------------ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/changelog.md b/changelog.md index 4d1f525..44c64ba 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2024-10-27 - 2.1.85 - fix(compiler) +Improve path handling in compiler options + +- Refactored path import in tsbuild.classes.compiler.ts. +- Enhanced mergeCompilerOptions to read paths and baseUrl from tsconfig.json if present. + ## 2024-07-22 - 2.1.84 - fix(cli) Fixed transpilation order issue in tsfolders command diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index eef7b8a..f4e659e 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@git.zone/tsbuild', - version: '2.1.84', + version: '2.1.85', description: 'TypeScript nightly to easily make use of latest features' } diff --git a/ts/tsbuild.classes.compiler.ts b/ts/tsbuild.classes.compiler.ts index 7330898..32524cf 100644 --- a/ts/tsbuild.classes.compiler.ts +++ b/ts/tsbuild.classes.compiler.ts @@ -1,5 +1,6 @@ // import all the stuff we need import * as plugins from './plugins.js'; +import * as paths from './paths.js'; import type { CompilerOptions, ScriptTarget, ModuleKind } from './tsbuild.exports.js'; /** @@ -20,6 +21,7 @@ export const compilerOptionsDefault: CompilerOptions = { esModuleInterop: true, useDefineForClassFields: false, verbatimModuleSyntax: true, + baseUrl: './', }; /** @@ -49,6 +51,20 @@ export const mergeCompilerOptions = ( moduleResolution: plugins.typescript.ModuleResolutionKind.NodeJs, } : {}), + ...(() => { + const returnObject: CompilerOptions = {}; + console.log(`looking at tsconfig.json at ${paths.cwd}`); + const tsconfig = plugins.smartfile.fs.toObjectSync(plugins.path.join(paths.cwd, 'tsconfig.json')); + if (tsconfig && tsconfig.compilerOptions && tsconfig.compilerOptions.baseUrl) { + console.log('baseUrl found in tsconfig.json'); + returnObject.baseUrl = tsconfig.compilerOptions.baseUrl; + } + if (tsconfig && tsconfig.compilerOptions && tsconfig.compilerOptions.paths) { + console.log('paths found in tsconfig.json'); + returnObject.paths = tsconfig.compilerOptions.paths; + } + return returnObject; + })(), }; console.log(mergedOptions); diff --git a/ts/tsbuild.cli.ts b/ts/tsbuild.cli.ts index 0a39265..8e72d07 100644 --- a/ts/tsbuild.cli.ts +++ b/ts/tsbuild.cli.ts @@ -60,17 +60,5 @@ export const runCli = async () => { await tsbuild.compileGlobStringObject(compilationCommandObject, {}, process.cwd(), argvArg); }); - /** - * the custom command compiles any customDir to dist_customDir - */ - tsbuildCli.addCommand('interfaces').subscribe(async (argvArg) => { - const tsFolders = ['ts_interfaces']; - const compilationCommandObject: { [key: string]: string } = {}; - for (const tsFolder of tsFolders) { - compilationCommandObject[`./${tsFolder}/**/*.ts`] = `./dist_${tsFolder}`; - } - await tsbuild.compileGlobStringObject(compilationCommandObject, {}, process.cwd(), argvArg); - }); - tsbuildCli.startParse(); };