synckit
Advanced tools
Comparing version 0.8.1 to 0.8.2
@@ -20,3 +20,3 @@ import { __awaiter } from "tslib"; | ||
}; | ||
const { SYNCKIT_BUFFER_SIZE, SYNCKIT_TIMEOUT, SYNCKIT_EXEC_ARV, SYNCKIT_TS_RUNNER, } = process.env; | ||
const { SYNCKIT_BUFFER_SIZE, SYNCKIT_TIMEOUT, SYNCKIT_EXEC_ARGV, SYNCKIT_TS_RUNNER, NODE_OPTIONS, } = process.env; | ||
export const DEFAULT_BUFFER_SIZE = SYNCKIT_BUFFER_SIZE | ||
@@ -28,3 +28,3 @@ ? +SYNCKIT_BUFFER_SIZE | ||
/* istanbul ignore next */ | ||
export const DEFAULT_EXEC_ARGV = (SYNCKIT_EXEC_ARV === null || SYNCKIT_EXEC_ARV === void 0 ? void 0 : SYNCKIT_EXEC_ARV.split(',')) || []; | ||
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 || | ||
@@ -139,2 +139,12 @@ TsRunner.TsNode); | ||
} | ||
/* istanbul ignore if -- https://github.com/facebook/jest/issues/5274 */ | ||
if (process.versions.pnp) { | ||
const nodeOptions = NODE_OPTIONS === null || NODE_OPTIONS === void 0 ? void 0 : NODE_OPTIONS.split(/\s+/); | ||
const pnpApiPath = cjsRequire.resolve('pnpapi'); | ||
if (!(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]; | ||
} | ||
} | ||
return { | ||
@@ -214,24 +224,41 @@ ext, | ||
const { workerPort } = workerData; | ||
parentPort.on('message', ({ sharedBuffer, id, args }) => { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
; | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
parentPort.on('message', ({ sharedBuffer, id, args }) => { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
; | ||
(() => __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); | ||
}))(); | ||
}); | ||
/** | ||
* @see https://github.com/un-ts/synckit/issues/94 | ||
* | ||
* Starting the worker can fail, due to syntax error, for example. In that case | ||
* we just fail all incoming messages with whatever error message we got. | ||
* Otherwise incoming messages will hang forever waiting for a reply. | ||
*/ | ||
} | ||
catch (error) { | ||
parentPort.on('message', ({ sharedBuffer, id }) => { | ||
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); | ||
workerPort.postMessage({ | ||
id, | ||
error, | ||
properties: extractProperties(error), | ||
}); | ||
Atomics.add(sharedBufferView, 0, 1); | ||
Atomics.notify(sharedBufferView, 0); | ||
}))(); | ||
}); | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "synckit", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"type": "module", | ||
"description": "Perform async work synchronously in Node.js using `worker_threads` with first-class TypeScript support.", | ||
"repository": "git+https://github.com/rx-ts/synckit.git", | ||
"repository": "git+https://github.com/un-ts/synckit.git", | ||
"author": "JounQin (https://www.1stG.me) <admin@1stg.me>", | ||
@@ -41,2 +41,3 @@ "donate": { | ||
"license": "MIT", | ||
"packageManager": "yarn@1.22.19", | ||
"engines": { | ||
@@ -91,4 +92,4 @@ "node": "^14.18.0 || >=16.0.0" | ||
"devDependencies": { | ||
"@1stg/lib-config": "^9.0.0", | ||
"@changesets/changelog-github": "^0.4.5", | ||
"@1stg/lib-config": "^9.0.2", | ||
"@changesets/changelog-github": "^0.4.6", | ||
"@changesets/cli": "^2.23.2", | ||
@@ -100,2 +101,3 @@ "@types/jest": "^28.1.5", | ||
"esbuild-runner": "^2.2.1", | ||
"execa": "^6.1.0", | ||
"jest": "^28.1.3", | ||
@@ -102,0 +104,0 @@ "patch-package": "^6.4.7", |
@@ -22,2 +22,3 @@ # synckit | ||
- [API](#api) | ||
- [Options](#options) | ||
- [Envs](#envs) | ||
@@ -54,3 +55,5 @@ - [TypeScript](#typescript) | ||
// the worker path must be absolute | ||
const syncFn = createSyncFn(require.resolve('./worker')) | ||
const syncFn = createSyncFn(require.resolve('./worker'), { | ||
tsRunner: 'tsx', // optional, can be `'ts-node' | 'esbuild-register' | 'esbuild-runner' | 'tsx'` | ||
}) | ||
@@ -73,2 +76,9 @@ // do whatever you want, you will get the result synchronously! | ||
### 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` | ||
### Envs | ||
@@ -123,3 +133,3 @@ | ||
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | | ||
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) | | ||
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) | | ||
@@ -126,0 +136,0 @@ ## Changelog |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
42921
569
143
19