@vcp-dev/site-edit-bridge 0.10.24 → 0.10.25
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/engine-worker-client.js +20 -1
- package/dist/index.js +7 -6
- package/dist/next-dev-server.js +4 -3
- package/package.json +3 -3
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
1
3
|
import { Worker } from "node:worker_threads";
|
|
2
4
|
import { SITE_EDIT_ENGINE_WORKER_METHODS, deserializeSiteEditEngineError, } from "./engine-worker-messages.js";
|
|
3
5
|
import { attachSiteEditWebSocketServer, normalizeSiteEditBridgeServerOptions, } from "./server.js";
|
|
@@ -114,7 +116,8 @@ export function attachSiteEditBridgeServerInWorker(server, options, dependencies
|
|
|
114
116
|
};
|
|
115
117
|
const spawnWorker = () => {
|
|
116
118
|
const workerGeneration = (generation += 1);
|
|
117
|
-
const
|
|
119
|
+
const workerUrl = dependencies.workerUrl ?? new URL("./engine-worker.js", import.meta.url);
|
|
120
|
+
const next = new Worker(resolveWorkerEntrypoint(workerUrl), {
|
|
118
121
|
workerData,
|
|
119
122
|
resourceLimits: { maxOldGenerationSizeMb: maxHeapMb },
|
|
120
123
|
...(dependencies.execArgv ? { execArgv: dependencies.execArgv } : {}),
|
|
@@ -248,6 +251,22 @@ export function attachSiteEditBridgeServerInWorker(server, options, dependencies
|
|
|
248
251
|
eventListeners: listeners,
|
|
249
252
|
};
|
|
250
253
|
}
|
|
254
|
+
function resolveWorkerEntrypoint(workerUrl) {
|
|
255
|
+
if (!workerUrl.pathname.endsWith(".ts")) {
|
|
256
|
+
return workerUrl;
|
|
257
|
+
}
|
|
258
|
+
// Node 24 chooses its built-in strip-only loader before worker execArgv
|
|
259
|
+
// preloads run. A .ts worker entry can therefore bypass `--import tsx` and
|
|
260
|
+
// fail on non-erasable syntax in its dependency graph. Start from a JS data
|
|
261
|
+
// module and let tsx's scoped API import the requested source entry after
|
|
262
|
+
// the worker is online. Built .js and custom .mjs workers remain direct.
|
|
263
|
+
const tsxApiUrl = pathToFileURL(createRequire(import.meta.url).resolve("tsx/esm/api")).href;
|
|
264
|
+
const launcherSource = [
|
|
265
|
+
`import { tsImport } from ${JSON.stringify(tsxApiUrl)};`,
|
|
266
|
+
`await tsImport(${JSON.stringify(workerUrl.href)}, ${JSON.stringify(workerUrl.href)});`,
|
|
267
|
+
].join("\n");
|
|
268
|
+
return new URL(`data:text/javascript,${encodeURIComponent(launcherSource)}`);
|
|
269
|
+
}
|
|
251
270
|
function readPositiveInteger(value) {
|
|
252
271
|
if (!value || !/^\d+$/.test(value.trim())) {
|
|
253
272
|
return undefined;
|