UNPKG

2.07 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import { Service } from './index';
4export interface NodeLoaderHooksAPI1 {
5 resolve: NodeLoaderHooksAPI1.ResolveHook;
6 getFormat: NodeLoaderHooksAPI1.GetFormatHook;
7 transformSource: NodeLoaderHooksAPI1.TransformSourceHook;
8}
9export declare namespace NodeLoaderHooksAPI1 {
10 type ResolveHook = NodeLoaderHooksAPI2.ResolveHook;
11 type GetFormatHook = (url: string, context: {}, defaultGetFormat: GetFormatHook) => Promise<{
12 format: NodeLoaderHooksFormat;
13 }>;
14 type TransformSourceHook = (source: string | Buffer, context: {
15 url: string;
16 format: NodeLoaderHooksFormat;
17 }, defaultTransformSource: NodeLoaderHooksAPI1.TransformSourceHook) => Promise<{
18 source: string | Buffer;
19 }>;
20}
21export interface NodeLoaderHooksAPI2 {
22 resolve: NodeLoaderHooksAPI2.ResolveHook;
23 load: NodeLoaderHooksAPI2.LoadHook;
24}
25export declare namespace NodeLoaderHooksAPI2 {
26 type ResolveHook = (specifier: string, context: {
27 conditions?: NodeImportConditions;
28 importAssertions?: NodeImportAssertions;
29 parentURL: string;
30 }, defaultResolve: ResolveHook) => Promise<{
31 url: string;
32 format?: NodeLoaderHooksFormat;
33 shortCircuit?: boolean;
34 }>;
35 type LoadHook = (url: string, context: {
36 format: NodeLoaderHooksFormat | null | undefined;
37 importAssertions?: NodeImportAssertions;
38 }, defaultLoad: NodeLoaderHooksAPI2['load']) => Promise<{
39 format: NodeLoaderHooksFormat;
40 source: string | Buffer | undefined;
41 shortCircuit?: boolean;
42 }>;
43 type NodeImportConditions = unknown;
44 interface NodeImportAssertions {
45 type?: 'json';
46 }
47}
48export declare type NodeLoaderHooksFormat = 'builtin' | 'commonjs' | 'dynamic' | 'json' | 'module' | 'wasm';
49export declare type NodeImportConditions = unknown;
50export interface NodeImportAssertions {
51 type?: 'json';
52}
53export declare function createEsmHooks(tsNodeService: Service): NodeLoaderHooksAPI1 | NodeLoaderHooksAPI2;