Skip to content

Commit 3205edd

Browse files
committed
fix: resolve tsconfig extends
closes #371
1 parent 175ea9d commit 3205edd

File tree

6 files changed

+29
-23
lines changed

6 files changed

+29
-23
lines changed

example/tsconfig.base.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"useDefineForClassFields": false
4+
}
5+
}

example/tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"compilerOptions": {
3-
"useDefineForClassFields": false
4-
}
2+
"extends": ["./tsconfig.base.json"]
53
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@rollup/pluginutils": "^5.0.4",
3939
"debug": "^4.3.4",
4040
"es-module-lexer": "^1.3.1",
41-
"joycon": "^3.1.1"
41+
"get-tsconfig": "^4.7.2"
4242
},
4343
"peerDependencies": {
4444
"esbuild": ">=0.18.0",

pnpm-lock.yaml

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export default ({
152152
const tsconfigRaw =
153153
tsconfig === false
154154
? undefined
155-
: await getTsconfig(dirname(id), tsconfig)
155+
: getTsconfig(id, tsconfig || 'tsconfig.json')
156156

157157
const result = await transform(code, {
158158
loader,

src/tsconfig.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
import { readFile } from 'fs/promises'
2-
import JoyCon from 'joycon'
1+
import { getTsconfig as findTsconfig, TsConfigJsonResolved } from 'get-tsconfig'
32

4-
const joycon = new JoyCon()
3+
const cache = new Map<string, unknown>()
54

6-
joycon.addLoader({
7-
test: /\.json$/,
8-
load: (file) => readFile(file, 'utf8'),
9-
})
10-
11-
export const getTsconfig = async (
12-
cwd: string,
13-
tsconfig?: string,
14-
): Promise<string> => {
15-
// This call is cached
16-
const { data } = await joycon.load([tsconfig || 'tsconfig.json'], cwd)
17-
return data
5+
export function getTsconfig(
6+
searchPath: string,
7+
configName: string,
8+
): TsConfigJsonResolved | undefined {
9+
return findTsconfig(searchPath, configName, cache)?.config
1810
}

0 commit comments

Comments
 (0)