generated from astrohelm/node-workspace
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.d.ts
100 lines (94 loc) · 2.56 KB
/
options.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
import type { RunningCodeOptions, ScriptOptions } from 'node:vm';
type TAccess = (type?: 'reader' | 'realm', path: string) => boolean | object;
/**
* @example
* ({
* dir: '/tests',
* filename: 'index.js',
* npmIsolation: true,
* ctx: { console, A: 5, B: 'Hello world' }, //? Inject global variables, default {}
* access: (name, type) => true, //? Control access to Realm submodules or reader API
* })
*/
export interface TOptions {
/**
* @default process.cwd()
* @description __dirname, used for require start point
* @warning Provided to realm only with CJS type
*/
dir?: string;
/**
* @default 'ISO'
* @description __filename
* @warning Provided to realm only with CJS type
*/
filename?: string;
/**
* @default false
* @description Runs npm modules in the same realm as current
* @warning Work only in CJS realms
*/
npmIsolation?: boolean;
/**
* @default 'cjs'
* @description Type of realm
* @warning In ISO mode realm Isolation does not inject global variables such as require, module, exports, __filename and __dirname
* @example
* // CJS realm
* new Isolation('module.exports = (a,b) => a + b;');
* // ISO realm
* new Isolation('(a,b) => a + b;', { type: 'iso' })
*/
type?: 'cjs' | 'iso'; // cjs
/**
* @default type => type === 'realm' ? false : true;
* @description Isolation access control and stabbing
*/
// prettier-ignore
access?: TAccess | {
realm?: (path: string) => boolean | object;
reader?: (path: string) => boolean;
};
/**
* @default Isolation.contextify.EMPTY
* @description Realm context
*/
ctx?: Context | { [key: string]: unknown };
runOpts?: RunningCodeOptions;
realmOpts?: ScriptOptions;
}
/**
* @example
* ({
* type: 'cjs',
* dir: '/tests',
* filename: 'index.js',
* npmIsolation: true,
* ctx: { console, A: 5, B: 'Hello world' },
* access: (name, type) => true,
* prepare: true,
* depth: 5,
* })
*/
export interface TOptionsReader extends TOptions {
/**
* @default false
* @description If true, Reader will return unexecuted script
*/
prepare?: boolean;
/**
* @default true
* @description If true, Reader will go through all depth folder
*/
depth?: boolean | number;
/**
* @default false
* @description If true, all deep dependencies names will appear in the root
* @example
* // option: false
* ({ myscript: Function, test: 123, depthFolder: { myscript: 'hello world' } })
* // option: true
* ({ myscript: 'hello world', test: 123 })
*/
flat?: boolean;
}