index.d.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import { BaseError } from 'make-error';
  2. import type * as _ts from 'typescript';
  3. export { createRepl, CreateReplOptions, ReplService } from './repl';
  4. /**
  5. * Registered `ts-node` instance information.
  6. */
  7. export declare const REGISTER_INSTANCE: unique symbol;
  8. /**
  9. * Expose `REGISTER_INSTANCE` information on node.js `process`.
  10. */
  11. declare global {
  12. namespace NodeJS {
  13. interface Process {
  14. [REGISTER_INSTANCE]?: Service;
  15. }
  16. }
  17. }
  18. /**
  19. * Common TypeScript interfaces between versions.
  20. */
  21. export interface TSCommon {
  22. version: typeof _ts.version;
  23. sys: typeof _ts.sys;
  24. ScriptSnapshot: typeof _ts.ScriptSnapshot;
  25. displayPartsToString: typeof _ts.displayPartsToString;
  26. createLanguageService: typeof _ts.createLanguageService;
  27. getDefaultLibFilePath: typeof _ts.getDefaultLibFilePath;
  28. getPreEmitDiagnostics: typeof _ts.getPreEmitDiagnostics;
  29. flattenDiagnosticMessageText: typeof _ts.flattenDiagnosticMessageText;
  30. transpileModule: typeof _ts.transpileModule;
  31. ModuleKind: typeof _ts.ModuleKind;
  32. ScriptTarget: typeof _ts.ScriptTarget;
  33. findConfigFile: typeof _ts.findConfigFile;
  34. readConfigFile: typeof _ts.readConfigFile;
  35. parseJsonConfigFileContent: typeof _ts.parseJsonConfigFileContent;
  36. formatDiagnostics: typeof _ts.formatDiagnostics;
  37. formatDiagnosticsWithColorAndContext: typeof _ts.formatDiagnosticsWithColorAndContext;
  38. }
  39. /**
  40. * Export the current version.
  41. */
  42. export declare const VERSION: any;
  43. /**
  44. * Options for creating a new TypeScript compiler instance.
  45. */
  46. export interface CreateOptions {
  47. /**
  48. * Specify working directory for config resolution.
  49. *
  50. * @default process.cwd()
  51. */
  52. dir?: string;
  53. /**
  54. * Emit output files into `.ts-node` directory.
  55. *
  56. * @default false
  57. */
  58. emit?: boolean;
  59. /**
  60. * Scope compiler to files within `cwd`.
  61. *
  62. * @default false
  63. */
  64. scope?: boolean;
  65. /**
  66. * Use pretty diagnostic formatter.
  67. *
  68. * @default false
  69. */
  70. pretty?: boolean;
  71. /**
  72. * Use TypeScript's faster `transpileModule`.
  73. *
  74. * @default false
  75. */
  76. transpileOnly?: boolean;
  77. /**
  78. * **DEPRECATED** Specify type-check is enabled (e.g. `transpileOnly == false`).
  79. *
  80. * @default true
  81. */
  82. typeCheck?: boolean;
  83. /**
  84. * Use TypeScript's compiler host API.
  85. *
  86. * @default false
  87. */
  88. compilerHost?: boolean;
  89. /**
  90. * Logs TypeScript errors to stderr instead of throwing exceptions.
  91. *
  92. * @default false
  93. */
  94. logError?: boolean;
  95. /**
  96. * Load files from `tsconfig.json` on startup.
  97. *
  98. * @default false
  99. */
  100. files?: boolean;
  101. /**
  102. * Specify a custom TypeScript compiler.
  103. *
  104. * @default "typescript"
  105. */
  106. compiler?: string;
  107. /**
  108. * Override the path patterns to skip compilation.
  109. *
  110. * @default /node_modules/
  111. * @docsDefault "/node_modules/"
  112. */
  113. ignore?: string[];
  114. /**
  115. * Path to TypeScript JSON project file.
  116. */
  117. project?: string;
  118. /**
  119. * Skip project config resolution and loading.
  120. *
  121. * @default false
  122. */
  123. skipProject?: boolean;
  124. /**
  125. * Skip ignore check.
  126. *
  127. * @default false
  128. */
  129. skipIgnore?: boolean;
  130. /**
  131. * JSON object to merge with compiler options.
  132. *
  133. * @allOf [{"$ref": "https://schemastore.azurewebsites.net/schemas/json/tsconfig.json#definitions/compilerOptionsDefinition/properties/compilerOptions"}]
  134. */
  135. compilerOptions?: object;
  136. /**
  137. * Ignore TypeScript warnings by diagnostic code.
  138. */
  139. ignoreDiagnostics?: Array<number | string>;
  140. /**
  141. * Modules to require, like node's `--require` flag.
  142. *
  143. * If specified in tsconfig.json, the modules will be resolved relative to the tsconfig.json file.
  144. *
  145. * If specified programmatically, each input string should be pre-resolved to an absolute path for
  146. * best results.
  147. */
  148. require?: Array<string>;
  149. readFile?: (path: string) => string | undefined;
  150. fileExists?: (path: string) => boolean;
  151. transformers?: _ts.CustomTransformers | ((p: _ts.Program) => _ts.CustomTransformers);
  152. }
  153. /**
  154. * Options for registering a TypeScript compiler instance globally.
  155. */
  156. export interface RegisterOptions extends CreateOptions {
  157. /**
  158. * Re-order file extensions so that TypeScript imports are preferred.
  159. *
  160. * @default false
  161. */
  162. preferTsExts?: boolean;
  163. }
  164. /**
  165. * Must be an interface to support `typescript-json-schema`.
  166. */
  167. export interface TsConfigOptions extends Omit<RegisterOptions, 'transformers' | 'readFile' | 'fileExists' | 'skipProject' | 'project' | 'dir'> {
  168. }
  169. /**
  170. * Information retrieved from type info check.
  171. */
  172. export interface TypeInfo {
  173. name: string;
  174. comment: string;
  175. }
  176. /**
  177. * Default register options, including values specified via environment
  178. * variables.
  179. */
  180. export declare const DEFAULTS: RegisterOptions;
  181. /**
  182. * Split a string array of values.
  183. */
  184. export declare function split(value: string | undefined): string[] | undefined;
  185. /**
  186. * Parse a string as JSON.
  187. */
  188. export declare function parse(value: string | undefined): object | undefined;
  189. /**
  190. * Replace backslashes with forward slashes.
  191. */
  192. export declare function normalizeSlashes(value: string): string;
  193. /**
  194. * TypeScript diagnostics error.
  195. */
  196. export declare class TSError extends BaseError {
  197. diagnosticText: string;
  198. diagnosticCodes: number[];
  199. name: string;
  200. constructor(diagnosticText: string, diagnosticCodes: number[]);
  201. }
  202. /**
  203. * Primary ts-node service, which wraps the TypeScript API and can compile TypeScript to JavaScript
  204. */
  205. export interface Service {
  206. ts: TSCommon;
  207. config: _ts.ParsedCommandLine;
  208. options: RegisterOptions;
  209. enabled(enabled?: boolean): boolean;
  210. ignored(fileName: string): boolean;
  211. compile(code: string, fileName: string, lineOffset?: number): string;
  212. getTypeInfo(code: string, fileName: string, position: number): TypeInfo;
  213. }
  214. /**
  215. * Re-export of `Service` interface for backwards-compatibility
  216. * @deprecated use `Service` instead
  217. * @see Service
  218. */
  219. export declare type Register = Service;
  220. /**
  221. * Register TypeScript compiler instance onto node.js
  222. */
  223. export declare function register(opts?: RegisterOptions): Service;
  224. /**
  225. * Create TypeScript compiler instance.
  226. */
  227. export declare function create(rawOptions?: CreateOptions): Service;