Update checked-in dependencies
This commit is contained in:
parent
49f7b34c3d
commit
5261a1223f
1640 changed files with 174830 additions and 182292 deletions
353
node_modules/synckit/lib/index.cjs
generated
vendored
353
node_modules/synckit/lib/index.cjs
generated
vendored
|
|
@ -1,19 +1,41 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var node_crypto = require('node:crypto');
|
||||
var fs = require('node:fs');
|
||||
var node_module = require('node:module');
|
||||
var module$1 = require('node:module');
|
||||
var path = require('node:path');
|
||||
var node_url = require('node:url');
|
||||
var node_worker_threads = require('node:worker_threads');
|
||||
var utils = require('@pkgr/utils');
|
||||
|
||||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
||||
|
||||
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
||||
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
||||
var core = require('@pkgr/core');
|
||||
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __spreadValues = (a, b) => {
|
||||
for (var prop in b || (b = {}))
|
||||
if (__hasOwnProp.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
if (__getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(b)) {
|
||||
if (__propIsEnum.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
}
|
||||
return a;
|
||||
};
|
||||
var __objRest = (source, exclude) => {
|
||||
var target = {};
|
||||
for (var prop in source)
|
||||
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
||||
target[prop] = source[prop];
|
||||
if (source != null && __getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(source)) {
|
||||
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
||||
target[prop] = source[prop];
|
||||
}
|
||||
return target;
|
||||
};
|
||||
var __async = (__this, __arguments, generator) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
var fulfilled = (value) => {
|
||||
|
|
@ -35,27 +57,46 @@ var __async = (__this, __arguments, generator) => {
|
|||
});
|
||||
};
|
||||
const import_meta = {};
|
||||
const INT32_BYTES = 4;
|
||||
const TsRunner = {
|
||||
// https://github.com/TypeStrong/ts-node
|
||||
TsNode: "ts-node",
|
||||
// https://github.com/egoist/esbuild-register
|
||||
EsbuildRegister: "esbuild-register",
|
||||
// https://github.com/folke/esbuild-runner
|
||||
EsbuildRunner: "esbuild-runner",
|
||||
// https://github.com/swc-project/swc-node/tree/master/packages/register
|
||||
SWC: "swc",
|
||||
// https://github.com/esbuild-kit/tsx
|
||||
TSX: "tsx"
|
||||
};
|
||||
const {
|
||||
SYNCKIT_BUFFER_SIZE,
|
||||
SYNCKIT_TIMEOUT,
|
||||
NODE_OPTIONS,
|
||||
SYNCKIT_EXEC_ARGV,
|
||||
SYNCKIT_TS_RUNNER,
|
||||
NODE_OPTIONS
|
||||
SYNCKIT_GLOBAL_SHIMS,
|
||||
SYNCKIT_TIMEOUT,
|
||||
SYNCKIT_TS_RUNNER
|
||||
} = process.env;
|
||||
const DEFAULT_BUFFER_SIZE = SYNCKIT_BUFFER_SIZE ? +SYNCKIT_BUFFER_SIZE : void 0;
|
||||
const IS_NODE_20 = Number(process.versions.node.split(".")[0]) >= 20;
|
||||
const DEFAULT_TIMEOUT = SYNCKIT_TIMEOUT ? +SYNCKIT_TIMEOUT : void 0;
|
||||
const DEFAULT_WORKER_BUFFER_SIZE = DEFAULT_BUFFER_SIZE || 1024;
|
||||
const DEFAULT_EXEC_ARGV = (SYNCKIT_EXEC_ARGV == null ? void 0 : SYNCKIT_EXEC_ARGV.split(",")) || [];
|
||||
const DEFAULT_TS_RUNNER = SYNCKIT_TS_RUNNER || TsRunner.TsNode;
|
||||
const DEFAULT_TS_RUNNER = SYNCKIT_TS_RUNNER;
|
||||
const DEFAULT_GLOBAL_SHIMS = ["1", "true"].includes(
|
||||
SYNCKIT_GLOBAL_SHIMS
|
||||
);
|
||||
const DEFAULT_GLOBAL_SHIMS_PRESET = [
|
||||
{
|
||||
moduleName: "node-fetch",
|
||||
globalName: "fetch"
|
||||
},
|
||||
{
|
||||
moduleName: "node:perf_hooks",
|
||||
globalName: "performance",
|
||||
named: "performance"
|
||||
}
|
||||
];
|
||||
const MTS_SUPPORTED_NODE_VERSION = 16;
|
||||
const syncFnCache = /* @__PURE__ */ new Map();
|
||||
let syncFnCache;
|
||||
function extractProperties(object) {
|
||||
if (object && typeof object === "object") {
|
||||
const properties = {};
|
||||
|
|
@ -65,64 +106,77 @@ function extractProperties(object) {
|
|||
return properties;
|
||||
}
|
||||
}
|
||||
function createSyncFn(workerPath, bufferSizeOrOptions, timeout) {
|
||||
if (!path__default["default"].isAbsolute(workerPath)) {
|
||||
throw new Error("`workerPath` must be absolute");
|
||||
}
|
||||
function createSyncFn(workerPath, timeoutOrOptions) {
|
||||
syncFnCache != null ? syncFnCache : syncFnCache = /* @__PURE__ */ new Map();
|
||||
const cachedSyncFn = syncFnCache.get(workerPath);
|
||||
if (cachedSyncFn) {
|
||||
return cachedSyncFn;
|
||||
}
|
||||
if (!path.isAbsolute(workerPath)) {
|
||||
throw new Error("`workerPath` must be absolute");
|
||||
}
|
||||
const syncFn = startWorkerThread(
|
||||
workerPath,
|
||||
typeof bufferSizeOrOptions === "number" ? { bufferSize: bufferSizeOrOptions, timeout } : bufferSizeOrOptions
|
||||
/* istanbul ignore next */
|
||||
typeof timeoutOrOptions === "number" ? { timeout: timeoutOrOptions } : timeoutOrOptions
|
||||
);
|
||||
syncFnCache.set(workerPath, syncFn);
|
||||
return syncFn;
|
||||
}
|
||||
const cjsRequire = typeof require === "undefined" ? node_module.createRequire(import_meta.url) : require;
|
||||
const cjsRequire = typeof require === "undefined" ? module$1.createRequire(import_meta.url) : (
|
||||
/* istanbul ignore next */
|
||||
require
|
||||
);
|
||||
const dataUrl = (code) => new URL(`data:text/javascript,${encodeURIComponent(code)}`);
|
||||
const isFile = (path2) => {
|
||||
var _a;
|
||||
try {
|
||||
return fs__default["default"].statSync(path2).isFile();
|
||||
return !!((_a = fs.statSync(path2, { throwIfNoEntry: false })) == null ? void 0 : _a.isFile());
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
||||
let ext = path__default["default"].extname(workerPath);
|
||||
let ext = path.extname(workerPath);
|
||||
if (!/[/\\]node_modules[/\\]/.test(workerPath) && (!ext || /^\.[cm]?js$/.test(ext))) {
|
||||
const workPathWithoutExt = ext ? workerPath.slice(0, -ext.length) : workerPath;
|
||||
let extensions;
|
||||
switch (ext) {
|
||||
case ".cjs":
|
||||
case ".cjs": {
|
||||
extensions = [".cts", ".cjs"];
|
||||
break;
|
||||
case ".mjs":
|
||||
}
|
||||
case ".mjs": {
|
||||
extensions = [".mts", ".mjs"];
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
extensions = [".ts", ".js"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
const found = utils.tryExtensions(workPathWithoutExt, extensions);
|
||||
const found = core.tryExtensions(workPathWithoutExt, extensions);
|
||||
let differentExt;
|
||||
if (found && (!ext || (differentExt = found !== workPathWithoutExt))) {
|
||||
workerPath = found;
|
||||
if (differentExt) {
|
||||
ext = path__default["default"].extname(workerPath);
|
||||
ext = path.extname(workerPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
const isTs = /\.[cm]?ts$/.test(workerPath);
|
||||
let jsUseEsm = workerPath.endsWith(".mjs");
|
||||
let tsUseEsm = workerPath.endsWith(".mts");
|
||||
if (isTs) {
|
||||
if (!tsUseEsm) {
|
||||
const pkg = utils.findUp(workerPath);
|
||||
const pkg = core.findUp(workerPath);
|
||||
if (pkg) {
|
||||
tsUseEsm = cjsRequire(pkg).type === "module";
|
||||
}
|
||||
}
|
||||
if (tsRunner == null && core.isPkgAvailable(TsRunner.TsNode)) {
|
||||
tsRunner = TsRunner.TsNode;
|
||||
}
|
||||
switch (tsRunner) {
|
||||
case TsRunner.TsNode: {
|
||||
if (tsUseEsm) {
|
||||
|
|
@ -162,7 +216,13 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|||
throw new Error(`Unknown ts runner: ${String(tsRunner)}`);
|
||||
}
|
||||
}
|
||||
} else if (!jsUseEsm) {
|
||||
const pkg = core.findUp(workerPath);
|
||||
if (pkg) {
|
||||
jsUseEsm = cjsRequire(pkg).type === "module";
|
||||
}
|
||||
}
|
||||
let resolvedPnpLoaderPath;
|
||||
if (process.versions.pnp) {
|
||||
const nodeOptions = NODE_OPTIONS == null ? void 0 : NODE_OPTIONS.split(/\s+/);
|
||||
let pnpApiPath;
|
||||
|
|
@ -174,79 +234,182 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|||
(option, index) => ["-r", "--require"].includes(option) && pnpApiPath === cjsRequire.resolve(nodeOptions[index + 1])
|
||||
)) && !execArgv.includes(pnpApiPath)) {
|
||||
execArgv = ["-r", pnpApiPath, ...execArgv];
|
||||
const pnpLoaderPath = path__default["default"].resolve(pnpApiPath, "../.pnp.loader.mjs");
|
||||
const pnpLoaderPath = path.resolve(pnpApiPath, "../.pnp.loader.mjs");
|
||||
if (isFile(pnpLoaderPath)) {
|
||||
const experimentalLoader = node_url.pathToFileURL(pnpLoaderPath).toString();
|
||||
execArgv = ["--experimental-loader", experimentalLoader, ...execArgv];
|
||||
resolvedPnpLoaderPath = node_url.pathToFileURL(pnpLoaderPath).toString();
|
||||
if (!IS_NODE_20) {
|
||||
execArgv = [
|
||||
"--experimental-loader",
|
||||
resolvedPnpLoaderPath,
|
||||
...execArgv
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
ext,
|
||||
isTs,
|
||||
jsUseEsm,
|
||||
tsRunner,
|
||||
tsUseEsm,
|
||||
workerPath,
|
||||
pnpLoaderPath: resolvedPnpLoaderPath,
|
||||
execArgv
|
||||
};
|
||||
};
|
||||
const md5Hash = (text) => node_crypto.createHash("md5").update(text).digest("hex");
|
||||
const encodeImportModule = (moduleNameOrGlobalShim, type = "import") => {
|
||||
const { moduleName, globalName, named, conditional } = typeof moduleNameOrGlobalShim === "string" ? { moduleName: moduleNameOrGlobalShim } : moduleNameOrGlobalShim;
|
||||
const importStatement = type === "import" ? `import${globalName ? " " + (named === null ? "* as " + globalName : (named == null ? void 0 : named.trim()) ? `{${named}}` : globalName) + " from" : ""} '${path.isAbsolute(moduleName) ? String(node_url.pathToFileURL(moduleName)) : moduleName}'` : `${globalName ? "const " + ((named == null ? void 0 : named.trim()) ? `{${named}}` : globalName) + "=" : ""}require('${moduleName.replace(/\\/g, "\\\\")}')`;
|
||||
if (!globalName) {
|
||||
return importStatement;
|
||||
}
|
||||
const overrideStatement = `globalThis.${globalName}=${(named == null ? void 0 : named.trim()) ? named : globalName}`;
|
||||
return importStatement + (conditional === false ? `;${overrideStatement}` : `;if(!globalThis.${globalName})${overrideStatement}`);
|
||||
};
|
||||
const _generateGlobals = (globalShims, type) => globalShims.reduce(
|
||||
(acc, shim) => `${acc}${acc ? ";" : ""}${encodeImportModule(shim, type)}`,
|
||||
""
|
||||
);
|
||||
let globalsCache;
|
||||
let tmpdir;
|
||||
const _dirname = typeof __dirname === "undefined" ? path.dirname(node_url.fileURLToPath(import_meta.url)) : (
|
||||
/* istanbul ignore next */
|
||||
__dirname
|
||||
);
|
||||
let sharedBuffer;
|
||||
let sharedBufferView;
|
||||
const generateGlobals = (workerPath, globalShims, type = "import") => {
|
||||
globalsCache != null ? globalsCache : globalsCache = /* @__PURE__ */ new Map();
|
||||
const cached = globalsCache.get(workerPath);
|
||||
if (cached) {
|
||||
const [content2, filepath2] = cached;
|
||||
if (type === "require" && !filepath2 || type === "import" && filepath2 && isFile(filepath2)) {
|
||||
return content2;
|
||||
}
|
||||
}
|
||||
const globals = _generateGlobals(globalShims, type);
|
||||
let content = globals;
|
||||
let filepath;
|
||||
if (type === "import") {
|
||||
if (!tmpdir) {
|
||||
tmpdir = path.resolve(core.findUp(_dirname), "../node_modules/.synckit");
|
||||
}
|
||||
fs.mkdirSync(tmpdir, { recursive: true });
|
||||
filepath = path.resolve(tmpdir, md5Hash(workerPath) + ".mjs");
|
||||
content = encodeImportModule(filepath);
|
||||
fs.writeFileSync(filepath, globals);
|
||||
}
|
||||
globalsCache.set(workerPath, [content, filepath]);
|
||||
return content;
|
||||
};
|
||||
function startWorkerThread(workerPath, {
|
||||
bufferSize = DEFAULT_WORKER_BUFFER_SIZE,
|
||||
timeout = DEFAULT_TIMEOUT,
|
||||
execArgv = DEFAULT_EXEC_ARGV,
|
||||
tsRunner = DEFAULT_TS_RUNNER
|
||||
tsRunner = DEFAULT_TS_RUNNER,
|
||||
transferList = [],
|
||||
globalShims = DEFAULT_GLOBAL_SHIMS
|
||||
} = {}) {
|
||||
const { port1: mainPort, port2: workerPort } = new node_worker_threads.MessageChannel();
|
||||
const {
|
||||
isTs,
|
||||
ext,
|
||||
jsUseEsm,
|
||||
tsUseEsm,
|
||||
tsRunner: finalTsRunner,
|
||||
workerPath: finalWorkerPath,
|
||||
pnpLoaderPath,
|
||||
execArgv: finalExecArgv
|
||||
} = setupTsRunner(workerPath, { execArgv, tsRunner });
|
||||
const workerPathUrl = node_url.pathToFileURL(finalWorkerPath);
|
||||
if (/\.[cm]ts$/.test(finalWorkerPath)) {
|
||||
const isTsxSupported = !tsUseEsm || Number.parseFloat(process.versions.node) >= MTS_SUPPORTED_NODE_VERSION;
|
||||
if ([
|
||||
if (!finalTsRunner) {
|
||||
throw new Error("No ts runner specified, ts worker path is not supported");
|
||||
} else if ([
|
||||
// https://github.com/egoist/esbuild-register/issues/79
|
||||
TsRunner.EsbuildRegister,
|
||||
// https://github.com/folke/esbuild-runner/issues/67
|
||||
TsRunner.EsbuildRunner,
|
||||
// https://github.com/swc-project/swc-node/issues/667
|
||||
TsRunner.SWC,
|
||||
...isTsxSupported ? [] : [TsRunner.TSX]
|
||||
].includes(tsRunner)) {
|
||||
.../* istanbul ignore next */
|
||||
isTsxSupported ? [] : [TsRunner.TSX]
|
||||
].includes(finalTsRunner)) {
|
||||
throw new Error(
|
||||
`${tsRunner} is not supported for ${ext} files yet` + (isTsxSupported ? ", you can try [tsx](https://github.com/esbuild-kit/tsx) instead" : "")
|
||||
`${finalTsRunner} is not supported for ${ext} files yet` + /* istanbul ignore next */
|
||||
(isTsxSupported ? ", you can try [tsx](https://github.com/esbuild-kit/tsx) instead" : "")
|
||||
);
|
||||
}
|
||||
}
|
||||
const useEval = isTs && !tsUseEsm;
|
||||
const finalGlobalShims = (globalShims === true ? DEFAULT_GLOBAL_SHIMS_PRESET : Array.isArray(globalShims) ? globalShims : []).filter(({ moduleName }) => core.isPkgAvailable(moduleName));
|
||||
sharedBufferView != null ? sharedBufferView : sharedBufferView = new Int32Array(
|
||||
/* istanbul ignore next */
|
||||
sharedBuffer != null ? sharedBuffer : sharedBuffer = new SharedArrayBuffer(
|
||||
INT32_BYTES
|
||||
),
|
||||
0,
|
||||
1
|
||||
);
|
||||
const useGlobals = finalGlobalShims.length > 0;
|
||||
const useEval = isTs ? !tsUseEsm : !jsUseEsm && useGlobals;
|
||||
const worker = new node_worker_threads.Worker(
|
||||
tsUseEsm && tsRunner === TsRunner.TsNode ? dataUrl(`import '${String(workerPathUrl)}'`) : useEval ? `require('${finalWorkerPath.replace(/\\/g, "\\\\")}')` : workerPathUrl,
|
||||
jsUseEsm && useGlobals || tsUseEsm && finalTsRunner === TsRunner.TsNode ? dataUrl(
|
||||
`${generateGlobals(
|
||||
finalWorkerPath,
|
||||
finalGlobalShims
|
||||
)};import '${String(workerPathUrl)}'`
|
||||
) : useEval ? `${generateGlobals(
|
||||
finalWorkerPath,
|
||||
finalGlobalShims,
|
||||
"require"
|
||||
)};${encodeImportModule(finalWorkerPath, "require")}` : workerPathUrl,
|
||||
{
|
||||
eval: useEval,
|
||||
workerData: { workerPort },
|
||||
transferList: [workerPort],
|
||||
workerData: { sharedBuffer, workerPort, pnpLoaderPath },
|
||||
transferList: [workerPort, ...transferList],
|
||||
execArgv: finalExecArgv
|
||||
}
|
||||
);
|
||||
let nextID = 0;
|
||||
const syncFn = (...args) => {
|
||||
const id = nextID++;
|
||||
const sharedBuffer = new SharedArrayBuffer(bufferSize);
|
||||
const sharedBufferView = new Int32Array(sharedBuffer);
|
||||
const msg = { sharedBuffer, id, args };
|
||||
worker.postMessage(msg);
|
||||
const status = Atomics.wait(sharedBufferView, 0, 0, timeout);
|
||||
const receiveMessageWithId = (port, expectedId, waitingTimeout) => {
|
||||
const start = Date.now();
|
||||
const status = Atomics.wait(sharedBufferView, 0, 0, waitingTimeout);
|
||||
Atomics.store(sharedBufferView, 0, 0);
|
||||
if (!["ok", "not-equal"].includes(status)) {
|
||||
const abortMsg = {
|
||||
id: expectedId,
|
||||
cmd: "abort"
|
||||
};
|
||||
port.postMessage(abortMsg);
|
||||
throw new Error("Internal error: Atomics.wait() failed: " + status);
|
||||
}
|
||||
const {
|
||||
id: id2,
|
||||
result,
|
||||
error,
|
||||
properties
|
||||
} = node_worker_threads.receiveMessageOnPort(mainPort).message;
|
||||
if (id !== id2) {
|
||||
throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
||||
const _a = node_worker_threads.receiveMessageOnPort(mainPort).message, { id } = _a, message = __objRest(_a, ["id"]);
|
||||
if (id < expectedId) {
|
||||
const waitingTime = Date.now() - start;
|
||||
return receiveMessageWithId(
|
||||
port,
|
||||
expectedId,
|
||||
waitingTimeout ? waitingTimeout - waitingTime : void 0
|
||||
);
|
||||
}
|
||||
if (expectedId !== id) {
|
||||
throw new Error(
|
||||
`Internal error: Expected id ${expectedId} but got id ${id}`
|
||||
);
|
||||
}
|
||||
return __spreadValues({ id }, message);
|
||||
};
|
||||
const syncFn = (...args) => {
|
||||
const id = nextID++;
|
||||
const msg = { id, args };
|
||||
worker.postMessage(msg);
|
||||
const { result, error, properties } = receiveMessageWithId(
|
||||
mainPort,
|
||||
id,
|
||||
timeout
|
||||
);
|
||||
if (error) {
|
||||
throw Object.assign(error, properties);
|
||||
}
|
||||
|
|
@ -259,51 +422,51 @@ function runAsWorker(fn) {
|
|||
if (!node_worker_threads.workerData) {
|
||||
return;
|
||||
}
|
||||
const { workerPort } = node_worker_threads.workerData;
|
||||
try {
|
||||
node_worker_threads.parentPort.on(
|
||||
"message",
|
||||
({ sharedBuffer, id, args }) => {
|
||||
;
|
||||
(() => __async(this, null, function* () {
|
||||
const sharedBufferView = new Int32Array(sharedBuffer);
|
||||
let msg;
|
||||
try {
|
||||
msg = { id, result: yield fn(...args) };
|
||||
} catch (error) {
|
||||
msg = { id, error, properties: extractProperties(error) };
|
||||
}
|
||||
workerPort.postMessage(msg);
|
||||
Atomics.add(sharedBufferView, 0, 1);
|
||||
Atomics.notify(sharedBufferView, 0);
|
||||
}))();
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
node_worker_threads.parentPort.on(
|
||||
"message",
|
||||
({ sharedBuffer, id }) => {
|
||||
const sharedBufferView = new Int32Array(sharedBuffer);
|
||||
workerPort.postMessage({
|
||||
id,
|
||||
error,
|
||||
properties: extractProperties(error)
|
||||
});
|
||||
Atomics.add(sharedBufferView, 0, 1);
|
||||
Atomics.notify(sharedBufferView, 0);
|
||||
}
|
||||
);
|
||||
const { workerPort, sharedBuffer: sharedBuffer2, pnpLoaderPath } = node_worker_threads.workerData;
|
||||
if (pnpLoaderPath && IS_NODE_20) {
|
||||
module$1.register(pnpLoaderPath);
|
||||
}
|
||||
const sharedBufferView2 = new Int32Array(sharedBuffer2, 0, 1);
|
||||
node_worker_threads.parentPort.on(
|
||||
"message",
|
||||
({ id, args }) => {
|
||||
(() => __async(this, null, function* () {
|
||||
let isAborted = false;
|
||||
const handleAbortMessage = (msg2) => {
|
||||
if (msg2.id === id && msg2.cmd === "abort") {
|
||||
isAborted = true;
|
||||
}
|
||||
};
|
||||
workerPort.on("message", handleAbortMessage);
|
||||
let msg;
|
||||
try {
|
||||
msg = { id, result: yield fn(...args) };
|
||||
} catch (error) {
|
||||
msg = { id, error, properties: extractProperties(error) };
|
||||
}
|
||||
workerPort.off("message", handleAbortMessage);
|
||||
if (isAborted) {
|
||||
return;
|
||||
}
|
||||
workerPort.postMessage(msg);
|
||||
Atomics.add(sharedBufferView2, 0, 1);
|
||||
Atomics.notify(sharedBufferView2, 0);
|
||||
}))();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
exports.DEFAULT_BUFFER_SIZE = DEFAULT_BUFFER_SIZE;
|
||||
exports.DEFAULT_EXEC_ARGV = DEFAULT_EXEC_ARGV;
|
||||
exports.DEFAULT_GLOBAL_SHIMS = DEFAULT_GLOBAL_SHIMS;
|
||||
exports.DEFAULT_GLOBAL_SHIMS_PRESET = DEFAULT_GLOBAL_SHIMS_PRESET;
|
||||
exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
|
||||
exports.DEFAULT_TS_RUNNER = DEFAULT_TS_RUNNER;
|
||||
exports.DEFAULT_WORKER_BUFFER_SIZE = DEFAULT_WORKER_BUFFER_SIZE;
|
||||
exports.MTS_SUPPORTED_NODE_VERSION = MTS_SUPPORTED_NODE_VERSION;
|
||||
exports.TsRunner = TsRunner;
|
||||
exports._generateGlobals = _generateGlobals;
|
||||
exports.createSyncFn = createSyncFn;
|
||||
exports.encodeImportModule = encodeImportModule;
|
||||
exports.extractProperties = extractProperties;
|
||||
exports.generateGlobals = generateGlobals;
|
||||
exports.isFile = isFile;
|
||||
exports.runAsWorker = runAsWorker;
|
||||
|
|
|
|||
20
node_modules/synckit/lib/index.d.ts
generated
vendored
20
node_modules/synckit/lib/index.d.ts
generated
vendored
|
|
@ -1,4 +1,6 @@
|
|||
import { AnyAsyncFn, Syncify, ValueOf } from './types.js';
|
||||
/// <reference types="node" />
|
||||
import { type TransferListItem } from 'node:worker_threads';
|
||||
import type { AnyAsyncFn, GlobalShim, Syncify, ValueOf } from './types.js';
|
||||
export * from './types.js';
|
||||
export declare const TsRunner: {
|
||||
readonly TsNode: "ts-node";
|
||||
|
|
@ -8,21 +10,23 @@ export declare const TsRunner: {
|
|||
readonly TSX: "tsx";
|
||||
};
|
||||
export type TsRunner = ValueOf<typeof TsRunner>;
|
||||
export declare const DEFAULT_BUFFER_SIZE: number | undefined;
|
||||
export declare const DEFAULT_TIMEOUT: number | undefined;
|
||||
export declare const DEFAULT_WORKER_BUFFER_SIZE: number;
|
||||
export declare const DEFAULT_EXEC_ARGV: string[];
|
||||
export declare const DEFAULT_TS_RUNNER: TsRunner;
|
||||
export declare const DEFAULT_TS_RUNNER: TsRunner | undefined;
|
||||
export declare const DEFAULT_GLOBAL_SHIMS: boolean;
|
||||
export declare const DEFAULT_GLOBAL_SHIMS_PRESET: GlobalShim[];
|
||||
export declare const MTS_SUPPORTED_NODE_VERSION = 16;
|
||||
export interface SynckitOptions {
|
||||
bufferSize?: number;
|
||||
timeout?: number;
|
||||
execArgv?: string[];
|
||||
globalShims?: GlobalShim[] | boolean;
|
||||
timeout?: number;
|
||||
transferList?: TransferListItem[];
|
||||
tsRunner?: TsRunner;
|
||||
}
|
||||
export declare function extractProperties<T extends object>(object: T): T;
|
||||
export declare function extractProperties<T>(object?: T): T | undefined;
|
||||
export declare function createSyncFn<T extends AnyAsyncFn>(workerPath: string, bufferSize?: number, timeout?: number): Syncify<T>;
|
||||
export declare function createSyncFn<T extends AnyAsyncFn>(workerPath: string, options?: SynckitOptions): Syncify<T>;
|
||||
export declare function createSyncFn<T extends AnyAsyncFn<R>, R = unknown>(workerPath: string, timeoutOrOptions?: SynckitOptions | number): Syncify<T>;
|
||||
export declare const isFile: (path: string) => boolean;
|
||||
export declare const encodeImportModule: (moduleNameOrGlobalShim: GlobalShim | string, type?: 'import' | 'require') => string;
|
||||
export declare const generateGlobals: (workerPath: string, globalShims: GlobalShim[], type?: 'import' | 'require') => string;
|
||||
export declare function runAsWorker<R = unknown, T extends AnyAsyncFn<R> = AnyAsyncFn<R>>(fn: T): void;
|
||||
|
|
|
|||
277
node_modules/synckit/lib/index.js
generated
vendored
277
node_modules/synckit/lib/index.js
generated
vendored
|
|
@ -1,10 +1,12 @@
|
|||
import { __awaiter } from "tslib";
|
||||
import { __awaiter, __rest } from "tslib";
|
||||
import { createHash } from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import module from 'node:module';
|
||||
import path from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import { MessageChannel, Worker, receiveMessageOnPort, workerData, parentPort, } from 'node:worker_threads';
|
||||
import { findUp, tryExtensions } from '@pkgr/utils';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import { MessageChannel, Worker, parentPort, receiveMessageOnPort, workerData, } from 'node:worker_threads';
|
||||
import { findUp, isPkgAvailable, tryExtensions } from '@pkgr/core';
|
||||
const INT32_BYTES = 4;
|
||||
export * from './types.js';
|
||||
export const TsRunner = {
|
||||
TsNode: 'ts-node',
|
||||
|
|
@ -13,17 +15,25 @@ export const TsRunner = {
|
|||
SWC: 'swc',
|
||||
TSX: 'tsx',
|
||||
};
|
||||
const { SYNCKIT_BUFFER_SIZE, SYNCKIT_TIMEOUT, SYNCKIT_EXEC_ARGV, SYNCKIT_TS_RUNNER, NODE_OPTIONS, } = process.env;
|
||||
export const DEFAULT_BUFFER_SIZE = SYNCKIT_BUFFER_SIZE
|
||||
? +SYNCKIT_BUFFER_SIZE
|
||||
: undefined;
|
||||
const { NODE_OPTIONS, SYNCKIT_EXEC_ARGV, SYNCKIT_GLOBAL_SHIMS, SYNCKIT_TIMEOUT, SYNCKIT_TS_RUNNER, } = process.env;
|
||||
const IS_NODE_20 = Number(process.versions.node.split('.')[0]) >= 20;
|
||||
export const DEFAULT_TIMEOUT = SYNCKIT_TIMEOUT ? +SYNCKIT_TIMEOUT : undefined;
|
||||
export const DEFAULT_WORKER_BUFFER_SIZE = DEFAULT_BUFFER_SIZE || 1024;
|
||||
export const DEFAULT_EXEC_ARGV = (SYNCKIT_EXEC_ARGV === null || SYNCKIT_EXEC_ARGV === void 0 ? void 0 : SYNCKIT_EXEC_ARGV.split(',')) || [];
|
||||
export const DEFAULT_TS_RUNNER = (SYNCKIT_TS_RUNNER ||
|
||||
TsRunner.TsNode);
|
||||
export const DEFAULT_TS_RUNNER = SYNCKIT_TS_RUNNER;
|
||||
export const DEFAULT_GLOBAL_SHIMS = ['1', 'true'].includes(SYNCKIT_GLOBAL_SHIMS);
|
||||
export const DEFAULT_GLOBAL_SHIMS_PRESET = [
|
||||
{
|
||||
moduleName: 'node-fetch',
|
||||
globalName: 'fetch',
|
||||
},
|
||||
{
|
||||
moduleName: 'node:perf_hooks',
|
||||
globalName: 'performance',
|
||||
named: 'performance',
|
||||
},
|
||||
];
|
||||
export const MTS_SUPPORTED_NODE_VERSION = 16;
|
||||
const syncFnCache = new Map();
|
||||
let syncFnCache;
|
||||
export function extractProperties(object) {
|
||||
if (object && typeof object === 'object') {
|
||||
const properties = {};
|
||||
|
|
@ -33,29 +43,31 @@ export function extractProperties(object) {
|
|||
return properties;
|
||||
}
|
||||
}
|
||||
export function createSyncFn(workerPath, bufferSizeOrOptions, timeout) {
|
||||
if (!path.isAbsolute(workerPath)) {
|
||||
throw new Error('`workerPath` must be absolute');
|
||||
}
|
||||
export function createSyncFn(workerPath, timeoutOrOptions) {
|
||||
syncFnCache !== null && syncFnCache !== void 0 ? syncFnCache : (syncFnCache = new Map());
|
||||
const cachedSyncFn = syncFnCache.get(workerPath);
|
||||
if (cachedSyncFn) {
|
||||
return cachedSyncFn;
|
||||
}
|
||||
const syncFn = startWorkerThread(workerPath, typeof bufferSizeOrOptions === 'number'
|
||||
? { bufferSize: bufferSizeOrOptions, timeout }
|
||||
: bufferSizeOrOptions);
|
||||
if (!path.isAbsolute(workerPath)) {
|
||||
throw new Error('`workerPath` must be absolute');
|
||||
}
|
||||
const syncFn = startWorkerThread(workerPath, typeof timeoutOrOptions === 'number'
|
||||
? { timeout: timeoutOrOptions }
|
||||
: timeoutOrOptions);
|
||||
syncFnCache.set(workerPath, syncFn);
|
||||
return syncFn;
|
||||
}
|
||||
const cjsRequire = typeof require === 'undefined'
|
||||
? createRequire(import.meta.url)
|
||||
? module.createRequire(import.meta.url)
|
||||
: require;
|
||||
const dataUrl = (code) => new URL(`data:text/javascript,${encodeURIComponent(code)}`);
|
||||
export const isFile = (path) => {
|
||||
var _a;
|
||||
try {
|
||||
return fs.statSync(path).isFile();
|
||||
return !!((_a = fs.statSync(path, { throwIfNoEntry: false })) === null || _a === void 0 ? void 0 : _a.isFile());
|
||||
}
|
||||
catch (_a) {
|
||||
catch (_b) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
@ -68,15 +80,18 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|||
: workerPath;
|
||||
let extensions;
|
||||
switch (ext) {
|
||||
case '.cjs':
|
||||
case '.cjs': {
|
||||
extensions = ['.cts', '.cjs'];
|
||||
break;
|
||||
case '.mjs':
|
||||
}
|
||||
case '.mjs': {
|
||||
extensions = ['.mts', '.mjs'];
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
extensions = ['.ts', '.js'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
const found = tryExtensions(workPathWithoutExt, extensions);
|
||||
let differentExt;
|
||||
|
|
@ -88,6 +103,7 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|||
}
|
||||
}
|
||||
const isTs = /\.[cm]?ts$/.test(workerPath);
|
||||
let jsUseEsm = workerPath.endsWith('.mjs');
|
||||
let tsUseEsm = workerPath.endsWith('.mts');
|
||||
if (isTs) {
|
||||
if (!tsUseEsm) {
|
||||
|
|
@ -98,6 +114,9 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|||
'module';
|
||||
}
|
||||
}
|
||||
if (tsRunner == null && isPkgAvailable(TsRunner.TsNode)) {
|
||||
tsRunner = TsRunner.TsNode;
|
||||
}
|
||||
switch (tsRunner) {
|
||||
case TsRunner.TsNode: {
|
||||
if (tsUseEsm) {
|
||||
|
|
@ -139,6 +158,14 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (!jsUseEsm) {
|
||||
const pkg = findUp(workerPath);
|
||||
if (pkg) {
|
||||
jsUseEsm =
|
||||
cjsRequire(pkg).type === 'module';
|
||||
}
|
||||
}
|
||||
let resolvedPnpLoaderPath;
|
||||
if (process.versions.pnp) {
|
||||
const nodeOptions = NODE_OPTIONS === null || NODE_OPTIONS === void 0 ? void 0 : NODE_OPTIONS.split(/\s+/);
|
||||
let pnpApiPath;
|
||||
|
|
@ -153,65 +180,159 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|||
execArgv = ['-r', pnpApiPath, ...execArgv];
|
||||
const pnpLoaderPath = path.resolve(pnpApiPath, '../.pnp.loader.mjs');
|
||||
if (isFile(pnpLoaderPath)) {
|
||||
const experimentalLoader = pathToFileURL(pnpLoaderPath).toString();
|
||||
execArgv = ['--experimental-loader', experimentalLoader, ...execArgv];
|
||||
resolvedPnpLoaderPath = pathToFileURL(pnpLoaderPath).toString();
|
||||
if (!IS_NODE_20) {
|
||||
execArgv = [
|
||||
'--experimental-loader',
|
||||
resolvedPnpLoaderPath,
|
||||
...execArgv,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
ext,
|
||||
isTs,
|
||||
jsUseEsm,
|
||||
tsRunner,
|
||||
tsUseEsm,
|
||||
workerPath,
|
||||
pnpLoaderPath: resolvedPnpLoaderPath,
|
||||
execArgv,
|
||||
};
|
||||
};
|
||||
function startWorkerThread(workerPath, { bufferSize = DEFAULT_WORKER_BUFFER_SIZE, timeout = DEFAULT_TIMEOUT, execArgv = DEFAULT_EXEC_ARGV, tsRunner = DEFAULT_TS_RUNNER, } = {}) {
|
||||
const md5Hash = (text) => createHash('md5').update(text).digest('hex');
|
||||
export const encodeImportModule = (moduleNameOrGlobalShim, type = 'import') => {
|
||||
const { moduleName, globalName, named, conditional } = typeof moduleNameOrGlobalShim === 'string'
|
||||
? { moduleName: moduleNameOrGlobalShim }
|
||||
: moduleNameOrGlobalShim;
|
||||
const importStatement = type === 'import'
|
||||
? `import${globalName
|
||||
? ' ' +
|
||||
(named === null
|
||||
? '* as ' + globalName
|
||||
: (named === null || named === void 0 ? void 0 : named.trim())
|
||||
? `{${named}}`
|
||||
: globalName) +
|
||||
' from'
|
||||
: ''} '${path.isAbsolute(moduleName)
|
||||
? String(pathToFileURL(moduleName))
|
||||
: moduleName}'`
|
||||
: `${globalName
|
||||
? 'const ' + ((named === null || named === void 0 ? void 0 : named.trim()) ? `{${named}}` : globalName) + '='
|
||||
: ''}require('${moduleName
|
||||
.replace(/\\/g, '\\\\')}')`;
|
||||
if (!globalName) {
|
||||
return importStatement;
|
||||
}
|
||||
const overrideStatement = `globalThis.${globalName}=${(named === null || named === void 0 ? void 0 : named.trim()) ? named : globalName}`;
|
||||
return (importStatement +
|
||||
(conditional === false
|
||||
? `;${overrideStatement}`
|
||||
: `;if(!globalThis.${globalName})${overrideStatement}`));
|
||||
};
|
||||
export const _generateGlobals = (globalShims, type) => globalShims.reduce((acc, shim) => `${acc}${acc ? ';' : ''}${encodeImportModule(shim, type)}`, '');
|
||||
let globalsCache;
|
||||
let tmpdir;
|
||||
const _dirname = typeof __dirname === 'undefined'
|
||||
? path.dirname(fileURLToPath(import.meta.url))
|
||||
: __dirname;
|
||||
let sharedBuffer;
|
||||
let sharedBufferView;
|
||||
export const generateGlobals = (workerPath, globalShims, type = 'import') => {
|
||||
globalsCache !== null && globalsCache !== void 0 ? globalsCache : (globalsCache = new Map());
|
||||
const cached = globalsCache.get(workerPath);
|
||||
if (cached) {
|
||||
const [content, filepath] = cached;
|
||||
if ((type === 'require' && !filepath) ||
|
||||
(type === 'import' && filepath && isFile(filepath))) {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
const globals = _generateGlobals(globalShims, type);
|
||||
let content = globals;
|
||||
let filepath;
|
||||
if (type === 'import') {
|
||||
if (!tmpdir) {
|
||||
tmpdir = path.resolve(findUp(_dirname), '../node_modules/.synckit');
|
||||
}
|
||||
fs.mkdirSync(tmpdir, { recursive: true });
|
||||
filepath = path.resolve(tmpdir, md5Hash(workerPath) + '.mjs');
|
||||
content = encodeImportModule(filepath);
|
||||
fs.writeFileSync(filepath, globals);
|
||||
}
|
||||
globalsCache.set(workerPath, [content, filepath]);
|
||||
return content;
|
||||
};
|
||||
function startWorkerThread(workerPath, { timeout = DEFAULT_TIMEOUT, execArgv = DEFAULT_EXEC_ARGV, tsRunner = DEFAULT_TS_RUNNER, transferList = [], globalShims = DEFAULT_GLOBAL_SHIMS, } = {}) {
|
||||
const { port1: mainPort, port2: workerPort } = new MessageChannel();
|
||||
const { isTs, ext, tsUseEsm, workerPath: finalWorkerPath, execArgv: finalExecArgv, } = setupTsRunner(workerPath, { execArgv, tsRunner });
|
||||
const { isTs, ext, jsUseEsm, tsUseEsm, tsRunner: finalTsRunner, workerPath: finalWorkerPath, pnpLoaderPath, execArgv: finalExecArgv, } = setupTsRunner(workerPath, { execArgv, tsRunner });
|
||||
const workerPathUrl = pathToFileURL(finalWorkerPath);
|
||||
if (/\.[cm]ts$/.test(finalWorkerPath)) {
|
||||
const isTsxSupported = !tsUseEsm ||
|
||||
Number.parseFloat(process.versions.node) >= MTS_SUPPORTED_NODE_VERSION;
|
||||
if ([
|
||||
if (!finalTsRunner) {
|
||||
throw new Error('No ts runner specified, ts worker path is not supported');
|
||||
}
|
||||
else if ([
|
||||
TsRunner.EsbuildRegister,
|
||||
TsRunner.EsbuildRunner,
|
||||
TsRunner.SWC,
|
||||
...(isTsxSupported ? [] : [TsRunner.TSX]),
|
||||
].includes(tsRunner)) {
|
||||
throw new Error(`${tsRunner} is not supported for ${ext} files yet` +
|
||||
].includes(finalTsRunner)) {
|
||||
throw new Error(`${finalTsRunner} is not supported for ${ext} files yet` +
|
||||
(isTsxSupported
|
||||
? ', you can try [tsx](https://github.com/esbuild-kit/tsx) instead'
|
||||
: ''));
|
||||
}
|
||||
}
|
||||
const useEval = isTs && !tsUseEsm;
|
||||
const worker = new Worker(tsUseEsm && tsRunner === TsRunner.TsNode
|
||||
? dataUrl(`import '${String(workerPathUrl)}'`)
|
||||
const finalGlobalShims = (globalShims === true
|
||||
? DEFAULT_GLOBAL_SHIMS_PRESET
|
||||
: Array.isArray(globalShims)
|
||||
? globalShims
|
||||
: []).filter(({ moduleName }) => isPkgAvailable(moduleName));
|
||||
sharedBufferView !== null && sharedBufferView !== void 0 ? sharedBufferView : (sharedBufferView = new Int32Array((sharedBuffer !== null && sharedBuffer !== void 0 ? sharedBuffer : (sharedBuffer = new SharedArrayBuffer(INT32_BYTES))), 0, 1));
|
||||
const useGlobals = finalGlobalShims.length > 0;
|
||||
const useEval = isTs ? !tsUseEsm : !jsUseEsm && useGlobals;
|
||||
const worker = new Worker((jsUseEsm && useGlobals) || (tsUseEsm && finalTsRunner === TsRunner.TsNode)
|
||||
? dataUrl(`${generateGlobals(finalWorkerPath, finalGlobalShims)};import '${String(workerPathUrl)}'`)
|
||||
: useEval
|
||||
? `require('${finalWorkerPath.replace(/\\/g, '\\\\')}')`
|
||||
? `${generateGlobals(finalWorkerPath, finalGlobalShims, 'require')};${encodeImportModule(finalWorkerPath, 'require')}`
|
||||
: workerPathUrl, {
|
||||
eval: useEval,
|
||||
workerData: { workerPort },
|
||||
transferList: [workerPort],
|
||||
workerData: { sharedBuffer, workerPort, pnpLoaderPath },
|
||||
transferList: [workerPort, ...transferList],
|
||||
execArgv: finalExecArgv,
|
||||
});
|
||||
let nextID = 0;
|
||||
const syncFn = (...args) => {
|
||||
const id = nextID++;
|
||||
const sharedBuffer = new SharedArrayBuffer(bufferSize);
|
||||
const sharedBufferView = new Int32Array(sharedBuffer);
|
||||
const msg = { sharedBuffer, id, args };
|
||||
worker.postMessage(msg);
|
||||
const status = Atomics.wait(sharedBufferView, 0, 0, timeout);
|
||||
const receiveMessageWithId = (port, expectedId, waitingTimeout) => {
|
||||
const start = Date.now();
|
||||
const status = Atomics.wait(sharedBufferView, 0, 0, waitingTimeout);
|
||||
Atomics.store(sharedBufferView, 0, 0);
|
||||
if (!['ok', 'not-equal'].includes(status)) {
|
||||
const abortMsg = {
|
||||
id: expectedId,
|
||||
cmd: 'abort',
|
||||
};
|
||||
port.postMessage(abortMsg);
|
||||
throw new Error('Internal error: Atomics.wait() failed: ' + status);
|
||||
}
|
||||
const { id: id2, result, error, properties, } = receiveMessageOnPort(mainPort)
|
||||
.message;
|
||||
if (id !== id2) {
|
||||
throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
||||
const _a = receiveMessageOnPort(mainPort).message, { id } = _a, message = __rest(_a, ["id"]);
|
||||
if (id < expectedId) {
|
||||
const waitingTime = Date.now() - start;
|
||||
return receiveMessageWithId(port, expectedId, waitingTimeout ? waitingTimeout - waitingTime : undefined);
|
||||
}
|
||||
if (expectedId !== id) {
|
||||
throw new Error(`Internal error: Expected id ${expectedId} but got id ${id}`);
|
||||
}
|
||||
return Object.assign({ id }, message);
|
||||
};
|
||||
const syncFn = (...args) => {
|
||||
const id = nextID++;
|
||||
const msg = { id, args };
|
||||
worker.postMessage(msg);
|
||||
const { result, error, properties } = receiveMessageWithId(mainPort, id, timeout);
|
||||
if (error) {
|
||||
throw Object.assign(error, properties);
|
||||
}
|
||||
|
|
@ -224,36 +345,36 @@ export function runAsWorker(fn) {
|
|||
if (!workerData) {
|
||||
return;
|
||||
}
|
||||
const { workerPort } = workerData;
|
||||
try {
|
||||
parentPort.on('message', ({ sharedBuffer, id, args }) => {
|
||||
;
|
||||
(() => __awaiter(this, void 0, void 0, function* () {
|
||||
const sharedBufferView = new Int32Array(sharedBuffer);
|
||||
let msg;
|
||||
try {
|
||||
msg = { id, result: yield fn(...args) };
|
||||
}
|
||||
catch (error) {
|
||||
msg = { id, error, properties: extractProperties(error) };
|
||||
}
|
||||
workerPort.postMessage(msg);
|
||||
Atomics.add(sharedBufferView, 0, 1);
|
||||
Atomics.notify(sharedBufferView, 0);
|
||||
}))();
|
||||
});
|
||||
const { workerPort, sharedBuffer, pnpLoaderPath } = workerData;
|
||||
if (pnpLoaderPath && IS_NODE_20) {
|
||||
module.register(pnpLoaderPath);
|
||||
}
|
||||
catch (error) {
|
||||
parentPort.on('message', ({ sharedBuffer, id }) => {
|
||||
const sharedBufferView = new Int32Array(sharedBuffer);
|
||||
workerPort.postMessage({
|
||||
id,
|
||||
error,
|
||||
properties: extractProperties(error),
|
||||
});
|
||||
const sharedBufferView = new Int32Array(sharedBuffer, 0, 1);
|
||||
parentPort.on('message', ({ id, args }) => {
|
||||
;
|
||||
(() => __awaiter(this, void 0, void 0, function* () {
|
||||
let isAborted = false;
|
||||
const handleAbortMessage = (msg) => {
|
||||
if (msg.id === id && msg.cmd === 'abort') {
|
||||
isAborted = true;
|
||||
}
|
||||
};
|
||||
workerPort.on('message', handleAbortMessage);
|
||||
let msg;
|
||||
try {
|
||||
msg = { id, result: yield fn(...args) };
|
||||
}
|
||||
catch (error) {
|
||||
msg = { id, error, properties: extractProperties(error) };
|
||||
}
|
||||
workerPort.off('message', handleAbortMessage);
|
||||
if (isAborted) {
|
||||
return;
|
||||
}
|
||||
workerPort.postMessage(msg);
|
||||
Atomics.add(sharedBufferView, 0, 1);
|
||||
Atomics.notify(sharedBufferView, 0);
|
||||
});
|
||||
}
|
||||
}))();
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
2
node_modules/synckit/lib/index.js.map
generated
vendored
2
node_modules/synckit/lib/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
13
node_modules/synckit/lib/types.d.ts
generated
vendored
13
node_modules/synckit/lib/types.d.ts
generated
vendored
|
|
@ -7,12 +7,17 @@ export type Syncify<T extends AnyAsyncFn> = T extends (...args: infer Args) => P
|
|||
export type PromiseType<T extends AnyPromise> = T extends Promise<infer R> ? R : never;
|
||||
export type ValueOf<T> = T[keyof T];
|
||||
export interface MainToWorkerMessage<T extends unknown[]> {
|
||||
sharedBuffer: SharedArrayBuffer;
|
||||
id: number;
|
||||
args: T;
|
||||
}
|
||||
export interface MainToWorkerCommandMessage {
|
||||
id: number;
|
||||
cmd: string;
|
||||
}
|
||||
export interface WorkerData {
|
||||
sharedBuffer: SharedArrayBuffer;
|
||||
workerPort: MessagePort;
|
||||
pnpLoaderPath: string | undefined;
|
||||
}
|
||||
export interface DataMessage<T> {
|
||||
result?: T;
|
||||
|
|
@ -22,3 +27,9 @@ export interface DataMessage<T> {
|
|||
export interface WorkerToMainMessage<T = unknown> extends DataMessage<T> {
|
||||
id: number;
|
||||
}
|
||||
export interface GlobalShim {
|
||||
moduleName: string;
|
||||
globalName?: string;
|
||||
named?: string | null;
|
||||
conditional?: boolean;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue