synckit 0.8.0 → 0.8.3
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 +25 -6
- package/lib/index.cjs +79 -28
- package/lib/index.d.ts +3 -0
- package/lib/index.js +96 -35
- package/lib/index.js.map +1 -1
- package/package.json +89 -2
package/README.md
CHANGED
@@ -19,11 +19,13 @@ Perform async work synchronously in Node.js using `worker_threads` with first-cl
|
|
19
19
|
- [Usage](#usage)
|
20
20
|
- [Install](#install)
|
21
21
|
- [API](#api)
|
22
|
+
- [Options](#options)
|
22
23
|
- [Envs](#envs)
|
23
24
|
- [TypeScript](#typescript)
|
24
25
|
- [`ts-node`](#ts-node)
|
25
26
|
- [`esbuild-register`](#esbuild-register)
|
26
27
|
- [`esbuild-runner`](#esbuild-runner)
|
28
|
+
- [`swc`](#swc)
|
27
29
|
- [`tsx`](#tsx)
|
28
30
|
- [Benchmark](#benchmark)
|
29
31
|
- [Sponsors](#sponsors)
|
@@ -50,7 +52,9 @@ npm i synckit
|
|
50
52
|
import { createSyncFn } from 'synckit'
|
51
53
|
|
52
54
|
// the worker path must be absolute
|
53
|
-
const syncFn = createSyncFn(require.resolve('./worker')
|
55
|
+
const syncFn = createSyncFn(require.resolve('./worker'), {
|
56
|
+
tsRunner: 'tsx', // optional, can be `'ts-node' | 'esbuild-register' | 'esbuild-runner' | 'tsx'`
|
57
|
+
})
|
54
58
|
|
55
59
|
// do whatever you want, you will get the result synchronously!
|
56
60
|
const result = syncFn(...args)
|
@@ -68,12 +72,19 @@ runAsWorker(async (...args) => {
|
|
68
72
|
|
69
73
|
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)
|
70
74
|
|
75
|
+
### Options
|
76
|
+
|
77
|
+
1. `bufferSize` same as env `SYNCKIT_BUFFER_SIZE`
|
78
|
+
2. `timeout` same as env `SYNCKIT_TIMEOUT`
|
79
|
+
3. `execArgv` same as env `SYNCKIT_EXEC_ARGV`
|
80
|
+
4. `tsRunner` same as env `SYNCKIT_TS_RUNNER`
|
81
|
+
|
71
82
|
### Envs
|
72
83
|
|
73
84
|
1. `SYNCKIT_BUFFER_SIZE`: `bufferSize` to create `SharedArrayBuffer` for `worker_threads` (default as `1024`)
|
74
85
|
2. `SYNCKIT_TIMEOUT`: `timeout` for performing the async job (no default)
|
75
86
|
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)
|
76
|
-
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' | 'tsx'`, `'ts-node'` is used by default, make sure you have installed them already
|
87
|
+
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
|
77
88
|
|
78
89
|
### TypeScript
|
79
90
|
|
@@ -87,15 +98,19 @@ If you want to integrate with [tsconfig-paths](https://www.npmjs.com/package/tsc
|
|
87
98
|
|
88
99
|
#### `esbuild-register`
|
89
100
|
|
90
|
-
Please view
|
101
|
+
Please view [`esbuild-register`][] for its document
|
91
102
|
|
92
103
|
#### `esbuild-runner`
|
93
104
|
|
94
|
-
Please view
|
105
|
+
Please view [`esbuild-runner`][] for its document
|
106
|
+
|
107
|
+
#### `swc`
|
108
|
+
|
109
|
+
Please view [`@swc-node/register`][] for its document
|
95
110
|
|
96
111
|
#### `tsx`
|
97
112
|
|
98
|
-
Please view
|
113
|
+
Please view [`tsx`][] for its document
|
99
114
|
|
100
115
|
## Benchmark
|
101
116
|
|
@@ -117,7 +132,7 @@ You can try it with running `yarn benchmark` by yourself. [Here](./benchmarks/be
|
|
117
132
|
|
118
133
|
| 1stG | RxTS | UnTS |
|
119
134
|
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
120
|
-
| [](https://opencollective.com/1stG) | [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
|
121
136
|
|
122
137
|
## Changelog
|
123
138
|
|
@@ -127,6 +142,10 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m
|
|
127
142
|
|
128
143
|
[MIT][] © [JounQin][]@[1stG.me][]
|
129
144
|
|
145
|
+
[`esbuild-register`]: https://github.com/egoist/esbuild-register
|
146
|
+
[`esbuild-runner`]: https://github.com/folke/esbuild-runner
|
147
|
+
[`@swc-node/register`]: https://github.com/swc-project/swc-node/tree/master/packages/register
|
148
|
+
[`tsx`]: https://github.com/esbuild-kit/tsx
|
130
149
|
[1stg.me]: https://www.1stg.me
|
131
150
|
[jounqin]: https://GitHub.com/JounQin
|
132
151
|
[mit]: http://opensource.org/licenses/MIT
|
package/lib/index.cjs
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
+
var fs = require('node:fs');
|
5
6
|
var node_module = require('node:module');
|
6
7
|
var path = require('node:path');
|
7
8
|
var node_url = require('node:url');
|
@@ -10,6 +11,7 @@ var utils = require('@pkgr/utils');
|
|
10
11
|
|
11
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
12
13
|
|
14
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
13
15
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
14
16
|
|
15
17
|
var __async = (__this, __arguments, generator) => {
|
@@ -37,19 +39,22 @@ const TsRunner = {
|
|
37
39
|
TsNode: "ts-node",
|
38
40
|
EsbuildRegister: "esbuild-register",
|
39
41
|
EsbuildRunner: "esbuild-runner",
|
42
|
+
SWC: "swc",
|
40
43
|
TSX: "tsx"
|
41
44
|
};
|
42
45
|
const {
|
43
46
|
SYNCKIT_BUFFER_SIZE,
|
44
47
|
SYNCKIT_TIMEOUT,
|
45
|
-
|
46
|
-
SYNCKIT_TS_RUNNER
|
48
|
+
SYNCKIT_EXEC_ARGV,
|
49
|
+
SYNCKIT_TS_RUNNER,
|
50
|
+
NODE_OPTIONS
|
47
51
|
} = process.env;
|
48
52
|
const DEFAULT_BUFFER_SIZE = SYNCKIT_BUFFER_SIZE ? +SYNCKIT_BUFFER_SIZE : void 0;
|
49
53
|
const DEFAULT_TIMEOUT = SYNCKIT_TIMEOUT ? +SYNCKIT_TIMEOUT : void 0;
|
50
54
|
const DEFAULT_WORKER_BUFFER_SIZE = DEFAULT_BUFFER_SIZE || 1024;
|
51
|
-
const DEFAULT_EXEC_ARGV = (
|
55
|
+
const DEFAULT_EXEC_ARGV = (SYNCKIT_EXEC_ARGV == null ? void 0 : SYNCKIT_EXEC_ARGV.split(",")) || [];
|
52
56
|
const DEFAULT_TS_RUNNER = SYNCKIT_TS_RUNNER || TsRunner.TsNode;
|
57
|
+
const MTS_SUPPORTED_NODE_VERSION = 16;
|
53
58
|
const syncFnCache = /* @__PURE__ */ new Map();
|
54
59
|
const extractProperties = (object) => {
|
55
60
|
if (object && typeof object === "object") {
|
@@ -74,8 +79,15 @@ function createSyncFn(workerPath, bufferSizeOrOptions, timeout) {
|
|
74
79
|
}
|
75
80
|
const cjsRequire = typeof require === "undefined" ? node_module.createRequire(import_meta.url) : require;
|
76
81
|
const dataUrl = (code) => new URL(`data:text/javascript,${encodeURIComponent(code)}`);
|
82
|
+
const isFile = (path2) => {
|
83
|
+
try {
|
84
|
+
return fs__default["default"].statSync(path2).isFile();
|
85
|
+
} catch (e) {
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
};
|
77
89
|
const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
78
|
-
|
90
|
+
let ext = path__default["default"].extname(workerPath);
|
79
91
|
if (!/[/\\]node_modules[/\\]/.test(workerPath) && (!ext || /^\.[cm]?js$/.test(ext))) {
|
80
92
|
const workPathWithoutExt = ext ? workerPath.slice(0, -ext.length) : workerPath;
|
81
93
|
let extensions;
|
@@ -91,8 +103,12 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|
91
103
|
break;
|
92
104
|
}
|
93
105
|
const found = utils.tryExtensions(workPathWithoutExt, extensions);
|
94
|
-
|
106
|
+
let differentExt;
|
107
|
+
if (found && (!ext || (differentExt = found !== workPathWithoutExt))) {
|
95
108
|
workerPath = found;
|
109
|
+
if (differentExt) {
|
110
|
+
ext = path__default["default"].extname(workerPath);
|
111
|
+
}
|
96
112
|
}
|
97
113
|
}
|
98
114
|
const isTs = /\.[cm]?ts$/.test(workerPath);
|
@@ -127,6 +143,12 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|
127
143
|
}
|
128
144
|
break;
|
129
145
|
}
|
146
|
+
case TsRunner.SWC: {
|
147
|
+
if (!execArgv.includes("-r")) {
|
148
|
+
execArgv = ["-r", `@${TsRunner.SWC}-node/register`, ...execArgv];
|
149
|
+
}
|
150
|
+
break;
|
151
|
+
}
|
130
152
|
case TsRunner.TSX: {
|
131
153
|
if (!execArgv.includes("--loader")) {
|
132
154
|
execArgv = ["--loader", TsRunner.TSX, ...execArgv];
|
@@ -138,6 +160,17 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|
138
160
|
}
|
139
161
|
}
|
140
162
|
}
|
163
|
+
if (process.versions.pnp) {
|
164
|
+
const nodeOptions = NODE_OPTIONS == null ? void 0 : NODE_OPTIONS.split(/\s+/);
|
165
|
+
const pnpApiPath = cjsRequire.resolve("pnpapi");
|
166
|
+
if (!(nodeOptions == null ? void 0 : nodeOptions.some((option, index) => ["-r", "--require"].includes(option) && pnpApiPath === cjsRequire.resolve(nodeOptions[index + 1]))) && !execArgv.includes(pnpApiPath)) {
|
167
|
+
execArgv = ["-r", pnpApiPath, ...execArgv];
|
168
|
+
const pnpLoaderPath = path__default["default"].resolve(pnpApiPath, "../.pnp.loader.mjs");
|
169
|
+
if (isFile(pnpLoaderPath)) {
|
170
|
+
execArgv = ["--experimental-loader", pnpLoaderPath, ...execArgv];
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
141
174
|
return {
|
142
175
|
ext,
|
143
176
|
isTs,
|
@@ -154,21 +187,27 @@ function startWorkerThread(workerPath, {
|
|
154
187
|
} = {}) {
|
155
188
|
const { port1: mainPort, port2: workerPort } = new node_worker_threads.MessageChannel();
|
156
189
|
const {
|
190
|
+
isTs,
|
157
191
|
ext,
|
158
192
|
tsUseEsm,
|
159
193
|
workerPath: finalWorkerPath,
|
160
194
|
execArgv: finalExecArgv
|
161
195
|
} = setupTsRunner(workerPath, { execArgv, tsRunner });
|
162
196
|
const workerPathUrl = node_url.pathToFileURL(finalWorkerPath);
|
163
|
-
if (/\.[cm]ts$/.test(finalWorkerPath)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
197
|
+
if (/\.[cm]ts$/.test(finalWorkerPath)) {
|
198
|
+
const isTsxSupported = !tsUseEsm || Number.parseFloat(process.versions.node) >= MTS_SUPPORTED_NODE_VERSION;
|
199
|
+
if ([
|
200
|
+
TsRunner.EsbuildRegister,
|
201
|
+
TsRunner.EsbuildRunner,
|
202
|
+
TsRunner.SWC,
|
203
|
+
...isTsxSupported ? [] : [TsRunner.TSX]
|
204
|
+
].includes(tsRunner)) {
|
205
|
+
throw new Error(`${tsRunner} is not supported for ${ext} files yet` + (isTsxSupported ? ", you can try [tsx](https://github.com/esbuild-kit/tsx) instead" : ""));
|
206
|
+
}
|
168
207
|
}
|
169
|
-
const
|
170
|
-
|
171
|
-
|
208
|
+
const useEval = isTs && !tsUseEsm;
|
209
|
+
const worker = new node_worker_threads.Worker(tsUseEsm && tsRunner === TsRunner.TsNode ? dataUrl(`import '${String(workerPathUrl)}'`) : useEval ? `require('${finalWorkerPath.replace(/\\/g, "\\\\")}')` : workerPathUrl, {
|
210
|
+
eval: useEval,
|
172
211
|
workerData: { workerPort },
|
173
212
|
transferList: [workerPort],
|
174
213
|
execArgv: finalExecArgv
|
@@ -206,24 +245,34 @@ function runAsWorker(fn) {
|
|
206
245
|
return;
|
207
246
|
}
|
208
247
|
const { workerPort } = node_worker_threads.workerData;
|
209
|
-
|
210
|
-
((
|
248
|
+
try {
|
249
|
+
node_worker_threads.parentPort.on("message", ({ sharedBuffer, id, args }) => {
|
250
|
+
;
|
251
|
+
(() => __async(this, null, function* () {
|
252
|
+
const sharedBufferView = new Int32Array(sharedBuffer);
|
253
|
+
let msg;
|
254
|
+
try {
|
255
|
+
msg = { id, result: yield fn(...args) };
|
256
|
+
} catch (error) {
|
257
|
+
msg = { id, error, properties: extractProperties(error) };
|
258
|
+
}
|
259
|
+
workerPort.postMessage(msg);
|
260
|
+
Atomics.add(sharedBufferView, 0, 1);
|
261
|
+
Atomics.notify(sharedBufferView, 0);
|
262
|
+
}))();
|
263
|
+
});
|
264
|
+
} catch (error) {
|
265
|
+
node_worker_threads.parentPort.on("message", ({ sharedBuffer, id }) => {
|
211
266
|
const sharedBufferView = new Int32Array(sharedBuffer);
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
id,
|
218
|
-
error,
|
219
|
-
properties: extractProperties(error)
|
220
|
-
};
|
221
|
-
}
|
222
|
-
workerPort.postMessage(msg);
|
267
|
+
workerPort.postMessage({
|
268
|
+
id,
|
269
|
+
error,
|
270
|
+
properties: extractProperties(error)
|
271
|
+
});
|
223
272
|
Atomics.add(sharedBufferView, 0, 1);
|
224
273
|
Atomics.notify(sharedBufferView, 0);
|
225
|
-
})
|
226
|
-
}
|
274
|
+
});
|
275
|
+
}
|
227
276
|
}
|
228
277
|
|
229
278
|
exports.DEFAULT_BUFFER_SIZE = DEFAULT_BUFFER_SIZE;
|
@@ -231,7 +280,9 @@ exports.DEFAULT_EXEC_ARGV = DEFAULT_EXEC_ARGV;
|
|
231
280
|
exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
|
232
281
|
exports.DEFAULT_TS_RUNNER = DEFAULT_TS_RUNNER;
|
233
282
|
exports.DEFAULT_WORKER_BUFFER_SIZE = DEFAULT_WORKER_BUFFER_SIZE;
|
283
|
+
exports.MTS_SUPPORTED_NODE_VERSION = MTS_SUPPORTED_NODE_VERSION;
|
234
284
|
exports.TsRunner = TsRunner;
|
235
285
|
exports.createSyncFn = createSyncFn;
|
236
286
|
exports.extractProperties = extractProperties;
|
287
|
+
exports.isFile = isFile;
|
237
288
|
exports.runAsWorker = runAsWorker;
|
package/lib/index.d.ts
CHANGED
@@ -4,6 +4,7 @@ export declare const TsRunner: {
|
|
4
4
|
readonly TsNode: "ts-node";
|
5
5
|
readonly EsbuildRegister: "esbuild-register";
|
6
6
|
readonly EsbuildRunner: "esbuild-runner";
|
7
|
+
readonly SWC: "swc";
|
7
8
|
readonly TSX: "tsx";
|
8
9
|
};
|
9
10
|
export declare type TsRunner = ValueOf<typeof TsRunner>;
|
@@ -12,6 +13,7 @@ export declare const DEFAULT_TIMEOUT: number | undefined;
|
|
12
13
|
export declare const DEFAULT_WORKER_BUFFER_SIZE: number;
|
13
14
|
export declare const DEFAULT_EXEC_ARGV: string[];
|
14
15
|
export declare const DEFAULT_TS_RUNNER: TsRunner;
|
16
|
+
export declare const MTS_SUPPORTED_NODE_VERSION = 16;
|
15
17
|
export interface SynckitOptions {
|
16
18
|
bufferSize?: number;
|
17
19
|
timeout?: number;
|
@@ -21,4 +23,5 @@ export interface SynckitOptions {
|
|
21
23
|
export declare const extractProperties: <T>(object?: T | undefined) => T | undefined;
|
22
24
|
export declare function createSyncFn<T extends AnyAsyncFn>(workerPath: string, bufferSize?: number, timeout?: number): Syncify<T>;
|
23
25
|
export declare function createSyncFn<T extends AnyAsyncFn>(workerPath: string, options?: SynckitOptions): Syncify<T>;
|
26
|
+
export declare const isFile: (path: string) => boolean;
|
24
27
|
export declare function runAsWorker<R = unknown, T extends AnyAsyncFn<R> = AnyAsyncFn<R>>(fn: T): void;
|
package/lib/index.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { __awaiter } from "tslib";
|
2
|
+
import fs from 'node:fs';
|
2
3
|
import { createRequire } from 'node:module';
|
3
4
|
import path from 'node:path';
|
4
5
|
import { pathToFileURL } from 'node:url';
|
@@ -14,19 +15,22 @@ export const TsRunner = {
|
|
14
15
|
EsbuildRegister: 'esbuild-register',
|
15
16
|
// https://github.com/folke/esbuild-runner
|
16
17
|
EsbuildRunner: 'esbuild-runner',
|
18
|
+
// https://github.com/swc-project/swc-node/tree/master/packages/register
|
19
|
+
SWC: 'swc',
|
17
20
|
// https://github.com/esbuild-kit/tsx
|
18
21
|
TSX: 'tsx',
|
19
22
|
};
|
20
|
-
const { SYNCKIT_BUFFER_SIZE, SYNCKIT_TIMEOUT,
|
23
|
+
const { SYNCKIT_BUFFER_SIZE, SYNCKIT_TIMEOUT, SYNCKIT_EXEC_ARGV, SYNCKIT_TS_RUNNER, NODE_OPTIONS, } = process.env;
|
21
24
|
export const DEFAULT_BUFFER_SIZE = SYNCKIT_BUFFER_SIZE
|
22
25
|
? +SYNCKIT_BUFFER_SIZE
|
23
26
|
: undefined;
|
24
27
|
export const DEFAULT_TIMEOUT = SYNCKIT_TIMEOUT ? +SYNCKIT_TIMEOUT : undefined;
|
25
28
|
export const DEFAULT_WORKER_BUFFER_SIZE = DEFAULT_BUFFER_SIZE || 1024;
|
26
29
|
/* istanbul ignore next */
|
27
|
-
export const DEFAULT_EXEC_ARGV = (
|
30
|
+
export const DEFAULT_EXEC_ARGV = (SYNCKIT_EXEC_ARGV === null || SYNCKIT_EXEC_ARGV === void 0 ? void 0 : SYNCKIT_EXEC_ARGV.split(',')) || [];
|
28
31
|
export const DEFAULT_TS_RUNNER = (SYNCKIT_TS_RUNNER ||
|
29
32
|
TsRunner.TsNode);
|
33
|
+
export const MTS_SUPPORTED_NODE_VERSION = 16;
|
30
34
|
const syncFnCache = new Map();
|
31
35
|
// MessagePort doesn't copy the properties of Error objects. We still want
|
32
36
|
// error objects to have extra properties such as "warnings" so implement the
|
@@ -59,8 +63,16 @@ const cjsRequire = typeof require === 'undefined'
|
|
59
63
|
? createRequire(import.meta.url)
|
60
64
|
: /* istanbul ignore next */ require;
|
61
65
|
const dataUrl = (code) => new URL(`data:text/javascript,${encodeURIComponent(code)}`);
|
66
|
+
export const isFile = (path) => {
|
67
|
+
try {
|
68
|
+
return fs.statSync(path).isFile();
|
69
|
+
}
|
70
|
+
catch (_a) {
|
71
|
+
return false;
|
72
|
+
}
|
73
|
+
};
|
62
74
|
const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
63
|
-
|
75
|
+
let ext = path.extname(workerPath);
|
64
76
|
if (!/[/\\]node_modules[/\\]/.test(workerPath) &&
|
65
77
|
(!ext || /^\.[cm]?js$/.test(ext))) {
|
66
78
|
const workPathWithoutExt = ext
|
@@ -79,8 +91,12 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|
79
91
|
break;
|
80
92
|
}
|
81
93
|
const found = tryExtensions(workPathWithoutExt, extensions);
|
82
|
-
|
94
|
+
let differentExt;
|
95
|
+
if (found && (!ext || (differentExt = found !== workPathWithoutExt))) {
|
83
96
|
workerPath = found;
|
97
|
+
if (differentExt) {
|
98
|
+
ext = path.extname(workerPath);
|
99
|
+
}
|
84
100
|
}
|
85
101
|
}
|
86
102
|
const isTs = /\.[cm]?ts$/.test(workerPath);
|
@@ -118,6 +134,12 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|
118
134
|
}
|
119
135
|
break;
|
120
136
|
}
|
137
|
+
case TsRunner.SWC: {
|
138
|
+
if (!execArgv.includes('-r')) {
|
139
|
+
execArgv = ['-r', `@${TsRunner.SWC}-node/register`, ...execArgv];
|
140
|
+
}
|
141
|
+
break;
|
142
|
+
}
|
121
143
|
case TsRunner.TSX: {
|
122
144
|
if (!execArgv.includes('--loader')) {
|
123
145
|
execArgv = ['--loader', TsRunner.TSX, ...execArgv];
|
@@ -129,6 +151,20 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|
129
151
|
}
|
130
152
|
}
|
131
153
|
}
|
154
|
+
/* istanbul ignore if -- https://github.com/facebook/jest/issues/5274 */
|
155
|
+
if (process.versions.pnp) {
|
156
|
+
const nodeOptions = NODE_OPTIONS === null || NODE_OPTIONS === void 0 ? void 0 : NODE_OPTIONS.split(/\s+/);
|
157
|
+
const pnpApiPath = cjsRequire.resolve('pnpapi');
|
158
|
+
if (!(nodeOptions === null || nodeOptions === void 0 ? void 0 : nodeOptions.some((option, index) => ['-r', '--require'].includes(option) &&
|
159
|
+
pnpApiPath === cjsRequire.resolve(nodeOptions[index + 1]))) &&
|
160
|
+
!execArgv.includes(pnpApiPath)) {
|
161
|
+
execArgv = ['-r', pnpApiPath, ...execArgv];
|
162
|
+
const pnpLoaderPath = path.resolve(pnpApiPath, '../.pnp.loader.mjs');
|
163
|
+
if (isFile(pnpLoaderPath)) {
|
164
|
+
execArgv = ['--experimental-loader', pnpLoaderPath, ...execArgv];
|
165
|
+
}
|
166
|
+
}
|
167
|
+
}
|
132
168
|
return {
|
133
169
|
ext,
|
134
170
|
isTs,
|
@@ -137,29 +173,37 @@ const setupTsRunner = (workerPath, { execArgv, tsRunner }) => {
|
|
137
173
|
execArgv,
|
138
174
|
};
|
139
175
|
};
|
176
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
140
177
|
function startWorkerThread(workerPath, { bufferSize = DEFAULT_WORKER_BUFFER_SIZE, timeout = DEFAULT_TIMEOUT, execArgv = DEFAULT_EXEC_ARGV, tsRunner = DEFAULT_TS_RUNNER, } = {}) {
|
141
178
|
const { port1: mainPort, port2: workerPort } = new MessageChannel();
|
142
|
-
const { ext, tsUseEsm, workerPath: finalWorkerPath, execArgv: finalExecArgv, } = setupTsRunner(workerPath, { execArgv, tsRunner });
|
179
|
+
const { isTs, ext, tsUseEsm, workerPath: finalWorkerPath, execArgv: finalExecArgv, } = setupTsRunner(workerPath, { execArgv, tsRunner });
|
143
180
|
const workerPathUrl = pathToFileURL(finalWorkerPath);
|
144
|
-
if (/\.[cm]ts$/.test(finalWorkerPath)
|
145
|
-
|
181
|
+
if (/\.[cm]ts$/.test(finalWorkerPath)) {
|
182
|
+
const isTsxSupported = !tsUseEsm ||
|
183
|
+
Number.parseFloat(process.versions.node) >= MTS_SUPPORTED_NODE_VERSION;
|
184
|
+
/* istanbul ignore if */
|
185
|
+
if ([
|
146
186
|
// https://github.com/egoist/esbuild-register/issues/79
|
147
187
|
TsRunner.EsbuildRegister,
|
148
188
|
// https://github.com/folke/esbuild-runner/issues/67
|
149
189
|
TsRunner.EsbuildRunner,
|
190
|
+
// https://github.com/swc-project/swc-node/issues/667
|
191
|
+
TsRunner.SWC,
|
192
|
+
... /* istanbul ignore next */(isTsxSupported ? [] : [TsRunner.TSX]),
|
150
193
|
].includes(tsRunner)) {
|
151
|
-
|
194
|
+
throw new Error(`${tsRunner} is not supported for ${ext} files yet` +
|
195
|
+
(isTsxSupported
|
196
|
+
? ', you can try [tsx](https://github.com/esbuild-kit/tsx) instead'
|
197
|
+
: ''));
|
198
|
+
}
|
152
199
|
}
|
153
|
-
const
|
154
|
-
|
155
|
-
TsRunner.TsNode,
|
156
|
-
// https://github.com/egoist/esbuild-register/issues/79
|
157
|
-
// TsRunner.EsbuildRegister,
|
158
|
-
// https://github.com/folke/esbuild-runner/issues/67
|
159
|
-
// TsRunner.EsbuildRunner
|
160
|
-
].includes(tsRunner)
|
200
|
+
const useEval = isTs && !tsUseEsm;
|
201
|
+
const worker = new Worker(tsUseEsm && tsRunner === TsRunner.TsNode
|
161
202
|
? dataUrl(`import '${String(workerPathUrl)}'`)
|
162
|
-
:
|
203
|
+
: useEval
|
204
|
+
? `require('${finalWorkerPath.replace(/\\/g, '\\\\')}')`
|
205
|
+
: workerPathUrl, {
|
206
|
+
eval: useEval,
|
163
207
|
workerData: { workerPort },
|
164
208
|
transferList: [workerPort],
|
165
209
|
execArgv: finalExecArgv,
|
@@ -197,26 +241,43 @@ export function runAsWorker(fn) {
|
|
197
241
|
return;
|
198
242
|
}
|
199
243
|
const { workerPort } = workerData;
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
244
|
+
try {
|
245
|
+
parentPort.on('message', ({ sharedBuffer, id, args }) => {
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
247
|
+
;
|
248
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
249
|
+
const sharedBufferView = new Int32Array(sharedBuffer);
|
250
|
+
let msg;
|
251
|
+
try {
|
252
|
+
msg = { id, result: yield fn(...args) };
|
253
|
+
}
|
254
|
+
catch (error) {
|
255
|
+
msg = { id, error, properties: extractProperties(error) };
|
256
|
+
}
|
257
|
+
workerPort.postMessage(msg);
|
258
|
+
Atomics.add(sharedBufferView, 0, 1);
|
259
|
+
Atomics.notify(sharedBufferView, 0);
|
260
|
+
}))();
|
261
|
+
});
|
262
|
+
/**
|
263
|
+
* @see https://github.com/un-ts/synckit/issues/94
|
264
|
+
*
|
265
|
+
* Starting the worker can fail, due to syntax error, for example. In that case
|
266
|
+
* we just fail all incoming messages with whatever error message we got.
|
267
|
+
* Otherwise incoming messages will hang forever waiting for a reply.
|
268
|
+
*/
|
269
|
+
}
|
270
|
+
catch (error) {
|
271
|
+
parentPort.on('message', ({ sharedBuffer, id }) => {
|
204
272
|
const sharedBufferView = new Int32Array(sharedBuffer);
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
msg = {
|
211
|
-
id,
|
212
|
-
error,
|
213
|
-
properties: extractProperties(error),
|
214
|
-
};
|
215
|
-
}
|
216
|
-
workerPort.postMessage(msg);
|
273
|
+
workerPort.postMessage({
|
274
|
+
id,
|
275
|
+
error,
|
276
|
+
properties: extractProperties(error),
|
277
|
+
});
|
217
278
|
Atomics.add(sharedBufferView, 0, 1);
|
218
279
|
Atomics.notify(sharedBufferView, 0);
|
219
|
-
})
|
220
|
-
}
|
280
|
+
});
|
281
|
+
}
|
221
282
|
}
|
222
283
|
//# sourceMappingURL=index.js.map
|
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,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;AAYnD,cAAc,YAAY,CAAA;AAE1B,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,wCAAwC;IACxC,MAAM,EAAE,SAAS;IACjB,6CAA6C;IAC7C,eAAe,EAAE,kBAAkB;IACnC,0CAA0C;IAC1C,aAAa,EAAE,gBAAgB;IAC/B,qCAAqC;IACrC,GAAG,EAAE,KAAK;CACF,CAAA;AAIV,MAAM,EACJ,mBAAmB,EACnB,eAAe,EACf,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,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;AAYnD,cAAc,YAAY,CAAA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C,gBAAgB,EAAE,CAAC,CAAC,CAAA;YACrC,CAAC,CAAA,CAAC,EAAE,CAAA;QACN,CAAC,CACF,CAAA;QAED;;;;;;WAMG;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,UAAW,CAAC,EAAE,CACZ,SAAS,EACT,CAAC,EAAE,YAAY,EAAE,EAAE,EAAsC,EAAE,EAAE;YAC3D,MAAM,gBAAgB,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,CAAA;YACrD,UAAU,CAAC,WAAW,CAAC;gBACrB,EAAE;gBACF,KAAK;gBACL,UAAU,EAAE,iBAAiB,CAAC,KAAK,CAAC;aACrC,CAAC,CAAA;YACF,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;YACnC,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAA;QACrC,CAAC,CACF,CAAA;KACF;AACH,CAAC"}
|
package/package.json
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "synckit",
|
3
|
-
"version": "0.8.
|
3
|
+
"version": "0.8.3",
|
4
4
|
"type": "module",
|
5
5
|
"description": "Perform async work synchronously in Node.js using `worker_threads` with first-class TypeScript support.",
|
6
|
-
"repository": "git+https://github.com/
|
6
|
+
"repository": "git+https://github.com/un-ts/synckit.git",
|
7
7
|
"author": "JounQin (https://www.1stG.me) <admin@1stg.me>",
|
8
8
|
"donate": {
|
9
9
|
"recipients": [
|
@@ -38,6 +38,7 @@
|
|
38
38
|
},
|
39
39
|
"funding": "https://opencollective.com/unts",
|
40
40
|
"license": "MIT",
|
41
|
+
"packageManager": "yarn@1.22.19",
|
41
42
|
"engines": {
|
42
43
|
"node": "^14.18.0 || >=16.0.0"
|
43
44
|
},
|
@@ -63,8 +64,94 @@
|
|
63
64
|
"synchronize",
|
64
65
|
"synckit"
|
65
66
|
],
|
67
|
+
"scripts": {
|
68
|
+
"benchmark": "run-s benchmark:*",
|
69
|
+
"benchmark-export": "run-s benchmark-export:*",
|
70
|
+
"benchmark-export:cjs": "yarn benchmark:cjs > benchmarks/benchmark.cjs.txt",
|
71
|
+
"benchmark-export:esm": "yarn benchmark:esm> benchmarks/benchmark.esm.txt",
|
72
|
+
"benchmark:cjs": "node benchmarks/benchmark.cjs",
|
73
|
+
"benchmark:esm": "node benchmarks/benchmark.js",
|
74
|
+
"build": "run-p build:*",
|
75
|
+
"build:r": "r -f cjs",
|
76
|
+
"build:ts": "tsc -p src",
|
77
|
+
"lint": "run-p lint:*",
|
78
|
+
"lint:es": "eslint . --cache -f friendly --max-warnings 10",
|
79
|
+
"lint:tsc": "tsc --noEmit",
|
80
|
+
"prepare": "patch-package && simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
|
81
|
+
"prerelease": "yarn build",
|
82
|
+
"release": "changeset publish",
|
83
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
84
|
+
"typecov": "type-coverage"
|
85
|
+
},
|
66
86
|
"dependencies": {
|
67
87
|
"@pkgr/utils": "^2.3.0",
|
68
88
|
"tslib": "^2.4.0"
|
89
|
+
},
|
90
|
+
"devDependencies": {
|
91
|
+
"@1stg/lib-config": "^9.0.2",
|
92
|
+
"@changesets/changelog-github": "^0.4.6",
|
93
|
+
"@changesets/cli": "^2.23.2",
|
94
|
+
"@swc-node/register": "^1.5.1",
|
95
|
+
"@types/jest": "^28.1.5",
|
96
|
+
"@types/node": "^18.0.4",
|
97
|
+
"deasync": "^0.1.27",
|
98
|
+
"esbuild-register": "^3.3.3",
|
99
|
+
"esbuild-runner": "^2.2.1",
|
100
|
+
"execa": "^6.1.0",
|
101
|
+
"jest": "^28.1.3",
|
102
|
+
"patch-package": "^6.4.7",
|
103
|
+
"sync-threads": "^1.0.1",
|
104
|
+
"ts-expect": "^1.3.0",
|
105
|
+
"ts-jest": "^28.0.6",
|
106
|
+
"ts-node": "^10.9.1",
|
107
|
+
"tsx": "^3.8.0",
|
108
|
+
"type-coverage": "^2.22.0",
|
109
|
+
"typescript": "^4.7.4",
|
110
|
+
"yarn-deduplicate": "^5.0.0"
|
111
|
+
},
|
112
|
+
"resolutions": {
|
113
|
+
"prettier": "^2.7.1"
|
114
|
+
},
|
115
|
+
"commitlint": {
|
116
|
+
"extends": "@1stg"
|
117
|
+
},
|
118
|
+
"jest": {
|
119
|
+
"preset": "ts-jest",
|
120
|
+
"testEnvironment": "node",
|
121
|
+
"collectCoverage": true,
|
122
|
+
"extensionsToTreatAsEsm": [
|
123
|
+
".ts"
|
124
|
+
],
|
125
|
+
"moduleNameMapper": {
|
126
|
+
"^(\\.{1,2}/.*)\\.js$": "$1",
|
127
|
+
"^synckit$": "<rootDir>/src"
|
128
|
+
},
|
129
|
+
"globals": {
|
130
|
+
"ts-jest": {
|
131
|
+
"useESM": true,
|
132
|
+
"tsconfig": {
|
133
|
+
"importHelpers": false
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
},
|
138
|
+
"prettier": "@1stg/prettier-config",
|
139
|
+
"renovate": {
|
140
|
+
"extends": [
|
141
|
+
"@1stg"
|
142
|
+
]
|
143
|
+
},
|
144
|
+
"typeCoverage": {
|
145
|
+
"atLeast": 100,
|
146
|
+
"cache": true,
|
147
|
+
"detail": true,
|
148
|
+
"ignoreAsAssertion": true,
|
149
|
+
"ignoreFiles": [
|
150
|
+
"**/*.d.ts"
|
151
|
+
],
|
152
|
+
"ignoreNonNullAssertion": true,
|
153
|
+
"showRelativePath": true,
|
154
|
+
"strict": true,
|
155
|
+
"update": true
|
69
156
|
}
|
70
157
|
}
|