@ohos-ports/rspack-core 1.7.11-beta.1 → 2.2.9-beta.0
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 +11 -1
- package/compiled/@rspack/lite-tapable/dist/index.d.ts +190 -0
- package/compiled/@rspack/lite-tapable/license +22 -0
- package/compiled/@rspack/lite-tapable/package.json +1 -0
- package/compiled/@swc/types/index.d.ts +161 -11
- package/compiled/@swc/types/package.json +1 -1
- package/compiled/connect-next/index.d.ts +57 -0
- package/compiled/connect-next/license +26 -0
- package/compiled/connect-next/package.json +1 -0
- package/compiled/http-proxy-middleware/index.d.ts +455 -0
- package/compiled/{browserslist-load-config → http-proxy-middleware}/license +3 -2
- package/compiled/http-proxy-middleware/package.json +1 -0
- package/compiled/open/index.d.ts +161 -0
- package/compiled/open/package.json +1 -0
- package/compiled/tinypool/README.md +196 -2
- package/compiled/tinypool/dist/{common-Qw-RoVFD.js → common-Bo3KCGim.js} +4 -1
- package/compiled/tinypool/dist/entry/worker.js +1 -1
- package/compiled/tinypool/dist/index.d.ts +9 -4
- package/compiled/tinypool/dist/index.js +17 -53
- package/compiled/tinypool/package.json +22 -6
- package/compiled/watchpack/index.d.ts +3 -217
- package/compiled/watchpack/index.js +1778 -1091
- package/compiled/watchpack/package.json +8 -1
- package/compiled/watchpack/types/DirectoryWatcher.d.ts +335 -0
- package/compiled/watchpack/types/LinkResolver.d.ts +10 -0
- package/compiled/watchpack/types/getWatcherManager.d.ts +62 -0
- package/compiled/watchpack/types/index.d.ts +269 -0
- package/compiled/watchpack/types/reducePlan.d.ts +34 -0
- package/compiled/watchpack/types/util/globToRegExp.d.ts +2 -0
- package/compiled/watchpack/types/watchEventSource.d.ts +53 -0
- package/compiled/watchpack/types/watchpack.d.ts +2 -0
- package/compiled/webpack-sources/index.d.ts +61 -0
- package/compiled/webpack-sources/index.js +2370 -576
- package/compiled/webpack-sources/package.json +8 -1
- package/compiled/webpack-sources/types/CachedSource.d.ts +192 -0
- package/compiled/webpack-sources/types/CompatSource.d.ts +87 -0
- package/compiled/webpack-sources/types/ConcatSource.d.ts +75 -0
- package/compiled/webpack-sources/types/OriginalSource.d.ts +87 -0
- package/compiled/webpack-sources/types/PrefixSource.d.ts +59 -0
- package/compiled/webpack-sources/types/RawSource.d.ts +75 -0
- package/compiled/webpack-sources/types/ReplaceSource.d.ts +107 -0
- package/compiled/webpack-sources/types/SizeOnlySource.d.ts +24 -0
- package/compiled/webpack-sources/types/Source.d.ts +189 -0
- package/compiled/webpack-sources/types/SourceMapSource.d.ts +136 -0
- package/compiled/webpack-sources/types/helpers/createMappingsSerializer.d.ts +60 -0
- package/compiled/webpack-sources/types/helpers/getFromStreamChunks.d.ts +16 -0
- package/compiled/webpack-sources/types/helpers/getGeneratedSourceInfo.d.ts +31 -0
- package/compiled/webpack-sources/types/helpers/getName.d.ts +15 -0
- package/compiled/webpack-sources/types/helpers/getSource.d.ts +15 -0
- package/compiled/webpack-sources/types/helpers/readMappings.d.ts +19 -0
- package/compiled/webpack-sources/types/helpers/scopes.d.ts +119 -0
- package/compiled/webpack-sources/types/helpers/splitIntoLines.d.ts +6 -0
- package/compiled/webpack-sources/types/helpers/splitIntoPotentialTokens.d.ts +37 -0
- package/compiled/webpack-sources/types/helpers/streamAndGetSourceAndMap.d.ts +39 -0
- package/compiled/webpack-sources/types/helpers/streamChunks.d.ts +56 -0
- package/compiled/webpack-sources/types/helpers/streamChunksOfCombinedSourceMap.d.ts +42 -0
- package/compiled/webpack-sources/types/helpers/streamChunksOfRawSource.d.ts +16 -0
- package/compiled/webpack-sources/types/helpers/streamChunksOfSourceMap.d.ts +19 -0
- package/compiled/webpack-sources/types/helpers/stringBufferUtils.d.ts +55 -0
- package/compiled/webpack-sources/types/index.d.ts +50 -0
- package/dist/BuildInfo.d.ts +3 -1
- package/dist/ChunkGraph.d.ts +1 -1
- package/dist/CodeGenerationResults.d.ts +6 -1
- package/dist/Compilation.d.ts +60 -89
- package/dist/Compiler.d.ts +25 -22
- package/dist/ContextModuleFactory.d.ts +2 -2
- package/dist/Diagnostics.d.ts +2 -6
- package/dist/ExecuteModulePlugin.d.ts +1 -1
- package/dist/ExportsInfo.d.ts +1 -1
- package/dist/ExternalModule.d.ts +15 -1
- package/dist/FileSystem.d.ts +4 -2
- package/dist/FileSystemDependencies.d.ts +15 -0
- package/dist/Module.d.ts +9 -6
- package/dist/ModuleGraph.d.ts +11 -8
- package/dist/ModuleGraphConnection.d.ts +10 -0
- package/dist/Modules.d.ts +3 -0
- package/dist/MultiCompiler.d.ts +9 -9
- package/dist/MultiStats.d.ts +3 -3
- package/dist/MultiWatching.d.ts +3 -3
- package/dist/NativeWatchFileSystem.d.ts +31 -2
- package/dist/NormalModule.d.ts +4 -5
- package/dist/NormalModuleFactory.d.ts +5 -4
- package/dist/Resolver.d.ts +10 -2
- package/dist/ResolverFactory.d.ts +2 -2
- package/dist/RuntimeGlobals.d.ts +61 -56
- package/dist/RuntimeModule.d.ts +3 -3
- package/dist/RuntimeTemplate.d.ts +151 -0
- package/dist/Stats.d.ts +4 -4
- package/dist/VirtualModulesPlugin.d.ts +1 -1
- package/dist/Watching.d.ts +5 -5
- package/dist/builtin-loader/lightningcss/index.d.ts +11 -14
- package/dist/builtin-loader/lightningcss/target.d.ts +4 -0
- package/dist/builtin-loader/swc/index.d.ts +3 -5
- package/dist/builtin-loader/swc/pluginImport.d.ts +1 -1
- package/dist/builtin-loader/swc/types.d.ts +36 -65
- package/dist/builtin-plugin/APIPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +3 -3
- package/dist/builtin-plugin/AssetModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/BannerPlugin.d.ts +3 -3
- package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CaseSensitivePlugin.d.ts +3 -3
- package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CircularCheckRspackPlugin.d.ts +33 -0
- package/dist/builtin-plugin/CircularDependencyRspackPlugin.d.ts +10 -4
- package/dist/builtin-plugin/CircularModulesInfoPlugin.d.ts +7 -0
- package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CompactHashedChunkIdsPlugin.d.ts +12 -0
- package/dist/builtin-plugin/CompactHashedModuleIdsPlugin.d.ts +12 -0
- package/dist/builtin-plugin/ContextReplacementPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CopyRspackPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CssChunkingPlugin.d.ts +3 -3
- package/dist/builtin-plugin/CssHttpExternalsRspackPlugin.d.ts +9 -0
- package/dist/builtin-plugin/CssModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/DataUriPlugin.d.ts +3 -3
- package/dist/builtin-plugin/DefinePlugin.d.ts +3 -3
- package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +2 -2
- package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +13 -2
- package/dist/builtin-plugin/DllEntryPlugin.d.ts +3 -3
- package/dist/builtin-plugin/DllReferenceAgencyPlugin.d.ts +3 -3
- package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +4 -4
- package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +3 -3
- package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +2 -2
- package/dist/builtin-plugin/EnableLibraryPlugin.d.ts +2 -2
- package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +3 -3
- package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/EntryPlugin.d.ts +4 -4
- package/dist/builtin-plugin/EsmLibraryPlugin.d.ts +7 -2
- package/dist/builtin-plugin/EsmNodeTargetPlugin.d.ts +9 -0
- package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +3 -3
- package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ExternalsPlugin.d.ts +4 -3
- package/dist/builtin-plugin/FetchCompileAsyncWasmPlugin.d.ts +3 -3
- package/dist/builtin-plugin/FileUriPlugin.d.ts +3 -3
- package/dist/builtin-plugin/FlagAllModulesAsUsedPlugin.d.ts +3 -3
- package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +2 -2
- package/dist/builtin-plugin/HashedModuleIdsPlugin.d.ts +10 -0
- package/dist/builtin-plugin/HotModuleReplacementPlugin.d.ts +2 -2
- package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +5 -5
- package/dist/builtin-plugin/HttpUriPlugin.d.ts +7 -3
- package/dist/builtin-plugin/IgnorePlugin.d.ts +3 -3
- package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/InlineExportsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +21 -6
- package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +2 -2
- package/dist/builtin-plugin/JsonModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/LibManifestPlugin.d.ts +3 -3
- package/dist/builtin-plugin/LightningCssMinimizerRspackPlugin.d.ts +7 -11
- package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +3 -3
- package/dist/builtin-plugin/MangleExportsPlugin.d.ts +2 -2
- package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +2 -2
- package/dist/builtin-plugin/ModuleInfoHeaderPlugin.d.ts +3 -3
- package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/NaturalChunkIdsPlugin.d.ts +2 -2
- package/dist/builtin-plugin/NaturalModuleIdsPlugin.d.ts +2 -2
- package/dist/builtin-plugin/NoEmitOnErrorsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/NodeTargetPlugin.d.ts +3 -3
- package/dist/builtin-plugin/NormalModuleReplacementPlugin.d.ts +4 -4
- package/dist/builtin-plugin/OccurrenceChunkIdsPlugin.d.ts +3 -3
- package/dist/builtin-plugin/ProgressPlugin.d.ts +8 -7
- package/dist/builtin-plugin/ProvidePlugin.d.ts +3 -3
- package/dist/builtin-plugin/RealContentHashPlugin.d.ts +15 -4
- package/dist/builtin-plugin/RemoveDuplicateModulesPlugin.d.ts +3 -3
- package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +3 -3
- package/dist/builtin-plugin/RsdoctorPlugin.d.ts +8 -11
- package/dist/builtin-plugin/RslibPlugin.d.ts +5 -6
- package/dist/builtin-plugin/RstestPlugin.d.ts +3 -4
- package/dist/builtin-plugin/RuntimeChunkPlugin.d.ts +3 -3
- package/dist/builtin-plugin/RuntimePlugin.d.ts +7 -11
- package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +9 -9
- package/dist/builtin-plugin/SizeLimitsPlugin.d.ts +5 -5
- package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +3 -3
- package/dist/builtin-plugin/SplitChunksPlugin.d.ts +6 -5
- package/dist/builtin-plugin/SubresourceIntegrityPlugin.d.ts +2 -2
- package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +7 -6
- package/dist/builtin-plugin/SyncModuleIdsPlugin.d.ts +16 -0
- package/dist/builtin-plugin/URLPlugin.d.ts +3 -3
- package/dist/builtin-plugin/WorkerPlugin.d.ts +4 -4
- package/dist/builtin-plugin/base.d.ts +3 -3
- package/dist/builtin-plugin/css-extract/index.d.ts +3 -3
- package/dist/builtin-plugin/css-extract/loader.d.ts +1 -1
- package/dist/builtin-plugin/css-extract/utils.d.ts +8 -1
- package/dist/builtin-plugin/html-plugin/hooks.d.ts +3 -3
- package/dist/builtin-plugin/html-plugin/index.d.ts +2 -2
- package/dist/builtin-plugin/html-plugin/options.d.ts +2 -7
- package/dist/builtin-plugin/html-plugin/plugin.d.ts +5 -9
- package/dist/builtin-plugin/html-plugin/taps.d.ts +1 -1
- package/dist/builtin-plugin/index.d.ts +92 -84
- package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +6 -6
- package/dist/builtin-plugin/lazy-compilation/middleware.d.ts +4 -4
- package/dist/builtin-plugin/rsc/Coordinator.d.ts +8 -0
- package/dist/builtin-plugin/rsc/RscClientPlugin.d.ts +13 -0
- package/dist/builtin-plugin/rsc/RscServerPlugin.d.ts +47 -0
- package/dist/builtin-plugin/rsc/index.d.ts +24 -0
- package/dist/checkNodeVersion.d.ts +1 -0
- package/dist/config/adapter.d.ts +4 -4
- package/dist/config/adapterRuleUse.d.ts +89 -55
- package/dist/config/browserslistTargetHandler.d.ts +1 -1
- package/dist/config/defaults.d.ts +5 -3
- package/dist/config/devServer.d.ts +103 -238
- package/dist/config/index.d.ts +5 -5
- package/dist/config/normalization.d.ts +26 -47
- package/dist/config/target.d.ts +19 -12
- package/dist/config/types.d.ts +615 -256
- package/dist/container/ContainerPlugin.d.ts +4 -4
- package/dist/container/ContainerReferencePlugin.d.ts +4 -4
- package/dist/container/ModuleFederationManifestPlugin.d.ts +12 -5
- package/dist/container/ModuleFederationPlugin.d.ts +22 -5
- package/dist/container/ModuleFederationPluginV1.d.ts +10 -6
- package/dist/container/ModuleFederationRuntimePlugin.d.ts +3 -3
- package/dist/cssExtractHmr.js +2 -27
- package/dist/cssExtractLoader.js +24 -65
- package/dist/exports.d.ts +98 -84
- package/dist/index.d.ts +4 -3
- package/dist/index.js +14201 -11810
- package/dist/lib/AbstractMethodError.d.ts +1 -1
- package/dist/lib/Cache.d.ts +5 -2
- package/dist/lib/CacheFacade.d.ts +4 -4
- package/dist/lib/DllPlugin.d.ts +2 -2
- package/dist/lib/DllReferencePlugin.d.ts +3 -3
- package/dist/lib/EntryOptionPlugin.d.ts +2 -2
- package/dist/lib/EnvironmentPlugin.d.ts +3 -3
- package/dist/lib/HookWebpackError.d.ts +2 -3
- package/dist/lib/IgnoreWarningsPlugin.d.ts +1 -1
- package/dist/lib/LoaderOptionsPlugin.d.ts +2 -2
- package/dist/lib/LoaderTargetPlugin.d.ts +2 -2
- package/dist/lib/WebpackError.d.ts +2 -2
- package/dist/lib/cache/MemoryCachePlugin.d.ts +1 -1
- package/dist/lib/cache/getLazyHashedEtag.d.ts +2 -2
- package/dist/lib/cache/mergeEtags.d.ts +1 -2
- package/dist/loader-runner/ModuleError.d.ts +1 -1
- package/dist/loader-runner/cache.d.ts +27 -0
- package/dist/loader-runner/dependencies.d.ts +23 -0
- package/dist/loader-runner/index.d.ts +10 -11
- package/dist/loader-runner/loadLoader.d.ts +2 -2
- package/dist/loader-runner/service.d.ts +10 -1
- package/dist/loader-runner/utils.d.ts +3 -3
- package/dist/loader-runner/worker.d.ts +1 -1
- package/dist/logging/createConsoleLogger.d.ts +2 -2
- package/dist/l~0.js +34 -0
- package/dist/l~3.js +34 -0
- package/dist/moduleFederationDefaultRuntime.js +1 -1
- package/dist/node/NodeEnvironmentPlugin.d.ts +2 -2
- package/dist/node/NodeTemplatePlugin.d.ts +1 -1
- package/dist/node/NodeWatchFileSystem.d.ts +15 -3
- package/dist/node/nodeConsole.d.ts +1 -1
- package/dist/rspack.d.ts +7 -8
- package/dist/rspackOptionsApply.d.ts +1 -1
- package/dist/runtime/cssExtractHmr.d.ts +2 -2
- package/dist/runtime/moduleFederationDefaultRuntime.d.ts +1 -2
- package/dist/sharing/CollectSharedEntryPlugin.d.ts +22 -0
- package/dist/sharing/ConsumeSharedPlugin.d.ts +18 -6
- package/dist/sharing/IndependentSharedPlugin.d.ts +37 -0
- package/dist/sharing/ProvideSharedPlugin.d.ts +22 -3
- package/dist/sharing/SharePlugin.d.ts +51 -3
- package/dist/sharing/ShareRuntimePlugin.d.ts +2 -2
- package/dist/sharing/SharedContainerPlugin.d.ts +23 -0
- package/dist/sharing/SharedUsedExportsOptimizerPlugin.d.ts +14 -0
- package/dist/sharing/TreeShakingSharedPlugin.d.ts +19 -0
- package/dist/sharing/utils.d.ts +1 -0
- package/dist/stats/DefaultStatsFactoryPlugin.d.ts +1 -1
- package/dist/stats/DefaultStatsPresetPlugin.d.ts +1 -1
- package/dist/stats/DefaultStatsPrinterPlugin.d.ts +1 -1
- package/dist/stats/StatsFactory.d.ts +7 -5
- package/dist/stats/StatsPrinter.d.ts +7 -7
- package/dist/stats/statsFactoryUtils.d.ts +15 -19
- package/dist/swc.d.ts +2 -2
- package/dist/taps/compilation.d.ts +1 -1
- package/dist/taps/compiler.d.ts +1 -1
- package/dist/taps/contextModuleFactory.d.ts +1 -1
- package/dist/taps/externalModule.d.ts +2 -0
- package/dist/taps/index.d.ts +7 -6
- package/dist/taps/javascriptModules.d.ts +1 -1
- package/dist/taps/normalModuleFactory.d.ts +1 -1
- package/dist/taps/types.d.ts +2 -2
- package/dist/trace/index.d.ts +1 -0
- package/dist/trace/traceHookPlugin.d.ts +1 -1
- package/dist/util/bindingHelpers.d.ts +7 -0
- package/dist/util/comparators.d.ts +1 -1
- package/dist/util/createHash.d.ts +2 -2
- package/dist/util/fs.d.ts +19 -18
- package/dist/util/hash/md4.d.ts +1 -1
- package/dist/util/hash/xxhash64.d.ts +1 -1
- package/dist/util/identifier.d.ts +35 -9
- package/dist/util/index.d.ts +2 -2
- package/dist/util/source.d.ts +3 -3
- package/dist/util/supportsColor.d.ts +6 -0
- package/dist/util/targetsVersion.d.ts +2 -0
- package/dist/util/validateConfig.d.ts +1 -1
- package/dist/util/watchTimeInfo.d.ts +7 -0
- package/dist/web/JsonpTemplatePlugin.d.ts +13 -0
- package/dist/webworker/WebWorkerTemplatePlugin.d.ts +13 -0
- package/dist/worker.js +935 -907
- package/hot/dev-server.js +12 -11
- package/hot/emitter.js +3 -1
- package/hot/lazy-compilation-node.js +4 -1
- package/hot/lazy-compilation-web.js +2 -3
- package/hot/log-apply-result.js +8 -5
- package/hot/log.js +18 -10
- package/hot/only-dev-server.js +13 -12
- package/hot/poll.js +10 -9
- package/hot/signal.js +12 -10
- package/module.d.ts +39 -2
- package/package.json +15 -39
- package/compiled/browserslist-load-config/index.d.ts +0 -21
- package/compiled/browserslist-load-config/index.js +0 -252
- package/compiled/browserslist-load-config/package.json +0 -1
- package/compiled/webpack-sources/types.d.ts +0 -458
- package/dist/builtin-loader/index.d.ts +0 -1
- package/dist/builtin-plugin/WebWorkerTemplatePlugin.d.ts +0 -7
- package/dist/container/index.d.ts +0 -4
- package/dist/util/MergeCaller.d.ts +0 -10
- package/dist/util/fake.d.ts +0 -14
|
@@ -16,5 +16,199 @@ Tinypool is a fork of piscina. What we try to achieve in this library, is to eli
|
|
|
16
16
|
|
|
17
17
|
_In case you need more tiny libraries like tinypool or tinyspy, please consider submitting an [RFC](https://github.com/tinylibs/rfcs)_
|
|
18
18
|
|
|
19
|
-
##
|
|
20
|
-
|
|
19
|
+
## Example
|
|
20
|
+
|
|
21
|
+
### Using `node:worker_threads`
|
|
22
|
+
|
|
23
|
+
#### Basic usage
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
// main.mjs
|
|
27
|
+
import Tinypool from 'tinypool'
|
|
28
|
+
|
|
29
|
+
const pool = new Tinypool({
|
|
30
|
+
filename: new URL('./worker.mjs', import.meta.url),
|
|
31
|
+
})
|
|
32
|
+
const result = await pool.run({ a: 4, b: 6 })
|
|
33
|
+
console.log(result) // Prints 10
|
|
34
|
+
|
|
35
|
+
// Make sure to destroy pool once it's not needed anymore
|
|
36
|
+
// This terminates all pool's idle workers
|
|
37
|
+
await pool.destroy()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
// worker.mjs
|
|
42
|
+
export default ({ a, b }) => {
|
|
43
|
+
return a + b
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Main thread <-> worker thread communication
|
|
48
|
+
|
|
49
|
+
<details>
|
|
50
|
+
<summary>See code</summary>
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
// main.mjs
|
|
54
|
+
import Tinypool from 'tinypool'
|
|
55
|
+
import { MessageChannel } from 'node:worker_threads'
|
|
56
|
+
|
|
57
|
+
const pool = new Tinypool({
|
|
58
|
+
filename: new URL('./worker.mjs', import.meta.url),
|
|
59
|
+
})
|
|
60
|
+
const { port1, port2 } = new MessageChannel()
|
|
61
|
+
const promise = pool.run({ port: port1 }, { transferList: [port1] })
|
|
62
|
+
|
|
63
|
+
port2.on('message', (message) => console.log('Main thread received:', message))
|
|
64
|
+
setTimeout(() => port2.postMessage('Hello from main thread!'), 1000)
|
|
65
|
+
|
|
66
|
+
await promise
|
|
67
|
+
|
|
68
|
+
port1.close()
|
|
69
|
+
port2.close()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
// worker.mjs
|
|
74
|
+
export default ({ port }) => {
|
|
75
|
+
return new Promise((resolve) => {
|
|
76
|
+
port.on('message', (message) => {
|
|
77
|
+
console.log('Worker received:', message)
|
|
78
|
+
|
|
79
|
+
port.postMessage('Hello from worker thread!')
|
|
80
|
+
resolve()
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
</details>
|
|
87
|
+
|
|
88
|
+
### Using `node:child_process`
|
|
89
|
+
|
|
90
|
+
#### Basic usage
|
|
91
|
+
|
|
92
|
+
<details>
|
|
93
|
+
<summary>See code</summary>
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
// main.mjs
|
|
97
|
+
import Tinypool from 'tinypool'
|
|
98
|
+
|
|
99
|
+
const pool = new Tinypool({
|
|
100
|
+
runtime: 'child_process',
|
|
101
|
+
filename: new URL('./worker.mjs', import.meta.url),
|
|
102
|
+
})
|
|
103
|
+
const result = await pool.run({ a: 4, b: 6 })
|
|
104
|
+
console.log(result) // Prints 10
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
// worker.mjs
|
|
109
|
+
export default ({ a, b }) => {
|
|
110
|
+
return a + b
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
</details>
|
|
115
|
+
|
|
116
|
+
#### Main process <-> worker process communication
|
|
117
|
+
|
|
118
|
+
<details>
|
|
119
|
+
<summary>See code</summary>
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
// main.mjs
|
|
123
|
+
import Tinypool from 'tinypool'
|
|
124
|
+
|
|
125
|
+
const pool = new Tinypool({
|
|
126
|
+
runtime: 'child_process',
|
|
127
|
+
filename: new URL('./worker.mjs', import.meta.url),
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
const messages = []
|
|
131
|
+
const listeners = []
|
|
132
|
+
const channel = {
|
|
133
|
+
onMessage: (listener) => listeners.push(listener),
|
|
134
|
+
postMessage: (message) => messages.push(message),
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const promise = pool.run({}, { channel })
|
|
138
|
+
|
|
139
|
+
// Send message to worker
|
|
140
|
+
setTimeout(
|
|
141
|
+
() => listeners.forEach((listener) => listener('Hello from main process')),
|
|
142
|
+
1000
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
// Wait for task to finish
|
|
146
|
+
await promise
|
|
147
|
+
|
|
148
|
+
console.log(messages)
|
|
149
|
+
// [{ received: 'Hello from main process', response: 'Hello from worker' }]
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
// worker.mjs
|
|
154
|
+
export default async function run() {
|
|
155
|
+
return new Promise((resolve) => {
|
|
156
|
+
process.on('message', (message) => {
|
|
157
|
+
// Ignore Tinypool's internal messages
|
|
158
|
+
if (message?.__tinypool_worker_message__) return
|
|
159
|
+
|
|
160
|
+
process.send({ received: message, response: 'Hello from worker' })
|
|
161
|
+
resolve()
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
</details>
|
|
168
|
+
|
|
169
|
+
## API
|
|
170
|
+
|
|
171
|
+
We have a similar API to Piscina, so for more information, you can read Piscina's detailed [documentation](https://github.com/piscinajs/piscina#piscina---the-nodejs-worker-pool) and apply the same techniques here.
|
|
172
|
+
|
|
173
|
+
### Tinypool specific APIs
|
|
174
|
+
|
|
175
|
+
#### Pool constructor options
|
|
176
|
+
|
|
177
|
+
- `isolateWorkers`: Disabled by default. Always starts with a fresh worker when running tasks to isolate the environment.
|
|
178
|
+
- `terminateTimeout`: Disabled by default. If terminating a worker takes `terminateTimeout` amount of milliseconds to execute, an error is raised.
|
|
179
|
+
- `maxMemoryLimitBeforeRecycle`: Disabled by default. When defined, the worker's heap memory usage is compared against this value after task has been finished. If the current memory usage exceeds this limit, worker is terminated and a new one is started to take its place. This option is useful when your tasks leak memory and you don't want to enable `isolateWorkers` option.
|
|
180
|
+
- `runtime`: Used to pick worker runtime. Default value is `worker_threads`.
|
|
181
|
+
- `worker_threads`: Runs workers in [`node:worker_threads`](https://nodejs.org/api/worker_threads.html). For `main thread <-> worker thread` communication you can use [`MessagePort`](https://nodejs.org/api/worker_threads.html#class-messageport) in the `pool.run()` method's [`transferList` option](https://nodejs.org/api/worker_threads.html#portpostmessagevalue-transferlist). See [example](#main-thread---worker-thread-communication).
|
|
182
|
+
- `child_process`: Runs workers in [`node:child_process`](https://nodejs.org/api/child_process.html). For `main thread <-> worker process` communication you can use `TinypoolChannel` in the `pool.run()` method's `channel` option. For filtering out the Tinypool's internal messages see `TinypoolWorkerMessage`. See [example](#main-process---worker-process-communication).
|
|
183
|
+
- `teardown`: name of the function in file that should be called before worker is terminated. Must be named exported.
|
|
184
|
+
- `serialization`: Specify the kind of serialization used for the `child_process` runtime. Possible values are `'json'` and `'advanced'`. See Node.js [Advanced serialization](https://nodejs.org/docs/latest/api/child_process.html#advanced-serialization) for more details.
|
|
185
|
+
|
|
186
|
+
#### Pool methods
|
|
187
|
+
|
|
188
|
+
- `cancelPendingTasks()`: Gracefully cancels all pending tasks without stopping or interfering with on-going tasks. This method is useful when your tasks may have side effects and should not be terminated forcefully during task execution. If your tasks don't have any side effects you may want to use [`{ signal }`](https://github.com/piscinajs/piscina#cancelable-tasks) option for forcefully terminating all tasks, including the on-going ones, instead.
|
|
189
|
+
- `recycleWorkers(options)`: Waits for all current tasks to finish and re-creates all workers. Can be used to force isolation imperatively even when `isolateWorkers` is disabled. Accepts `{ runtime }` option as argument.
|
|
190
|
+
|
|
191
|
+
#### Exports
|
|
192
|
+
|
|
193
|
+
- `workerId`: Each worker now has an id ( <= `maxThreads`) that can be imported from `tinypool` in the worker itself (or `process.__tinypool_state__.workerId`).
|
|
194
|
+
|
|
195
|
+
## Authors
|
|
196
|
+
|
|
197
|
+
| <a href="https://github.com/Aslemammad"> <img width='150' src="https://avatars.githubusercontent.com/u/37929992?v=4" /><br> Mohammad Bagher </a> |
|
|
198
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
199
|
+
|
|
200
|
+
## Sponsors
|
|
201
|
+
|
|
202
|
+
Your sponsorship can make a huge difference in continuing our work in open source!
|
|
203
|
+
|
|
204
|
+
<p align="center">
|
|
205
|
+
<a href="https://cdn.jsdelivr.net/gh/aslemammad/static/sponsors.svg">
|
|
206
|
+
<img src='https://cdn.jsdelivr.net/gh/aslemammad/static/sponsors.svg'/>
|
|
207
|
+
</a>
|
|
208
|
+
</p>
|
|
209
|
+
|
|
210
|
+
## Credits
|
|
211
|
+
|
|
212
|
+
[The Vitest team](https://vitest.dev/) for giving me the chance of creating and maintaing this project for vitest.
|
|
213
|
+
|
|
214
|
+
[Piscina](https://github.com/piscinajs/piscina), because Tinypool is not more than a friendly fork of piscina.
|
|
@@ -17,6 +17,9 @@ function markMovable(value) {
|
|
|
17
17
|
value: true
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
+
function withNullPrototype(source) {
|
|
21
|
+
return Object.assign(Object.create(null), source);
|
|
22
|
+
}
|
|
20
23
|
function isTaskQueue(value) {
|
|
21
24
|
return typeof value === "object" && value !== null && "size" in value && typeof value.shift === "function" && typeof value.remove === "function" && typeof value.push === "function";
|
|
22
25
|
}
|
|
@@ -25,4 +28,4 @@ const kResponseCountField = 1;
|
|
|
25
28
|
const kFieldCount = 2;
|
|
26
29
|
|
|
27
30
|
//#endregion
|
|
28
|
-
export { isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable };
|
|
31
|
+
export { isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable, withNullPrototype };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isMovable, kRequestCountField, kResponseCountField, kTransferable, kValue } from "../common-
|
|
1
|
+
import { isMovable, kRequestCountField, kResponseCountField, kTransferable, kValue } from "../common-Bo3KCGim.js";
|
|
2
2
|
import { stderr, stdout } from "../utils-De75vAgL.js";
|
|
3
3
|
import { getHandler, throwInNextTick } from "../utils-B--2TaWv.js";
|
|
4
4
|
import { parentPort, receiveMessageOnPort, workerData } from "node:worker_threads";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { MessagePort, TransferListItem } from "node:worker_threads";
|
|
3
3
|
import { EventEmitterAsyncResource } from "node:events";
|
|
4
|
+
import { URL } from "node:url";
|
|
5
|
+
import { SerializationType } from "node:child_process";
|
|
4
6
|
|
|
5
7
|
//#region src/common.d.ts
|
|
6
8
|
/** Channel for communicating between main thread and workers */
|
|
@@ -22,6 +24,7 @@ interface TinypoolWorker {
|
|
|
22
24
|
resourceLimits?: any;
|
|
23
25
|
workerData: TinypoolData;
|
|
24
26
|
trackUnmanagedFds?: boolean;
|
|
27
|
+
serialization?: SerializationType;
|
|
25
28
|
}): void;
|
|
26
29
|
terminate(): Promise<any>;
|
|
27
30
|
postMessage(message: any, transferListItem?: TransferListItem[]): void;
|
|
@@ -74,6 +77,7 @@ declare const kQueueOptions: unique symbol;
|
|
|
74
77
|
declare function isTransferable(value: any): boolean;
|
|
75
78
|
declare function isMovable(value: any): boolean;
|
|
76
79
|
declare function markMovable(value: object): void;
|
|
80
|
+
declare function withNullPrototype<T extends object>(source: T): T;
|
|
77
81
|
interface Transferable {
|
|
78
82
|
readonly [kTransferable]: object;
|
|
79
83
|
readonly [kValue]: object;
|
|
@@ -124,7 +128,7 @@ type ResourceLimits = Worker extends {
|
|
|
124
128
|
resourceLimits?: infer T;
|
|
125
129
|
} ? T : object;
|
|
126
130
|
interface Options {
|
|
127
|
-
filename?: string | null;
|
|
131
|
+
filename?: string | URL | null;
|
|
128
132
|
runtime?: 'worker_threads' | 'child_process';
|
|
129
133
|
name?: string;
|
|
130
134
|
minThreads?: number;
|
|
@@ -144,6 +148,7 @@ interface Options {
|
|
|
144
148
|
trackUnmanagedFds?: boolean;
|
|
145
149
|
isolateWorkers?: boolean;
|
|
146
150
|
teardown?: string;
|
|
151
|
+
serialization?: SerializationType;
|
|
147
152
|
}
|
|
148
153
|
interface FilledOptions extends Options {
|
|
149
154
|
filename: string | null;
|
|
@@ -160,7 +165,7 @@ interface FilledOptions extends Options {
|
|
|
160
165
|
interface RunOptions {
|
|
161
166
|
transferList?: TransferList;
|
|
162
167
|
channel?: TinypoolChannel;
|
|
163
|
-
filename?: string | null;
|
|
168
|
+
filename?: string | URL | null;
|
|
164
169
|
signal?: AbortSignalAny | null;
|
|
165
170
|
name?: string | null;
|
|
166
171
|
runtime?: Options['runtime'];
|
|
@@ -171,7 +176,7 @@ type TransferList = MessagePort extends {
|
|
|
171
176
|
type TransferListItem$1 = TransferList extends (infer T)[] ? T : never;
|
|
172
177
|
declare class Tinypool extends EventEmitterAsyncResource {
|
|
173
178
|
#private;
|
|
174
|
-
constructor(
|
|
179
|
+
constructor(_options?: Options);
|
|
175
180
|
run(task: any, options?: RunOptions): Promise<any>;
|
|
176
181
|
destroy(): Promise<void>;
|
|
177
182
|
get options(): FilledOptions;
|
|
@@ -192,4 +197,4 @@ declare class Tinypool extends EventEmitterAsyncResource {
|
|
|
192
197
|
declare const _workerId: number;
|
|
193
198
|
|
|
194
199
|
//#endregion
|
|
195
|
-
export { Options, ReadyMessage, RequestMessage, ResponseMessage, StartupMessage, Task, TaskQueue, Tinypool, TinypoolChannel, TinypoolData, TinypoolPrivateData, TinypoolWorker, TinypoolWorkerMessage, Transferable, Tinypool as default, isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable, _workerId as workerId };
|
|
200
|
+
export { Options, ReadyMessage, RequestMessage, ResponseMessage, StartupMessage, Task, TaskQueue, Tinypool, TinypoolChannel, TinypoolData, TinypoolPrivateData, TinypoolWorker, TinypoolWorkerMessage, Transferable, Tinypool as default, isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable, withNullPrototype, _workerId as workerId };
|
|
@@ -1,55 +1,15 @@
|
|
|
1
|
-
import { isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable } from "./common-
|
|
1
|
+
import { isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable, withNullPrototype } from "./common-Bo3KCGim.js";
|
|
2
2
|
import { MessageChannel, MessagePort, Worker, receiveMessageOnPort } from "node:worker_threads";
|
|
3
3
|
import { EventEmitterAsyncResource, once } from "node:events";
|
|
4
4
|
import { AsyncResource } from "node:async_hooks";
|
|
5
5
|
import { URL, fileURLToPath } from "node:url";
|
|
6
|
-
import { join } from "node:path";
|
|
7
6
|
import { inspect, types } from "node:util";
|
|
8
7
|
import assert from "node:assert";
|
|
9
8
|
import { performance } from "node:perf_hooks";
|
|
10
9
|
import { readFileSync } from "node:fs";
|
|
11
|
-
import
|
|
12
|
-
import
|
|
10
|
+
import { availableParallelism } from "node:os";
|
|
11
|
+
import { fork } from "node:child_process";
|
|
13
12
|
|
|
14
|
-
//#region src/physicalCpuCount.ts
|
|
15
|
-
function exec(command) {
|
|
16
|
-
const output = childProcess.execSync(command, {
|
|
17
|
-
encoding: "utf8",
|
|
18
|
-
stdio: [
|
|
19
|
-
null,
|
|
20
|
-
null,
|
|
21
|
-
null
|
|
22
|
-
]
|
|
23
|
-
});
|
|
24
|
-
return output;
|
|
25
|
-
}
|
|
26
|
-
let amount;
|
|
27
|
-
try {
|
|
28
|
-
const platform = os.platform();
|
|
29
|
-
if (platform === "linux") {
|
|
30
|
-
const output1 = exec("cat /proc/cpuinfo | grep \"physical id\" | sort |uniq | wc -l");
|
|
31
|
-
const output2 = exec("cat /proc/cpuinfo | grep \"core id\" | sort | uniq | wc -l");
|
|
32
|
-
const physicalCpuAmount = parseInt(output1.trim(), 10);
|
|
33
|
-
const physicalCoreAmount = parseInt(output2.trim(), 10);
|
|
34
|
-
amount = physicalCpuAmount * physicalCoreAmount;
|
|
35
|
-
} else if (platform === "darwin") {
|
|
36
|
-
const output = exec("sysctl -n hw.physicalcpu_max");
|
|
37
|
-
amount = parseInt(output.trim(), 10);
|
|
38
|
-
} else if (platform === "win32") throw new Error();
|
|
39
|
-
else {
|
|
40
|
-
const cores = os.cpus().filter(function(cpu, index) {
|
|
41
|
-
const hasHyperthreading = cpu.model.includes("Intel");
|
|
42
|
-
const isOdd = index % 2 === 1;
|
|
43
|
-
return !hasHyperthreading || isOdd;
|
|
44
|
-
});
|
|
45
|
-
amount = cores.length;
|
|
46
|
-
}
|
|
47
|
-
} catch {
|
|
48
|
-
amount = os.cpus().length;
|
|
49
|
-
}
|
|
50
|
-
if (amount === 0) amount = os.cpus().length;
|
|
51
|
-
|
|
52
|
-
//#endregion
|
|
53
13
|
//#region src/runtime/thread-worker.ts
|
|
54
14
|
var ThreadWorker = class {
|
|
55
15
|
name = "ThreadWorker";
|
|
@@ -188,7 +148,7 @@ function hasUnref(stream) {
|
|
|
188
148
|
|
|
189
149
|
//#endregion
|
|
190
150
|
//#region src/index.ts
|
|
191
|
-
const cpuCount =
|
|
151
|
+
const cpuCount = availableParallelism();
|
|
192
152
|
function onabort(abortSignal, listener) {
|
|
193
153
|
if ("addEventListener" in abortSignal) abortSignal.addEventListener("abort", listener, { once: true });
|
|
194
154
|
else abortSignal.once("abort", listener);
|
|
@@ -277,6 +237,7 @@ var ArrayBufferViewTransferable = class {
|
|
|
277
237
|
};
|
|
278
238
|
let taskIdCounter = 0;
|
|
279
239
|
function maybeFileURLToPath(filename) {
|
|
240
|
+
if (typeof filename !== "string") return filename.protocol === "file:" ? fileURLToPath(filename) : filename.href;
|
|
280
241
|
return filename.startsWith("file:") ? fileURLToPath(new URL(filename)) : filename;
|
|
281
242
|
}
|
|
282
243
|
var TaskInfo = class extends AsyncResource {
|
|
@@ -506,12 +467,12 @@ var ThreadPool = class {
|
|
|
506
467
|
this.publicInterface = publicInterface;
|
|
507
468
|
this.taskQueue = options.taskQueue || new ArrayTaskQueue();
|
|
508
469
|
const filename = options.filename ? maybeFileURLToPath(options.filename) : null;
|
|
509
|
-
this.options = {
|
|
470
|
+
this.options = withNullPrototype({
|
|
510
471
|
...kDefaultOptions,
|
|
511
472
|
...options,
|
|
512
473
|
filename,
|
|
513
474
|
maxQueue: 0
|
|
514
|
-
};
|
|
475
|
+
});
|
|
515
476
|
if (options.maxThreads !== void 0 && this.options.minThreads >= options.maxThreads) this.options.minThreads = options.maxThreads;
|
|
516
477
|
if (options.minThreads !== void 0 && this.options.maxThreads <= options.minThreads) this.options.maxThreads = options.minThreads;
|
|
517
478
|
if (options.maxQueue === "auto") this.options.maxQueue = this.options.maxThreads ** 2;
|
|
@@ -549,7 +510,8 @@ var ThreadPool = class {
|
|
|
549
510
|
execArgv: this.options.execArgv,
|
|
550
511
|
resourceLimits: this.options.resourceLimits,
|
|
551
512
|
workerData: [tinypoolPrivateData, this.options.workerData],
|
|
552
|
-
trackUnmanagedFds: this.options.trackUnmanagedFds
|
|
513
|
+
trackUnmanagedFds: this.options.trackUnmanagedFds,
|
|
514
|
+
serialization: this.options.serialization
|
|
553
515
|
});
|
|
554
516
|
const onMessage = (message$1) => {
|
|
555
517
|
const { taskId, result } = message$1;
|
|
@@ -636,7 +598,7 @@ var ThreadPool = class {
|
|
|
636
598
|
const { transferList = [], signal = null, channel } = options;
|
|
637
599
|
if (filename == null) filename = this.options.filename;
|
|
638
600
|
if (name == null) name = this.options.name;
|
|
639
|
-
if (typeof filename !== "string") return Promise.reject(Errors.FilenameNotProvided());
|
|
601
|
+
if (typeof filename !== "string" && !(filename instanceof URL)) return Promise.reject(Errors.FilenameNotProvided());
|
|
640
602
|
filename = maybeFileURLToPath(filename);
|
|
641
603
|
let resolve;
|
|
642
604
|
let reject;
|
|
@@ -718,7 +680,8 @@ var ThreadPool = class {
|
|
|
718
680
|
}
|
|
719
681
|
await Promise.all(exitEvents);
|
|
720
682
|
}
|
|
721
|
-
async recycleWorkers(
|
|
683
|
+
async recycleWorkers(_options = {}) {
|
|
684
|
+
const options = withNullPrototype(_options);
|
|
722
685
|
const runtimeChanged = options?.runtime && options.runtime !== this.options.runtime;
|
|
723
686
|
if (options?.runtime) this.options.runtime = options.runtime;
|
|
724
687
|
if (this.options.isolateWorkers && !runtimeChanged) return;
|
|
@@ -735,7 +698,8 @@ var ThreadPool = class {
|
|
|
735
698
|
};
|
|
736
699
|
var Tinypool = class extends EventEmitterAsyncResource {
|
|
737
700
|
#pool;
|
|
738
|
-
constructor(
|
|
701
|
+
constructor(_options = {}) {
|
|
702
|
+
const options = withNullPrototype(_options);
|
|
739
703
|
if (options.minThreads !== void 0 && options.minThreads > 0 && options.minThreads < 1) options.minThreads = Math.max(1, Math.floor(options.minThreads * cpuCount));
|
|
740
704
|
if (options.maxThreads !== void 0 && options.maxThreads > 0 && options.maxThreads < 1) options.maxThreads = Math.max(1, Math.floor(options.maxThreads * cpuCount));
|
|
741
705
|
super({
|
|
@@ -746,7 +710,7 @@ var Tinypool = class extends EventEmitterAsyncResource {
|
|
|
746
710
|
this.#pool = new ThreadPool(this, options);
|
|
747
711
|
}
|
|
748
712
|
run(task, options = kDefaultRunOptions) {
|
|
749
|
-
const { transferList, filename, name, signal, runtime, channel } = options;
|
|
713
|
+
const { transferList, filename, name, signal, runtime, channel } = withNullPrototype(options);
|
|
750
714
|
return this.#pool.runTask(task, {
|
|
751
715
|
transferList,
|
|
752
716
|
filename,
|
|
@@ -792,7 +756,7 @@ var Tinypool = class extends EventEmitterAsyncResource {
|
|
|
792
756
|
return process.__tinypool_state__?.workerData || void 0;
|
|
793
757
|
}
|
|
794
758
|
static get version() {
|
|
795
|
-
const { version } = JSON.parse(readFileSync(
|
|
759
|
+
const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
|
|
796
760
|
return version;
|
|
797
761
|
}
|
|
798
762
|
static move(val) {
|
|
@@ -817,4 +781,4 @@ const _workerId = process.__tinypool_state__?.workerId;
|
|
|
817
781
|
var src_default = Tinypool;
|
|
818
782
|
|
|
819
783
|
//#endregion
|
|
820
|
-
export { Tinypool, src_default as default, isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable, _workerId as workerId };
|
|
784
|
+
export { Tinypool, src_default as default, isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable, withNullPrototype, _workerId as workerId };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinypool",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
5
|
-
"packageManager": "pnpm@9.0.6",
|
|
4
|
+
"version": "2.2.0",
|
|
6
5
|
"description": "A minimal and tiny Node.js Worker Thread Pool implementation, a fork of piscina, but with fewer features",
|
|
7
6
|
"license": "MIT",
|
|
8
7
|
"homepage": "https://github.com/tinylibs/tinypool#readme",
|
|
@@ -31,9 +30,26 @@
|
|
|
31
30
|
"files": [
|
|
32
31
|
"dist"
|
|
33
32
|
],
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^20.12.8",
|
|
35
|
+
"clean-publish": "^3.4.4",
|
|
36
|
+
"eslint": "^9.4.0",
|
|
37
|
+
"eslint-config-prettier": "^9.1.0",
|
|
38
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
39
|
+
"eslint-plugin-unicorn": "^53.0.0",
|
|
40
|
+
"prettier": "^3.3.2",
|
|
41
|
+
"tsdown": "^0.11.3",
|
|
42
|
+
"typescript": "^5.4.5",
|
|
43
|
+
"typescript-eslint": "^7.13.0",
|
|
44
|
+
"vite": "^5.2.11",
|
|
45
|
+
"vitest": "^4.0.1"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"test": "vitest",
|
|
49
|
+
"bench": "vitest bench",
|
|
50
|
+
"dev": "tsdown --watch ./src",
|
|
51
|
+
"build": "tsdown",
|
|
52
|
+
"lint": "eslint --max-warnings=0",
|
|
53
|
+
"typecheck": "tsc --noEmit"
|
|
38
54
|
}
|
|
39
55
|
}
|