Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

212 lines
5.6KB

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