UNPKG

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