synckit 0.7.1 → 0.7.2
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/README.md +14 -0
- package/lib/index.cjs +11 -11
- package/lib/index.js +7 -4
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +36 -4
package/README.md
CHANGED
@@ -22,6 +22,8 @@ Perform async work synchronously in Node.js using `worker_threads` with first-cl
|
|
22
22
|
- [Envs](#envs)
|
23
23
|
- [TypeScript](#typescript)
|
24
24
|
- [Benchmark](#benchmark)
|
25
|
+
- [Sponsors](#sponsors)
|
26
|
+
- [Backers](#backers)
|
25
27
|
- [Changelog](#changelog)
|
26
28
|
- [License](#license)
|
27
29
|
|
@@ -86,6 +88,18 @@ See [benchmark.cjs](./benchmarks/benchmark.cjs.txt) and [benchmark.esm](./benchm
|
|
86
88
|
|
87
89
|
You can try it with running `yarn benchmark` by yourself. [Here](./benchmarks/benchmark.js) is the benchmark source code.
|
88
90
|
|
91
|
+
## Sponsors
|
92
|
+
|
93
|
+
| 1stG | RxTS | UnTS |
|
94
|
+
| ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
95
|
+
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
|
96
|
+
|
97
|
+
## Backers
|
98
|
+
|
99
|
+
| 1stG | RxTS | UnTS |
|
100
|
+
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
101
|
+
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
|
102
|
+
|
89
103
|
## Changelog
|
90
104
|
|
91
105
|
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
|
package/lib/index.cjs
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var
|
6
|
-
var path = require('path');
|
7
|
-
var
|
8
|
-
var
|
5
|
+
var node_module = require('node:module');
|
6
|
+
var path = require('node:path');
|
7
|
+
var node_url = require('node:url');
|
8
|
+
var node_worker_threads = require('node:worker_threads');
|
9
9
|
var utils = require('@pkgr/utils');
|
10
10
|
|
11
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
@@ -61,7 +61,7 @@ function createSyncFn(workerPath, bufferSizeOrOptions, timeout) {
|
|
61
61
|
syncFnCache.set(workerPath, syncFn);
|
62
62
|
return syncFn;
|
63
63
|
}
|
64
|
-
const cjsRequire = typeof require === "undefined" ?
|
64
|
+
const cjsRequire = typeof require === "undefined" ? node_module.createRequire(import_meta.url) : require;
|
65
65
|
const dataUrl = (code) => new URL(`data:text/javascript,${encodeURIComponent(code)}`);
|
66
66
|
const setupTsNode = (workerPath, execArgv) => {
|
67
67
|
if (!/[/\\]node_modules[/\\]/.test(workerPath)) {
|
@@ -98,14 +98,14 @@ function startWorkerThread(workerPath, {
|
|
98
98
|
timeout = DEFAULT_TIMEOUT,
|
99
99
|
execArgv = DEFAULT_EXEC_ARGV
|
100
100
|
} = {}) {
|
101
|
-
const { port1: mainPort, port2: workerPort } = new
|
101
|
+
const { port1: mainPort, port2: workerPort } = new node_worker_threads.MessageChannel();
|
102
102
|
const {
|
103
103
|
isTs,
|
104
104
|
tsUseEsm,
|
105
105
|
workerPath: finalWorkerPath,
|
106
106
|
execArgv: finalExecArgv
|
107
107
|
} = setupTsNode(workerPath, execArgv);
|
108
|
-
const worker = new
|
108
|
+
const worker = new node_worker_threads.Worker(isTs ? tsUseEsm ? dataUrl(`import '${String(node_url.pathToFileURL(finalWorkerPath))}'`) : `require('ts-node/register');require('${finalWorkerPath.replace(/\\/g, "\\\\")}')` : node_url.pathToFileURL(finalWorkerPath), {
|
109
109
|
eval: isTs && !tsUseEsm,
|
110
110
|
workerData: { workerPort },
|
111
111
|
transferList: [workerPort],
|
@@ -127,7 +127,7 @@ function startWorkerThread(workerPath, {
|
|
127
127
|
result,
|
128
128
|
error,
|
129
129
|
properties
|
130
|
-
} =
|
130
|
+
} = node_worker_threads.receiveMessageOnPort(mainPort).message;
|
131
131
|
if (id !== id2) {
|
132
132
|
throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
133
133
|
}
|
@@ -140,11 +140,11 @@ function startWorkerThread(workerPath, {
|
|
140
140
|
return syncFn;
|
141
141
|
}
|
142
142
|
function runAsWorker(fn) {
|
143
|
-
if (!
|
143
|
+
if (!node_worker_threads.workerData) {
|
144
144
|
return;
|
145
145
|
}
|
146
|
-
const { workerPort } =
|
147
|
-
|
146
|
+
const { workerPort } = node_worker_threads.workerData;
|
147
|
+
node_worker_threads.parentPort.on("message", ({ sharedBuffer, id, args }) => {
|
148
148
|
(() => __async(this, null, function* () {
|
149
149
|
const sharedBufferView = new Int32Array(sharedBuffer);
|
150
150
|
let msg;
|
package/lib/index.js
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
var _a;
|
2
2
|
import { __awaiter } from "tslib";
|
3
|
-
import { createRequire } from 'module';
|
4
|
-
import path from 'path';
|
5
|
-
import { pathToFileURL } from 'url';
|
6
|
-
import { MessageChannel, Worker, receiveMessageOnPort,
|
3
|
+
import { createRequire } from 'node:module';
|
4
|
+
import path from 'node:path';
|
5
|
+
import { pathToFileURL } from 'node:url';
|
6
|
+
import { MessageChannel, Worker, receiveMessageOnPort,
|
7
|
+
// type-coverage:ignore-next-line -- we can't control
|
8
|
+
workerData, parentPort, } from 'node:worker_threads';
|
7
9
|
import { findUp, tryExtensions } from '@pkgr/utils';
|
8
10
|
export * from './types.js';
|
9
11
|
const { SYNCKIT_BUFFER_SIZE, SYNCKIT_TIMEOUT, SYNCKIT_EXEC_ARV } = process.env;
|
@@ -122,6 +124,7 @@ function startWorkerThread(workerPath, { bufferSize = DEFAULT_WORKER_BUFFER_SIZE
|
|
122
124
|
}
|
123
125
|
/* istanbul ignore next */
|
124
126
|
export function runAsWorker(fn) {
|
127
|
+
// type-coverage:ignore-next-line -- we can't control
|
125
128
|
if (!workerData) {
|
126
129
|
return;
|
127
130
|
}
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EACL,cAAc,EACd,MAAM,EACN,oBAAoB;AACpB,qDAAqD;AACrD,UAAU,EACV,UAAU,GACX,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAWnD,cAAc,YAAY,CAAA;AAE1B,MAAM,EAAE,mBAAmB,EAAE,eAAe,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;AAE9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB;IACpD,CAAC,CAAC,CAAC,mBAAmB;IACtB,CAAC,CAAC,SAAS,CAAA;AAEb,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAA;AAE7E,MAAM,CAAC,MAAM,0BAA0B,GAAG,mBAAmB,IAAI,IAAI,CAAA;AAErE,0BAA0B;AAC1B,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,KAAK,CAAC,GAAG,CAAC,mCAAI,EAAE,CAAA;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G;oBACJ,EAAE;oBACF,KAAK;oBACL,UAAU,EAAE,iBAAiB,CAAC,KAAK,CAAC;iBACrC,CAAA;aACF;YACD,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;YAC3B,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;YACnC,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAA;QACrC,CAAC,CAAA,CAAC,EAAE,CAAA;IACN,CAAC,CACF,CAAA;AACH,CAAC"}
|
package/lib/types.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
-
import { MessagePort } from 'worker_threads';
|
2
|
+
import { MessagePort } from 'node:worker_threads';
|
3
3
|
export declare type AnyFn<R = any, T extends any[] = any[]> = (...args: T) => R;
|
4
4
|
export declare type AnyPromise<T = any> = Promise<T>;
|
5
5
|
export declare type AnyAsyncFn<T = any> = AnyFn<Promise<T>>;
|
package/package.json
CHANGED
@@ -1,13 +1,45 @@
|
|
1
1
|
{
|
2
2
|
"name": "synckit",
|
3
|
-
"version": "0.7.
|
3
|
+
"version": "0.7.2",
|
4
4
|
"type": "module",
|
5
5
|
"description": "Perform async work synchronously in Node.js using `worker_threads`, or `child_process` as fallback, with first-class TypeScript support.",
|
6
6
|
"repository": "git+https://github.com/rx-ts/synckit.git",
|
7
|
-
"author": "JounQin <admin@1stg.me>",
|
7
|
+
"author": "JounQin (https://www.1stG.me) <admin@1stg.me>",
|
8
|
+
"donate": {
|
9
|
+
"recipients": [
|
10
|
+
{
|
11
|
+
"name": "unts",
|
12
|
+
"platform": "opencollective",
|
13
|
+
"address": "https://opencollective.com/unts",
|
14
|
+
"weight": 60
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"name": "rxts",
|
18
|
+
"platform": "opencollective",
|
19
|
+
"address": "https://opencollective.com/rxts",
|
20
|
+
"weight": 20
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"name": "1stG",
|
24
|
+
"email": "i@1stg.me",
|
25
|
+
"weight": 20,
|
26
|
+
"platforms": [
|
27
|
+
{
|
28
|
+
"platform": "opencollective",
|
29
|
+
"address": "https://opencollective.com/1stG"
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"platform": "patreon",
|
33
|
+
"address": "https://www.patreon.com/1stG"
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}
|
37
|
+
]
|
38
|
+
},
|
39
|
+
"funding": "https://opencollective.com/unts",
|
8
40
|
"license": "MIT",
|
9
41
|
"engines": {
|
10
|
-
"node": "
|
42
|
+
"node": "^12.20.0 || ^14.18.0 || >=16.0.0"
|
11
43
|
},
|
12
44
|
"main": "./lib/index.cjs",
|
13
45
|
"module": "./lib/index.js",
|
@@ -32,7 +64,7 @@
|
|
32
64
|
"synckit"
|
33
65
|
],
|
34
66
|
"dependencies": {
|
35
|
-
"@pkgr/utils": "^2.
|
67
|
+
"@pkgr/utils": "^2.2.0",
|
36
68
|
"tslib": "^2.4.0"
|
37
69
|
}
|
38
70
|
}
|