@nyariv/sandboxjs 0.8.24 → 0.8.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/build/eval.d.ts +3 -0
- package/build/eval.js +14 -1
- package/build/parser.js +4 -5
- package/build/utils.d.ts +3 -0
- package/build/utils.js +8 -0
- package/dist/Sandbox.js +14 -1
- package/dist/Sandbox.js.map +1 -1
- package/dist/Sandbox.min.js +1 -1
- package/dist/Sandbox.min.js.map +1 -1
- package/dist/SandboxExec.js.map +1 -1
- package/dist/SandboxExec.min.js +1 -1
- package/dist/SandboxExec.min.js.map +1 -1
- package/dist/eval.d.ts +3 -0
- package/dist/executor.js +1 -1
- package/dist/executor.js.map +1 -1
- package/dist/node/Sandbox.js +13 -0
- package/dist/node/eval.d.ts +3 -0
- package/dist/node/parser.js +4 -5
- package/dist/node/utils.d.ts +3 -0
- package/dist/node/utils.js +11 -0
- package/dist/parser.js +4 -5
- package/dist/parser.js.map +1 -1
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +9 -1
- package/dist/utils.js.map +1 -1
- package/jest.config.js +200 -0
- package/package.json +18 -17
- package/tsconfig.jest.json +16 -0
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export declare const AsyncFunction: Function;
|
|
2
|
+
export declare const GeneratorFunction: Function;
|
|
3
|
+
export declare const AsyncGeneratorFunction: Function;
|
|
1
4
|
import { IEvalContext } from './eval';
|
|
2
5
|
import { Change, Unknown } from './executor';
|
|
3
6
|
import { IConstants, IExecutionTree, Lisp, LispItem } from './parser';
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// Reusable AsyncFunction constructor reference
|
|
2
|
+
const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
|
|
3
|
+
const GeneratorFunction = Object.getPrototypeOf(function* () { }).constructor;
|
|
4
|
+
const AsyncGeneratorFunction = Object.getPrototypeOf(async function* () { }).constructor;
|
|
1
5
|
const SandboxGlobal = function SandboxGlobal(globals) {
|
|
2
6
|
if (globals === globalThis)
|
|
3
7
|
return globalThis;
|
|
@@ -39,7 +43,11 @@ function createExecContext(sandbox, executionTree, evalContext) {
|
|
|
39
43
|
const execContext = new ExecContext(sandbox.context, executionTree.constants, executionTree.tree, new Set(), new WeakMap(), new WeakMap(), sandbox.setSubscriptions, sandbox.changeSubscriptions, evals, (fn) => sandbox.sandboxFunctions.set(fn, execContext), !!evalContext, evalContext);
|
|
40
44
|
if (evalContext) {
|
|
41
45
|
const func = evalContext.sandboxFunction(execContext);
|
|
46
|
+
const asyncFunc = evalContext.sandboxAsyncFunction(execContext);
|
|
42
47
|
evals.set(Function, func);
|
|
48
|
+
evals.set(AsyncFunction, asyncFunc);
|
|
49
|
+
evals.set(GeneratorFunction, func);
|
|
50
|
+
evals.set(AsyncGeneratorFunction, asyncFunc);
|
|
43
51
|
evals.set(eval, evalContext.sandboxedEval(func));
|
|
44
52
|
evals.set(setTimeout, evalContext.sandboxedSetTimeout(func));
|
|
45
53
|
evals.set(setInterval, evalContext.sandboxedSetInterval(func));
|
|
@@ -275,5 +283,5 @@ class Prop {
|
|
|
275
283
|
}
|
|
276
284
|
}
|
|
277
285
|
|
|
278
|
-
export { CodeString, ExecContext, FunctionScope, LocalScope, Prop, SandboxError, SandboxGlobal, Scope, createContext, createExecContext, isLisp };
|
|
286
|
+
export { AsyncFunction, AsyncGeneratorFunction, CodeString, ExecContext, FunctionScope, GeneratorFunction, LocalScope, Prop, SandboxError, SandboxGlobal, Scope, createContext, createExecContext, isLisp };
|
|
279
287
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["import { IEvalContext } from './eval';\nimport { Change, Unknown } from './executor';\nimport { IConstants, IExecutionTree, Lisp, LispItem } from './parser';\nimport SandboxExec from './SandboxExec';\n\nexport type replacementCallback = (obj: any, isStaticAccess: boolean) => any;\n\nexport interface IOptionParams {\n audit?: boolean;\n forbidFunctionCalls?: boolean;\n forbidFunctionCreation?: boolean;\n prototypeReplacements?: Map<new () => any, replacementCallback>;\n prototypeWhitelist?: Map<any, Set<string>>;\n globals: IGlobals;\n executionQuota?: bigint;\n onExecutionQuotaReached?: (\n ticks: Ticks,\n scope: Scope,\n context: IExecutionTree,\n tree: LispItem\n ) => boolean | void;\n}\n\nexport interface IOptions {\n audit: boolean;\n forbidFunctionCalls: boolean;\n forbidFunctionCreation: boolean;\n prototypeReplacements: Map<new () => any, replacementCallback>;\n prototypeWhitelist: Map<any, Set<string>>;\n globals: IGlobals;\n executionQuota?: bigint;\n onExecutionQuotaReached?: (\n ticks: Ticks,\n scope: Scope,\n context: IExecutionTree,\n tree: LispItem\n ) => boolean | void;\n}\n\nexport interface IContext {\n sandbox: SandboxExec;\n globalScope: Scope;\n sandboxGlobal: ISandboxGlobal;\n globalsWhitelist: Set<any>;\n prototypeWhitelist: Map<any, Set<string>>;\n options: IOptions;\n auditReport?: IAuditReport;\n}\n\nexport interface IAuditReport {\n globalsAccess: Set<unknown>;\n prototypeAccess: { [name: string]: Set<string> };\n}\n\nexport interface Ticks {\n ticks: bigint;\n}\n\nexport type SubscriptionSubject = object;\n\nexport interface IExecContext extends IExecutionTree {\n ctx: IContext;\n getSubscriptions: Set<(obj: SubscriptionSubject, name: string) => void>;\n setSubscriptions: WeakMap<SubscriptionSubject, Map<string, Set<(modification: Change) => void>>>;\n changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\n setSubscriptionsGlobal: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >;\n changeSubscriptionsGlobal: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\n registerSandboxFunction: (fn: (...args: any[]) => any) => void;\n evals: Map<any, any>;\n allowJit: boolean;\n evalContext?: IEvalContext;\n}\n\nexport interface ISandboxGlobal {\n [key: string]: unknown;\n}\ninterface SandboxGlobalConstructor {\n new (globals: IGlobals): ISandboxGlobal;\n}\n\nexport const SandboxGlobal = function SandboxGlobal(this: ISandboxGlobal, globals: IGlobals) {\n if (globals === (globalThis as any)) return globalThis;\n for (const i in globals) {\n this[i] = globals[i];\n }\n} as any as SandboxGlobalConstructor;\n\nexport type IGlobals = ISandboxGlobal;\n\nexport class ExecContext implements IExecContext {\n constructor(\n public ctx: IContext,\n public constants: IConstants,\n public tree: Lisp[],\n public getSubscriptions: Set<(obj: SubscriptionSubject, name: string) => void>,\n public setSubscriptions: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >,\n public changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>,\n public setSubscriptionsGlobal: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >,\n public changeSubscriptionsGlobal: WeakMap<\n SubscriptionSubject,\n Set<(modification: Change) => void>\n >,\n public evals: Map<any, any>,\n public registerSandboxFunction: (fn: (...args: any[]) => any) => void,\n public allowJit: boolean,\n public evalContext?: IEvalContext\n ) {}\n}\n\nexport function createContext(sandbox: SandboxExec, options: IOptions): IContext {\n const sandboxGlobal = new SandboxGlobal(options.globals);\n const context = {\n sandbox: sandbox,\n globalsWhitelist: new Set(Object.values(options.globals)),\n prototypeWhitelist: new Map([...options.prototypeWhitelist].map((a) => [a[0].prototype, a[1]])),\n options,\n globalScope: new Scope(null, options.globals, sandboxGlobal),\n sandboxGlobal,\n };\n context.prototypeWhitelist.set(Object.getPrototypeOf([][Symbol.iterator]()) as Object, new Set());\n return context;\n}\n\nexport function createExecContext(\n sandbox: {\n setSubscriptions: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >;\n changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\n sandboxFunctions: WeakMap<(...args: any[]) => any, IExecContext>;\n context: IContext;\n },\n executionTree: IExecutionTree,\n evalContext?: IEvalContext\n): IExecContext {\n const evals = new Map();\n const execContext: IExecContext = new ExecContext(\n sandbox.context,\n executionTree.constants,\n executionTree.tree,\n new Set<(obj: SubscriptionSubject, name: string) => void>(),\n new WeakMap<SubscriptionSubject, Map<string, Set<(modification: Change) => void>>>(),\n new WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>(),\n sandbox.setSubscriptions,\n sandbox.changeSubscriptions,\n evals,\n (fn) => sandbox.sandboxFunctions.set(fn, execContext),\n !!evalContext,\n evalContext\n );\n if (evalContext) {\n const func = evalContext.sandboxFunction(execContext);\n evals.set(Function, func);\n evals.set(eval, evalContext.sandboxedEval(func));\n evals.set(setTimeout, evalContext.sandboxedSetTimeout(func));\n evals.set(setInterval, evalContext.sandboxedSetInterval(func));\n }\n return execContext;\n}\n\nexport class CodeString {\n start: number;\n end: number;\n ref: { str: string };\n constructor(str: string | CodeString) {\n this.ref = { str: '' };\n if (str instanceof CodeString) {\n this.ref = str.ref;\n this.start = str.start;\n this.end = str.end;\n } else {\n this.ref.str = str;\n this.start = 0;\n this.end = str.length;\n }\n }\n\n substring(start: number, end?: number): CodeString {\n if (!this.length) return this;\n start = this.start + start;\n if (start < 0) {\n start = 0;\n }\n if (start > this.end) {\n start = this.end;\n }\n end = end === undefined ? this.end : this.start + end;\n if (end < 0) {\n end = 0;\n }\n if (end > this.end) {\n end = this.end;\n }\n const code = new CodeString(this);\n code.start = start;\n code.end = end;\n return code;\n }\n\n get length() {\n const len = this.end - this.start;\n return len < 0 ? 0 : len;\n }\n\n char(i: number) {\n if (this.start === this.end) return undefined;\n return this.ref.str[this.start + i];\n }\n\n toString() {\n return this.ref.str.substring(this.start, this.end);\n }\n\n trimStart() {\n const found = /^\\s+/.exec(this.toString());\n const code = new CodeString(this);\n if (found) {\n code.start += found[0].length;\n }\n return code;\n }\n\n slice(start: number, end?: number) {\n if (start < 0) {\n start = this.end - this.start + start;\n }\n if (start < 0) {\n start = 0;\n }\n if (end === undefined) {\n end = this.end - this.start;\n }\n\n if (end < 0) {\n end = this.end - this.start + end;\n }\n if (end < 0) {\n end = 0;\n }\n return this.substring(start, end);\n }\n\n trim() {\n const code = this.trimStart();\n const found = /\\s+$/.exec(code.toString());\n if (found) {\n code.end -= found[0].length;\n }\n return code;\n }\n\n valueOf() {\n return this.toString();\n }\n}\n\nfunction keysOnly(obj: unknown): Record<string, true> {\n const ret: Record<string, true> = Object.assign({}, obj);\n for (const key in ret) {\n ret[key] = true;\n }\n return ret;\n}\n\nconst reservedWords = new Set([\n 'instanceof',\n 'typeof',\n 'return',\n 'throw',\n 'try',\n 'catch',\n 'if',\n 'finally',\n 'else',\n 'in',\n 'of',\n 'var',\n 'let',\n 'const',\n 'for',\n 'delete',\n 'false',\n 'true',\n 'while',\n 'do',\n 'break',\n 'continue',\n 'new',\n 'function',\n 'async',\n 'await',\n 'switch',\n 'case',\n]);\n\nexport const enum VarType {\n let = 'let',\n const = 'const',\n var = 'var',\n}\n\nexport class Scope {\n parent: Scope | null;\n const: { [key: string]: true } = {};\n let: { [key: string]: true } = {};\n var: { [key: string]: true } = {};\n globals: { [key: string]: true };\n allVars: { [key: string]: unknown } & Object;\n functionThis?: Unknown;\n constructor(parent: Scope | null, vars = {}, functionThis?: Unknown) {\n const isFuncScope = functionThis !== undefined || parent === null;\n this.parent = parent;\n this.allVars = vars;\n this.let = isFuncScope ? this.let : keysOnly(vars);\n this.var = isFuncScope ? keysOnly(vars) : this.var;\n this.globals = parent === null ? keysOnly(vars) : {};\n this.functionThis = functionThis;\n }\n\n get(key: string, functionScope = false): Prop {\n const functionThis = this.functionThis;\n if (key === 'this' && functionThis !== undefined) {\n return new Prop({ this: functionThis }, key, true, false, true);\n }\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\n if (this.parent === null || !functionScope || functionThis !== undefined) {\n if (this.globals.hasOwnProperty(key)) {\n return new Prop(functionThis, key, false, true, true);\n }\n if (key in this.allVars && (!(key in {}) || this.allVars.hasOwnProperty(key))) {\n return new Prop(\n this.allVars,\n key,\n this.const.hasOwnProperty(key),\n this.globals.hasOwnProperty(key),\n true\n );\n }\n if (this.parent === null) {\n return new Prop(undefined, key);\n }\n }\n return this.parent.get(key, functionScope);\n }\n\n set(key: string, val: unknown) {\n if (key === 'this') throw new SyntaxError('\"this\" cannot be assigned');\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\n const prop = this.get(key);\n if (prop.context === undefined) {\n throw new ReferenceError(`Variable '${key}' was not declared.`);\n }\n if (prop.isConst) {\n throw new TypeError(`Cannot assign to const variable '${key}'`);\n }\n if (prop.isGlobal) {\n throw new SandboxError(`Cannot override global variable '${key}'`);\n }\n if (!(prop.context instanceof Object)) throw new SandboxError('Scope is not an object');\n prop.context[prop.prop] = val;\n return prop;\n }\n\n declare(key: string, type: VarType, value: unknown = undefined, isGlobal = false): Prop {\n if (key === 'this') throw new SyntaxError('\"this\" cannot be declared');\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\n if (type === 'var' && this.functionThis === undefined && this.parent !== null) {\n return this.parent.declare(key, type, value, isGlobal);\n } else if (\n (this[type].hasOwnProperty(key) && type !== 'const' && !this.globals.hasOwnProperty(key)) ||\n !(key in this.allVars)\n ) {\n if (isGlobal) {\n this.globals[key] = true;\n }\n this[type][key] = true;\n this.allVars[key] = value;\n } else {\n throw new SandboxError(`Identifier '${key}' has already been declared`);\n }\n return new Prop(this.allVars, key, this.const.hasOwnProperty(key), isGlobal);\n }\n}\n\nexport interface IScope {\n [key: string]: any;\n}\n\nexport class FunctionScope implements IScope {}\n\nexport class LocalScope implements IScope {}\n\nexport class SandboxError extends Error {}\n\nexport function isLisp<Type extends Lisp = Lisp>(item: LispItem | LispItem): item is Type {\n return (\n Array.isArray(item) &&\n typeof item[0] === 'number' &&\n item[0] !== LispType.None &&\n item[0] !== LispType.True\n );\n}\n\nexport const enum LispType {\n None,\n Prop,\n StringIndex,\n Let,\n Const,\n Call,\n KeyVal,\n Number,\n Return,\n Assign,\n InlineFunction,\n ArrowFunction,\n CreateArray,\n If,\n IfCase,\n InlineIf,\n InlineIfCase,\n SpreadObject,\n SpreadArray,\n ArrayProp,\n PropOptional,\n CallOptional,\n CreateObject,\n Group,\n Not,\n IncrementBefore,\n IncrementAfter,\n DecrementBefore,\n DecrementAfter,\n And,\n Or,\n StrictNotEqual,\n StrictEqual,\n Plus,\n Var,\n GlobalSymbol,\n Literal,\n Function,\n Loop,\n Try,\n Switch,\n SwitchCase,\n Block,\n Expression,\n Await,\n New,\n Throw,\n Minus,\n Divide,\n Power,\n Multiply,\n Modulus,\n Equal,\n NotEqual,\n SmallerEqualThan,\n LargerEqualThan,\n SmallerThan,\n LargerThan,\n Negative,\n Positive,\n Typeof,\n Delete,\n Instanceof,\n In,\n Inverse,\n SubractEquals,\n AddEquals,\n DivideEquals,\n PowerEquals,\n MultiplyEquals,\n ModulusEquals,\n BitNegateEquals,\n BitAndEquals,\n BitOrEquals,\n UnsignedShiftRightEquals,\n ShiftRightEquals,\n ShiftLeftEquals,\n BitAnd,\n BitOr,\n BitNegate,\n BitShiftLeft,\n BitShiftRight,\n BitUnsignedShiftRight,\n BigInt,\n LiteralIndex,\n RegexIndex,\n LoopAction,\n Void,\n True,\n\n LispEnumSize,\n}\n\nexport class Prop {\n constructor(\n public context: Unknown,\n public prop: string,\n public isConst = false,\n public isGlobal = false,\n public isVariable = false\n ) {}\n\n get<T = unknown>(context: IExecContext): T {\n const ctx = this.context;\n if (ctx === undefined) throw new ReferenceError(`${this.prop} is not defined`);\n if (ctx === null)\n throw new TypeError(`Cannot read properties of null, (reading '${this.prop}')`);\n context.getSubscriptions.forEach((cb) => cb(ctx, this.prop));\n return (ctx as any)[this.prop] as T;\n }\n}\n"],"names":[],"mappings":"AAmFa,MAAA,aAAa,GAAG,SAAS,aAAa,CAAuB,OAAiB,EAAA;IACzF,IAAI,OAAO,KAAM,UAAkB;AAAE,QAAA,OAAO,UAAU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ACxE,IAAA,QACE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;AACnB,QAAA,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;QAC3B,IAAI,CAAC,CAAC,CAAC,KAAkB,CAAA;AACzB,QAAA,IAAI,CAAC,CAAC,CAAC,KAAA,EAAA,sBACP;AACJ,CAAC;MAgGY,IAAI,CAAA;IACf,WACS,CAAA,OAAgB,EAChB,IAAY,EACZ,OAAA,GAAU,KAAK,EACf,QAAW,GAAA,KAAK,EAChB,UAAA,GAAa,KAAK,EAAA;QAJlB,IAAO,CAAA,OAAA,GAAP,OAAO,CAAS;QAChB,IAAI,CAAA,IAAA,GAAJ,IAAI,CAAQ;QACZ,IAAO,CAAA,OAAA,GAAP,OAAO,CAAQ;QACf,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAQ;QAChB,IAAU,CAAA,UAAA,GAAV,UAAU,CAAQ;KACvB;AAEJ,IAAA,GAAG,CAAc,OAAqB,EAAA;AACpC,QAAA,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC;QACzB,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,cAAc,CAAC,CAAA,EAAG,IAAI,CAAC,IAAI,CAAiB,eAAA,CAAA,CAAC,CAAC;QAC/E,IAAI,GAAG,KAAK,IAAI;YACd,MAAM,IAAI,SAAS,CAAC,CAAA,0CAAA,EAA6C,IAAI,CAAC,IAAI,CAAI,EAAA,CAAA,CAAC,CAAC;AAClF,QAAA,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7D,QAAA,OAAQ,GAAW,CAAC,IAAI,CAAC,IAAI,CAAM,CAAC;KACrC;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["// Reusable AsyncFunction constructor reference\nexport const AsyncFunction: Function = Object.getPrototypeOf(async function () {}).constructor;\nexport const GeneratorFunction: Function = Object.getPrototypeOf(function* () {}).constructor;\nexport const AsyncGeneratorFunction: Function = Object.getPrototypeOf(async function* () {}).constructor;\n\nimport { IEvalContext } from './eval';\nimport { Change, Unknown } from './executor';\nimport { IConstants, IExecutionTree, Lisp, LispItem } from './parser';\nimport SandboxExec from './SandboxExec';\n\nexport type replacementCallback = (obj: any, isStaticAccess: boolean) => any;\n\nexport interface IOptionParams {\n audit?: boolean;\n forbidFunctionCalls?: boolean;\n forbidFunctionCreation?: boolean;\n prototypeReplacements?: Map<new () => any, replacementCallback>;\n prototypeWhitelist?: Map<any, Set<string>>;\n globals: IGlobals;\n executionQuota?: bigint;\n onExecutionQuotaReached?: (\n ticks: Ticks,\n scope: Scope,\n context: IExecutionTree,\n tree: LispItem\n ) => boolean | void;\n}\n\nexport interface IOptions {\n audit: boolean;\n forbidFunctionCalls: boolean;\n forbidFunctionCreation: boolean;\n prototypeReplacements: Map<new () => any, replacementCallback>;\n prototypeWhitelist: Map<any, Set<string>>;\n globals: IGlobals;\n executionQuota?: bigint;\n onExecutionQuotaReached?: (\n ticks: Ticks,\n scope: Scope,\n context: IExecutionTree,\n tree: LispItem\n ) => boolean | void;\n}\n\nexport interface IContext {\n sandbox: SandboxExec;\n globalScope: Scope;\n sandboxGlobal: ISandboxGlobal;\n globalsWhitelist: Set<any>;\n prototypeWhitelist: Map<any, Set<string>>;\n options: IOptions;\n auditReport?: IAuditReport;\n}\n\nexport interface IAuditReport {\n globalsAccess: Set<unknown>;\n prototypeAccess: { [name: string]: Set<string> };\n}\n\nexport interface Ticks {\n ticks: bigint;\n}\n\nexport type SubscriptionSubject = object;\n\nexport interface IExecContext extends IExecutionTree {\n ctx: IContext;\n getSubscriptions: Set<(obj: SubscriptionSubject, name: string) => void>;\n setSubscriptions: WeakMap<SubscriptionSubject, Map<string, Set<(modification: Change) => void>>>;\n changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\n setSubscriptionsGlobal: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >;\n changeSubscriptionsGlobal: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\n registerSandboxFunction: (fn: (...args: any[]) => any) => void;\n evals: Map<any, any>;\n allowJit: boolean;\n evalContext?: IEvalContext;\n}\n\nexport interface ISandboxGlobal {\n [key: string]: unknown;\n}\ninterface SandboxGlobalConstructor {\n new (globals: IGlobals): ISandboxGlobal;\n}\n\nexport const SandboxGlobal = function SandboxGlobal(this: ISandboxGlobal, globals: IGlobals) {\n if (globals === (globalThis as any)) return globalThis;\n for (const i in globals) {\n this[i] = globals[i];\n }\n} as any as SandboxGlobalConstructor;\n\nexport type IGlobals = ISandboxGlobal;\n\nexport class ExecContext implements IExecContext {\n constructor(\n public ctx: IContext,\n public constants: IConstants,\n public tree: Lisp[],\n public getSubscriptions: Set<(obj: SubscriptionSubject, name: string) => void>,\n public setSubscriptions: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >,\n public changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>,\n public setSubscriptionsGlobal: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >,\n public changeSubscriptionsGlobal: WeakMap<\n SubscriptionSubject,\n Set<(modification: Change) => void>\n >,\n public evals: Map<any, any>,\n public registerSandboxFunction: (fn: (...args: any[]) => any) => void,\n public allowJit: boolean,\n public evalContext?: IEvalContext\n ) {}\n}\n\nexport function createContext(sandbox: SandboxExec, options: IOptions): IContext {\n const sandboxGlobal = new SandboxGlobal(options.globals);\n const context = {\n sandbox: sandbox,\n globalsWhitelist: new Set(Object.values(options.globals)),\n prototypeWhitelist: new Map([...options.prototypeWhitelist].map((a) => [a[0].prototype, a[1]])),\n options,\n globalScope: new Scope(null, options.globals, sandboxGlobal),\n sandboxGlobal,\n };\n context.prototypeWhitelist.set(Object.getPrototypeOf([][Symbol.iterator]()) as Object, new Set());\n return context;\n}\n\nexport function createExecContext(\n sandbox: {\n setSubscriptions: WeakMap<\n SubscriptionSubject,\n Map<string, Set<(modification: Change) => void>>\n >;\n changeSubscriptions: WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>;\n sandboxFunctions: WeakMap<(...args: any[]) => any, IExecContext>;\n context: IContext;\n },\n executionTree: IExecutionTree,\n evalContext?: IEvalContext\n): IExecContext {\n const evals = new Map();\n const execContext: IExecContext = new ExecContext(\n sandbox.context,\n executionTree.constants,\n executionTree.tree,\n new Set<(obj: SubscriptionSubject, name: string) => void>(),\n new WeakMap<SubscriptionSubject, Map<string, Set<(modification: Change) => void>>>(),\n new WeakMap<SubscriptionSubject, Set<(modification: Change) => void>>(),\n sandbox.setSubscriptions,\n sandbox.changeSubscriptions,\n evals,\n (fn) => sandbox.sandboxFunctions.set(fn, execContext),\n !!evalContext,\n evalContext\n );\n if (evalContext) {\n const func = evalContext.sandboxFunction(execContext);\n const asyncFunc = evalContext.sandboxAsyncFunction(execContext);\n evals.set(Function, func);\n evals.set(AsyncFunction, asyncFunc);\n evals.set(GeneratorFunction, func);\n evals.set(AsyncGeneratorFunction, asyncFunc);\n evals.set(eval, evalContext.sandboxedEval(func));\n evals.set(setTimeout, evalContext.sandboxedSetTimeout(func));\n evals.set(setInterval, evalContext.sandboxedSetInterval(func));\n\n }\n return execContext;\n}\n\nexport class CodeString {\n start: number;\n end: number;\n ref: { str: string };\n constructor(str: string | CodeString) {\n this.ref = { str: '' };\n if (str instanceof CodeString) {\n this.ref = str.ref;\n this.start = str.start;\n this.end = str.end;\n } else {\n this.ref.str = str;\n this.start = 0;\n this.end = str.length;\n }\n }\n\n substring(start: number, end?: number): CodeString {\n if (!this.length) return this;\n start = this.start + start;\n if (start < 0) {\n start = 0;\n }\n if (start > this.end) {\n start = this.end;\n }\n end = end === undefined ? this.end : this.start + end;\n if (end < 0) {\n end = 0;\n }\n if (end > this.end) {\n end = this.end;\n }\n const code = new CodeString(this);\n code.start = start;\n code.end = end;\n return code;\n }\n\n get length() {\n const len = this.end - this.start;\n return len < 0 ? 0 : len;\n }\n\n char(i: number) {\n if (this.start === this.end) return undefined;\n return this.ref.str[this.start + i];\n }\n\n toString() {\n return this.ref.str.substring(this.start, this.end);\n }\n\n trimStart() {\n const found = /^\\s+/.exec(this.toString());\n const code = new CodeString(this);\n if (found) {\n code.start += found[0].length;\n }\n return code;\n }\n\n slice(start: number, end?: number) {\n if (start < 0) {\n start = this.end - this.start + start;\n }\n if (start < 0) {\n start = 0;\n }\n if (end === undefined) {\n end = this.end - this.start;\n }\n\n if (end < 0) {\n end = this.end - this.start + end;\n }\n if (end < 0) {\n end = 0;\n }\n return this.substring(start, end);\n }\n\n trim() {\n const code = this.trimStart();\n const found = /\\s+$/.exec(code.toString());\n if (found) {\n code.end -= found[0].length;\n }\n return code;\n }\n\n valueOf() {\n return this.toString();\n }\n}\n\nfunction keysOnly(obj: unknown): Record<string, true> {\n const ret: Record<string, true> = Object.assign({}, obj);\n for (const key in ret) {\n ret[key] = true;\n }\n return ret;\n}\n\nconst reservedWords = new Set([\n 'instanceof',\n 'typeof',\n 'return',\n 'throw',\n 'try',\n 'catch',\n 'if',\n 'finally',\n 'else',\n 'in',\n 'of',\n 'var',\n 'let',\n 'const',\n 'for',\n 'delete',\n 'false',\n 'true',\n 'while',\n 'do',\n 'break',\n 'continue',\n 'new',\n 'function',\n 'async',\n 'await',\n 'switch',\n 'case',\n]);\n\nexport const enum VarType {\n let = 'let',\n const = 'const',\n var = 'var',\n}\n\nexport class Scope {\n parent: Scope | null;\n const: { [key: string]: true } = {};\n let: { [key: string]: true } = {};\n var: { [key: string]: true } = {};\n globals: { [key: string]: true };\n allVars: { [key: string]: unknown } & Object;\n functionThis?: Unknown;\n constructor(parent: Scope | null, vars = {}, functionThis?: Unknown) {\n const isFuncScope = functionThis !== undefined || parent === null;\n this.parent = parent;\n this.allVars = vars;\n this.let = isFuncScope ? this.let : keysOnly(vars);\n this.var = isFuncScope ? keysOnly(vars) : this.var;\n this.globals = parent === null ? keysOnly(vars) : {};\n this.functionThis = functionThis;\n }\n\n get(key: string, functionScope = false): Prop {\n const functionThis = this.functionThis;\n if (key === 'this' && functionThis !== undefined) {\n return new Prop({ this: functionThis }, key, true, false, true);\n }\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\n if (this.parent === null || !functionScope || functionThis !== undefined) {\n if (this.globals.hasOwnProperty(key)) {\n return new Prop(functionThis, key, false, true, true);\n }\n if (key in this.allVars && (!(key in {}) || this.allVars.hasOwnProperty(key))) {\n return new Prop(\n this.allVars,\n key,\n this.const.hasOwnProperty(key),\n this.globals.hasOwnProperty(key),\n true\n );\n }\n if (this.parent === null) {\n return new Prop(undefined, key);\n }\n }\n return this.parent.get(key, functionScope);\n }\n\n set(key: string, val: unknown) {\n if (key === 'this') throw new SyntaxError('\"this\" cannot be assigned');\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\n const prop = this.get(key);\n if (prop.context === undefined) {\n throw new ReferenceError(`Variable '${key}' was not declared.`);\n }\n if (prop.isConst) {\n throw new TypeError(`Cannot assign to const variable '${key}'`);\n }\n if (prop.isGlobal) {\n throw new SandboxError(`Cannot override global variable '${key}'`);\n }\n if (!(prop.context instanceof Object)) throw new SandboxError('Scope is not an object');\n prop.context[prop.prop] = val;\n return prop;\n }\n\n declare(key: string, type: VarType, value: unknown = undefined, isGlobal = false): Prop {\n if (key === 'this') throw new SyntaxError('\"this\" cannot be declared');\n if (reservedWords.has(key)) throw new SyntaxError(\"Unexepected token '\" + key + \"'\");\n if (type === 'var' && this.functionThis === undefined && this.parent !== null) {\n return this.parent.declare(key, type, value, isGlobal);\n } else if (\n (this[type].hasOwnProperty(key) && type !== 'const' && !this.globals.hasOwnProperty(key)) ||\n !(key in this.allVars)\n ) {\n if (isGlobal) {\n this.globals[key] = true;\n }\n this[type][key] = true;\n this.allVars[key] = value;\n } else {\n throw new SandboxError(`Identifier '${key}' has already been declared`);\n }\n return new Prop(this.allVars, key, this.const.hasOwnProperty(key), isGlobal);\n }\n}\n\nexport interface IScope {\n [key: string]: any;\n}\n\nexport class FunctionScope implements IScope {}\n\nexport class LocalScope implements IScope {}\n\nexport class SandboxError extends Error {}\n\nexport function isLisp<Type extends Lisp = Lisp>(item: LispItem | LispItem): item is Type {\n return (\n Array.isArray(item) &&\n typeof item[0] === 'number' &&\n item[0] !== LispType.None &&\n item[0] !== LispType.True\n );\n}\n\nexport const enum LispType {\n None,\n Prop,\n StringIndex,\n Let,\n Const,\n Call,\n KeyVal,\n Number,\n Return,\n Assign,\n InlineFunction,\n ArrowFunction,\n CreateArray,\n If,\n IfCase,\n InlineIf,\n InlineIfCase,\n SpreadObject,\n SpreadArray,\n ArrayProp,\n PropOptional,\n CallOptional,\n CreateObject,\n Group,\n Not,\n IncrementBefore,\n IncrementAfter,\n DecrementBefore,\n DecrementAfter,\n And,\n Or,\n StrictNotEqual,\n StrictEqual,\n Plus,\n Var,\n GlobalSymbol,\n Literal,\n Function,\n Loop,\n Try,\n Switch,\n SwitchCase,\n Block,\n Expression,\n Await,\n New,\n Throw,\n Minus,\n Divide,\n Power,\n Multiply,\n Modulus,\n Equal,\n NotEqual,\n SmallerEqualThan,\n LargerEqualThan,\n SmallerThan,\n LargerThan,\n Negative,\n Positive,\n Typeof,\n Delete,\n Instanceof,\n In,\n Inverse,\n SubractEquals,\n AddEquals,\n DivideEquals,\n PowerEquals,\n MultiplyEquals,\n ModulusEquals,\n BitNegateEquals,\n BitAndEquals,\n BitOrEquals,\n UnsignedShiftRightEquals,\n ShiftRightEquals,\n ShiftLeftEquals,\n BitAnd,\n BitOr,\n BitNegate,\n BitShiftLeft,\n BitShiftRight,\n BitUnsignedShiftRight,\n BigInt,\n LiteralIndex,\n RegexIndex,\n LoopAction,\n Void,\n True,\n\n LispEnumSize,\n}\n\nexport class Prop {\n constructor(\n public context: Unknown,\n public prop: string,\n public isConst = false,\n public isGlobal = false,\n public isVariable = false\n ) {}\n\n get<T = unknown>(context: IExecContext): T {\n const ctx = this.context;\n if (ctx === undefined) throw new ReferenceError(`${this.prop} is not defined`);\n if (ctx === null)\n throw new TypeError(`Cannot read properties of null, (reading '${this.prop}')`);\n context.getSubscriptions.forEach((cb) => cb(ctx, this.prop));\n return (ctx as any)[this.prop] as T;\n }\n}\n"],"names":[],"mappings":"AAAA;AACO,MAAM,aAAa,GAAa,MAAM,CAAC,cAAc,CAAC,kBAAK,EAAc,CAAC,CAAC,CAAC;AAC5E,MAAM,iBAAiB,GAAa,MAAM,CAAC,cAAc,CAAC,aAAS,EAAK,CAAC,CAAC,CAAC;AAC3E,MAAM,sBAAsB,GAAa,MAAM,CAAC,cAAc,CAAC,mBAAe,EAAK,CAAC,CAAC,CAAC;AAqFtF,MAAM,aAAa,GAAG,SAAS,aAAa,CAAuB,OAAiB,EAAA;IACzF,IAAI,OAAO,KAAM,UAAkB;AAAE,QAAA,OAAO,UAAU;AACtD,IAAA,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;QACvB,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IACtB;AACF;MAIa,WAAW,CAAA;IACtB,WAAA,CACS,GAAa,EACb,SAAqB,EACrB,IAAY,EACZ,gBAAuE,EACvE,gBAGN,EACM,mBAAsF,EACtF,sBAGN,EACM,yBAGN,EACM,KAAoB,EACpB,uBAA8D,EAC9D,QAAiB,EACjB,WAA0B,EAAA;QApB1B,IAAA,CAAA,GAAG,GAAH,GAAG;QACH,IAAA,CAAA,SAAS,GAAT,SAAS;QACT,IAAA,CAAA,IAAI,GAAJ,IAAI;QACJ,IAAA,CAAA,gBAAgB,GAAhB,gBAAgB;QAChB,IAAA,CAAA,gBAAgB,GAAhB,gBAAgB;QAIhB,IAAA,CAAA,mBAAmB,GAAnB,mBAAmB;QACnB,IAAA,CAAA,sBAAsB,GAAtB,sBAAsB;QAItB,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QAIzB,IAA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2B,IAAyB,EAAA;AACxE,IAAA,QACE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;AACnB,QAAA,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;QAC3B,IAAI,CAAC,CAAC,CAAC,KAAA,CAAA;AACP,QAAA,IAAI,CAAC,CAAC,CAAC,KAAA,EAAA;AAEX;MAgGa,IAAI,CAAA;IACf,WAAA,CACS,OAAgB,EAChB,IAAY,EACZ,OAAA,GAAU,KAAK,EACf,QAAA,GAAW,KAAK,EAChB,UAAA,GAAa,KAAK,EAAA;QAJlB,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,IAAI,GAAJ,IAAI;QACJ,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,QAAQ,GAAR,QAAQ;QACR,IAAA,CAAA,UAAU,GAAV,UAAU;IAChB;AAEH,IAAA,GAAG,CAAc,OAAqB,EAAA;AACpC,QAAA,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO;QACxB,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,cAAc,CAAC,CAAA,EAAG,IAAI,CAAC,IAAI,CAAA,eAAA,CAAiB,CAAC;QAC9E,IAAI,GAAG,KAAK,IAAI;YACd,MAAM,IAAI,SAAS,CAAC,CAAA,0CAAA,EAA6C,IAAI,CAAC,IAAI,CAAA,EAAA,CAAI,CAAC;AACjF,QAAA,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5D,QAAA,OAAQ,GAAW,CAAC,IAAI,CAAC,IAAI,CAAM;IACrC;AACD;;;;"}
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For a detailed explanation regarding each configuration property, visit:
|
|
3
|
+
* https://jestjs.io/docs/configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** @type {import('jest').Config} */
|
|
7
|
+
export default {
|
|
8
|
+
// All imported modules in your tests should be mocked automatically
|
|
9
|
+
// automock: false,
|
|
10
|
+
|
|
11
|
+
// Stop running tests after `n` failures
|
|
12
|
+
// bail: 0,
|
|
13
|
+
|
|
14
|
+
// The directory where Jest should store its cached dependency information
|
|
15
|
+
// cacheDirectory: "C:\\Users\\user\\AppData\\Local\\Temp\\jest",
|
|
16
|
+
|
|
17
|
+
// Automatically clear mock calls, instances, contexts and results before every test
|
|
18
|
+
// clearMocks: false,
|
|
19
|
+
|
|
20
|
+
// Indicates whether the coverage information should be collected while executing the test
|
|
21
|
+
collectCoverage: true,
|
|
22
|
+
|
|
23
|
+
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
24
|
+
// collectCoverageFrom: undefined,
|
|
25
|
+
|
|
26
|
+
// The directory where Jest should output its coverage files
|
|
27
|
+
coverageDirectory: "coverage",
|
|
28
|
+
|
|
29
|
+
// An array of regexp pattern strings used to skip coverage collection
|
|
30
|
+
// coveragePathIgnorePatterns: [
|
|
31
|
+
// "\\\\node_modules\\\\"
|
|
32
|
+
// ],
|
|
33
|
+
|
|
34
|
+
// Indicates which provider should be used to instrument code for coverage
|
|
35
|
+
coverageProvider: "v8",
|
|
36
|
+
|
|
37
|
+
// A list of reporter names that Jest uses when writing coverage reports
|
|
38
|
+
// coverageReporters: [
|
|
39
|
+
// "json",
|
|
40
|
+
// "text",
|
|
41
|
+
// "lcov",
|
|
42
|
+
// "clover"
|
|
43
|
+
// ],
|
|
44
|
+
|
|
45
|
+
// An object that configures minimum threshold enforcement for coverage results
|
|
46
|
+
// coverageThreshold: undefined,
|
|
47
|
+
|
|
48
|
+
// A path to a custom dependency extractor
|
|
49
|
+
// dependencyExtractor: undefined,
|
|
50
|
+
|
|
51
|
+
// Make calling deprecated APIs throw helpful error messages
|
|
52
|
+
// errorOnDeprecated: false,
|
|
53
|
+
|
|
54
|
+
// The default configuration for fake timers
|
|
55
|
+
// fakeTimers: {
|
|
56
|
+
// "enableGlobally": false
|
|
57
|
+
// },
|
|
58
|
+
|
|
59
|
+
// Force coverage collection from ignored files using an array of glob patterns
|
|
60
|
+
// forceCoverageMatch: [],
|
|
61
|
+
|
|
62
|
+
// A path to a module which exports an async function that is triggered once before all test suites
|
|
63
|
+
// globalSetup: undefined,
|
|
64
|
+
|
|
65
|
+
// A path to a module which exports an async function that is triggered once after all test suites
|
|
66
|
+
// globalTeardown: undefined,
|
|
67
|
+
|
|
68
|
+
// A set of global variables that need to be available in all test environments
|
|
69
|
+
// globals: {},
|
|
70
|
+
|
|
71
|
+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
72
|
+
// maxWorkers: "50%",
|
|
73
|
+
|
|
74
|
+
// An array of directory names to be searched recursively up from the requiring module's location
|
|
75
|
+
// moduleDirectories: [
|
|
76
|
+
// "node_modules"
|
|
77
|
+
// ],
|
|
78
|
+
|
|
79
|
+
// An array of file extensions your modules use
|
|
80
|
+
moduleFileExtensions: [
|
|
81
|
+
"js",
|
|
82
|
+
"mjs",
|
|
83
|
+
"cjs",
|
|
84
|
+
"jsx",
|
|
85
|
+
"ts",
|
|
86
|
+
"tsx",
|
|
87
|
+
"json",
|
|
88
|
+
"node"
|
|
89
|
+
],
|
|
90
|
+
|
|
91
|
+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
92
|
+
moduleNameMapper: {
|
|
93
|
+
'^(\\.{1,2}/.*)\\.js$': '$1', // fixes path issues
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
97
|
+
// modulePathIgnorePatterns: [],
|
|
98
|
+
|
|
99
|
+
// Activates notifications for test results
|
|
100
|
+
// notify: false,
|
|
101
|
+
|
|
102
|
+
// An enum that specifies notification mode. Requires { notify: true }
|
|
103
|
+
// notifyMode: "failure-change",
|
|
104
|
+
|
|
105
|
+
// A preset that is used as a base for Jest's configuration
|
|
106
|
+
preset: 'ts-jest/presets/default-esm',
|
|
107
|
+
|
|
108
|
+
// Run tests from one or more projects
|
|
109
|
+
// projects: undefined,
|
|
110
|
+
|
|
111
|
+
// Use this configuration option to add custom reporters to Jest
|
|
112
|
+
// reporters: undefined,
|
|
113
|
+
|
|
114
|
+
// Automatically reset mock state before every test
|
|
115
|
+
// resetMocks: false,
|
|
116
|
+
|
|
117
|
+
// Reset the module registry before running each individual test
|
|
118
|
+
// resetModules: false,
|
|
119
|
+
|
|
120
|
+
// A path to a custom resolver
|
|
121
|
+
// resolver: undefined,
|
|
122
|
+
|
|
123
|
+
// Automatically restore mock state and implementation before every test
|
|
124
|
+
// restoreMocks: false,
|
|
125
|
+
|
|
126
|
+
// The root directory that Jest should scan for tests and modules within
|
|
127
|
+
// rootDir: undefined,
|
|
128
|
+
|
|
129
|
+
// A list of paths to directories that Jest should use to search for files in
|
|
130
|
+
// roots: [
|
|
131
|
+
// "<rootDir>"
|
|
132
|
+
// ],
|
|
133
|
+
|
|
134
|
+
// Allows you to use a custom runner instead of Jest's default test runner
|
|
135
|
+
// runner: "jest-runner",
|
|
136
|
+
|
|
137
|
+
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
138
|
+
// setupFiles: [],
|
|
139
|
+
|
|
140
|
+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
141
|
+
// setupFilesAfterEnv: [],
|
|
142
|
+
|
|
143
|
+
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
144
|
+
// slowTestThreshold: 5,
|
|
145
|
+
|
|
146
|
+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
147
|
+
// snapshotSerializers: [],
|
|
148
|
+
|
|
149
|
+
// The test environment that will be used for testing
|
|
150
|
+
testEnvironment: 'node',
|
|
151
|
+
|
|
152
|
+
// Options that will be passed to the testEnvironment
|
|
153
|
+
// testEnvironmentOptions: {},
|
|
154
|
+
|
|
155
|
+
// Adds a location field to test results
|
|
156
|
+
// testLocationInResults: false,
|
|
157
|
+
|
|
158
|
+
// The glob patterns Jest uses to detect test files
|
|
159
|
+
// testMatch: [
|
|
160
|
+
// "**/__tests__/**/*.[jt]s?(x)",
|
|
161
|
+
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
162
|
+
// ],
|
|
163
|
+
|
|
164
|
+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
165
|
+
// testPathIgnorePatterns: [
|
|
166
|
+
// "\\\\node_modules\\\\"
|
|
167
|
+
// ],
|
|
168
|
+
|
|
169
|
+
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
170
|
+
// testRegex: [],
|
|
171
|
+
|
|
172
|
+
// This option allows the use of a custom results processor
|
|
173
|
+
// testResultsProcessor: undefined,
|
|
174
|
+
|
|
175
|
+
// This option allows use of a custom test runner
|
|
176
|
+
// testRunner: "jest-circus/runner",
|
|
177
|
+
|
|
178
|
+
// A map from regular expressions to paths to transformers
|
|
179
|
+
transform: {
|
|
180
|
+
'^.+\\.tsx?$': ['ts-jest', { useESM: true, tsconfig: 'tsconfig.jest.json' }],
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
184
|
+
// transformIgnorePatterns: [
|
|
185
|
+
// "\\\\node_modules\\\\",
|
|
186
|
+
// "\\.pnp\\.[^\\\\]+$"
|
|
187
|
+
// ],
|
|
188
|
+
|
|
189
|
+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
190
|
+
// unmockedModulePathPatterns: undefined,
|
|
191
|
+
|
|
192
|
+
// Indicates whether each individual test should be reported during the run
|
|
193
|
+
// verbose: undefined,
|
|
194
|
+
|
|
195
|
+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
196
|
+
// watchPathIgnorePatterns: [],
|
|
197
|
+
|
|
198
|
+
// Whether to use watchman for file crawling
|
|
199
|
+
// watchman: true,
|
|
200
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyariv/sandboxjs",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.26",
|
|
4
4
|
"description": "Javascript sandboxing library.",
|
|
5
5
|
"main": "dist/node/Sandbox.js",
|
|
6
6
|
"module": "./build/Sandbox.js",
|
|
7
7
|
"browser": "./dist/Sandbox.min.js",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "
|
|
9
|
+
"test": "jest",
|
|
10
10
|
"build": "tsc --project tsconfig.json --outDir build --declaration && rollup -c",
|
|
11
11
|
"lint": "eslint --ignore-path .eslintignore --ext .js,.ts .",
|
|
12
12
|
"lint:fix": "eslint --ignore-path .eslintignore --ext .js,.ts --fix .",
|
|
@@ -23,20 +23,21 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/nyariv/SandboxJS#readme",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@rollup/plugin-node-resolve": "^
|
|
27
|
-
"@rollup/plugin-terser": "^0.4.
|
|
28
|
-
"@rollup/plugin-typescript": "^
|
|
29
|
-
"@
|
|
30
|
-
"@typescript-eslint/
|
|
31
|
-
"
|
|
32
|
-
"eslint": "^
|
|
33
|
-
"eslint-config-prettier": "^
|
|
34
|
-
"
|
|
35
|
-
"node-fetch": "^2",
|
|
36
|
-
"prettier": "^
|
|
37
|
-
"rollup": "^
|
|
38
|
-
"rollup-plugin-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
26
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
27
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
28
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
29
|
+
"@types/jest": "^30.0.0",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^8.53.0",
|
|
31
|
+
"@typescript-eslint/parser": "^8.53.0",
|
|
32
|
+
"eslint": "^9.39.2",
|
|
33
|
+
"eslint-config-prettier": "^10.1.8",
|
|
34
|
+
"jest": "^30.2.0",
|
|
35
|
+
"node-fetch": "^3.3.2",
|
|
36
|
+
"prettier": "^3.8.0",
|
|
37
|
+
"rollup": "^4.55.2",
|
|
38
|
+
"rollup-plugin-bundle-stats": "^4.21.8",
|
|
39
|
+
"ts-jest": "^29.4.6",
|
|
40
|
+
"tslib": "^2.8.1",
|
|
41
|
+
"typescript": "^5.9.3"
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "ES2020",
|
|
4
|
+
"target": "ES2020",
|
|
5
|
+
"rootDir": "src/",
|
|
6
|
+
"baseUrl": ".",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"noImplicitAny": false
|
|
12
|
+
},
|
|
13
|
+
"files": ["src/SandboxExec.ts"],
|
|
14
|
+
"include": ["src/**/*"],
|
|
15
|
+
"exclude": []
|
|
16
|
+
}
|