vivth 1.2.3 → 1.3.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.
Files changed (71) hide show
  1. package/README.md +608 -586
  2. package/README.src.md +5 -1
  3. package/bun.lock +6 -0
  4. package/index.mjs +10 -6
  5. package/package.json +3 -1
  6. package/src/bundler/CompileJS.mjs +11 -8
  7. package/src/bundler/EsBundler.mjs +4 -2
  8. package/src/bundler/FSInline.mjs +3 -0
  9. package/src/bundler/FSInlineAnalyzer.mjs +31 -7
  10. package/src/bundler/FSInlineBundled.mjs +5 -1
  11. package/src/bundler/adds/ToBundledJSPlugin.mjs +3 -4
  12. package/src/class/Console.mjs +12 -4
  13. package/src/class/Derived.mjs +5 -1
  14. package/src/class/Effect.mjs +6 -6
  15. package/src/class/EnvSignal.mjs +1 -8
  16. package/src/class/EventSignal.mjs +8 -7
  17. package/src/class/FileSafe.mjs +1 -1
  18. package/src/class/ListSignal.mjs +18 -10
  19. package/src/class/LitExp.mjs +241 -204
  20. package/src/class/Paths.mjs +10 -8
  21. package/src/class/QChannel.mjs +14 -7
  22. package/src/class/SafeExit.mjs +16 -7
  23. package/src/class/Signal.mjs +8 -7
  24. package/src/class/WorkerMainThread.mjs +45 -24
  25. package/src/class/WorkerMainThreadBundled.mjs +42 -24
  26. package/src/class/WorkerThread.mjs +21 -7
  27. package/src/common/Base64URL.mjs +2 -2
  28. package/src/common/Base64URLFromFile.mjs +1 -1
  29. package/src/doc/JSautoDOC.mjs +99 -62
  30. package/src/doc/correctBeforeParse.mjs +139 -0
  31. package/src/doc/parsedFile.mjs +127 -76
  32. package/src/function/CreateImmutable.mjs +12 -7
  33. package/src/function/GetRuntime.mjs +8 -3
  34. package/src/function/LazyFactory.mjs +10 -4
  35. package/src/function/Try.mjs +4 -1
  36. package/src/function/TryAsync.mjs +2 -1
  37. package/src/function/TrySync.mjs +3 -1
  38. package/src/function/TsToMjs.mjs +7 -4
  39. package/src/types/AnyButUndefined.mjs +1 -0
  40. package/src/types/LitExpResultType.mjs +7 -0
  41. package/src/types/Runtime.mjs +1 -1
  42. package/tsconfig.json +27 -5
  43. package/types/dev/workerThreadClass.d.mts +1 -1
  44. package/types/index.d.mts +7 -6
  45. package/types/src/bundler/CompileJS.d.mts +14 -9
  46. package/types/src/bundler/EsBundler.d.mts +1 -1
  47. package/types/src/class/Derived.d.mts +4 -64
  48. package/types/src/class/Effect.d.mts +8 -8
  49. package/types/src/class/EnvSignal.d.mts +0 -1
  50. package/types/src/class/EventSignal.d.mts +5 -5
  51. package/types/src/class/FileSafe.d.mts +2 -2
  52. package/types/src/class/ListSignal.d.mts +1 -1
  53. package/types/src/class/LitExp.d.mts +49 -53
  54. package/types/src/class/Paths.d.mts +4 -4
  55. package/types/src/class/QChannel.d.mts +1 -1
  56. package/types/src/class/SafeExit.d.mts +3 -3
  57. package/types/src/class/Signal.d.mts +3 -3
  58. package/types/src/class/WorkerMainThread.d.mts +13 -8
  59. package/types/src/class/WorkerMainThreadBundled.d.mts +13 -8
  60. package/types/src/class/WorkerThread.d.mts +4 -4
  61. package/types/src/common/Base64URL.d.mts +2 -2
  62. package/types/src/common/Base64URLFromFile.d.mts +2 -2
  63. package/types/src/doc/JSautoDOC.d.mts +33 -12
  64. package/types/src/doc/correctBeforeParse.d.mts +2 -0
  65. package/types/src/doc/parsedFile.d.mts +7 -10
  66. package/types/src/function/CreateImmutable.d.mts +2 -2
  67. package/types/src/function/Try.d.mts +2 -2
  68. package/types/src/function/TryAsync.d.mts +2 -2
  69. package/types/src/function/TrySync.d.mts +3 -2
  70. package/types/src/function/TsToMjs.d.mts +2 -2
  71. package/types/src/types/LitExpResultType.d.mts +7 -0
