server: add explicit hook for main file

This commit is contained in:
Koushik Dutta
2023-03-19 14:41:02 -07:00
parent 9bafe97ef6
commit abfd0ffe35
10 changed files with 54 additions and 43 deletions

View File

@@ -9,7 +9,7 @@ import net from "net";
export class NodeForkWorker extends ChildProcessWorker {
constructor(pluginId: string, options: RuntimeWorkerOptions) {
constructor(mainFilename: string, pluginId: string, options: RuntimeWorkerOptions) {
super(pluginId, options);
const {env, pluginDebug} = options;
@@ -19,7 +19,7 @@ export class NodeForkWorker extends ChildProcessWorker {
execArgv.push(`--inspect=0.0.0.0:${pluginDebug.inspectPort}`);
}
this.worker = child_process.fork(require.main.filename, ['child', this.pluginId], {
this.worker = child_process.fork(mainFilename, ['child', this.pluginId], {
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
env: Object.assign({}, process.env, env, {
NODE_PATH: path.join(getPluginNodePath(this.pluginId), 'node_modules'),

View File

@@ -10,11 +10,11 @@ export class NodeThreadWorker extends EventEmitter implements RuntimeWorker {
terminated: boolean;
worker: worker_threads.Worker;
constructor(public pluginId: string, options: RuntimeWorkerOptions) {
constructor(mainFilename: string, public pluginId: string, options: RuntimeWorkerOptions) {
super();
const { env } = options;
this.worker = new worker_threads.Worker(require.main.filename, {
this.worker = new worker_threads.Worker(mainFilename, {
argv: ['child-thread', this.pluginId],
env: Object.assign({}, process.env, env, {
NODE_PATH: path.join(getPluginNodePath(this.pluginId), 'node_modules'),

View File

@@ -58,12 +58,14 @@ export class PythonRuntimeWorker extends ChildProcessWorker {
args.push(this.pluginId);
const types = require.resolve('@scrypted/types');
const PYTHONPATH = types.substring(0, types.indexOf('@scrypted/types') + '@scrypted/types'.length);
this.worker = child_process.spawn(pythonPath, args, {
// stdin, stdout, stderr, peer in, peer out
stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'],
env: Object.assign({
PYTHONUNBUFFERED: '1',
PYTHONPATH: path.join(process.cwd(), 'node_modules/@scrypted/types'),
PYTHONPATH,
}, gstEnv, process.env, env),
});