ts-patch

  • Version 3.2.0
  • Published
  • 302 kB
  • 6 dependencies
  • MIT license

Install

npm i ts-patch
yarn add ts-patch
pnpm add ts-patch

Overview

Patch typescript to support custom transformers in tsconfig.json

Index

Functions

function check

check: {
(moduleName?: string | string[], opts?: Partial<InstallerOptions>): CheckResult;
(moduleNames?: string[], opts?: Partial<InstallerOptions>): CheckResult;
};
  • Check if files can be patched

function getInstallerOptions

getInstallerOptions: (options?: Partial<InstallerOptions>) => InstallerOptions;

    function getLiveModule

    getLiveModule: (moduleName: TsModule.Name) => { js: string; tsModule: TsModule };

      function install

      install: (opts?: Partial<InstallerOptions>) => boolean;
      • Patch TypeScript modules

      function patch

      patch: {
      (moduleName: string, opts?: Partial<InstallerOptions>): boolean;
      (moduleNames: string[], opts?: Partial<InstallerOptions>): boolean;
      };
      • Patch a TypeScript module

      function uninstall

      uninstall: (opts?: Partial<InstallerOptions>) => boolean;
      • Remove patches from TypeScript modules

      Interfaces

      interface InstallerOptions

      interface InstallerOptions {}

        property dir

        dir: string;

          property logger

          logger: Logger;

            property logLevel

            logLevel: LogLevel;

              property silent

              silent: boolean;

                property skipCache

                skipCache: boolean;

                  property useColor

                  useColor: boolean;

                    interface PluginConfig

                    interface PluginConfig {}

                      property after

                      after?: boolean;
                      • Apply transformer after internal TypeScript transformers

                      property afterDeclarations

                      afterDeclarations?: boolean;
                      • Apply transformer on d.ts files

                      property import

                      import?: string;
                      • The optional name of the exported transform plugin in the transform module.

                      property isEsm

                      isEsm?: boolean;
                      • Is the transformer an ES Module

                      property name

                      name?: string;
                      • Language Server TypeScript Plugin name

                      property resolvePathAliases

                      resolvePathAliases?: boolean;
                      • Resolve Path Aliases?

                      property transform

                      transform?: string;
                      • Path to transformer or transformer module name

                      property transformProgram

                      transformProgram?: boolean;
                      • Transform *Program* instance (alters during createProgram()) (type, after, & afterDeclarations settings will not apply) Entry point must be (program: Program, host?: CompilerHost) => Program

                      property tsConfig

                      tsConfig?: string;
                      • tsconfig.json file (for transformer)

                      property type

                      type?: 'ls' | 'program' | 'config' | 'checker' | 'raw' | 'compilerOptions';
                      • Plugin entry point format type, default is program

                      index signature

                      [x: string]: any;

                        interface PluginPackageConfig

                        interface PluginPackageConfig {}

                          property tscOptions

                          tscOptions?: {
                          /**
                          * Sets the JSDocParsingMode to ParseAll
                          *
                          * @see https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/#optimizations-by-skipping-jsdoc-parsing
                          * @default false
                          */
                          parseAllJsDoc?: boolean;
                          };

                            interface TransformerBasePlugin

                            interface TransformerBasePlugin {}

                              property after

                              after?:
                              | ts.TransformerFactory<ts.SourceFile>
                              | ts.TransformerFactory<ts.SourceFile>[];

                                property afterDeclarations

                                afterDeclarations?:
                                | ts.TransformerFactory<ts.SourceFile | ts.Bundle>
                                | ts.TransformerFactory<ts.SourceFile | ts.Bundle>[];

                                  property before

                                  before?:
                                  | ts.TransformerFactory<ts.SourceFile>
                                  | ts.TransformerFactory<ts.SourceFile>[];

                                    Type Aliases

                                    type CompilerOptionsPattern

                                    type CompilerOptionsPattern = (
                                    compilerOpts: ts.CompilerOptions,
                                    config: {}
                                    ) => TransformerPlugin;

                                      type ConfigPattern

                                      type ConfigPattern = (config: {}) => TransformerPlugin;

                                        type DiagnosticMap

                                        type DiagnosticMap = WeakMap<ts.Program, ts.Diagnostic[]>;

                                          type LSPattern

                                          type LSPattern = (ls: ts.LanguageService, config: {}) => TransformerPlugin;

                                            type PluginFactory

                                            type PluginFactory =
                                            | LSPattern
                                            | ProgramPattern
                                            | ConfigPattern
                                            | CompilerOptionsPattern
                                            | TypeCheckerPattern
                                            | RawPattern;

                                              type ProgramPattern

                                              type ProgramPattern = (
                                              program: ts.Program,
                                              config: {},
                                              extras: TransformerExtras
                                              ) => TransformerPlugin;

                                                type ProgramTransformer

                                                type ProgramTransformer = (
                                                program: ts.Program,
                                                host: ts.CompilerHost | undefined,
                                                config: PluginConfig,
                                                extras: ProgramTransformerExtras
                                                ) => ts.Program;

                                                  type ProgramTransformerExtras

                                                  type ProgramTransformerExtras = {
                                                  /**
                                                  * Originating TypeScript instance
                                                  */
                                                  ts: typeof ts;
                                                  };

                                                    type RawPattern

                                                    type RawPattern = (
                                                    context: ts.TransformationContext,
                                                    program: ts.Program,
                                                    config: {}
                                                    ) => ts.Transformer<ts.SourceFile>;

                                                      type TransformerExtras

                                                      type TransformerExtras = {
                                                      /**
                                                      * Originating TypeScript instance
                                                      */
                                                      ts: typeof ts;
                                                      /**
                                                      * TypeScript library file event was triggered in (ie. 'tsserverlibrary' or 'typescript')
                                                      */
                                                      library: string;
                                                      addDiagnostic: (diag: ts.Diagnostic) => number;
                                                      removeDiagnostic: (index: number) => void;
                                                      diagnostics: readonly ts.Diagnostic[];
                                                      };

                                                        type TransformerList

                                                        type TransformerList = Required<ts.CustomTransformers>;

                                                          type TransformerPlugin

                                                          type TransformerPlugin = TransformerBasePlugin | TsTransformerFactory;

                                                            type TsTransformerFactory

                                                            type TsTransformerFactory = ts.TransformerFactory<ts.SourceFile>;

                                                              type TypeCheckerPattern

                                                              type TypeCheckerPattern = (checker: ts.TypeChecker, config: {}) => TransformerPlugin;

                                                                Namespaces

                                                                namespace InstallerOptions

                                                                namespace InstallerOptions {}

                                                                  function getDefaults

                                                                  getDefaults: () => {
                                                                  logLevel: LogLevel.normal;
                                                                  useColor: true;
                                                                  dir: string;
                                                                  silent: false;
                                                                  skipCache: false;
                                                                  };

                                                                    Package Files (8)

                                                                    Dependencies (6)

                                                                    Dev Dependencies (0)

                                                                    No dev dependencies.

                                                                    Peer Dependencies (0)

                                                                    No peer dependencies.

                                                                    Badge

                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/ts-patch.

                                                                    • Markdown
                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/ts-patch)
                                                                    • HTML
                                                                      <a href="https://www.jsdocs.io/package/ts-patch"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>