UNPKG

4.58 kBTypeScriptView Raw
1import * as TS from "typescript";
2import { MaybeArray } from "helpertypes";
3import { Plugin } from "rollup";
4interface ExtendedDiagnostic extends TS.Diagnostic {
5 scope?: string;
6}
7interface CustomTransformerOptions {
8 program: TS.Program | undefined;
9 printer: TS.Printer;
10 typescript: typeof TS;
11 addDiagnostics(...diagnostics: ExtendedDiagnostic[]): void;
12}
13type CustomTransformersFunction = (options: CustomTransformerOptions) => TS.CustomTransformers;
14// A Record from chunk file names to their stats
15type DeclarationStats = Record<string, DeclarationChunkStats>;
16interface DeclarationChunkStats {
17 // An array of the external type dependencies for a declaration chunk
18 externalTypes: ExternalType[];
19}
20interface ExternalType {
21 // The name of the external library that provides the typings. For example, "typescript" or "@types/node"
22 library: string;
23 // The version of the referenced external library
24 version: string;
25}
26// eslint-disable-next-line @typescript-eslint/no-explicit-any
27type BabelConfig = Record<string, any>;
28// eslint-disable-next-line @typescript-eslint/no-explicit-any
29type SwcConfig = Record<string, any>;
30type Transpiler = "typescript" | "babel" | "swc";
31interface TranspilerOptions {
32 typescriptSyntax: Transpiler;
33 otherSyntax: Transpiler;
34}
35interface DebugTransformerData {
36 kind: "transformer";
37 fileName: string;
38 text: string;
39}
40interface DebugEmitData {
41 kind: "emit";
42 fileName: string;
43 text: string;
44 fileKind: EmitPathKind;
45}
46interface DebugMetricsData {
47 kind: "metrics";
48 fileName?: string;
49}
50interface DebugTsconfigData {
51 kind: "tsconfig";
52}
53type DebugData = DebugTransformerData | DebugEmitData | DebugMetricsData | DebugTsconfigData;
54type DebugOptionCallback = (data: DebugData) => boolean;
55interface BrowserslistPathConfig {
56 path: string;
57}
58interface BrowserslistQueryConfig {
59 query: string[] | string;
60}
61type BrowserslistConfig = BrowserslistPathConfig | BrowserslistQueryConfig;
62interface TsConfigResolverWithFileName {
63 fileName: string;
64 hook(resolvedOptions: TS.CompilerOptions): TS.CompilerOptions;
65}
66type TsConfigResolver = TsConfigResolverWithFileName["hook"];
67type OutputPathKind = "declaration" | "declarationMap" | "buildInfo";
68type TranspilationPhase = "file" | "chunk";
69type EmitPathKind = OutputPathKind | "javascript";
70type OutputPathHook = (path: string, kind: OutputPathKind) => string | undefined;
71type DiagnosticsHook = (diagnostics: readonly TS.Diagnostic[]) => readonly TS.Diagnostic[] | undefined;
72type BabelConfigHook = (config: BabelConfig | undefined, fileName: string | undefined, phase: TranspilationPhase) => BabelConfig | undefined;
73type SwcConfigHook = (config: SwcConfig | undefined, fileName: string | undefined, phase: TranspilationPhase) => SwcConfig | undefined;
74type DeclarationStatsHook = (stats: DeclarationStats) => DeclarationStats | undefined;
75interface HookRecord {
76 outputPath: OutputPathHook;
77 diagnostics: DiagnosticsHook;
78 babelConfig: BabelConfigHook;
79 swcConfig: SwcConfigHook;
80 declarationStats: DeclarationStatsHook;
81}
82interface InputCompilerOptions extends Omit<TS.CompilerOptions, "module" | "moduleResolution" | "newLine" | "jsx" | "target"> {
83 module: string;
84 moduleResolution: string;
85 newLine: string;
86 jsx: string;
87 target: string;
88}
89interface TypescriptPluginOptions {
90 transpiler: Transpiler | TranspilerOptions;
91 tsconfig?: string | Partial<TS.CompilerOptions> | Partial<InputCompilerOptions> | TS.ParsedCommandLine | TsConfigResolver | TsConfigResolverWithFileName;
92 babelConfig?: string | Partial<BabelConfig>;
93 swcConfig?: string | MaybeArray<Partial<SwcConfig>>;
94 browserslist?: false | string[] | string | BrowserslistConfig;
95 cwd: string;
96 transformers?: (TS.CustomTransformers | CustomTransformersFunction)[] | TS.CustomTransformers | CustomTransformersFunction;
97 include: string[] | string;
98 exclude: string[] | string;
99 transpileOnly?: boolean;
100 fileSystem: TS.System;
101 hook: Partial<HookRecord>;
102 debug: boolean | DebugOptionCallback;
103 typescript: typeof TS;
104}
105/**
106 * A Rollup plugin that transpiles the given input with Typescript
107 */
108declare function typescriptRollupPlugin(pluginInputOptions?: Partial<TypescriptPluginOptions>): Plugin;
109export { CustomTransformerOptions, CustomTransformersFunction, DeclarationStats, DeclarationChunkStats, ExternalType, typescriptRollupPlugin as default };
110export type { TypescriptPluginOptions, BrowserslistConfig, BrowserslistPathConfig, BrowserslistQueryConfig };