UNPKG

2.82 kBTypeScriptView Raw
1import * as ts from 'typescript';
2export interface PluginConfig {
3 /**
4 * Language Server TypeScript Plugin name
5 */
6 name?: string;
7 /**
8 * Path to transformer or transformer module name
9 */
10 transform?: string;
11 /**
12 * The optional name of the exported transform plugin in the transform module.
13 */
14 import?: string;
15 /**
16 * Plugin entry point format type, default is program
17 */
18 type?: 'ls' | 'program' | 'config' | 'checker' | 'raw' | 'compilerOptions';
19 /**
20 * Should transformer applied after all ones
21 */
22 after?: boolean;
23 /**
24 * Should transformer applied for d.ts files, supports from TS2.9
25 */
26 afterDeclarations?: boolean;
27}
28export interface TransformerBasePlugin {
29 before?: ts.TransformerFactory<ts.SourceFile>;
30 after?: ts.TransformerFactory<ts.SourceFile>;
31 afterDeclarations?: ts.TransformerFactory<ts.SourceFile | ts.Bundle>;
32}
33export declare type TransformerList = Required<ts.CustomTransformers>;
34export declare type TransformerPlugin = TransformerBasePlugin | ts.TransformerFactory<ts.SourceFile>;
35export declare type LSPattern = (ls: ts.LanguageService, config: {}) => TransformerPlugin;
36export declare type ProgramPattern = (program: ts.Program, config: {}, helpers?: {
37 ts: typeof ts;
38 addDiagnostic: (diag: ts.Diagnostic) => void;
39}) => TransformerPlugin;
40export declare type CompilerOptionsPattern = (compilerOpts: ts.CompilerOptions, config: {}) => TransformerPlugin;
41export declare type ConfigPattern = (config: {}) => TransformerPlugin;
42export declare type TypeCheckerPattern = (checker: ts.TypeChecker, config: {}) => TransformerPlugin;
43export declare type RawPattern = (context: ts.TransformationContext, program: ts.Program, config: {}) => ts.Transformer<ts.SourceFile>;
44export declare type PluginFactory = LSPattern | ProgramPattern | ConfigPattern | CompilerOptionsPattern | TypeCheckerPattern | RawPattern;
45/**
46 * @example
47 *
48 * new PluginCreator([
49 * {transform: '@zerollup/ts-transform-paths', someOption: '123'},
50 * {transform: '@zerollup/ts-transform-paths', type: 'ls', someOption: '123'},
51 * {transform: '@zerollup/ts-transform-paths', type: 'ls', after: true, someOption: '123'}
52 * ]).createTransformers({ program })
53 */
54export declare class PluginCreator {
55 private typescript;
56 private configs;
57 private resolveBaseDir;
58 constructor(typescript: typeof ts, configs: PluginConfig[], resolveBaseDir?: string);
59 mergeTransformers(into: TransformerList, source: ts.CustomTransformers | TransformerBasePlugin): this;
60 createTransformers(params: {
61 program: ts.Program;
62 } | {
63 ls: ts.LanguageService;
64 }, customTransformers?: ts.CustomTransformers): Required<ts.CustomTransformers>;
65 private resolveFactory;
66 private validateConfigs;
67}