Skip to content

Commit 52999f0

Browse files
committed
fixed app.js loading
1 parent 1e4e86c commit 52999f0

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jspython-cli",
3-
"version": "2.1.13",
3+
"version": "2.1.14",
44
"description": "CLI for jspython. Allows you to run jspython (*.jspy) files",
55
"main": "./lib/public-api.js",
66
"bin": {

src/cli.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import arg from 'arg';
22
import fs from 'fs';
33
import { Interpreter } from 'jspython-interpreter';
4-
import {
5-
AssertInfo,
6-
initialScope,
7-
jsPythonForNode
8-
} from './jspython-node';
4+
import { AssertInfo, initialScope, jsPythonForNode } from './jspython-node';
95
import { InterpreterOptions } from './types';
106
import { trimChar } from './utils';
117
var util = require('util');
@@ -23,11 +19,6 @@ process
2319
process.exit(1);
2420
});
2521

26-
const options = getOptionsFromArguments(process.argv);
27-
const jspyContext: Record<string, any> = { ...initialScope, ...{ params: options.params } };
28-
29-
const interpreter: Interpreter = jsPythonForNode(options) as Interpreter;
30-
3122
function getOptionsFromArguments(rawArgs: string[]): InterpreterOptions {
3223
const args = arg(
3324
{
@@ -82,6 +73,10 @@ function getOptionsFromArguments(rawArgs: string[]): InterpreterOptions {
8273
}
8374

8475
async function main() {
76+
const options = getOptionsFromArguments(process.argv);
77+
const interpreter: Interpreter = (await jsPythonForNode(options)) as Interpreter;
78+
const jspyContext: Record<string, any> = { ...initialScope, ...{ params: options.params } };
79+
8580
if (options.version) {
8681
console.log(interpreter.jsPythonInfo());
8782
console.log(`JSPython cli v${(pkg || {}).version}\n`);

src/jspython-node.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,16 @@ initialScope.params = (name: string) => {
113113
return value === undefined ? null : value;
114114
};
115115

116-
export function jsPythonForNode(
116+
export async function jsPythonForNode(
117117
options: InterpreterOptions = {
118118
srcRoot: ''
119119
}
120-
): NodeJsInterpreter {
120+
): Promise<NodeJsInterpreter> {
121121
const interpreter: NodeJsInterpreter = jsPython() as NodeJsInterpreter;
122122
Object.assign(context.params, options.params);
123123

124+
await initialize(options.srcRoot || '');
125+
124126
interpreter
125127
.registerPackagesLoader(packageLoader as PackageLoader)
126128
.registerModuleLoader(moduleLoader);
@@ -134,7 +136,6 @@ export function jsPythonForNode(
134136
moduleName?: string | undefined
135137
) {
136138
initialScope.asserts.splice(0, initialScope.asserts.length);
137-
await initialize(options.srcRoot || '');
138139
return evaluate.call(interpreter, script, evaluationContext, entryFunctionName, moduleName);
139140
};
140141

0 commit comments

Comments
 (0)