Skip to content

Commit

Permalink
fix: resolve tsconfig extends
Browse files Browse the repository at this point in the history
closes #371
  • Loading branch information
sxzz committed Sep 28, 2023
1 parent 175ea9d commit 3205edd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
5 changes: 5 additions & 0 deletions example/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"useDefineForClassFields": false
}
}
4 changes: 1 addition & 3 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"compilerOptions": {
"useDefineForClassFields": false
}
"extends": ["./tsconfig.base.json"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@rollup/pluginutils": "^5.0.4",
"debug": "^4.3.4",
"es-module-lexer": "^1.3.1",
"joycon": "^3.1.1"
"get-tsconfig": "^4.7.2"
},
"peerDependencies": {
"esbuild": ">=0.18.0",
Expand Down
17 changes: 14 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default ({
const tsconfigRaw =
tsconfig === false
? undefined
: await getTsconfig(dirname(id), tsconfig)
: getTsconfig(id, tsconfig || 'tsconfig.json')

const result = await transform(code, {
loader,
Expand Down
22 changes: 7 additions & 15 deletions src/tsconfig.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import { readFile } from 'fs/promises'
import JoyCon from 'joycon'
import { getTsconfig as findTsconfig, TsConfigJsonResolved } from 'get-tsconfig'

const joycon = new JoyCon()
const cache = new Map<string, unknown>()

joycon.addLoader({
test: /\.json$/,
load: (file) => readFile(file, 'utf8'),
})

export const getTsconfig = async (
cwd: string,
tsconfig?: string,
): Promise<string> => {
// This call is cached
const { data } = await joycon.load([tsconfig || 'tsconfig.json'], cwd)
return data
export function getTsconfig(
searchPath: string,
configName: string,
): TsConfigJsonResolved | undefined {
return findTsconfig(searchPath, configName, cache)?.config
}

0 comments on commit 3205edd

Please sign in to comment.