@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/package.json
CHANGED
package/dist/mjs/connection.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// packages/isolate-daemon/src/connection.ts
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
+
import path from "node:path";
|
|
3
4
|
import ivm from "isolated-vm";
|
|
4
5
|
import {
|
|
5
6
|
createFrameParser,
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
ErrorCode,
|
|
9
10
|
STREAM_CHUNK_SIZE,
|
|
10
11
|
STREAM_DEFAULT_CREDIT,
|
|
12
|
+
normalizeEntryFilename,
|
|
11
13
|
marshalValue,
|
|
12
14
|
unmarshalValue
|
|
13
15
|
} from "@ricsam/isolate-protocol";
|
|
@@ -406,7 +408,7 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
406
408
|
}
|
|
407
409
|
},
|
|
408
410
|
fs: {
|
|
409
|
-
getDirectory: async (
|
|
411
|
+
getDirectory: async (path2) => {
|
|
410
412
|
const conn = callbackContext.connection;
|
|
411
413
|
if (!conn) {
|
|
412
414
|
throw new Error("FS callbacks not available");
|
|
@@ -415,7 +417,7 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
415
417
|
connection: conn,
|
|
416
418
|
callbackContext,
|
|
417
419
|
invokeClientCallback,
|
|
418
|
-
basePath:
|
|
420
|
+
basePath: path2
|
|
419
421
|
});
|
|
420
422
|
}
|
|
421
423
|
}
|
|
@@ -439,6 +441,7 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
439
441
|
if (moduleLoaderCallback) {
|
|
440
442
|
instance.moduleLoaderCallbackId = moduleLoaderCallback.callbackId;
|
|
441
443
|
instance.moduleCache = new Map;
|
|
444
|
+
instance.moduleToFilename = new Map;
|
|
442
445
|
}
|
|
443
446
|
if (customCallbacks) {
|
|
444
447
|
await setupCustomFunctions(runtime.context, customCallbacks, connection, instance);
|
|
@@ -504,7 +507,7 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
504
507
|
console: playwrightCallbacks.console,
|
|
505
508
|
onEvent: (event) => {
|
|
506
509
|
if (event.type === "browserConsoleLog" && playwrightCallbacks.onBrowserConsoleLogCallbackId) {
|
|
507
|
-
const promise = invokeClientCallback(connection, playwrightCallbacks.onBrowserConsoleLogCallbackId, [{ level: event.level,
|
|
510
|
+
const promise = invokeClientCallback(connection, playwrightCallbacks.onBrowserConsoleLogCallbackId, [{ level: event.level, stdout: event.stdout, timestamp: event.timestamp }]).catch(() => {});
|
|
508
511
|
pendingCallbacks.push(promise);
|
|
509
512
|
} else if (event.type === "networkRequest" && playwrightCallbacks.onNetworkRequestCallbackId) {
|
|
510
513
|
const promise = invokeClientCallback(connection, playwrightCallbacks.onNetworkRequestCallbackId, [event]).catch(() => {});
|
|
@@ -583,10 +586,12 @@ async function handleEval(message, connection, state) {
|
|
|
583
586
|
}
|
|
584
587
|
instance.lastActivity = Date.now();
|
|
585
588
|
try {
|
|
589
|
+
const filename = normalizeEntryFilename(message.filename);
|
|
586
590
|
const mod = await instance.runtime.isolate.compileModule(message.code, {
|
|
587
|
-
filename
|
|
591
|
+
filename
|
|
588
592
|
});
|
|
589
593
|
if (instance.moduleLoaderCallbackId) {
|
|
594
|
+
instance.moduleToFilename?.set(mod, filename);
|
|
590
595
|
const resolver = createModuleResolver(instance, connection);
|
|
591
596
|
await mod.instantiate(instance.runtime.context, resolver);
|
|
592
597
|
} else {
|
|
@@ -1354,17 +1359,22 @@ async function setupCustomFunctions(context, customCallbacks, connection, instan
|
|
|
1354
1359
|
}
|
|
1355
1360
|
}
|
|
1356
1361
|
function createModuleResolver(instance, connection) {
|
|
1357
|
-
return async (specifier,
|
|
1362
|
+
return async (specifier, referrer) => {
|
|
1358
1363
|
const cached = instance.moduleCache?.get(specifier);
|
|
1359
1364
|
if (cached)
|
|
1360
1365
|
return cached;
|
|
1361
1366
|
if (!instance.moduleLoaderCallbackId) {
|
|
1362
1367
|
throw new Error(`Module not found: ${specifier}`);
|
|
1363
1368
|
}
|
|
1364
|
-
const
|
|
1369
|
+
const importerPath = instance.moduleToFilename?.get(referrer) ?? "<unknown>";
|
|
1370
|
+
const importerResolveDir = path.posix.dirname(importerPath);
|
|
1371
|
+
const result = await invokeClientCallback(connection, instance.moduleLoaderCallbackId, [specifier, { path: importerPath, resolveDir: importerResolveDir }]);
|
|
1372
|
+
const { code, resolveDir } = result;
|
|
1365
1373
|
const mod = await instance.runtime.isolate.compileModule(code, {
|
|
1366
1374
|
filename: specifier
|
|
1367
1375
|
});
|
|
1376
|
+
const resolvedPath = path.posix.join(resolveDir, path.posix.basename(specifier));
|
|
1377
|
+
instance.moduleToFilename?.set(mod, resolvedPath);
|
|
1368
1378
|
const resolver = createModuleResolver(instance, connection);
|
|
1369
1379
|
await mod.instantiate(instance.runtime.context, resolver);
|
|
1370
1380
|
instance.moduleCache?.set(specifier, mod);
|
|
@@ -1785,4 +1795,4 @@ export {
|
|
|
1785
1795
|
handleConnection
|
|
1786
1796
|
};
|
|
1787
1797
|
|
|
1788
|
-
//# debugId=
|
|
1798
|
+
//# debugId=E68FD11623EE904064756E2164756E21
|