@e-mc/module 0.9.17 → 0.9.19

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 (4) hide show
  1. package/LICENSE +4 -8
  2. package/README.md +6 -6
  3. package/index.js +38 -50
  4. package/package.json +3 -3
package/LICENSE CHANGED
@@ -1,11 +1,7 @@
1
- Copyright 2024 An Pham
1
+ Copyright 2025 An Pham
2
2
 
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
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
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
6
 
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
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.17/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.19/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.17/lib/core.d.ts
398
- - https://www.unpkg.com/@e-mc/types@0.9.17/lib/logger.d.ts
399
- - https://www.unpkg.com/@e-mc/types@0.9.17/lib/module.d.ts
400
- - https://www.unpkg.com/@e-mc/types@0.9.17/lib/node.d.ts
401
- - https://www.unpkg.com/@e-mc/types@0.9.17/lib/settings.d.ts
397
+ - https://www.unpkg.com/@e-mc/types@0.9.19/lib/core.d.ts
398
+ - https://www.unpkg.com/@e-mc/types@0.9.19/lib/logger.d.ts
399
+ - https://www.unpkg.com/@e-mc/types@0.9.19/lib/module.d.ts
400
+ - https://www.unpkg.com/@e-mc/types@0.9.19/lib/node.d.ts
401
+ - https://www.unpkg.com/@e-mc/types@0.9.19/lib/settings.d.ts
402
402
 
403
403
  * https://www.npmjs.com/package/@types/node
404
404
 
package/index.js CHANGED
@@ -703,8 +703,9 @@ function formatPercent(value, precision) {
703
703
  value *= 100;
704
704
  return value.toPrecision(value < 1 ? 2 : precision) + '%';
705
705
  }
706
+ const isErrorNo = (value) => value instanceof Error && (0, types_1.isString)(value.code);
706
707
  const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
707
- const asFile = (value) => typeof value === 'string' ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
708
+ const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
708
709
  const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
709
710
  const isFunction = (value) => typeof value === 'function';
710
711
  const isFileURL = (value) => /^file:\/\//i.test(value);
@@ -740,7 +741,7 @@ class Module extends EventEmitter {
740
741
  this[_f] = new AbortController();
741
742
  this[_g] = null;
742
743
  }
