UNPKG

2.51 kBTypeScriptView Raw
1import { FilterPattern } from '@rollup/pluginutils';
2import { Plugin } from 'rollup';
3import { CompilerOptions, CustomTransformers } from 'typescript';
4
5export interface RollupTypescriptPluginOptions {
6 /**
7 * Determine which files are transpiled by Typescript (all `.ts` and
8 * `.tsx` files by default).
9 */
10 include?: FilterPattern;
11 /**
12 * Determine which files are ignored by Typescript
13 */
14 exclude?: FilterPattern;
15 /**
16 * When set to false, ignores any options specified in the config file.
17 * If set to a string that corresponds to a file path, the specified file
18 * will be used as config file.
19 */
20 tsconfig?: string | false;
21 /**
22 * Overrides TypeScript used for transpilation
23 */
24 typescript?: typeof import('typescript');
25 /**
26 * Overrides the injected TypeScript helpers with a custom version.
27 */
28 tslib?: Promise<string> | string;
29 /**
30 * TypeScript custom transformers
31 */
32 transformers?: CustomTransformerFactories;
33}
34
35type ElementType<T extends Array<any>> = T extends (infer U)[] ? U : never;
36
37export type TransformerStage = keyof CustomTransformers;
38type StagedTransformerFactory<T extends TransformerStage> = ElementType<CustomTransformers[T]>;
39type TransformerFactory<T extends TransformerStage> =
40 | StagedTransformerFactory<T>
41 | ProgramTransformerFactory<T>
42 | TypeCheckerTransformerFactory<T>;
43
44export type CustomTransformerFactories = {
45 [stage in TransformerStage]?: Array<TransformerFactory<stage>>;
46};
47
48interface ProgramTransformerFactory<T extends TransformerStage> {
49 type: 'program';
50
51 factory(program: Program): StagedTransformerFactory<T>;
52}
53
54interface TypeCheckerTransformerFactory<T extends TransformerStage> {
55 type: 'typeChecker';
56
57 factory(typeChecker: TypeChecker): StagedTransformerFactory<T>;
58}
59
60/** Properties of `CompilerOptions` that are normally enums */
61export type EnumCompilerOptions = 'module' | 'moduleResolution' | 'newLine' | 'jsx' | 'target';
62
63/** JSON representation of Typescript compiler options */
64export type JsonCompilerOptions = Omit<CompilerOptions, EnumCompilerOptions> &
65 Record<EnumCompilerOptions, string>;
66
67/** Compiler options set by the plugin user. */
68export type PartialCompilerOptions = Partial<CompilerOptions> | Partial<JsonCompilerOptions>;
69
70export type RollupTypescriptOptions = RollupTypescriptPluginOptions & PartialCompilerOptions;
71
72/**
73 * Seamless integration between Rollup and Typescript.
74 */
75export default function typescript(options?: RollupTypescriptOptions): Plugin;