vivth 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +2141 -1776
  2. package/README.src.md +5 -0
  3. package/bun.lock +6 -0
  4. package/index.mjs +12 -3
  5. package/package.json +4 -2
  6. package/src/bundler/CompileJS.mjs +60 -28
  7. package/src/bundler/EsBundler.mjs +2 -1
  8. package/src/bundler/FSInline.mjs +8 -1
  9. package/src/bundler/FSInlineAnalyzer.mjs +47 -38
  10. package/src/bundler/adds/ToBundledJSPlugin.mjs +38 -26
  11. package/src/bundler/adds/pluginVivthBundle.mjs +3 -1
  12. package/src/class/EventSignal.mjs +15 -9
  13. package/src/class/ListSignal.mjs +1 -1
  14. package/src/class/LitExp.mjs +3 -2
  15. package/src/class/Paths.mjs +0 -4
  16. package/src/class/QChannel.mjs +4 -5
  17. package/src/class/SafeExit.mjs +7 -7
  18. package/src/class/Signal.mjs +4 -1
  19. package/src/common/Base64URL.mjs +6 -4
  20. package/src/common/Dev.mjs +134 -0
  21. package/src/common/DevBundled.mjs +5 -0
  22. package/src/common/Trace.mjs +24 -0
  23. package/src/doc/JSautoDOC.mjs +15 -11
  24. package/src/doc/parsedFile.mjs +1 -1
  25. package/src/function/GetNamedImportAlias.mjs +37 -0
  26. package/src/function/LazyFactory.mjs +1 -1
  27. package/src/function/TsToMjs.mjs +3 -3
  28. package/src/types/DevTestCB.mjs +11 -0
  29. package/src/types/Runtime.mjs +0 -1
  30. package/src/types/VivthDevCodeBlockStringType.mjs +6 -0
  31. package/tsconfig.json +6 -1
  32. package/types/index.d.mts +8 -3
  33. package/types/src/bundler/CompileJS.d.mts +56 -28
  34. package/types/src/bundler/EsBundler.d.mts +2 -2
  35. package/types/src/bundler/FSInline.d.mts +8 -1
  36. package/types/src/bundler/FSInlineAnalyzer.d.mts +1 -0
  37. package/types/src/bundler/adds/ToBundledJSPlugin.d.mts +6 -3
  38. package/types/src/class/EventSignal.d.mts +8 -8
  39. package/types/src/class/ListSignal.d.mts +2 -2
  40. package/types/src/class/LitExp.d.mts +1 -0
  41. package/types/src/class/Paths.d.mts +0 -4
  42. package/types/src/class/QChannel.d.mts +4 -4
  43. package/types/src/class/SafeExit.d.mts +7 -7
  44. package/types/src/common/Base64URL.d.mts +5 -3
  45. package/types/src/common/Dev.d.mts +68 -0
  46. package/types/src/common/DevBundled.d.mts +3 -0
  47. package/types/src/common/Trace.d.mts +14 -0
  48. package/types/src/doc/JSautoDOC.d.mts +8 -7
  49. package/types/src/function/GetNamedImportAlias.d.mts +22 -0
  50. package/types/src/function/LazyFactory.d.mts +1 -1
  51. package/types/src/function/TsToMjs.d.mts +3 -3
  52. package/types/src/function/WithDefer.d.mts +10 -0
  53. package/types/src/types/DevTestCB.d.mts +3 -0
  54. package/types/src/types/IsDevCBStringType.d.mts +4 -0
  55. package/types/src/types/Runtime.d.mts +3 -0
  56. package/types/src/types/VivthDevCodeBlockStringType.d.mts +4 -0
package/README.src.md CHANGED
@@ -10,6 +10,9 @@ npm i vivth
10
10
 
11
11
  - `vivth` are intended to be a collections of usefull `primitives`, and not to be directly used as
12
12
  underlying framework;
13
+ - `vivth` are leaning to `esm(.mjs)+jsdoc` first;
14
+ > - some functionality "might need" work around if you are using other than `esm+jsdoc`;
15
+ > - `CompileJS`, `ESBundler` expose `format` option for some leeway for `commonJS`;
13
16
  - completely `JSruntime` agnostic:
14
17
  > - instead of `vivth` trying to guess, all runtime specific API should be provided by dev;
15
18
  - contains helpers to help you write data driven javascript program, including:
@@ -40,3 +43,5 @@ npm i vivth
40
43
 
41
44
  - `1.3.x:beta`:
42
45
  > - type should now fully fixed, even with strict ts check;