743
- static get VERSION() { return "0.9.17"; }
744
+ static get VERSION() { return "0.9.19"; }
744
745
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
745
746
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
746
747
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -826,7 +827,7 @@ class Module extends EventEmitter {
826
827
  if (error && hideAbort(message)) {
827
828
  return;
828
829
  }
829
- if (options.type) {
830
+ if (typeof options.type === 'number') {
830
831
  type |= options.type;
831
832
  }
832
833
  const BROADCAST_OUT = VALUES["broadcast.out"];
@@ -1332,7 +1333,7 @@ class Module extends EventEmitter {
1332
1333
  filename = undefined;
1333
1334
  }
1334
1335
  if (typeof value === 'string') {
1335
- let pathname = value.trim(), convert = true;
1336
+ let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
1336
1337
  if (normalize) {
1337
1338
  pathname = path.normalize(pathname);
1338
1339
  convert = PLATFORM_WIN32;
@@ -1436,14 +1437,10 @@ class Module extends EventEmitter {
1436
1437
  }
1437
1438
  }
1438
1439
  static isErrorCode(err, ...code) {
1439
- if (err instanceof Error) {
1440
- const value = err.code;
1441
- return typeof value === 'string' && code.includes(value);
1442
- }
1443
- return false;
1440
+ return isErrorNo(err) && code.includes(err.code);
1444
1441
  }
1445
1442
  static resolveFile(value) {
1446
- if (isFileURL(value = value instanceof URL ? value.toString() : value.trim())) {
1443
+ if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
1447
1444
  try {
1448
1445
  return url.fileURLToPath(value);
1449
1446
  }
@@ -1458,7 +1455,7 @@ class Module extends EventEmitter {
1458
1455
  }
1459
1456
  static resolvePath(value, base) {
1460
1457
  try {
1461
- if (this.isURL(value = value.trim())) {
1458
+ if (this.isURL(value)) {
1462
1459
  return isFileURL(value) ? url.fileURLToPath(value) : new URL(value).href;
1463
1460
  }
1464
1461
  if (base instanceof URL || this.isURL(base)) {
@@ -1490,7 +1487,7 @@ class Module extends EventEmitter {
1490
1487
  if (typeof flags === 'boolean') {
1491
1488
  flags = flags ? 2 : 0;
1492
1489
  }
1493
- let result = value.trim();
1490
+ let result = PLATFORM_WIN32 ? value.trim() : value;
1494
1491
  result = flags & 1 ? path.resolve(result) : path.normalize(result);
1495
1492
  if ((flags & 3) && result.length) {
1496
1493
  result = ensureDir(result);
@@ -3276,9 +3273,6 @@ class Module extends EventEmitter {
3276
3273
  else if (result === false) {
3277
3274
  return;
3278
3275
  }
3279
- if (options.passThrough) {
3280
- message = null;
3281
- }
3282
3276
  const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
3283
3277
  applyLogId.call(this, options);
3284
3278
  if (options.queue !== false && !options.passThrough && !this._logFlushed) {
@@ -3408,11 +3402,11 @@ class Module extends EventEmitter {
3408
3402
  options = value;
3409
3403
  value = undefined;
3410
3404
  }
3411
- if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND && name) {
3405
+ if (name && isErrorNo(err) && err.code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
3412
3406
  if (typeof options === 'number') {
3413
3407
  options = undefined;
3414
3408
  }
3415
- this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: 'npm', args: ['i', name] } });
3409
+ this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command: 'npm', args: ['i', name] } });
3416
3410
  return true;
3417
3411
  }
3418
3412
  if (value) {
@@ -3421,47 +3415,41 @@ class Module extends EventEmitter {
3421
3415
  return false;
3422
3416
  }
3423
3417
  checkFail(message, options) {
3424
- const code = options.code;
3425
- if (code && message instanceof Error) {
3426
- const valid = message.code === code;
3427
- switch (code) {
3428
- case types_1.ERR_CODE.MODULE_NOT_FOUND: {
3429
- const exec = options.exec;
3430
- if (exec) {
3431
- if (valid && !this.aborted) {
3432
- const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3433
- const target = this.host || this;
3434
- let session = CACHE_EXEC.get(target);
3435
- if (!session) {
3436
- CACHE_EXEC.set(target, session = []);
3437
- }
3438
- if (session.includes(command)) {
3439
- return false;
3440
- }
3441
- session.push(command);
3442
- let type = options.type || 0;
3443
- type |= 4096;
3444
- type &= ~1;
3445
- if (options.passThrough) {
3446
- options.passThrough = false;
3447
- message = null;
3448
- }
3449
- return { type, value: ["Install required?", command], message };
3450
- }
3451
- delete options.exec;
3452
- }
3453
- break;
3418
+ let { code, exec } = options;
3419
+ if (!code && isErrorNo(message)) {
3420
+ code = message.code;
3421
+ }
3422
+ if (exec && code?.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
3423
+ if (!this.aborted) {
3424
+ const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3425
+ const target = this.host || this;
3426
+ let session = CACHE_EXEC.get(target);
3427
+ if (!session) {
3428
+ CACHE_EXEC.set(target, session = []);
3429
+ }
3430
+ if (session.includes(command)) {
3431
+ return false;
3432
+ }
3433
+ session.push(command);
3434
+ let type = options.type || 0;
3435
+ type |= 4096;
3436
+ type &= ~1;
3437
+ if (options.passThrough) {
3438
+ options.passThrough = false;
3439
+ message = null;
3454
3440
  }
3441
+ return { type, value: ["Install required?", command], message };
3455
3442
  }
3443
+ delete options.exec;
3456
3444
  }
3457
3445
  }
3458
3446
  writeLog(type, value, timeStamp, duration) {
3459
- let queue;
3447
+ let queue = false;
3460
3448
  if ((0, types_1.isObject)(type)) {
3461
3449
  if (typeof value === 'boolean') {
3462
3450
  queue = value;
3463
3451
  }
3464
- ({ type = types_1.STATUS_TYPE.UNKNOWN, value, timeStamp, duration } = type);
3452
+ value = type.value;
3465
3453
  }
3466
3454
  const output = Module.asString(value);
3467
3455
  if (output) {
@@ -3489,7 +3477,7 @@ class Module extends EventEmitter {
3489
3477
  from = timeStamp;
3490
3478
  timeStamp = 0;
3491
3479
  }
3492
- else if ((0, types_1.isObject)(timeStamp)) {
3480
+ else if ((0, types_1.isPlainObject)(timeStamp)) {
3493
3481
  ({ timeStamp, duration, from, source } = timeStamp);
3494
3482
  }
3495
3483
  const name = types_1.STATUS_TYPE[type] || types_1.STATUS_TYPE[type = 0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.9.17",
3
+ "version": "0.9.19",
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": "BSD-3-Clause",
20
+ "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.9.17",
23
+ "@e-mc/types": "0.9.19",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "16.5.4",
26
26
  "js-yaml": "^4.1.0",