@@ -20,7 +20,8 @@ interpreter.addFunction('showAsserts', () => {
2020 console . table ( context . asserts ) ;
2121} ) ;
2222interpreter . addFunction ( 'params' , ( name : string ) => {
23- return context . params [ name ] ;
23+ const value = context . params [ name ] ;
24+ return value === undefined ? null : value ;
2425} ) ;
2526
2627run ( ) ;
@@ -48,9 +49,12 @@ async function run() {
4849 interpreter . registerPackagesLoader ( packageLoader as PackageLoader ) ;
4950 const scripts = fs . readFileSync ( options . file , 'utf8' ) ;
5051 context . asserts . length = 0 ;
51- const res = await interpreter . evaluate ( scripts ) ;
52- console . log ( 'Execution result:\n' , res ) ;
53- console . log ( 'Finish' ) ;
52+ console . log ( "JSPython (c) FalconSoft Ltd" )
53+ console . log ( `${ options . file } ` )
54+ const res = await interpreter . evaluate ( scripts , undefined , undefined , options . file ) ;
55+ if ( res !== null ) {
56+ console . log ( res ) ;
57+ }
5458 }
5559}
5660
@@ -90,15 +94,20 @@ function getOptionsFromArguments(rawArgs: string[]) {
9094
9195/**@type {PackageLoader } */
9296function packageLoader ( packageName : string ) : any {
93- if ( [ 'fs' , 'path' , 'readline' , 'timers' , 'child_process' , 'util' , 'zlib' , 'stream' , 'net' , 'https' , 'http' , 'events' , 'os' , 'buffer' ]
94- . includes ( packageName ) ) {
95- return require ( packageName )
96- }
97-
9897 try {
98+ if ( [ 'fs' , 'path' , 'readline' , 'timers' , 'child_process' , 'util' , 'zlib' , 'stream' , 'net' , 'https' , 'http' , 'events' , 'os' , 'buffer' ]
99+ . includes ( packageName ) ) {
100+ return require ( packageName )
101+ }
102+
103+ if ( packageName . toLowerCase ( ) . endsWith ( '.js' ) || packageName . toLowerCase ( ) . endsWith ( '.json' ) ) {
104+ return require ( `${ process . cwd ( ) . split ( '\\' ) . join ( '/' ) } /${ packageName } ` )
105+ }
106+
99107 return require ( `${ process . cwd ( ) . split ( '\\' ) . join ( '/' ) } /node_modules/${ packageName } ` ) ;
100108 }
101109 catch ( err ) {
102110 console . log ( 'Import Error: ' , err ) ;
111+ throw err ;
103112 }
104113}
0 commit comments