vivth 1.3.2 → 1.3.4
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 +2156 -1782
- package/README.src.md +10 -0
- package/bun.lock +6 -0
- package/index.mjs +12 -3
- package/package.json +4 -2
- package/src/bundler/CompileJS.mjs +62 -28
- package/src/bundler/EsBundler.mjs +2 -1
- package/src/bundler/FSInline.mjs +8 -1
- package/src/bundler/FSInlineAnalyzer.mjs +47 -38
- package/src/bundler/adds/ToBundledJSPlugin.mjs +42 -28
- package/src/bundler/adds/pluginVivthBundle.mjs +3 -1
- package/src/class/EventSignal.mjs +15 -9
- package/src/class/FileSafe.mjs +30 -1
- package/src/class/ListSignal.mjs +1 -1
- package/src/class/LitExp.mjs +3 -2
- package/src/class/Paths.mjs +2 -11
- package/src/class/QChannel.mjs +4 -5
- package/src/class/SafeExit.mjs +7 -24
- package/src/class/Setup.mjs +5 -8
- package/src/class/Signal.mjs +4 -1
- package/src/common/Base64URL.mjs +6 -4
- package/src/common/Dev.mjs +134 -0
- package/src/common/DevBundled.mjs +5 -0
- package/src/common/Trace.mjs +24 -0
- package/src/doc/JSautoDOC.mjs +16 -11
- package/src/doc/correctBeforeParse.mjs +1 -1
- package/src/doc/parsedFile.mjs +1 -1
- package/src/function/GetNamedImportAlias.mjs +37 -0
- package/src/function/LazyFactory.mjs +1 -1
- package/src/function/TsToMjs.mjs +3 -3
- package/src/types/DevTestCB.mjs +11 -0
- package/src/types/Runtime.mjs +0 -1
- package/src/types/VivthDevCodeBlockStringType.mjs +6 -0
- package/tsconfig.json +6 -1
- package/types/index.d.mts +8 -3
- package/types/src/bundler/CompileJS.d.mts +58 -28
- package/types/src/bundler/EsBundler.d.mts +2 -2
- package/types/src/bundler/FSInline.d.mts +8 -1
- package/types/src/bundler/FSInlineAnalyzer.d.mts +1 -0
- package/types/src/bundler/adds/ToBundledJSPlugin.d.mts +6 -3
- package/types/src/class/EventSignal.d.mts +8 -8
- package/types/src/class/FileSafe.d.mts +21 -0
- package/types/src/class/ListSignal.d.mts +2 -2
- package/types/src/class/LitExp.d.mts +1 -0
- package/types/src/class/Paths.d.mts +2 -9
- package/types/src/class/QChannel.d.mts +4 -4
- package/types/src/class/SafeExit.d.mts +7 -24
- package/types/src/class/Setup.d.mts +5 -8
- package/types/src/common/Base64URL.d.mts +5 -3
- package/types/src/common/Dev.d.mts +68 -0
- package/types/src/common/DevBundled.d.mts +3 -0
- package/types/src/common/Trace.d.mts +14 -0
- package/types/src/doc/JSautoDOC.d.mts +8 -7
- package/types/src/function/GetNamedImportAlias.d.mts +22 -0
- package/types/src/function/LazyFactory.d.mts +1 -1
- package/types/src/function/TsToMjs.d.mts +3 -3
- package/types/src/function/WithDefer.d.mts +10 -0
- package/types/src/types/DevTestCB.d.mts +3 -0
- package/types/src/types/IsDevCBStringType.d.mts +4 -0
- package/types/src/types/Runtime.d.mts +3 -0
- package/types/src/types/VivthDevCodeBlockStringType.d.mts +4 -0
package/types/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { ToBundledJSPlugin } from "./src/bundler/adds/ToBundledJSPlugin.mjs";
|
|
1
2
|
export { CompileJS } from "./src/bundler/CompileJS.mjs";
|
|
2
3
|
export { CreateESPlugin } from "./src/bundler/CreateESPlugin.mjs";
|
|
3
4
|
export { EsBundler } from "./src/bundler/EsBundler.mjs";
|
|
@@ -18,13 +19,18 @@ export { SafeExit } from "./src/class/SafeExit.mjs";
|
|
|
18
19
|
export { Setup } from "./src/class/Setup.mjs";
|
|
19
20
|
export { Signal } from "./src/class/Signal.mjs";
|
|
20
21
|
export { WorkerMainThread } from "./src/class/WorkerMainThread.mjs";
|
|
22
|
+
export { WorkerResult } from "./src/class/WorkerResult.mjs";
|
|
23
|
+
export { WorkerThread } from "./src/class/WorkerThread.mjs";
|
|
21
24
|
export { Base64URL } from "./src/common/Base64URL.mjs";
|
|
22
25
|
export { Base64URLFromFile } from "./src/common/Base64URLFromFile.mjs";
|
|
26
|
+
export { Dev } from "./src/common/Dev.mjs";
|
|
23
27
|
export { EventNameSpace } from "./src/common/EventNameSpace.mjs";
|
|
28
|
+
export { Trace } from "./src/common/Trace.mjs";
|
|
24
29
|
export { JSautoDOC } from "./src/doc/JSautoDOC.mjs";
|
|
25
30
|
export { CreateImmutable } from "./src/function/CreateImmutable.mjs";
|
|
26
31
|
export { EventCheck } from "./src/function/EventCheck.mjs";
|
|
27
32
|
export { EventObject } from "./src/function/EventObject.mjs";
|
|
33
|
+
export { GetNamedImportAlias } from "./src/function/GetNamedImportAlias.mjs";
|
|
28
34
|
export { GetRuntime } from "./src/function/GetRuntime.mjs";
|
|
29
35
|
export { IsAsync } from "./src/function/IsAsync.mjs";
|
|
30
36
|
export { LazyFactory } from "./src/function/LazyFactory.mjs";
|
|
@@ -33,10 +39,8 @@ export { Try } from "./src/function/Try.mjs";
|
|
|
33
39
|
export { TryAsync } from "./src/function/TryAsync.mjs";
|
|
34
40
|
export { TrySync } from "./src/function/TrySync.mjs";
|
|
35
41
|
export { TsToMjs } from "./src/function/TsToMjs.mjs";
|
|
36
|
-
export { WorkerResult } from "./src/class/WorkerResult.mjs";
|
|
37
|
-
export { WorkerThread } from "./src/class/WorkerThread.mjs";
|
|
38
|
-
export { ToBundledJSPlugin } from "./src/bundler/adds/ToBundledJSPlugin.mjs";
|
|
39
42
|
export type AnyButUndefined = import("./src/types/AnyButUndefined.mjs").AnyButUndefined;
|
|
43
|
+
export type DevTestCB = import("./src/types/DevTestCB.mjs").DevTestCB;
|
|
40
44
|
export type ExtnameType = import("./src/types/ExtnameType.mjs").ExtnameType;
|
|
41
45
|
export type IsListSignal = import("./src/types/IsListSignal.mjs").IsListSignal;
|
|
42
46
|
export type ListArg = import("./src/types/ListArg.mjs").ListArg;
|
|
@@ -46,3 +50,4 @@ export type MutationType = import("./src/types/MutationType.mjs").MutationType;
|
|
|
46
50
|
export type QCBFIFOReturn = import("./src/types/QCBFIFOReturn.mjs").QCBFIFOReturn;
|
|
47
51
|
export type QCBReturn = import("./src/types/QCBReturn.mjs").QCBReturn;
|
|
48
52
|
export type Runtime = import("./src/types/Runtime.mjs").Runtime;
|
|
53
|
+
export type VivthDevCodeBlockStringType = import("./src/types/VivthDevCodeBlockStringType.mjs").VivthDevCodeBlockStringType;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - function to compile `.ts`|`.mts`|`.mjs` file, into a single executable;
|
|
4
|
-
* - also generate js representation;
|
|
4
|
+
* - also generate js representation of the `bundled` version of the target;
|
|
5
5
|
* - uses [pkg](https://www.npmjs.com/package/pkg), [bun](https://bun.com/docs/bundler/executables), and [deno](https://docs.deno.com/runtime/reference/cli/compile/) compiler under the hood;
|
|
6
|
-
* >- they are used only as packaging agent, and doesn't necessarily supports their advanced feature, such as, assets bundling(use [FSInline](#fsinline) instead);
|
|
6
|
+
* >- they are used only as packaging/compiler agent, and doesn't necessarily supports their advanced feature, such as, assets bundling(use [`FSInline`](#fsinline) instead);
|
|
7
7
|
* >- `WorkerThread` will be converted to inline using `FSInline` too;
|
|
8
8
|
*
|
|
9
9
|
* !!!WARNING!!!
|
|
@@ -22,8 +22,12 @@
|
|
|
22
22
|
* @param {string} options.entryPoint
|
|
23
23
|
* - need to be manually prefixed;
|
|
24
24
|
* @param {BufferEncoding} [options.encoding]
|
|
25
|
-
* -
|
|
25
|
+
* - read and write encoding for the sources;
|
|
26
26
|
* - default: `utf-8`;
|
|
27
|
+
* @param {(entryPointContent:string)=>string} [options.preprocessEntryPoint]
|
|
28
|
+
* - to modify entry point before bundling;
|
|
29
|
+
* - `entryPointContent` is the original string of the entry point;
|
|
30
|
+
* - returned value then passed to `ESBundler`;
|
|
27
31
|
* @param {boolean} options.minifyFirst
|
|
28
32
|
* - minify the bundle before compilation;
|
|
29
33
|
* @param {string} options.outDir
|
|
@@ -43,39 +47,65 @@
|
|
|
43
47
|
* bundledJSFile:string|undefined
|
|
44
48
|
* }>>}
|
|
45
49
|
* @example
|
|
50
|
+
* import process from 'node:process';
|
|
46
51
|
* import { join } from 'node:path';
|
|
47
52
|
*
|
|
48
|
-
* import { CompileJS, Paths } from 'vivth';
|
|
53
|
+
* import { CompileJS, Console, Paths, Setup } from 'vivth';
|
|
54
|
+
*
|
|
55
|
+
* const { paths, safeExit } = Setup;
|
|
56
|
+
* new paths({
|
|
57
|
+
* root: process.env.INIT_CWD ?? process.cwd(),
|
|
58
|
+
* });
|
|
59
|
+
* new safeExit({
|
|
60
|
+
* eventNames: ['SIGINT', 'SIGTERM'],
|
|
61
|
+
* terminator: () => process.exit(0),
|
|
62
|
+
* listener: (eventName) => {
|
|
63
|
+
* process.once(eventName, function () {
|
|
64
|
+
* if (!safeExit.instance) {
|
|
65
|
+
* return;
|
|
66
|
+
* }
|
|
67
|
+
* safeExit.instance.exiting.correction(true);
|
|
68
|
+
* Console.log(`safe exit via "${eventName}"`);
|
|
69
|
+
* });
|
|
70
|
+
* },
|
|
71
|
+
* });
|
|
72
|
+
* const pathRoot = Paths.root;
|
|
73
|
+
* if (pathRoot) {
|
|
74
|
+
* const [[, error], [, errorbun]] = await Promise.all([
|
|
75
|
+
* CompileJS({
|
|
76
|
+
* entryPoint: join(pathRoot, '/dev/myEntryPoint.mjs'),
|
|
77
|
+
* minifyFirst: true,
|
|
78
|
+
* outDir: join(pathRoot, '/dev-pkg/'),
|
|
79
|
+
* compiler: 'pkg',
|
|
80
|
+
* compilerArguments: {
|
|
81
|
+
* target: 'node18-win-x64',
|
|
82
|
+
* },
|
|
83
|
+
* encoding: 'utf-8',
|
|
84
|
+
* }),
|
|
85
|
+
* await CompileJS({
|
|
86
|
+
* entryPoint: join(pathRoot, '/dev/myEntryPoint.mjs'),
|
|
87
|
+
* minifyFirst: true,
|
|
88
|
+
* outDir: join(pathRoot, '/dev-bun/'),
|
|
89
|
+
* compiler: 'bun',
|
|
90
|
+
* compilerArguments: {
|
|
91
|
+
* target: 'bun-win-x64',
|
|
92
|
+
* },
|
|
93
|
+
* encoding: 'utf-8',
|
|
94
|
+
* }),
|
|
95
|
+
* ]);
|
|
96
|
+
* if (error || errorbun) {
|
|
97
|
+
* Console.error({ error, errorbun });
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
49
100
|
*
|
|
50
|
-
* const [[resultPkg, errorPkg], [resultBun, errorBun]] = await Promise.all([
|
|
51
|
-
* CompileJS({
|
|
52
|
-
* entryPoint: join(Paths.root, '/dev'),
|
|
53
|
-
* minifyFirst: true,
|
|
54
|
-
* outDir: join(Paths.root, '/dev-pkg'),
|
|
55
|
-
* compiler: 'pkg',
|
|
56
|
-
* compilerArguments: {
|
|
57
|
-
* target: ['node18-win-x64'],
|
|
58
|
-
* },
|
|
59
|
-
* esBundlerPlugins: [],
|
|
60
|
-
* }),
|
|
61
|
-
* CompileJS({
|
|
62
|
-
* entryPoint: join(Paths.root, '/dev'),
|
|
63
|
-
* minifyFirst: true,
|
|
64
|
-
* outDir: join(Paths.root, '/dev-pkg'),
|
|
65
|
-
* compiler: 'bun',
|
|
66
|
-
* compilerArguments: {
|
|
67
|
-
* target: ['bun-win-x64'],
|
|
68
|
-
* },
|
|
69
|
-
* esBundlerPlugins: [],
|
|
70
|
-
* }),
|
|
71
|
-
* ])
|
|
72
101
|
*/
|
|
73
|
-
export function CompileJS({ entryPoint, minifyFirst, encoding, outDir, compiler, compilerArguments, esBundlerPlugins, }: {
|
|
102
|
+
export function CompileJS({ entryPoint, minifyFirst, encoding, outDir, preprocessEntryPoint, compiler, compilerArguments, esBundlerPlugins, }: {
|
|
74
103
|
entryPoint: string;
|
|
75
104
|
encoding?: BufferEncoding | undefined;
|
|
105
|
+
preprocessEntryPoint?: ((entryPointContent: string) => string) | undefined;
|
|
76
106
|
minifyFirst: boolean;
|
|
77
107
|
outDir: string;
|
|
78
|
-
compiler?: "
|
|
108
|
+
compiler?: "pkg" | "bun" | "deno" | undefined;
|
|
79
109
|
compilerArguments?: Record<string, string> | undefined;
|
|
80
110
|
esBundlerPlugins?: import("esbuild").Plugin[] | undefined;
|
|
81
111
|
}): ReturnType<typeof TryAsync<{
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - the code can also uses composites from the result from multiple readFiles;
|
|
8
8
|
* @param {string} options.root
|
|
9
9
|
* - use dirname of said fileString path;
|
|
10
|
-
* @param {'.mts'|'.ts'|'.mjs'} options.extension
|
|
10
|
+
* @param {'.mts'|'.ts'|'.mjs'|'.cjs'} options.extension
|
|
11
11
|
* @param {boolean} [options.withBinHeader]
|
|
12
12
|
* @param {Omit<Parameters<build>[0],
|
|
13
13
|
* 'entryPoints'|'bundle'|'write'|'sourcemap'>
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
export function EsBundler({ content, extension, root, withBinHeader }: {
|
|
30
30
|
content: string;
|
|
31
31
|
root: string;
|
|
32
|
-
extension: ".mts" | ".ts" | ".mjs";
|
|
32
|
+
extension: ".mts" | ".ts" | ".mjs" | ".cjs";
|
|
33
33
|
withBinHeader?: boolean | undefined;
|
|
34
34
|
}, esbuildOptions?: Omit<Parameters<typeof build>[0], "entryPoints" | "bundle" | "write" | "sourcemap">): ReturnType<typeof TryAsync<string>>;
|
|
35
35
|
import { build } from 'esbuild';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
|
-
* - class helper to inline
|
|
3
|
+
* - class helper to inline files;
|
|
4
|
+
* >- as `type: "buffer"`;
|
|
4
5
|
* - use only if you are planning to use [CompileJS](#compilejs);
|
|
6
|
+
* >- the class static methods don't obfuscate target file;
|
|
7
|
+
* >- don't embed any sensitive content using this methods of this class;
|
|
5
8
|
*/
|
|
6
9
|
export class FSInline {
|
|
7
10
|
/**
|
|
@@ -12,6 +15,9 @@ export class FSInline {
|
|
|
12
15
|
* @param {string} filePathFromProject
|
|
13
16
|
* - doesn't require prefix;
|
|
14
17
|
* @returns {Promise<Buffer<ArrayBuffer>>}
|
|
18
|
+
* - dev: returns `ArrayBuffer`;
|
|
19
|
+
* - bundled: embed the `ArrayBuffer` of file, which then returned;
|
|
20
|
+
* >- `Dev` will be cleaned up;
|
|
15
21
|
* @example
|
|
16
22
|
* import { FSInline } from 'vivth';
|
|
17
23
|
*
|
|
@@ -21,6 +27,7 @@ export class FSInline {
|
|
|
21
27
|
/**
|
|
22
28
|
* @description
|
|
23
29
|
* - declare entrypoint of file inlining, include all files on `dir` and `subdir` that match the `fileRule`;
|
|
30
|
+
* - consider this as inline assets embed/bundler;
|
|
24
31
|
* @param {string} dirPathFromProject
|
|
25
32
|
* - doesn't require prefix;
|
|
26
33
|
* @param {RegExp} fileRule
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description
|
|
3
3
|
* - generate `esbuild.Plugin` for changing dev time file into runtime file;
|
|
4
|
-
* - on using esbuild with this plugin, it will
|
|
4
|
+
* - on using esbuild with this plugin, it will:
|
|
5
|
+
* >- replace any module that have similiar file name but ended with Bundled(before extname);
|
|
5
6
|
* >- works on `.mts`|`.ts`|`.mjs`|`.cjs`|`.js`;
|
|
6
|
-
* >-
|
|
7
|
+
* >- `${fileName}.mjs` -> seek for and use `${fileName}Bundled.mjs`, if not found use `${fileName}.mjs`;
|
|
8
|
+
* >- removes `Dev.vivthDevCodeBlock` code block;
|
|
7
9
|
* @param {string} includedInPath
|
|
8
|
-
* - is generalized, you can freely uses forward or backward slash;
|
|
10
|
+
* - is generalized path, you can freely uses forward or backward slash;
|
|
9
11
|
* @returns {ReturnType<CreateESPlugin>}
|
|
10
12
|
* @example
|
|
11
13
|
* import { ToBundledJSPlugin } from 'vivth';
|
|
@@ -13,4 +15,5 @@
|
|
|
13
15
|
* export const myBundledPlugin = ToBundledJSPlugin('/myProjectName/src/');
|
|
14
16
|
*/
|
|
15
17
|
export function ToBundledJSPlugin(includedInPath: string): ReturnType<typeof CreateESPlugin>;
|
|
18
|
+
export function removeVivthDevCodeBlock(originalContent_: string): string;
|
|
16
19
|
import { CreateESPlugin } from '../CreateESPlugin.mjs';
|
|
@@ -44,14 +44,14 @@ export class EventSignal<ISLIST extends boolean> {
|
|
|
44
44
|
* @description
|
|
45
45
|
* - remove subscriber from the named `EventSignal_instance`;
|
|
46
46
|
* @param {string} name
|
|
47
|
-
* @param {import('./Effect.mjs').Effect}
|
|
47
|
+
* @param {import('./Effect.mjs').Effect} effectInstance
|
|
48
48
|
* @returns {void}
|
|
49
49
|
* @example
|
|
50
50
|
* import { EventSignal } from 'vivth';
|
|
51
51
|
*
|
|
52
52
|
* EventSignal.remove.subscriber('yourEventSignalName', myEffectInstance);
|
|
53
53
|
*/
|
|
54
|
-
subscriber: (name: string,
|
|
54
|
+
subscriber: (name: string, effectInstance: import("./Effect.mjs").Effect) => void;
|
|
55
55
|
/**
|
|
56
56
|
* @static remove
|
|
57
57
|
* @description
|
|
@@ -83,14 +83,14 @@ export class EventSignal<ISLIST extends boolean> {
|
|
|
83
83
|
* @description
|
|
84
84
|
* - remove subscriber from the named `EventSignal_instance`;
|
|
85
85
|
* @param {string} name
|
|
86
|
-
* @param {import('./Effect.mjs').Effect}
|
|
86
|
+
* @param {import('./Effect.mjs').Effect} effectInstance
|
|
87
87
|
* @returns {void}
|
|
88
88
|
* @example
|
|
89
89
|
* import { EventSignal } from 'vivth';
|
|
90
90
|
*
|
|
91
91
|
* EventSignal.remove.subscriber('yourEventSignalName', myEffectInstance);
|
|
92
92
|
*/
|
|
93
|
-
subscriber: (name: string,
|
|
93
|
+
subscriber: (name: string, effectInstance: import("./Effect.mjs").Effect) => void;
|
|
94
94
|
/**
|
|
95
95
|
* @static remove
|
|
96
96
|
* @description
|
|
@@ -170,7 +170,7 @@ export class EventSignal<ISLIST extends boolean> {
|
|
|
170
170
|
* @instance remove
|
|
171
171
|
* @description
|
|
172
172
|
* - remove subscriber from the `EventSignal_instance`;
|
|
173
|
-
* @param {import('./Effect.mjs').Effect}
|
|
173
|
+
* @param {import('./Effect.mjs').Effect} effectInstance
|
|
174
174
|
* @returns {void}
|
|
175
175
|
* @example
|
|
176
176
|
* import { EventSignal, Effect, Console } from 'vivth';
|
|
@@ -184,7 +184,7 @@ export class EventSignal<ISLIST extends boolean> {
|
|
|
184
184
|
* myEventSignal.dispatch.value = 'hey';
|
|
185
185
|
* eventSignal_instance.remove.subscriber(myEffectInstance);
|
|
186
186
|
*/
|
|
187
|
-
subscriber: (
|
|
187
|
+
subscriber: (effectInstance: import("./Effect.mjs").Effect) => void;
|
|
188
188
|
/**
|
|
189
189
|
* @instance remove
|
|
190
190
|
* @description
|
|
@@ -227,7 +227,7 @@ export class EventSignal<ISLIST extends boolean> {
|
|
|
227
227
|
* @instance remove
|
|
228
228
|
* @description
|
|
229
229
|
* - remove subscriber from the `EventSignal_instance`;
|
|
230
|
-
* @param {import('./Effect.mjs').Effect}
|
|
230
|
+
* @param {import('./Effect.mjs').Effect} effectInstance
|
|
231
231
|
* @returns {void}
|
|
232
232
|
* @example
|
|
233
233
|
* import { EventSignal, Effect, Console } from 'vivth';
|
|
@@ -241,7 +241,7 @@ export class EventSignal<ISLIST extends boolean> {
|
|
|
241
241
|
* myEventSignal.dispatch.value = 'hey';
|
|
242
242
|
* eventSignal_instance.remove.subscriber(myEffectInstance);
|
|
243
243
|
*/
|
|
244
|
-
subscriber: (
|
|
244
|
+
subscriber: (effectInstance: import("./Effect.mjs").Effect) => void;
|
|
245
245
|
/**
|
|
246
246
|
* @instance remove
|
|
247
247
|
* @description
|
|
@@ -3,6 +3,27 @@
|
|
|
3
3
|
* - collection of static methods of file access with added safety to mkdir before proceeding;
|
|
4
4
|
*/
|
|
5
5
|
export class FileSafe {
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* - method to safely detects whether filePaths exist;
|
|
9
|
+
* - uses fs/promises access under the hood;
|
|
10
|
+
* - also returning promise of result & error as value;
|
|
11
|
+
* @param {string} filePath
|
|
12
|
+
* @returns {ReturnType<typeof TryAsync<true>>}
|
|
13
|
+
* @example
|
|
14
|
+
* import { join } from 'node:path';
|
|
15
|
+
* import { FileSafe, Paths } from 'vivth';
|
|
16
|
+
*
|
|
17
|
+
* const [, error] = await FileSafe.write(
|
|
18
|
+
* join(Paths.root, '/some/path.mjs'),
|
|
19
|
+
* );
|
|
20
|
+
* if (!error) {
|
|
21
|
+
* // file exists
|
|
22
|
+
* } else {
|
|
23
|
+
* // file not exists
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
static exist: (filePath: string) => ReturnType<typeof TryAsync<true>>;
|
|
6
27
|
/**
|
|
7
28
|
* @description
|
|
8
29
|
* - method to create file safely by recursively mkdir the dirname of the outFile;
|
|
@@ -40,7 +40,7 @@ export class ListSignal<LISTARG extends import("../types/ListArg.mjs").ListArg>
|
|
|
40
40
|
* @instance arrayMethods
|
|
41
41
|
* @description
|
|
42
42
|
* - reference to structuredClone elements of `value`;
|
|
43
|
-
* - calling doesn't notify
|
|
43
|
+
* - calling doesn't notify for changes;
|
|
44
44
|
* @returns {Array<LISTARG>}
|
|
45
45
|
*/
|
|
46
46
|
readonly structuredClone: Array<LISTARG>;
|
|
@@ -146,7 +146,7 @@ export class ListSignal<LISTARG extends import("../types/ListArg.mjs").ListArg>
|
|
|
146
146
|
* @instance arrayMethods
|
|
147
147
|
* @description
|
|
148
148
|
* - reference to structuredClone elements of `value`;
|
|
149
|
-
* - calling doesn't notify
|
|
149
|
+
* - calling doesn't notify for changes;
|
|
150
150
|
* @returns {Array<LISTARG>}
|
|
151
151
|
*/
|
|
152
152
|
readonly structuredClone: Array<LISTARG>;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* >- destructuring is meant for extensive typehelper;
|
|
8
8
|
* >- and destructuring can lead to unhandled error here and there;
|
|
9
9
|
* >- therefore error as value is introduced to help to prevent error on runtime;
|
|
10
|
+
* - made primarily for generating string file, that are purely managed programatically;
|
|
10
11
|
* @template {LitExpKeyType} KEYS
|
|
11
12
|
*/
|
|
12
13
|
export class LitExp<KEYS extends import("../types/LitExpKeyType.mjs").LitExpKeyType> {
|
|
@@ -51,15 +51,8 @@ export class Paths {
|
|
|
51
51
|
* ```
|
|
52
52
|
* - node/bun compatible:
|
|
53
53
|
* ```js
|
|
54
|
-
* process
|
|
55
|
-
*
|
|
56
|
-
* - deno: need for `deno run --allow-env --allow-read your_script.ts`:
|
|
57
|
-
* ```js
|
|
58
|
-
* Deno.env.get("INIT_CWD") ?? Deno.cwd()
|
|
59
|
-
* ```
|
|
60
|
-
* - pkg:
|
|
61
|
-
* ```js
|
|
62
|
-
* __dirname
|
|
54
|
+
* import process from 'node:process';
|
|
55
|
+
* process.env.INIT_CWD ?? process.cwd()
|
|
63
56
|
* ```
|
|
64
57
|
* - other: you need to check your JSRuntime for the rootPath reference;
|
|
65
58
|
* @example
|
|
@@ -19,9 +19,9 @@ export class QChannel<DEFINEDANY extends import("../types/AnyButUndefined.mjs").
|
|
|
19
19
|
* import { QChannel } from 'vivth';
|
|
20
20
|
*
|
|
21
21
|
* const myMappedQref = (window['myMappedQref'] = new Map());
|
|
22
|
-
* export const MyQClass = QChannel.
|
|
22
|
+
* export const MyQClass = QChannel.setup(myMappedQref);
|
|
23
23
|
*/
|
|
24
|
-
static
|
|
24
|
+
static setup: (uniqueMap: Map<import("../types/AnyButUndefined.mjs").AnyButUndefined, [Promise<any>, {}]>) => typeof QChannel;
|
|
25
25
|
/**
|
|
26
26
|
* @type {Map<AnyButUndefined, [Promise<any>, {}]>}
|
|
27
27
|
*/
|
|
@@ -140,7 +140,7 @@ export class QChannel<DEFINEDANY extends import("../types/AnyButUndefined.mjs").
|
|
|
140
140
|
* - `callbackBlock` with error as value:
|
|
141
141
|
* - caveat:
|
|
142
142
|
* >- no need to manually call resume();
|
|
143
|
-
* >- slightly less performant than `
|
|
143
|
+
* >- slightly less performant than `key`;
|
|
144
144
|
* @template RESULT
|
|
145
145
|
* @param {DEFINEDANY} keyID
|
|
146
146
|
* @param {(options:Omit<QCBReturn,
|
|
@@ -149,7 +149,7 @@ export class QChannel<DEFINEDANY extends import("../types/AnyButUndefined.mjs").
|
|
|
149
149
|
* @returns {ReturnType<typeof TryAsync<RESULT>>}
|
|
150
150
|
* @example
|
|
151
151
|
* const q = new QChannel('channel name');
|
|
152
|
-
* const [result, error] = await q.callback(keyID, async ({ isLastOnQ })
|
|
152
|
+
* const [result, error] = await q.callback(keyID, async ({ isLastOnQ }) => {
|
|
153
153
|
* // if (!isLastOnQ()) { // imperative debounce if needed
|
|
154
154
|
* // return;
|
|
155
155
|
* // }
|
|
@@ -26,14 +26,10 @@ export class SafeExit {
|
|
|
26
26
|
* ['SIGINT', 'SIGTERM']
|
|
27
27
|
* ```
|
|
28
28
|
* @param {()=>void} options.terminator
|
|
29
|
-
* - standard node
|
|
29
|
+
* - standard, process must be imported statically from 'node:process':
|
|
30
30
|
* ```js
|
|
31
31
|
* () => process.exit(0),
|
|
32
32
|
* ```
|
|
33
|
-
* - Deno:
|
|
34
|
-
* ```js
|
|
35
|
-
* () => Deno.exit(0),
|
|
36
|
-
* ```
|
|
37
33
|
* @param {(eventName:string)=>void} [options.listener]
|
|
38
34
|
* - default value
|
|
39
35
|
* ```js
|
|
@@ -42,34 +38,21 @@ export class SafeExit {
|
|
|
42
38
|
* SafeExit.instance.exiting.correction(true);
|
|
43
39
|
* Console.log(`safe exit via "${eventName}"`);
|
|
44
40
|
* });
|
|
45
|
-
* };
|
|
46
|
-
* ```
|
|
47
|
-
* - example Deno:
|
|
48
|
-
* ```js
|
|
49
|
-
* (eventName) => {
|
|
50
|
-
* const sig = Deno.signal(eventName);
|
|
51
|
-
* for await (const _ of sig) {
|
|
52
|
-
* exiting.correction(true);
|
|
53
|
-
* sig.dispose();
|
|
54
|
-
* Console.log(`safe exit via "${eventName}"`);
|
|
55
|
-
* }
|
|
56
41
|
* }
|
|
57
42
|
* ```
|
|
58
43
|
* - if your exit callback doesn't uses `process` global object you need to input on the SafeExit instantiation
|
|
59
44
|
* @example
|
|
45
|
+
* import process from 'node:process';
|
|
60
46
|
* import { SafeExit, Console } from 'vivth';
|
|
61
47
|
*
|
|
62
48
|
* new SafeExit({
|
|
63
49
|
* eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
64
|
-
* terminator : () => process.exit(0),
|
|
65
|
-
* // optional deno example
|
|
50
|
+
* terminator : () => process.exit(0),
|
|
66
51
|
* listener : (eventName) => {
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* exiting.correction(true);
|
|
70
|
-
* sig.dispose();
|
|
52
|
+
* process.once(eventName, function () {
|
|
53
|
+
* SafeExit.instance?.exiting.correction(true);
|
|
71
54
|
* Console.log(`safe exit via "${eventName}"`);
|
|
72
|
-
* }
|
|
55
|
+
* });
|
|
73
56
|
* }
|
|
74
57
|
* });
|
|
75
58
|
*/
|
|
@@ -111,7 +94,7 @@ export class SafeExit {
|
|
|
111
94
|
* // code
|
|
112
95
|
* }
|
|
113
96
|
* SafeExit.instance.addCallback(exitCallback);
|
|
114
|
-
*
|
|
97
|
+
* // somewhere else
|
|
115
98
|
* SafeExit.instance.removeCallback(exitCallback);
|
|
116
99
|
*/
|
|
117
100
|
removeCallback: (cb: () => (Promise<void>)) => void;
|
|
@@ -13,15 +13,12 @@ export class Setup {
|
|
|
13
13
|
* // eventNames are blank by default, you need to manually name them all;
|
|
14
14
|
* // 'exit' will be omited, as it might cause async callbacks failed to execute;
|
|
15
15
|
* eventNames: ['SIGINT', 'SIGTERM', ...eventNames],
|
|
16
|
-
* terminator
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* for await (const _ of sig) {
|
|
21
|
-
* exiting.correction(true);
|
|
22
|
-
* sig.dispose();
|
|
16
|
+
* terminator : () => process.exit(0),
|
|
17
|
+
* listener : (eventName) => {
|
|
18
|
+
* process.once(eventName, function () {
|
|
19
|
+
* SafeExit.instance?.exiting.correction(true);
|
|
23
20
|
* Console.log(`safe exit via "${eventName}"`);
|
|
24
|
-
* }
|
|
21
|
+
* });
|
|
25
22
|
* }
|
|
26
23
|
* });
|
|
27
24
|
*/
|
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
* @description
|
|
3
3
|
* - create inline base64 url;
|
|
4
4
|
* - usage:
|
|
5
|
-
* >- can be extremely usefull to display file on desktop app webview, without exposing http server;
|
|
5
|
+
* >- can be extremely usefull to display file on desktop app `webview` or any bundled browser, without exposing http server;
|
|
6
6
|
* @param {string} fileString
|
|
7
7
|
* @param {string} mimeType
|
|
8
8
|
* @param {(string:string)=>string} btoaFunction
|
|
9
9
|
* - check your js runtime `btoa`;
|
|
10
10
|
* - node compatible:
|
|
11
11
|
* ```js
|
|
12
|
-
* (str, prevBufferEncoding) =>
|
|
13
|
-
* Buffer.from(str, prevBufferEncoding).toString('base64')
|
|
12
|
+
* (str, prevBufferEncoding) => {
|
|
13
|
+
* return Buffer.from(str, prevBufferEncoding).toString('base64');
|
|
14
|
+
* }
|
|
14
15
|
* ```
|
|
15
16
|
* @returns {string}
|
|
16
17
|
* @example
|
|
17
18
|
* import { Base64URL } from 'vivth'
|
|
18
19
|
* import fileString from './fileString.mjs';
|
|
19
20
|
*
|
|
21
|
+
* // example for browser;
|
|
20
22
|
* Base64URL(fileString, 'application/javascript', btoa);
|
|
21
23
|
*/
|
|
22
24
|
export function Base64URL(fileString: string, mimeType: string, btoaFunction: (string: string) => string): string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("../types/VivthDevCodeBlockStringType.mjs").VivthDevCodeBlockStringType} VivthDevCodeBlockStringType
|
|
3
|
+
* @typedef {import('../types/DevTestCB.mjs').DevTestCB} DevTestCB
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* - class helper for `devTime` only code block;
|
|
8
|
+
*/
|
|
9
|
+
export class Dev {
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* - persistent variable(during `devTime` and `bundled`);
|
|
13
|
+
* - can be used as `condition` for checking whether it is in `devTime` or `bundled`;
|
|
14
|
+
* @type {boolean}
|
|
15
|
+
* @example
|
|
16
|
+
* import { Dev } from 'vivth';
|
|
17
|
+
*
|
|
18
|
+
* if (Dev.isDev) {
|
|
19
|
+
* // this code block will presist even on `bundled`;
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
static isDev: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* @type {Signal<Map<string,Awaited<ReturnType<typeof TryAsync<boolean>>>>>}
|
|
25
|
+
*/
|
|
26
|
+
static #notifications: Signal<Map<string, Awaited<ReturnType<typeof TryAsync<boolean>>>>>;
|
|
27
|
+
/**
|
|
28
|
+
* @type {DevTestCB}
|
|
29
|
+
*/
|
|
30
|
+
static #test: DevTestCB;
|
|
31
|
+
static #effectForCheck: Effect & {
|
|
32
|
+
"vivth:unwrapLazy;": () => Effect;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* @description
|
|
36
|
+
* - to wrap `devTime` only code block;
|
|
37
|
+
* - when bundled uses `EsBundler` or esbuild with `ToBundledJSPlugin` plugin, the code block will be removed on the bundled version;
|
|
38
|
+
* @param {(options:{test:DevTestCB})=>Promise<void>} callback
|
|
39
|
+
* - also provide `test` method for inline testing:
|
|
40
|
+
* >- which is wrapped in `TryAsync`, throwed errors will automatically return `false`;
|
|
41
|
+
* @param {VivthDevCodeBlockStringType} _closing
|
|
42
|
+
* - it is needed to detect the code block closing;
|
|
43
|
+
* - should use single or double quote and not back tick;
|
|
44
|
+
* @returns {Promise<void>}
|
|
45
|
+
* @example
|
|
46
|
+
* import { Dev, Signal } from 'vivth';
|
|
47
|
+
*
|
|
48
|
+
* Dev.vivthDevCodeBlock(async function () {
|
|
49
|
+
* // this code block will be removed on `bundled` version;
|
|
50
|
+
* }, 'vivthDevCodeBlock');
|
|
51
|
+
*
|
|
52
|
+
* const numberSignal = new Signal(0);
|
|
53
|
+
* Dev.vivthDevCodeBlock(async ({ test }) => {
|
|
54
|
+
* // this code block will be removed on `bundled` version;
|
|
55
|
+
* const [{ removeId: removeTest }] = await Promise.all([
|
|
56
|
+
* test(async () => numberSignal.value === 0)
|
|
57
|
+
* ])
|
|
58
|
+
* }, 'vivthDevCodeBlock');
|
|
59
|
+
*/
|
|
60
|
+
static vivthDevCodeBlock: (callback: (options: {
|
|
61
|
+
test: DevTestCB;
|
|
62
|
+
}) => Promise<void>, _closing: VivthDevCodeBlockStringType) => Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
export type VivthDevCodeBlockStringType = import("../types/VivthDevCodeBlockStringType.mjs").VivthDevCodeBlockStringType;
|
|
65
|
+
export type DevTestCB = import("../types/DevTestCB.mjs").DevTestCB;
|
|
66
|
+
import { Signal } from '../class/Signal.mjs';
|
|
67
|
+
import { TryAsync } from '../function/TryAsync.mjs';
|
|
68
|
+
import { Effect } from '../class/Effect.mjs';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - returns position of stack trace as string, formatted as `fileName:lineNumber:columnNumber`;
|
|
4
|
+
* - extremely usefull for:
|
|
5
|
+
* >- jumping positions to code line;
|
|
6
|
+
* >- creating dynamic string id;
|
|
7
|
+
* @param {number} traceIndex
|
|
8
|
+
* @returns {string}
|
|
9
|
+
* @example
|
|
10
|
+
* import { Trace, Console } from 'vivth';
|
|
11
|
+
*
|
|
12
|
+
* Console.log(Trace(3)); // "D://test.mjs:3:13"
|
|
13
|
+
*/
|
|
14
|
+
export function Trace(traceIndex: number): string;
|
|
@@ -4,21 +4,22 @@
|
|
|
4
4
|
* - this autodocumenter uses [chokidar](https://npmjs.com/package/chokidar) under the hood;
|
|
5
5
|
* - this class also is used to generate this `README.md`;
|
|
6
6
|
* - behaviours:
|
|
7
|
+
* >- auto export must follows the following rules;
|
|
7
8
|
* >1) add `"at"noautodoc` on self closing jsdoc comment to opt out from generating documentation on said file;
|
|
8
|
-
*
|
|
9
|
-
* >
|
|
10
|
-
* >
|
|
11
|
-
* >4) create `README.md` based on, `options.paths.dir` and `README.src.md`;
|
|
9
|
+
* >2) will (generate) export all named exported 'const'|'function'|'async function'|'class', alphanumeric name, started with Capital letter, same name with fileName on `options.paths.file`;
|
|
10
|
+
* >3) will (generate) declare typedef of existing typedef with alphanumeric name, started with Capital letter, same name with fileName, and have no valid export like on point <sup>1</sup> on `options.paths.file`;
|
|
11
|
+
* >4) will (generate) create `README.md` based on, `options.paths.dir` and `README.src.md`;
|
|
12
12
|
* >5) extract `"at"description` jsdoc:
|
|
13
13
|
* >>- on static/prop that have depths, all of children should have `"at"static`/`"at"instance` `nameOfImmediateParent`, same block but before `"at"description` comment line;
|
|
14
14
|
* >>- `"at"description` are treated as plain `markdown`;
|
|
15
15
|
* >>- first `"at"${string}` after `"at"description` until `"at"example` will be treated as `javascript` comment block on the `markdown`;
|
|
16
16
|
* >>- `"at"example` are treated as `javascript` block on the `markdown` file, and should be placed last on the same comment block;
|
|
17
17
|
* >>- you can always look at `vivth/src` files to check how the source, and the `README.md` and `index.mjs` documentation/generation results;
|
|
18
|
-
* >6) this types of arrow functions will be converted to regullar function, for concise type emition:
|
|
18
|
+
* >6) this types of arrow functions will be converted to regullar function, for concise type emition, includes:
|
|
19
19
|
* >>- validly exported function;
|
|
20
|
-
* >>- static/instance method
|
|
21
|
-
* >7) transpile `.ts` and `.mts` to `.mjs` same name and directory;
|
|
20
|
+
* >>- static/instance method with generic template;
|
|
21
|
+
* >7) transpile `.ts` and `.mts` to `.mjs` with same name and directory;
|
|
22
|
+
* >>- use `"at"preserve` to preserve tsdoc comment section;
|
|
22
23
|
*/
|
|
23
24
|
export class JSautoDOC {
|
|
24
25
|
/**
|