@ricsam/isolate-daemon 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/connection.cjs
CHANGED
|
@@ -46,6 +46,7 @@ __export(exports_connection, {
|
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(exports_connection);
|
|
48
48
|
var import_node_crypto = require("node:crypto");
|
|
49
|
+
var import_node_path = __toESM(require("node:path"));
|
|
49
50
|
var import_isolated_vm = __toESM(require("isolated-vm"));
|
|
50
51
|
var import_isolate_protocol = require("@ricsam/isolate-protocol");
|
|
51
52
|
var import_callback_fs_handler = require("./callback-fs-handler.cjs");
|
|
@@ -434,7 +435,7 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
434
435
|
}
|
|
435
436
|
},
|
|
436
437
|
fs: {
|
|
437
|
-
getDirectory: async (
|
|
438
|
+
getDirectory: async (path2) => {
|
|
438
439
|
const conn = callbackContext.connection;
|
|
439
440
|
if (!conn) {
|
|
440
441
|
throw new Error("FS callbacks not available");
|
|
@@ -443,7 +444,7 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
443
444
|
connection: conn,
|
|
444
445
|
callbackContext,
|
|
445
446
|
invokeClientCallback,
|
|
446
|
-
basePath:
|
|
447
|
+
basePath: path2
|
|
447
448
|
});
|
|
448
449
|
}
|
|
449
450
|
}
|
|
@@ -467,6 +468,7 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
467
468
|
if (moduleLoaderCallback) {
|
|
468
469
|
instance.moduleLoaderCallbackId = moduleLoaderCallback.callbackId;
|
|
469
470
|
instance.moduleCache = new Map;
|
|
471
|
+
instance.moduleToFilename = new Map;
|
|
470
472
|
}
|
|
471
473
|
if (customCallbacks) {
|
|
472
474
|
await setupCustomFunctions(runtime.context, customCallbacks, connection, instance);
|
|
@@ -532,7 +534,7 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
532
534
|
console: playwrightCallbacks.console,
|
|
533
535
|
onEvent: (event) => {
|
|
534
536
|
if (event.type === "browserConsoleLog" && playwrightCallbacks.onBrowserConsoleLogCallbackId) {
|
|
535
|
-
const promise = invokeClientCallback(connection, playwrightCallbacks.onBrowserConsoleLogCallbackId, [{ level: event.level,
|
|
537
|
+
const promise = invokeClientCallback(connection, playwrightCallbacks.onBrowserConsoleLogCallbackId, [{ level: event.level, stdout: event.stdout, timestamp: event.timestamp }]).catch(() => {});
|
|
536
538
|
pendingCallbacks.push(promise);
|
|
537
539
|
} else if (event.type === "networkRequest" && playwrightCallbacks.onNetworkRequestCallbackId) {
|
|
538
540
|
const promise = invokeClientCallback(connection, playwrightCallbacks.onNetworkRequestCallbackId, [event]).catch(() => {});
|
|
@@ -611,10 +613,12 @@ async function handleEval(message, connection, state) {
|
|
|
611
613
|
}
|
|
612
614
|
instance.lastActivity = Date.now();
|
|
613
615
|
try {
|
|
616
|
+
const filename = import_isolate_protocol.normalizeEntryFilename(message.filename);
|
|
614
617
|
const mod = await instance.runtime.isolate.compileModule(message.code, {
|
|
615
|
-
filename
|
|
618
|
+
filename
|
|
616
619
|
});
|
|
617
620
|
if (instance.moduleLoaderCallbackId) {
|
|
621
|
+
instance.moduleToFilename?.set(mod, filename);
|
|
618
622
|
const resolver = createModuleResolver(instance, connection);
|
|
619
623
|
await mod.instantiate(instance.runtime.context, resolver);
|
|
620
624
|
} else {
|
|
@@ -1382,17 +1386,22 @@ async function setupCustomFunctions(context, customCallbacks, connection, instan
|
|
|
1382
1386
|
}
|
|
1383
1387
|
}
|
|
1384
1388
|
function createModuleResolver(instance, connection) {
|
|
1385
|
-
return async (specifier,
|
|
1389
|
+
return async (specifier, referrer) => {
|
|
1386
1390
|
const cached = instance.moduleCache?.get(specifier);
|
|
1387
1391
|
if (cached)
|
|
1388
1392
|
return cached;
|
|
1389
1393
|
if (!instance.moduleLoaderCallbackId) {
|
|
1390
1394
|
throw new Error(`Module not found: ${specifier}`);
|
|
1391
1395
|
}
|
|
1392
|
-
const
|
|
1396
|
+
const importerPath = instance.moduleToFilename?.get(referrer) ?? "<unknown>";
|
|
1397
|
+
const importerResolveDir = import_node_path.default.posix.dirname(importerPath);
|
|
1398
|
+
const result = await invokeClientCallback(connection, instance.moduleLoaderCallbackId, [specifier, { path: importerPath, resolveDir: importerResolveDir }]);
|
|
1399
|
+
const { code, resolveDir } = result;
|
|
1393
1400
|
const mod = await instance.runtime.isolate.compileModule(code, {
|
|
1394
1401
|
filename: specifier
|
|
1395
1402
|
});
|
|
1403
|
+
const resolvedPath = import_node_path.default.posix.join(resolveDir, import_node_path.default.posix.basename(specifier));
|
|
1404
|
+
instance.moduleToFilename?.set(mod, resolvedPath);
|
|
1396
1405
|
const resolver = createModuleResolver(instance, connection);
|
|
1397
1406
|
await mod.instantiate(instance.runtime.context, resolver);
|
|
1398
1407
|
instance.moduleCache?.set(specifier, mod);
|
|
@@ -1810,4 +1819,4 @@ async function handleClearCollectedData(message, connection, state) {
|
|
|
1810
1819
|
}
|
|
1811
1820
|
}
|
|
1812
1821
|
|
|
1813
|
-
//# debugId=
|
|
1822
|
+
//# debugId=6F23033E4A4DC7E564756E2164756E21
|