npm package diff
Package: @forge/tunnel
Versions: 5.10.0-next.12 - 5.10.0-next.13
File: package/out/sandbox/node-sandbox.js
Index: package/out/sandbox/node-sandbox.js
===================================================================
--- package/out/sandbox/node-sandbox.js
+++ package/out/sandbox/node-sandbox.js
@@ -2,39 +2,58 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeSandbox = void 0;
const tslib_1 = require("tslib");
const child_process_1 = require("child_process");
-const path_1 = require("path");
+const path_1 = tslib_1.__importDefault(require("path"));
const readline_1 = tslib_1.__importDefault(require("readline"));
const uuid_1 = require("uuid");
const runtime_1 = require("@forge/runtime");
-const RUNNER = (0, path_1.join)(__dirname, '..', '..', 'out', 'sandbox', 'sandbox-runner.js');
+const RUNNER = path_1.default.join(__dirname, '..', '..', 'out', 'sandbox', 'sandbox-runner.js');
class NodeSandbox {
+ statsigService;
name;
process;
callbacks;
- constructor({ appPath, modName, handler, debugPort }) {
- this.name = `${modName}.${handler}`;
- const fileName = `${appPath}/${modName}.cjs`;
+ constructor({ appPath, modName, handler, debugPort }, statsigService) {
+ this.statsigService = statsigService;
+ const name = `${modName}.${handler}`;
+ this.name = name;
this.callbacks = new Map();
- this.process = (0, child_process_1.fork)(RUNNER, [fileName, handler], {
- stdio: ['ignore', 'pipe', 2, 'ipc'],
- env: {
- _HANDLER: this.name,
- FORGE_EFS_RUNTIME_PATH: appPath,
- FORGE_CUSTOM_WRAPPER_FILE_NAME: '__forge_wrapper__.cjs'
- },
- execArgv: debugPort ? [`--inspect=0.0.0.0:${debugPort}`] : undefined
- });
- readline_1.default.createInterface(this.process.stdout).on('line', (line) => {
- const message = JSON.parse(line);
- this.handleOutput(message);
- });
- this.process.on('message', (message) => {
- const requestId = message.requestId;
- const result = message.result;
- this.callbacks.get(requestId)?.(result);
- });
+ this.process = (async () => {
+ const useSingleWrapper = await this.statsigService.packageSingleWrapper();
+ let fileName;
+ let handlerName;
+ let handlerEnv;
+ if (useSingleWrapper) {
+ fileName = path_1.default.join(appPath, '__forge__.js');
+ handlerName = 'main';
+ handlerEnv = '__forge__.main';
+ }
+ else {
+ fileName = path_1.default.join(appPath, `${modName}.cjs`);
+ handlerName = handler;
+ handlerEnv = `index.${handler}`;
+ }
+ const process = (0, child_process_1.fork)(RUNNER, [fileName, handlerName], {
+ stdio: ['ignore', 'pipe', 2, 'ipc'],
+ env: {
+ _HANDLER: handlerEnv,
+ FORGE_EFS_RUNTIME_PATH: appPath,
+ FORGE_CUSTOM_WRAPPER_FILE_NAME: '__forge_wrapper__.cjs'
+ },
+ execArgv: debugPort ? [`--inspect=0.0.0.0:${debugPort}`] : undefined
+ });
+ readline_1.default.createInterface(process.stdout).on('line', (line) => {
+ const message = JSON.parse(line);
+ this.handleOutput(message);
+ });
+ process.on('message', (message) => {
+ const requestId = message.requestId;
+ const result = message.result;
+ this.callbacks.get(requestId)?.(result);
+ });
+ return process;
+ })();
}
handleOutput(output) {
if (output.invocationId) {
const p3LogEvent = output;
@@ -60,12 +79,12 @@
requestId,
deadline
};
const message = { lambdaEvent, tunnelContext };
- this.process.send(message);
+ void this.process.then((process) => process.send(message));
});
}
stop() {
- this.process.kill();
+ void this.process.then((process) => process.kill());
}
}
exports.NodeSandbox = NodeSandbox;