vivth 1.4.10 → 1.5.1

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 +28 -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 +78 -42
  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,36 +1,34 @@
1
1
  // @ts-check
2
2
 
3
- import { extname, join } from 'node:path';
3
+ import { extname } from 'node:path';
4
4
  import { readFile } from 'node:fs/promises';
5
5
 
6
6
  import prettier from 'prettier';
7
- import chokidar from 'chokidar';
8
7
 
9
- import { EventSignal } from '../class/EventSignal.mjs';
10
- import { parsedFile } from './parsedFile.mjs';
11
- import { SafeExit } from '../class/SafeExit.mjs';
12
- import { Effect } from '../class/Effect.mjs';
8
+ import { FileSafe } from '../class/FileSafe.mjs';
9
+ import { ForEach } from '../class/ForEach.mjs';
10
+ import { FSDirArchWatcher } from '../class/FSDirArchWatcher.mjs';
11
+ import { JSONFileHandler } from '../class/JSONFileHandler.mjs';
13
12
  import { Paths } from '../class/Paths.mjs';
14
- import { Signal } from '../class/Signal.mjs';
13
+ import { IsSameFile } from '../function/IsSameFile.mjs';
15
14
  import { LazyFactory } from '../function/LazyFactory.mjs';
16
15
  import { TryAsync } from '../function/TryAsync.mjs';
17
- import { Console } from '../class/Console.mjs';
16
+ import { parsedFileForDOC } from './parsedFileForDOC.mjs';
17
+ import { Preferrence } from '../common/Preferrence.mjs';
18
+ import { basename, join } from 'node:path';
18
19
  import { TsToMjs } from '../function/TsToMjs.mjs';
19
- import { FileSafe } from '../class/FileSafe.mjs';
20
+ import { Console } from '../class/Console.mjs';
20
21
  import { correctBeforeParse } from './correctBeforeParse.mjs';
22
+ import { GetterSetter } from '../class/GetterSetter.mjs';
23
+ import { ForOfSync } from '../function/ForOfSync.mjs';
24
+ import { TryNew } from '../function/TryNew.mjs';
25
+ import { cleanPreserveTypedef } from './cleanPreserveTypedef.mjs';
26
+
27
+ export const multiExportEntryPointsPath = './generated/vivth/exports/';
21
28
 
22
29
  /**
23
- * @typedef {import('fs').Stats} Stats
24
- */
25
- /**
26
- * @type {BufferEncoding}
27
- */
28
- const encoding = 'utf-8';
29
- const readmesrcname = 'README.src.md';
30
- /**
31
- * @type {Set<import('../types/ExtnameType.mjs').ExtnameType>}
30
+ * @typedef {import('../typehints/VivthCleanup.mjs').VivthCleanup} VivthCleanup
32
31
  */
33
- const acceptableExt = new Set(['.mjs', '.mts', '.ts']);
34
32
 
35
33
  /**
36
34
  * @description
@@ -54,358 +52,749 @@ const acceptableExt = new Set(['.mjs', '.mts', '.ts']);
54
52
  * >>- static/instance method with generic template;
55
53
  * >7) transpile `.ts` and `.mts` to `.mjs` with same name and directory;
56
54
  * >>- use `"at"preserve` to preserve tsdoc comment section;
55
+ * >8) integrated with assembly script to wasm compiler on the doc;
56
+ * >>- see [AssemblyScript](#assemblyscript);
57
+ * >9) modify following root json files:
58
+ * >>- `package.json`: assign `exports`, `main`, `module`;
59
+ * >>- `tsconfig.json`: assign `includes`, anything passed on `options.jstsconfigs`;
60
+ * >>- `jsconfig.json`: assign `includes`, anything passed on `options.jstsconfigs`;
61
+ * >10) generates files to `/generated/vivth/exports/`:
62
+ * >>- `./browser.mjs`: able to be called on `browser` platform;
63
+ * >>- `./node.mjs`: able to be called on `node` platform;
64
+ * >>- `./neutral.mjs`: able to be called on `node` and `browser` platform;
65
+ * >>- `./unsupported.mjs`: most likely will throw error when called, it is more of a logged error to be managed;
66
+ * >>- `./all.mjs`: collections of all platform;
67
+ * >11) doesn't support accessor;
68
+ * >>- due to how TLS way accessor type not casting its getter and setter working around accessor requires ignoring this specific error, and it might become ugly real quick;
69
+ * >>- we recomend to stick with getter and setter;
70
+ * - for runtime example see file `/dev/auto-doc.mjs` on source code;
71
+ * @implements {VivthCleanup}
57
72
  */
