-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.ts
69 lines (65 loc) · 2.01 KB
/
options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import type { FilterPattern } from '@rollup/pluginutils'
import type { TranspileOptions } from 'typescript'
/**
* Represents the options for the plugin.
*/
export type Options = {
include?: FilterPattern
exclude?: FilterPattern
enforce?: 'pre' | 'post' | undefined
/**
* Whether to generate declaration source maps.
*
* Supported by `typescript` and `oxc` transformer only.
*
* @link https://www.typescriptlang.org/tsconfig/#declarationMap
*/
sourceMap?: boolean
ignoreErrors?: boolean
/** An extra directory layer for output files. */
extraOutdir?: string
/** Patch `export default` in `.d.cts` to `export = ` */
patchCjsDefaultExport?: boolean
/** Base directory for input files. */
inputBase?: string
rewriteImports?: (
id: string,
importer: string,
) => string | void | null | undefined
} & (
| {
/**
* `oxc-transform` or `@swc/core` should be installed yourself
* if you want to use `oxc` or `swc` transformer.
*/
transformer?: 'oxc' | 'swc'
}
| {
/**
* `typescript` should be installed yourself.
* @default 'typescript'
*/
transformer?: 'typescript'
/** Only for typescript transformer */
transformOptions?: TranspileOptions
}
)
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U
export type OptionsResolved = Overwrite<
Required<Options>,
Pick<Options, 'enforce' | 'extraOutdir' | 'rewriteImports' | 'inputBase'>
>
export function resolveOptions(options: Options): OptionsResolved {
return {
include: options.include || [/\.[cm]?tsx?$/],
exclude: options.exclude || [/node_modules/],
enforce: 'enforce' in options ? options.enforce : 'pre',
sourceMap: options.sourceMap || false,
transformer: options.transformer || 'typescript',
ignoreErrors: options.ignoreErrors || false,
extraOutdir: options.extraOutdir,
patchCjsDefaultExport: options.patchCjsDefaultExport || false,
rewriteImports: options.rewriteImports,
inputBase: options.inputBase,
}
}