/
types.ts
54 lines (53 loc) · 1.54 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import type * as ts from 'typescript';
import type { Service } from '../index';
import type { ProjectLocalResolveHelper } from '../util';
/**
* Third-party transpilers are implemented as a CommonJS module with a
* named export "create"
*
* @category Transpiler
*/
export interface TranspilerModule {
create: TranspilerFactory;
}
/**
* Called by ts-node to create a custom transpiler.
*
* @category Transpiler
*/
export type TranspilerFactory = (
options: CreateTranspilerOptions
) => Transpiler;
/** @category Transpiler */
export interface CreateTranspilerOptions {
// TODO this is confusing because its only a partial Service. Rename?
// Careful: must avoid stripInternal breakage by guarding with Extract<>
service: Pick<
Service,
Extract<'config' | 'options' | 'projectLocalResolveHelper', keyof Service>
>;
/**
* If `"transpiler"` option is declared in an "extends" tsconfig, this path might be different than
* the `projectLocalResolveHelper`
*
* @internal
*/
transpilerConfigLocalResolveHelper: ProjectLocalResolveHelper;
}
/** @category Transpiler */
export interface Transpiler {
// TODOs
// Create spec for returning diagnostics? Currently transpilers are allowed to
// throw an error but that's it.
transpile(input: string, options: TranspileOptions): TranspileOutput;
}
/** @category Transpiler */
export interface TranspileOptions {
fileName: string;
}
/** @category Transpiler */
export interface TranspileOutput {
outputText: string;
diagnostics?: ts.Diagnostic[];
sourceMapText?: string;
}