1 |
|
2 | import type _typescript from 'typescript';
|
3 |
|
4 | import type { FilterPattern } from '@rollup/pluginutils';
|
5 | import type { Plugin } from 'rollup';
|
6 | import type {
|
7 | CompilerOptions,
|
8 | CompilerOptionsValue,
|
9 | CustomTransformers,
|
10 | Program,
|
11 | TsConfigSourceFile,
|
12 | TypeChecker
|
13 | } from 'typescript';
|
14 |
|
15 | type ElementType<T extends Array<any> | undefined> = T extends (infer U)[] ? U : never;
|
16 |
|
17 | export type TransformerStage = keyof CustomTransformers;
|
18 | type StagedTransformerFactory<T extends TransformerStage> = ElementType<CustomTransformers[T]>;
|
19 | type TransformerFactory<T extends TransformerStage> =
|
20 | | StagedTransformerFactory<T>
|
21 | | ProgramTransformerFactory<T>
|
22 | | TypeCheckerTransformerFactory<T>;
|
23 |
|
24 | export type CustomTransformerFactories = {
|
25 | [stage in TransformerStage]?: Array<TransformerFactory<stage>>;
|
26 | };
|
27 |
|
28 | interface ProgramTransformerFactory<T extends TransformerStage> {
|
29 | type: 'program';
|
30 |
|
31 | factory(program: Program): StagedTransformerFactory<T>;
|
32 | }
|
33 |
|
34 | interface TypeCheckerTransformerFactory<T extends TransformerStage> {
|
35 | type: 'typeChecker';
|
36 |
|
37 | factory(typeChecker: TypeChecker): StagedTransformerFactory<T>;
|
38 | }
|
39 |
|
40 | export interface RollupTypescriptPluginOptions {
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 | cacheDir?: string;
|
47 | |
48 |
|
49 |
|
50 |
|
51 | include?: FilterPattern;
|
52 | |
53 |
|
54 |
|
55 | exclude?: FilterPattern;
|
56 | |
57 |
|
58 |
|
59 |
|
60 | filterRoot?: string | false;
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 | tsconfig?: string | false;
|
67 | |
68 |
|
69 |
|
70 | typescript?: typeof _typescript;
|
71 | |
72 |
|
73 |
|
74 | tslib?: Promise<string> | string;
|
75 | |
76 |
|
77 |
|
78 | transformers?: CustomTransformerFactories | ((program: Program) => CustomTransformers);
|
79 | /**
|
80 | * When set to false, force non-cached files to always be emitted in the output directory.output
|
81 | * If not set, will default to true with a warning.
|
82 | */
|
83 | outputToFilesystem?: boolean;
|
84 | /**
|
85 | * Pass additional compiler options to the plugin.
|
86 | */
|
87 | compilerOptions?: PartialCompilerOptions;
|
88 | /**
|
89 | * Override force setting of `noEmit` and `emitDeclarationOnly` and use what is defined in `tsconfig.json`
|
90 | */
|
91 | noForceEmit?: boolean;
|
92 | }
|
93 |
|
94 | export interface FlexibleCompilerOptions extends CompilerOptions {
|
95 | [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined | any;
|
96 | }
|
97 |
|
98 | /** Properties of `CompilerOptions` that are normally enums */
|
99 | export type EnumCompilerOptions = 'module' | 'moduleResolution' | 'newLine' | 'jsx' | 'target';
|
100 |
|
101 | /** JSON representation of Typescript compiler options */
|
102 | export type JsonCompilerOptions = Omit<FlexibleCompilerOptions, EnumCompilerOptions> &
|
103 | Record<EnumCompilerOptions, string>;
|
104 |
|
105 | /** Compiler options set by the plugin user. */
|
106 | export type PartialCompilerOptions =
|
107 | | Partial<FlexibleCompilerOptions>
|
108 | | Partial<JsonCompilerOptions>;
|
109 |
|
110 | export type RollupTypescriptOptions = RollupTypescriptPluginOptions & PartialCompilerOptions;
|
111 |
|
112 | /**
|
113 | * Seamless integration between Rollup and Typescript.
|
114 | */
|
115 | export default function typescript(options?: RollupTypescriptOptions): Plugin;
|
116 |
|
\ | No newline at end of file |