UNPKG

3.72 kBTypeScriptView Raw
1/* eslint-disable no-use-before-define */
2import { FilterPattern } from '@rollup/pluginutils';
3import { Plugin } from 'rollup';
4import {
5 CompilerOptions,
6 CompilerOptionsValue,
7 CustomTransformers,
8 Program,
9 TsConfigSourceFile,
10 TypeChecker
11} from 'typescript';
12
13type ElementType<T extends Array<any> | undefined> = T extends (infer U)[] ? U : never;
14
15export type TransformerStage = keyof CustomTransformers;
16type StagedTransformerFactory<T extends TransformerStage> = ElementType<CustomTransformers[T]>;
17type TransformerFactory<T extends TransformerStage> =
18 | StagedTransformerFactory<T>
19 | ProgramTransformerFactory<T>
20 | TypeCheckerTransformerFactory<T>;
21
22export type CustomTransformerFactories = {
23 [stage in TransformerStage]?: Array<TransformerFactory<stage>>;
24};
25
26interface ProgramTransformerFactory<T extends TransformerStage> {
27 type: 'program';
28
29 factory(program: Program): StagedTransformerFactory<T>;
30}
31
32interface TypeCheckerTransformerFactory<T extends TransformerStage> {
33 type: 'typeChecker';
34
35 factory(typeChecker: TypeChecker): StagedTransformerFactory<T>;
36}
37
38export interface RollupTypescriptPluginOptions {
39 /**
40 * If using incremental this is the folder where the cached
41 * files will be created and kept for Typescript incremental
42 * compilation.
43 */
44 cacheDir?: string;
45 /**
46 * Determine which files are transpiled by Typescript (all `.ts` and
47 * `.tsx` files by default).
48 */
49 include?: FilterPattern;
50 /**
51 * Determine which files are ignored by Typescript
52 */
53 exclude?: FilterPattern;
54 /**
55 * Sets the `resolve` value for the underlying filter function. If not set will use the `rootDir` property
56 * @see {@link https://github.com/rollup/plugins/tree/master/packages/pluginutils#createfilter} @rollup/pluginutils `createFilter`
57 */
58 filterRoot?: string | false;
59 /**
60 * When set to false, ignores any options specified in the config file.
61 * If set to a string that corresponds to a file path, the specified file
62 * will be used as config file.
63 */
64 tsconfig?: string | false;
65 /**
66 * Overrides TypeScript used for transpilation
67 */
68 typescript?: typeof import('typescript');
69 /**
70 * Overrides the injected TypeScript helpers with a custom version.
71 */
72 tslib?: Promise<string> | string;
73 /**
74 * TypeScript custom transformers
75 */
76 transformers?: CustomTransformerFactories;
77 /**
78 * When set to false, force non-cached files to always be emitted in the output directory.output
79 * If not set, will default to true with a warning.
80 */
81 outputToFilesystem?: boolean;
82 /**
83 * Pass additional compiler options to the plugin.
84 */
85 compilerOptions?: PartialCompilerOptions;
86 /**
87 * Override force setting of `noEmit` and `emitDeclarationOnly` and use what is defined in `tsconfig.json`
88 */
89 noForceEmit?: boolean;
90}
91
92export interface FlexibleCompilerOptions extends CompilerOptions {
93 [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined | any;
94}
95
96/** Properties of `CompilerOptions` that are normally enums */
97export type EnumCompilerOptions = 'module' | 'moduleResolution' | 'newLine' | 'jsx' | 'target';
98
99/** JSON representation of Typescript compiler options */
100export type JsonCompilerOptions = Omit<FlexibleCompilerOptions, EnumCompilerOptions> &
101 Record<EnumCompilerOptions, string>;
102
103/** Compiler options set by the plugin user. */
104export type PartialCompilerOptions =
105 | Partial<FlexibleCompilerOptions>
106 | Partial<JsonCompilerOptions>;
107
108export type RollupTypescriptOptions = RollupTypescriptPluginOptions & PartialCompilerOptions;
109
110/**
111 * Seamless integration between Rollup and Typescript.
112 */
113export default function typescript(options?: RollupTypescriptOptions): Plugin;