vivth 1.4.10 → 1.5.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 (379) hide show
  1. package/README.md +6060 -2037
  2. package/README.src.md +22 -14
  3. package/bun.lock +154 -194
  4. package/dev/auto/.src.ignore +25 -0
  5. package/dev/auto-doc.mjs +137 -0
  6. package/generated/types/generated/vivth/exports/all.d.mts +145 -0
  7. package/generated/types/generated/vivth/exports/neutral.d.mts +105 -0
  8. package/generated/types/generated/vivth/exports/node.d.mts +40 -0
  9. package/generated/types/src/bundler/CompileAS.d.mts +30 -0
  10. package/generated/types/src/bundler/CompileJS.d.mts +109 -0
  11. package/{types → generated/types}/src/bundler/CreateESPlugin.d.mts +1 -1
  12. package/{types → generated/types}/src/bundler/EsBundler.d.mts +9 -7
  13. package/generated/types/src/bundler/FSAnalyzer.d.mts +58 -0
  14. package/generated/types/src/bundler/FSasar.bundled.d.mts +28 -0
  15. package/generated/types/src/bundler/FSasar.d.mts +51 -0
  16. package/generated/types/src/bundler/FileSelfMapper.d.mts +137 -0
  17. package/generated/types/src/bundler/JSDirMapper.d.mts +128 -0
  18. package/generated/types/src/bundler/RunWatchThenCompileJSOnSafeExit.d.mts +63 -0
  19. package/generated/types/src/bundler/adds/BrowserExternals.d.mts +21 -0
  20. package/generated/types/src/bundler/adds/CreateTransform.d.mts +26 -0
  21. package/generated/types/src/bundler/adds/LastEditedUnix.d.mts +5 -0
  22. package/generated/types/src/bundler/adds/NodeModuleList.d.mts +15 -0
  23. package/generated/types/src/bundler/adds/PathFSBundles.bundled.d.mts +25 -0
  24. package/generated/types/src/bundler/adds/PathFSBundles.d.mts +48 -0
  25. package/generated/types/src/bundler/adds/PathFSDir.bundled.d.mts +30 -0
  26. package/generated/types/src/bundler/adds/PathFSDir.d.mts +48 -0
  27. package/generated/types/src/bundler/adds/PathFSFile.bundled.d.mts +25 -0
  28. package/generated/types/src/bundler/adds/PathFSFile.d.mts +40 -0
  29. package/{types → generated/types}/src/bundler/adds/ToBundledJSPlugin.d.mts +6 -6
  30. package/generated/types/src/bundler/adds/autoExternalize.d.mts +2 -0
  31. package/generated/types/src/bundler/adds/emptyBufferValue.d.mts +1 -0
  32. package/generated/types/src/bundler/adds/isModuleTheBundledVersion.d.mts +1 -0
  33. package/generated/types/src/bundler/adds/onEndEsBuildErrorLogger.d.mts +1 -0
  34. package/generated/types/src/bundler/adds/resolveJSDependencyPath.d.mts +1 -0
  35. package/generated/types/src/class/AwaitSignal.d.mts +48 -0
  36. package/generated/types/src/class/Console.d.mts +82 -0
  37. package/generated/types/src/class/DataLog.d.mts +25 -0
  38. package/generated/types/src/class/Derived.d.mts +74 -0
  39. package/generated/types/src/class/Effect.d.mts +213 -0
  40. package/{types → generated/types}/src/class/EnvSignal.d.mts +6 -2
  41. package/generated/types/src/class/EsWatcher.d.mts +36 -0
  42. package/{types → generated/types}/src/class/EventSignal.d.mts +39 -39
  43. package/generated/types/src/class/FSDirArchWatcher.d.mts +110 -0
  44. package/{types → generated/types}/src/class/FileSafe.d.mts +32 -16
  45. package/generated/types/src/class/ForEach.d.mts +57 -0
  46. package/generated/types/src/class/ForSignal.d.mts +63 -0
  47. package/generated/types/src/class/GetterSetter.d.mts +38 -0
  48. package/generated/types/src/class/JSONFileHandler.d.mts +50 -0
  49. package/{types → generated/types}/src/class/ListSignal.d.mts +49 -15
  50. package/{types → generated/types}/src/class/LitExp.d.mts +18 -18
  51. package/generated/types/src/class/ObjectSignal.d.mts +267 -0
  52. package/generated/types/src/class/Paths.d.mts +95 -0
  53. package/generated/types/src/class/Prettivy.d.mts +26 -0
  54. package/{types → generated/types}/src/class/QChannel.d.mts +24 -16
  55. package/generated/types/src/class/SafeExit.d.mts +69 -0
  56. package/{types → generated/types}/src/class/Setup.d.mts +29 -16
  57. package/{types → generated/types}/src/class/Signal.d.mts +29 -15
  58. package/generated/types/src/class/SignalCollection.d.mts +96 -0
  59. package/{types → generated/types}/src/class/WalkThrough.d.mts +4 -19
  60. package/generated/types/src/class/WorkerMainThread.bundled.d.mts +83 -0
  61. package/{types → generated/types}/src/class/WorkerMainThread.d.mts +33 -39
  62. package/{types → generated/types}/src/class/WorkerThread.d.mts +11 -5
  63. package/{types → generated/types}/src/common/Base64URL.d.mts +2 -1
  64. package/generated/types/src/common/Base64URLFromFile.d.mts +20 -0
  65. package/generated/types/src/common/BundledV.bundled.d.mts +3 -0
  66. package/generated/types/src/common/BundledV.d.mts +36 -0
  67. package/{types → generated/types}/src/common/CreateStringID.d.mts +5 -4
  68. package/generated/types/src/common/EnvMode.d.mts +79 -0
  69. package/generated/types/src/common/FactoryKey.d.mts +9 -0
  70. package/generated/types/src/common/Preferrence.d.mts +25 -0
  71. package/{types → generated/types}/src/common/Trace.d.mts +1 -1
  72. package/{types → generated/types}/src/common/TracePath.d.mts +1 -1
  73. package/generated/types/src/common/VivthUnBundledCodeBlock.d.mts +6 -0
  74. package/generated/types/src/doc/JSautoDOC.d.mts +172 -0
  75. package/generated/types/src/doc/cleanPreserveTypedef.d.mts +1 -0
  76. package/{types/src/doc/parsedFile.d.mts → generated/types/src/doc/parsedFileForDOC.d.mts} +56 -27
  77. package/generated/types/src/function/ClearRequireCache.d.mts +1 -0
  78. package/{types → generated/types}/src/function/CreateImmutable.d.mts +5 -4
  79. package/{types → generated/types}/src/function/EventCheck.d.mts +3 -1
  80. package/{types → generated/types}/src/function/EventObject.d.mts +2 -6
  81. package/generated/types/src/function/ForInAsync.d.mts +36 -0
  82. package/generated/types/src/function/ForInSync.d.mts +36 -0
  83. package/generated/types/src/function/ForOfAsync.d.mts +25 -0
  84. package/generated/types/src/function/ForOfSync.d.mts +36 -0
  85. package/generated/types/src/function/GetBufferFromRelativePath.d.mts +15 -0
  86. package/generated/types/src/function/GetFilesFromDir.d.mts +14 -0
  87. package/generated/types/src/function/GetMaxFilenameLength.d.mts +9 -0
  88. package/generated/types/src/function/GetModuleEsbuildPlatform.d.mts +13 -0
  89. package/{types → generated/types}/src/function/GetNamedImportAlias.d.mts +1 -1
  90. package/generated/types/src/function/GetRuntime.d.mts +2 -0
  91. package/generated/types/src/function/InstantiateAssemblyScript.d.mts +15 -0
  92. package/{types → generated/types}/src/function/IsAsync.d.mts +1 -1
  93. package/generated/types/src/function/IsInstanceOf.d.mts +25 -0
  94. package/generated/types/src/function/IsSameFile.d.mts +16 -0
  95. package/generated/types/src/function/IsStringLooksLikeAPath.d.mts +16 -0
  96. package/generated/types/src/function/IsTypeOf.d.mts +25 -0
  97. package/{types → generated/types}/src/function/LazyFactory.d.mts +9 -10
  98. package/generated/types/src/function/MonkeyPatch.d.mts +33 -0
  99. package/generated/types/src/function/NewAnimationTimeline.d.mts +24 -0
  100. package/generated/types/src/function/NewChainable.d.mts +35 -0
  101. package/generated/types/src/function/NewDynamicsExport.d.mts +49 -0
  102. package/generated/types/src/function/NewObjectWrapper.d.mts +10 -0
  103. package/generated/types/src/function/ObjectRegistrar.d.mts +17 -0
  104. package/generated/types/src/function/ParseSQLFile.d.mts +25 -0
  105. package/generated/types/src/function/PipeAsync.d.mts +19 -0
  106. package/generated/types/src/function/PipeSync.d.mts +17 -0
  107. package/generated/types/src/function/SafeImport.d.mts +21 -0
  108. package/generated/types/src/function/TemplateLiteral.d.mts +23 -0
  109. package/{types → generated/types}/src/function/Timeout.d.mts +1 -1
  110. package/{types → generated/types}/src/function/Tries.d.mts +4 -4
  111. package/{types → generated/types}/src/function/TryAsync.d.mts +2 -2
  112. package/{types → generated/types}/src/function/TryNew.d.mts +1 -1
  113. package/generated/types/src/function/TsToMjs.d.mts +27 -0
  114. package/generated/types/src/function/UniqueFSTempName.d.mts +9 -0
  115. package/generated/types/src/function/errorToMessage.d.mts +5 -0
  116. package/generated/types/src/neinth/VivthyNeinth.d.mts +202 -0
  117. package/generated/types/src/typehints/ArrayToKeys.d.mts +23 -0
  118. package/generated/types/src/typehints/AssemblyScriptExportsType.d.mts +4 -0
  119. package/generated/types/src/typehints/AssemblyScriptLoaderInstantiate.d.mts +4 -0
  120. package/generated/types/src/typehints/AutoDocASOptions.d.mts +15 -0
  121. package/generated/types/src/typehints/ChainableType.d.mts +3 -0
  122. package/generated/types/src/typehints/ComponentDecorator_Constructor.d.mts +3 -0
  123. package/generated/types/src/typehints/ConsoleAdditionalSettingType.d.mts +3 -0
  124. package/generated/types/src/typehints/Decorator.d.mts +11 -0
  125. package/generated/types/src/typehints/DecoratorMonkeyPatch.d.mts +15 -0
  126. package/{types/src/types → generated/types/src/typehints}/DevTestCB.d.mts +2 -2
  127. package/generated/types/src/typehints/EnvModeType.d.mts +4 -0
  128. package/generated/types/src/typehints/ListArg.d.mts +4 -0
  129. package/generated/types/src/typehints/MonkeyPatchedType.d.mts +1 -0
  130. package/generated/types/src/typehints/ParametersFollowingN.d.mts +13 -0
  131. package/generated/types/src/typehints/PrefixedKeysOf.d.mts +1 -0
  132. package/generated/types/src/typehints/Runtime.d.mts +4 -0
  133. package/generated/types/src/typehints/SafeImportReturnType.d.mts +1 -0
  134. package/generated/types/src/typehints/StylePropRefType.d.mts +2 -0
  135. package/generated/types/src/typehints/TemplateLiteralValueHandler.d.mts +10 -0
  136. package/generated/types/src/typehints/VLifecycleCallbacks.d.mts +6 -0
  137. package/generated/types/src/typehints/VivthCleanup.d.mts +12 -0
  138. package/generated/types/src/web/BrowserDirMapper.d.mts +70 -0
  139. package/generated/types/src/web/EnsureValidTag.d.mts +7 -0
  140. package/generated/types/src/web/ViteAddDynamics.d.mts +28 -0
  141. package/generated/types/src/web/ViteGetAllHTMLFile.d.mts +9 -0
  142. package/generated/types/src/web/WC_extendsA.d.mts +135 -0
  143. package/generated/types/src/web/WC_extendsB.d.mts +135 -0
  144. package/generated/types/src/web/bindings/WC_StyleProp_bind.d.mts +42 -0
  145. package/generated/types/src/web/bindings/WC_createElement_bind.d.mts +51 -0
  146. package/generated/types/src/web/bindings/WC_createNamedSlot.d.mts +26 -0
  147. package/generated/types/src/web/bindings/WC_litRender_bind.d.mts +20 -0
  148. package/generated/types/src/web/bindings/WC_litStyleMap.d.mts +7 -0
  149. package/generated/types/src/web/common/CSS.d.mts +23 -0
  150. package/generated/types/src/web/common/E.d.mts +41 -0
  151. package/generated/types/src/web/common/NewStyleSheetAsync.d.mts +15 -0
  152. package/generated/types/src/web/common/NewStyleSheetSync.d.mts +15 -0
  153. package/generated/types/src/web/common/WC_TagName_type.d.mts +15 -0
  154. package/generated/types/src/web/signals/IsInViewPortSignal.d.mts +52 -0
  155. package/generated/types/src/web/signals/ObserverSignal.d.mts +32 -0
  156. package/generated/types/src/web/signals/WC_litRef.d.mts +26 -0
  157. package/generated/types/src/web/signals/WC_loopedSiblingsRef.d.mts +44 -0
  158. package/generated/vivth/exports/all.mjs +233 -0
  159. package/generated/vivth/exports/neutral.mjs +193 -0
  160. package/generated/vivth/exports/node.mjs +46 -0
  161. package/package.json +50 -14
  162. package/src/bundler/CompileAS.mjs +36 -0
  163. package/src/bundler/CompileJS.mjs +98 -171
  164. package/src/bundler/CreateESPlugin.mjs +1 -1
  165. package/src/bundler/EsBundler.mjs +38 -13
  166. package/src/bundler/FSAnalyzer.mjs +253 -0
  167. package/src/bundler/FSasar.bundled.mjs +128 -0
  168. package/src/bundler/FSasar.mjs +96 -0
  169. package/src/bundler/FileSelfMapper.mjs +491 -0
  170. package/src/bundler/JSDirMapper.mjs +528 -0
  171. package/src/bundler/RunWatchThenCompileJSOnSafeExit.mjs +129 -0
  172. package/src/bundler/adds/BrowserExternals.mjs +37 -0
  173. package/src/bundler/adds/CreateTransform.mjs +36 -0
  174. package/src/bundler/adds/LastEditedUnix.mjs +12 -0
  175. package/src/bundler/adds/NodeModuleList.mjs +33 -0
  176. package/src/bundler/adds/PathFSBundles.bundled.mjs +41 -0
  177. package/src/bundler/adds/PathFSBundles.mjs +91 -0
  178. package/src/bundler/adds/PathFSDir.bundled.mjs +53 -0
  179. package/src/bundler/adds/PathFSDir.mjs +100 -0
  180. package/src/bundler/adds/PathFSFile.bundled.mjs +40 -0
  181. package/src/bundler/adds/PathFSFile.mjs +85 -0
  182. package/src/bundler/adds/ToBundledJSPlugin.mjs +116 -55
  183. package/src/bundler/adds/autoExternalize.mjs +81 -0
  184. package/src/bundler/adds/emptyBufferValue.mjs +5 -0
  185. package/src/bundler/adds/isModuleTheBundledVersion.mjs +10 -0
  186. package/src/bundler/adds/onEndEsBuildErrorLogger.mjs +34 -0
  187. package/src/bundler/adds/resolveJSDependencyPath.mjs +17 -0
  188. package/src/class/AwaitSignal.mjs +119 -0
  189. package/src/class/Console.mjs +36 -14
  190. package/src/class/DataLog.mjs +29 -0
  191. package/src/class/Derived.mjs +67 -55
  192. package/src/class/Effect.mjs +270 -84
  193. package/src/class/EnvSignal.mjs +11 -8
  194. package/src/class/EsWatcher.mjs +60 -0
  195. package/src/class/EventSignal.mjs +46 -58
  196. package/src/class/FSDirArchWatcher.mjs +246 -0
  197. package/src/class/FileSafe.mjs +72 -24
  198. package/src/class/ForEach.mjs +78 -0
  199. package/src/class/ForSignal.mjs +115 -0
  200. package/src/class/GetterSetter.mjs +40 -0
  201. package/src/class/JSONFileHandler.mjs +90 -0
  202. package/src/class/ListSignal.mjs +68 -26
  203. package/src/class/LitExp.mjs +59 -36
  204. package/src/class/ObjectSignal.mjs +225 -0
  205. package/src/class/Paths.mjs +56 -20
  206. package/src/class/Prettivy.mjs +51 -0
  207. package/src/class/QChannel.mjs +48 -26
  208. package/src/class/SafeExit.mjs +156 -99
  209. package/src/class/Setup.mjs +28 -16
  210. package/src/class/Signal.mjs +50 -27
  211. package/src/class/SignalCollection.mjs +130 -0
  212. package/src/class/WalkThrough.mjs +6 -23
  213. package/src/class/{WorkerMainThreadBundled.mjs → WorkerMainThread.bundled.mjs} +56 -77
  214. package/src/class/WorkerMainThread.mjs +98 -94
  215. package/src/class/WorkerThread.mjs +24 -17
  216. package/src/common/Base64URL.mjs +6 -3
  217. package/src/common/Base64URLFromFile.mjs +17 -4
  218. package/src/common/BundledV.bundled.mjs +7 -0
  219. package/src/common/BundledV.mjs +45 -0
  220. package/src/common/CreateStringID.mjs +8 -7
  221. package/src/common/EnvMode.mjs +172 -0
  222. package/src/common/FactoryKey.mjs +11 -0
  223. package/src/common/Preferrence.mjs +27 -0
  224. package/src/common/Trace.mjs +1 -1
  225. package/src/common/TracePath.mjs +53 -3
  226. package/src/common/VivthUnBundledCodeBlock.mjs +8 -0
  227. package/src/doc/JSautoDOC.mjs +673 -284
  228. package/src/doc/cleanPreserveTypedef.mjs +27 -0
  229. package/src/doc/correctBeforeParse.mjs +57 -48
  230. package/src/doc/{parsedFile.mjs → parsedFileForDOC.mjs} +133 -120
  231. package/src/function/ClearRequireCache.mjs +33 -0
  232. package/src/function/CreateImmutable.mjs +40 -37
  233. package/src/function/EventCheck.mjs +5 -2
  234. package/src/function/EventObject.mjs +2 -6
  235. package/src/function/ForInAsync.mjs +76 -0
  236. package/src/function/ForInSync.mjs +87 -0
  237. package/src/function/ForOfAsync.mjs +61 -0
  238. package/src/function/ForOfSync.mjs +70 -0
  239. package/src/function/GetBufferFromRelativePath.mjs +25 -0
  240. package/src/function/GetFilesFromDir.mjs +49 -0
  241. package/src/function/GetMaxFilenameLength.mjs +32 -0
  242. package/src/function/GetModuleEsbuildPlatform.mjs +118 -0
  243. package/src/function/GetNamedImportAlias.mjs +2 -2
  244. package/src/function/GetRuntime.mjs +10 -14
  245. package/src/function/InstantiateAssemblyScript.mjs +22 -0
  246. package/src/function/IsAsync.mjs +1 -1
  247. package/src/function/IsInstanceOf.mjs +29 -0
  248. package/src/function/IsSameFile.mjs +41 -0
  249. package/src/function/IsStringLooksLikeAPath.mjs +20 -0
  250. package/src/function/IsTypeOf.mjs +27 -0
  251. package/src/function/IsTypeOf.mts +31 -0
  252. package/src/function/LazyFactory.mjs +25 -23
  253. package/src/function/MonkeyPatch.mjs +38 -0
  254. package/src/function/NewAnimationTimeline.mjs +55 -0
  255. package/src/function/NewChainable.mjs +69 -0
  256. package/src/function/NewDynamicsExport.mjs +312 -0
  257. package/src/function/NewObjectWrapper.mjs +14 -0
  258. package/src/function/ObjectRegistrar.mjs +23 -0
  259. package/src/function/ParseSQLFile.mjs +129 -0
  260. package/src/function/PipeAsync.mjs +30 -0
  261. package/src/function/PipeSync.mjs +28 -0
  262. package/src/function/SafeImport.mjs +77 -0
  263. package/src/function/TemplateLiteral.mjs +42 -23
  264. package/src/function/Timeout.mjs +4 -4
  265. package/src/function/Tries.mjs +22 -16
  266. package/src/function/TryAsync.mjs +3 -2
  267. package/src/function/TryNew.mjs +1 -1
  268. package/src/function/TsToMjs.mjs +184 -21
  269. package/src/function/UniqueFSTempName.mjs +33 -0
  270. package/src/function/errorToMessage.mjs +21 -0
  271. package/src/function/resolveErrorArray.mjs +15 -1
  272. package/src/neinth/VivthyNeinth.mjs +487 -0
  273. package/src/typehints/ArrayToKeys.mjs +17 -0
  274. package/src/typehints/ArrayToKeys.mts +31 -0
  275. package/src/typehints/AssemblyScriptExportsType.mjs +7 -0
  276. package/src/typehints/AssemblyScriptLoaderInstantiate.mjs +7 -0
  277. package/src/typehints/AutoDocASOptions.mjs +14 -0
  278. package/src/typehints/ChainableType.mjs +11 -0
  279. package/src/typehints/ComponentDecorator_Constructor.mjs +10 -0
  280. package/src/typehints/ConsoleAdditionalSettingType.mjs +6 -0
  281. package/src/typehints/Decorator.mjs +9 -0
  282. package/src/typehints/Decorator.mts +31 -0
  283. package/src/typehints/DecoratorMonkeyPatch.mjs +10 -0
  284. package/src/typehints/DecoratorMonkeyPatch.mts +43 -0
  285. package/src/{types → typehints}/DevTestCB.mjs +2 -2
  286. package/src/typehints/EnvModeType.mjs +6 -0
  287. package/src/{types → typehints}/ListArg.mjs +1 -1
  288. package/src/{types → typehints}/LitExpResultType.mjs +1 -1
  289. package/src/typehints/MonkeyPatchedType.mjs +13 -0
  290. package/src/typehints/ParametersFollowingN.mjs +8 -0
  291. package/src/typehints/ParametersFollowingN.mts +17 -0
  292. package/src/typehints/PrefixedKeysOf.mjs +9 -0
  293. package/src/typehints/Runtime.mjs +6 -0
  294. package/src/typehints/SafeImportReturnType.mjs +6 -0
  295. package/src/typehints/StylePropRefType.mjs +12 -0
  296. package/src/typehints/TemplateLiteralValueHandler.mjs +14 -0
  297. package/src/typehints/VLifecycleCallbacks.mjs +10 -0
  298. package/src/typehints/VivthCleanup.mjs +14 -0
  299. package/src/web/BrowserDirMapper.mjs +255 -0
  300. package/src/web/EnsureValidTag.mjs +5 -0
  301. package/src/web/EnsureValidTag.mts +10 -0
  302. package/src/web/ViteAddDynamics.mjs +34 -0
  303. package/src/web/ViteGetAllHTMLFile.mjs +97 -0
  304. package/src/web/WC_extendsA.mjs +330 -0
  305. package/src/web/WC_extendsB.mjs +332 -0
  306. package/src/web/bindings/WC_StyleProp_bind.mjs +70 -0
  307. package/src/web/bindings/WC_createElement_bind.mjs +95 -0
  308. package/src/web/bindings/WC_createNamedSlot.mjs +29 -0
  309. package/src/web/bindings/WC_litRender_bind.mjs +26 -0
  310. package/src/web/bindings/WC_litStyleMap.mjs +14 -0
  311. package/src/web/common/CSS.mjs +35 -0
  312. package/src/web/common/E.mjs +126 -0
  313. package/src/web/common/NewStyleSheetAsync.mjs +21 -0
  314. package/src/web/common/NewStyleSheetSync.mjs +21 -0
  315. package/src/web/common/WC_TagName_type.mjs +10 -0
  316. package/src/web/common/WC_TagName_type.mts +36 -0
  317. package/src/web/signals/IsInViewPortSignal.mjs +140 -0
  318. package/src/web/signals/ObserverSignal.mjs +93 -0
  319. package/src/web/signals/WC_litRef.mjs +61 -0
  320. package/src/web/signals/WC_loopedSiblingsRef.mjs +100 -0
  321. package/tsconfig.json +44 -41
  322. package/index.mjs +0 -91
  323. package/src/bundler/FSInline.mjs +0 -67
  324. package/src/bundler/FSInlineAnalyzer.mjs +0 -228
  325. package/src/bundler/FSInlineBundled.mjs +0 -38
  326. package/src/bundler/adds/externals.mjs +0 -8
  327. package/src/class/ListDerived.mjs +0 -42
  328. package/src/common/Dev.mjs +0 -142
  329. package/src/common/DevBundled.mjs +0 -5
  330. package/src/common/lazie.mjs +0 -3
  331. package/src/types/IsListSignal.mjs +0 -6
  332. package/src/types/Runtime.mjs +0 -6
  333. package/src/types/VivthDevCodeBlockStringType.mjs +0 -6
  334. package/types/index.d.mts +0 -58
  335. package/types/src/bundler/CompileJS.d.mts +0 -119
  336. package/types/src/bundler/FSInline.d.mts +0 -50
  337. package/types/src/bundler/FSInlineAnalyzer.d.mts +0 -37
  338. package/types/src/bundler/FSInlineBundled.d.mts +0 -22
  339. package/types/src/bundler/adds/externals.d.mts +0 -1
  340. package/types/src/class/Console.d.mts +0 -71
  341. package/types/src/class/Derived.d.mts +0 -98
  342. package/types/src/class/Effect.d.mts +0 -216
  343. package/types/src/class/ListDerived.d.mts +0 -38
  344. package/types/src/class/Paths.d.mts +0 -69
  345. package/types/src/class/SafeExit.d.mts +0 -103
  346. package/types/src/class/WorkerMainThreadBundled.d.mts +0 -83
  347. package/types/src/common/Base64URLFromFile.d.mts +0 -16
  348. package/types/src/common/Dev.d.mts +0 -68
  349. package/types/src/common/DevBundled.d.mts +0 -3
  350. package/types/src/common/lazie.d.mts +0 -1
  351. package/types/src/doc/JSautoDOC.d.mts +0 -83
  352. package/types/src/function/GetRuntime.d.mts +0 -2
  353. package/types/src/function/TemplateLiteral.d.mts +0 -22
  354. package/types/src/function/TsToMjs.d.mts +0 -23
  355. package/types/src/types/IsListSignal.d.mts +0 -4
  356. package/types/src/types/ListArg.d.mts +0 -4
  357. package/types/src/types/Runtime.d.mts +0 -4
  358. package/types/src/types/VivthDevCodeBlockStringType.d.mts +0 -4
  359. /package/{types → generated/types}/src/bundler/adds/pluginVivthBundle.d.mts +0 -0
  360. /package/{types → generated/types}/src/class/WorkerResult.d.mts +0 -0
  361. /package/{types → generated/types}/src/common/EventNameSpace.d.mts +0 -0
  362. /package/{types → generated/types}/src/common/eventObjects.d.mts +0 -0
  363. /package/{types → generated/types}/src/common/keys.d.mts +0 -0
  364. /package/{types → generated/types}/src/doc/correctBeforeParse.d.mts +0 -0
  365. /package/{types → generated/types}/src/function/TrySync.d.mts +0 -0
  366. /package/{types → generated/types}/src/function/resolveErrorArray.d.mts +0 -0
  367. /package/{types/src/types → generated/types/src/typehints}/AnyButUndefined.d.mts +0 -0
  368. /package/{types/src/types → generated/types/src/typehints}/ExtnameType.d.mts +0 -0
  369. /package/{types/src/types → generated/types/src/typehints}/LitExpKeyType.d.mts +0 -0
  370. /package/{types/src/types → generated/types/src/typehints}/LitExpResultType.d.mts +0 -0
  371. /package/{types/src/types → generated/types/src/typehints}/MutationType.d.mts +0 -0
  372. /package/{types/src/types → generated/types/src/typehints}/QCBFIFOReturn.d.mts +0 -0
  373. /package/{types/src/types → generated/types/src/typehints}/QCBReturn.d.mts +0 -0
  374. /package/src/{types → typehints}/AnyButUndefined.mjs +0 -0
  375. /package/src/{types → typehints}/ExtnameType.mjs +0 -0
  376. /package/src/{types → typehints}/LitExpKeyType.mjs +0 -0
  377. /package/src/{types → typehints}/MutationType.mjs +0 -0
  378. /package/src/{types → typehints}/QCBFIFOReturn.mjs +0 -0
  379. /package/src/{types → typehints}/QCBReturn.mjs +0 -0
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
 
