vivth 1.1.1 → 1.2.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/.vivth-temp/README.src.md +35 -0
- package/README.md +1243 -441
- package/README.src.md +5 -2
- package/bun.lock +228 -0
- package/index.mjs +22 -9
- package/package.json +6 -3
- package/src/bundler/CompileJS.mjs +258 -0
- package/src/bundler/CreateESPlugin.mjs +24 -0
- package/src/bundler/EsBundler.mjs +27 -13
- package/src/bundler/FSInline.mjs +57 -0
- package/src/bundler/FSInlineAnalyzer.mjs +197 -0
- package/src/bundler/FSInlineBundled.mjs +34 -0
- package/src/bundler/adds/ToBundledJSPlugin.mjs +77 -0
- package/src/bundler/adds/externals.mjs +8 -0
- package/src/bundler/adds/pluginVivthBundle.mjs +5 -0
- package/src/class/Console.mjs +48 -27
- package/src/class/Derived.mjs +55 -7
- package/src/class/Effect.mjs +100 -39
- package/src/class/EnvSignal.mjs +5 -5
- package/src/class/EventSignal.mjs +55 -5
- package/src/class/FileSafe.mjs +124 -0
- package/src/class/ListDerived.mjs +6 -3
- package/src/class/ListSignal.mjs +11 -11
- package/src/class/LitExp.mjs +405 -0
- package/src/class/Paths.mjs +39 -4
- package/src/class/QChannel.mjs +79 -28
- package/src/class/SafeExit.mjs +31 -11
- package/src/class/Setup.mjs +12 -7
- package/src/class/Signal.mjs +26 -24
- package/src/class/WorkerMainThread.mjs +108 -135
- package/src/class/WorkerMainThreadBundled.mjs +216 -0
- package/src/class/WorkerThread.mjs +40 -31
- package/src/common/Base64URL.mjs +10 -5
- package/src/common/Base64URLFromFile.mjs +24 -0
- package/src/common/keys.mjs +3 -0
- package/src/doc/JSautoDOC.mjs +32 -56
- package/src/doc/parsedFile.mjs +37 -36
- package/src/function/CreateImmutable.mjs +9 -9
- package/src/function/EventCheck.mjs +2 -2
- package/src/function/EventObject.mjs +5 -5
- package/src/function/GetRuntime.mjs +38 -0
- package/src/function/IsAsync.mjs +2 -2
- package/src/function/LazyFactory.mjs +13 -13
- package/src/function/Timeout.mjs +2 -2
- package/src/function/Try.mjs +17 -12
- package/src/function/TryAsync.mjs +5 -5
- package/src/function/TrySync.mjs +5 -5
- package/src/function/TsToMjs.mjs +5 -4
- package/src/types/LitExpKeyType.mjs +5 -0
- package/src/types/QCBReturn.mjs +1 -1
- package/src/types/Runtime.mjs +7 -0
- package/types/dev/fsInline.d.mts +1 -0
- package/types/dev/test.d.mts +1 -0
- package/types/dev/testWorker.d.mts +7 -0
- package/types/dev/testbundle.d.mts +1 -0
- package/types/dev/workerThreadClass.d.mts +13 -0
- package/types/index.d.mts +18 -9
- package/types/src/bundler/CompileJS.d.mts +78 -0
- package/types/src/bundler/CreateESPlugin.d.mts +17 -0
- package/types/src/bundler/EsBundler.d.mts +33 -4
- package/types/src/bundler/FSInline.d.mts +43 -0
- package/types/src/bundler/FSInlineAnalyzer.d.mts +36 -0
- package/types/src/bundler/FSInlineBundled.d.mts +22 -0
- package/types/src/bundler/adds/ToBundledJSPlugin.d.mts +16 -0
- package/types/src/bundler/adds/externals.d.mts +1 -0
- package/types/src/bundler/adds/pluginVivthBundle.d.mts +1 -0
- package/types/src/class/Console.d.mts +36 -5
- package/types/src/class/Derived.d.mts +132 -5
- package/types/src/class/Effect.d.mts +106 -7
- package/types/src/class/EnvSignal.d.mts +8 -8
- package/types/src/class/EventSignal.d.mts +151 -7
- package/types/src/class/FileSafe.d.mts +90 -0
- package/types/src/class/ListDerived.d.mts +8 -5
- package/types/src/class/ListSignal.d.mts +123 -18
- package/types/src/class/LitExp.d.mts +361 -0
- package/types/src/class/Paths.d.mts +30 -4
- package/types/src/class/QChannel.d.mts +69 -22
- package/types/src/class/SafeExit.d.mts +24 -9
- package/types/src/class/Setup.d.mts +13 -10
- package/types/src/class/Signal.d.mts +73 -17
- package/types/src/class/WorkerMainThread.d.mts +47 -39
- package/types/src/class/WorkerMainThreadBundled.d.mts +85 -0
- package/types/src/class/WorkerThread.d.mts +34 -26
- package/types/src/common/Base64URL.d.mts +22 -1
- package/types/src/common/Base64URLFromFile.d.mts +16 -0
- package/types/src/common/keys.d.mts +1 -0
- package/types/src/doc/JSautoDOC.d.mts +3 -19
- package/types/src/doc/parsedFile.d.mts +72 -13
- package/types/src/function/CreateImmutable.d.mts +27 -2
- package/types/src/function/EventCheck.d.mts +15 -0
- package/types/src/function/EventObject.d.mts +17 -2
- package/types/src/function/GetRuntime.d.mts +2 -0
- package/types/src/function/IsAsync.d.mts +18 -0
- package/types/src/function/LazyFactory.d.mts +35 -2
- package/types/src/function/Timeout.d.mts +16 -0
- package/types/src/function/Try.d.mts +52 -1
- package/types/src/function/TryAsync.d.mts +22 -1
- package/types/src/function/TrySync.d.mts +16 -1
- package/types/src/function/TsToMjs.d.mts +19 -0
- package/types/src/types/LitExpKeyType.d.mts +1 -0
- package/types/src/types/QCBReturn.d.mts +1 -1
- package/types/src/types/Runtime.d.mts +1 -0
- package/dev/index.mjs +0 -28
- package/src/bundler/CompileMJS.mjs +0 -110
- package/src/function/WriteFileSafe.mjs +0 -37
- package/types/src/bundler/A.d.mts +0 -1
- package/types/src/bundler/CompileMJS.d.mts +0 -8
- package/types/src/function/WriteFileSafe.d.mts +0 -2
|
@@ -6,14 +6,15 @@ import { unwrapLazy } from '../common/lazie.mjs';
|
|
|
6
6
|
* @description
|
|
7
7
|
* - function helper for creating lazyObject:
|
|
8
8
|
* >- usefull for lazily instantiating an object, since instance naturally have props/methods;
|
|
9
|
-
* @template
|
|
10
|
-
* @param {() =>
|
|
11
|
-
* @returns {
|
|
9
|
+
* @template FACTORY
|
|
10
|
+
* @param {() => FACTORY} factory
|
|
11
|
+
* @returns {FACTORY & {[unwrapLazy]: ()=> FACTORY}}
|
|
12
12
|
* - the unwrapLazy prop can be accessed to force instatiation/call;
|
|
13
13
|
* >- `unwrapLazy` prop name can be checked by checking the list of possible prop, from your ide;
|
|
14
|
-
* >- as of version 1.0.0
|
|
14
|
+
* >- as of version `1.0.0`, value is `vivth:unwrapLazy;`;
|
|
15
15
|
* @example
|
|
16
16
|
* import { LazyFactory } from 'vivth';
|
|
17
|
+
*
|
|
17
18
|
* class MyClass{
|
|
18
19
|
* constructor() {
|
|
19
20
|
* this.myProp = 1; // will only available when accessed;
|
|
@@ -31,29 +32,28 @@ import { unwrapLazy } from '../common/lazie.mjs';
|
|
|
31
32
|
*
|
|
32
33
|
* const a = myInstance; // not yet initiated;
|
|
33
34
|
* const b = a.myProp // imediately initiated;
|
|
35
|
+
* // OR
|
|
36
|
+
* myInstance["vivth:unwrapLazy;"]() // forcefully call the callback;
|
|
34
37
|
*/
|
|
35
|
-
export
|
|
38
|
+
export function LazyFactory(factory) {
|
|
36
39
|
let instance;
|
|
37
40
|
// @ts-expect-error
|
|
38
41
|
return new Proxy(
|
|
39
42
|
{},
|
|
40
43
|
{
|
|
41
44
|
get(_, prop) {
|
|
42
|
-
if (!instance) {
|
|
43
|
-
instance = factory();
|
|
44
|
-
}
|
|
45
45
|
if (prop === unwrapLazy) {
|
|
46
46
|
if (!instance) {
|
|
47
47
|
instance = factory();
|
|
48
48
|
}
|
|
49
|
-
return instance;
|
|
49
|
+
return () => instance;
|
|
50
|
+
}
|
|
51
|
+
if (!instance) {
|
|
52
|
+
instance = factory();
|
|
50
53
|
}
|
|
51
54
|
return instance[prop];
|
|
52
55
|
},
|
|
53
56
|
set(_, prop, newValue) {
|
|
54
|
-
if (prop === unwrapLazy) {
|
|
55
|
-
instance = factory();
|
|
56
|
-
}
|
|
57
57
|
if (!instance) {
|
|
58
58
|
instance = factory();
|
|
59
59
|
}
|
|
@@ -68,4 +68,4 @@ export const LazyFactory = (factory) => {
|
|
|
68
68
|
},
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
}
|
|
71
|
+
}
|
package/src/function/Timeout.mjs
CHANGED
package/src/function/Try.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
import { Console } from '../class/Console.mjs';
|
|
3
4
|
import { TryAsync } from './TryAsync.mjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -9,28 +10,28 @@ import { TryAsync } from './TryAsync.mjs';
|
|
|
9
10
|
* - usefull to flatten indentation for error handlings;
|
|
10
11
|
* - caveat:
|
|
11
12
|
* >- run in sequence, awaiting each key bofore running next key;
|
|
12
|
-
* @template {string}
|
|
13
|
-
* @template
|
|
13
|
+
* @template {string} KEY
|
|
14
|
+
* @template RETURNTYPE
|
|
14
15
|
* @template {Record<
|
|
15
|
-
*
|
|
16
|
-
* () => Promise<
|
|
16
|
+
* KEY,
|
|
17
|
+
* (err:{prevError:undefined|Error}) => Promise<RETURNTYPE>
|
|
17
18
|
* >} RecordTryType
|
|
18
19
|
* @param {RecordTryType} tryRecord
|
|
19
20
|
* @returns {Promise<
|
|
20
|
-
* [[keyof RecordTryType,
|
|
21
|
+
* [[keyof RecordTryType, RETURNTYPE], undefined]
|
|
21
22
|
* | [[undefined, undefined], Error]
|
|
22
23
|
* >}
|
|
23
24
|
* @example
|
|
24
25
|
* import { Try } from 'vivth';
|
|
25
26
|
*
|
|
26
27
|
* const [[key, result], error] = await Try({
|
|
27
|
-
* someRuntime: async () => {
|
|
28
|
+
* someRuntime: async ( prevError ) => {
|
|
28
29
|
* // asuming on this one doesn't naturally throw error,
|
|
29
30
|
* // yet you need to continue to next key,
|
|
30
31
|
* // instead of returning,
|
|
31
32
|
* // you should throw new Error(something);
|
|
32
33
|
* },
|
|
33
|
-
* browser: async () => {
|
|
34
|
+
* browser: async ( prevError ) => {
|
|
34
35
|
* return location?.origin;
|
|
35
36
|
* // if no error, stop other key function from running;
|
|
36
37
|
* // key = 'browser'
|
|
@@ -39,7 +40,7 @@ import { TryAsync } from './TryAsync.mjs';
|
|
|
39
40
|
* // if error;
|
|
40
41
|
* // run nodeOrBun;
|
|
41
42
|
* },
|
|
42
|
-
* nodeOrBun: async () => {
|
|
43
|
+
* nodeOrBun: async ( prevError ) => {
|
|
43
44
|
* return process?.env?.INIT_CWD ?? process?.cwd();
|
|
44
45
|
* // if no error;
|
|
45
46
|
* // key = 'nodeOrBun'
|
|
@@ -51,14 +52,18 @@ import { TryAsync } from './TryAsync.mjs';
|
|
|
51
52
|
* },
|
|
52
53
|
* });
|
|
53
54
|
*/
|
|
54
|
-
export
|
|
55
|
+
export async function Try(tryRecord) {
|
|
56
|
+
let prevError = undefined;
|
|
55
57
|
for (const key in tryRecord) {
|
|
56
58
|
const callback = tryRecord[key];
|
|
57
|
-
const [result, error] = await TryAsync(
|
|
59
|
+
const [result, error] = await TryAsync(async () => {
|
|
60
|
+
return await callback({ prevError });
|
|
61
|
+
});
|
|
58
62
|
if (error) {
|
|
63
|
+
prevError = error;
|
|
59
64
|
continue;
|
|
60
65
|
}
|
|
61
66
|
return [[key, result], undefined];
|
|
62
67
|
}
|
|
63
|
-
return [[undefined, undefined],
|
|
64
|
-
}
|
|
68
|
+
return [[undefined, undefined], prevError];
|
|
69
|
+
}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* @description
|
|
5
5
|
* - function for error as value for asynchronous operation;
|
|
6
6
|
* - usefull to flatten indentation for error handlings;
|
|
7
|
-
* @template
|
|
8
|
-
* @param {()=>Promise<
|
|
9
|
-
* @returns {Promise<[
|
|
7
|
+
* @template RESULT
|
|
8
|
+
* @param {()=>Promise<RESULT>} asyncFunction_
|
|
9
|
+
* @returns {Promise<[RESULT|undefined, Error|undefined]>}
|
|
10
10
|
* @example
|
|
11
11
|
* import { TryAsync } from 'vivth';
|
|
12
12
|
*
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
* return await res.json();
|
|
22
22
|
* })
|
|
23
23
|
*/
|
|
24
|
-
export
|
|
24
|
+
export async function TryAsync(asyncFunction_) {
|
|
25
25
|
try {
|
|
26
26
|
const result = await asyncFunction_();
|
|
27
27
|
return [result, undefined];
|
|
28
28
|
} catch (error) {
|
|
29
29
|
return [undefined, error];
|
|
30
30
|
}
|
|
31
|
-
}
|
|
31
|
+
}
|
package/src/function/TrySync.mjs
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* @description
|
|
5
5
|
* - function for error as value for synchronous operation;
|
|
6
6
|
* - usefull to flatten indentation for error handlings;
|
|
7
|
-
* @template
|
|
8
|
-
* @param {()=>
|
|
9
|
-
* @returns {[
|
|
7
|
+
* @template RESULT
|
|
8
|
+
* @param {()=>RESULT} function_
|
|
9
|
+
* @returns {[RESULT|undefined, Error|undefined]}
|
|
10
10
|
* @example
|
|
11
11
|
* import { readFileSync } from 'fs';
|
|
12
12
|
* import { TrySync } from './yourModule.js';
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
* return readFileSync('./some/file.txt', 'utf-8');
|
|
16
16
|
* });
|
|
17
17
|
*/
|
|
18
|
-
export
|
|
18
|
+
export function TrySync(function_) {
|
|
19
19
|
try {
|
|
20
20
|
const result = function_();
|
|
21
21
|
return [result, undefined];
|
|
22
22
|
} catch (error) {
|
|
23
23
|
return [undefined, error];
|
|
24
24
|
}
|
|
25
|
-
}
|
|
25
|
+
}
|
package/src/function/TsToMjs.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { transform } from 'esbuild';
|
|
|
8
8
|
import { Console } from '../class/Console.mjs';
|
|
9
9
|
import { Paths } from '../class/Paths.mjs';
|
|
10
10
|
import { TryAsync } from './TryAsync.mjs';
|
|
11
|
-
import {
|
|
11
|
+
import { FileSafe } from '../class/FileSafe.mjs';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @description
|
|
@@ -16,6 +16,7 @@ import { WriteFileSafe } from './WriteFileSafe.mjs';
|
|
|
16
16
|
* - on certain circumstance where `.mjs` result needed to be typed, you need to manually add `jsdoc`;
|
|
17
17
|
* >- uses `"at"preserve` to register `jsdoc` inline;
|
|
18
18
|
* @param {string} path_
|
|
19
|
+
* - path from `Paths.root`;
|
|
19
20
|
* @param {Object} [options]
|
|
20
21
|
* @param {string} [options.overrideDir]
|
|
21
22
|
* - default: write conversion to same directory;
|
|
@@ -28,7 +29,7 @@ import { WriteFileSafe } from './WriteFileSafe.mjs';
|
|
|
28
29
|
*
|
|
29
30
|
* TsToMjs('./myFile.mts', { encoding: 'utf-8', overrideDir: './other/dir' });
|
|
30
31
|
*/
|
|
31
|
-
export
|
|
32
|
+
export async function TsToMjs(path_, { overrideDir = undefined, encoding = 'utf-8' } = {}) {
|
|
32
33
|
const rootPath = Paths.normalize(Paths.root);
|
|
33
34
|
if (!Paths.normalize(path_).startsWith(rootPath)) {
|
|
34
35
|
path_ = Paths.normalize(join(rootPath, path_));
|
|
@@ -59,9 +60,9 @@ export const TsToMjs = async (path_, { overrideDir = undefined, encoding = 'utf-
|
|
|
59
60
|
}
|
|
60
61
|
const outputDir = overrideDir ? join(rootPath, overrideDir) : dirname(path_);
|
|
61
62
|
const outputPath = join(outputDir, basename(path_).replace(ext, '.mjs'));
|
|
62
|
-
const [_, writeError] = await
|
|
63
|
+
const [_, writeError] = await FileSafe.write(outputPath, result.code, { encoding });
|
|
63
64
|
if (!writeError) {
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
67
|
Console.error(writeError);
|
|
67
|
-
}
|
|
68
|
+
}
|
package/src/types/QCBReturn.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* `workerThreadClass` description placeholder;
|
|
4
|
+
*/
|
|
5
|
+
export const workerThreadClass: {
|
|
6
|
+
new (handler: (ev: any, isLastOnQ: () => boolean) => any): WorkerThread<any, any>;
|
|
7
|
+
#refs: Parameters<(typeof WorkerThread)["setup"]>[0];
|
|
8
|
+
setup<RECEIVE, POST>(refs: {
|
|
9
|
+
parentPort: typeof import("worker_threads")["parentPort"];
|
|
10
|
+
}): typeof WorkerThread<RECEIVE, POST>;
|
|
11
|
+
#isCloseWorkerEvent: (ev: any) => boolean;
|
|
12
|
+
};
|
|
13
|
+
import { WorkerThread } from '../index.mjs';
|
package/types/index.d.mts
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { CompileJS } from "./src/bundler/CompileJS.mjs";
|
|
2
|
+
export { CreateESPlugin } from "./src/bundler/CreateESPlugin.mjs";
|
|
2
3
|
export { EsBundler } from "./src/bundler/EsBundler.mjs";
|
|
4
|
+
export { FSInline } from "./src/bundler/FSInline.mjs";
|
|
5
|
+
export { FSInlineAnalyzer } from "./src/bundler/FSInlineAnalyzer.mjs";
|
|
3
6
|
export { Console } from "./src/class/Console.mjs";
|
|
4
7
|
export { Derived } from "./src/class/Derived.mjs";
|
|
5
8
|
export { Effect } from "./src/class/Effect.mjs";
|
|
6
9
|
export { EnvSignal } from "./src/class/EnvSignal.mjs";
|
|
7
10
|
export { EventSignal } from "./src/class/EventSignal.mjs";
|
|
11
|
+
export { FileSafe } from "./src/class/FileSafe.mjs";
|
|
8
12
|
export { ListDerived } from "./src/class/ListDerived.mjs";
|
|
9
13
|
export { ListSignal } from "./src/class/ListSignal.mjs";
|
|
14
|
+
export { LitExp } from "./src/class/LitExp.mjs";
|
|
10
15
|
export { Paths } from "./src/class/Paths.mjs";
|
|
11
16
|
export { QChannel } from "./src/class/QChannel.mjs";
|
|
12
17
|
export { SafeExit } from "./src/class/SafeExit.mjs";
|
|
13
18
|
export { Setup } from "./src/class/Setup.mjs";
|
|
14
19
|
export { Signal } from "./src/class/Signal.mjs";
|
|
15
20
|
export { WorkerMainThread } from "./src/class/WorkerMainThread.mjs";
|
|
16
|
-
export { WorkerResult } from "./src/class/WorkerResult.mjs";
|
|
17
|
-
export { WorkerThread } from "./src/class/WorkerThread.mjs";
|
|
18
21
|
export { Base64URL } from "./src/common/Base64URL.mjs";
|
|
22
|
+
export { Base64URLFromFile } from "./src/common/Base64URLFromFile.mjs";
|
|
19
23
|
export { EventNameSpace } from "./src/common/EventNameSpace.mjs";
|
|
20
24
|
export { JSautoDOC } from "./src/doc/JSautoDOC.mjs";
|
|
21
25
|
export { CreateImmutable } from "./src/function/CreateImmutable.mjs";
|
|
22
26
|
export { EventCheck } from "./src/function/EventCheck.mjs";
|
|
23
27
|
export { EventObject } from "./src/function/EventObject.mjs";
|
|
28
|
+
export { GetRuntime } from "./src/function/GetRuntime.mjs";
|
|
24
29
|
export { IsAsync } from "./src/function/IsAsync.mjs";
|
|
25
30
|
export { LazyFactory } from "./src/function/LazyFactory.mjs";
|
|
26
31
|
export { Timeout } from "./src/function/Timeout.mjs";
|
|
@@ -28,11 +33,15 @@ export { Try } from "./src/function/Try.mjs";
|
|
|
28
33
|
export { TryAsync } from "./src/function/TryAsync.mjs";
|
|
29
34
|
export { TrySync } from "./src/function/TrySync.mjs";
|
|
30
35
|
export { TsToMjs } from "./src/function/TsToMjs.mjs";
|
|
31
|
-
export {
|
|
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";
|
|
32
39
|
export type AnyButUndefined = import("./src/types/AnyButUndefined.mjs").AnyButUndefined;
|
|
33
|
-
export type QCBReturn = import("./src/types/QCBReturn.mjs").QCBReturn;
|
|
34
|
-
export type QCBFIFOReturn = import("./src/types/QCBFIFOReturn.mjs").QCBFIFOReturn;
|
|
35
|
-
export type MutationType = import("./src/types/MutationType.mjs").MutationType;
|
|
36
|
-
export type ListArg = import("./src/types/ListArg.mjs").ListArg;
|
|
37
|
-
export type IsListSignal = import("./src/types/IsListSignal.mjs").IsListSignal;
|
|
38
40
|
export type ExtnameType = import("./src/types/ExtnameType.mjs").ExtnameType;
|
|
41
|
+
export type IsListSignal = import("./src/types/IsListSignal.mjs").IsListSignal;
|
|
42
|
+
export type ListArg = import("./src/types/ListArg.mjs").ListArg;
|
|
43
|
+
export type LitExpKeyType = import("./src/types/LitExpKeyType.mjs").LitExpKeyType;
|
|
44
|
+
export type MutationType = import("./src/types/MutationType.mjs").MutationType;
|
|
45
|
+
export type QCBFIFOReturn = import("./src/types/QCBFIFOReturn.mjs").QCBFIFOReturn;
|
|
46
|
+
export type QCBReturn = import("./src/types/QCBReturn.mjs").QCBReturn;
|
|
47
|
+
export type Runtime = import("./src/types/Runtime.mjs").Runtime;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - function to compile `.ts`|`.mts`|`.mjs` file, into a single executable;
|
|
4
|
+
* - also generate js representation;
|
|
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);
|
|
7
|
+
* >- `WorkerThread` will be converted to inline using `FSInline` too;
|
|
8
|
+
*
|
|
9
|
+
* !!!WARNING!!!
|
|
10
|
+
* !!!WARNING!!!
|
|
11
|
+
* !!!WARNING!!!
|
|
12
|
+
*
|
|
13
|
+
* - This function does not obfuscate and will not prevent decompilation. Do not embed environment variables or sensitive information inside `options.entryPoint`;
|
|
14
|
+
* - It is designed for quick binarization, allowing execution on machines without `Node.js`, `Bun`, or `Deno` installed;
|
|
15
|
+
* - The resulting binary will contain `FSInline` and `WorkerMainThread` target paths Buffers, which are loaded into memory at runtime. If your logic depends on the file system, use `node:fs` or `node:fs/promises` APIs and ship external files alongside the binary (not compiled);
|
|
16
|
+
*
|
|
17
|
+
* !!!WARNING!!!
|
|
18
|
+
* !!!WARNING!!!
|
|
19
|
+
* !!!WARNING!!!
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options
|
|
22
|
+
* @param {string} options.entryPoint
|
|
23
|
+
* - need to be manually prefixed;
|
|
24
|
+
* @param {BufferEncoding} [options.encoding]
|
|
25
|
+
* - write and read encoding for the sources;
|
|
26
|
+
* - default: `utf-8`;
|
|
27
|
+
* @param {boolean} options.minifyFirst
|
|
28
|
+
* - minify the bundle before compilation;
|
|
29
|
+
* @param {string} options.outDir
|
|
30
|
+
* - need manual prefix;
|
|
31
|
+
* @param {'pkg'|'bun'|'deno'} [options.compiler]
|
|
32
|
+
* - default: no comilation, just bundling;
|
|
33
|
+
* - `bun` and `pkg` is checked, if there's bug on `deno`, please report on github for issues;
|
|
34
|
+
* @param {Record<string, string>} [options.compilerArguments]
|
|
35
|
+
* - `key` are to used as `--keyName`;
|
|
36
|
+
* - value are the following value of the key;
|
|
37
|
+
* - no need to add the output/outdir, as it use the `options.outDir`;
|
|
38
|
+
* @return {ReturnType<TryAsync<{compileResult:Promise<any>,
|
|
39
|
+
* commandCalled: string;
|
|
40
|
+
* compiledBinFile: string;
|
|
41
|
+
* bundledJSFile:string
|
|
42
|
+
* }>>}
|
|
43
|
+
* @example
|
|
44
|
+
* import { join } from 'node:path';
|
|
45
|
+
*
|
|
46
|
+
* import { CompileJS, Paths } from 'vivth';
|
|
47
|
+
*
|
|
48
|
+
* const [[resultPkg, errorPkg], [resultBun, errorBun]] = await Promise.all([
|
|
49
|
+
* CompileJS({
|
|
50
|
+
* entryPoint: join(Paths.root, '/dev'),
|
|
51
|
+
* minifyFirst: true,
|
|
52
|
+
* outDir: join(Paths.root, '/dev-pkg'),
|
|
53
|
+
* compiler: 'pkg',
|
|
54
|
+
* compilerArguments: {
|
|
55
|
+
* target: ['node18-win-x64'],
|
|
56
|
+
* }
|
|
57
|
+
* }),
|
|
58
|
+
* CompileJS({
|
|
59
|
+
* entryPoint: join(Paths.root, '/dev'),
|
|
60
|
+
* minifyFirst: true,
|
|
61
|
+
* outDir: join(Paths.root, '/dev-pkg'),
|
|
62
|
+
* compiler: 'bun',
|
|
63
|
+
* compilerArguments: {
|
|
64
|
+
* target: ['bun-win-x64'],
|
|
65
|
+
* }
|
|
66
|
+
* }),
|
|
67
|
+
* ])
|
|
68
|
+
*/
|
|
69
|
+
export function CompileJS({ entryPoint, minifyFirst, encoding, outDir, compiler, compilerArguments, }: {
|
|
70
|
+
entryPoint: string;
|
|
71
|
+
encoding?: BufferEncoding;
|
|
72
|
+
minifyFirst: boolean;
|
|
73
|
+
outDir: string;
|
|
74
|
+
compiler?: "pkg" | "bun" | "deno";
|
|
75
|
+
compilerArguments?: Record<string, string>;
|
|
76
|
+
}): ReturnType<typeof TryAsync>;
|
|
77
|
+
export type PlatformKey = "win32" | "linux" | "darwin" | string;
|
|
78
|
+
import { TryAsync } from '../function/TryAsync.mjs';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - typed esbuild Plugin generator;
|
|
4
|
+
* @param {string} name
|
|
5
|
+
* @param {import('esbuild').Plugin["setup"]} setup
|
|
6
|
+
* @returns {import('esbuild').Plugin}
|
|
7
|
+
* @example
|
|
8
|
+
* import { CreateESPlugin } from 'vivth';
|
|
9
|
+
*
|
|
10
|
+
* export const pluginAddCopyRight = CreateESPlugin(
|
|
11
|
+
* 'MyCopyrightDeclaration',
|
|
12
|
+
* async (build) => {
|
|
13
|
+
* // build script;
|
|
14
|
+
* }
|
|
15
|
+
* );
|
|
16
|
+
*/
|
|
17
|
+
export function CreateESPlugin(name: string, setup: import("esbuild").Plugin["setup"]): import("esbuild").Plugin;
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - opinionated bundler for extension below using esbuild;
|
|
4
|
+
* - bundles all imports into a single output string;
|
|
5
|
+
* @param {Object} options
|
|
6
|
+
* @param {string} options.content
|
|
7
|
+
* - the code can also uses composites from the result from multiple readFiles;
|
|
8
|
+
* @param {string} options.root
|
|
9
|
+
* - use dirname of said fileString path;
|
|
10
|
+
* @param {'.mts'|'.ts'|'.mjs'} options.extension
|
|
11
|
+
* @param {boolean} [options.withBinHeader]
|
|
12
|
+
* @param {Omit<Parameters<build>[0],
|
|
13
|
+
* 'entryPoints'|'bundle'|'write'|'sourcemap'>
|
|
14
|
+
* } [esbuildOptions]
|
|
15
|
+
* @returns {ReturnType<typeof TryAsync<string>>}
|
|
16
|
+
* @example
|
|
17
|
+
* import { EsBundler } from 'vivth';
|
|
18
|
+
*
|
|
19
|
+
* const bundledString = EsBundler(
|
|
20
|
+
* {
|
|
21
|
+
* content: ``,
|
|
22
|
+
* extension: '.mts',
|
|
23
|
+
* ...options
|
|
24
|
+
* },
|
|
25
|
+
* {
|
|
26
|
+
* ...esbuildOptions,
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
export function EsBundler({ content, extension, root, withBinHeader }: {
|
|
2
30
|
content: string;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
31
|
+
root: string;
|
|
32
|
+
extension: ".mts" | ".ts" | ".mjs";
|
|
33
|
+
withBinHeader?: boolean;
|
|
34
|
+
}, esbuildOptions?: Omit<Parameters<typeof build>[0], "entryPoints" | "bundle" | "write" | "sourcemap">): ReturnType<typeof TryAsync<string>>;
|
|
6
35
|
import { build } from 'esbuild';
|
|
7
36
|
import { TryAsync } from '../function/TryAsync.mjs';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - class helper to inline file;
|
|
4
|
+
* - use only if you are planning to use [CompileJS](#compilejs);
|
|
5
|
+
*/
|
|
6
|
+
export class FSInline {
|
|
7
|
+
/**
|
|
8
|
+
* @description
|
|
9
|
+
* - declare entrypoint of file inlining;
|
|
10
|
+
* >- on the dev time, it's just regullar `readFile` from `node:fs/promises`;
|
|
11
|
+
* >- on the compiled, it will read file from `FSInline.vivthFSInlinelists`
|
|
12
|
+
* @param {string} filePathFromProject
|
|
13
|
+
* - doesn't require prefix;
|
|
14
|
+
* @returns {Promise<Buffer<ArrayBuffer>>}
|
|
15
|
+
* @example
|
|
16
|
+
* import { FSInline } from 'vivth';
|
|
17
|
+
*
|
|
18
|
+
* (await FSInline.vivthFSInlineFile('/assets/text.txt')).toString('utf-8');
|
|
19
|
+
*/
|
|
20
|
+
static vivthFSInlineFile: (filePathFromProject: string) => Promise<Buffer<ArrayBuffer>>;
|
|
21
|
+
/**
|
|
22
|
+
* @description
|
|
23
|
+
* - declare entrypoint of file inlining, include all files on `dir` and `subdir` that match the `fileRule`;
|
|
24
|
+
* @param {string} dirPathFromProject
|
|
25
|
+
* - doesn't require prefix;
|
|
26
|
+
* @param {RegExp} fileRule
|
|
27
|
+
* @returns {Promise<typeof FSInline["vivthFSInlineFile"]>}
|
|
28
|
+
* @example
|
|
29
|
+
* import { FSInline } from 'vivth';
|
|
30
|
+
*
|
|
31
|
+
* export const pngAssets = await FSInline.vivthFSInlineDir('/assets', /.png$/g);
|
|
32
|
+
*/
|
|
33
|
+
static vivthFSInlineDir: (dirPathFromProject: string, fileRule: RegExp) => Promise<(typeof FSInline)["vivthFSInlineFile"]>;
|
|
34
|
+
/**
|
|
35
|
+
* @description
|
|
36
|
+
* - placeholder for FSInline;
|
|
37
|
+
* - it's remain publicly accessible so it doesn't mess with regex analyze on bundle;
|
|
38
|
+
* - shouldn't be manually accessed;
|
|
39
|
+
* >- access via `FSInline.vivthFSInlineFile` or `FSInline.vivthFSInlineDir`;
|
|
40
|
+
* @type {Record<string, Buffer<ArrayBuffer>>}
|
|
41
|
+
*/
|
|
42
|
+
static vivthFSInlinelists: Record<string, Buffer<ArrayBuffer>>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - collections of static method to analyze content for `FSInline`;
|
|
4
|
+
*/
|
|
5
|
+
export class FSInlineAnalyzer {
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* - to be used on bundled content;
|
|
9
|
+
* @param {string} content
|
|
10
|
+
* @param {'cjs'|'esm'} format
|
|
11
|
+
* @returns {ReturnType<typeof TryAsync<string>>}
|
|
12
|
+
* @example
|
|
13
|
+
* import { readFile } from 'node:fs/promises';
|
|
14
|
+
*
|
|
15
|
+
* import { FSInlineAnalyzer } from 'vivth';
|
|
16
|
+
*
|
|
17
|
+
* const [resultFinalContent, errorFinalContent] = await FSInlineAnalyzer.finalContent(
|
|
18
|
+
* await readFile('./resultESBunlded.mjs', {encoding: 'utf-8'}),
|
|
19
|
+
* 'esm'
|
|
20
|
+
* );
|
|
21
|
+
*/
|
|
22
|
+
static finalContent: (content: string, format: "cjs" | "esm") => ReturnType<typeof TryAsync<string>>;
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {{path:string, buffer:Buffer<ArrayBuffer>}[]} _dirReturn
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} dirName
|
|
28
|
+
* @param {RegExp} ruleForFileFullPath
|
|
29
|
+
* @returns {Promise<_dirReturn>}
|
|
30
|
+
*/
|
|
31
|
+
static #dir: (dirName: string, ruleForFileFullPath: RegExp) => Promise<{
|
|
32
|
+
path: string;
|
|
33
|
+
buffer: Buffer<ArrayBuffer>;
|
|
34
|
+
}[]>;
|
|
35
|
+
}
|
|
36
|
+
import { TryAsync } from '../function/TryAsync.mjs';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class FSInline {
|
|
2
|
+
static prefix: string;
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} filePathFromProject
|
|
5
|
+
* @returns {Promise<Buffer<ArrayBuffer>>}
|
|
6
|
+
*/
|
|
7
|
+
static vivthFSInlineFile: (filePathFromProject: string) => Promise<Buffer<ArrayBuffer>>;
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} dirPathFromProject
|
|
10
|
+
* @param {Object} regexRule
|
|
11
|
+
* @param {RegExp} regexRule.dir
|
|
12
|
+
* @param {RegExp} regexRule.file
|
|
13
|
+
* @returns {Promise<typeof FSInline["vivthFSInlineFile"]>}
|
|
14
|
+
* - relative to the `dirPathFromProject`
|
|
15
|
+
*/
|
|
16
|
+
static vivthFSInlineDir: (dirPathFromProject: string) => Promise<(typeof FSInline)["vivthFSInlineFile"]>;
|
|
17
|
+
/**
|
|
18
|
+
* - to be used as embed placeholder on `bundled` and `compiled`;
|
|
19
|
+
* @type {Record<string, Buffer<ArrayBufferLike>>}
|
|
20
|
+
*/
|
|
21
|
+
static vivthFSInlinelists: Record<string, Buffer<ArrayBufferLike>>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* - generate `esbuild.Plugin` for changing dev time file into runtime file;
|
|
4
|
+
* - on using esbuild with this plugin, it will replace any module that have similiar file name but ended with Bundled(before extname);
|
|
5
|
+
* >- works on `.mts`|`.ts`|`.mjs`|`.cjs`|`.js`;
|
|
6
|
+
* >- `anyFileName.mjs` -> seek for and use `anyFileNameBundled.mjs`, if not found use `anyFileName.mjs`;
|
|
7
|
+
* @param {string} includedInPath
|
|
8
|
+
* - is generalized, you can freely uses forward or backward slash;
|
|
9
|
+
* @returns {ReturnType<CreateESPlugin>}
|
|
10
|
+
* @example
|
|
11
|
+
* import { ToBundledJSPlugin } from 'vivth';
|
|
12
|
+
*
|
|
13
|
+
* export const myBundledPlugin = ToBundledJSPlugin('/myProjectName/src/');
|
|
14
|
+
*/
|
|
15
|
+
export function ToBundledJSPlugin(includedInPath: string): ReturnType<typeof CreateESPlugin>;
|
|
16
|
+
import { CreateESPlugin } from '../CreateESPlugin.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const externals: string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const pluginVivthBundle: import("esbuild").Plugin;
|