vivth 1.2.3 → 1.3.1
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 +609 -586
- package/README.src.md +5 -1
- package/bun.lock +6 -0
- package/index.mjs +10 -6
- package/package.json +3 -1
- package/src/bundler/CompileJS.mjs +11 -8
- package/src/bundler/EsBundler.mjs +4 -2
- package/src/bundler/FSInline.mjs +3 -0
- package/src/bundler/FSInlineAnalyzer.mjs +31 -7
- package/src/bundler/FSInlineBundled.mjs +5 -1
- package/src/bundler/adds/ToBundledJSPlugin.mjs +3 -4
- package/src/class/Console.mjs +12 -4
- package/src/class/Derived.mjs +5 -1
- package/src/class/Effect.mjs +6 -6
- package/src/class/EnvSignal.mjs +1 -8
- package/src/class/EventSignal.mjs +8 -7
- package/src/class/FileSafe.mjs +1 -1
- package/src/class/ListSignal.mjs +18 -10
- package/src/class/LitExp.mjs +241 -204
- package/src/class/Paths.mjs +10 -8
- package/src/class/QChannel.mjs +14 -7
- package/src/class/SafeExit.mjs +16 -7
- package/src/class/Signal.mjs +8 -7
- package/src/class/WorkerMainThread.mjs +45 -24
- package/src/class/WorkerMainThreadBundled.mjs +42 -24
- package/src/class/WorkerThread.mjs +21 -7
- package/src/common/Base64URL.mjs +2 -2
- package/src/common/Base64URLFromFile.mjs +1 -1
- package/src/doc/JSautoDOC.mjs +101 -62
- package/src/doc/correctBeforeParse.mjs +139 -0
- package/src/doc/parsedFile.mjs +127 -76
- package/src/function/CreateImmutable.mjs +12 -7
- package/src/function/GetRuntime.mjs +8 -3
- package/src/function/LazyFactory.mjs +10 -4
- package/src/function/Try.mjs +4 -1
- package/src/function/TryAsync.mjs +2 -1
- package/src/function/TrySync.mjs +3 -1
- package/src/function/TsToMjs.mjs +7 -4
- package/src/types/AnyButUndefined.mjs +1 -0
- package/src/types/LitExpResultType.mjs +7 -0
- package/src/types/Runtime.mjs +1 -1
- package/tsconfig.json +27 -5
- package/types/dev/workerThreadClass.d.mts +1 -1
- package/types/index.d.mts +7 -6
- package/types/src/bundler/CompileJS.d.mts +14 -9
- package/types/src/bundler/EsBundler.d.mts +1 -1
- package/types/src/class/Derived.d.mts +4 -64
- package/types/src/class/Effect.d.mts +8 -8
- package/types/src/class/EnvSignal.d.mts +0 -1
- package/types/src/class/EventSignal.d.mts +5 -5
- package/types/src/class/FileSafe.d.mts +2 -2
- package/types/src/class/ListSignal.d.mts +1 -1
- package/types/src/class/LitExp.d.mts +49 -53
- package/types/src/class/Paths.d.mts +4 -4
- package/types/src/class/QChannel.d.mts +1 -1
- package/types/src/class/SafeExit.d.mts +3 -3
- package/types/src/class/Signal.d.mts +3 -3
- package/types/src/class/WorkerMainThread.d.mts +13 -8
- package/types/src/class/WorkerMainThreadBundled.d.mts +13 -8
- package/types/src/class/WorkerThread.d.mts +4 -4
- package/types/src/common/Base64URL.d.mts +2 -2
- package/types/src/common/Base64URLFromFile.d.mts +2 -2
- package/types/src/doc/JSautoDOC.d.mts +34 -12
- package/types/src/doc/correctBeforeParse.d.mts +2 -0
- package/types/src/doc/parsedFile.d.mts +7 -10
- package/types/src/function/CreateImmutable.d.mts +2 -2
- package/types/src/function/Try.d.mts +2 -2
- package/types/src/function/TryAsync.d.mts +2 -2
- package/types/src/function/TrySync.d.mts +3 -2
- package/types/src/function/TsToMjs.d.mts +2 -2
- package/types/src/types/LitExpResultType.d.mts +7 -0
package/src/doc/parsedFile.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import { readFile
|
|
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
|
-
] =
|
|
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 (
|
|
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
|
|
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
|
-
|
|
135
|
+
const rootPath = Paths.root;
|
|
136
|
+
if (rootPath === undefined || parsedFile.#isExportNameValid(exportName) === false) {
|
|
107
137
|
return undefined;
|
|
108
138
|
}
|
|
109
|
-
if (
|
|
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(([
|
|
115
|
-
if (
|
|
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
|
|
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 [
|
|
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
|
|
171
|
+
return new RegExp(
|
|
172
|
+
`(?:@typedef|@callback)[\\s\\S]*?${baseNameNoExt}\\s?[\\s\\S]*?`,
|
|
173
|
+
''
|
|
174
|
+
).test(captured);
|
|
136
175
|
});
|
|
137
|
-
if (
|
|
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)
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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 (
|
|
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 (
|
|
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
|
|
430
|
+
return this.#stats.isFile();
|
|
365
431
|
};
|
|
366
432
|
/**
|
|
367
433
|
* @returns {Promise<boolean>}
|
|
368
434
|
*/
|
|
369
435
|
isDirectory = async () => {
|
|
370
|
-
return
|
|
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
|
|
523
|
+
return this_.#stats.mtimeMs;
|
|
473
524
|
},
|
|
474
525
|
/**
|
|
475
526
|
* @returns {Promise<number>}
|
|
476
527
|
*/
|
|
477
528
|
createdAt: async () => {
|
|
478
|
-
return
|
|
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 (
|
|
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
|
|
548
|
+
return (await readFile(this_.#fullPath)).toString(this.#encoding);
|
|
498
549
|
});
|
|
499
|
-
if (
|
|
550
|
+
if (error === undefined) {
|
|
500
551
|
this_.#rawContent = raw;
|
|
501
|
-
return this_.#rawContent
|
|
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 (
|
|
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 {
|
|
570
|
+
* @returns {ReturnType<typeof TryAsync<any>>}
|
|
520
571
|
*/
|
|
521
|
-
|
|
572
|
+
importAsModuleJS = async () => {
|
|
522
573
|
const realTimePath = `${this.#fullPath}?${Date.now()}`;
|
|
523
|
-
let [importedModule, error] =
|
|
524
|
-
return import(`file://${realTimePath}`);
|
|
574
|
+
let [importedModule, error] = await TryAsync(async () => {
|
|
575
|
+
return await import(`file://${realTimePath}`);
|
|
525
576
|
});
|
|
526
|
-
if (
|
|
577
|
+
if (error === undefined) {
|
|
527
578
|
return [importedModule, undefined];
|
|
528
579
|
}
|
|
529
|
-
[importedModule, error] =
|
|
530
|
-
return import(realTimePath);
|
|
580
|
+
[importedModule, error] = await TryAsync(async () => {
|
|
581
|
+
return await import(realTimePath);
|
|
531
582
|
});
|
|
532
|
-
if (
|
|
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 (
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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 (
|
|
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 (
|
|
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 (
|
|
49
|
+
if (instance === undefined) {
|
|
47
50
|
instance = factory();
|
|
48
51
|
}
|
|
49
52
|
return () => instance;
|
|
50
53
|
}
|
|
51
|
-
if (
|
|
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 (
|
|
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 (
|
|
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
|
}
|
package/src/function/Try.mjs
CHANGED
|
@@ -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,
|
|
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
|
}
|
package/src/function/TrySync.mjs
CHANGED
|
@@ -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
|
|
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
|
}
|
package/src/function/TsToMjs.mjs
CHANGED
|
@@ -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 (
|
|
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 [
|
|
64
|
-
if (
|
|
66
|
+
const [, writeError] = await FileSafe.write(outputPath, result.code, { encoding });
|
|
67
|
+
if (writeError === undefined) {
|
|
65
68
|
return;
|
|
66
69
|
}
|
|
67
70
|
Console.error(writeError);
|
package/src/types/Runtime.mjs
CHANGED