/
types.d.ts
292 lines (260 loc) · 11 KB
/
types.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import type { MediaType } from "./media_type.ts";
import type {
RawSourceMap,
SourceMapUrl,
} from "https://esm.sh/source-map@0.7.3/source-map.d.ts";
/** Additional meta data that is used to enrich the output of the module
* graph. */
export interface CacheInfo {
/** The string path to where the local version of the content is located. For
* non `file:` URLs, this is the location of the cached content, otherwise it
* is the absolute path to the local file. */
local?: string;
/** The string path to where a transpiled version of the source content is
* located, if any. */
emit?: string;
/** The string path to where an external source map of the transpiled source
* content is located, if any. */
map?: string;
}
export interface TypesDependency {
/** The string URL to the type information for the module. */
types: string;
/** An optional range which indicates the source of the dependency. */
source?: Range;
}
export interface ResolveResult {
/** The string URL of the fully qualified specifier for a module. */
specifier: string;
/** The module kind of the resolved module. */
kind: ModuleKind;
}
export interface LoadResponseModule {
/** A module with code has been loaded. */
kind: "module";
/** The string URL of the resource. If there were redirects, the final
* specifier should be set here, otherwise the requested specifier. */
specifier: string;
/** For remote resources, a record of headers should be set, where the key's
* have been normalized to be lower case values. */
headers?: Record<string, string>;
/** The string value of the loaded resources. */
content: string;
}
export interface LoadResponseExternalBuiltIn {
/** The loaded module is either _external_ or _built-in_ to the runtime. */
kind: "external" | "builtIn";
/** The strung URL of the resource. If there were redirects, the final
* specifier should be set here, otherwise the requested specifier. */
specifier: string;
}
export type LoadResponse = LoadResponseModule | LoadResponseExternalBuiltIn;
export interface PositionJson {
/** The line number of a position within a source file. The number is a zero
* based index. */
line: number;
/** The character number of a position within a source file. The number is a
* zero based index. */
character: number;
}
export interface Range {
/** A string URL representing a source of a dependency. */
specifier: string;
/** The start location of a range of text in a source file. */
start?: PositionJson;
/** The end location of a range of text in a source file. */
end?: PositionJson;
}
export interface RangeJson {
/** The start location of a range of text in a source file. */
start: PositionJson;
/** The end location of a range of text in a source file. */
end: PositionJson;
}
export interface ResolvedDependency {
/** The fully resolved string URL of the dependency, which should be
* resolvable in the module graph. If there was an error, `error` will be set
* and this will be undefined. */
specifier?: string;
/** Any error encountered when trying to resolved the specifier. If this is
* defined, `specifier` will be undefined. */
error?: string;
/** The range within the source code where the specifier was identified. */
span: RangeJson;
}
export interface TypesDependencyJson {
/** The string specifier that was used for the dependency. */
specifier: string;
/** An object pointing to the resolved dependency. */
dependency: ResolvedDependency;
}
/** The kind of module.
*
* For asserted modules, the value of the `asserted` property is set to the
* `type` value of the assertion.
*
* Dependency analysis is not performed for asserted, AMD, Script, SystemJS, or
* UMD modules currently. Synthetic modules were injected into the graph with
* their own dependencies provided. */
export type ModuleKind =
| "amd"
| "asserted"
| "builtIn"
| "commonJs"
| "esm"
| "external"
| "script"
| "systemJs"
| "umd";
export interface DependencyJson {
/** The string specifier that was used for the dependency. */
specifier: string;
/** An object pointing to the resolved _code_ dependency. */
code?: ResolvedDependency;
/** An object pointing to the resolved _type_ dependency of a module. This is
* populated when the `@deno-types` directive was used to supply a type
* definition file for a dependency. */
type?: ResolvedDependency;
/** A flag indicating if the dependency was dynamic. (e.g.
* `await import("mod.ts")`) */
isDynamic?: true;
assertionType?: string;
}
export interface ModuleJson extends CacheInfo {
/** The string URL of the module. */
specifier: string;
/** Any error encountered when attempting to load the module. */
error?: string;
/** The module kind that was determined when the module was resolved. This is
* used by loaders to indicate how a module needs to be loaded at runtime. */
kind?: ModuleKind;
/** An array of dependencies that were identified in the module. */
dependencies?: DependencyJson[];
/** If the module had a types dependency, the information about that
* dependency. */
typesDependency?: TypesDependencyJson;
/** The resolved media type of the module, which determines how Deno will
* handle the module. */
mediaType?: MediaType;
/** The size of the source content of the module in bytes. */
size?: number;
/** If available, the calculated checksum of the module which can be used for
* validating the integrity of the module. */
checksum?: string;
/** If available, the upstream source map from the module. If present,
* `sourceMapUrl` will be undefined. */
sourceMap?: RawSourceMap;
/** If available, the upstream source map URL from the module. If present,
* `sourceMap` will be undefined. */
sourceMapUrl?: SourceMapUrl;
}
export interface GraphImportJson {
/** The referrer (URL string) that was used as a base when resolving the
* imports added to the graph. */
referrer: string;
/** An array of resolved dependencies which were imported using the
* referrer. */
dependencies?: DependencyJson[];
}
/** The plain-object representation of a module graph that is suitable for
* serialization to JSON. */
export interface ModuleGraphJson {
/** The module specifiers (URL string) of the _roots_ of the module graph of
* which the module graph was built for. */
roots: string[];
/** An array of modules that are part of the module graph. */
modules: ModuleJson[];
/** External imports that were added to the graph when it was being built.
* The key is the referrer which was used as a base to resolve the
* dependency. The value is the resolved dependency. */
imports?: GraphImportJson[];
/** A record/map of any redirects encountered when resolving modules. The
* key was the requested module specifier and the value is the redirected
* module specifier. */
redirects: Record<string, string>;
}
export interface Dependency {
/** An object pointing to the resolved _code_ dependency. */
code?: ResolvedDependency;
/** An object pointing to the resolved _type_ dependency of a module. This is
* populated when the `@deno-types` directive was used to supply a type
* definition file for a dependency. */
type?: ResolvedDependency;
/** A flag indicating if the dependency was dynamic. (e.g.
* `await import("mod.ts")`) */
isDynamic?: true;
}
export class Module {
private constructor();
/** Any cache information that was available on the module when the graph
* was built. */
readonly cacheInfo?: CacheInfo;
/** The calculated checksum of the source of the module if available when the
* graph was built. */
readonly checksum?: string;
/** A record of the dependencies, where the key is the string specifier of
* the dependency and the value is the dependency object. */
readonly dependencies?: Record<string, Dependency>;
/** A module kind that can be used to determine how a module should be loaded
* at runtime. */
readonly kind: ModuleKind;
/** The media type assigned to the module. This determines how Deno will
* handle the module. */
readonly mediaType: MediaType;
/** The size of the source content in bytes. */
readonly size: number;
/** The source content of the module. */
readonly source: string;
/** The fully qualified string URL of the module. */
readonly specifier: string;
/** The types dependency for the module, where the first value in the tuple
* was the string specifier used and the second value is the resolved
* dependency. */
readonly typesDependency?: [string, ResolvedDependency];
/** Explicitly free the memory used by the module. */
free(): void;
/** Returns a plain-object representation of the module suitable for
* serialization as JSON. */
toJSON(): ModuleJson;
}
/** An interface to the web assembly structure of a built module graph. */
export class ModuleGraph {
private constructor();
/** The modules that are part of the module graph. */
readonly modules: Module[];
/** The root specifiers that were used to build the module graph from. */
readonly roots: string[];
/** Explicitly free the memory used by the module graph. The web assembly
* bindings does use weak references, meaning that the memory should be
* automatically garbage collected when the graph falls out of use. */
free(): void;
/** Retrieve a module from the module graph, if an error was encountered when
* loading the module, this method will throw with that error. */
get(specifier: string): Module | undefined;
/** Determine if the graph sources are valid by calling the passed `check()`
* function. If any of the modules in the graph fail the check, then an
* error is thrown. */
lock(): void;
/** Given a string URL, return the resolved string URL accounting for any
* redirections that might have occurred when resolving the module graph. */
resolve(specifier: string): string;
/** Given a string specifier of a module's dependency and the referring
* module's string URL, return the string URL of the dependency, otherwise
* return undefined. */
resolveDependency(specifier: string, referrer: string): string | undefined;
/** Returns a plain-object representation of the module graph suitable for
* serialization as JSON, similar to the `deno info --json` output. */
toJSON(): ModuleGraphJson;
/** Provides a string output representation of the module graph similar to
* `deno info` with or without ANSI color escape sequences. If `noColor` is
* expressly `true`, the string will be returned without color escape
* sequences. If `noColor` is expressly `false` the returned string will
* include ANSI color escape sequences. If not expressly set, `Deno.noColor`
* will be used, or if the `Deno` namespace isn't present, will default to
* `true` and not provide ANSI color escape sequences.
*
* @param noColor An optional flag indicating if ANSI color escape codes
* should be included in the returned string. */
toString(noColor?: boolean): string;
}