UNPKG

3.65 kBTypeScriptView Raw
1/**
2 * NOTE: This file is used during the build process for patch as well
3 */
4import type * as ts from 'typescript';
5export interface PluginConfig {
6 [x: string]: any;
7 /**
8 * Language Server TypeScript Plugin name
9 */
10 name?: string;
11 /**
12 * Path to transformer or transformer module name
13 */
14 transform?: string;
15 /**
16 * Resolve Path Aliases?
17 */
18 resolvePathAliases?: boolean;
19 /**
20 * tsconfig.json file (for transformer)
21 */
22 tsConfig?: string;
23 /**
24 * The optional name of the exported transform plugin in the transform module.
25 */
26 import?: string;
27 /**
28 * Is the transformer an ES Module
29 */
30 isEsm?: boolean;
31 /**
32 * Plugin entry point format type, default is program
33 */
34 type?: 'ls' | 'program' | 'config' | 'checker' | 'raw' | 'compilerOptions';
35 /**
36 * Apply transformer after internal TypeScript transformers
37 */
38 after?: boolean;
39 /**
40 * Apply transformer on d.ts files
41 */
42 afterDeclarations?: boolean;
43 /**
44 * Transform *Program* instance (alters during createProgram()) (`type`, `after`, & `afterDeclarations` settings will
45 * not apply) Entry point must be (program: Program, host?: CompilerHost) => Program
46 */
47 transformProgram?: boolean;
48}
49export type TransformerList = Required<ts.CustomTransformers>;
50export type TransformerPlugin = TransformerBasePlugin | TsTransformerFactory;
51export type TsTransformerFactory = ts.TransformerFactory<ts.SourceFile>;
52export type PluginFactory = LSPattern | ProgramPattern | ConfigPattern | CompilerOptionsPattern | TypeCheckerPattern | RawPattern;
53export interface TransformerBasePlugin {
54 before?: ts.TransformerFactory<ts.SourceFile> | ts.TransformerFactory<ts.SourceFile>[];
55 after?: ts.TransformerFactory<ts.SourceFile> | ts.TransformerFactory<ts.SourceFile>[];
56 afterDeclarations?: ts.TransformerFactory<ts.SourceFile | ts.Bundle> | ts.TransformerFactory<ts.SourceFile | ts.Bundle>[];
57}
58export type DiagnosticMap = WeakMap<ts.Program, ts.Diagnostic[]>;
59export type TransformerExtras = {
60 /**
61 * Originating TypeScript instance
62 */
63 ts: typeof ts;
64 /**
65 * TypeScript library file event was triggered in (ie. 'tsserverlibrary' or 'typescript')
66 */
67 library: string;
68 addDiagnostic: (diag: ts.Diagnostic) => number;
69 removeDiagnostic: (index: number) => void;
70 diagnostics: readonly ts.Diagnostic[];
71};
72export type ProgramTransformerExtras = {
73 /**
74 * Originating TypeScript instance
75 */
76 ts: typeof ts;
77};
78export type ProgramTransformer = (program: ts.Program, host: ts.CompilerHost | undefined, config: PluginConfig, extras: ProgramTransformerExtras) => ts.Program;
79export type LSPattern = (ls: ts.LanguageService, config: {}) => TransformerPlugin;
80export type CompilerOptionsPattern = (compilerOpts: ts.CompilerOptions, config: {}) => TransformerPlugin;
81export type ConfigPattern = (config: {}) => TransformerPlugin;
82export type TypeCheckerPattern = (checker: ts.TypeChecker, config: {}) => TransformerPlugin;
83export type ProgramPattern = (program: ts.Program, config: {}, extras: TransformerExtras) => TransformerPlugin;
84export type RawPattern = (context: ts.TransformationContext, program: ts.Program, config: {}) => ts.Transformer<ts.SourceFile>;
85export interface PluginPackageConfig {
86 tscOptions?: {
87 /**
88 * Sets the JSDocParsingMode to ParseAll
89 *
90 * @see https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/#optimizations-by-skipping-jsdoc-parsing
91 * @default false
92 */
93 parseAllJsDoc?: boolean;
94 };
95}