Skip to content

Commit 317d070

Browse files
LucasIcarusegoist
andauthored
feat: Support extends within tsconfig files. (#24)
Co-authored-by: EGOIST <0x142857@gmail.com>
1 parent 38af6bd commit 317d070

8 files changed

Lines changed: 41 additions & 51 deletions

File tree

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
"defu": "^6.0.0",
2828
"esbuild": "0.14.9",
2929
"esbuild-register": "^3.1.2",
30-
"joycon": "^3.0.1",
31-
"jsonc-parser": "^3.0.0",
30+
"load-tsconfig": "^0.2.3",
3231
"path-exists": "^5.0.0",
3332
"prettier": "2.5.1",
3433
"rollup": "^2.60.0",

pnpm-lock.yaml

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

src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import path from 'path'
12
import defu from 'defu'
23
import { createUnplugin } from 'unplugin'
34
import { createFilter, FilterPattern } from '@rollup/pluginutils'
5+
import { loadTsConfig } from 'load-tsconfig'
46

57
import { transform, JscConfig, Options as SwcOptions } from '@swc/core'
68
import { resolveId } from './resolve'
7-
import { getCompilerOptions } from './tsconfig'
89

910
export type Options = SwcOptions & {
1011
include?: FilterPattern
@@ -30,10 +31,10 @@ export default createUnplugin(
3031
const compilerOptions =
3132
tsconfigFile === false
3233
? {}
33-
: await getCompilerOptions(
34-
id,
34+
: loadTsConfig(
35+
path.dirname(id),
3536
tsconfigFile === true ? undefined : tsconfigFile,
36-
)
37+
)?.data?.compilerOptions || {}
3738

3839
const isTs = /\.tsx?$/.test(id)
3940

src/tsconfig.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2020",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"jsxFactory": "customJsxFactory",
8+
"esModuleInterop": true,
9+
"moduleResolution": "node",
10+
"skipLibCheck": true,
11+
"noUnusedLocals": true,
12+
"noImplicitAny": true,
13+
"allowJs": true,
14+
"resolveJsonModule": true,
15+
"experimentalDecorators": false
16+
}
17+
}
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
{
2+
"extends": "./tsconfig.base.json",
23
"compilerOptions": {
3-
"target": "es2020",
4-
"module": "esnext",
5-
"strict": true,
6-
"jsx": "preserve",
7-
"jsxFactory": "customJsxFactory",
8-
"esModuleInterop": true,
9-
"moduleResolution": "node",
10-
"skipLibCheck": true,
11-
"noUnusedLocals": true,
12-
"noImplicitAny": true,
13-
"allowJs": true,
14-
"resolveJsonModule": true,
154
"experimentalDecorators": true
165
}
17-
}
6+
}

test/index.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ test("read tsconfig", async () => {
4646
})
4747

4848
const code = output[0].code
49-
assert.match(code, "customJsxFactory")
49+
assert.match(code, 'customJsxFactory')
50+
51+
// NOTE: use tsconfig.base.json which experimentalDecorators turned off will throw
52+
await rollup({
53+
input: fixture('read-tsconfig/index.tsx'),
54+
plugins: [swc.rollup({ tsconfigFile: 'tsconfig.base.json' })],
55+
}).catch(e => assert.match(e.toString(), 'Unexpected token `@`.'))
5056
})
5157

5258
test("custom swcrc", async () => {

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"noImplicitAny": true,
1111
"allowJs": true,
1212
"resolveJsonModule": true
13-
}
13+
},
14+
"exclude": ["dist"]
1415
}

0 commit comments

Comments
 (0)