3
- import { Console } from './Console.mjs';
3
+ import { join, normalize, sep } from 'path-unified';
4
4
 
5
5
  /**
6
6
  * @description
@@ -28,10 +28,11 @@ export class Paths {
28
28
  * ```
29
29
  * - other: you need to check your JSRuntime for the rootPath reference;
30
30
  * @example
31
- * import { Paths } from 'vivth';
31
+ * import { Paths } from 'vivth/neutral';
32
32
  *
33
33
  * new Paths({
34
- * root: location.origin,
34
+ * // root: location.origin,
35
+ * // root: process.env.INIT_CWD ?? process.cwd(),
35
36
  * })
36
37
  */
37
38
  constructor({ root }) {
@@ -47,52 +48,87 @@ export class Paths {
47
48
  #root;
48
49
  /**
49
50
  * @description
51
+ * - MIGHT THROW AN ERROR;
52
+ * >- most `vivth` modules uses this value, so you need to instantiate Paths by all means before using them;
50
53
  * - reference for rootPath
51
54
  * - `Paths` needed to be instantiated via:
52
55
  * >- `Paths` constructor;
53
56
  * >- `Setup.paths` constructor;
54
- * @type {string|undefined}
57
+ * @type {string}
55
58
  */
56
59
  static get root() {
57
- if (Paths.#instance === undefined) {
58
- Console.error({
60
+ if (Paths.#instance === undefined || !Paths.#instance.#root) {
61
+ throw {
59
62
  error: 'Paths.instance.#root is undefined',
60
63
  solutions: 'instantiate `Paths` or instantiate `Setup`',
61
- });
62
- return undefined;
64
+ };
63
65
  }
64
66
  return Paths.#instance.#root;
65
67
  }
66
68
  /**
67
69
  * @description
68
- * - normalize path separator to forward slash `/`;
69
- * @param {string} path_
70
+ * - replace path separator to forward slash `/`;
71
+ * - remove repeating `./`;
72
+ * @param {string} path
70
73
  * @returns {string}
71
74
  * @example
72
- * import { Paths } from 'vivth';
75
+ * import { Paths } from 'vivth/neutral';
73
76
  *
74
77
  * Paths.normalize('file:\\D:\\myFile.mjs'); // "file://D://myFile.mjs"
75
78
  */
76
- static normalize = (path_) => {
77
- return path_.replace(/\\/g, '/');
79
+ static normalize = (path) => {
80
+ return normalize(path)
81
+ .replace(/\\/g, '/')
82
+ .replace(/\/\.\//g, '');
83
+ };
84
+ /**
85
+ * @description
86
+ * - replace path separator to `sep`;
87
+ * @param {string} path
88
+ * @returns {string}
89
+ * @example
90
+ * import { Paths } from 'vivth/neutral';
91
+ *
92
+ * Paths.nativeSep('path//myFile.mjs'); // "path\myFile.mjs" OR "path/myFile.mjs" depending on sep value;
93
+ */
94
+ static nativeSep = (path) => {
95
+ return Paths.normalize(path).replace(/\//g, sep);
78
96
  };
79
97
  /**
80
98
  * @description
81
- * - normalize path separator to forward slash `/`;
82
- * - then starts with forward slash `/`;
83
- * @param {string} path_
99
+ * - normalized then starts with forward slash `/`;
100
+ * @param {string} path
84
101
  * @returns {`/${string}`}
85
102
  * @example
86
- * import { Paths } from 'vivth';
103
+ * import { Paths } from 'vivth/neutral';
87
104
  *
88
105
  * Paths.normalizesForRoot('path\\myFile.mjs'); // "/path/myFile.mjs"
89
106
  */
90
- static normalizesForRoot = (path_) => {
91
- let normalized = Paths.normalize(path_);
92
- if (normalized.startsWith('/') === false) {
107
+ static normalizeForRoot = (path) => {
108
+ let normalized = Paths.normalize(path);
109
+ if (!normalized.startsWith('/')) {
93
110
  normalized = `/${normalized}`;
94
111
  }
95
112
  // @ts-expect-error
96
113
  return normalized;
97
114
  };
115
+ /**
116
+ * @description
117
+ * - convert path to diskAbsolute and normalized to be using forward slash;
118
+ * - usefull for arguments for `methods` OR `functions` that needs to be absolute disk path, regardles if path is relative to project root, or already absolute path;
119
+ * @param {string} path
120
+ * @returns {string}
121
+ * @example
122
+ * import { Paths } from 'vivth/neutral';
123
+ *
124
+ * Paths.normalizesForRoot('\\path\\myFile.mjs'); // "D://something/path/myFile.mjs"
125
+ */
126
+ static diskAbsolute = (path) => {
127
+ path = Paths.normalize(path);
128
+ const rootPath = Paths.normalize(Paths.root);
129
+ if (!path.startsWith(rootPath)) {
130
+ path = Paths.normalize(join(rootPath, path));
131
+ }
132
+ return path;
133
+ };
98
134
  }
@@ -0,0 +1,51 @@
1
+ // @ts-check
2
+
3
+ import { resolveConfig, format } from 'prettier';
4
+ import { QChannel } from './QChannel.mjs';
5
+ import { LazyFactory } from '../function/LazyFactory.mjs';
6
+ import { Console } from './Console.mjs';
7
+
8
+ /**
9
+ * @description
10
+ * - `prettier` wrapper with option inference from path;
11
+ */
12
+ export class Prettivy {
13
+ static #q = LazyFactory(() => new QChannel('JSPrettify'));
14
+ /**
15
+ * @param {string} path
16
+ */
17
+ constructor(path) {
18
+ this.path = path;
19
+ this.getOptions();
20
+ }
21
+ /**
22
+ * @type {string}
23
+ */
24
+ path;
25
+ /**
26
+ * @type {import('prettier').Options|null}
27
+ */
28
+ #options = null;
29
+ getOptions = async () => {
30
+ const [res, errorPrettifyResolveConfig] = await Prettivy.#q.callback(this, async () => {
31
+ if (!this.#options) {
32
+ this.options = await resolveConfig(this.path);
33
+ }
34
+ return this.#options;
35
+ });
36
+ if (!errorPrettifyResolveConfig) {
37
+ return res;
38
+ }
39
+ Console.error({ errorPrettifyResolveConfig });
40
+ };
41
+ /**
42
+ * @param {string} contentBeforePrettified
43
+ * @returns {Promise<string>}
44
+ */
45
+ format = async (contentBeforePrettified) => {
46
+ return await format(contentBeforePrettified, {
47
+ ...(await this.getOptions()),
48
+ filepath: this.path,
49
+ });
50
+ };
51
+ }
@@ -4,24 +4,38 @@ import { LazyFactory } from '../function/LazyFactory.mjs';
4
4
  import { TryAsync } from '../function/TryAsync.mjs';
5
5
  import { Console } from './Console.mjs';
6
6
 
7
+ /**
8
+ * @typedef { import('../typehints/VivthCleanup.mjs').VivthCleanup } VivthCleanup
9
+ */
10
+
7
11
  /**
8
12
  * @description
9
13
  * - class for `Queue` handling;
10
14
  * @template {AnyButUndefined} DEFINEDANY
15
+ * @implements {VivthCleanup}
11
16
  */
12
17
  export class QChannel {
18
+ vivthCleanup = async () => {
19
+ this.close();
20
+ };
13
21
  /**
14
22
  * @param {string} name
15
23
  * - only used as helper for logging, and has nothing to do with runtime behaviour;
24
+ * @param {boolean} [log]
16
25
  */
17
- constructor(name) {
26
+ constructor(name, log = false) {
18
27
  this.name = name;
28
+ this.#log = log;
19
29
  this.open();
20
30
  }
21
31
  /**
22
- * @typedef {import('../types/AnyButUndefined.mjs').AnyButUndefined} AnyButUndefined
23
- * @typedef {import('../types/QCBReturn.mjs').QCBReturn} QCBReturn
24
- * @typedef {import('../types/QCBFIFOReturn.mjs').QCBFIFOReturn} QCBFIFOReturn
32
+ * @type {boolean}
33
+ */
34
+ #log;
35
+ /**
36
+ * @typedef {import('../typehints/AnyButUndefined.mjs').AnyButUndefined} AnyButUndefined
37
+ * @typedef {import('../typehints/QCBReturn.mjs').QCBReturn} QCBReturn
38
+ * @typedef {import('../typehints/QCBFIFOReturn.mjs').QCBFIFOReturn} QCBFIFOReturn
25
39
  */
26
40
  /**
27
41
  * @description
@@ -30,7 +44,7 @@ export class QChannel {
30
44
  * @returns {typeof QChannel}
31
45
  * - usefull for Queue primitive on multiple library but single reference, like the Web by making the `Map` on `window` object;
32
46
  * @example
33
- * import { QChannel } from 'vivth';
47
+ * import { QChannel } from 'vivth/neutral';
34
48
  *
35
49
  * const myMappedQref = (window['myMappedQref'] = new Map());
36
50
  * export const MyQClass = QChannel.setup(myMappedQref);
@@ -52,33 +66,28 @@ export class QChannel {
52
66
  */
53
67
  static #uniqueCB = async (id, instance) => {
54
68
  const existing = QChannel.#uniquePromiser.get(id);
55
- // @ts-expect-error
56
- let resolveFn;
57
- const nextPromise = new Promise((resolve) => {
58
- resolveFn = resolve;
59
- });
69
+ const { promise, resolve } = Promise.withResolvers();
60
70
  const context = {};
61
71
  if (existing === undefined) {
62
- QChannel.#uniquePromiser.set(id, [nextPromise, context]);
72
+ QChannel.#uniquePromiser.set(id, [promise, context]);
63
73
  await Promise.resolve();
64
74
  } else {
65
75
  const [prevPromise] = existing;
66
76
  await prevPromise;
67
- QChannel.#uniquePromiser.set(id, [nextPromise, context]);
77
+ QChannel.#uniquePromiser.set(id, [promise, context]);
68
78
  }
69
79
  const resume = () => {
70
- // @ts-expect-error
71
- resolveFn();
80
+ resolve(true);
72
81
  QChannel.#uniquePromiser.delete(id);
73
82
  };
74
83
  return {
75
84
  resume,
76
85
  isLastOnQ: () => {
77
- if (QChannel.#uniquePromiser.has(id) === false) {
86
+ const res = QChannel.#uniquePromiser.get(id);
87
+ if (!res) {
78
88
  return false;
79
89
  }
80
- // @ts-expect-error
81
- const [, lastContext] = QChannel.#uniquePromiser.get(id);
90
+ const [, lastContext] = res;
82
91
  return instance.#shouldRun && lastContext === context;
83
92
  },
84
93
  };
@@ -105,7 +114,7 @@ export class QChannel {
105
114
  /**
106
115
  * uses locally declared object to make it unique from other QChannel instances;
107
116
  */
108
- qfifo
117
+ qfifo,
109
118
  );
110
119
  },
111
120
  /**
@@ -124,7 +133,7 @@ export class QChannel {
124
133
  /**
125
134
  * @type {()=>Promise<RESULT>}
126
135
  */
127
- asyncCallback
136
+ asyncCallback,
128
137
  ) => {
129
138
  return await TryAsync(async () => {
130
139
  const { resume } = await this.fifo.key();
@@ -148,7 +157,7 @@ export class QChannel {
148
157
  */
149
158
  get #shouldRun() {
150
159
  const shoulRun = this.#shouldRun_;
151
- if (shoulRun === false) {
160
+ if (!shoulRun) {
152
161
  Console.warn({ qChannel_name: this.name, message: 'is closed' });
153
162
  }
154
163
  return shoulRun;
@@ -157,20 +166,26 @@ export class QChannel {
157
166
  * @description
158
167
  * - disable queue;
159
168
  * - when `closed`, `isLastOnQ` will allways return `false`;
160
- * @returns {void}
169
+ * @type {()=>void}
161
170
  */
162
171
  close = () => {
163
172
  this.#shouldRun_ = false;
173
+ if (!this.#log) {
174
+ return;
175
+ }
164
176
  Console.info({ qChannel_name: this.name, message: 'closed' });
165
177
  };
166
178
  /**
167
179
  * @description
168
180
  * - enable queue;
169
181
  * - when `opened`, `isLastOnQ` will evaluate whether calls are actually the last of queue;
170
- * @returns {void}
182
+ * @type {()=>void}
171
183
  */
172
184
  open = () => {
173
185
  this.#shouldRun_ = true;
186
+ if (!this.#log) {
187
+ return;
188
+ }
174
189
  Console.info({ qChannel_name: this.name, message: 'opened' });
175
190
  };
176
191
  /**
@@ -199,14 +214,14 @@ export class QChannel {
199
214
  key = async (keyID) => {
200
215
  const { resume } = await QChannel.#uniqueCB(this, this);
201
216
  const mapped = this.#mapped;
202
- if (mapped.has(keyID) === false) {
217
+ if (!mapped.has(keyID)) {
203
218
  mapped.set(keyID, {});
204
219
  }
205
220
  resume();
206
221
  return await QChannel.#uniqueCB(
207
222
  // @ts-expect-error
208
223
  mapped.get(keyID),
209
- this
224
+ this,
210
225
  );
211
226
  };
212
227
  /**
@@ -228,14 +243,21 @@ export class QChannel {
228
243
  * // return;
229
244
  * // }
230
245
  * // code
246
+ * // return result
231
247
  * })
232
248
  */
233
249
  async callback(keyID, asyncCallback) {
234
- return await TryAsync(async () => {
250
+ /**
251
+ * @type {undefined|(()=>void)}
252
+ */
253
+ let resume_;
254
+ const res = await TryAsync(async () => {
235
255
  const { resume, isLastOnQ } = await this.key(keyID);
256
+ resume_ = resume;
236
257
  const result = await asyncCallback({ isLastOnQ });
237
- resume();
238
258
  return result;
239
259
  });
260
+ resume_?.();
261
+ return res;
240
262
  }
241
263
  }
@@ -1,17 +1,20 @@
1
1
  // @ts-check
2
2
 
3
+ import process from 'node:process';
4
+ import { spawn } from 'node:child_process';
5
+
3
6
  import { TryAsync } from '../function/TryAsync.mjs';
4
- import { TrySync } from '../function/TrySync.mjs';
5
7
  import { WalkThrough } from './WalkThrough.mjs';
6
8
  import { Console } from './Console.mjs';
7
- import { Effect, mapOfEffects } from './Effect.mjs';
8
- import { EnvSignal } from './EnvSignal.mjs';
9
+ import { mapOfEffects } from './Effect.mjs';
9
10
  import { setOFSignals } from './Signal.mjs';
10
-
11
- /**
12
- * @type {Set<()=>Promise<void>>}
13
- */
14
- export const safeCleanUpCBs = new Set();
11
+ import { ForOfSync } from '../function/ForOfSync.mjs';
12
+ import { QChannel } from './QChannel.mjs';
13
+ import { Paths } from './Paths.mjs';
14
+ import { FileSafe } from './FileSafe.mjs';
15
+ import { UniqueFSTempName } from '../function/UniqueFSTempName.mjs';
16
+ import { Preferrence } from '../common/Preferrence.mjs';
17
+ import { join } from 'node:path';
15
18
 
16
19
  /**
17
20
  * @description
@@ -20,114 +23,168 @@ export const safeCleanUpCBs = new Set();
20
23
  * - most of functionality might need to access `SafeExit.instance.exiting`, if you get warning, you can instantiate `SafeExit` before running anything;
21
24
  */
22
25
  export class SafeExit {
26
+ /**
27
+ * @type {QChannel<any>}
28
+ */
29
+ #q = new QChannel('SafeExit');
23
30
  /**
24
31
  * @description
25
32
  * - only accessible after instantiation;
26
33
  * @type {SafeExit|undefined}
27
34
  */
28
35
  static instance;
36
+ /**
37
+ * @type {Set<()=>Promise<void>>}
38
+ */
39
+ safeCleanUpCBs = new Set();
29
40
  /**
30
41
  * @description
31
- * @param {Object} options
32
- * @param {[string, ...string[]]} options.eventNames
33
- * - eventNames are blank by default, you need to manually name them all;
34
- * - 'exit' will be omited, as it might cause async callbacks failed to execute;
42
+ * @param {...NodeJS.Signals} eventNames
43
+ * - `beforeExit` is auto included;
35
44
  * - example:
36
45
  * ```js
37
- * ['SIGINT', 'SIGTERM']
38
- * ```
39
- * @param {()=>void} options.terminator
40
- * - standard, process must be imported statically from 'node:process':
41
- * ```js
42
- * () => process.exit(0),
43
- * ```
44
- * @param {(eventName:string)=>void} [options.listener]
45
- * - default value
46
- * ```js
47
- * (eventName) => {
48
- * process.once(eventName, function () {
49
- * SafeExit.instance.exiting.correction(true);
50
- * Console.log(`safe exit via "${eventName}"`);
51
- * });
52
- * }
46
+ * ['SIGINT', 'SIGTERM'] // both are automatically added
53
47
  * ```
54
- * - if your exit callback doesn't uses `process` global object you need to input on the SafeExit instantiation
55
48
  * @example
56
49
  * import process from 'node:process';
57
- * import { SafeExit, Console } from 'vivth';
50
+ * import { SafeExit } from 'vivth/node';
58
51
  *
59
- * new SafeExit({
60
- * eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
61
- * terminator : () => process.exit(0),
62
- * listener : (eventName) => {
63
- * process.once(eventName, function () {
64
- * SafeExit.instance?.exiting.correction(true);
65
- * Console.log(`safe exit via "${eventName}"`);
66
- * });
67
- * }
68
- * });
52
+ * new SafeExit('SIGINT', 'SIGTERM', ...eventNames);
69
53
  */
70
- constructor({ eventNames, terminator, listener = undefined }) {
54
+ constructor(...eventNames) {
71
55
  if (SafeExit.instance instanceof SafeExit) {
72
56
  return SafeExit.instance;
73
57
  }
74
58
  SafeExit.instance = this;
75
- this.#exit = terminator;
76
- if (listener) {
77
- this.#listener = listener;
78
- }
79
59
  this.#register(eventNames);
80
60
  }
61
+
81
62
  /**
82
- * @description
83
- * - optional exit event registration, by listening to it inside an `Effect`;
84
- * - when the value is `true`, meaning program is exitting;
85
- * @type {EnvSignal<boolean>}
63
+ * @type { undefined|import('node:child_process').ChildProcess }
64
+ */
65
+ #childProcessHelper;
66
+
67
+ /**
68
+ * @type {Parameters<QChannel<any>["callback"]>[1]}
86
69
  */
87
- exiting = new EnvSignal(false);
70
+ #mitigationQ = async ({ isLastOnQ }) => {
71
+ if (
72
+ /** */
73
+ !!this.#childProcessHelper ||
74
+ !isLastOnQ()
75
+ ) {
76
+ return;
77
+ }
78
+ const tempPath = UniqueFSTempName(
79
+ Paths.diskAbsolute(join(Paths.root, '/vivth/src/safeExit-guard-with-bun.mjs')),
80
+ '.mjs',
81
+ );
82
+
83
+ await FileSafe.write(
84
+ tempPath,
85
+ `import process from "node:process";process.title="close this terminal to emit 'SIGTERM' to main process at '${Paths.normalize(Paths.root)}'";`,
86
+ { encoding: Preferrence.encoding },
87
+ );
88
+ const proc = spawn(
89
+ 'bun',
90
+ [
91
+ /** */
92
+ '--watch',
93
+ tempPath,
94
+ ],
95
+ {
96
+ cwd: Paths.root,
97
+ stdio: 'ignore',
98
+ detached: true,
99
+ },
100
+ );
101
+ this.#childProcessHelper = proc;
102
+ SafeExit.instance?.addCallback(async () => {
103
+ proc.kill('SIGTERM');
104
+ });
105
+ process.once('exit', () => {
106
+ proc.kill('SIGTERM');
107
+ });
108
+ ForOfSync(['exit', 'close'], (eventName) => {
109
+ proc.once(eventName, () => {
110
+ process.emit('SIGTERM');
111
+ proc.kill('SIGTERM');
112
+ });
113
+ });
114
+ };
115
+ #exitMitigation = () => {
116
+ this.#q.callback(this.#mitigationQ, this.#mitigationQ);
117
+ };
118
+
88
119
  /**
89
- * @param {ConstructorParameters<typeof SafeExit>[0]["eventNames"]} eventNames
120
+ * @param {...ConstructorParameters<typeof SafeExit>[0][]} eventNames
90
121
  * @returns {void}
91
122
  */
92
- #register = (eventNames) => {
93
- eventNames.forEach((eventName) => {
94
- if (eventName.toLowerCase() === 'exit') {
95
- return;
96
- }
97
- this.#listener(eventName);
123
+ #register = (eventNames = []) => {
124
+ eventNames.push(
125
+ /**
126
+ * - `beforeExit` is necessary as sometimes `bun` might not listen to SIGNAL;
127
+ * - and then somehow `exit` is already called;
128
+ */
129
+ // @ts-expect-error
130
+ 'beforeExit',
131
+ 'SIGINT',
132
+ 'SIGTERM',
133
+ );
134
+ const setOfEvents = new Set(eventNames);
135
+ setOfEvents.delete(
136
+ // @ts-expect-error
137
+ 'exit',
138
+ );
139
+ ForOfSync(setOfEvents, (eventName) => {
140
+ this.#createListener(eventName);
98
141
  });
99
142
  };
143
+ #hasExited = false;
100
144
  /**
101
145
  * @type {(eventName:string)=>void}
102
146
  */
103
- #listener = (eventName) => {
104
- if (SafeExit.instance === undefined) {
105
- return;
106
- }
107
- SafeExit.instance.exiting.env.value;
108
- process.once(eventName, function () {
109
- if (SafeExit.instance === undefined) {
147
+ #createListener = (eventName) => {
148
+ process.once(eventName, async () => {
149
+ const [, errorCleanup] = await this.#q.callback(
150
+ this.#createListener,
151
+ async ({ isLastOnQ }) => {
152
+ if (!isLastOnQ() || this.#hasExited) {
153
+ return;
154
+ }
155
+ this.#hasExited = true;
156
+ await this.#cleanup(eventName);
157
+ },
158
+ );
159
+ if (!errorCleanup) {
110
160
  return;
111
161
  }
112
- Console.log(`safe exit via "${eventName}"`);
113
- SafeExit.instance.exiting.correction(true);
162
+ Console.error({ errorCleanup }, { now: true });
114
163
  });
115
164
  };
116
165
  /**
117
166
  * @description
118
- * - optional exit event registration;
119
- * - the callbacks will be called when exiting;
120
- * @param {()=>(Promise<void>)} cb
167
+ * - `SafeExit` ${eventName}.Callback registration;
168
+ * - `onEventName` all callbacks are called simultanousely using `await Promise.all`;
169
+ * >- for sequential event you need to put them in a single callback;
170
+ * @param {()=>(Promise<void>)} safeExitCallback
171
+ * @returns {{removeCallback:()=>void}}
121
172
  * @example
122
- * import { SafeExit } from 'vivth';
173
+ * import { SafeExit } from 'vivth/node';
123
174
  *
124
- * const exitCallback () => {
175
+ * const exitCallback = async () => {
125
176
  * // code
126
177
  * }
127
178
  * SafeExit.instance.addCallback(exitCallback);
128
179
  */
129
- addCallback = (cb) => {
130
- safeCleanUpCBs.add(cb);
180
+ addCallback = (safeExitCallback) => {
181
+ this.#exitMitigation();
182
+ this.safeCleanUpCBs.add(safeExitCallback);
183
+ return {
184
+ removeCallback: () => {
185
+ this.removeCallback(safeExitCallback);
186
+ },
187
+ };
131
188
  };
132
189
  /**
133
190
  * @description
@@ -135,7 +192,7 @@ export class SafeExit {
135
192
  * - the callbacks will be removed from registered via `addCallback` exiting;
136
193
  * @param {()=>(Promise<void>)} cb
137
194
  * @example
138
- * import { SafeExit } from 'vivth';
195
+ * import { SafeExit } from 'vivth/node';
139
196
  *
140
197
  * const exitCallback () => {
141
198
  * // code
@@ -145,39 +202,39 @@ export class SafeExit {
145
202
  * SafeExit.instance.removeCallback(exitCallback);
146
203
  */
147
204
  removeCallback = (cb) => {
148
- safeCleanUpCBs.delete(cb);
205
+ this.safeCleanUpCBs.delete(cb);
206
+ };
207
+ triggerExit = async () => {
208
+ await this.#cleanup('vivth/node.SafeExit.instance.triggerExit');
149
209
  };
210
+
150
211
  /**
151
- * @type {()=>void}
212
+ * @param {string} eventName
213
+ * @returns {Promise<void>}
152
214
  */
153
- #exit = () => {};
154
- // @ts-expect-error
155
- #autoCleanUp = new Effect(async ({ subscribe }) => {
156
- if (
157
- //
158
- !subscribe(this.exiting.env).value
159
- ) {
160
- return;
215
+ #cleanup = async (eventName) => {
216
+ Console.log({ SafeExit: `called by '${eventName}'` }, { now: true });
217
+ if (this.#childProcessHelper) {
218
+ this.#childProcessHelper.kill('SIGTERM');
219
+ Console.info('force closing bun terminal helper', { now: true });
161
220
  }
221
+ await Promise.all(
222
+ ForOfSync(this.safeCleanUpCBs, async (cleanup) => {
223
+ const [, error] = await TryAsync(async () => {
224
+ await cleanup();
225
+ });
226
+ if (error === undefined) {
227
+ return;
228
+ }
229
+ Console.warn(error);
230
+ })[0],
231
+ );
162
232
  WalkThrough.set(setOFSignals, (signal) => {
163
233
  signal.remove.ref();
164
234
  });
165
235
  WalkThrough.map(mapOfEffects, ([effect, _]) => {
166
236
  effect.options.removeEffect();
167
237
  });
168
- for await (const cleanup of safeCleanUpCBs) {
169
- const [, error] = await TryAsync(async () => {
170
- await cleanup();
171
- });
172
- if (error === undefined) {
173
- continue;
174
- }
175
- Console.warn(error);
176
- }
177
- const [, errorExitting] = TrySync(this.#exit);
178
- if (errorExitting === undefined) {
179
- return;
180
- }
181
- Console.error(errorExitting);
182
- });
238
+ process.exit(0);
239
+ };
183
240
  }