@@ -1,8 +1,8 @@
1
1
  // @ts-check
2
2
 
3
- import { readFile, stat } from 'node:fs/promises';
3
+ import { readFile } from 'node:fs/promises';
4
4
  import { Stats } from 'node:fs';
5
- import { normalize, basename, join, relative, extname, dirname } from 'node:path';
5
+ import { normalize, basename, join, relative, extname, dirname, resolve } from 'node:path';
6
6
 
7
7
  import { Paths } from '../class/Paths.mjs';
8
8
  import { LazyFactory } from '../function/LazyFactory.mjs';
@@ -24,9 +24,14 @@ export class parsedFile {
24
24
  */
25
25
  /**
26
26
  * @param {string} path__
27
+ * @param {import('fs').Stats} _stats
27
28
  * @param {BufferEncoding} [encoding]
28
29
  */
29
- constructor(path__, encoding = 'utf-8') {
30
+ constructor(path__, _stats, encoding = 'utf-8') {
31
+ if (Paths.root === undefined) {
32
+ return;
33
+ }
34
+ this.#stats = _stats;
30
35
  const root = Paths.root.replace(/\\/g, '/');
31
36
  if (Paths.normalize(path__).startsWith(root)) {
32
37
  this.#fullPath = path__;
@@ -38,20 +43,34 @@ export class parsedFile {
38
43
  }
39
44
  parse = async () => {
40
45
  const { details, error, exportName } = await this.content.parsed();
41
- if (error) {
46
+ if (error || exportName === undefined) {
42
47
  return;
43
48
  }
44
49
  for (let i = 0; i < details.length; i++) {
50
+ const detail = details[i];
51
+ if (detail === undefined) {
52
+ continue;
53
+ }
45
54
  const [
46
- _,
47
- __,
55
+ ,
56
+ ,
48
57
  instanceOrStaticDef,
49
58
  fullDescription,
50
59
  isExport,
51
60
  typeOfVar,
52
61
  getterOrSetter,
53
62
  namedVar,
54
- ] = details[i];
63
+ ] = detail;
64
+ if (
65
+ instanceOrStaticDef === undefined ||
66
+ fullDescription === undefined ||
67
+ isExport === undefined ||
68
+ typeOfVar === undefined ||
69
+ getterOrSetter === undefined ||
70
+ namedVar === undefined
71
+ ) {
72
+ continue;
73
+ }
55
74
  const interpreted = this.#interpreteArrayDesc(
56
75
  exportName,
57
76
  instanceOrStaticDef,
@@ -61,6 +80,9 @@ export class parsedFile {
61
80
  getterOrSetter,
62
81
  namedVar
63
82
  );
83
+ if (interpreted === undefined) {
84
+ return;
85
+ }
64
86
  this.documented.readme.add(interpreted);
65
87
  }
66
88
  };
@@ -68,14 +90,18 @@ export class parsedFile {
68
90
  return {
69
91
  typedef: async () => {
70
92
  const relativePath = this.path.relative;
71
- if (!relativePath) {
93
+ if (relativePath === '') {
94
+ return;
95
+ }
96
+ const baseName = this.baseName.noExt.split('.')[0];
97
+ if (baseName === undefined) {
98
+ return;
99
+ }
100
+ const content = await this.content.string();
101
+ if (content === undefined) {
72
102
  return;
73
103
  }
74
- const typedef = this.#parseTypedef(
75
- this.baseName.noExt.split('.')[0],
76
- relativePath,
77
- await this.content.string()
78
- );
104
+ const typedef = this.#parseTypedef(baseName, relativePath, content);
79
105
  return typedef;
80
106
  },
81
107
  /**
@@ -90,12 +116,15 @@ export class parsedFile {
90
116
  */
91
117
  static #isExportNameValid = (exportName) => {
92
118
  const firstLetter = exportName.split('')[0];
119
+ if (firstLetter === undefined) {
120
+ return false;
121
+ }
93
122
  return firstLetter.toUpperCase() === firstLetter;
94
123
  };
95
124
  /**
96
125
  * @type {undefined|{module:string, readme:string}}
97
126
  */
98
- parsedType = undefined;
127
+ parsedType;
99
128
  /**
100
129
  * @param {string} exportName
101
130
  * @param {string} relativePath
@@ -103,19 +132,30 @@ export class parsedFile {
103
132
  * @returns {parsedFile["parsedType"]}
104
133
  */
105
134
  #parseTypedef = (exportName, relativePath, content) => {
106
- if (!parsedFile.#isExportNameValid(exportName)) {
135
+ const rootPath = Paths.root;
136
+ if (rootPath === undefined || parsedFile.#isExportNameValid(exportName) === false) {
107
137
  return undefined;
108
138
  }
109
- if (!this.parsedType) {
139
+ if (this.parsedType === undefined) {
110
140
  const baseNameNoExt = this.baseName.noExt;
111
141
  const relativeDir = this.dirName.relative;
112
142
  const contents = content.matchAll(/(\/\*\*[\s\S]*?\*\/)/gm).toArray();
113
143
  const readme = contents
114
- .map(([_, val]) => {
115
- if (!/import\(['"][\s\S]*['"]\)/g.test(val)) {
144
+ .map(([, val]) => {
145
+ if (val === undefined) {
146
+ return;
147
+ }
148
+ if (/import\(['"][\s\S]*['"]\)/g.test(val) === false) {
116
149
  return val;
117
150
  }
118
- const [__, importDec] = /import\(['"]([\s\S]*)['"]\)/g.exec(val);
151
+ const res = /import\(['"]([\s\S]*)['"]\)/g.exec(val);
152
+ if (res === null) {
153
+ return;
154
+ }
155
+ const [, importDec] = res;
156
+ if (importDec === undefined) {
157
+ return;
158
+ }
119
159
  const correctedPath = Paths.normalize(normalize(join(relativeDir, importDec)));
120
160
  const rep = val.replace(
121
161
  importDec,
@@ -124,25 +164,32 @@ export class parsedFile {
124
164
  return rep;
125
165
  })
126
166
  .join('\n');
127
- const [[res]] = contents.filter(([_, captured]) => {
128
- if (
129
- !new RegExp(`(?:@typedef|@callback)[\\s\\S]*?${baseNameNoExt}\\s?[\\s\\S]*?`, '').test(
130
- captured
131
- )
132
- ) {
167
+ const [res0] = contents.filter(([_, captured]) => {
168
+ if (captured === undefined) {
133
169
  return false;
134
170
  }
135
- return true;
171
+ return new RegExp(
172
+ `(?:@typedef|@callback)[\\s\\S]*?${baseNameNoExt}\\s?[\\s\\S]*?`,
173
+ ''
174
+ ).test(captured);
136
175
  });
137
- if (!res.length) {
176
+ if (res0 === undefined) {
177
+ return undefined;
178
+ }
179
+ const [res] = res0;
180
+ if (
181
+ //
182
+ !res.length
183
+ ) {
138
184
  return undefined;
139
185
  }
140
186
  const templates = res
141
- .matchAll(/@template\s?{([\s\S]*?)}\s?(\w)*/gm)
187
+ .matchAll(/@template\s?{([\s\S]*?)}\s?(\w+)/gm)
142
188
  .map(([_, type, name]) => {
143
- return { name, comment: ` * @template {${type}} ${name}` };
189
+ return { name, type, comment: ` * @template {${type}} ${name}` };
144
190
  })
145
191
  .toArray();
192
+
146
193
  this.parsedType = {
147
194
  module: `/**-templates-
148
195
  * @typedef {import('./${relativePath}').${exportName}${
@@ -161,7 +208,16 @@ export class parsedFile {
161
208
  templates.length
162
209
  ? '\n' +
163
210
  templates
164
- .map(({ comment }) => {
211
+ .map(({ comment, type }) => {
212
+ const [, matched] = type?.match(/import\(['"]([\s\S]*)['"]\)/) ?? [];
213
+ if (matched && comment) {
214
+ comment = comment.replace(
215
+ matched,
216
+ `.${Paths.normalizesForRoot(
217
+ relative(rootPath, resolve(dirname(this.#fullPath), matched))
218
+ )}`
219
+ );
220
+ }
165
221
  return comment;
166
222
  })
167
223
  .join('\n')
@@ -180,7 +236,7 @@ export class parsedFile {
180
236
  * @param {string} typeOfVar
181
237
  * @param {string} getterOrSetter
182
238
  * @param {string} namedVar
183
- * @returns {refType}
239
+ * @returns {refType|undefined}
184
240
  */
185
241
  #interpreteArrayDesc = (
186
242
  exportName,
@@ -204,7 +260,8 @@ export class parsedFile {
204
260
  let parent = '';
205
261
  if (parentSrc) {
206
262
  TrySync(() => {
207
- parent = parentSrc[0][1];
263
+ const parentSrc_0 = parentSrc[0] ?? [, ''];
264
+ parent = parentSrc_0[1];
208
265
  });
209
266
  }
210
267
  const isExport = isExport_ === 'export';
@@ -242,6 +299,7 @@ export class parsedFile {
242
299
  if (namedVar === 'constructor') {
243
300
  reference = `new ${exportName}`;
244
301
  }
302
+ const parsedFullDescription = this.#parseFullDesc(fullDescription);
245
303
  return {
246
304
  reference: `\`${reference}\``,
247
305
  instanceOrStatic: {
@@ -249,7 +307,7 @@ export class parsedFile {
249
307
  type,
250
308
  },
251
309
  fullDescription,
252
- parsedFullDescription: this.#parseFullDesc(fullDescription),
310
+ parsedFullDescription,
253
311
  isExport,
254
312
  typeOfVar,
255
313
  namedVar,
@@ -261,7 +319,8 @@ export class parsedFile {
261
319
  */
262
320
  #parseFullDesc = (fullDescription) => {
263
321
  const fullDescTrue = fullDescription.split('@');
264
- const description = fullDescTrue[0]
322
+ const fullDescTrue_0 = fullDescTrue[0] ?? '';
323
+ const description = fullDescTrue_0
265
324
  .replace('*', '')
266
325
  .replace(/(?<!\\)\*\s/g, '\n')
267
326
  .trim();
@@ -272,8 +331,15 @@ export class parsedFile {
272
331
  * @${fullDescTrue.join('@').replace(/(?<!\\)\*/g, '\n *')}
273
332
  */\n\`\`\``;
274
333
  const [example_] = jsPreview.matchAll(/@example([\s\S]*)\*\//gm).toArray();
334
+ if (example_ === undefined) {
335
+ return {
336
+ description,
337
+ jsPreview: fullDescTrue.length ? jsPreview : '',
338
+ };
339
+ }
275
340
  TrySync(() => {
276
- example = example_[1].replace(/(?<!\\)\*/g, '').replace(/^\s{2,2}/gm, ' ');
341
+ const example_1 = example_[1] ?? '';
342
+ example = example_1.replace(/(?<!\\)\*/g, '').replace(/^\s{2,2}/gm, ' ');
277
343
  jsPreview = jsPreview.replace(example_[0], '\n */');
278
344
  });
279
345
  return {
@@ -289,7 +355,7 @@ export class parsedFile {
289
355
  };
290
356
  };
291
357
  /**
292
- * @type {{exportName:undefined, details:undefined, error:{fullpath:string, message:string}}
358
+ * @type {undefined|{exportName:undefined, details:undefined, error:{fullpath:string, message:string}}
293
359
  * | {exportName:string|undefined, details:ReturnType<typeof parsedFile["getDescription"]>, error:undefined}
294
360
  * }
295
361
  */
@@ -308,7 +374,7 @@ export class parsedFile {
308
374
  return { exportName: undefined, details: undefined, error };
309
375
  }
310
376
  const supposedName = this.baseName.noExt.split('.')[0];
311
- if (!this.#getTopExport(supposedName, content)) {
377
+ if (supposedName === undefined || this.#getTopExport(supposedName, content) === false) {
312
378
  return {
313
379
  details: undefined,
314
380
  exportName: undefined,
@@ -329,7 +395,7 @@ export class parsedFile {
329
395
  * @returns {boolean}
330
396
  */
331
397
  #getTopExport = (name, content) => {
332
- if (!parsedFile.#isExportNameValid(name)) {
398
+ if (parsedFile.#isExportNameValid(name) === false) {
333
399
  return false;
334
400
  }
335
401
  const regex = new RegExp(
@@ -352,22 +418,22 @@ export class parsedFile {
352
418
  /**
353
419
  * @type {string}
354
420
  */
355
- #fullPath;
421
+ #fullPath = '';
356
422
  /**
357
423
  * @type {string}
358
424
  */
359
- #relativePath;
425
+ #relativePath = '';
360
426
  /**
361
427
  * @returns {Promise<boolean>}
362
428
  */
363
429
  isFile = async () => {
364
- return (await this.stats()).isFile();
430
+ return this.#stats.isFile();
365
431
  };
366
432
  /**
367
433
  * @returns {Promise<boolean>}
368
434
  */
369
435
  isDirectory = async () => {
370
- return (await this.stats()).isDirectory();
436
+ return this.#stats.isDirectory();
371
437
  };
372
438
 
373
439
  baseName = LazyFactory(() => {
@@ -428,40 +494,25 @@ export class parsedFile {
428
494
  * @returns {string|undefined}
429
495
  */
430
496
  get withDot() {
431
- if (this_.isDirectory && !this_.isFile) {
432
- return undefined;
433
- }
434
497
  return extname(this_.#fullPath);
435
498
  },
436
499
  /**
437
500
  * @returns {string|undefined}
438
501
  */
439
502
  get noDot() {
440
- if (this_.isDirectory && !this_.isFile) {
441
- return undefined;
442
- }
443
503
  return extname(this_.#fullPath).replace(/^\./, '');
444
504
  },
445
505
  };
446
506
  }
447
507
  /**
448
- * @type {BufferEncoding}
508
+ * @type {BufferEncoding|undefined}
449
509
  */
450
510
  #encoding;
451
511
  /**
452
512
  * @type {Stats}
453
513
  */
514
+ // @ts-expect-error
454
515
  #stats;
455
- /**
456
- * @private
457
- * @returns {Promise<Stats>}
458
- */
459
- stats = async () => {
460
- if (!this.#stats) {
461
- this.#stats = await stat(this.#fullPath);
462
- }
463
- return this.#stats;
464
- };
465
516
  get timeStamp() {
466
517
  const this_ = this;
467
518
  return {
@@ -469,18 +520,18 @@ export class parsedFile {
469
520
  * @returns {Promise<number>}
470
521
  */
471
522
  lastModified: async () => {
472
- return (await this_.stats()).mtimeMs;
523
+ return this_.#stats.mtimeMs;
473
524
  },
474
525
  /**
475
526
  * @returns {Promise<number>}
476
527
  */
477
528
  createdAt: async () => {
478
- return (await this_.stats()).birthtimeMs;
529
+ return this_.#stats.birthtimeMs;
479
530
  },
480
531
  };
481
532
  }
482
533
  /**
483
- * @type {string}
534
+ * @type {string|undefined}
484
535
  */
485
536
  #rawContent;
486
537
  content = LazyFactory(() => {
@@ -490,15 +541,15 @@ export class parsedFile {
490
541
  * @return {Promise<string|undefined>}
491
542
  */
492
543
  string: async () => {
493
- if (this_.isDirectory && !this_.isFile) {
544
+ if ((await this_.isFile()) === false) {
494
545
  return undefined;
495
546
  }
496
547
  const [raw, error] = await TryAsync(async () => {
497
- return await readFile(this_.#fullPath, this_.#encoding);
548
+ return (await readFile(this_.#fullPath)).toString(this.#encoding);
498
549
  });
499
- if (!error) {
550
+ if (error === undefined) {
500
551
  this_.#rawContent = raw;
501
- return this_.#rawContent.toString();
552
+ return this_.#rawContent;
502
553
  }
503
554
  Console.error({
504
555
  error,
@@ -508,7 +559,7 @@ export class parsedFile {
508
559
  return undefined;
509
560
  },
510
561
  parsed: async () => {
511
- if (!this_.#parsed) {
562
+ if (this_.#parsed === undefined) {
512
563
  this_.#parsed = await this_.#parse();
513
564
  }
514
565
  return this_.#parsed;
@@ -516,23 +567,23 @@ export class parsedFile {
516
567
  };
517
568
  });
518
569
  /**
519
- * @returns {[Promise<any>, undefined]|[undefined, Error]}
570
+ * @returns {ReturnType<typeof TryAsync<any>>}
520
571
  */
521
- get importAsModuleJS() {
572
+ importAsModuleJS = async () => {
522
573
  const realTimePath = `${this.#fullPath}?${Date.now()}`;
523
- let [importedModule, error] = TrySync(async () => {
524
- return import(`file://${realTimePath}`);
574
+ let [importedModule, error] = await TryAsync(async () => {
575
+ return await import(`file://${realTimePath}`);
525
576
  });
526
- if (!error) {
577
+ if (error === undefined) {
527
578
  return [importedModule, undefined];
528
579
  }
529
- [importedModule, error] = TrySync(() => {
530
- return import(realTimePath);
580
+ [importedModule, error] = await TryAsync(async () => {
581
+ return await import(realTimePath);
531
582
  });
532
- if (!error) {
583
+ if (error === undefined) {
533
584
  return [importedModule, undefined];
534
585
  }
535
586
  Console.error({ error, timeStamp: Date.now() });
536
587
  return [undefined, error];
537
- }
588
+ };
538
589
  }
@@ -30,14 +30,15 @@ import { TrySync } from './TrySync.mjs';
30
30
  * })
31
31
  */
32
32
  export function CreateImmutable(parent, keyName, object, { lazy = true } = {}) {
33
- if (!parent || typeof parent !== 'object') {
34
- Console.error({
33
+ if (parent === undefined || typeof parent !== 'object') {
34
+ const error = {
35
35
  object,
36
36
  parent,
37
37
  keyName,
38
38
  message: 'Invalid parent object provided to `CreateImmutable`;',
39
- });
40
- return;
39
+ };
40
+ Console.error(error);
41
+ throw Error(JSON.stringify(error));
41
42
  }
42
43
  let [, error] = TrySync(() => {
43
44
  Object.defineProperty(parent, keyName, {
@@ -49,16 +50,20 @@ export function CreateImmutable(parent, keyName, object, { lazy = true } = {}) {
49
50
  });
50
51
  if (error) {
51
52
  [, error] = TrySync(() => {
53
+ // @ts-expect-error
52
54
  parent[keyName] = lazy ? LazyFactory(() => object.call(parent)) : object.call(parent);
53
55
  });
54
56
  }
55
57
  if (error) {
56
- Console.info({
58
+ const error = {
57
59
  parent,
58
60
  message: `"${keyName}" already defined on the "parent"`,
61
+ // @ts-expect-error
59
62
  realValue: parent[keyName],
60
- });
61
- return;
63
+ };
64
+ Console.warn(error);
65
+ throw new Error(JSON.stringify(error));
62
66
  }
67
+ // @ts-expect-error
63
68
  return parent[keyName];
64
69
  }
@@ -7,7 +7,7 @@
7
7
  /**
8
8
  * @type {Runtime|undefined}
9
9
  */
10
- let runtime = undefined;
10
+ let runtime;
11
11
 
12
12
  /**
13
13
  * @description
@@ -19,7 +19,7 @@ let runtime = undefined;
19
19
  * const runtime = GetRuntime();
20
20
  */
21
21
  export function GetRuntime() {
22
- if (!runtime) {
22
+ if (runtime === undefined) {
23
23
  if (typeof Bun !== 'undefined') {
24
24
  runtime = 'bun';
25
25
  }
@@ -28,7 +28,12 @@ export function GetRuntime() {
28
28
  runtime = 'deno';
29
29
  } else if (typeof process !== 'undefined' && process.versions?.node) {
30
30
  runtime = 'node';
31
- } else if (typeof window !== 'undefined' && typeof document !== 'undefined') {
31
+ } else if (
32
+ // @ts-expect-error
33
+ typeof window !== 'undefined' &&
34
+ // @ts-expect-error
35
+ typeof document !== 'undefined'
36
+ ) {
32
37
  runtime = 'browser';
33
38
  } else {
34
39
  runtime = 'unknown';
@@ -36,6 +36,9 @@ import { unwrapLazy } from '../common/lazie.mjs';
36
36
  * myInstance["vivth:unwrapLazy;"]() // forcefully call the callback;
37
37
  */
38
38
  export function LazyFactory(factory) {
39
+ /**
40
+ * @type {FACTORY|undefined}
41
+ */
39
42
  let instance;
40
43
  // @ts-expect-error
41
44
  return new Proxy(
@@ -43,27 +46,30 @@ export function LazyFactory(factory) {
43
46
  {
44
47
  get(_, prop) {
45
48
  if (prop === unwrapLazy) {
46
- if (!instance) {
49
+ if (instance === undefined) {
47
50
  instance = factory();
48
51
  }
49
52
  return () => instance;
50
53
  }
51
- if (!instance) {
54
+ if (instance === undefined) {
52
55
  instance = factory();
53
56
  }
57
+ // @ts-expect-error
54
58
  return instance[prop];
55
59
  },
56
60
  set(_, prop, newValue) {
57
- if (!instance) {
61
+ if (instance === undefined) {
58
62
  instance = factory();
59
63
  }
64
+ // @ts-expect-error
60
65
  instance[prop] = newValue;
61
66
  return true;
62
67
  },
63
68
  apply(_, thisArg, args) {
64
- if (!instance) {
69
+ if (instance === undefined) {
65
70
  instance = factory();
66
71
  }
72
+ // @ts-expect-error
67
73
  return Reflect.apply(instance, thisArg, args);
68
74
  },
69
75
  }
@@ -19,7 +19,7 @@ import { TryAsync } from './TryAsync.mjs';
19
19
  * @param {RecordTryType} tryRecord
20
20
  * @returns {Promise<
21
21
  * [[keyof RecordTryType, RETURNTYPE], undefined]
22
- * | [[undefined, undefined], Error]
22
+ * | [[undefined, undefined], Error|undefined]
23
23
  * >}
24
24
  * @example
25
25
  * import { Try } from 'vivth';
@@ -53,6 +53,9 @@ import { TryAsync } from './TryAsync.mjs';
53
53
  * });
54
54
  */
55
55
  export async function Try(tryRecord) {
56
+ /**
57
+ * @type {Error|undefined}
58
+ */
56
59
  let prevError = undefined;
57
60
  for (const key in tryRecord) {
58
61
  const callback = tryRecord[key];
@@ -6,7 +6,7 @@
6
6
  * - usefull to flatten indentation for error handlings;
7
7
  * @template RESULT
8
8
  * @param {()=>Promise<RESULT>} asyncFunction_
9
- * @returns {Promise<[RESULT|undefined, Error|undefined]>}
9
+ * @returns {Promise<[RESULT,undefined]|[undefined,Error]>}
10
10
  * @example
11
11
  * import { TryAsync } from 'vivth';
12
12
  *
@@ -26,6 +26,7 @@ export async function TryAsync(asyncFunction_) {
26
26
  const result = await asyncFunction_();
27
27
  return [result, undefined];
28
28
  } catch (error) {
29
+ // @ts-expect-error
29
30
  return [undefined, error];
30
31
  }
31
32
  }
@@ -6,7 +6,8 @@
6
6
  * - usefull to flatten indentation for error handlings;
7
7
  * @template RESULT
8
8
  * @param {()=>RESULT} function_
9
- * @returns {[RESULT|undefined, Error|undefined]}
9
+ * @returns {[RESULT,undefined]|
10
+ * [undefined,Error]}
10
11
  * @example
11
12
  * import { readFileSync } from 'fs';
12
13
  * import { TrySync } from './yourModule.js';
@@ -20,6 +21,7 @@ export function TrySync(function_) {
20
21
  const result = function_();
21
22
  return [result, undefined];
22
23
  } catch (error) {
24
+ // @ts-expect-error
23
25
  return [undefined, error];
24
26
  }
25
27
  }
@@ -30,8 +30,11 @@ import { FileSafe } from '../class/FileSafe.mjs';
30
30
  * TsToMjs('./myFile.mts', { encoding: 'utf-8', overrideDir: './other/dir' });
31
31
  */
32
32
  export async function TsToMjs(path_, { overrideDir = undefined, encoding = 'utf-8' } = {}) {
33
+ if (Paths.root === undefined) {
34
+ return;
35
+ }
33
36
  const rootPath = Paths.normalize(Paths.root);
34
- if (!Paths.normalize(path_).startsWith(rootPath)) {
37
+ if (Paths.normalize(path_).startsWith(rootPath) === false) {
35
38
  path_ = Paths.normalize(join(rootPath, path_));
36
39
  }
37
40
  const ext = extname(path_);
@@ -54,14 +57,14 @@ export async function TsToMjs(path_, { overrideDir = undefined, encoding = 'utf-
54
57
  legalComments: 'inline',
55
58
  });
56
59
  });
57
- if (transformError) {
60
+ if (transformError || result === undefined) {
58
61
  Console.error(transformError);
59
62
  return;
60
63
  }
61
64
  const outputDir = overrideDir ? join(rootPath, overrideDir) : dirname(path_);
62
65
  const outputPath = join(outputDir, basename(path_).replace(ext, '.mjs'));
63
- const [_, writeError] = await FileSafe.write(outputPath, result.code, { encoding });
64
- if (!writeError) {
66
+ const [, writeError] = await FileSafe.write(outputPath, result.code, { encoding });
67
+ if (writeError === undefined) {
65
68
  return;
66
69
  }
67
70
  Console.error(writeError);
@@ -1,4 +1,5 @@
1
1
  // @ts-check
2
+
2
3
  /**
3
4
  * - type helper for ID or objects;
4
5
  * @typedef {{}|null|number|string|boolean|symbol|bigint|function} AnyButUndefined
@@ -0,0 +1,7 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @template {import('./LitExpKeyType.mjs').LitExpKeyType} KEYS
5
+ * @typedef {{result:{whole:string[], named:Array<Record<keyof KEYS, string>>},
6
+ * regexp: RegExp}} LitExpResultType
7
+ */
@@ -1,4 +1,4 @@
1
- // @ts-expect-error
1
+ // @ts-check
2
2
 
3
3
  /**
4
4
  * @description