-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.d.ts
73 lines (56 loc) 路 2.15 KB
/
index.d.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// CommonJS
export interface CommonjsContext {
__filename: string
__dirname: string
require: NodeRequire
}
export function createCommonJS (url: string) : CommonjsContext
// Resolve
export interface ResolveOptions {
from?: string | URL
conditions?: string[]
}
export function resolve (id: string, opts: ResolveOptions) : Promise<string>
export function resolvePath (id: string, opts: ResolveOptions) : Promise<string>
export function resolveSync (id: string, opts: ResolveOptions) : string
export function resolvePathSync (id: string, opts: ResolveOptions) : string
export function createResolve (defaults: ResolveOptions) : (id: string, url?: string | URL) => Promise<string>
export function resolveImports (code: string, opts: ResolveOptions) : Promise<string>
// Import analyzes
export interface ESMImport {
type: 'static' | 'dynamic'
code: string
start: number
end: number
}
export interface StaticImport extends ESMImport {
type: 'static'
imports: string
specifier: string
}
export interface ParsedStaticImport extends StaticImport {
defaultImport?: string
namespacedImport?: string
namedImports?: { [name: string]: string }
}
export interface DynamicImport extends ESMImport {
type: 'dynamic'
expression: string
}
export function findStaticImports (code: string) : StaticImport[]
export function findDynamicImports (code: string) : DynamicImport[]
export function findNamedExports (code:string): string[]
export function parseStaticImport (staticImport: StaticImport) : ParsedStaticImport
// Evaluate
export interface EvaluateOptions extends ResolveOptions {
url?: string
}
export function loadModule (url: string, opts?: EvaluateOptions) : Promise<any>
export function evalModule (code: string, opts?: EvaluateOptions) : Promise<any>
export function transformModule(code: string, opts?: EvaluateOptions) : Promise<string>
// Utils
export function fileURLToPath (id: URL | string) : string
export function normalizeid (id: URL | string) : string
export function loadURL (id: string) : Promise<string>
export function toDataURL(code: string) : string
export function interopDefault<T> (sourceModule: T): 'default' extends keyof T ? T['default'] : T