46
+ - `1.3.3+:beta`:
47
+ > - added class `Dev` for testing and `Dev`/`preBundled` only code block;
package/bun.lock CHANGED
@@ -14,7 +14,9 @@
14
14
  "devDependencies": {
15
15
  "@types/bun": "latest",
16
16
  "concurrently": "^9.2.1",
17
+ "prettier": "^3.6.2",
17
18
  "typescript": "^5.9.2",
19
+ "vivth": "link:vivth",
18
20
  },
19
21
  },
20
22
  },
@@ -261,6 +263,8 @@
261
263
 
262
264
  "prebuild-install": ["prebuild-install@7.1.1", "", { "dependencies": { "detect-libc": "^2.0.0", "expand-template": "^2.0.3", "github-from-package": "0.0.0", "minimist": "^1.2.3", "mkdirp-classic": "^0.5.3", "napi-build-utils": "^1.0.1", "node-abi": "^3.3.0", "pump": "^3.0.0", "rc": "^1.2.7", "simple-get": "^4.0.0", "tar-fs": "^2.0.0", "tunnel-agent": "^0.6.0" }, "bin": { "prebuild-install": "bin.js" } }, "sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw=="],
263
265
 
266
+ "prettier": ["prettier@3.6.2", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ=="],
267
+
264
268
  "process-nextick-args": ["process-nextick-args@2.0.1", "", {}, "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="],
265
269
 
266
270
  "progress": ["progress@2.0.3", "", {}, "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA=="],
@@ -335,6 +339,8 @@
335
339
 
336
340
  "util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="],
337
341
 
342
+ "vivth": ["vivth@link:vivth", {}],
343
+
338
344
  "webidl-conversions": ["webidl-conversions@3.0.1", "", {}, "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="],
339
345
 
340
346
  "whatwg-url": ["whatwg-url@5.0.0", "", { "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" } }, "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw=="],
package/index.mjs CHANGED
@@ -6,6 +6,7 @@
6
6
  * this library is made and distributed under MIT license;
7
7
  */
8
8
 
9
+ export { ToBundledJSPlugin } from './src/bundler/adds/ToBundledJSPlugin.mjs';
9
10
  export { CompileJS } from './src/bundler/CompileJS.mjs';
10
11
  export { CreateESPlugin } from './src/bundler/CreateESPlugin.mjs';
11
12
  export { EsBundler } from './src/bundler/EsBundler.mjs';
@@ -26,13 +27,18 @@ export { SafeExit } from './src/class/SafeExit.mjs';
26
27
  export { Setup } from './src/class/Setup.mjs';
27
28
  export { Signal } from './src/class/Signal.mjs';
28
29
  export { WorkerMainThread } from './src/class/WorkerMainThread.mjs';
30
+ export { WorkerResult } from './src/class/WorkerResult.mjs';
31
+ export { WorkerThread } from './src/class/WorkerThread.mjs';
29
32
  export { Base64URL } from './src/common/Base64URL.mjs';
30
33
  export { Base64URLFromFile } from './src/common/Base64URLFromFile.mjs';
34
+ export { Dev } from './src/common/Dev.mjs';
31
35
  export { EventNameSpace } from './src/common/EventNameSpace.mjs';
36
+ export { Trace } from './src/common/Trace.mjs';
32
37
  export { JSautoDOC } from './src/doc/JSautoDOC.mjs';
33
38
  export { CreateImmutable } from './src/function/CreateImmutable.mjs';
34
39
  export { EventCheck } from './src/function/EventCheck.mjs';
35
40
  export { EventObject } from './src/function/EventObject.mjs';
41
+ export { GetNamedImportAlias } from './src/function/GetNamedImportAlias.mjs';
36
42
  export { GetRuntime } from './src/function/GetRuntime.mjs';
37
43
  export { IsAsync } from './src/function/IsAsync.mjs';
38
44
  export { LazyFactory } from './src/function/LazyFactory.mjs';
@@ -41,12 +47,12 @@ export { Try } from './src/function/Try.mjs';
41
47
  export { TryAsync } from './src/function/TryAsync.mjs';
42
48
  export { TrySync } from './src/function/TrySync.mjs';
43
49
  export { TsToMjs } from './src/function/TsToMjs.mjs';
44
- export { WorkerResult } from './src/class/WorkerResult.mjs';
45
- export { WorkerThread } from './src/class/WorkerThread.mjs';
46
- export { ToBundledJSPlugin } from './src/bundler/adds/ToBundledJSPlugin.mjs';
47
50
  /**
48
51
  * @typedef {import('./src/types/AnyButUndefined.mjs').AnyButUndefined} AnyButUndefined
49
52
  */
