Skip to content

Commit

Permalink
feat: --use-babel supports outDir config in ts config.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 3, 2023
1 parent 9636588 commit bf7ec6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/core/src/compile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tsCompile from '@tsbb/typescript';
import tsCompile, { findConfigFile, readConfigFile, reportDiagnostic } from '@tsbb/typescript';
import { BabelCompileOptions } from '@tsbb/babel';
import { babelTransform } from './watcher/babelTransform.js';
import { watcherCopyFiles } from './watcher/copyFiles.js';
Expand Down Expand Up @@ -42,5 +42,15 @@ export async function compile(options: CompileOptions = {}) {
}
throw new Error(err.join('\n'));
}
const tsConfig = findConfigFile();
if (tsConfig) {
const { config, error } = readConfigFile(tsConfig);
if (error) {
return reportDiagnostic(error);
}
if (config.compilerOptions.outDir && !options.cjs) {
options.cjs = config.compilerOptions.outDir;
}
}
babelTransform(options);
}
3 changes: 2 additions & 1 deletion packages/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface TsCompileOptions {
}

export const findConfigFile = () => ts.findConfigFile('.', ts.sys.fileExists, 'tsconfig.json');
export const readConfigFile = (tsConfigPath: string) => ts.readConfigFile(path.resolve(tsConfigPath), ts.sys.readFile);

export default async function compile(options: TsCompileOptions = {}) {
const { isCopyFiles = true, onWriteFile, onCopyFiles, bail } = options;
Expand All @@ -67,7 +68,7 @@ export default async function compile(options: TsCompileOptions = {}) {
return;
}

const { config, error } = ts.readConfigFile(path.resolve(tsConfigPath), ts.sys.readFile);
const { config, error } = readConfigFile(tsConfigPath);
if (error) {
return reportDiagnostic(error);
}
Expand Down

0 comments on commit bf7ec6f

Please sign in to comment.