1 | import * as TS from "typescript";
|
2 | import { MaybeArray } from "helpertypes";
|
3 | import { Plugin } from "rollup";
|
4 | interface ExtendedDiagnostic extends TS.Diagnostic {
|
5 | scope?: string;
|
6 | }
|
7 | interface CustomTransformerOptions {
|
8 | program: TS.Program | undefined;
|
9 | printer: TS.Printer;
|
10 | typescript: typeof TS;
|
11 | addDiagnostics(...diagnostics: ExtendedDiagnostic[]): void;
|
12 | }
|
13 | type CustomTransformersFunction = (options: CustomTransformerOptions) => TS.CustomTransformers;
|
14 |
|
15 | type DeclarationStats = Record<string, DeclarationChunkStats>;
|
16 | interface DeclarationChunkStats {
|
17 |
|
18 | externalTypes: ExternalType[];
|
19 | }
|
20 | interface ExternalType {
|
21 |
|
22 | library: string;
|
23 |
|
24 | version: string;
|
25 | }
|
26 |
|
27 | type BabelConfig = Record<string, any>;
|
28 |
|
29 | type SwcConfig = Record<string, any>;
|
30 | type Transpiler = "typescript" | "babel" | "swc";
|
31 | interface TranspilerOptions {
|
32 | typescriptSyntax: Transpiler;
|
33 | otherSyntax: Transpiler;
|
34 | }
|
35 | interface DebugTransformerData {
|
36 | kind: "transformer";
|
37 | fileName: string;
|
38 | text: string;
|
39 | }
|
40 | interface DebugEmitData {
|
41 | kind: "emit";
|
42 | fileName: string;
|
43 | text: string;
|
44 | fileKind: EmitPathKind;
|
45 | }
|
46 | interface DebugMetricsData {
|
47 | kind: "metrics";
|
48 | fileName?: string;
|
49 | }
|
50 | interface DebugTsconfigData {
|
51 | kind: "tsconfig";
|
52 | }
|
53 | type DebugData = DebugTransformerData | DebugEmitData | DebugMetricsData | DebugTsconfigData;
|
54 | type DebugOptionCallback = (data: DebugData) => boolean;
|
55 | interface BrowserslistPathConfig {
|
56 | path: string;
|
57 | }
|
58 | interface BrowserslistQueryConfig {
|
59 | query: string[] | string;
|
60 | }
|
61 | type BrowserslistConfig = BrowserslistPathConfig | BrowserslistQueryConfig;
|
62 | interface TsConfigResolverWithFileName {
|
63 | fileName: string;
|
64 | hook(resolvedOptions: TS.CompilerOptions): TS.CompilerOptions;
|
65 | }
|
66 | type TsConfigResolver = TsConfigResolverWithFileName["hook"];
|
67 | type OutputPathKind = "declaration" | "declarationMap" | "buildInfo";
|
68 | type TranspilationPhase = "file" | "chunk";
|
69 | type EmitPathKind = OutputPathKind | "javascript";
|
70 | type OutputPathHook = (path: string, kind: OutputPathKind) => string | undefined;
|
71 | type DiagnosticsHook = (diagnostics: readonly TS.Diagnostic[]) => readonly TS.Diagnostic[] | undefined;
|
72 | type BabelConfigHook = (config: BabelConfig | undefined, fileName: string | undefined, phase: TranspilationPhase) => BabelConfig | undefined;
|
73 | type SwcConfigHook = (config: SwcConfig | undefined, fileName: string | undefined, phase: TranspilationPhase) => SwcConfig | undefined;
|
74 | type DeclarationStatsHook = (stats: DeclarationStats) => DeclarationStats | undefined;
|
75 | interface HookRecord {
|
76 | outputPath: OutputPathHook;
|
77 | diagnostics: DiagnosticsHook;
|
78 | babelConfig: BabelConfigHook;
|
79 | swcConfig: SwcConfigHook;
|
80 | declarationStats: DeclarationStatsHook;
|
81 | }
|
82 | interface 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 | }
|
89 | interface 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 |
|
107 |
|
108 | declare function typescriptRollupPlugin(pluginInputOptions?: Partial<TypescriptPluginOptions>): Plugin;
|
109 | export { CustomTransformerOptions, CustomTransformersFunction, DeclarationStats, DeclarationChunkStats, ExternalType, typescriptRollupPlugin as default };
|
110 | export type { TypescriptPluginOptions, BrowserslistConfig, BrowserslistPathConfig, BrowserslistQueryConfig };
|