/
index.d.ts
53 lines (53 loc) · 1.61 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
/**
* index.ts
*
* Copyright (c) 2019 Guo Y.K. <hi@guoyk.net>
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
/// <reference types="node" />
import vm = require("vm");
/** mtime based scriptlet file cache policy */
export declare const MTIME = "mtime";
/** error code - dependency loop detected */
export declare const ERR_DEPENDENCY_LOOP = "ERR_DEPENDENCY_LOOP";
/** error code - missing dependency */
export declare const ERR_DEPENDENCY_MISSING = "ERR_DEPENDENCY_MISSING";
/** all cached scripts */
export declare const cachedScriptlets: Map<string, ICachedScriptlet>;
/** cached script */
export interface ICachedScriptlet {
/** full path for scriptlet */
fullPath: string;
/** mtime in milisecond of scriptlet file */
mtimeMs: number;
/** compiled vm.Script */
script: vm.Script;
}
/** scriptlet execution option */
export interface IScriptletOption {
/**
* extra dependencies for script, key prefixed with '$' is strongly suggested
*/
extra?: Map<string, any>;
/**
* cache policy, true for full cache, false for none cache, 'mtime' for
* mtime based file cache, default to 'false'
*/
cache?: boolean | string;
/**
* internal tracker for dependency loop detection
*/
_loopTracker?: Set<string>;
}
export declare class ScriptletError extends Error {
code: string;
constructor(code: string, message: string);
}
/**
* run a scriptlet
* @param id scriptlet file to run
* @param option scriptlet execution option
*/
export declare function run(file: string, option?: IScriptletOption): Promise<any>;