58
73
  export class JSautoDOC {
74
+ vivthCleanup = async () => {
75
+ await this.watcher?.vivthCleanup();
76
+ };
77
+ /**
78
+ * @typedef {'readme' |
79
+ * 'handledJS'
80
+ * } returnTypeStringType
81
+ */
82
+ /**
83
+ * @typedef {FSDirArchWatcher<{
84
+ * path: string;
85
+ * parsed: undefined;
86
+ * ext: `.${string}`;
87
+ * type: returnTypeStringType;
88
+ * readme?:string;
89
+ * } | {
90
+ * path: string;
91
+ * parsed: parsedFileForDOC;
92
+ * ext: string;
93
+ * type: returnTypeStringType;
94
+ * readme?:string;
95
+ * }>} FSDirArchWatcher__
96
+ */
59
97
  /**
60
98
  * @type {JSautoDOC|undefined}
61
99
  */
62
100
  static #instance;
63
101
  /**
64
102
  * @description
65
- * @param {Object} [options]
66
- * @param {Object} [options.paths]
67
- * @param {string} options.paths.file
68
- * - entry point;
69
- * @param {string} options.paths.readMe
70
- * - readme target;
71
- * @param {string} options.paths.dir
103
+ * @param {Object} options
104
+ * @param {string} options.src
72
105
  * - source directory;
73
106
  * @param {string} [options.copyright]
74
107
  * @param {string} [options.tableOfContentTitle]
75
- * @param {import('chokidar').ChokidarOptions} [options.option]
108
+ * @param {number} [options.maxDebounceForGeneratingDocAndExport]
109
+ * - default `10_000`;
110
+ * @param {import('chokidar').ChokidarOptions} [options.chokidarOptions]
76
111
  * - ChokidarOptions;
112
+ * @param {import('../typehints/AutoDocASOptions.mjs').AutoDocASOptions} [options.assemblyScriptOptions]
113
+ * - abstracted details to handle `.as.ts` file;
114
+ * @param {(arg0:{map:Map<string, {
115
+ * path: string;
116
+ * parsed: undefined;
117
+ * ext: `.${string}`;
118
+ * type: returnTypeStringType;
119
+ * readme?:string;
120
+ * } | {
121
+ * path: string;
122
+ * parsed: parsedFileForDOC;
123
+ * ext: string;
124
+ * type: returnTypeStringType;
125
+ * readme?:string;
126
+ * }>})=>Promise<void>} [options.onLastGeneratedCallback]
127
+ * - callback to be run on finishing generating document AND exports;
128
+ * - only handle that marked as `isLastCalled`;
129
+ * @param { import('typescript').CompilerOptions |
130
+ * import('typescript').ParsedCommandLine
131
+ * } [options.jstsconfigs]
132
+ * - type of `ts/jsconfig` to be assigned to existing respective `.json` file;
77
133
  * @example
78
- * import { JSautoDOC } from 'vivth';
134
+ * import { JSautoDOC } from 'vivth/node';
79
135
  *
80
- * new JSautoDOC({
81
- * paths: { dir: 'src', file: 'index.mjs', readMe: 'README.md' },
136
+ * new JSautoDOC({
137
+ * src: '/src',
82
138
  * copyright: 'this library is made and distributed under MIT license;',
83
139
  * tableOfContentTitle: 'list of exported API and typehelpers',
140
+ * // assemblyScriptOptions: {},
141
+ * // onLastGeneratedCallback: async (options) => {
142
+ * // Console.log(options);
143
+ * // },
84
144
  * });
85
- *
86
145
  */
87
146
  constructor({
88
- paths = { dir: './src', file: './index.mjs', readMe: './README.md' },
147
+ src = './src',
148
+ onLastGeneratedCallback = undefined,
89
149
  tableOfContentTitle = 'exported-api-and-type-list',
90
150
  copyright = '',
91
- option = {},
92
- } = {}) {
151
+ maxDebounceForGeneratingDocAndExport = 10_000,
152
+ assemblyScriptOptions = undefined,
153
+ chokidarOptions = undefined,
154
+ jstsconfigs = undefined,
155
+ }) {
93
156
  if (JSautoDOC.#instance instanceof JSautoDOC) {
94
- return this;
157
+ return JSautoDOC.#instance;
95
158
  }
96
159
  JSautoDOC.#instance = this;
160
+ this.#onLastGeneratedCallback = onLastGeneratedCallback;
97
161
  this.#tableOfContentTitle = tableOfContentTitle;
98
- this.#paths = paths;
162
+ this.#source = src;
99
163
  this.#copyright = copyright;
100
- const rootPath = Paths.root;
101
- if (rootPath === undefined) {
164
+ this.#assemblyScriptOptions = assemblyScriptOptions;
165
+ this.#readmePath = Paths.diskAbsolute('/README.src.md');
166
+ Promise.all([
167
+ this.#jstsConfigAddInclude('/tsconfig.json', jstsconfigs),
168
+ this.#jstsConfigAddInclude('/jsconfig.json', jstsconfigs),
169
+ ]);
170
+ FileSafe.exist(this.#readmePath).then(async (isExist) => {
171
+ if (isExist) {
172
+ return;
173
+ }
174
+ await this.#writeREADMEDefaultSRC();
175
+ });
176
+ const [fsDirArchWatcher, errorfsDirArchWatcherInstance] = TryNew(
177
+ FSDirArchWatcher,
178
+ [src, this.#readmePath],
179
+ {
180
+ debounce: maxDebounceForGeneratingDocAndExport,
181
+ chokidarOptions,
182
+ /**
183
+ * @type {FSDirArchWatcher__["eachHandler"]}
184
+ */
185
+ each: async (eventName, path, stats) => {
186
+ /**
187
+ * @type {`.${string}`}
188
+ */
189
+ // @ts-expect-error
190
+ const ext = extname(path);
191
+ const readMeHandled = await this.checkReadmeFile(path);
192
+ if (readMeHandled.isBeingHandled) {
193
+ return { path, parsed: undefined, readme: readMeHandled.content, ext, type: 'readme' };
194
+ }
195
+ if (!this.#acceptableExt.has(ext)) {
196
+ throw '';
197
+ }
198
+ if (basename(path).endsWith(`.d${ext}`)) {
199
+ const renamedPath = path.replace(new RegExp(`.d${ext}$`), ext);
200
+ await FileSafe.rename(path, renamedPath);
201
+ throw '';
202
+ }
203
+ switch (eventName) {
204
+ case 'add':
205
+ case 'change':
206
+ if (ext !== '.mjs') {
207
+ await TsToMjs(path, {
208
+ encoding: Preferrence.encoding,
209
+ assemblyScriptOptions: this.#assemblyScriptOptions,
210
+ });
211
+ throw '';
212
+ }
213
+ if (!stats?.isFile()) {
214
+ throw '';
215
+ }
216
+ if (await FileSafe.exist(path.replace(/.mjs$/, '.mts'))) {
217
+ const newString = cleanPreserveTypedef(
218
+ await readFile(path, { encoding: Preferrence.encoding }),
219
+ );
220
+ if (newString) {
221
+ await FileSafe.write(path, newString, { encoding: Preferrence.encoding });
222
+ }
223
+ }
224
+ return await this.#addAndChangesHandler(ext, path, stats);
225
+ default:
226
+ /**
227
+ * - auto deleted from the map so need to call `.delete`
228
+ */
229
+ throw '';
230
+ }
231
+ },
232
+ // @ts-expect-error
233
+ full: this.#fullHandler,
234
+ },
235
+ );
236
+ if (errorfsDirArchWatcherInstance) {
237
+ Console.error({ errorfsDirArchWatcherInstance });
102
238
  return;
103
239
  }
104
- const watchpath = join(rootPath, this.#paths.dir);
105
- const watcher = chokidar.watch(watchpath, option);
106
- const watcherReadme = chokidar.watch(join(rootPath, readmesrcname), option);
107
- /**
108
- * @type {(eventName: import('chokidar/handler.js').EventName, path: string, stats?: import('fs').Stats) => void}
109
- */
110
- const listener = (eventName, path, stats) => {
111
- const ext = extname(path);
112
- if (
113
- acceptableExt.has(
114
- // @ts-expect-error
115
- ext
116
- ) === false
117
- ) {
240
+ this.watcher = fsDirArchWatcher;
241
+ }
242
+ /**
243
+ * @type { FSDirArchWatcher<any>|undefined }
244
+ */
245
+ watcher;
246
+ /**
247
+ * @type {string}
248
+ */
249
+ #source = './src';
250
+ #packageJSONHandler = LazyFactory(() => new JSONFileHandler('/package.json'));
251
+ /**
252
+ * @type {Set<import('../typehints/ExtnameType.mjs').ExtnameType>}
253
+ */
254
+ #acceptableExt = new Set(['.js', '.mjs', '.mts', '.ts']);
255
+ /**
256
+ * @param {string} configPath
257
+ * @param {ConstructorParameters<typeof JSautoDOC>[0]["jstsconfigs"]} jstsconfigs
258
+ */
259
+ #jstsConfigAddInclude = async (configPath, jstsconfigs) => {
260
+ return await TryAsync(async () => {
261
+ if (!(await FileSafe.exist(Paths.diskAbsolute(configPath)))) {
118
262
  return;
119
263
  }
120
- if (ext !== '.mjs') {
121
- // no need to be awaited
122
- TsToMjs(path, {
123
- encoding,
124
- });
264
+ const handler = new JSONFileHandler(configPath);
265
+ const [object, error] = await handler.read();
266
+ if (error) {
125
267
  return;
126
268
  }
127
- switch (eventName) {
128
- case 'add':
129
- case 'change':
130
- this.#addHandler(eventName, path, stats);
131
- break;
132
- case 'unlink':
133
- this.#removeHandler(eventName, path, stats);
134
- break;
269
+ const include =
270
+ // @ts-expect-error
271
+ new Set(object.include ?? []);
272
+ include.add(`.${Paths.normalizeForRoot(this.#source)}`);
273
+ include.add('./generated/vivth/exports');
274
+ const obj = { include: Array.from(include) };
275
+ if (!jstsconfigs) {
276
+ Object.assign(obj, jstsconfigs);
135
277
  }
136
- };
137
- watcher.on('all', listener);
138
- watcherReadme.on('all', this.#readMeListener);
139
- if (SafeExit.instance) {
140
- SafeExit.instance.addCallback(async () => {
141
- watcher.close();
142
- watcherReadme.close();
143
- watcher.removeAllListeners();
144
- watcherReadme.removeAllListeners();
145
- watcher.removeListener('all', listener);
146
- watcherReadme.removeAllListeners(this.#readMeListener);
147
- watcherReadme.removeListener('all', this.#readMeListener);
148
- });
149
- }
150
- }
278
+ await handler.assign(obj);
279
+ });
280
+ };
151
281
  /**
152
- * @type {string|undefined}
282
+ * @type {ConstructorParameters<typeof JSautoDOC>[0]["onLastGeneratedCallback"]}
153
283
  */
154
- #copyright;
284
+ #onLastGeneratedCallback;
155
285
  /**
156
- * @type {{
157
- * file: string;
158
- * readMe: string;
159
- * dir: string;
160
- * }|undefined}
286
+ * @type {string|undefined}
161
287
  */
162
- #paths;
288
+ #tableOfContentTitle;
163
289
  /**
164
290
  * @type {string|undefined}
165
291
  */
166
- #tableOfContentTitle;
292
+ #copyright;
167
293
  /**
168
- * @param {import('chokidar/handler.js').EventName} _eventName
169
- * @param {string} path_
170
- * @param {Stats|undefined} stats
171
- * @returns {void}
294
+ * @type {string}
172
295
  */
173
- #readMeListener = (_eventName, path_, stats) => {
174
- if (stats && stats.isFile() === false) {
175
- return;
176
- }
177
- readFile(path_, { encoding }).then((content) => {
178
- this.#readMESRCContent.value = content;
179
- });
180
- };
296
+ // @ts-expect-error
297
+ #readmePath;
181
298
  /**
182
- * @type {Signal<Set<string>>}
299
+ * @type { string }
183
300
  */
184
- #filePaths = LazyFactory(() => new Signal(new Set()));
301
+ #readme = Paths.diskAbsolute('./README.md');
185
302
  /**
186
- * @type {Signal<string>}
303
+ * @type { import('../typehints/AutoDocASOptions.mjs').AutoDocASOptions|undefined }
187
304
  */
188
- #readMESRCContent = LazyFactory(() => new Signal(''));
189
- // @ts-expect-error
190
- #generatedREADME_md = new Effect(async ({ subscribe, isLastCalled }) => {
191
- const contentSRC = subscribe(this.#readMESRCContent).value;
192
- const filepaths = subscribe(this.#filePaths).value;
193
- if ((await isLastCalled(100)) === false || !contentSRC || !filepaths) {
194
- return;
305
+ #assemblyScriptOptions;
306
+ /**
307
+ * @param {string} path
308
+ * @returns {Promise<{isBeingHandled:boolean, content?: string}>}
309
+ * - is being handled;
310
+ */
311
+ checkReadmeFile = async (path) => {
312
+ const isREADMEPATH = IsSameFile(this.#readmePath, path);
313
+ if (!isREADMEPATH) {
314
+ return { isBeingHandled: false };
195
315
  }
196
- const res = await this.#generateFromSRC(contentSRC, filepaths);
197
- if ((await isLastCalled()) === false || res === undefined) {
198
- return;
316
+ let content = '';
317
+ if (!(await FileSafe.exist(this.#readmePath))) {
318
+ await FileSafe.write(this.#readmePath, `README HEADER PLACEHOLDER`, {
319
+ encoding: Preferrence.encoding,
320
+ });
199
321
  }
200
- const { readme, mjsFile } = res;
201
- const rootPath = Paths.root;
202
- if (rootPath === undefined || this.#paths === undefined) {
203
- return;
322
+ const [res] = await TryAsync(async () => {
323
+ return await readFile(path, { encoding: Preferrence.encoding });
324
+ });
325
+ if (!!res) {
326
+ content = res;
204
327
  }
205
- const readmePath = join(rootPath, this.#paths.readMe);
206
- const mjsFilePath = join(rootPath, this.#paths.file);
207
- const [[, errorWriteReadme], [, errorWriteMjsFile]] = await Promise.all([
208
- FileSafe.write(readmePath, await prettier.format(readme, { parser: 'markdown' }), {
209
- encoding,
210
- }),
211
- FileSafe.write(mjsFilePath, mjsFile, { encoding }),
212
- ]);
213
- if (errorWriteReadme === undefined) {
214
- Console.info({ vivthJSautoDOC: `successfully generate '${readmePath}'` });
215
- } else {
216
- Console.error({ vivthJSautoDOC: `unable to generate '${readmePath}'`, errorWriteReadme });
328
+ return { isBeingHandled: true, content };
329
+ };
330
+ /**
331
+ * @param {`.${string}`} extentionName
332
+ * @param {string} path
333
+ * @param {import('fs').Stats} [stats]
334
+ * @returns {Promise<{
335
+ * path: string;
336
+ * parsed: undefined;
337
+ * ext: `.${string}`;
338
+ * type: returnTypeStringType;
339
+ * } | {
340
+ * path: string;
341
+ * parsed: parsedFileForDOC;
342
+ * ext: string;
343
+ * type: returnTypeStringType;
344
+ * }>}
345
+ */
346
+ #addAndChangesHandler = async (extentionName, path, stats) => {
347
+ const [checkCorrectBeforeParse, errorCorrectBeforeParse] = await TryAsync(async () => {
348
+ return await correctBeforeParse(path, Preferrence.encoding);
349
+ });
350
+ if (errorCorrectBeforeParse) {
351
+ Console.error({ errorCorrectBeforeParse }, { now: true });
352
+ throw '';
217
353
  }
218
- if (errorWriteMjsFile === undefined) {
219
- Console.info({ vivthJSautoDOC: `successfully generate '${mjsFilePath}'` });
220
- } else {
221
- Console.error({ vivthJSautoDOC: `unable to generate '${mjsFilePath}'`, errorWriteMjsFile });
354
+ switch (checkCorrectBeforeParse) {
355
+ case 'shouldProceedNextCheck':
356
+ const parsed = new parsedFileForDOC(path, stats);
357
+ await parsed.parse();
358
+ return { ext: extentionName, parsed, path, type: 'handledJS' };
359
+ default:
360
+ throw '';
222
361
  }
362
+ };
363
+ /**
364
+ * @returns {Promise<void>}
365
+ */
366
+ #writeREADMEDefaultSRC = async () => {
367
+ await this.#readmeSourceGetterSetter.set?.(`---\n---\n---\nREADME SRC PLACEHOLDER\n---\n---\n`);
368
+ };
369
+ #readmeSourceGetterSetter = new GetterSetter({
370
+ get: async () => {
371
+ return await readFile(this.#readmePath, { encoding: Preferrence.encoding });
372
+ },
373
+ /**
374
+ * @param {string} content
375
+ */
376
+ set: async (content) => {
377
+ await FileSafe.write(this.#readmePath, content, { encoding: Preferrence.encoding });
378
+ },
223
379
  });
380
+
224
381
  /**
225
- * @param {string} string
226
- * @returns {string}
382
+ * @param { string } [exporter]
383
+ * @param { string } [typedefString]
384
+ * @returns { string }
227
385
  */
228
- #generateJSDOCFromstring = (string) => {
229
- return `\n/**\n * automatically generated by \`vivth.JSautoDOC\`\n * @copyright\n${string.replace(
230
- /^/gm,
231
- ' * '
232
- )}\n */\n`;
386
+ #generateSingularMJSExportAndType = (exporter, typedefString) => {
387
+ let content = '';
388
+ if (exporter) {
389
+ content += exporter ?? '';
390
+ }
391
+ if (exporter && typedefString) {
392
+ content += '\n';
393
+ }
394
+ if (typedefString) {
395
+ content += typedefString ?? '';
396
+ }
397
+ return content;
233
398
  };
399
+
234
400
  /**
235
- * @typedef { Object } generatedFromSRC
236
- * @property { string } readme
237
- * @property { string } mjsFile
401
+ * @param { string[] } array
402
+ * @returns { string[] }
238
403
  */
404
+ #cleanupArrayString = (array) => {
405
+ return array.filter((s) => s.trim() !== '');
406
+ };
407
+
239
408
  /**
240
- * @param {string} contentSRC
241
- * @param {Set<string>} filepaths
242
- * @returns {Promise<generatedFromSRC|undefined>}
409
+ * @param {[path: string, {
410
+ * path: string;
411
+ * parsed: undefined;
412
+ * ext: `.${string}`;
413
+ * type: returnTypeStringType;
414
+ * readme?: string;
415
+ * } | {
416
+ * path: string;
417
+ * parsed: parsedFileForDOC;
418
+ * ext: string;
419
+ * type: returnTypeStringType;
420
+ * readme?: string;
421
+ * }][]} array
422
+ * @returns {Promise<{
423
+ * readme:string,
424
+ * platforms:{
425
+ * node:string,
426
+ * browser:string,
427
+ * neutral:string,
428
+ * unsupported:string,
429
+ * all:string,
430
+ * },
431
+ * }|undefined>}
243
432
  */
244
- #generateFromSRC = async (contentSRC, filepaths) => {
433
+ #generateFromSRC = async (array) => {
434
+ const contentSRC = (await this.#readmeSourceGetterSetter.get?.()) ?? '';
245
435
  if (this.#tableOfContentTitle === undefined || this.#copyright === undefined) {
246
436
  return;
247
437
  }
248
438
  const tableID = this.#tableOfContentTitle.replace(/\s+/g, '-').toLowerCase();
439
+ /**
440
+ * @type { string[] }
441
+ */
249
442
  const tableOfContent = [];
443
+ /**
444
+ * @type { string[] }
445
+ */
250
446
  const apiDocuments = [];
251
- const mjsMain = ['// @ts-check', this.#generateJSDOCFromstring(this.#copyright)];
252
- const mjsTypes = [];
253
- const sortedFilepaths = [...filepaths].sort((a, b) => a.localeCompare(b));
254
- for await (const path_ of sortedFilepaths) {
255
- const {
256
- documented,
257
- content,
258
- hasValidExportObject,
259
- path: { relative: relativePath },
260
- baseName: { noExt },
261
- } = (await this.#parsedFilesRef.get(path_)).value;
262
- const trueContent = await content.string();
263
- if (trueContent === undefined) {
264
- return;
265
- }
266
- const hasNoAutoDoc = /\/\*\*[\s\*]*?@noautodoc[\s\*]*?\*\//.test(trueContent);
267
- if (hasValidExportObject) {
268
- mjsMain.push(
269
- `export { ${noExt} } from '${
270
- relativePath.startsWith('.') ? relativePath : `./${relativePath}`
271
- }';`
272
- );
273
- }
274
- /**
275
- * @type {string[]}
276
- */
277
- const currentDescription = [];
278
- const { readme, typedef } = documented;
279
- const [typedefString, error] = await TryAsync(async () => {
447
+ /**
448
+ * @type { Array<string> }
449
+ */
450
+ const all = [];
451
+ /**
452
+ * @type { Array<string> }
453
+ */
454
+ const node = [];
455
+ /**
456
+ * @type { Array<string> }
457
+ */
458
+ const browser = [];
459
+ /**
460
+ * @type { Array<string> }
461
+ */
462
+ const neutral = [];
463
+ /**
464
+ * @type { Array<string> }
465
+ */
466
+ const unsupported = [];
467
+
468
+ await Promise.all(
469
+ ForEach.array(array, async ([, { parsed }], i) => {
470
+ if (!parsed) {
471
+ return;
472
+ }
473
+ const {
474
+ documented,
475
+ content,
476
+ hasValidExportObject,
477
+ path: { relative: relativePath },
478
+ baseName: { noExt },
479
+ platform,
480
+ } = parsed;
481
+ const awaitedPlatform = await platform;
482
+ const trueContent = await content.string();
483
+ if (trueContent === undefined) {
484
+ return;
485
+ }
486
+ const hasNoAutoDoc = /\/\*\*[\s\*]*?@noautodoc[\s\*]*?\*\//.test(trueContent);
487
+ /**
488
+ * @type { undefined|string }
489
+ */
490
+ let comprehensiveExporter;
280
491
  if (hasValidExportObject) {
281
- throw new Error('');
492
+ comprehensiveExporter = `export { ${noExt} } from '${
493
+ relativePath.startsWith('.') ? relativePath : `./${relativePath}`
494
+ }';`;
282
495
  }
283
- const result = await typedef();
284
- return result;
285
- });
286
- if (error === undefined && typedefString) {
287
- mjsTypes.push(typedefString.module);
288
- if (hasNoAutoDoc === false) {
289
- const nameVarID = noExt.toLowerCase();
290
- tableOfContent.push(`[${noExt}](#${nameVarID})`);
291
- apiDocuments.push(
292
- `<h2 id="${nameVarID}">${noExt}</h2>\n\n- jsdoc types:\n\n\`\`\`js\n${
293
- typedefString.readme
294
- }\n\`\`\`\n*) <sub>[go to ${this.#tableOfContentTitle}](#${tableID})</sub>`
496
+ /**
497
+ * @type {string[]}
498
+ */
499
+ const currentDescription = [];
500
+ const { readme, typedef } = documented;
501
+ const [typedefString] = await TryAsync(async () => {
502
+ if (hasValidExportObject) {
503
+ throw 'has no valid export object';
504
+ }
505
+ const result = await typedef();
506
+ return result;
507
+ });
508
+ /**
509
+ * @type { undefined|string }
510
+ */
511
+ let comprehensiveTypedefString;
512
+ if (typedefString) {
513
+ const typedefStringModule = typedefString.module;
514
+ comprehensiveTypedefString = typedefStringModule;
515
+ if (!hasNoAutoDoc) {
516
+ const nameVarID = noExt.toLowerCase();
517
+ tableOfContent[i] =
518
+ tableOfContent[i] ?? '' + `[${awaitedPlatform}.${noExt}](#${nameVarID})`;
519
+ apiDocuments[i] =
520
+ apiDocuments[i] ??
521
+ '' +
522
+ `<h2 id="${nameVarID}">${awaitedPlatform}.${noExt}</h2>\n\n- jsdoc types:\n\n\`\`\`js\n${
523
+ /** */
524
+ typedefString.readme.replace(/\[at\]/g, '@').replace(/\[blank\]/g, '[]')
525
+ }\n\`\`\`\n*) <sub>[go to ${this.#tableOfContentTitle}](#${tableID})</sub>\n\n---`;
526
+ }
527
+ }
528
+ if (!hasNoAutoDoc && hasValidExportObject) {
529
+ ForOfSync(
530
+ readme,
531
+ ({
532
+ // fullDescription,
533
+ // instanceOrStatic,
534
+ // namedVar,
535
+ // typeOfVar,
536
+ parsedFullDescription,
537
+ reference,
538
+ }) => {
539
+ const { description, jsPreview } = parsedFullDescription;
540
+ currentDescription.push(
541
+ `\n#### reference: ${reference}\n${description}\n${jsPreview}`.replace(
542
+ /\[blank\]/g,
543
+ '',
544
+ ),
545
+ );
546
+ },
295
547
  );
548
+ const nameVarID = noExt.toLowerCase();
549
+ tableOfContent[i] =
550
+ tableOfContent[i] ?? '' + `[${awaitedPlatform}.${noExt}](#${noExt.toLowerCase()})`;
551
+ apiDocuments[i] =
552
+ apiDocuments[i] ??
553
+ '' +
554
+ `<h2 id="${nameVarID}">${awaitedPlatform}.${noExt}</h2>\n\n-current-description-to-replace-\n\n*) <sub>[go to ${
555
+ this.#tableOfContentTitle
556
+ }](#${tableID})</sub>\n\n---`.replace(
557
+ '-current-description-to-replace-',
558
+ currentDescription.join('\n'),
559
+ );
296
560
  }
297
- }
298
- if (hasNoAutoDoc === false && hasValidExportObject) {
299
- readme.forEach((ref) => {
300
- const {
301
- // fullDescription,
302
- // instanceOrStatic,
303
- // namedVar,
304
- // typeOfVar,
305
- parsedFullDescription,
306
- reference,
307
- } = ref;
308
- const { description, jsPreview } = parsedFullDescription;
309
- currentDescription.push(`\n#### reference:${reference}\n${description}\n${jsPreview}`);
310
- });
311
- const nameVarID = noExt.toLowerCase();
312
- tableOfContent.push(`[${noExt}](#${noExt.toLowerCase()})`);
313
- apiDocuments.push(
314
- `<h2 id="${nameVarID}">${noExt}</h2>\n\n-current-description-to-replace-\n\n*) <sub>[go to ${
315
- this.#tableOfContentTitle
316
- }](#${tableID})</sub>`.replace(
317
- '-current-description-to-replace-',
318
- currentDescription.join('\n')
319
- )
561
+
562
+ const collectedExportContent = this.#generateSingularMJSExportAndType(
563
+ comprehensiveExporter,
564
+ comprehensiveTypedefString,
320
565
  );
321
- }
322
- }
566
+ if (collectedExportContent) {
567
+ all[i] = collectedExportContent;
568
+ }
569
+
570
+ switch (awaitedPlatform) {
571
+ case 'node':
572
+ {
573
+ if (collectedExportContent) {
574
+ node[i] = collectedExportContent;
575
+ }
576
+ }
577
+ break;
578
+ case 'browser':
579
+ {
580
+ if (collectedExportContent) {
581
+ browser[i] = collectedExportContent;
582
+ }
583
+ }
584
+ break;
585
+ case 'neutral':
586
+ {
587
+ if (collectedExportContent) {
588
+ neutral[i] = collectedExportContent;
589
+ }
590
+ }
591
+ break;
592
+ default:
593
+ case 'unsupported':
594
+ {
595
+ if (collectedExportContent) {
596
+ unsupported[i] = collectedExportContent;
597
+ }
598
+ }
599
+ break;
600
+ }
601
+ }),
602
+ );
323
603
  const tableOfContentString = `<h2 id="${this.#tableOfContentTitle
324
604
  .replace(/\s+/g, '-')
325
605
  .toLowerCase()}">${
326
606
  this.#tableOfContentTitle
327
- }</h2>\n\n - -table-of-content-to-replace-\n\n-api-document-to-replace-`
328
- .replace('-table-of-content-to-replace-', tableOfContent.join('\n - '))
329
- .replace('-api-document-to-replace-', apiDocuments.join('\n\n'));
330
- return {
331
- mjsFile: [...mjsMain, ...mjsTypes].join('\n'),
332
- readme: `${contentSRC}\n${tableOfContentString}`,
333
- };
334
- };
335
- #parsedFilesRef = LazyFactory(() => {
336
- const prefix = 'parsedFiles:';
607
+ }</h2>\n\n - -table-of-content-to-replace-\n\n---\n\n-api-document-to-replace-`
608
+ .replace(
609
+ '-table-of-content-to-replace-',
610
+ this.#cleanupArrayString(tableOfContent).join('\n - '),
611
+ )
612
+ .replace('-api-document-to-replace-', this.#cleanupArrayString(apiDocuments).join('\n\n'));
613
+
614
+ const readme = `${contentSRC}\n\n---\n\n${tableOfContentString}`;
615
+
337
616
  return {
338
- /**
339
- * @param {string} path__
340
- * @returns {Promise<Signal<parsedFile>>}
341
- */
342
- get: async (path__) => {
343
- const dispatch = (await EventSignal.get(`${prefix}${path__}`, false)).dispatch;
344
- // @ts-expect-error
345
- return dispatch;
346
- },
347
- /**
348
- * @param {string} path__
349
- * @returns {Promise<void>}
350
- */
351
- unRef: async (path__) => {
352
- const parsedFile = await this.#parsedFilesRef.get(`${prefix}${path__}`);
353
- parsedFile.remove.ref();
617
+ readme,
618
+ platforms: {
619
+ all: this.#cleanupArrayString(all).join('\n'),
620
+ browser: this.#cleanupArrayString(browser).join('\n'),
621
+ neutral: this.#cleanupArrayString(neutral).join('\n'),
622
+ node: this.#cleanupArrayString(node).join('\n'),
623
+ unsupported: this.#cleanupArrayString(unsupported).join('\n'),
354
624
  },
355
625
  };
356
- });
626
+ };
627
+
357
628
  /**
358
- * @type {(eventName: 'add'|'change', path: string, stats?: import('fs').Stats) => void}
629
+ * @param {string} name
630
+ * @param {boolean} absolutePath
631
+ * @returns {string}
359
632
  */
360
- #addHandler = (eventName, path__, _stats) => {
361
- TryAsync(async () => {
362
- if (
363
- //
364
- !_stats?.isFile()
365
- ) {
366
- return;
367
- }
368
- const res = await correctBeforeParse(path__, 'utf-8');
369
- switch (res) {
370
- case 'shouldProceedNextCheck':
371
- const dispatch = await this.#parsedFilesRef.get(path__);
372
- dispatch.value = new parsedFile(path__, _stats, encoding);
373
- this.#filePaths.subscribers.notify(async ({ signalInstance }) => {
374
- await dispatch.value.parse();
375
- dispatch.subscribers.notify();
376
- Console.info({ vivthJSautoDOC: `${eventName} '${path__}' to export and doc` });
377
- signalInstance.value.add(path__);
378
- });
379
- break;
380
- case 'waitForRewrite':
381
- case 'doNotProcess':
382
- break;
633
+ #generateExportPath = (name, absolutePath) => {
634
+ const rel = Paths.normalize(join(multiExportEntryPointsPath, `${name}.mjs`));
635
+ if (!absolutePath) {
636
+ if (!rel.startsWith('.')) {
637
+ return `./${rel}`;
383
638
  }
384
- }).then(([, error]) => {
385
- if (error === undefined) {
386
- return;
387
- }
388
- Console.error(error);
639
+ return rel;
640
+ }
641
+ return Paths.normalize(join(Paths.root, rel));
642
+ };
643
+
644
+ /**
645
+ * @param {string} content
646
+ * @returns {string}
647
+ */
648
+ #generateExportMJSDOCFromstring = (content) => {
649
+ return `// @ts-check\n/**\n * automatically generated by \`JSautoDOC\`\n * @copyright\n${(
650
+ this.#copyright ?? ''
651
+ ).replace(/^/gm, ' * ')}\n */\n${content}`;
652
+ };
653
+
654
+ /**
655
+ * @param {string} name
656
+ * @param {Object} [packageJSONObject]
657
+ * @returns {void}
658
+ */
659
+ #assignToPackageJSONExports = (name, packageJSONObject) => {
660
+ if (!packageJSONObject) {
661
+ return;
662
+ }
663
+ const relativePath = this.#generateExportPath(name, false);
664
+ if (name === 'all') {
665
+ Object.assign(packageJSONObject, { main: relativePath, module: relativePath });
666
+ }
667
+ Object.assign(packageJSONObject, {
668
+ exports: {
669
+ ...// @ts-expect-error
670
+ (packageJSONObject.exports ?? {}),
671
+ [`.${Paths.normalizeForRoot(name)}`]: {
672
+ import: relativePath,
673
+ types: relativePath.replace('./', './generated/types/').replace(/\.mjs$/g, '.d.mts'),
674
+ },
675
+ },
389
676
  });
390
677
  };
678
+
391
679
  /**
392
- * @type {(eventName: 'unlink', path: string, stats?: import('fs').Stats) => void}
680
+ * @param {{
681
+ * all:string,
682
+ * node:string,
683
+ * browser:string,
684
+ * neutral:string,
685
+ * unsupported:string,
686
+ * }} platforms
687
+ * @param {BufferEncoding} encoding
688
+ * @param {any} packageJSONObject
689
+ * @param {'node'|'browser'|'neutral'|'unsupported'} name
690
+ * @returns {ReturnType<typeof TryAsync<void>>}
393
691
  */
394
- #removeHandler = (eventName, path__, _stats) => {
395
- TryAsync(async () => {
396
- if (_stats?.isFile()) {
397
- return true;
398
- }
399
- return false;
400
- }).then(([, error]) => {
401
- if (error === undefined) {
692
+ #generatePlatformsHandler = (platforms, encoding, packageJSONObject, name) => {
693
+ return TryAsync(async () => {
694
+ const path = this.#generateExportPath(name, true);
695
+ if (!platforms[name]) {
696
+ const [, errorRemovingPath] = await FileSafe.rm(path);
697
+ if (errorRemovingPath) {
698
+ return;
699
+ }
700
+ Console.info(
701
+ {
702
+ JSautoDOC: `✅ Successfully deleting '${path}' for having no valid exports`,
703
+ },
704
+ {
705
+ now: true,
706
+ },
707
+ );
402
708
  return;
403
709
  }
404
- this.#filePaths.subscribers.notify(async ({ signalInstance }) => {
405
- Console.warn({ [eventName]: path__ });
406
- signalInstance.value.delete(path__);
407
- await this.#parsedFilesRef.unRef(path__);
710
+ const content = this.#generateExportMJSDOCFromstring(platforms[name]);
711
+ this.#assignToPackageJSONExports(name, packageJSONObject);
712
+ await FileSafe.write(path, content, {
713
+ encoding,
408
714
  });
715
+ Console.info(
716
+ {
717
+ JSautoDOC: `✅ Successfully write '${path}'`,
718
+ },
719
+ {
720
+ now: true,
721
+ },
722
+ );
409
723
  });
410
724
  };
725
+
726
+ /**
727
+ * @type {FSDirArchWatcher__["fullHandler"]}
728
+ */
729
+ #fullHandler = async ({ array, map }) => {
730
+ const readmePath = this.#readme;
731
+ Console.info(
732
+ {
733
+ JSautoDOC: `generating content for '${Paths.normalize(readmePath)}'`,
734
+ },
735
+ {
736
+ now: true,
737
+ },
738
+ );
739
+ const res = await this.#generateFromSRC(array);
740
+ if (!res) {
741
+ return;
742
+ }
743
+ const { readme, platforms } = res;
744
+ const [packageJSONObject] = await this.#packageJSONHandler.read();
745
+ const encoding = Preferrence.encoding;
746
+ const [promises_] = ForOfSync(
747
+ ['all', 'browser', 'node', 'neutral', 'unsupported'],
748
+ async (key) => {
749
+ await this.#generatePlatformsHandler(
750
+ platforms,
751
+ encoding,
752
+ packageJSONObject,
753
+ // @ts-expect-error
754
+ key,
755
+ );
756
+ },
757
+ );
758
+ const [[, errorWriteReadme]] = await Promise.all([
759
+ TryAsync(async () => {
760
+ return await FileSafe.write(
761
+ readmePath,
762
+ await prettier.format(readme, { parser: 'markdown' }),
763
+ {
764
+ encoding,
765
+ },
766
+ );
767
+ }),
768
+ ...promises_,
769
+ ]);
770
+ if (!!packageJSONObject) {
771
+ await this.#packageJSONHandler.write(packageJSONObject);
772
+ }
773
+ if (errorWriteReadme === undefined) {
774
+ Console.info(
775
+ {
776
+ JSautoDOC: `✅ Successfully generate '${Paths.normalize(readmePath)}';`,
777
+ },
778
+ {
779
+ now: true,
780
+ },
781
+ );
782
+ }
783
+ if (errorWriteReadme) {
784
+ Console.error(
785
+ {
786
+ JSautoDOC: `❌ Unable to generate '${Paths.normalize(readmePath)}';`,
787
+ errorWriteReadme,
788
+ },
789
+ {
790
+ now: true,
791
+ },
792
+ );
793
+ return;
794
+ }
795
+ if (!this.#onLastGeneratedCallback) {
796
+ return;
797
+ }
798
+ await this.#onLastGeneratedCallback({ map });
799
+ };
411
800
  }