vivth 1.4.9 → 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} +61 -84
- package/src/class/WorkerMainThread.mjs +103 -102
- 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 -134
- 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
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { basename, extname, join, relative } from 'node:path';
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
|
|
6
|
+
import { FSWatcher, watch } from 'chokidar';
|
|
7
|
+
|
|
8
|
+
import { EsWatcher } from '../class/EsWatcher.mjs';
|
|
9
|
+
import { Paths } from '../class/Paths.mjs';
|
|
10
|
+
import { QChannel } from '../class/QChannel.mjs';
|
|
11
|
+
import { SafeExit } from '../class/SafeExit.mjs';
|
|
12
|
+
import { Console } from '../class/Console.mjs';
|
|
13
|
+
import { TryNew } from '../function/TryNew.mjs';
|
|
14
|
+
import { pluginVivthBundle } from './adds/pluginVivthBundle.mjs';
|
|
15
|
+
import { BrowserExternals } from './adds/BrowserExternals.mjs';
|
|
16
|
+
import { ForOfSync } from '../function/ForOfSync.mjs';
|
|
17
|
+
import { FileSafe } from '../class/FileSafe.mjs';
|
|
18
|
+
import { TsToMjs } from '../function/TsToMjs.mjs';
|
|
19
|
+
import { LazyFactory } from '../function/LazyFactory.mjs';
|
|
20
|
+
import { compileAsync } from 'sass';
|
|
21
|
+
import { Preferrence } from '../common/Preferrence.mjs';
|
|
22
|
+
import { TryAsync } from '../function/TryAsync.mjs';
|
|
23
|
+
import { autoExternalize } from './adds/autoExternalize.mjs';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {import('../typehints/VivthCleanup.mjs').VivthCleanup} VivthCleanup
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @import {Stats} from 'node:fs'
|
|
31
|
+
* @import {EventName} from 'chokidar/handler.js'
|
|
32
|
+
* @import {Plugin,BuildOptions} from 'esbuild'
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @description
|
|
37
|
+
* - class helper for one to one Mapping JS files;
|
|
38
|
+
* - only bundles `.mts` AND `.mjs` in the `path.watch` directory, extension restriction to module as to enforce:
|
|
39
|
+
* >- `esm` style input;
|
|
40
|
+
* >- to not confuse IDE and esbuild resolver of extensionless static import;
|
|
41
|
+
* @template {BuildOptions} OPT
|
|
42
|
+
* @implements {VivthCleanup}
|
|
43
|
+
*/
|
|
44
|
+
export class JSDirMapper {
|
|
45
|
+
/**
|
|
46
|
+
* @type {QChannel<string>}
|
|
47
|
+
*/
|
|
48
|
+
#q = LazyFactory(() => new QChannel('JSDirMapper'));
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} path
|
|
51
|
+
* @returns {string}
|
|
52
|
+
*/
|
|
53
|
+
static #correctEndpointExt = (path) => {
|
|
54
|
+
if (!path.endsWith('.mjs')) {
|
|
55
|
+
path = `${path}.mjs`;
|
|
56
|
+
}
|
|
57
|
+
return Paths.normalize(path);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @description
|
|
62
|
+
* @param {Object} path
|
|
63
|
+
* - `relative`(to `Paths.root`) OR `absolute`, both are accepted;
|
|
64
|
+
* - handles:
|
|
65
|
+
* >- `.mts`,`.mjs`: bundled;
|
|
66
|
+
* >- `.css`: minified;
|
|
67
|
+
* >-`.scss`, `sass`: two step bundling;
|
|
68
|
+
* >>- bundle to `.s.css` at source path;
|
|
69
|
+
* >>- write to `.s.css` on target path;
|
|
70
|
+
* >- `.as.ts` and it's companion `js` will be dealt accordingly based on `options.asTsToMjsHandler`;
|
|
71
|
+
* >>- `.ts` and `.js` that are not `.wasm` related are ignored;
|
|
72
|
+
* >- everything else will be copied as is;
|
|
73
|
+
* @param {string} path.watch
|
|
74
|
+
* - watch this path for changes;
|
|
75
|
+
* @param {string} path.mapTo
|
|
76
|
+
* - bundles to this path
|
|
77
|
+
* @param {(
|
|
78
|
+
* arg0:
|
|
79
|
+
* {
|
|
80
|
+
* source:string;
|
|
81
|
+
* target:string;
|
|
82
|
+
* eventName:EventName;
|
|
83
|
+
* }
|
|
84
|
+
* )=>Promise<{
|
|
85
|
+
* shouldProcessDefault:
|
|
86
|
+
* boolean|{selfCleanup:()=>Promise<void>};
|
|
87
|
+
* }>
|
|
88
|
+
* } [path.filter]
|
|
89
|
+
* - handler trap before sending it to
|
|
90
|
+
* @param {Object} options
|
|
91
|
+
* @param {Object} options.esbuild
|
|
92
|
+
* @param {Omit<ConstructorParameters<typeof EsWatcher<OPT>>[0],
|
|
93
|
+
* "entryPoints"|
|
|
94
|
+
* "outFile"|
|
|
95
|
+
* "write"|
|
|
96
|
+
* "format"|
|
|
97
|
+
* "bundle"|
|
|
98
|
+
* "logLevel"|
|
|
99
|
+
* "mainFields"
|
|
100
|
+
* >} options.esbuild.buildOptions
|
|
101
|
+
* - `logLimit`: default = `3`;
|
|
102
|
+
* - `entryPoints`: auto filled with `path.watch` + filepath;
|
|
103
|
+
* - `outFile`: auto filled with `path.mapTo` + filepath(suffixed with `.mjs`);
|
|
104
|
+
* - `write`: auto filled by `vivth.JSDirMapper`;
|
|
105
|
+
* - `mainFields`: auto filled by `vivth.JSDirMapper`, ['module', 'main'];
|
|
106
|
+
* - `format`: auto filled by `vivth.JSDirMapper`, always `esm`;
|
|
107
|
+
* - `bundle`: auto filled by `vivth.JSDirMapper`, always `true`;
|
|
108
|
+
* - `logLevel`: auto filled by `vivth.JSDirMapper`;
|
|
109
|
+
* @param {ConstructorParameters<typeof EsWatcher<OPT>>[1]} [options.esbuild.watchOption]
|
|
110
|
+
* @param {Parameters<typeof TsToMjs>[1]} [options.asTsToMjsHandler]
|
|
111
|
+
* - argument[1] used for `.as.ts` extention(assemblyscript to `.wasm` + `.mjs` loader):
|
|
112
|
+
* >- handled via `vivth.TsToMjs`;
|
|
113
|
+
* >- preferably to be isolated on a single folder;
|
|
114
|
+
* - when falsy -> ignore `.as.ts`;
|
|
115
|
+
* @example
|
|
116
|
+
* import process from 'node:process';
|
|
117
|
+
*
|
|
118
|
+
* import { SafeExit, Paths, JSDirMapper } from 'vivth/node';
|
|
119
|
+
*
|
|
120
|
+
* new Paths({
|
|
121
|
+
* root: process.env.INIT_CWD ?? process.cwd(),
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* new SafeExit('SIGINT', 'SIGTERM');
|
|
125
|
+
*
|
|
126
|
+
* new JSDirMapper(
|
|
127
|
+
* {
|
|
128
|
+
* mapTo: '/test/jsdirmapped/',
|
|
129
|
+
* watch: '/test/jsdirmapper/',
|
|
130
|
+
* },
|
|
131
|
+
* {
|
|
132
|
+
* esbuild: { buildOptions: { platform: 'browser' } },
|
|
133
|
+
* asTsToMjsHandler: { assemblyScriptOptions: {} },
|
|
134
|
+
* },
|
|
135
|
+
* );
|
|
136
|
+
*
|
|
137
|
+
*/
|
|
138
|
+
constructor({ mapTo, watch, filter }, { esbuild, asTsToMjsHandler }) {
|
|
139
|
+
this.#watchPath = Paths.diskAbsolute(watch);
|
|
140
|
+
this.#mapToPath = Paths.diskAbsolute(mapTo);
|
|
141
|
+
this.#esbuildOptions = esbuild;
|
|
142
|
+
this.#asTsToMjsHandler = asTsToMjsHandler;
|
|
143
|
+
this.#filter = filter;
|
|
144
|
+
this.#start();
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @type {undefined|((
|
|
148
|
+
* arg0:
|
|
149
|
+
* {
|
|
150
|
+
* source:string;
|
|
151
|
+
* target:string;
|
|
152
|
+
* eventName:EventName;
|
|
153
|
+
* }
|
|
154
|
+
* )=>Promise<{
|
|
155
|
+
* shouldProcessDefault:
|
|
156
|
+
* boolean|{selfCleanup:()=>Promise<void>};
|
|
157
|
+
* }>)
|
|
158
|
+
* }
|
|
159
|
+
*/
|
|
160
|
+
#filter;
|
|
161
|
+
/**
|
|
162
|
+
* @type { string }
|
|
163
|
+
*/
|
|
164
|
+
#watchPath;
|
|
165
|
+
/**
|
|
166
|
+
* @type { string }
|
|
167
|
+
*/
|
|
168
|
+
#mapToPath;
|
|
169
|
+
/**
|
|
170
|
+
* @type {ConstructorParameters<typeof JSDirMapper<OPT>>[1]["esbuild"]}
|
|
171
|
+
*/
|
|
172
|
+
#esbuildOptions;
|
|
173
|
+
/**
|
|
174
|
+
* @type {ConstructorParameters<typeof JSDirMapper<OPT>>[1]["asTsToMjsHandler"]}
|
|
175
|
+
*/
|
|
176
|
+
#asTsToMjsHandler;
|
|
177
|
+
/**
|
|
178
|
+
* @type {FSWatcher|undefined}
|
|
179
|
+
*/
|
|
180
|
+
#watcher;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @type { Map<string, ()=>Promise<void>> }
|
|
184
|
+
*/
|
|
185
|
+
#mappedPathCleanupCallbacks = new Map();
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @type {Map<string, ()=>Promise<any>>}
|
|
189
|
+
*/
|
|
190
|
+
#esbuildPathRebuild = new Map();
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* @type {Map<string, Set<string>>}
|
|
194
|
+
* - key: dependecies;
|
|
195
|
+
* - value: importer;
|
|
196
|
+
*/
|
|
197
|
+
#depMap = new Map();
|
|
198
|
+
|
|
199
|
+
#start = () => {
|
|
200
|
+
this.#watcher = watch(this.#watchPath);
|
|
201
|
+
this.#watcher.addListener('all', this.#allListener);
|
|
202
|
+
SafeExit.instance?.addCallback(this.vivthCleanup);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
vivthCleanup = async () => {
|
|
206
|
+
SafeExit.instance?.removeCallback(this.vivthCleanup);
|
|
207
|
+
this.#watcher?.removeAllListeners();
|
|
208
|
+
await Promise.all([
|
|
209
|
+
this.#watcher?.close(),
|
|
210
|
+
...ForOfSync(this.#mappedPathCleanupCallbacks, async ([, cb]) => {
|
|
211
|
+
await cb();
|
|
212
|
+
})[0],
|
|
213
|
+
]);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @param {string} extension
|
|
218
|
+
* @param {()=>boolean} isLastOnQ
|
|
219
|
+
* @param {EventName} eventName
|
|
220
|
+
* @param {string} path
|
|
221
|
+
* @param {string} targetPath
|
|
222
|
+
* @param {Stats} [stats]
|
|
223
|
+
* @returns {Promise<false|'js'|'css'|'as.ts'|'common'>}
|
|
224
|
+
*/
|
|
225
|
+
#allListenerChecks = async (extension, isLastOnQ, eventName, path, targetPath, stats) => {
|
|
226
|
+
if (!isLastOnQ()) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
switch (eventName) {
|
|
230
|
+
case 'add':
|
|
231
|
+
case 'change':
|
|
232
|
+
break;
|
|
233
|
+
case 'unlink':
|
|
234
|
+
case 'error':
|
|
235
|
+
await Promise.all([
|
|
236
|
+
this.#mappedPathCleanupCallbacks.get(path)?.(),
|
|
237
|
+
FileSafe.rm(targetPath),
|
|
238
|
+
]);
|
|
239
|
+
return false;
|
|
240
|
+
default:
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
const pathBaseName = basename(path);
|
|
244
|
+
if (
|
|
245
|
+
!stats ||
|
|
246
|
+
!stats.isFile() ||
|
|
247
|
+
this.#mappedPathCleanupCallbacks.has(path) ||
|
|
248
|
+
pathBaseName.endsWith(`.d${extension}`)
|
|
249
|
+
) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
switch (extension) {
|
|
253
|
+
case '.scss':
|
|
254
|
+
case '.sass':
|
|
255
|
+
await this.#allListenerQCSS(path, path.replace(/\.\w+$/, '.s.css'));
|
|
256
|
+
return false;
|
|
257
|
+
case '.css':
|
|
258
|
+
return 'css';
|
|
259
|
+
case '.mjs':
|
|
260
|
+
case '.mts':
|
|
261
|
+
return 'js';
|
|
262
|
+
case '.js':
|
|
263
|
+
case '.ts':
|
|
264
|
+
if (path.endsWith('.as.ts') || path.endsWith('.js')) {
|
|
265
|
+
return 'as.ts';
|
|
266
|
+
}
|
|
267
|
+
return false;
|
|
268
|
+
default:
|
|
269
|
+
return 'common';
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* @param {string} path
|
|
275
|
+
* @param {()=>boolean} isLastOnQ
|
|
276
|
+
* @param {EventName} eventName
|
|
277
|
+
* @param {Stats} [stats]
|
|
278
|
+
* @returns
|
|
279
|
+
*/
|
|
280
|
+
#allListenerQ = async (path, isLastOnQ, eventName, stats) => {
|
|
281
|
+
const extension = extname(path);
|
|
282
|
+
const targetPath = Paths.normalize(join(this.#mapToPath, relative(this.#watchPath, path)));
|
|
283
|
+
if (this.#filter) {
|
|
284
|
+
const { shouldProcessDefault } = await this.#filter({
|
|
285
|
+
source: path,
|
|
286
|
+
target: targetPath,
|
|
287
|
+
eventName,
|
|
288
|
+
});
|
|
289
|
+
if (typeof shouldProcessDefault === 'boolean') {
|
|
290
|
+
if (!shouldProcessDefault) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
const { selfCleanup } = shouldProcessDefault;
|
|
295
|
+
this.#mappedPathCleanupCallbacks.set(path, selfCleanup);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const handler = await this.#allListenerChecks(
|
|
300
|
+
extension,
|
|
301
|
+
isLastOnQ,
|
|
302
|
+
eventName,
|
|
303
|
+
path,
|
|
304
|
+
targetPath,
|
|
305
|
+
stats,
|
|
306
|
+
);
|
|
307
|
+
if (!handler) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
switch (handler) {
|
|
311
|
+
case 'js':
|
|
312
|
+
{
|
|
313
|
+
await this.#allListenerQJS(path, targetPath);
|
|
314
|
+
}
|
|
315
|
+
break;
|
|
316
|
+
case 'as.ts':
|
|
317
|
+
{
|
|
318
|
+
await TsToMjs(path, this.#asTsToMjsHandler);
|
|
319
|
+
}
|
|
320
|
+
break;
|
|
321
|
+
case 'css':
|
|
322
|
+
{
|
|
323
|
+
await this.#allListenerQCSS(path, targetPath);
|
|
324
|
+
}
|
|
325
|
+
break;
|
|
326
|
+
case 'common':
|
|
327
|
+
{
|
|
328
|
+
await this.#allListenerQCommon(path, targetPath);
|
|
329
|
+
}
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* @param {string} path
|
|
335
|
+
* @param {string} targetPath
|
|
336
|
+
* @returns {Promise<void>}
|
|
337
|
+
*/
|
|
338
|
+
#allListenerQJS = async (path, targetPath) => {
|
|
339
|
+
const buildOptions = this.#esbuildOptions.buildOptions;
|
|
340
|
+
if (buildOptions.platform === 'browser') {
|
|
341
|
+
buildOptions.external = Array.from(
|
|
342
|
+
BrowserExternals.union(new Set(buildOptions.external ?? [])),
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
const correctedTargetPath = JSDirMapper.#correctEndpointExt(targetPath);
|
|
346
|
+
const [eswatcherInstance, errorInstantiatingWatcher] = TryNew(
|
|
347
|
+
EsWatcher,
|
|
348
|
+
{
|
|
349
|
+
logLimit: 3,
|
|
350
|
+
...buildOptions,
|
|
351
|
+
entryPoints: [path],
|
|
352
|
+
outfile: correctedTargetPath,
|
|
353
|
+
write: true,
|
|
354
|
+
format: 'esm',
|
|
355
|
+
bundle: true,
|
|
356
|
+
mainFields: ['module', 'main'],
|
|
357
|
+
loader: {
|
|
358
|
+
'.mjs': 'js',
|
|
359
|
+
'.js': 'js',
|
|
360
|
+
'.mts': 'ts',
|
|
361
|
+
'.ts': 'ts',
|
|
362
|
+
...buildOptions.loader,
|
|
363
|
+
},
|
|
364
|
+
logLevel: 'silent',
|
|
365
|
+
plugins: [
|
|
366
|
+
this.#autoExternalize(path, correctedTargetPath),
|
|
367
|
+
...(buildOptions?.plugins ?? []),
|
|
368
|
+
pluginVivthBundle,
|
|
369
|
+
],
|
|
370
|
+
},
|
|
371
|
+
this.#esbuildOptions.watchOption,
|
|
372
|
+
);
|
|
373
|
+
if (errorInstantiatingWatcher) {
|
|
374
|
+
Console.error(
|
|
375
|
+
{ errorInstantiatingWatcher },
|
|
376
|
+
{
|
|
377
|
+
now: true,
|
|
378
|
+
},
|
|
379
|
+
);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
this.#esbuildPathRebuild.set(path, eswatcherInstance.rebuild);
|
|
383
|
+
this.#mappedPathCleanupCallbacks.set(path, async () => {
|
|
384
|
+
this.#esbuildPathRebuild.delete(path);
|
|
385
|
+
this.#depMap.delete(path);
|
|
386
|
+
await eswatcherInstance.vivthCleanup();
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* @param {string} path
|
|
392
|
+
* @param {string} targetPath
|
|
393
|
+
* @returns {Promise<void>}
|
|
394
|
+
*/
|
|
395
|
+
#allListenerQCSSPrebundled = async (path, targetPath) => {
|
|
396
|
+
const encoding = Preferrence.encoding;
|
|
397
|
+
const [content, errorReadingPrebundledSCSS] = await TryAsync(async () => {
|
|
398
|
+
return await readFile(path, { encoding });
|
|
399
|
+
});
|
|
400
|
+
if (errorReadingPrebundledSCSS) {
|
|
401
|
+
Console.error(
|
|
402
|
+
{
|
|
403
|
+
JSDirMapper: `❌ Error to Copy prebundled .s.css '${path}'`,
|
|
404
|
+
errorReadingPrebundledSCSS,
|
|
405
|
+
},
|
|
406
|
+
{ now: true },
|
|
407
|
+
);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const [, errorCopyResultSCSS] = await FileSafe.write(targetPath, content, { encoding });
|
|
411
|
+
if (errorCopyResultSCSS) {
|
|
412
|
+
Console.error(
|
|
413
|
+
{
|
|
414
|
+
JSDirMapper: `❌ Error to Copy prebundled .s.css '${path}'`,
|
|
415
|
+
errorCopyResultSCSS,
|
|
416
|
+
},
|
|
417
|
+
{ now: true },
|
|
418
|
+
);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
Console.info(
|
|
422
|
+
{
|
|
423
|
+
JSDirMapper: `✅ Copied prebundled .s.css '${path}' 👉 '${targetPath}'`,
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
now: true,
|
|
427
|
+
},
|
|
428
|
+
);
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* @param {string} path
|
|
432
|
+
* @param {string} targetPath
|
|
433
|
+
* @returns {Promise<void>}
|
|
434
|
+
*/
|
|
435
|
+
#allListenerQCSS = async (path, targetPath) => {
|
|
436
|
+
if (path.endsWith('.s.css')) {
|
|
437
|
+
this.#allListenerQCSSPrebundled(path, targetPath);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
const result = await compileAsync(path, { style: 'compressed' });
|
|
441
|
+
const css = result.css;
|
|
442
|
+
const [, errorWritingCSS] = await FileSafe.write(targetPath, css, {
|
|
443
|
+
encoding: Preferrence.encoding,
|
|
444
|
+
});
|
|
445
|
+
if (errorWritingCSS) {
|
|
446
|
+
Console.error(
|
|
447
|
+
{
|
|
448
|
+
JSDirMapper: `❌ Error to Generate '${path}'`,
|
|
449
|
+
errorWritingCSS,
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
now: true,
|
|
453
|
+
},
|
|
454
|
+
);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
Console.info(
|
|
458
|
+
{
|
|
459
|
+
JSDirMapper: `✅ Generate '${path}' 👉 '${targetPath}'`,
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
now: true,
|
|
463
|
+
},
|
|
464
|
+
);
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* @param {string} path
|
|
468
|
+
* @param {string} targetPath
|
|
469
|
+
* @returns {Promise<void>}
|
|
470
|
+
*/
|
|
471
|
+
#allListenerQCommon = async (path, targetPath) => {
|
|
472
|
+
const [, errorCopyCommonFile] = await FileSafe.copy(path, targetPath);
|
|
473
|
+
if (errorCopyCommonFile) {
|
|
474
|
+
Console.error(
|
|
475
|
+
{
|
|
476
|
+
JSDirMapper: `❌ Error to copy '${path}'`,
|
|
477
|
+
errorCopyCommonFile,
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
now: true,
|
|
481
|
+
},
|
|
482
|
+
);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
Console.info(
|
|
486
|
+
{
|
|
487
|
+
JSDirMapper: `✅ Copied '${path}' 👉 '${targetPath}'`,
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
now: true,
|
|
491
|
+
},
|
|
492
|
+
);
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* @param {EventName} eventName
|
|
496
|
+
* @param {string} path
|
|
497
|
+
* @param {Stats} [stats]
|
|
498
|
+
*/
|
|
499
|
+
#allListener = (eventName, path, stats) => {
|
|
500
|
+
path = Paths.normalize(path);
|
|
501
|
+
this.#q
|
|
502
|
+
.callback(path, async ({ isLastOnQ }) => {
|
|
503
|
+
await this.#allListenerQ(path, isLastOnQ, eventName, stats);
|
|
504
|
+
})
|
|
505
|
+
.then(([, errorAllListenerCallback]) => {
|
|
506
|
+
if (!errorAllListenerCallback) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
Console.error({ errorAllListenerCallback }, { now: true });
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* @param {string} path
|
|
515
|
+
* @param {string} targetPath
|
|
516
|
+
* @returns {Plugin}
|
|
517
|
+
*/
|
|
518
|
+
#autoExternalize = (path, targetPath) => {
|
|
519
|
+
return autoExternalize(
|
|
520
|
+
path,
|
|
521
|
+
targetPath,
|
|
522
|
+
this.#watchPath,
|
|
523
|
+
this.#mapToPath,
|
|
524
|
+
this.#depMap,
|
|
525
|
+
this.#esbuildPathRebuild,
|
|
526
|
+
);
|
|
527
|
+
};
|
|
528
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
|
|
6
|
+
import { Paths } from '../class/Paths.mjs';
|
|
7
|
+
import { GetRuntime } from '../function/GetRuntime.mjs';
|
|
8
|
+
import { TryAsync } from '../function/TryAsync.mjs';
|
|
9
|
+
import { CompileJS } from './CompileJS.mjs';
|
|
10
|
+
import { Console } from '../class/Console.mjs';
|
|
11
|
+
import { SafeExit } from '../class/SafeExit.mjs';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {import('node:child_process').ChildProcess} proc
|
|
15
|
+
* @param {Parameters<RunWatchThenCompileJSOnSafeExit>[0]["compileJSargs"]} compileJSargs
|
|
16
|
+
* @param {string} entryPoint
|
|
17
|
+
* @param {string} outDir
|
|
18
|
+
* @param {boolean} showLog
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
const createCleaner = (proc, compileJSargs, entryPoint, outDir, showLog) => {
|
|
22
|
+
const cleaner = async () => {
|
|
23
|
+
SafeExit.instance?.removeCallback(cleaner);
|
|
24
|
+
proc.kill('SIGTERM');
|
|
25
|
+
const [successInfo, errorCompile] = await CompileJS({
|
|
26
|
+
...compileJSargs,
|
|
27
|
+
entryPoint,
|
|
28
|
+
outDir,
|
|
29
|
+
});
|
|
30
|
+
if (errorCompile) {
|
|
31
|
+
Console.error(errorCompile, { now: true });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (showLog) {
|
|
35
|
+
Console.info(successInfo, { now: true });
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return cleaner;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {'bun'|'node'} runtime
|
|
43
|
+
* @param {string[]} command
|
|
44
|
+
* @returns {Promise<import('node:child_process').ChildProcess>}
|
|
45
|
+
*/
|
|
46
|
+
const handleNodeBun = async (runtime, command) => {
|
|
47
|
+
const proc = spawn(runtime, command, {
|
|
48
|
+
cwd: Paths.root,
|
|
49
|
+
stdio: 'inherit',
|
|
50
|
+
env: process.env,
|
|
51
|
+
});
|
|
52
|
+
return proc;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @description
|
|
57
|
+
* - function to:
|
|
58
|
+
* >- spawn watcher on `source`;
|
|
59
|
+
* >- run the `source`;
|
|
60
|
+
* >- compile `source` to target on `SafeExit`;
|
|
61
|
+
* - this function assume `Paths` and `SafeExit` to be instantiated;
|
|
62
|
+
* @param {Object} options
|
|
63
|
+
* @param {boolean} options.showLog
|
|
64
|
+
* @param {string} options.source
|
|
65
|
+
* - filepath for source;
|
|
66
|
+
* - `relative`(to `Paths.root`) OR `absolute`, both are accepted;
|
|
67
|
+
* @param {string} options.target
|
|
68
|
+
* - dirpath for compile target;
|
|
69
|
+
* - `relative`(to `Paths.root`) OR `absolute`, both are accepted;
|
|
70
|
+
* @param {string[]} [options.additionalSpawnArgument]
|
|
71
|
+
* @param {Omit<
|
|
72
|
+
* Parameters<typeof import('./CompileJS.mjs').CompileJS>[0],
|
|
73
|
+
* "entryPoint"|
|
|
74
|
+
* "outDir"
|
|
75
|
+
* >} [options.compileJSargs]
|
|
76
|
+
* @returns {ReturnType<typeof TryAsync<import('../typehints/VivthCleanup.mjs').VivthCleanup>>}
|
|
77
|
+
* @example
|
|
78
|
+
* import { RunWatchThenCompileJSOnSafeExit } from "vivth/node";
|
|
79
|
+
*
|
|
80
|
+
* // assume `Paths` and `SafeExit` to be instantiated;
|
|
81
|
+
* await RunWatchThenCompileJSOnSafeExit({
|
|
82
|
+
* showLog: false,
|
|
83
|
+
* source: '/test/watchrun/hi.mjs',
|
|
84
|
+
* target: '/test/watchrun/compile-bun/',
|
|
85
|
+
* compileJSargs: {
|
|
86
|
+
* minifyFirst: false,
|
|
87
|
+
* esbuildOptions: {},
|
|
88
|
+
* compilerArguments: {
|
|
89
|
+
* target: 'bun-win-x64',
|
|
90
|
+
* },
|
|
91
|
+
* asar: {},
|
|
92
|
+
* encoding: 'utf-8',
|
|
93
|
+
* },
|
|
94
|
+
* })
|
|
95
|
+
*/
|
|
96
|
+
export async function RunWatchThenCompileJSOnSafeExit({
|
|
97
|
+
/** */
|
|
98
|
+
source,
|
|
99
|
+
target,
|
|
100
|
+
additionalSpawnArgument = [],
|
|
101
|
+
compileJSargs = {},
|
|
102
|
+
showLog,
|
|
103
|
+
}) {
|
|
104
|
+
return await TryAsync(async () => {
|
|
105
|
+
const entryPoint = Paths.diskAbsolute(source);
|
|
106
|
+
const outDir = Paths.diskAbsolute(target);
|
|
107
|
+
const runtime = GetRuntime();
|
|
108
|
+
const command = ['--watch', entryPoint, ...additionalSpawnArgument];
|
|
109
|
+
/**
|
|
110
|
+
* should be cleanup callback
|
|
111
|
+
* @type {import('node:child_process').ChildProcess}
|
|
112
|
+
*/
|
|
113
|
+
let proc;
|
|
114
|
+
switch (runtime) {
|
|
115
|
+
case 'bun':
|
|
116
|
+
case 'node':
|
|
117
|
+
{
|
|
118
|
+
proc = await handleNodeBun(runtime, command);
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
default: {
|
|
122
|
+
throw `'vivth/node.RunWatchThenCompileJSOnSafeExit' cannot run in ${runtime}`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const cleaner = createCleaner(proc, compileJSargs, entryPoint, outDir, showLog);
|
|
126
|
+
SafeExit.instance?.addCallback(cleaner);
|
|
127
|
+
return { vivthCleanup: cleaner };
|
|
128
|
+
});
|
|
129
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { NodeModuleList } from './NodeModuleList.mjs';
|
|
4
|
+
|
|
5
|
+
const vivthNonBrowserDependencies = [
|
|
6
|
+
'esbuild',
|
|
7
|
+
'../prelude/bootstrap.js',
|
|
8
|
+
'./common',
|
|
9
|
+
'../prelude/diagnostic.js',
|
|
10
|
+
'assemblyscript/asc',
|
|
11
|
+
'./adds/asarPath.mjs',
|
|
12
|
+
'assemblyscript',
|
|
13
|
+
'@electron/asar',
|
|
14
|
+
'mime-types',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @description
|
|
19
|
+
* - esbuild external `Set` for browser platform;
|
|
20
|
+
* - this Set is automatically applied to [FileSelfMapper](#fileselfmapper) and [EsBundler](#esbundler) if platform is equal to browser;
|
|
21
|
+
* - while `vivth` already exports environtment specific(`node`, `browser`, `neutral`) via `vivth/node.JSAutoDoc`, there are possibility of other library might bleeded out when trying to:
|
|
22
|
+
* >- use esbuild;
|
|
23
|
+
* >- earlier version of `vivth`;
|
|
24
|
+
* >- importing from `vivth`, which is definitely bleeded out, and you need to import from proper `exports`;
|
|
25
|
+
* >- importing from `vivth/all`, which is definitely bleeded out, and you need to import from proper `exports`;
|
|
26
|
+
* @type {Set<string>}
|
|
27
|
+
* @example
|
|
28
|
+
* import { BrowserExternals } from 'vivth/node';
|
|
29
|
+
* import { build } from 'esbuild';
|
|
30
|
+
*
|
|
31
|
+
* await build({
|
|
32
|
+
* ...esbuildOptions,
|
|
33
|
+
* platform: 'browser',
|
|
34
|
+
* external: Array.from(BrowserExternals),
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
export const BrowserExternals = new Set(vivthNonBrowserDependencies).union(NodeModuleList());
|