1 |
|
2 | import { FilterPattern } from '@rollup/pluginutils';
|
3 | import { Plugin } from 'rollup';
|
4 | import {
|
5 | CompilerOptions,
|
6 | CompilerOptionsValue,
|
7 | CustomTransformers,
|
8 | Program,
|
9 | TsConfigSourceFile,
|
10 | TypeChecker
|
11 | } from 'typescript';
|
12 |
|
13 | type ElementType<T extends Array<any> | undefined> = T extends (infer U)[] ? U : never;
|
14 |
|
15 | export type TransformerStage = keyof CustomTransformers;
|
16 | type StagedTransformerFactory<T extends TransformerStage> = ElementType<CustomTransformers[T]>;
|
17 | type TransformerFactory<T extends TransformerStage> =
|
18 | | StagedTransformerFactory<T>
|
19 | | ProgramTransformerFactory<T>
|
20 | | TypeCheckerTransformerFactory<T>;
|
21 |
|
22 | export type CustomTransformerFactories = {
|
23 | [stage in TransformerStage]?: Array<TransformerFactory<stage>>;
|
24 | };
|
25 |
|
26 | interface ProgramTransformerFactory<T extends TransformerStage> {
|
27 | type: 'program';
|
28 |
|
29 | factory(program: Program): StagedTransformerFactory<T>;
|
30 | }
|
31 |
|
32 | interface TypeCheckerTransformerFactory<T extends TransformerStage> {
|
33 | type: 'typeChecker';
|
34 |
|
35 | factory(typeChecker: TypeChecker): StagedTransformerFactory<T>;
|
36 | }
|
37 |
|
38 | export interface RollupTypescriptPluginOptions {
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | cacheDir?: string;
|
45 | |
46 |
|
47 |
|
48 |
|
49 | include?: FilterPattern;
|
50 | |
51 |
|
52 |
|
53 | exclude?: FilterPattern;
|
54 | |
55 |
|
56 |
|
57 |
|
58 | filterRoot?: string | false;
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 | tsconfig?: string | false;
|
65 | |
66 |
|
67 |
|
68 | typescript?: typeof import('typescript');
|
69 | |
70 |
|
71 |
|
72 | tslib?: Promise<string> | string;
|
73 | |
74 |
|
75 |
|
76 | transformers?: CustomTransformerFactories;
|
77 | |
78 |
|
79 |
|
80 |
|
81 | outputToFilesystem?: boolean;
|
82 | |
83 |
|
84 |
|
85 | compilerOptions?: PartialCompilerOptions;
|
86 | |
87 |
|
88 |
|
89 | noForceEmit?: boolean;
|
90 | }
|
91 |
|
92 | export interface FlexibleCompilerOptions extends CompilerOptions {
|
93 | [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined | any;
|
94 | }
|
95 |
|
96 |
|
97 | export type EnumCompilerOptions = 'module' | 'moduleResolution' | 'newLine' | 'jsx' | 'target';
|
98 |
|
99 |
|
100 | export type JsonCompilerOptions = Omit<FlexibleCompilerOptions, EnumCompilerOptions> &
|
101 | Record<EnumCompilerOptions, string>;
|
102 |
|
103 |
|
104 | export type PartialCompilerOptions =
|
105 | | Partial<FlexibleCompilerOptions>
|
106 | | Partial<JsonCompilerOptions>;
|
107 |
|
108 | export type RollupTypescriptOptions = RollupTypescriptPluginOptions & PartialCompilerOptions;
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | export default function typescript(options?: RollupTypescriptOptions): Plugin;
|