53
+ /**
54
+ * @typedef {import('./src/types/DevTestCB.mjs').DevTestCB} DevTestCB
55
+ */
50
56
  /**
51
57
  * @typedef {import('./src/types/ExtnameType.mjs').ExtnameType} ExtnameType
52
58
  */
@@ -74,4 +80,7 @@ export { ToBundledJSPlugin } from './src/bundler/adds/ToBundledJSPlugin.mjs';
74
80
  */
75
81
  /**
76
82
  * @typedef {import('./src/types/Runtime.mjs').Runtime} Runtime
83
+ */
84
+ /**
85
+ * @typedef {import('./src/types/VivthDevCodeBlockStringType.mjs').VivthDevCodeBlockStringType} VivthDevCodeBlockStringType
77
86
  */
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "vivth",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "library primitives",
5
5
  "main": "index.mjs",
6
6
  "types": "./types/index.d.mts",
7
7
  "devDependencies": {
8
8
  "@types/bun": "latest",
9
9
  "concurrently": "^9.2.1",
10
- "typescript": "^5.9.2"
10
+ "typescript": "^5.9.2",
11
+ "vivth": "link:vivth"
11
12
  },
12
13
  "dependencies": {
14
+ "prettier": "^3.6.2",
13
15
  "@types/mime-types": "^3.0.1",
14
16
  "chokidar": "^4.0.3",
15
17
  "esbuild": "^0.25.9",
@@ -10,6 +10,7 @@ import { EsBundler } from './EsBundler.mjs';
10
10
  import { FileSafe } from '../class/FileSafe.mjs';
11
11
  import { TryAsync } from '../function/TryAsync.mjs';
12
12
  import { FSInlineAnalyzer } from './FSInlineAnalyzer.mjs';
13
+ import { removeVivthDevCodeBlock } from './adds/ToBundledJSPlugin.mjs';
13
14
 
14
15
  /**
15
16
  * @typedef {'win32' | 'linux' | 'darwin' | string} PlatformKey
@@ -67,9 +68,9 @@ const getBinaryExtension = () => {
67
68
  /**
68
69
  * @description
69
70
  * - function to compile `.ts`|`.mts`|`.mjs` file, into a single executable;
70
- * - also generate js representation;
71
+ * - also generate js representation of the `bundled` version of the target;
71
72
  * - 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;
72
- * >- they are used only as packaging agent, and doesn't necessarily supports their advanced feature, such as, assets bundling(use [FSInline](#fsinline) instead);
73
+ * >- they are used only as packaging/compiler agent, and doesn't necessarily supports their advanced feature, such as, assets bundling(use [`FSInline`](#fsinline) instead);
73
74
  * >- `WorkerThread` will be converted to inline using `FSInline` too;
74
75
  *
75
76
  * !!!WARNING!!!
@@ -88,8 +89,12 @@ const getBinaryExtension = () => {
88
89
  * @param {string} options.entryPoint
89
90
  * - need to be manually prefixed;
90
91
  * @param {BufferEncoding} [options.encoding]
91
- * - write and read encoding for the sources;
92
+ * - read and write encoding for the sources;
92
93
  * - default: `utf-8`;
94
+ * @param {(entryPointContent:string)=>string} [options.preprocessEntryPoint]
95
+ * - to modify entry point before bundling;
96
+ * - `entryPointContent` is the original string of the entry point;
97
+ * - returned value then passed to `ESBundler`;
93
98
  * @param {boolean} options.minifyFirst
94
99
  * - minify the bundle before compilation;
95
100
  * @param {string} options.outDir
@@ -110,44 +115,68 @@ const getBinaryExtension = () => {
110
115
  * }>>}
111
116
  * @example
112
117
  * import { join } from 'node:path';
118
+ * import { CompileJS, Console, Paths, Setup } from 'vivth';
113
119
  *
114
- * import { CompileJS, Paths } from 'vivth';
120
+ * const { paths, safeExit } = Setup;
121
+ * new paths({
122
+ * root: process?.env?.INIT_CWD ?? process?.cwd(),
123
+ * });
124
+ * new safeExit({
125
+ * eventNames: ['SIGINT', 'SIGTERM'],
126
+ * terminator: () => process.exit(0), // OR on deno () => Deno.exit\* (0),
127
+ * listener: (eventName) => {
128
+ * process.once(eventName, function () {
129
+ * if (!safeExit.instance) {
130
+ * return;
131
+ * }
132
+ * safeExit.instance.exiting.correction(true);
133
+ * Console.log(`safe exit via "${eventName}"`);
134
+ * });
135
+ * },
136
+ * });
137
+ * const pathRoot = Paths.root;
138
+ * if (pathRoot) {
139
+ * const [[, error], [, errorbun]] = await Promise.all([
140
+ * CompileJS({
141
+ * entryPoint: join(pathRoot, '/dev/myEntryPoint.mjs'),
142
+ * minifyFirst: true,
143
+ * outDir: join(pathRoot, '/dev-pkg/'),
144
+ * compiler: 'pkg',
145
+ * compilerArguments: {
146
+ * target: 'node18-win-x64',
147
+ * },
148
+ * encoding: 'utf-8',
149
+ * }),
150
+ * await CompileJS({
151
+ * entryPoint: join(pathRoot, '/dev/myEntryPoint.mjs'),
152
+ * minifyFirst: true,
153
+ * outDir: join(pathRoot, '/dev-bun/'),
154
+ * compiler: 'bun',
155
+ * compilerArguments: {
156
+ * target: 'bun-win-x64',
157
+ * },
158
+ * encoding: 'utf-8',
159
+ * }),
160
+ * ]);
161
+ * if (error || errorbun) {
162
+ * Console.error({ error, errorbun });
163
+ * }
164
+ * }
115
165
  *
116
- * const [[resultPkg, errorPkg], [resultBun, errorBun]] = await Promise.all([
117
- * CompileJS({
118
- * entryPoint: join(Paths.root, '/dev'),
119
- * minifyFirst: true,
120
- * outDir: join(Paths.root, '/dev-pkg'),
121
- * compiler: 'pkg',
122
- * compilerArguments: {
123
- * target: ['node18-win-x64'],
124
- * },
125
- * esBundlerPlugins: [],
126
- * }),
127
- * CompileJS({
128
- * entryPoint: join(Paths.root, '/dev'),
129
- * minifyFirst: true,
130
- * outDir: join(Paths.root, '/dev-pkg'),
131
- * compiler: 'bun',
132
- * compilerArguments: {
133
- * target: ['bun-win-x64'],
134
- * },
135
- * esBundlerPlugins: [],
136
- * }),
137
- * ])
138
166
  */
139
167
  export async function CompileJS({
140
168
  entryPoint,
141
169
  minifyFirst,
142
170
  encoding = 'utf-8',
143
171
  outDir,
172
+ preprocessEntryPoint = undefined,
144
173
  compiler = undefined,
145
174
  compilerArguments = {},
146
175
  esBundlerPlugins = [],
147
176
  }) {
148
177
  return await TryAsync(async () => {
149
178
  /**
150
- * @type {'cjs'|'esm'|'iife'}
179
+ * @type {'cjs'|'esm'}
151
180
  */
152
181
  let format;
153
182
  switch (compiler) {
@@ -174,7 +203,10 @@ export async function CompileJS({
174
203
  `extention mismatch: "${extOfSource}", should be one of:".mjs"|".mts"|".ts"`
175
204
  );
176
205
  }
177
- const sourceText = await readFile(entryPoint, { encoding });
206
+ let sourceText = removeVivthDevCodeBlock(await readFile(entryPoint, { encoding }));
207
+ if (preprocessEntryPoint) {
208
+ sourceText = preprocessEntryPoint(sourceText);
209
+ }
178
210
  const [bundledPrep, errorPrep] = await EsBundler(
179
211
  {
180
212
  content: sourceText,
@@ -17,7 +17,7 @@ import { externals } from './adds/externals.mjs';
17
17
  * - the code can also uses composites from the result from multiple readFiles;
18
18
  * @param {string} options.root
19
19
  * - use dirname of said fileString path;
20
- * @param {'.mts'|'.ts'|'.mjs'} options.extension
20
+ * @param {'.mts'|'.ts'|'.mjs'|'.cjs'} options.extension
21
21
  * @param {boolean} [options.withBinHeader]
22
22
  * @param {Omit<Parameters<build>[0],
23
23
  * 'entryPoints'|'bundle'|'write'|'sourcemap'>
@@ -51,6 +51,7 @@ export async function EsBundler(
51
51
  loader = 'ts';
52
52
  break;
53
53
  case '.mjs':
54
+ case '.cjs':
54
55
  loader = 'js';
55
56
  break;
56
57
  default:
@@ -7,8 +7,11 @@ import { Paths } from '../class/Paths.mjs';
7
7
 
8
8
  /**
9
9
  * @description
10
- * - class helper to inline file;
10
+ * - class helper to inline files;
11
+ * >- as `type: "buffer"`;
11
12
  * - use only if you are planning to use [CompileJS](#compilejs);
13
+ * >- the class static methods don't obfuscate target file;
14
+ * >- don't embed any sensitive content using this methods of this class;
12
15
  */
13
16
  export class FSInline {
14
17
  /**
@@ -19,6 +22,9 @@ export class FSInline {
19
22
  * @param {string} filePathFromProject
20
23
  * - doesn't require prefix;
21
24
  * @returns {Promise<Buffer<ArrayBuffer>>}
25
+ * - dev: returns `ArrayBuffer`;
26
+ * - bundled: embed the `ArrayBuffer` of file, which then returned;
27
+ * >- `Dev` will be cleaned up;
22
28
  * @example
23
29
  * import { FSInline } from 'vivth';
24
30
  *
@@ -35,6 +41,7 @@ export class FSInline {
35
41
  /**
36
42
  * @description
37
43
  * - declare entrypoint of file inlining, include all files on `dir` and `subdir` that match the `fileRule`;
44
+ * - consider this as inline assets embed/bundler;
38
45
  * @param {string} dirPathFromProject
39
46
  * - doesn't require prefix;
40
47
  * @param {RegExp} fileRule
@@ -8,6 +8,7 @@ import { LitExp } from '../class/LitExp.mjs';
8
8
  import { TryAsync } from '../function/TryAsync.mjs';
9
9
  import { FSInline } from './FSInline.mjs';
10
10
  import { EsBundler } from './EsBundler.mjs';
11
+ import { removeVivthDevCodeBlock } from './adds/ToBundledJSPlugin.mjs';
11
12
 
12
13
  /**
13
14
  * @param {string} str
@@ -25,6 +26,7 @@ const hydrateRegex = (str) => {
25
26
  /**
26
27
  * @description
27
28
  * - collections of static method to analyze content for `FSInline`;
29
+ * - mostly used internally;
28
30
  */
29
31
  export class FSInlineAnalyzer {
30
32
  /**
@@ -45,25 +47,26 @@ export class FSInlineAnalyzer {
45
47
  */
46
48
  static finalContent = async (content, format) => {
47
49
  return await TryAsync(async () => {
50
+ content = removeVivthDevCodeBlock(content);
48
51
  const [literalFile, errorPrepareFile] = LitExp.prepare({
49
- FSInline: /\w*/,
52
+ FSInline: /[\w][\w\d]*/,
50
53
  method: /\.vivthFSInlineFile\s*?\(\s*?['"]/,
51
54
  path: false,
52
- closing: /['"]\s*?\)(?:;|)/,
55
+ closing: /['"]\s*?\)/,
53
56
  });
54
57
  const [literalWorker, errorPreparWorker] = LitExp.prepare({
55
- ref: /\w*/,
58
+ ref: /[\w][\w\d]*/,
56
59
  method: /\.newVivthWorker\s*?\(\s*?['"]/,
57
60
  path: false,
58
- closing: /['"]/,
61
+ closing: /['"]\s*\)/,
59
62
  });
60
63
  const [literalDir, errorPrepareDir] = LitExp.prepare({
61
- FSInline: /\w*/,
64
+ FSInline: /[\w][\w\d]*/,
62
65
  method: /\.vivthFSInlineDir\s*?\(\s*?['"]/,
63
66
  path: false,
64
- methodClosing: /['"]\s*?,/,
67
+ methodClosing: /['"]\s*?,\s*/,
65
68
  rule: false,
66
- functionClosing: /\)(?:;|)/,
69
+ functionClosing: /\s*?\)/,
67
70
  });
68
71
  if (errorPrepareFile || errorPrepareDir || errorPreparWorker) {
69
72
  throw { errorPrepareFile, errorPrepareDir, errorPreparWorker };
@@ -71,7 +74,6 @@ export class FSInlineAnalyzer {
71
74
  const templateFile = literalFile`${'FSInline'}${'method'}${'path'}${'closing'}`;
72
75
  const templateWorker = literalWorker`${'ref'}${'method'}${'path'}${'closing'}`;
73
76
  const templateDir = literalDir`${'FSInline'}${'method'}${'path'}${'methodClosing'}${'rule'}${'functionClosing'}`;
74
-
75
77
  const [resultMatchingFile, errorMatchingFile] = templateFile.evaluate.matchedAllAndGrouped(
76
78
  content,
77
79
  {
@@ -94,19 +96,47 @@ export class FSInlineAnalyzer {
94
96
  if (errorMatchingFile || errorMatchingDir || errorMatchingWorker) {
95
97
  throw { errorMatchingFile, errorMatchingDir, errorMatchingWorker };
96
98
  }
97
- const {
98
- result: { named: namedFile },
99
- } = resultMatchingFile;
100
99
  if (Paths.root === undefined) {
101
100
  throw new Error('Path.root undefined');
102
101
  }
102
+ const {
103
+ result: { named: namedFile },
104
+ } = resultMatchingFile;
103
105
  for (let i = 0; i < namedFile.length; i++) {
104
106
  const res = namedFile[i];
105
107
  if (res === undefined) {
106
108
  continue;
107
109
  }
108
110
  const { path } = res;
109
- FSInline.vivthFSInlinelists[path] = Buffer.from(await readFile(join(Paths.root, path)));
111
+ if ('path' in FSInline.vivthFSInlinelists) {
112
+ continue;
113
+ }
114
+ FSInline.vivthFSInlinelists[path] = Buffer.from(
115
+ removeVivthDevCodeBlock(await readFile(join(Paths.root, path), { encoding: 'utf-8' }))
116
+ );
117
+ }
118
+ const {
119
+ result: { named: namedDir },
120
+ } = resultMatchingDir;
121
+ for (let i = 0; i < namedDir.length; i++) {
122
+ const res = namedDir[i];
123
+ if (res === undefined) {
124
+ continue;
125
+ }
126
+ let { path, rule } = res;
127
+ rule = rule.trim();
128
+ const results = await FSInlineAnalyzer.#dir(join(Paths.root, path), hydrateRegex(rule));
129
+ for (let j = 0; j < results.length; j++) {
130
+ const res = results[j];
131
+ if (res === undefined) {
132
+ continue;
133
+ }
134
+ const { path, buffer } = res;
135
+ if (path in FSInline.vivthFSInlinelists) {
136
+ continue;
137
+ }
138
+ FSInline.vivthFSInlinelists[path] = buffer;
139
+ }
110
140
  }
111
141
  const {
112
142
  result: { named: namedWorker },
@@ -118,12 +148,12 @@ export class FSInlineAnalyzer {
118
148
  }
119
149
  const { path } = res;
120
150
  const fullPath = join(Paths.root, path);
121
- const content = await readFile(fullPath, { encoding: 'utf-8' });
151
+ const content = removeVivthDevCodeBlock(await readFile(fullPath, { encoding: 'utf-8' }));
122
152
  const [contentBundled, errorBundled] = await EsBundler(
123
153
  {
124
154
  content,
125
155
  // @ts-expect-error
126
- extension: extname(path),
156
+ extension: extname(fullPath),
127
157
  root: dirname(fullPath),
128
158
  },
129
159
  {
@@ -143,29 +173,6 @@ export class FSInlineAnalyzer {
143
173
  }
144
174
  FSInline.vivthFSInlinelists[path] = Buffer.from(trueContent);
145
175
  }
146
- const {
147
- result: { named: namedDir },
148
- } = resultMatchingDir;
149
- for (let i = 0; i < namedDir.length; i++) {
150
- const res = namedDir[i];
151
- if (res === undefined) {
152
- continue;
153
- }
154
- let { path, rule } = res;
155
- rule = rule.trim();
156
- const results = await FSInlineAnalyzer.#dir(join(Paths.root, path), hydrateRegex(rule));
157
- for (let j = 0; j < results.length; j++) {
158
- const res = results[j];
159
- if (res === undefined) {
160
- continue;
161
- }
162
- const { path, buffer } = res;
163
- if (path in FSInline.vivthFSInlinelists) {
164
- continue;
165
- }
166
- FSInline.vivthFSInlinelists[path] = buffer;
167
- }
168
- }
169
176
  return content.replace(
170
177
  /static\s*vivthFSInlinelists(?:;|)/,
171
178
  `static vivthFSInlinelists=${JSON.stringify(FSInline.vivthFSInlinelists)}`
@@ -208,7 +215,9 @@ export class FSInlineAnalyzer {
208
215
  if (entry.isFile() && ruleForFileFullPath.test(fullPath)) {
209
216
  result.push({
210
217
  path: relativePath,
211
- buffer: Buffer.from(await readFile(fullPath)),
218
+ buffer: Buffer.from(
219
+ removeVivthDevCodeBlock(await readFile(fullPath, { encoding: 'utf-8' }))
220
+ ),
212
221
  });
213
222
  }
214
223
  }
@@ -3,15 +3,34 @@
3
3
  import { basename, extname } from 'node:path';
4
4
  import { readFile, exists } from 'node:fs/promises';
5
5
  import { CreateESPlugin } from '../CreateESPlugin.mjs';
6
+ import { GetNamedImportAlias } from '../../function/GetNamedImportAlias.mjs';
7
+
8
+ /**
9
+ * @param {string} originalContent_
10
+ * @returns {string}
11
+ */
12
+ export const removeVivthDevCodeBlock = (originalContent_) => {
13
+ const alias = GetNamedImportAlias(originalContent_, 'Dev', 'vivth');
14
+ if (!alias) {
15
+ return originalContent_;
16
+ }
17
+ const regex = new RegExp(
18
+ `(\\s*${alias}.vivthDevCodeBlock\\s*\\([\\s\\S]*?,\\s*['"]vivthDevCodeBlock['"]\\s*\\)(?:\\;|,|))`,
19
+ 'g'
20
+ );
21
+ return originalContent_.replace(regex, '');
22
+ };
6
23
 
7
24
  /**
8
25
  * @description
9
26
  * - generate `esbuild.Plugin` for changing dev time file into runtime file;
10
- * - on using esbuild with this plugin, it will replace any module that have similiar file name but ended with Bundled(before extname);
27
+ * - on using esbuild with this plugin, it will:
28
+ * >- replace any module that have similiar file name but ended with Bundled(before extname);
11
29
  * >- works on `.mts`|`.ts`|`.mjs`|`.cjs`|`.js`;
12
- * >- `anyFileName.mjs` -> seek for and use `anyFileNameBundled.mjs`, if not found use `anyFileName.mjs`;
30
+ * >- `${fileName}.mjs` -> seek for and use `${fileName}Bundled.mjs`, if not found use `${fileName}.mjs`;
31
+ * >- removes `Dev.vivthDevCodeBlock` code block;
13
32
  * @param {string} includedInPath
14
- * - is generalized, you can freely uses forward or backward slash;
33
+ * - is generalized path, you can freely uses forward or backward slash;
15
34
  * @returns {ReturnType<CreateESPlugin>}
16
35
  * @example
17
36
  * import { ToBundledJSPlugin } from 'vivth';
@@ -39,38 +58,31 @@ export function ToBundledJSPlugin(includedInPath) {
39
58
  loader = 'js';
40
59
  break;
41
60
  }
42
- const originalContent = (await readFile(filePath)).toString('utf-8');
43
- if (loader === undefined) {
44
- return {
45
- contents: originalContent,
46
- loader,
47
- };
48
- }
49
- if (filePath.endsWith(`Bundled${fileExt}`)) {
50
- return {
51
- contents: originalContent,
52
- loader,
53
- };
61
+ /**
62
+ * @type {ReturnType<Parameters<import('esbuild').PluginBuild["onLoad"]>[1]>}
63
+ */
64
+ const ret = { loader };
65
+ if (loader === undefined || filePath.endsWith(`Bundled${fileExt}`)) {
66
+ const originalContent = (await readFile(filePath)).toString('utf-8');
67
+ ret.contents = removeVivthDevCodeBlock(originalContent);
68
+ return ret;
54
69
  }
55
70
  const originalBaseName = basename(filePath);
56
71
  const originalFileName = originalBaseName.replace(fileExt, '');
57
72
  const realRef = `${originalFileName}Bundled`;
58
- const runtimeFile = filePath.replace(
73
+ const bundledFile = filePath.replace(
59
74
  new RegExp(`${originalBaseName}\$`.replace('.', '\\.'), ''),
60
75
  `${realRef}${fileExt}`
61
76
  );
62
- const isExist = await exists(runtimeFile);
77
+ const isExist = await exists(bundledFile);
63
78
  if (isExist === false) {
64
- return {
65
- contents: originalContent,
66
- loader,
67
- };
79
+ const originalContent = (await readFile(filePath)).toString('utf-8');
80
+ ret.contents = removeVivthDevCodeBlock(originalContent);
81
+ return ret;
68
82
  }
69
- const contents = (await readFile(runtimeFile)).toString('utf-8');
70
- return {
71
- contents,
72
- loader,
73
- };
83
+ const originalContent = (await readFile(bundledFile)).toString('utf-8');
84
+ ret.contents = removeVivthDevCodeBlock(originalContent);
85
+ return ret;
74
86
  });
75
87
  });
76
88
  }
@@ -2,4 +2,6 @@
2
2
 
3
3
  import { ToBundledJSPlugin } from './ToBundledJSPlugin.mjs';
4
4
 
5
- export const pluginVivthBundle = ToBundledJSPlugin('/vivth/src/');
5
+ const path = '/vivth/src/';
6
+
7
+ export const pluginVivthBundle = ToBundledJSPlugin(path);
@@ -135,17 +135,20 @@ export class EventSignal {
135
135
  * @description
136
136
  * - remove subscriber from the named `EventSignal_instance`;
137
137
  * @param {string} name
138
- * @param {import('./Effect.mjs').Effect} effect
138
+ * @param {import('./Effect.mjs').Effect} effectInstance
139
139
  * @returns {void}
140
140
  * @example
141
141
  * import { EventSignal } from 'vivth';
142
142
  *
143
143
  * EventSignal.remove.subscriber('yourEventSignalName', myEffectInstance);
144
144
  */
145
- subscriber: (name, effect) => {
146
- effect.options.removeEffect();
145
+ subscriber: (name, effectInstance) => {
146
+ /**
147
+ * this part is not needed, as the effect might need to react to other signals
148
+ // effectInstance.options.removeEffect();
149
+ */
147
150
  EventSignal.get(name).then(({ remove }) => {
148
- remove.subscriber(effect);
151
+ remove.subscriber(effectInstance);
149
152
  });
150
153
  },
151
154
  /**
@@ -186,7 +189,7 @@ export class EventSignal {
186
189
  * @instance remove
187
190
  * @description
188
191
  * - remove subscriber from the `EventSignal_instance`;
189
- * @param {import('./Effect.mjs').Effect} effect
192
+ * @param {import('./Effect.mjs').Effect} effectInstance
190
193
  * @returns {void}
191
194
  * @example
192
195
  * import { EventSignal, Effect, Console } from 'vivth';
@@ -200,10 +203,13 @@ export class EventSignal {
200
203
  * myEventSignal.dispatch.value = 'hey';
201
204
  * eventSignal_instance.remove.subscriber(myEffectInstance);
202
205
  */
203
- subscriber: (effect) => {
204
- effect.options.removeEffect();
205
- this.dispatch.remove.subscriber(effect);
206
- this.listen.remove.subscriber(effect);
206
+ subscriber: (effectInstance) => {
207
+ /**
208
+ * this part is not needed, as the effect might need to react to other signals
209
+ // effectInstance.options.removeEffect();
210
+ */
211
+ this.dispatch.remove.subscriber(effectInstance);
212
+ this.listen.remove.subscriber(effectInstance);
207
213
  },
208
214
  /**
209
215
  * @instance remove
@@ -85,7 +85,7 @@ export class ListSignal extends Signal {
85
85
  * @instance arrayMethods
86
86
  * @description
87
87
  * - reference to structuredClone elements of `value`;
88
- * - calling doesn't notify
88
+ * - calling doesn't notify for changes;
89
89
  * @returns {Array<LISTARG>}
90
90
  */
91
91
  get structuredClone() {
@@ -12,6 +12,7 @@ import { TrySync } from '../function/TrySync.mjs';
12
12
  * >- destructuring is meant for extensive typehelper;
13
13
  * >- and destructuring can lead to unhandled error here and there;
14
14
  * >- therefore error as value is introduced to help to prevent error on runtime;
15
+ * - made primarily for generating string file, that are purely managed programatically;
15
16
  * @template {LitExpKeyType} KEYS
16
17
  */
17
18
  export class LitExp {
@@ -32,7 +33,7 @@ export class LitExp {
32
33
  * new RegExp(escapedLiteral, 'g');
33
34
  */
34
35
  static escape = (string) => {
35
- return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
36
+ return string.replace(/[.*+?^${}()|[\]\\\]]/g, '\\$&');
36
37
  };
37
38
  /**
38
39
  * @description
@@ -131,7 +132,7 @@ export class LitExp {
131
132
  throw new Error('string undefined');
132
133
  }
133
134
  if (i + 1 == stringsLength && string === '') {
134
- result.push('(?:\\s+?|$)');
135
+ result.push('(?:\\s+?|;|,|$|)');
135
136
  } else {
136
137
  result.push(LitExp.escape(string));
137
138
  }
@@ -31,10 +31,6 @@ export class Paths {
31
31
  * ```js
32
32
  * Deno.env.get("INIT_CWD") ?? Deno.cwd()
33
33
  * ```
34
- * - pkg:
35
- * ```js
36
- * __dirname
37
- * ```
38
34
  * - other: you need to check your JSRuntime for the rootPath reference;
39
35
  * @example
40
36
  * import { Paths } from 'vivth';