fix(compiler): Improve path handling in compiler options

This commit is contained in:
Philipp Kunz 2024-10-27 13:35:54 +01:00
parent 4892c8f7ae
commit 88444e835f
4 changed files with 23 additions and 13 deletions

View File

@ -1,5 +1,11 @@
# Changelog # 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) ## 2024-07-22 - 2.1.84 - fix(cli)
Fixed transpilation order issue in tsfolders command Fixed transpilation order issue in tsfolders command

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@git.zone/tsbuild', name: '@git.zone/tsbuild',
version: '2.1.84', version: '2.1.85',
description: 'TypeScript nightly to easily make use of latest features' description: 'TypeScript nightly to easily make use of latest features'
} }

View File

@ -1,5 +1,6 @@
// import all the stuff we need // import all the stuff we need
import * as plugins from './plugins.js'; import * as plugins from './plugins.js';
import * as paths from './paths.js';
import type { CompilerOptions, ScriptTarget, ModuleKind } from './tsbuild.exports.js'; import type { CompilerOptions, ScriptTarget, ModuleKind } from './tsbuild.exports.js';
/** /**
@ -20,6 +21,7 @@ export const compilerOptionsDefault: CompilerOptions = {
esModuleInterop: true, esModuleInterop: true,
useDefineForClassFields: false, useDefineForClassFields: false,
verbatimModuleSyntax: true, verbatimModuleSyntax: true,
baseUrl: './',
}; };
/** /**
@ -49,6 +51,20 @@ export const mergeCompilerOptions = (
moduleResolution: plugins.typescript.ModuleResolutionKind.NodeJs, 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); console.log(mergedOptions);

View File

@ -60,17 +60,5 @@ export const runCli = async () => {
await tsbuild.compileGlobStringObject(compilationCommandObject, {}, process.cwd(), argvArg); 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(); tsbuildCli.startParse();
}; };