From 96139f70f2e2415477f14af03eb2bc45a472f33c Mon Sep 17 00:00:00 2001 From: yeliex Date: Tue, 5 Mar 2024 12:10:37 +0800 Subject: [PATCH] fix: add default tsconfig.baseUrl to align with tsc behavior (#759) --- .changeset/three-rockets-jump.md | 5 +++++ packages/register/read-default-tsconfig.ts | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/three-rockets-jump.md diff --git a/.changeset/three-rockets-jump.md b/.changeset/three-rockets-jump.md new file mode 100644 index 000000000..fdd71a638 --- /dev/null +++ b/.changeset/three-rockets-jump.md @@ -0,0 +1,5 @@ +--- +"@fake-scope/fake-pkg": patch +--- + +fix: add default tsconfig.baseUrl to align with tsc behavior diff --git a/packages/register/read-default-tsconfig.ts b/packages/register/read-default-tsconfig.ts index 44e072c59..ed30165e1 100644 --- a/packages/register/read-default-tsconfig.ts +++ b/packages/register/read-default-tsconfig.ts @@ -34,6 +34,12 @@ export function readDefaultTsConfig( const { config } = ts.readConfigFile(fullTsConfigPath, ts.sys.readFile) const { options, errors, fileNames } = ts.parseJsonConfigFileContent(config, ts.sys, dirname(fullTsConfigPath)) + + // if baseUrl not set, use dirname of tsconfig.json. align with ts https://www.typescriptlang.org/tsconfig#paths + if (options.paths && !options.baseUrl) { + options.baseUrl = dirname(fullTsConfigPath) + } + if (!errors.length) { compilerOptions = options compilerOptions.files = fileNames