Skip to content

Commit 407cec6

Browse files
sxzzegoist
andauthoredJul 25, 2022
feat: optimize tsconfig.json loading (#660)
* feat: add option to override tsconfig * fix: resolve tsconfig * tweaks Co-authored-by: EGOIST <0x142857@gmail.com>
1 parent 2087907 commit 407cec6

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed
 

‎src/index.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import path from 'path'
22
import fs from 'fs'
33
import { Worker } from 'worker_threads'
4-
import type { Buildable, MarkRequired } from 'ts-essentials'
54
import { removeFiles, debouncePromise, slash, MaybePromise } from './utils'
65
import { loadTsupConfig } from './load'
76
import glob from 'globby'
@@ -53,7 +52,7 @@ const normalizeOptions = async (
5352
...optionsFromConfigFile,
5453
...optionsOverride,
5554
}
56-
const options: Buildable<NormalizedOptions> = {
55+
const options: Partial<NormalizedOptions> = {
5756
target: 'node14',
5857
outDir: 'dist',
5958
..._options,
@@ -108,6 +107,12 @@ const normalizeOptions = async (
108107
options.tsconfigResolvePaths = tsconfig.data?.compilerOptions?.paths || {}
109108
options.tsconfigDecoratorMetadata =
110109
tsconfig.data?.compilerOptions?.emitDecoratorMetadata
110+
if (options.dts) {
111+
options.dts.compilerOptions = {
112+
...(tsconfig.data.compilerOptions || {}),
113+
...(options.dts.compilerOptions || {}),
114+
}
115+
}
111116
} else if (options.tsconfig) {
112117
throw new PrettyError(`Cannot find tsconfig: ${options.tsconfig}`)
113118
}

‎src/options.ts

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export type DtsConfig = {
2929
banner?: string
3030
/** Insert at the bottom */
3131
footer?: string
32+
/**
33+
* Overrides `compilerOptions`
34+
* This option takes higher priority than `compilerOptions` in tsconfig.json
35+
*/
36+
compilerOptions?: any
3237
}
3338

3439
export type BannerOrFooter =

‎src/rollup.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ import resolveFrom from 'resolve-from'
1515

1616
const logger = createLogger()
1717

18-
const loadCompilerOptions = (tsconfig?: string) => {
19-
if (!tsconfig) return {}
20-
const configFile = ts.readConfigFile(tsconfig, ts.sys.readFile)
18+
const parseCompilerOptions = (compilerOptions?: any) => {
19+
if (!compilerOptions) return {}
2120
const { options } = ts.parseJsonConfigFileContent(
22-
configFile.config,
21+
{ compilerOptions },
2322
ts.sys,
2423
'./'
2524
)
@@ -83,7 +82,7 @@ const getRollupConfig = async (
8382
): Promise<RollupConfig> => {
8483
setSilent(options.silent)
8584

86-
const compilerOptions = loadCompilerOptions(options.tsconfig)
85+
const compilerOptions = parseCompilerOptions(options.dts?.compilerOptions)
8786

8887
const dtsOptions = options.dts || {}
8988
dtsOptions.entry = dtsOptions.entry || options.entry

0 commit comments

Comments
 (0)
Please sign in to comment.