File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import vm from 'node:vm';
22import type { Metas } from '../types.js' ;
33import { MAIN_FUNCTION_EXEC } from '../const.js' ;
44import type { ScriptExecution } from './ScriptExecution.js' ;
5+ import { ensureError } from '../utils/error.js' ;
56
67export type ScriptArguments = {
78 script : string ;
@@ -38,8 +39,19 @@ export class Script {
3839 this . tags = ( parameters [ 'tags' ] as string ) . split ( TAGS_SEPARATOR ) ;
3940 this . bias = parameters [ 'bias' ] as number ;
4041
41- // Init script
42- this . vmScript = new vm . Script ( `${ this . scriptCode } ; ${ MAIN_FUNCTION_EXEC } ` ) ;
42+ // Init Script
43+ this . vmScript = this . evaluate ( ) ;
44+ }
45+
46+ evaluate ( ) {
47+ try {
48+ return new vm . Script ( `${ this . scriptCode } ; ${ MAIN_FUNCTION_EXEC } ` , {
49+ filename : this . name
50+ } ) ;
51+ } catch ( err ) {
52+ const error = ensureError ( err ) ;
53+ throw error ;
54+ }
4355 }
4456
4557 run ( context : ScriptExecution ) {
You can’t perform that action at this time.
0 commit comments