@e-mc/module 0.9.18 → 0.9.20
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/LICENSE +4 -8
- package/README.md +6 -6
- package/index.js +45 -48
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2025 An Pham
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.20/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -394,11 +394,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
|
|
|
394
394
|
|
|
395
395
|
## References
|
|
396
396
|
|
|
397
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
398
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
399
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
400
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
401
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
397
|
+
- https://www.unpkg.com/@e-mc/types@0.9.20/lib/core.d.ts
|
|
398
|
+
- https://www.unpkg.com/@e-mc/types@0.9.20/lib/logger.d.ts
|
|
399
|
+
- https://www.unpkg.com/@e-mc/types@0.9.20/lib/module.d.ts
|
|
400
|
+
- https://www.unpkg.com/@e-mc/types@0.9.20/lib/node.d.ts
|
|
401
|
+
- https://www.unpkg.com/@e-mc/types@0.9.20/lib/settings.d.ts
|
|
402
402
|
|
|
403
403
|
* https://www.npmjs.com/package/@types/node
|
|
404
404
|
|
package/index.js
CHANGED
|
@@ -535,7 +535,7 @@ function addCacheItem(map, key, data, cache) {
|
|
|
535
535
|
key = Module.toPosix(key, true);
|
|
536
536
|
if (!cache) {
|
|
537
537
|
if (MEMORY_CACHE_DISK.include) {
|
|
538
|
-
if (!MEMORY_CACHE_DISK.include.some(value =>
|
|
538
|
+
if (!MEMORY_CACHE_DISK.include.some(value => isMatch(key, value))) {
|
|
539
539
|
return;
|
|
540
540
|
}
|
|
541
541
|
}
|
|
@@ -543,13 +543,16 @@ function addCacheItem(map, key, data, cache) {
|
|
|
543
543
|
cache = true;
|
|
544
544
|
}
|
|
545
545
|
}
|
|
546
|
-
if (!(cache && MEMORY_CACHE_DISK.exclude?.some(value =>
|
|
546
|
+
if (!(cache && MEMORY_CACHE_DISK.exclude?.some(value => isMatch(key, value)))) {
|
|
547
547
|
if (!map.has(key)) {
|
|
548
548
|
++CACHE_TOTAL;
|
|
549
549
|
}
|
|
550
550
|
map.set(key, [Date.now(), data]);
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
|
+
function isMatch(key, value) {
|
|
554
|
+
return pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') && !value.includes('/') });
|
|
555
|
+
}
|
|
553
556
|
function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
|
|
554
557
|
const srcDir = path.join(src, ...paths);
|
|
555
558
|
fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
|
|
@@ -703,6 +706,7 @@ function formatPercent(value, precision) {
|
|
|
703
706
|
value *= 100;
|
|
704
707
|
return value.toPrecision(value < 1 ? 2 : precision) + '%';
|
|
705
708
|
}
|
|
709
|
+
const isErrorNo = (value) => value instanceof Error && (0, types_1.isString)(value.code);
|
|
706
710
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
707
711
|
const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
708
712
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
@@ -740,7 +744,7 @@ class Module extends EventEmitter {
|
|
|
740
744
|
this[_f] = new AbortController();
|
|
741
745
|
this[_g] = null;
|
|
742
746
|
}
|
|
743
|
-
static get VERSION() { return "0.9.
|
|
747
|
+
static get VERSION() { return "0.9.20"; }
|
|
744
748
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
745
749
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
746
750
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -1332,22 +1336,28 @@ class Module extends EventEmitter {
|
|
|
1332
1336
|
filename = undefined;
|
|
1333
1337
|
}
|
|
1334
1338
|
if (typeof value === 'string') {
|
|
1335
|
-
let pathname = PLATFORM_WIN32 ? value.trim() : value
|
|
1339
|
+
let pathname = PLATFORM_WIN32 ? value.trim() : value;
|
|
1336
1340
|
if (normalize) {
|
|
1337
1341
|
pathname = path.normalize(pathname);
|
|
1338
|
-
convert = PLATFORM_WIN32;
|
|
1339
1342
|
}
|
|
1340
|
-
if (
|
|
1343
|
+
if (PLATFORM_WIN32) {
|
|
1341
1344
|
pathname = pathname.replace(/(?:^\\|\\+)/g, '/');
|
|
1342
1345
|
}
|
|
1343
|
-
if (pathname
|
|
1346
|
+
if (pathname) {
|
|
1347
|
+
pathname = pathname.replace(/(?<!^)\/+$/, '');
|
|
1344
1348
|
if (normalize && PLATFORM_WIN32) {
|
|
1345
1349
|
const match = /^([A-Z]):\//.exec(pathname);
|
|
1346
1350
|
if (match) {
|
|
1347
1351
|
pathname = match[1].toLowerCase() + pathname.substring(1);
|
|
1348
1352
|
}
|
|
1349
1353
|
}
|
|
1350
|
-
|
|
1354
|
+
if (!filename) {
|
|
1355
|
+
return pathname;
|
|
1356
|
+
}
|
|
1357
|
+
if (pathname !== '/') {
|
|
1358
|
+
pathname += '/';
|
|
1359
|
+
}
|
|
1360
|
+
return pathname + filename;
|
|
1351
1361
|
}
|
|
1352
1362
|
}
|
|
1353
1363
|
return filename || '';
|
|
@@ -1436,11 +1446,7 @@ class Module extends EventEmitter {
|
|
|
1436
1446
|
}
|
|
1437
1447
|
}
|
|
1438
1448
|
static isErrorCode(err, ...code) {
|
|
1439
|
-
|
|
1440
|
-
const value = err.code;
|
|
1441
|
-
return typeof value === 'string' && code.includes(value);
|
|
1442
|
-
}
|
|
1443
|
-
return false;
|
|
1449
|
+
return isErrorNo(err) && code.includes(err.code);
|
|
1444
1450
|
}
|
|
1445
1451
|
static resolveFile(value) {
|
|
1446
1452
|
if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
|
|
@@ -3276,9 +3282,6 @@ class Module extends EventEmitter {
|
|
|
3276
3282
|
else if (result === false) {
|
|
3277
3283
|
return;
|
|
3278
3284
|
}
|
|
3279
|
-
if (options.passThrough) {
|
|
3280
|
-
message = null;
|
|
3281
|
-
}
|
|
3282
3285
|
const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
|
|
3283
3286
|
applyLogId.call(this, options);
|
|
3284
3287
|
if (options.queue !== false && !options.passThrough && !this._logFlushed) {
|
|
@@ -3408,11 +3411,11 @@ class Module extends EventEmitter {
|
|
|
3408
3411
|
options = value;
|
|
3409
3412
|
value = undefined;
|
|
3410
3413
|
}
|
|
3411
|
-
if (
|
|
3414
|
+
if (name && isErrorNo(err) && err.code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
|
|
3412
3415
|
if (typeof options === 'number') {
|
|
3413
3416
|
options = undefined;
|
|
3414
3417
|
}
|
|
3415
|
-
this.writeFail("
|
|
3418
|
+
this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command: 'npm', args: ['i', name] } });
|
|
3416
3419
|
return true;
|
|
3417
3420
|
}
|
|
3418
3421
|
if (value) {
|
|
@@ -3421,38 +3424,32 @@ class Module extends EventEmitter {
|
|
|
3421
3424
|
return false;
|
|
3422
3425
|
}
|
|
3423
3426
|
checkFail(message, options) {
|
|
3424
|
-
|
|
3425
|
-
if (code && message
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
options.passThrough = false;
|
|
3447
|
-
message = null;
|
|
3448
|
-
}
|
|
3449
|
-
return { type, value: ["Install required?", command], message };
|
|
3450
|
-
}
|
|
3451
|
-
delete options.exec;
|
|
3452
|
-
}
|
|
3453
|
-
break;
|
|
3427
|
+
let { code, exec } = options;
|
|
3428
|
+
if (!code && isErrorNo(message)) {
|
|
3429
|
+
code = message.code;
|
|
3430
|
+
}
|
|
3431
|
+
if (exec && code?.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
|
|
3432
|
+
if (!this.aborted) {
|
|
3433
|
+
const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
|
|
3434
|
+
const target = this.host || this;
|
|
3435
|
+
let session = CACHE_EXEC.get(target);
|
|
3436
|
+
if (!session) {
|
|
3437
|
+
CACHE_EXEC.set(target, session = []);
|
|
3438
|
+
}
|
|
3439
|
+
if (session.includes(command)) {
|
|
3440
|
+
return false;
|
|
3441
|
+
}
|
|
3442
|
+
session.push(command);
|
|
3443
|
+
let type = options.type || 0;
|
|
3444
|
+
type |= 4096;
|
|
3445
|
+
type &= ~1;
|
|
3446
|
+
if (options.passThrough) {
|
|
3447
|
+
options.passThrough = false;
|
|
3448
|
+
message = null;
|
|
3454
3449
|
}
|
|
3450
|
+
return { type, value: ["Install required?", command], message };
|
|
3455
3451
|
}
|
|
3452
|
+
delete options.exec;
|
|
3456
3453
|
}
|
|
3457
3454
|
}
|
|
3458
3455
|
writeLog(type, value, timeStamp, duration) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.20",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.9.
|
|
23
|
+
"@e-mc/types": "0.9.20",
|
|
24
24
|
"chalk": "4.1.2",
|
|
25
25
|
"file-type": "16.5.4",
|
|
26
26
|
"js-yaml": "^4.1.0",
|