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 e95cc41
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 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.

4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ export default ({
}

const tsconfigRaw =
tsconfig === false
? undefined
: await getTsconfig(dirname(id), tsconfig)
tsconfig === false ? undefined : getTsconfig(tsconfig || id)

const result = await transform(code, {
loader,
Expand Down
21 changes: 6 additions & 15 deletions src/tsconfig.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
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(
filename: string,
): TsConfigJsonResolved | undefined {
return findTsconfig(filename, undefined, cache)?.config
}

0 comments on commit e95cc41

Please sign in to comment.