Skip to content

Commit

Permalink
fix(js): mimic the behavior of tsc compilation for runTypeCheck
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #9203
  • Loading branch information
Chau Tran authored and Chau Tran committed Mar 18, 2022
1 parent 08c6b02 commit 1c4a90f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/js/src/utils/swc/compile-swc.ts
Expand Up @@ -20,8 +20,9 @@ function getTypeCheckOptions(normalizedOptions: NormalizedSwcExecutorOptions) {
const typeCheckOptions: TypeCheckOptions = {
mode: 'emitDeclarationOnly',
tsConfigPath: tsConfig,
outDir: outputPath.replace(`/${projectRoot}`, ''),
outDir: outputPath,
workspaceRoot: root,
rootDir: projectRoot,
};

if (watch) {
Expand Down
5 changes: 4 additions & 1 deletion packages/js/src/utils/typescript/run-type-check.ts
Expand Up @@ -19,6 +19,7 @@ interface BaseTypeCheckOptions {
tsConfigPath: string;
cacheDir?: string;
incremental?: boolean;
rootDir?: string;
}

type Mode = NoEmitMode | EmitDeclarationOnlyMode;
Expand Down Expand Up @@ -116,7 +117,8 @@ export async function runTypeCheck(

async function setupTypeScript(options: TypeCheckOptions) {
const ts = await import('typescript');
const { workspaceRoot, tsConfigPath, cacheDir, incremental } = options;
const { workspaceRoot, tsConfigPath, cacheDir, incremental, rootDir } =
options;
const config = readTsConfig(tsConfigPath);
if (config.errors.length) {
throw new Error(`Invalid config file: ${config.errors}`);
Expand All @@ -132,6 +134,7 @@ async function setupTypeScript(options: TypeCheckOptions) {
skipLibCheck: true,
...emitOptions,
incremental,
rootDir: rootDir || config.options.rootDir,
};

return { ts, workspaceRoot, cacheDir, config, compilerOptions };
Expand Down

0 comments on commit 1c4a90f

Please sign in to comment.