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.
- package/README.md +6060 -2037
- package/README.src.md +22 -14
- package/bun.lock +154 -194
- package/dev/auto/.src.ignore +25 -0
- package/dev/auto-doc.mjs +137 -0
- package/generated/types/generated/vivth/exports/all.d.mts +145 -0
- package/generated/types/generated/vivth/exports/neutral.d.mts +105 -0
- package/generated/types/generated/vivth/exports/node.d.mts +40 -0
- package/generated/types/src/bundler/CompileAS.d.mts +30 -0
- package/generated/types/src/bundler/CompileJS.d.mts +109 -0
- package/{types → generated/types}/src/bundler/CreateESPlugin.d.mts +1 -1
- package/{types → generated/types}/src/bundler/EsBundler.d.mts +9 -7
- package/generated/types/src/bundler/FSAnalyzer.d.mts +58 -0
- package/generated/types/src/bundler/FSasar.bundled.d.mts +28 -0
- package/generated/types/src/bundler/FSasar.d.mts +51 -0
- package/generated/types/src/bundler/FileSelfMapper.d.mts +137 -0
- package/generated/types/src/bundler/JSDirMapper.d.mts +128 -0
- package/generated/types/src/bundler/RunWatchThenCompileJSOnSafeExit.d.mts +63 -0
- package/generated/types/src/bundler/adds/BrowserExternals.d.mts +21 -0
- package/generated/types/src/bundler/adds/CreateTransform.d.mts +26 -0
- package/generated/types/src/bundler/adds/LastEditedUnix.d.mts +5 -0
- package/generated/types/src/bundler/adds/NodeModuleList.d.mts +15 -0
- package/generated/types/src/bundler/adds/PathFSBundles.bundled.d.mts +25 -0
- package/generated/types/src/bundler/adds/PathFSBundles.d.mts +48 -0
- package/generated/types/src/bundler/adds/PathFSDir.bundled.d.mts +30 -0
- package/generated/types/src/bundler/adds/PathFSDir.d.mts +48 -0
- package/generated/types/src/bundler/adds/PathFSFile.bundled.d.mts +25 -0
- package/generated/types/src/bundler/adds/PathFSFile.d.mts +40 -0
- package/{types → generated/types}/src/bundler/adds/ToBundledJSPlugin.d.mts +6 -6
- package/generated/types/src/bundler/adds/autoExternalize.d.mts +2 -0
- package/generated/types/src/bundler/adds/emptyBufferValue.d.mts +1 -0
- package/generated/types/src/bundler/adds/isModuleTheBundledVersion.d.mts +1 -0
- package/generated/types/src/bundler/adds/onEndEsBuildErrorLogger.d.mts +1 -0
- package/generated/types/src/bundler/adds/resolveJSDependencyPath.d.mts +1 -0
- package/generated/types/src/class/AwaitSignal.d.mts +48 -0
- package/generated/types/src/class/Console.d.mts +82 -0
- package/generated/types/src/class/DataLog.d.mts +25 -0
- package/generated/types/src/class/Derived.d.mts +74 -0
- package/generated/types/src/class/Effect.d.mts +213 -0
- package/{types → generated/types}/src/class/EnvSignal.d.mts +6 -2
- package/generated/types/src/class/EsWatcher.d.mts +36 -0
- package/{types → generated/types}/src/class/EventSignal.d.mts +39 -39
- package/generated/types/src/class/FSDirArchWatcher.d.mts +110 -0
- package/{types → generated/types}/src/class/FileSafe.d.mts +32 -16
- package/generated/types/src/class/ForEach.d.mts +57 -0
- package/generated/types/src/class/ForSignal.d.mts +63 -0
- package/generated/types/src/class/GetterSetter.d.mts +38 -0
- package/generated/types/src/class/JSONFileHandler.d.mts +50 -0
- package/{types → generated/types}/src/class/ListSignal.d.mts +49 -15
- package/{types → generated/types}/src/class/LitExp.d.mts +18 -18
- package/generated/types/src/class/ObjectSignal.d.mts +267 -0
- package/generated/types/src/class/Paths.d.mts +95 -0
- package/generated/types/src/class/Prettivy.d.mts +26 -0
- package/{types → generated/types}/src/class/QChannel.d.mts +24 -16
- package/generated/types/src/class/SafeExit.d.mts +69 -0
- package/{types → generated/types}/src/class/Setup.d.mts +29 -16
- package/{types → generated/types}/src/class/Signal.d.mts +29 -15
- package/generated/types/src/class/SignalCollection.d.mts +96 -0
- package/{types → generated/types}/src/class/WalkThrough.d.mts +4 -19
- package/generated/types/src/class/WorkerMainThread.bundled.d.mts +83 -0
- package/{types → generated/types}/src/class/WorkerMainThread.d.mts +33 -39
- package/{types → generated/types}/src/class/WorkerThread.d.mts +11 -5
- package/{types → generated/types}/src/common/Base64URL.d.mts +2 -1
- package/generated/types/src/common/Base64URLFromFile.d.mts +20 -0
- package/generated/types/src/common/BundledV.bundled.d.mts +3 -0
- package/generated/types/src/common/BundledV.d.mts +36 -0
- package/{types → generated/types}/src/common/CreateStringID.d.mts +5 -4
- package/generated/types/src/common/EnvMode.d.mts +79 -0
- package/generated/types/src/common/FactoryKey.d.mts +9 -0
- package/generated/types/src/common/Preferrence.d.mts +25 -0
- package/{types → generated/types}/src/common/Trace.d.mts +1 -1
- package/{types → generated/types}/src/common/TracePath.d.mts +1 -1
- package/generated/types/src/common/VivthUnBundledCodeBlock.d.mts +6 -0
- package/generated/types/src/doc/JSautoDOC.d.mts +172 -0
- package/generated/types/src/doc/cleanPreserveTypedef.d.mts +1 -0
- package/{types/src/doc/parsedFile.d.mts → generated/types/src/doc/parsedFileForDOC.d.mts} +56 -27
- package/generated/types/src/function/ClearRequireCache.d.mts +1 -0
- package/{types → generated/types}/src/function/CreateImmutable.d.mts +5 -4
- package/{types → generated/types}/src/function/EventCheck.d.mts +3 -1
- package/{types → generated/types}/src/function/EventObject.d.mts +2 -6
- package/generated/types/src/function/ForInAsync.d.mts +36 -0
- package/generated/types/src/function/ForInSync.d.mts +36 -0
- package/generated/types/src/function/ForOfAsync.d.mts +25 -0
- package/generated/types/src/function/ForOfSync.d.mts +36 -0
- package/generated/types/src/function/GetBufferFromRelativePath.d.mts +15 -0
- package/generated/types/src/function/GetFilesFromDir.d.mts +14 -0
- package/generated/types/src/function/GetMaxFilenameLength.d.mts +9 -0
- package/generated/types/src/function/GetModuleEsbuildPlatform.d.mts +13 -0
- package/{types → generated/types}/src/function/GetNamedImportAlias.d.mts +1 -1
- package/generated/types/src/function/GetRuntime.d.mts +2 -0
- package/generated/types/src/function/InstantiateAssemblyScript.d.mts +15 -0
- package/{types → generated/types}/src/function/IsAsync.d.mts +1 -1
- package/generated/types/src/function/IsInstanceOf.d.mts +25 -0
- package/generated/types/src/function/IsSameFile.d.mts +16 -0
- package/generated/types/src/function/IsStringLooksLikeAPath.d.mts +16 -0
- package/generated/types/src/function/IsTypeOf.d.mts +25 -0
- package/{types → generated/types}/src/function/LazyFactory.d.mts +9 -10
- package/generated/types/src/function/MonkeyPatch.d.mts +33 -0
- package/generated/types/src/function/NewAnimationTimeline.d.mts +24 -0
- package/generated/types/src/function/NewChainable.d.mts +35 -0
- package/generated/types/src/function/NewDynamicsExport.d.mts +49 -0
- package/generated/types/src/function/NewObjectWrapper.d.mts +10 -0
- package/generated/types/src/function/ObjectRegistrar.d.mts +17 -0
- package/generated/types/src/function/ParseSQLFile.d.mts +25 -0
- package/generated/types/src/function/PipeAsync.d.mts +19 -0
- package/generated/types/src/function/PipeSync.d.mts +17 -0
- package/generated/types/src/function/SafeImport.d.mts +21 -0
- package/generated/types/src/function/TemplateLiteral.d.mts +23 -0
- package/{types → generated/types}/src/function/Timeout.d.mts +1 -1
- package/{types → generated/types}/src/function/Tries.d.mts +4 -4
- package/{types → generated/types}/src/function/TryAsync.d.mts +2 -2
- package/{types → generated/types}/src/function/TryNew.d.mts +1 -1
- package/generated/types/src/function/TsToMjs.d.mts +27 -0
- package/generated/types/src/function/UniqueFSTempName.d.mts +9 -0
- package/generated/types/src/function/errorToMessage.d.mts +5 -0
- package/generated/types/src/neinth/VivthyNeinth.d.mts +202 -0
- package/generated/types/src/typehints/ArrayToKeys.d.mts +23 -0
- package/generated/types/src/typehints/AssemblyScriptExportsType.d.mts +4 -0
- package/generated/types/src/typehints/AssemblyScriptLoaderInstantiate.d.mts +4 -0
- package/generated/types/src/typehints/AutoDocASOptions.d.mts +15 -0
- package/generated/types/src/typehints/ChainableType.d.mts +3 -0
- package/generated/types/src/typehints/ComponentDecorator_Constructor.d.mts +3 -0
- package/generated/types/src/typehints/ConsoleAdditionalSettingType.d.mts +3 -0
- package/generated/types/src/typehints/Decorator.d.mts +11 -0
- package/generated/types/src/typehints/DecoratorMonkeyPatch.d.mts +15 -0
- package/{types/src/types → generated/types/src/typehints}/DevTestCB.d.mts +2 -2
- package/generated/types/src/typehints/EnvModeType.d.mts +4 -0
- package/generated/types/src/typehints/ListArg.d.mts +4 -0
- package/generated/types/src/typehints/MonkeyPatchedType.d.mts +1 -0
- package/generated/types/src/typehints/ParametersFollowingN.d.mts +13 -0
- package/generated/types/src/typehints/PrefixedKeysOf.d.mts +1 -0
- package/generated/types/src/typehints/Runtime.d.mts +4 -0
- package/generated/types/src/typehints/SafeImportReturnType.d.mts +1 -0
- package/generated/types/src/typehints/StylePropRefType.d.mts +2 -0
- package/generated/types/src/typehints/TemplateLiteralValueHandler.d.mts +10 -0
- package/generated/types/src/typehints/VLifecycleCallbacks.d.mts +6 -0
- package/generated/types/src/typehints/VivthCleanup.d.mts +12 -0
- package/generated/types/src/web/BrowserDirMapper.d.mts +70 -0
- package/generated/types/src/web/EnsureValidTag.d.mts +7 -0
- package/generated/types/src/web/ViteAddDynamics.d.mts +28 -0
- package/generated/types/src/web/ViteGetAllHTMLFile.d.mts +9 -0
- package/generated/types/src/web/WC_extendsA.d.mts +135 -0
- package/generated/types/src/web/WC_extendsB.d.mts +135 -0
- package/generated/types/src/web/bindings/WC_StyleProp_bind.d.mts +42 -0
- package/generated/types/src/web/bindings/WC_createElement_bind.d.mts +51 -0
- package/generated/types/src/web/bindings/WC_createNamedSlot.d.mts +26 -0
- package/generated/types/src/web/bindings/WC_litRender_bind.d.mts +20 -0
- package/generated/types/src/web/bindings/WC_litStyleMap.d.mts +7 -0
- package/generated/types/src/web/common/CSS.d.mts +23 -0
- package/generated/types/src/web/common/E.d.mts +41 -0
- package/generated/types/src/web/common/NewStyleSheetAsync.d.mts +15 -0
- package/generated/types/src/web/common/NewStyleSheetSync.d.mts +15 -0
- package/generated/types/src/web/common/WC_TagName_type.d.mts +15 -0
- package/generated/types/src/web/signals/IsInViewPortSignal.d.mts +52 -0
- package/generated/types/src/web/signals/ObserverSignal.d.mts +32 -0
- package/generated/types/src/web/signals/WC_litRef.d.mts +26 -0
- package/generated/types/src/web/signals/WC_loopedSiblingsRef.d.mts +44 -0
- package/generated/vivth/exports/all.mjs +233 -0
- package/generated/vivth/exports/neutral.mjs +193 -0
- package/generated/vivth/exports/node.mjs +46 -0
- package/package.json +50 -14
- package/src/bundler/CompileAS.mjs +36 -0
- package/src/bundler/CompileJS.mjs +98 -171
- package/src/bundler/CreateESPlugin.mjs +1 -1
- package/src/bundler/EsBundler.mjs +38 -13
- package/src/bundler/FSAnalyzer.mjs +253 -0
- package/src/bundler/FSasar.bundled.mjs +128 -0
- package/src/bundler/FSasar.mjs +96 -0
- package/src/bundler/FileSelfMapper.mjs +491 -0
- package/src/bundler/JSDirMapper.mjs +528 -0
- package/src/bundler/RunWatchThenCompileJSOnSafeExit.mjs +129 -0
- package/src/bundler/adds/BrowserExternals.mjs +37 -0
- package/src/bundler/adds/CreateTransform.mjs +36 -0
- package/src/bundler/adds/LastEditedUnix.mjs +12 -0
- package/src/bundler/adds/NodeModuleList.mjs +33 -0
- package/src/bundler/adds/PathFSBundles.bundled.mjs +41 -0
- package/src/bundler/adds/PathFSBundles.mjs +91 -0
- package/src/bundler/adds/PathFSDir.bundled.mjs +53 -0
- package/src/bundler/adds/PathFSDir.mjs +100 -0
- package/src/bundler/adds/PathFSFile.bundled.mjs +40 -0
- package/src/bundler/adds/PathFSFile.mjs +85 -0
- package/src/bundler/adds/ToBundledJSPlugin.mjs +116 -55
- package/src/bundler/adds/autoExternalize.mjs +81 -0
- package/src/bundler/adds/emptyBufferValue.mjs +5 -0
- package/src/bundler/adds/isModuleTheBundledVersion.mjs +10 -0
- package/src/bundler/adds/onEndEsBuildErrorLogger.mjs +34 -0
- package/src/bundler/adds/resolveJSDependencyPath.mjs +17 -0
- package/src/class/AwaitSignal.mjs +119 -0
- package/src/class/Console.mjs +36 -14
- package/src/class/DataLog.mjs +29 -0
- package/src/class/Derived.mjs +67 -55
- package/src/class/Effect.mjs +270 -84
- package/src/class/EnvSignal.mjs +11 -8
- package/src/class/EsWatcher.mjs +60 -0
- package/src/class/EventSignal.mjs +46 -58
- package/src/class/FSDirArchWatcher.mjs +246 -0
- package/src/class/FileSafe.mjs +72 -24
- package/src/class/ForEach.mjs +78 -0
- package/src/class/ForSignal.mjs +115 -0
- package/src/class/GetterSetter.mjs +40 -0
- package/src/class/JSONFileHandler.mjs +90 -0
- package/src/class/ListSignal.mjs +68 -26
- package/src/class/LitExp.mjs +59 -36
- package/src/class/ObjectSignal.mjs +225 -0
- package/src/class/Paths.mjs +56 -20
- package/src/class/Prettivy.mjs +51 -0
- package/src/class/QChannel.mjs +48 -26
- package/src/class/SafeExit.mjs +156 -99
- package/src/class/Setup.mjs +28 -16
- package/src/class/Signal.mjs +50 -27
- package/src/class/SignalCollection.mjs +130 -0
- package/src/class/WalkThrough.mjs +6 -23
- package/src/class/{WorkerMainThreadBundled.mjs → WorkerMainThread.bundled.mjs} +56 -77
- package/src/class/WorkerMainThread.mjs +98 -94
- package/src/class/WorkerThread.mjs +24 -17
- package/src/common/Base64URL.mjs +6 -3
- package/src/common/Base64URLFromFile.mjs +17 -4
- package/src/common/BundledV.bundled.mjs +7 -0
- package/src/common/BundledV.mjs +45 -0
- package/src/common/CreateStringID.mjs +8 -7
- package/src/common/EnvMode.mjs +172 -0
- package/src/common/FactoryKey.mjs +11 -0
- package/src/common/Preferrence.mjs +27 -0
- package/src/common/Trace.mjs +1 -1
- package/src/common/TracePath.mjs +53 -3
- package/src/common/VivthUnBundledCodeBlock.mjs +8 -0
- package/src/doc/JSautoDOC.mjs +673 -284
- package/src/doc/cleanPreserveTypedef.mjs +27 -0
- package/src/doc/correctBeforeParse.mjs +57 -48
- package/src/doc/{parsedFile.mjs → parsedFileForDOC.mjs} +133 -120
- package/src/function/ClearRequireCache.mjs +33 -0
- package/src/function/CreateImmutable.mjs +40 -37
- package/src/function/EventCheck.mjs +5 -2
- package/src/function/EventObject.mjs +2 -6
- package/src/function/ForInAsync.mjs +76 -0
- package/src/function/ForInSync.mjs +87 -0
- package/src/function/ForOfAsync.mjs +61 -0
- package/src/function/ForOfSync.mjs +70 -0
- package/src/function/GetBufferFromRelativePath.mjs +25 -0
- package/src/function/GetFilesFromDir.mjs +49 -0
- package/src/function/GetMaxFilenameLength.mjs +32 -0
- package/src/function/GetModuleEsbuildPlatform.mjs +118 -0
- package/src/function/GetNamedImportAlias.mjs +2 -2
- package/src/function/GetRuntime.mjs +10 -14
- package/src/function/InstantiateAssemblyScript.mjs +22 -0
- package/src/function/IsAsync.mjs +1 -1
- package/src/function/IsInstanceOf.mjs +29 -0
- package/src/function/IsSameFile.mjs +41 -0
- package/src/function/IsStringLooksLikeAPath.mjs +20 -0
- package/src/function/IsTypeOf.mjs +27 -0
- package/src/function/IsTypeOf.mts +31 -0
- package/src/function/LazyFactory.mjs +25 -23
- package/src/function/MonkeyPatch.mjs +38 -0
- package/src/function/NewAnimationTimeline.mjs +55 -0
- package/src/function/NewChainable.mjs +69 -0
- package/src/function/NewDynamicsExport.mjs +312 -0
- package/src/function/NewObjectWrapper.mjs +14 -0
- package/src/function/ObjectRegistrar.mjs +23 -0
- package/src/function/ParseSQLFile.mjs +129 -0
- package/src/function/PipeAsync.mjs +30 -0
- package/src/function/PipeSync.mjs +28 -0
- package/src/function/SafeImport.mjs +77 -0
- package/src/function/TemplateLiteral.mjs +42 -23
- package/src/function/Timeout.mjs +4 -4
- package/src/function/Tries.mjs +22 -16
- package/src/function/TryAsync.mjs +3 -2
- package/src/function/TryNew.mjs +1 -1
- package/src/function/TsToMjs.mjs +184 -21
- package/src/function/UniqueFSTempName.mjs +33 -0
- package/src/function/errorToMessage.mjs +21 -0
- package/src/function/resolveErrorArray.mjs +15 -1
- package/src/neinth/VivthyNeinth.mjs +487 -0
- package/src/typehints/ArrayToKeys.mjs +17 -0
- package/src/typehints/ArrayToKeys.mts +31 -0
- package/src/typehints/AssemblyScriptExportsType.mjs +7 -0
- package/src/typehints/AssemblyScriptLoaderInstantiate.mjs +7 -0
- package/src/typehints/AutoDocASOptions.mjs +14 -0
- package/src/typehints/ChainableType.mjs +11 -0
- package/src/typehints/ComponentDecorator_Constructor.mjs +10 -0
- package/src/typehints/ConsoleAdditionalSettingType.mjs +6 -0
- package/src/typehints/Decorator.mjs +9 -0
- package/src/typehints/Decorator.mts +31 -0
- package/src/typehints/DecoratorMonkeyPatch.mjs +10 -0
- package/src/typehints/DecoratorMonkeyPatch.mts +43 -0
- package/src/{types → typehints}/DevTestCB.mjs +2 -2
- package/src/typehints/EnvModeType.mjs +6 -0
- package/src/{types → typehints}/ListArg.mjs +1 -1
- package/src/{types → typehints}/LitExpResultType.mjs +1 -1
- package/src/typehints/MonkeyPatchedType.mjs +13 -0
- package/src/typehints/ParametersFollowingN.mjs +8 -0
- package/src/typehints/ParametersFollowingN.mts +17 -0
- package/src/typehints/PrefixedKeysOf.mjs +9 -0
- package/src/typehints/Runtime.mjs +6 -0
- package/src/typehints/SafeImportReturnType.mjs +6 -0
- package/src/typehints/StylePropRefType.mjs +12 -0
- package/src/typehints/TemplateLiteralValueHandler.mjs +14 -0
- package/src/typehints/VLifecycleCallbacks.mjs +10 -0
- package/src/typehints/VivthCleanup.mjs +14 -0
- package/src/web/BrowserDirMapper.mjs +255 -0
- package/src/web/EnsureValidTag.mjs +5 -0
- package/src/web/EnsureValidTag.mts +10 -0
- package/src/web/ViteAddDynamics.mjs +34 -0
- package/src/web/ViteGetAllHTMLFile.mjs +97 -0
- package/src/web/WC_extendsA.mjs +330 -0
- package/src/web/WC_extendsB.mjs +332 -0
- package/src/web/bindings/WC_StyleProp_bind.mjs +70 -0
- package/src/web/bindings/WC_createElement_bind.mjs +95 -0
- package/src/web/bindings/WC_createNamedSlot.mjs +29 -0
- package/src/web/bindings/WC_litRender_bind.mjs +26 -0
- package/src/web/bindings/WC_litStyleMap.mjs +14 -0
- package/src/web/common/CSS.mjs +35 -0
- package/src/web/common/E.mjs +126 -0
- package/src/web/common/NewStyleSheetAsync.mjs +21 -0
- package/src/web/common/NewStyleSheetSync.mjs +21 -0
- package/src/web/common/WC_TagName_type.mjs +10 -0
- package/src/web/common/WC_TagName_type.mts +36 -0
- package/src/web/signals/IsInViewPortSignal.mjs +140 -0
- package/src/web/signals/ObserverSignal.mjs +93 -0
- package/src/web/signals/WC_litRef.mjs +61 -0
- package/src/web/signals/WC_loopedSiblingsRef.mjs +100 -0
- package/tsconfig.json +44 -41
- package/index.mjs +0 -91
- package/src/bundler/FSInline.mjs +0 -67
- package/src/bundler/FSInlineAnalyzer.mjs +0 -228
- package/src/bundler/FSInlineBundled.mjs +0 -38
- package/src/bundler/adds/externals.mjs +0 -8
- package/src/class/ListDerived.mjs +0 -42
- package/src/common/Dev.mjs +0 -142
- package/src/common/DevBundled.mjs +0 -5
- package/src/common/lazie.mjs +0 -3
- package/src/types/IsListSignal.mjs +0 -6
- package/src/types/Runtime.mjs +0 -6
- package/src/types/VivthDevCodeBlockStringType.mjs +0 -6
- package/types/index.d.mts +0 -58
- package/types/src/bundler/CompileJS.d.mts +0 -119
- package/types/src/bundler/FSInline.d.mts +0 -50
- package/types/src/bundler/FSInlineAnalyzer.d.mts +0 -37
- package/types/src/bundler/FSInlineBundled.d.mts +0 -22
- package/types/src/bundler/adds/externals.d.mts +0 -1
- package/types/src/class/Console.d.mts +0 -71
- package/types/src/class/Derived.d.mts +0 -98
- package/types/src/class/Effect.d.mts +0 -216
- package/types/src/class/ListDerived.d.mts +0 -38
- package/types/src/class/Paths.d.mts +0 -69
- package/types/src/class/SafeExit.d.mts +0 -103
- package/types/src/class/WorkerMainThreadBundled.d.mts +0 -83
- package/types/src/common/Base64URLFromFile.d.mts +0 -16
- package/types/src/common/Dev.d.mts +0 -68
- package/types/src/common/DevBundled.d.mts +0 -3
- package/types/src/common/lazie.d.mts +0 -1
- package/types/src/doc/JSautoDOC.d.mts +0 -83
- package/types/src/function/GetRuntime.d.mts +0 -2
- package/types/src/function/TemplateLiteral.d.mts +0 -22
- package/types/src/function/TsToMjs.d.mts +0 -23
- package/types/src/types/IsListSignal.d.mts +0 -4
- package/types/src/types/ListArg.d.mts +0 -4
- package/types/src/types/Runtime.d.mts +0 -4
- package/types/src/types/VivthDevCodeBlockStringType.d.mts +0 -4
- /package/{types → generated/types}/src/bundler/adds/pluginVivthBundle.d.mts +0 -0
- /package/{types → generated/types}/src/class/WorkerResult.d.mts +0 -0
- /package/{types → generated/types}/src/common/EventNameSpace.d.mts +0 -0
- /package/{types → generated/types}/src/common/eventObjects.d.mts +0 -0
- /package/{types → generated/types}/src/common/keys.d.mts +0 -0
- /package/{types → generated/types}/src/doc/correctBeforeParse.d.mts +0 -0
- /package/{types → generated/types}/src/function/TrySync.d.mts +0 -0
- /package/{types → generated/types}/src/function/resolveErrorArray.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/AnyButUndefined.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/ExtnameType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/LitExpKeyType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/LitExpResultType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/MutationType.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/QCBFIFOReturn.d.mts +0 -0
- /package/{types/src/types → generated/types/src/typehints}/QCBReturn.d.mts +0 -0
- /package/src/{types → typehints}/AnyButUndefined.mjs +0 -0
- /package/src/{types → typehints}/ExtnameType.mjs +0 -0
- /package/src/{types → typehints}/LitExpKeyType.mjs +0 -0
- /package/src/{types → typehints}/MutationType.mjs +0 -0
- /package/src/{types → typehints}/QCBFIFOReturn.mjs +0 -0
- /package/src/{types → typehints}/QCBReturn.mjs +0 -0
package/src/class/Paths.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
|
57
|
+
* @type {string}
|
|
55
58
|
*/
|
|
56
59
|
static get root() {
|
|
57
|
-
if (Paths.#instance === undefined) {
|
|
58
|
-
|
|
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
|
-
* -
|
|
69
|
-
*
|
|
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 = (
|
|
77
|
-
return
|
|
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
|
-
* -
|
|
82
|
-
*
|
|
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
|
|
91
|
-
let normalized = Paths.normalize(
|
|
92
|
-
if (normalized.startsWith('/')
|
|
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
|
+
}
|
package/src/class/QChannel.mjs
CHANGED
|
@@ -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
|
-
* @
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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, [
|
|
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, [
|
|
77
|
+
QChannel.#uniquePromiser.set(id, [promise, context]);
|
|
68
78
|
}
|
|
69
79
|
const resume = () => {
|
|
70
|
-
|
|
71
|
-
resolveFn();
|
|
80
|
+
resolve(true);
|
|
72
81
|
QChannel.#uniquePromiser.delete(id);
|
|
73
82
|
};
|
|
74
83
|
return {
|
|
75
84
|
resume,
|
|
76
85
|
isLastOnQ: () => {
|
|
77
|
-
|
|
86
|
+
const res = QChannel.#uniquePromiser.get(id);
|
|
87
|
+
if (!res) {
|
|
78
88
|
return false;
|
|
79
89
|
}
|
|
80
|
-
|
|
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
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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)
|
|
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
|
-
|
|
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
|
}
|
package/src/class/SafeExit.mjs
CHANGED
|
@@ -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 {
|
|
8
|
-
import { EnvSignal } from './EnvSignal.mjs';
|
|
9
|
+
import { mapOfEffects } from './Effect.mjs';
|
|
9
10
|
import { setOFSignals } from './Signal.mjs';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 {
|
|
32
|
-
*
|
|
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
|
|
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(
|
|
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
|
-
* @
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
63
|
+
* @type { undefined|import('node:child_process').ChildProcess }
|
|
64
|
+
*/
|
|
65
|
+
#childProcessHelper;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @type {Parameters<QChannel<any>["callback"]>[1]}
|
|
86
69
|
*/
|
|
87
|
-
|
|
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][
|
|
120
|
+
* @param {...ConstructorParameters<typeof SafeExit>[0][]} eventNames
|
|
90
121
|
* @returns {void}
|
|
91
122
|
*/
|
|
92
|
-
#register = (eventNames) => {
|
|
93
|
-
eventNames.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
#
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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.
|
|
113
|
-
SafeExit.instance.exiting.correction(true);
|
|
162
|
+
Console.error({ errorCleanup }, { now: true });
|
|
114
163
|
});
|
|
115
164
|
};
|
|
116
165
|
/**
|
|
117
166
|
* @description
|
|
118
|
-
* -
|
|
119
|
-
* -
|
|
120
|
-
*
|
|
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 = (
|
|
130
|
-
|
|
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
|
-
* @
|
|
212
|
+
* @param {string} eventName
|
|
213
|
+
* @returns {Promise<void>}
|
|
152
214
|
*/
|
|
153
|
-
#
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
169
|
-
|
|
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
|
}
|