Skip to content

Commit

Permalink
feat: Support extends within tsconfig files. (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: EGOIST <[email protected]>
  • Loading branch information
LucasIcarus and egoist authored Apr 12, 2022
1 parent 38af6bd commit 317d070
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 51 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"defu": "^6.0.0",
"esbuild": "0.14.9",
"esbuild-register": "^3.1.2",
"joycon": "^3.0.1",
"jsonc-parser": "^3.0.0",
"load-tsconfig": "^0.2.3",
"path-exists": "^5.0.0",
"prettier": "2.5.1",
"rollup": "^2.60.0",
Expand Down
11 changes: 7 additions & 4 deletions pnpm-lock.yaml

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

9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import path from 'path'
import defu from 'defu'
import { createUnplugin } from 'unplugin'
import { createFilter, FilterPattern } from '@rollup/pluginutils'
import { loadTsConfig } from 'load-tsconfig'

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

export type Options = SwcOptions & {
include?: FilterPattern
Expand All @@ -30,10 +31,10 @@ export default createUnplugin(
const compilerOptions =
tsconfigFile === false
? {}
: await getCompilerOptions(
id,
: loadTsConfig(
path.dirname(id),
tsconfigFile === true ? undefined : tsconfigFile,
)
)?.data?.compilerOptions || {}

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

Expand Down
26 changes: 0 additions & 26 deletions src/tsconfig.ts

This file was deleted.

17 changes: 17 additions & 0 deletions test/fixtures/read-tsconfig/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"jsxFactory": "customJsxFactory",
"esModuleInterop": true,
"moduleResolution": "node",
"skipLibCheck": true,
"noUnusedLocals": true,
"noImplicitAny": true,
"allowJs": true,
"resolveJsonModule": true,
"experimentalDecorators": false
}
}
15 changes: 2 additions & 13 deletions test/fixtures/read-tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"jsxFactory": "customJsxFactory",
"esModuleInterop": true,
"moduleResolution": "node",
"skipLibCheck": true,
"noUnusedLocals": true,
"noImplicitAny": true,
"allowJs": true,
"resolveJsonModule": true,
"experimentalDecorators": true
}
}
}
8 changes: 7 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ test("read tsconfig", async () => {
})

const code = output[0].code
assert.match(code, "customJsxFactory")
assert.match(code, 'customJsxFactory')

// NOTE: use tsconfig.base.json which experimentalDecorators turned off will throw
await rollup({
input: fixture('read-tsconfig/index.tsx'),
plugins: [swc.rollup({ tsconfigFile: 'tsconfig.base.json' })],
}).catch(e => assert.match(e.toString(), 'Unexpected token `@`.'))
})

test("custom swcrc", async () => {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"noImplicitAny": true,
"allowJs": true,
"resolveJsonModule": true
}
},
"exclude": ["dist"]
}

0 comments on commit 317d070

Please sign in to comment.