-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
70 lines (70 loc) · 2.45 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
export = fromMem;
/**
* Import or require the given code from memory. Knows about the different
* Peggy output formats. Returns the exports of the module.
*
* @param {string} code Code to import
* @param {FromMemOptions} options Options. Most important is filename.
* @returns {Promise<unknown>} The evaluated code.
*/
declare function fromMem(code: string, options: FromMemOptions): Promise<unknown>;
declare namespace fromMem {
export { guessModuleType, SourceFormat, FromMemOptions, ModuleType };
}
/**
* Figure out the module type for the given file. If no package.json is
* found, default to "commonjs".
*
* @param {string} filename Fully-qualified filename to start from.
* @returns {Promise<ModuleType>}
* @throws On invalid package.json
*/
declare function guessModuleType(filename: string): Promise<ModuleType>;
declare namespace guessModuleType {
function clearCache(): void;
}
type SourceFormat = "amd" | "bare" | "cjs" | "commonjs" | "es" | "es6" | "esm" | "globals" | "guess" | "mjs" | "module" | "umd";
/**
* Options for how to process code.
*/
type FromMemOptions = {
/**
* What format does the code
* have? "guess" means to read the closest package.json file looking for
* the "type" key. "globals", "amd", and "bare" are not actually supported.
*/
format?: SourceFormat | undefined;
/**
* If specified, use this instead of the
* current values in process.env. Works if includeGlobals is false by
* creating an otherwise-empty process instance.
*/
env?: Record<string, any> | undefined;
/**
* What is the fully-qualified synthetic filename
* for the code? Most important is the directory, which is used to find
* modules that the code import's or require's.
*/
filename: string;
/**
* Variables to make availble in
* the global scope while code is being evaluated.
*/
context?: Record<string, any> | undefined;
/**
* Include the typical global
* properties that node gives to all modules. (e.g. Buffer, process).
*/
includeGlobals?: boolean | undefined;
/**
* Specifies the line number offset that is
* displayed in stack traces produced by this script.
*/
lineOffset?: number | undefined;
/**
* Specifies the first-line column number
* offset that is displayed in stack traces produced by this script.
*/
columnOffset?: number | undefined;
};
type ModuleType = "commonjs" | "es";