Tracking de l'application VApp (IHM du jeu)
This commit is contained in:
21
VApp/node_modules/synckit/LICENSE
generated
vendored
Normal file
21
VApp/node_modules/synckit/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 UnTS
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
191
VApp/node_modules/synckit/README.md
generated
vendored
Normal file
191
VApp/node_modules/synckit/README.md
generated
vendored
Normal file
@ -0,0 +1,191 @@
|
||||
# synckit
|
||||
|
||||
[](https://github.com/un-ts/synckit/actions/workflows/ci.yml)
|
||||
[](https://codecov.io/gh/un-ts/synckit)
|
||||
[](https://github.com/plantain-00/type-coverage)
|
||||
[](https://www.npmjs.com/package/synckit)
|
||||
[](https://github.com/un-ts/synckit/releases)
|
||||
|
||||
[](https://conventionalcommits.org)
|
||||
[](https://renovatebot.com)
|
||||
[](https://standardjs.com)
|
||||
[](https://github.com/prettier/prettier)
|
||||
|
||||
Perform async work synchronously in Node.js using `worker_threads` with first-class TypeScript support.
|
||||
|
||||
## TOC <!-- omit in toc -->
|
||||
|
||||
- [Usage](#usage)
|
||||
- [Install](#install)
|
||||
- [API](#api)
|
||||
- [Types](#types)
|
||||
- [Options](#options)
|
||||
- [Envs](#envs)
|
||||
- [TypeScript](#typescript)
|
||||
- [`ts-node`](#ts-node)
|
||||
- [`esbuild-register`](#esbuild-register)
|
||||
- [`esbuild-runner`](#esbuild-runner)
|
||||
- [`swc`](#swc)
|
||||
- [`tsx`](#tsx)
|
||||
- [Benchmark](#benchmark)
|
||||
- [Sponsors](#sponsors)
|
||||
- [Backers](#backers)
|
||||
- [Changelog](#changelog)
|
||||
- [License](#license)
|
||||
|
||||
## Usage
|
||||
|
||||
### Install
|
||||
|
||||
```sh
|
||||
# yarn
|
||||
yarn add synckit
|
||||
|
||||
# npm
|
||||
npm i synckit
|
||||
```
|
||||
|
||||
### API
|
||||
|
||||
```js
|
||||
// runner.js
|
||||
import { createSyncFn } from 'synckit'
|
||||
|
||||
// the worker path must be absolute
|
||||
const syncFn = createSyncFn(require.resolve('./worker'), {
|
||||
tsRunner: 'tsx', // optional, can be `'ts-node' | 'esbuild-register' | 'esbuild-runner' | 'tsx'`
|
||||
})
|
||||
|
||||
// do whatever you want, you will get the result synchronously!
|
||||
const result = syncFn(...args)
|
||||
```
|
||||
|
||||
```js
|
||||
// worker.js
|
||||
import { runAsWorker } from 'synckit'
|
||||
|
||||
runAsWorker(async (...args) => {
|
||||
// do expensive work
|
||||
return result
|
||||
})
|
||||
```
|
||||
|
||||
You must make sure, the `result` is serializable by [`Structured Clone Algorithm`](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
|
||||
|
||||
### Types
|
||||
|
||||
````ts
|
||||
export interface GlobalShim {
|
||||
moduleName: string
|
||||
/**
|
||||
* `undefined` means side effect only
|
||||
*/
|
||||
globalName?: string
|
||||
/**
|
||||
* 1. `undefined` or empty string means `default`, for example:
|
||||
* ```js
|
||||
* import globalName from 'module-name'
|
||||
* ```
|
||||
*
|
||||
* 2. `null` means namespaced, for example:
|
||||
* ```js
|
||||
* import * as globalName from 'module-name'
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
named?: string | null
|
||||
/**
|
||||
* If not `false`, the shim will only be applied when the original `globalName` unavailable,
|
||||
* for example you may only want polyfill `globalThis.fetch` when it's unavailable natively:
|
||||
* ```js
|
||||
* import fetch from 'node-fetch'
|
||||
*
|
||||
* if (!globalThis.fetch) {
|
||||
* globalThis.fetch = fetch
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
conditional?: boolean
|
||||
}
|
||||
````
|
||||
|
||||
### Options
|
||||
|
||||
1. `bufferSize` same as env `SYNCKIT_BUFFER_SIZE`
|
||||
2. `timeout` same as env `SYNCKIT_TIMEOUT`
|
||||
3. `execArgv` same as env `SYNCKIT_EXEC_ARGV`
|
||||
4. `tsRunner` same as env `SYNCKIT_TS_RUNNER`
|
||||
5. `transferList`: Please refer Node.js [`worker_threads`](https://nodejs.org/api/worker_threads.html#:~:text=Default%3A%20true.-,transferList,-%3CObject%5B%5D%3E%20If) documentation
|
||||
6. `globalShims`: Similar like env `SYNCKIT_GLOBAL_SHIMS` but much more flexible which can be a `GlobalShim` `Array`, see `GlobalShim`'s [definition](#types) for more details
|
||||
|
||||
### Envs
|
||||
|
||||
1. `SYNCKIT_BUFFER_SIZE`: `bufferSize` to create `SharedArrayBuffer` for `worker_threads` (default as `1024`)
|
||||
2. `SYNCKIT_TIMEOUT`: `timeout` for performing the async job (no default)
|
||||
3. `SYNCKIT_EXEC_ARGV`: List of node CLI options passed to the worker, split with comma `,`. (default as `[]`), see also [`node` docs](https://nodejs.org/api/worker_threads.html)
|
||||
4. `SYNCKIT_TS_RUNNER`: Which TypeScript runner to be used, it could be very useful for development, could be `'ts-node' | 'esbuild-register' | 'esbuild-runner' | 'swc' | 'tsx'`, `'ts-node'` is used by default, make sure you have installed them already
|
||||
5. `SYNCKIT_GLOBAL_SHIMS`: Whether to enable the default `DEFAULT_GLOBAL_SHIMS_PRESET` as `globalShims`
|
||||
|
||||
### TypeScript
|
||||
|
||||
#### `ts-node`
|
||||
|
||||
If you want to use `ts-node` for worker file (a `.ts` file), it is supported out of box!
|
||||
|
||||
If you want to use a custom tsconfig as project instead of default `tsconfig.json`, use `TS_NODE_PROJECT` env. Please view [ts-node](https://github.com/TypeStrong/ts-node#tsconfig) for more details.
|
||||
|
||||
If you want to integrate with [tsconfig-paths](https://www.npmjs.com/package/tsconfig-paths), please view [ts-node](https://github.com/TypeStrong/ts-node#paths-and-baseurl) for more details.
|
||||
|
||||
#### `esbuild-register`
|
||||
|
||||
Please view [`esbuild-register`][] for its document
|
||||
|
||||
#### `esbuild-runner`
|
||||
|
||||
Please view [`esbuild-runner`][] for its document
|
||||
|
||||
#### `swc`
|
||||
|
||||
Please view [`@swc-node/register`][] for its document
|
||||
|
||||
#### `tsx`
|
||||
|
||||
Please view [`tsx`][] for its document
|
||||
|
||||
## Benchmark
|
||||
|
||||
It is about 20x faster than [`sync-threads`](https://github.com/lambci/sync-threads) but 3x slower than native for reading the file content itself 1000 times during runtime, and 18x faster than `sync-threads` but 4x slower than native for total time.
|
||||
|
||||
And it's almost same as [`deasync`](https://github.com/abbr/deasync) but requires no native bindings or `node-gyp`.
|
||||
|
||||
See [benchmark.cjs](./benchmarks/benchmark.cjs.txt) and [benchmark.esm](./benchmarks/benchmark.esm.txt) for more details.
|
||||
|
||||
You can try it with running `yarn benchmark` by yourself. [Here](./benchmarks/benchmark.js) is the benchmark source code.
|
||||
|
||||
## Sponsors
|
||||
|
||||
| 1stG | RxTS | UnTS |
|
||||
| ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
|
||||
|
||||
## Backers
|
||||
|
||||
| 1stG | RxTS | UnTS |
|
||||
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
|
||||
|
||||
## Changelog
|
||||
|
||||
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
|
||||
|
||||
## License
|
||||
|
||||
[MIT][] © [JounQin][]@[1stG.me][]
|
||||
|
||||
[`esbuild-register`]: https://github.com/egoist/esbuild-register
|
||||
[`esbuild-runner`]: https://github.com/folke/esbuild-runner
|
||||
[`@swc-node/register`]: https://github.com/swc-project/swc-node/tree/master/packages/register
|
||||
[`tsx`]: https://github.com/esbuild-kit/tsx
|
||||
[1stg.me]: https://www.1stg.me
|
||||
[jounqin]: https://GitHub.com/JounQin
|
||||
[mit]: http://opensource.org/licenses/MIT
|
395
VApp/node_modules/synckit/lib/index.cjs
generated
vendored
Normal file
395
VApp/node_modules/synckit/lib/index.cjs
generated
vendored
Normal file
@ -0,0 +1,395 @@
|
||||
'use strict';
|
||||
|
||||
var node_crypto = require('node:crypto');
|
||||
var fs = require('node:fs');
|
||||
var node_module = require('node:module');
|
||||
var path = require('node:path');
|
||||
var node_url = require('node:url');
|
||||
var node_worker_threads = require('node:worker_threads');
|
||||
var core = require('@pkgr/core');
|
||||
|
||||
var __async = (__this, __arguments, generator) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
var fulfilled = (value) => {
|
||||
try {
|
||||
step(generator.next(value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
var rejected = (value) => {
|
||||
try {
|
||||
step(generator.throw(value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
||||
step((generator = generator.apply(__this, __arguments)).next());
|
||||
});
|
||||
};
|
||||
const import_meta = {};
|
||||
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,
|
||||
SYNCKIT_EXEC_ARGV,
|
||||
SYNCKIT_TS_RUNNER,
|
||||
SYNCKIT_GLOBAL_SHIMS,
|
||||
NODE_OPTIONS
|
||||
} = process.env;
|
||||
const DEFAULT_BUFFER_SIZE = SYNCKIT_BUFFER_SIZE ? +SYNCKIT_BUFFER_SIZE : void 0;
|
||||
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;
|
||||
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();
|
||||
function extractProperties(object) {
|
||||
if (object && typeof object === "object") {
|
||||
const properties = {};
|
||||
for (const key in object) {
|
||||
properties[key] = object[key];
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
function createSyncFn(workerPath, bufferSizeOrOptions, timeout) {
|
||||
if (!path.isAbsolute(workerPath)) {
|
||||
throw new Error("`workerPath` must be absolute");
|
||||
}
|
||||
const cachedSyncFn = syncFnCache.get(workerPath);
|
||||
if (cachedSyncFn) {
|
||||
return cachedSyncFn;
|
||||
}
|
||||
const syncFn = startWorkerThread(
|
||||
workerPath,
|
||||
/* istanbul ignore next */
|
||||
typeof bufferSizeOrOptions === "number" ? { bufferSize: bufferSizeOrOptions, timeout } : bufferSizeOrOptions
|
||||
);
|
||||
syncFnCache.set(workerPath, syncFn);
|
||||
return syncFn;
|
||||
}
|
||||
const cjsRequire = typeof require === "undefined" ? node_module.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 !!((_a = fs.statSync(path2, { throwIfNoEntry: false })) == null ? void 0 : _a.isFile());
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
||||
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": {
|
||||
extensions = [".cts", ".cjs"];
|
||||
break;
|
||||
}
|
||||
case ".mjs": {
|
||||
extensions = [".mts", ".mjs"];
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
extensions = [".ts", ".js"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
const found = core.tryExtensions(workPathWithoutExt, extensions);
|
||||
let differentExt;
|
||||
if (found && (!ext || (differentExt = found !== workPathWithoutExt))) {
|
||||
workerPath = found;
|
||||
if (differentExt) {
|
||||
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 = 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) {
|
||||
if (!execArgv.includes("--loader")) {
|
||||
execArgv = ["--loader", `${TsRunner.TsNode}/esm`, ...execArgv];
|
||||
}
|
||||
} else if (!execArgv.includes("-r")) {
|
||||
execArgv = ["-r", `${TsRunner.TsNode}/register`, ...execArgv];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TsRunner.EsbuildRegister: {
|
||||
if (!execArgv.includes("-r")) {
|
||||
execArgv = ["-r", TsRunner.EsbuildRegister, ...execArgv];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TsRunner.EsbuildRunner: {
|
||||
if (!execArgv.includes("-r")) {
|
||||
execArgv = ["-r", `${TsRunner.EsbuildRunner}/register`, ...execArgv];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TsRunner.SWC: {
|
||||
if (!execArgv.includes("-r")) {
|
||||
execArgv = ["-r", `@${TsRunner.SWC}-node/register`, ...execArgv];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TsRunner.TSX: {
|
||||
if (!execArgv.includes("--loader")) {
|
||||
execArgv = ["--loader", TsRunner.TSX, ...execArgv];
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown ts runner: ${String(tsRunner)}`);
|
||||
}
|
||||
}
|
||||
} else if (!jsUseEsm) {
|
||||
const pkg = core.findUp(workerPath);
|
||||
if (pkg) {
|
||||
jsUseEsm = cjsRequire(pkg).type === "module";
|
||||
}
|
||||
}
|
||||
if (process.versions.pnp) {
|
||||
const nodeOptions = NODE_OPTIONS == null ? void 0 : NODE_OPTIONS.split(/\s+/);
|
||||
let pnpApiPath;
|
||||
try {
|
||||
pnpApiPath = cjsRequire.resolve("pnpapi");
|
||||
} catch (e) {
|
||||
}
|
||||
if (pnpApiPath && !(nodeOptions == null ? void 0 : nodeOptions.some(
|
||||
(option, index) => ["-r", "--require"].includes(option) && pnpApiPath === cjsRequire.resolve(nodeOptions[index + 1])
|
||||
)) && !execArgv.includes(pnpApiPath)) {
|
||||
execArgv = ["-r", pnpApiPath, ...execArgv];
|
||||
const pnpLoaderPath = path.resolve(pnpApiPath, "../.pnp.loader.mjs");
|
||||
if (isFile(pnpLoaderPath)) {
|
||||
const experimentalLoader = node_url.pathToFileURL(pnpLoaderPath).toString();
|
||||
execArgv = ["--experimental-loader", experimentalLoader, ...execArgv];
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
ext,
|
||||
isTs,
|
||||
jsUseEsm,
|
||||
tsRunner,
|
||||
tsUseEsm,
|
||||
workerPath,
|
||||
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)}`,
|
||||
""
|
||||
);
|
||||
const globalsCache = /* @__PURE__ */ new Map();
|
||||
let tmpdir;
|
||||
const _dirname = typeof __dirname === "undefined" ? path.dirname(node_url.fileURLToPath(import_meta.url)) : (
|
||||
/* istanbul ignore next */
|
||||
__dirname
|
||||
);
|
||||
const generateGlobals = (workerPath, globalShims, type = "import") => {
|
||||
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,
|
||||
transferList = [],
|
||||
globalShims = DEFAULT_GLOBAL_SHIMS
|
||||
} = {}) {
|
||||
const { port1: mainPort, port2: workerPort } = new node_worker_threads.MessageChannel();
|
||||
const {
|
||||
isTs,
|
||||
ext,
|
||||
jsUseEsm,
|
||||
tsUseEsm,
|
||||
tsRunner: finalTsRunner,
|
||||
workerPath: finalWorkerPath,
|
||||
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 (!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,
|
||||
.../* istanbul ignore next */
|
||||
isTsxSupported ? [] : [TsRunner.TSX]
|
||||
].includes(finalTsRunner)) {
|
||||
throw new Error(
|
||||
`${finalTsRunner} is not supported for ${ext} files yet` + /* istanbul ignore next */
|
||||
(isTsxSupported ? ", you can try [tsx](https://github.com/esbuild-kit/tsx) instead" : "")
|
||||
);
|
||||
}
|
||||
}
|
||||
const finalGlobalShims = (globalShims === true ? DEFAULT_GLOBAL_SHIMS_PRESET : Array.isArray(globalShims) ? globalShims : []).filter(({ moduleName }) => core.isPkgAvailable(moduleName));
|
||||
const useGlobals = finalGlobalShims.length > 0;
|
||||
const useEval = isTs ? !tsUseEsm : !jsUseEsm && useGlobals;
|
||||
const worker = new node_worker_threads.Worker(
|
||||
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, ...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);
|
||||
if (!["ok", "not-equal"].includes(status)) {
|
||||
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}`);
|
||||
}
|
||||
if (error) {
|
||||
throw Object.assign(error, properties);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
worker.unref();
|
||||
return syncFn;
|
||||
}
|
||||
function runAsWorker(fn) {
|
||||
if (!node_worker_threads.workerData) {
|
||||
return;
|
||||
}
|
||||
const { workerPort } = node_worker_threads.workerData;
|
||||
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);
|
||||
}))();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
36
VApp/node_modules/synckit/lib/index.d.ts
generated
vendored
Normal file
36
VApp/node_modules/synckit/lib/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
/// <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";
|
||||
readonly EsbuildRegister: "esbuild-register";
|
||||
readonly EsbuildRunner: "esbuild-runner";
|
||||
readonly SWC: "swc";
|
||||
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 | 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[];
|
||||
tsRunner?: TsRunner;
|
||||
transferList?: TransferListItem[];
|
||||
globalShims?: GlobalShim[] | boolean;
|
||||
}
|
||||
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 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;
|
343
VApp/node_modules/synckit/lib/index.js
generated
vendored
Normal file
343
VApp/node_modules/synckit/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,343 @@
|
||||
import { __awaiter } from "tslib";
|
||||
import { createHash } from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
import { createRequire } from 'node:module';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import { MessageChannel, Worker, parentPort, receiveMessageOnPort, workerData, } from 'node:worker_threads';
|
||||
import { findUp, isPkgAvailable, tryExtensions } from '@pkgr/core';
|
||||
export * from './types.js';
|
||||
export const TsRunner = {
|
||||
TsNode: 'ts-node',
|
||||
EsbuildRegister: 'esbuild-register',
|
||||
EsbuildRunner: 'esbuild-runner',
|
||||
SWC: 'swc',
|
||||
TSX: 'tsx',
|
||||
};
|
||||
const { SYNCKIT_BUFFER_SIZE, SYNCKIT_TIMEOUT, SYNCKIT_EXEC_ARGV, SYNCKIT_TS_RUNNER, SYNCKIT_GLOBAL_SHIMS, NODE_OPTIONS, } = process.env;
|
||||
export const DEFAULT_BUFFER_SIZE = SYNCKIT_BUFFER_SIZE
|
||||
? +SYNCKIT_BUFFER_SIZE
|
||||
: undefined;
|
||||
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;
|
||||
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();
|
||||
export function extractProperties(object) {
|
||||
if (object && typeof object === 'object') {
|
||||
const properties = {};
|
||||
for (const key in object) {
|
||||
properties[key] = object[key];
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
export function createSyncFn(workerPath, bufferSizeOrOptions, timeout) {
|
||||
if (!path.isAbsolute(workerPath)) {
|
||||
throw new Error('`workerPath` must be absolute');
|
||||
}
|
||||
const cachedSyncFn = syncFnCache.get(workerPath);
|
||||
if (cachedSyncFn) {
|
||||
return cachedSyncFn;
|
||||
}
|
||||
const syncFn = startWorkerThread(workerPath, typeof bufferSizeOrOptions === 'number'
|
||||
? { bufferSize: bufferSizeOrOptions, timeout }
|
||||
: bufferSizeOrOptions);
|
||||
syncFnCache.set(workerPath, syncFn);
|
||||
return syncFn;
|
||||
}
|
||||
const cjsRequire = typeof require === 'undefined'
|
||||
? createRequire(import.meta.url)
|
||||
: require;
|
||||
const dataUrl = (code) => new URL(`data:text/javascript,${encodeURIComponent(code)}`);
|
||||
export const isFile = (path) => {
|
||||
var _a;
|
||||
try {
|
||||
return !!((_a = fs.statSync(path, { throwIfNoEntry: false })) === null || _a === void 0 ? void 0 : _a.isFile());
|
||||
}
|
||||
catch (_b) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
||||
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': {
|
||||
extensions = ['.cts', '.cjs'];
|
||||
break;
|
||||
}
|
||||
case '.mjs': {
|
||||
extensions = ['.mts', '.mjs'];
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
extensions = ['.ts', '.js'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
const found = tryExtensions(workPathWithoutExt, extensions);
|
||||
let differentExt;
|
||||
if (found && (!ext || (differentExt = found !== workPathWithoutExt))) {
|
||||
workerPath = found;
|
||||
if (differentExt) {
|
||||
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 = findUp(workerPath);
|
||||
if (pkg) {
|
||||
tsUseEsm =
|
||||
cjsRequire(pkg).type ===
|
||||
'module';
|
||||
}
|
||||
}
|
||||
if (tsRunner == null && isPkgAvailable(TsRunner.TsNode)) {
|
||||
tsRunner = TsRunner.TsNode;
|
||||
}
|
||||
switch (tsRunner) {
|
||||
case TsRunner.TsNode: {
|
||||
if (tsUseEsm) {
|
||||
if (!execArgv.includes('--loader')) {
|
||||
execArgv = ['--loader', `${TsRunner.TsNode}/esm`, ...execArgv];
|
||||
}
|
||||
}
|
||||
else if (!execArgv.includes('-r')) {
|
||||
execArgv = ['-r', `${TsRunner.TsNode}/register`, ...execArgv];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TsRunner.EsbuildRegister: {
|
||||
if (!execArgv.includes('-r')) {
|
||||
execArgv = ['-r', TsRunner.EsbuildRegister, ...execArgv];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TsRunner.EsbuildRunner: {
|
||||
if (!execArgv.includes('-r')) {
|
||||
execArgv = ['-r', `${TsRunner.EsbuildRunner}/register`, ...execArgv];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TsRunner.SWC: {
|
||||
if (!execArgv.includes('-r')) {
|
||||
execArgv = ['-r', `@${TsRunner.SWC}-node/register`, ...execArgv];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TsRunner.TSX: {
|
||||
if (!execArgv.includes('--loader')) {
|
||||
execArgv = ['--loader', TsRunner.TSX, ...execArgv];
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown ts runner: ${String(tsRunner)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!jsUseEsm) {
|
||||
const pkg = findUp(workerPath);
|
||||
if (pkg) {
|
||||
jsUseEsm =
|
||||
cjsRequire(pkg).type === 'module';
|
||||
}
|
||||
}
|
||||
if (process.versions.pnp) {
|
||||
const nodeOptions = NODE_OPTIONS === null || NODE_OPTIONS === void 0 ? void 0 : NODE_OPTIONS.split(/\s+/);
|
||||
let pnpApiPath;
|
||||
try {
|
||||
pnpApiPath = cjsRequire.resolve('pnpapi');
|
||||
}
|
||||
catch (_a) { }
|
||||
if (pnpApiPath &&
|
||||
!(nodeOptions === null || nodeOptions === void 0 ? void 0 : nodeOptions.some((option, index) => ['-r', '--require'].includes(option) &&
|
||||
pnpApiPath === cjsRequire.resolve(nodeOptions[index + 1]))) &&
|
||||
!execArgv.includes(pnpApiPath)) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
ext,
|
||||
isTs,
|
||||
jsUseEsm,
|
||||
tsRunner,
|
||||
tsUseEsm,
|
||||
workerPath,
|
||||
execArgv,
|
||||
};
|
||||
};
|
||||
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)}`, '');
|
||||
const globalsCache = new Map();
|
||||
let tmpdir;
|
||||
const _dirname = typeof __dirname === 'undefined'
|
||||
? path.dirname(fileURLToPath(import.meta.url))
|
||||
: __dirname;
|
||||
export const generateGlobals = (workerPath, globalShims, type = 'import') => {
|
||||
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, { bufferSize = DEFAULT_WORKER_BUFFER_SIZE, 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, jsUseEsm, tsUseEsm, tsRunner: finalTsRunner, workerPath: finalWorkerPath, 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 (!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(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 finalGlobalShims = (globalShims === true
|
||||
? DEFAULT_GLOBAL_SHIMS_PRESET
|
||||
: Array.isArray(globalShims)
|
||||
? globalShims
|
||||
: []).filter(({ moduleName }) => isPkgAvailable(moduleName));
|
||||
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
|
||||
? `${generateGlobals(finalWorkerPath, finalGlobalShims, 'require')};${encodeImportModule(finalWorkerPath, 'require')}`
|
||||
: workerPathUrl, {
|
||||
eval: useEval,
|
||||
workerData: { workerPort },
|
||||
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);
|
||||
if (!['ok', 'not-equal'].includes(status)) {
|
||||
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}`);
|
||||
}
|
||||
if (error) {
|
||||
throw Object.assign(error, properties);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
worker.unref();
|
||||
return syncFn;
|
||||
}
|
||||
export function runAsWorker(fn) {
|
||||
if (!workerData) {
|
||||
return;
|
||||
}
|
||||
const { workerPort } = workerData;
|
||||
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);
|
||||
}))();
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
1
VApp/node_modules/synckit/lib/index.js.map
generated
vendored
Normal file
1
VApp/node_modules/synckit/lib/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
30
VApp/node_modules/synckit/lib/types.d.ts
generated
vendored
Normal file
30
VApp/node_modules/synckit/lib/types.d.ts
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
/// <reference types="node" />
|
||||
import { MessagePort } from 'node:worker_threads';
|
||||
export type AnyFn<R = any, T extends any[] = any[]> = (...args: T) => R;
|
||||
export type AnyPromise<T = any> = Promise<T>;
|
||||
export type AnyAsyncFn<T = any> = AnyFn<Promise<T>>;
|
||||
export type Syncify<T extends AnyAsyncFn> = T extends (...args: infer Args) => Promise<infer R> ? (...args: Args) => R : never;
|
||||
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 WorkerData {
|
||||
workerPort: MessagePort;
|
||||
}
|
||||
export interface DataMessage<T> {
|
||||
result?: T;
|
||||
error?: unknown;
|
||||
properties?: unknown;
|
||||
}
|
||||
export interface WorkerToMainMessage<T = unknown> extends DataMessage<T> {
|
||||
id: number;
|
||||
}
|
||||
export interface GlobalShim {
|
||||
moduleName: string;
|
||||
globalName?: string;
|
||||
named?: string | null;
|
||||
conditional?: boolean;
|
||||
}
|
2
VApp/node_modules/synckit/lib/types.js
generated
vendored
Normal file
2
VApp/node_modules/synckit/lib/types.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=types.js.map
|
1
VApp/node_modules/synckit/lib/types.js.map
generated
vendored
Normal file
1
VApp/node_modules/synckit/lib/types.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
39
VApp/node_modules/synckit/package.json
generated
vendored
Normal file
39
VApp/node_modules/synckit/package.json
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "synckit",
|
||||
"version": "0.8.8",
|
||||
"type": "module",
|
||||
"description": "Perform async work synchronously in Node.js using `worker_threads` with first-class TypeScript support.",
|
||||
"repository": "git+https://github.com/un-ts/synckit.git",
|
||||
"author": "JounQin (https://www.1stG.me) <admin@1stg.me>",
|
||||
"funding": "https://opencollective.com/unts",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^14.18.0 || >=16.0.0"
|
||||
},
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./lib/index.js",
|
||||
"exports": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"import": "./lib/index.js",
|
||||
"require": "./lib/index.cjs"
|
||||
},
|
||||
"types": "./lib/index.d.ts",
|
||||
"files": [
|
||||
"lib",
|
||||
"!**/*.tsbuildinfo"
|
||||
],
|
||||
"keywords": [
|
||||
"deasync",
|
||||
"make-synchronous",
|
||||
"sync",
|
||||
"sync-exec",
|
||||
"sync-rpc",
|
||||
"sync-threads",
|
||||
"synchronize",
|
||||
"synckit"
|
||||
],
|
||||
"dependencies": {
|
||||
"@pkgr/core": "^0.1.0",
|
||||
"tslib": "^2.6.2"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user