@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.
Files changed (317) hide show
  1. package/README.md +11 -1
  2. package/compiled/@rspack/lite-tapable/dist/index.d.ts +190 -0
  3. package/compiled/@rspack/lite-tapable/license +22 -0
  4. package/compiled/@rspack/lite-tapable/package.json +1 -0
  5. package/compiled/@swc/types/index.d.ts +161 -11
  6. package/compiled/@swc/types/package.json +1 -1
  7. package/compiled/connect-next/index.d.ts +57 -0
  8. package/compiled/connect-next/license +26 -0
  9. package/compiled/connect-next/package.json +1 -0
  10. package/compiled/http-proxy-middleware/index.d.ts +455 -0
  11. package/compiled/{browserslist-load-config → http-proxy-middleware}/license +3 -2
  12. package/compiled/http-proxy-middleware/package.json +1 -0
  13. package/compiled/open/index.d.ts +161 -0
  14. package/compiled/open/package.json +1 -0
  15. package/compiled/tinypool/README.md +196 -2
  16. package/compiled/tinypool/dist/{common-Qw-RoVFD.js → common-Bo3KCGim.js} +4 -1
  17. package/compiled/tinypool/dist/entry/worker.js +1 -1
  18. package/compiled/tinypool/dist/index.d.ts +9 -4
  19. package/compiled/tinypool/dist/index.js +17 -53
  20. package/compiled/tinypool/package.json +22 -6
  21. package/compiled/watchpack/index.d.ts +3 -217
  22. package/compiled/watchpack/index.js +1778 -1091
  23. package/compiled/watchpack/package.json +8 -1
  24. package/compiled/watchpack/types/DirectoryWatcher.d.ts +335 -0
  25. package/compiled/watchpack/types/LinkResolver.d.ts +10 -0
  26. package/compiled/watchpack/types/getWatcherManager.d.ts +62 -0
  27. package/compiled/watchpack/types/index.d.ts +269 -0
  28. package/compiled/watchpack/types/reducePlan.d.ts +34 -0
  29. package/compiled/watchpack/types/util/globToRegExp.d.ts +2 -0
  30. package/compiled/watchpack/types/watchEventSource.d.ts +53 -0
  31. package/compiled/watchpack/types/watchpack.d.ts +2 -0
  32. package/compiled/webpack-sources/index.d.ts +61 -0
  33. package/compiled/webpack-sources/index.js +2370 -576
  34. package/compiled/webpack-sources/package.json +8 -1
  35. package/compiled/webpack-sources/types/CachedSource.d.ts +192 -0
  36. package/compiled/webpack-sources/types/CompatSource.d.ts +87 -0
  37. package/compiled/webpack-sources/types/ConcatSource.d.ts +75 -0
  38. package/compiled/webpack-sources/types/OriginalSource.d.ts +87 -0
  39. package/compiled/webpack-sources/types/PrefixSource.d.ts +59 -0
  40. package/compiled/webpack-sources/types/RawSource.d.ts +75 -0
  41. package/compiled/webpack-sources/types/ReplaceSource.d.ts +107 -0
  42. package/compiled/webpack-sources/types/SizeOnlySource.d.ts +24 -0
  43. package/compiled/webpack-sources/types/Source.d.ts +189 -0
  44. package/compiled/webpack-sources/types/SourceMapSource.d.ts +136 -0
  45. package/compiled/webpack-sources/types/helpers/createMappingsSerializer.d.ts +60 -0
  46. package/compiled/webpack-sources/types/helpers/getFromStreamChunks.d.ts +16 -0
  47. package/compiled/webpack-sources/types/helpers/getGeneratedSourceInfo.d.ts +31 -0
  48. package/compiled/webpack-sources/types/helpers/getName.d.ts +15 -0
  49. package/compiled/webpack-sources/types/helpers/getSource.d.ts +15 -0
  50. package/compiled/webpack-sources/types/helpers/readMappings.d.ts +19 -0
  51. package/compiled/webpack-sources/types/helpers/scopes.d.ts +119 -0
  52. package/compiled/webpack-sources/types/helpers/splitIntoLines.d.ts +6 -0
  53. package/compiled/webpack-sources/types/helpers/splitIntoPotentialTokens.d.ts +37 -0
  54. package/compiled/webpack-sources/types/helpers/streamAndGetSourceAndMap.d.ts +39 -0
  55. package/compiled/webpack-sources/types/helpers/streamChunks.d.ts +56 -0
  56. package/compiled/webpack-sources/types/helpers/streamChunksOfCombinedSourceMap.d.ts +42 -0
  57. package/compiled/webpack-sources/types/helpers/streamChunksOfRawSource.d.ts +16 -0
  58. package/compiled/webpack-sources/types/helpers/streamChunksOfSourceMap.d.ts +19 -0
  59. package/compiled/webpack-sources/types/helpers/stringBufferUtils.d.ts +55 -0
  60. package/compiled/webpack-sources/types/index.d.ts +50 -0
  61. package/dist/BuildInfo.d.ts +3 -1
  62. package/dist/ChunkGraph.d.ts +1 -1
  63. package/dist/CodeGenerationResults.d.ts +6 -1
  64. package/dist/Compilation.d.ts +60 -89
  65. package/dist/Compiler.d.ts +25 -22
  66. package/dist/ContextModuleFactory.d.ts +2 -2
  67. package/dist/Diagnostics.d.ts +2 -6
  68. package/dist/ExecuteModulePlugin.d.ts +1 -1
  69. package/dist/ExportsInfo.d.ts +1 -1
  70. package/dist/ExternalModule.d.ts +15 -1
  71. package/dist/FileSystem.d.ts +4 -2
  72. package/dist/FileSystemDependencies.d.ts +15 -0
  73. package/dist/Module.d.ts +9 -6
  74. package/dist/ModuleGraph.d.ts +11 -8
  75. package/dist/ModuleGraphConnection.d.ts +10 -0
  76. package/dist/Modules.d.ts +3 -0
  77. package/dist/MultiCompiler.d.ts +9 -9
  78. package/dist/MultiStats.d.ts +3 -3
  79. package/dist/MultiWatching.d.ts +3 -3
  80. package/dist/NativeWatchFileSystem.d.ts +31 -2
  81. package/dist/NormalModule.d.ts +4 -5
  82. package/dist/NormalModuleFactory.d.ts +5 -4
  83. package/dist/Resolver.d.ts +10 -2
  84. package/dist/ResolverFactory.d.ts +2 -2
  85. package/dist/RuntimeGlobals.d.ts +61 -56
  86. package/dist/RuntimeModule.d.ts +3 -3
  87. package/dist/RuntimeTemplate.d.ts +151 -0
  88. package/dist/Stats.d.ts +4 -4
  89. package/dist/VirtualModulesPlugin.d.ts +1 -1
  90. package/dist/Watching.d.ts +5 -5
  91. package/dist/builtin-loader/lightningcss/index.d.ts +11 -14
  92. package/dist/builtin-loader/lightningcss/target.d.ts +4 -0
  93. package/dist/builtin-loader/swc/index.d.ts +3 -5
  94. package/dist/builtin-loader/swc/pluginImport.d.ts +1 -1
  95. package/dist/builtin-loader/swc/types.d.ts +36 -65
  96. package/dist/builtin-plugin/APIPlugin.d.ts +3 -3
  97. package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +3 -3
  98. package/dist/builtin-plugin/AssetModulesPlugin.d.ts +3 -3
  99. package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +3 -3
  100. package/dist/builtin-plugin/BannerPlugin.d.ts +3 -3
  101. package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +3 -3
  102. package/dist/builtin-plugin/CaseSensitivePlugin.d.ts +3 -3
  103. package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +3 -3
  104. package/dist/builtin-plugin/CircularCheckRspackPlugin.d.ts +33 -0
  105. package/dist/builtin-plugin/CircularDependencyRspackPlugin.d.ts +10 -4
  106. package/dist/builtin-plugin/CircularModulesInfoPlugin.d.ts +7 -0
  107. package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +3 -3
  108. package/dist/builtin-plugin/CompactHashedChunkIdsPlugin.d.ts +12 -0
  109. package/dist/builtin-plugin/CompactHashedModuleIdsPlugin.d.ts +12 -0
  110. package/dist/builtin-plugin/ContextReplacementPlugin.d.ts +3 -3
  111. package/dist/builtin-plugin/CopyRspackPlugin.d.ts +3 -3
  112. package/dist/builtin-plugin/CssChunkingPlugin.d.ts +3 -3
  113. package/dist/builtin-plugin/CssHttpExternalsRspackPlugin.d.ts +9 -0
  114. package/dist/builtin-plugin/CssModulesPlugin.d.ts +3 -3
  115. package/dist/builtin-plugin/DataUriPlugin.d.ts +3 -3
  116. package/dist/builtin-plugin/DefinePlugin.d.ts +3 -3
  117. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +2 -2
  118. package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +13 -2
  119. package/dist/builtin-plugin/DllEntryPlugin.d.ts +3 -3
  120. package/dist/builtin-plugin/DllReferenceAgencyPlugin.d.ts +3 -3
  121. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +4 -4
  122. package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +3 -3
  123. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +2 -2
  124. package/dist/builtin-plugin/EnableLibraryPlugin.d.ts +2 -2
  125. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +3 -3
  126. package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +3 -3
  127. package/dist/builtin-plugin/EntryPlugin.d.ts +4 -4
  128. package/dist/builtin-plugin/EsmLibraryPlugin.d.ts +7 -2
  129. package/dist/builtin-plugin/EsmNodeTargetPlugin.d.ts +9 -0
  130. package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +3 -3
  131. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +3 -3
  132. package/dist/builtin-plugin/ExternalsPlugin.d.ts +4 -3
  133. package/dist/builtin-plugin/FetchCompileAsyncWasmPlugin.d.ts +3 -3
  134. package/dist/builtin-plugin/FileUriPlugin.d.ts +3 -3
  135. package/dist/builtin-plugin/FlagAllModulesAsUsedPlugin.d.ts +3 -3
  136. package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +3 -3
  137. package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +2 -2
  138. package/dist/builtin-plugin/HashedModuleIdsPlugin.d.ts +10 -0
  139. package/dist/builtin-plugin/HotModuleReplacementPlugin.d.ts +2 -2
  140. package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +5 -5
  141. package/dist/builtin-plugin/HttpUriPlugin.d.ts +7 -3
  142. package/dist/builtin-plugin/IgnorePlugin.d.ts +3 -3
  143. package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +3 -3
  144. package/dist/builtin-plugin/InlineExportsPlugin.d.ts +3 -3
  145. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +21 -6
  146. package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +2 -2
  147. package/dist/builtin-plugin/JsonModulesPlugin.d.ts +3 -3
  148. package/dist/builtin-plugin/LibManifestPlugin.d.ts +3 -3
  149. package/dist/builtin-plugin/LightningCssMinimizerRspackPlugin.d.ts +7 -11
  150. package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +3 -3
  151. package/dist/builtin-plugin/MangleExportsPlugin.d.ts +2 -2
  152. package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +3 -3
  153. package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +3 -3
  154. package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +2 -2
  155. package/dist/builtin-plugin/ModuleInfoHeaderPlugin.d.ts +3 -3
  156. package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +3 -3
  157. package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +3 -3
  158. package/dist/builtin-plugin/NaturalChunkIdsPlugin.d.ts +2 -2
  159. package/dist/builtin-plugin/NaturalModuleIdsPlugin.d.ts +2 -2
  160. package/dist/builtin-plugin/NoEmitOnErrorsPlugin.d.ts +3 -3
  161. package/dist/builtin-plugin/NodeTargetPlugin.d.ts +3 -3
  162. package/dist/builtin-plugin/NormalModuleReplacementPlugin.d.ts +4 -4
  163. package/dist/builtin-plugin/OccurrenceChunkIdsPlugin.d.ts +3 -3
  164. package/dist/builtin-plugin/ProgressPlugin.d.ts +8 -7
  165. package/dist/builtin-plugin/ProvidePlugin.d.ts +3 -3
  166. package/dist/builtin-plugin/RealContentHashPlugin.d.ts +15 -4
  167. package/dist/builtin-plugin/RemoveDuplicateModulesPlugin.d.ts +3 -3
  168. package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +3 -3
  169. package/dist/builtin-plugin/RsdoctorPlugin.d.ts +8 -11
  170. package/dist/builtin-plugin/RslibPlugin.d.ts +5 -6
  171. package/dist/builtin-plugin/RstestPlugin.d.ts +3 -4
  172. package/dist/builtin-plugin/RuntimeChunkPlugin.d.ts +3 -3
  173. package/dist/builtin-plugin/RuntimePlugin.d.ts +7 -11
  174. package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +9 -9
  175. package/dist/builtin-plugin/SizeLimitsPlugin.d.ts +5 -5
  176. package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +3 -3
  177. package/dist/builtin-plugin/SplitChunksPlugin.d.ts +6 -5
  178. package/dist/builtin-plugin/SubresourceIntegrityPlugin.d.ts +2 -2
  179. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +7 -6
  180. package/dist/builtin-plugin/SyncModuleIdsPlugin.d.ts +16 -0
  181. package/dist/builtin-plugin/URLPlugin.d.ts +3 -3
  182. package/dist/builtin-plugin/WorkerPlugin.d.ts +4 -4
  183. package/dist/builtin-plugin/base.d.ts +3 -3
  184. package/dist/builtin-plugin/css-extract/index.d.ts +3 -3
  185. package/dist/builtin-plugin/css-extract/loader.d.ts +1 -1
  186. package/dist/builtin-plugin/css-extract/utils.d.ts +8 -1
  187. package/dist/builtin-plugin/html-plugin/hooks.d.ts +3 -3
  188. package/dist/builtin-plugin/html-plugin/index.d.ts +2 -2
  189. package/dist/builtin-plugin/html-plugin/options.d.ts +2 -7
  190. package/dist/builtin-plugin/html-plugin/plugin.d.ts +5 -9
  191. package/dist/builtin-plugin/html-plugin/taps.d.ts +1 -1
  192. package/dist/builtin-plugin/index.d.ts +92 -84
  193. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +6 -6
  194. package/dist/builtin-plugin/lazy-compilation/middleware.d.ts +4 -4
  195. package/dist/builtin-plugin/rsc/Coordinator.d.ts +8 -0
  196. package/dist/builtin-plugin/rsc/RscClientPlugin.d.ts +13 -0
  197. package/dist/builtin-plugin/rsc/RscServerPlugin.d.ts +47 -0
  198. package/dist/builtin-plugin/rsc/index.d.ts +24 -0
  199. package/dist/checkNodeVersion.d.ts +1 -0
  200. package/dist/config/adapter.d.ts +4 -4
  201. package/dist/config/adapterRuleUse.d.ts +89 -55
  202. package/dist/config/browserslistTargetHandler.d.ts +1 -1
  203. package/dist/config/defaults.d.ts +5 -3
  204. package/dist/config/devServer.d.ts +103 -238
  205. package/dist/config/index.d.ts +5 -5
  206. package/dist/config/normalization.d.ts +26 -47
  207. package/dist/config/target.d.ts +19 -12
  208. package/dist/config/types.d.ts +615 -256
  209. package/dist/container/ContainerPlugin.d.ts +4 -4
  210. package/dist/container/ContainerReferencePlugin.d.ts +4 -4
  211. package/dist/container/ModuleFederationManifestPlugin.d.ts +12 -5
  212. package/dist/container/ModuleFederationPlugin.d.ts +22 -5
  213. package/dist/container/ModuleFederationPluginV1.d.ts +10 -6
  214. package/dist/container/ModuleFederationRuntimePlugin.d.ts +3 -3
  215. package/dist/cssExtractHmr.js +2 -27
  216. package/dist/cssExtractLoader.js +24 -65
  217. package/dist/exports.d.ts +98 -84
  218. package/dist/index.d.ts +4 -3
  219. package/dist/index.js +14201 -11810
  220. package/dist/lib/AbstractMethodError.d.ts +1 -1
  221. package/dist/lib/Cache.d.ts +5 -2
  222. package/dist/lib/CacheFacade.d.ts +4 -4
  223. package/dist/lib/DllPlugin.d.ts +2 -2
  224. package/dist/lib/DllReferencePlugin.d.ts +3 -3
  225. package/dist/lib/EntryOptionPlugin.d.ts +2 -2
  226. package/dist/lib/EnvironmentPlugin.d.ts +3 -3
  227. package/dist/lib/HookWebpackError.d.ts +2 -3
  228. package/dist/lib/IgnoreWarningsPlugin.d.ts +1 -1
  229. package/dist/lib/LoaderOptionsPlugin.d.ts +2 -2
  230. package/dist/lib/LoaderTargetPlugin.d.ts +2 -2
  231. package/dist/lib/WebpackError.d.ts +2 -2
  232. package/dist/lib/cache/MemoryCachePlugin.d.ts +1 -1
  233. package/dist/lib/cache/getLazyHashedEtag.d.ts +2 -2
  234. package/dist/lib/cache/mergeEtags.d.ts +1 -2
  235. package/dist/loader-runner/ModuleError.d.ts +1 -1
  236. package/dist/loader-runner/cache.d.ts +27 -0
  237. package/dist/loader-runner/dependencies.d.ts +23 -0
  238. package/dist/loader-runner/index.d.ts +10 -11
  239. package/dist/loader-runner/loadLoader.d.ts +2 -2
  240. package/dist/loader-runner/service.d.ts +10 -1
  241. package/dist/loader-runner/utils.d.ts +3 -3
  242. package/dist/loader-runner/worker.d.ts +1 -1
  243. package/dist/logging/createConsoleLogger.d.ts +2 -2
  244. package/dist/l~0.js +34 -0
  245. package/dist/l~3.js +34 -0
  246. package/dist/moduleFederationDefaultRuntime.js +1 -1
  247. package/dist/node/NodeEnvironmentPlugin.d.ts +2 -2
  248. package/dist/node/NodeTemplatePlugin.d.ts +1 -1
  249. package/dist/node/NodeWatchFileSystem.d.ts +15 -3
  250. package/dist/node/nodeConsole.d.ts +1 -1
  251. package/dist/rspack.d.ts +7 -8
  252. package/dist/rspackOptionsApply.d.ts +1 -1
  253. package/dist/runtime/cssExtractHmr.d.ts +2 -2
  254. package/dist/runtime/moduleFederationDefaultRuntime.d.ts +1 -2
  255. package/dist/sharing/CollectSharedEntryPlugin.d.ts +22 -0
  256. package/dist/sharing/ConsumeSharedPlugin.d.ts +18 -6
  257. package/dist/sharing/IndependentSharedPlugin.d.ts +37 -0
  258. package/dist/sharing/ProvideSharedPlugin.d.ts +22 -3
  259. package/dist/sharing/SharePlugin.d.ts +51 -3
  260. package/dist/sharing/ShareRuntimePlugin.d.ts +2 -2
  261. package/dist/sharing/SharedContainerPlugin.d.ts +23 -0
  262. package/dist/sharing/SharedUsedExportsOptimizerPlugin.d.ts +14 -0
  263. package/dist/sharing/TreeShakingSharedPlugin.d.ts +19 -0
  264. package/dist/sharing/utils.d.ts +1 -0
  265. package/dist/stats/DefaultStatsFactoryPlugin.d.ts +1 -1
  266. package/dist/stats/DefaultStatsPresetPlugin.d.ts +1 -1
  267. package/dist/stats/DefaultStatsPrinterPlugin.d.ts +1 -1
  268. package/dist/stats/StatsFactory.d.ts +7 -5
  269. package/dist/stats/StatsPrinter.d.ts +7 -7
  270. package/dist/stats/statsFactoryUtils.d.ts +15 -19
  271. package/dist/swc.d.ts +2 -2
  272. package/dist/taps/compilation.d.ts +1 -1
  273. package/dist/taps/compiler.d.ts +1 -1
  274. package/dist/taps/contextModuleFactory.d.ts +1 -1
  275. package/dist/taps/externalModule.d.ts +2 -0
  276. package/dist/taps/index.d.ts +7 -6
  277. package/dist/taps/javascriptModules.d.ts +1 -1
  278. package/dist/taps/normalModuleFactory.d.ts +1 -1
  279. package/dist/taps/types.d.ts +2 -2
  280. package/dist/trace/index.d.ts +1 -0
  281. package/dist/trace/traceHookPlugin.d.ts +1 -1
  282. package/dist/util/bindingHelpers.d.ts +7 -0
  283. package/dist/util/comparators.d.ts +1 -1
  284. package/dist/util/createHash.d.ts +2 -2
  285. package/dist/util/fs.d.ts +19 -18
  286. package/dist/util/hash/md4.d.ts +1 -1
  287. package/dist/util/hash/xxhash64.d.ts +1 -1
  288. package/dist/util/identifier.d.ts +35 -9
  289. package/dist/util/index.d.ts +2 -2
  290. package/dist/util/source.d.ts +3 -3
  291. package/dist/util/supportsColor.d.ts +6 -0
  292. package/dist/util/targetsVersion.d.ts +2 -0
  293. package/dist/util/validateConfig.d.ts +1 -1
  294. package/dist/util/watchTimeInfo.d.ts +7 -0
  295. package/dist/web/JsonpTemplatePlugin.d.ts +13 -0
  296. package/dist/webworker/WebWorkerTemplatePlugin.d.ts +13 -0
  297. package/dist/worker.js +935 -907
  298. package/hot/dev-server.js +12 -11
  299. package/hot/emitter.js +3 -1
  300. package/hot/lazy-compilation-node.js +4 -1
  301. package/hot/lazy-compilation-web.js +2 -3
  302. package/hot/log-apply-result.js +8 -5
  303. package/hot/log.js +18 -10
  304. package/hot/only-dev-server.js +13 -12
  305. package/hot/poll.js +10 -9
  306. package/hot/signal.js +12 -10
  307. package/module.d.ts +39 -2
  308. package/package.json +15 -39
  309. package/compiled/browserslist-load-config/index.d.ts +0 -21
  310. package/compiled/browserslist-load-config/index.js +0 -252
  311. package/compiled/browserslist-load-config/package.json +0 -1
  312. package/compiled/webpack-sources/types.d.ts +0 -458
  313. package/dist/builtin-loader/index.d.ts +0 -1
  314. package/dist/builtin-plugin/WebWorkerTemplatePlugin.d.ts +0 -7
  315. package/dist/container/index.d.ts +0 -4
  316. package/dist/util/MergeCaller.d.ts +0 -10
  317. 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
- ## Docs
20
- Read **[full docs](https://github.com/tinylibs/tinypool#readme)** on GitHub.
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-Qw-RoVFD.js";
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(options?: Options);
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-Qw-RoVFD.js";
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 os from "node:os";
12
- import childProcess, { fork } from "node:child_process";
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 = amount;
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(options = {}) {
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(options = {}) {
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(join(__dirname, "../package.json"), "utf-8"));
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": "1.1.1",
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
- "pnpm": {
35
- "overrides": {
36
- "vitest>tinypool": "link:./"
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
  }