1
- import { EventEmitter } from 'events' ;
1
+ import { EventEmitter } from 'events' ;
2
2
import fs from 'fs' ;
3
3
import pa from 'path' ;
4
4
@@ -7,9 +7,9 @@ import pa from 'path';
7
7
*/
8
8
export interface VMFS {
9
9
/** Implements fs.statSync */
10
- statSync : typeof fs . statSync ;
10
+ statSync : typeof fs . statSync ;
11
11
/** Implements fs.readFileSync */
12
- readFileSync : typeof fs . readFileSync ;
12
+ readFileSync : typeof fs . readFileSync ;
13
13
}
14
14
15
15
/**
@@ -19,40 +19,54 @@ export interface VMPath {
19
19
/** Implements path.resolve */
20
20
resolve : typeof pa . resolve ;
21
21
/** Implements path.isAbsolute */
22
- isAbsolute : typeof pa . isAbsolute ;
22
+ isAbsolute : typeof pa . isAbsolute ;
23
23
/** Implements path.join */
24
- join : typeof pa . join ;
24
+ join : typeof pa . join ;
25
25
/** Implements path.basename */
26
- basename : typeof pa . basename ;
26
+ basename : typeof pa . basename ;
27
27
/** Implements path.dirname */
28
- dirname : typeof pa . dirname ;
29
- /** Implements fs.statSync */
30
- statSync : typeof fs . statSync ;
31
- /** Implements fs.readFileSync */
32
- readFileSync : typeof fs . readFileSync ;
28
+ dirname : typeof pa . dirname ;
33
29
}
34
30
35
31
/**
36
32
* Custom file system which abstracts functions from node's fs and path modules.
37
33
*/
38
- export interface VMFileSystemInterface implements VMFS , VMPath {
34
+ export interface VMFileSystemInterface extends VMFS , VMPath {
39
35
/** Implements (sep) => sep === path.sep */
40
- isSeparator ( char : string ) : boolean ;
36
+ isSeparator ( char : string ) : boolean ;
41
37
}
42
38
43
39
/**
44
40
* Implementation of a default file system.
45
41
*/
46
42
export class VMFileSystem implements VMFileSystemInterface {
47
- constructor ( options ?: { fs ?: VMFS , path ?: VMPath } ) ;
43
+ constructor ( options ?: { fs ?: VMFS , path ?: VMPath } ) ;
44
+ /** Implements fs.statSync */
45
+ statSync : typeof fs . statSync ;
46
+ /** Implements fs.readFileSync */
47
+ readFileSync : typeof fs . readFileSync ;
48
+ /** Implements path.resolve */
49
+ resolve : typeof pa . resolve ;
50
+ /** Implements path.isAbsolute */
51
+ isAbsolute : typeof pa . isAbsolute ;
52
+ /** Implements path.join */
53
+ join : typeof pa . join ;
54
+ /** Implements path.basename */
55
+ basename : typeof pa . basename ;
56
+ /** Implements path.dirname */
57
+ dirname : typeof pa . dirname ;
58
+ /** Implements (sep) => sep === path.sep */
59
+ isSeparator ( char : string ) : boolean ;
48
60
}
49
61
50
62
/**
51
63
* Require options for a VM
52
64
*/
53
65
export interface VMRequire {
54
- /** Array of allowed built-in modules, accepts ["*"] for all. Using "*" increases the attack surface and potential
55
- * new modules allow to escape the sandbox. (default: none) */
66
+ /**
67
+ * Array of allowed built-in modules, accepts ["*"] for all. Using "*" increases the attack surface and potential
68
+ * new modules allow to escape the sandbox. (default: none)
69
+ */
56
70
builtin ?: string [ ] ;
57
71
/*
58
72
* `host` (default) to require modules in host and proxy them to sandbox. `sandbox` to load, compile and
@@ -81,7 +95,7 @@ export interface VMRequire {
81
95
* A custom compiler function for all of the JS that comes
82
96
* into the VM
83
97
*/
84
- type CompilerFunction = ( code : string , filename : string ) => string ;
98
+ export type CompilerFunction = ( code : string , filename : string ) => string ;
85
99
86
100
/**
87
101
* Options for creating a VM
@@ -128,21 +142,23 @@ export interface NodeVMOptions extends VMOptions {
128
142
console ?: "inherit" | "redirect" | "off" ;
129
143
/** `true` or an object to enable `require` options (default: `false`). */
130
144
require ?: boolean | VMRequire ;
131
- /** **WARNING**: This should be disabled. It allows to create a NodeVM form within the sandbox which could return any host module.
132
- * `true` to enable VMs nesting (default: `false`). */
145
+ /**
146
+ * **WARNING**: This should be disabled. It allows to create a NodeVM form within the sandbox which could return any host module.
147
+ * `true` to enable VMs nesting (default: `false`).
148
+ */
133
149
nesting ?: boolean ;
134
150
/** `commonjs` (default) to wrap script into CommonJS wrapper, `none` to retrieve value returned by the script. */
135
151
wrapper ?: "commonjs" | "none" ;
136
152
/** File extensions that the internal module resolver should accept. */
137
153
sourceExtensions ?: string [ ] ;
138
- /**
139
- * Array of arguments passed to `process.argv`.
140
- * This object will not be copied and the script can change this object.
154
+ /**
155
+ * Array of arguments passed to `process.argv`.
156
+ * This object will not be copied and the script can change this object.
141
157
*/
142
158
argv ?: string [ ] ;
143
- /**
144
- * Environment map passed to `process.env`.
145
- * This object will not be copied and the script can change this object.
159
+ /**
160
+ * Environment map passed to `process.env`.
161
+ * This object will not be copied and the script can change this object.
146
162
*/
147
163
env ?: any ;
148
164
/** Run modules in strict mode. Required modules are always strict. */
@@ -161,7 +177,7 @@ export class VM {
161
177
/** Timeout to use for the run methods */
162
178
timeout ?: number ;
163
179
/** Runs the code */
164
- run ( script : string | VMScript , options ?: string | { filename ?: string } ) : any ;
180
+ run ( script : string | VMScript , options ?: string | { filename ?: string } ) : any ;
165
181
/** Runs the code in the specific file */
166
182
runFile ( filename : string ) : any ;
167
183
/** Loads all the values into the global object with the same names */
@@ -187,7 +203,7 @@ export class NodeVM extends EventEmitter implements VM {
187
203
/** Require a module in VM and return it's exports. */
188
204
require ( module : string ) : any ;
189
205
190
- /**
206
+ /**
191
207
* Create NodeVM and run code inside it.
192
208
*
193
209
* @param {string } script JavaScript code.
@@ -204,12 +220,12 @@ export class NodeVM extends EventEmitter implements VM {
204
220
*/
205
221
static file ( filename : string , options ?: NodeVMOptions ) : any ;
206
222
207
- /** Direct access to the global sandbox object */
223
+ /** Direct access to the global sandbox object */
208
224
readonly sandbox : any ;
209
225
/** Only here because of implements VM. Does nothing. */
210
226
timeout ?: number ;
211
227
/** Runs the code */
212
- run ( js : string | VMScript , options ?: string | { filename ?: string , wrapper ?: "commonjs" | "none" , strict ?: boolean } ) : any ;
228
+ run ( js : string | VMScript , options ?: string | { filename ?: string , wrapper ?: "commonjs" | "none" , strict ?: boolean } ) : any ;
213
229
/** Runs the code in the specific file */
214
230
runFile ( filename : string ) : any ;
215
231
/** Loads all the values into the global object with the same names */
@@ -248,8 +264,8 @@ export class VMScript {
248
264
readonly lineOffset : number ;
249
265
readonly columnOffset : number ;
250
266
readonly compiler : "javascript" | "coffeescript" | CompilerFunction ;
251
- /**
252
- * Wraps the code
267
+ /**
268
+ * Wraps the code
253
269
* @deprecated
254
270
*/
255
271
wrap ( prefix : string , postfix : string ) : this;
@@ -258,4 +274,4 @@ export class VMScript {
258
274
}
259
275
260
276
/** Custom Error class */
261
- export class VMError extends Error { }
277
+ export class VMError extends Error { }
0 commit comments