@e-mc/module 0.10.10 → 0.10.12

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 (3) hide show
  1. package/README.md +6 -6
  2. package/index.js +52 -51
  3. package/package.json +2 -2
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.10.10/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.10.12/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -407,11 +407,11 @@ interface LoggerModule {
407
407
 
408
408
  ## References
409
409
 
410
- - https://www.unpkg.com/@e-mc/types@0.10.10/lib/core.d.ts
411
- - https://www.unpkg.com/@e-mc/types@0.10.10/lib/logger.d.ts
412
- - https://www.unpkg.com/@e-mc/types@0.10.10/lib/module.d.ts
413
- - https://www.unpkg.com/@e-mc/types@0.10.10/lib/node.d.ts
414
- - https://www.unpkg.com/@e-mc/types@0.10.10/lib/settings.d.ts
410
+ - https://www.unpkg.com/@e-mc/types@0.10.12/lib/core.d.ts
411
+ - https://www.unpkg.com/@e-mc/types@0.10.12/lib/logger.d.ts
412
+ - https://www.unpkg.com/@e-mc/types@0.10.12/lib/module.d.ts
413
+ - https://www.unpkg.com/@e-mc/types@0.10.12/lib/node.d.ts
414
+ - https://www.unpkg.com/@e-mc/types@0.10.12/lib/settings.d.ts
415
415
 
416
416
  * https://www.npmjs.com/package/@types/node
417
417
 
package/index.js CHANGED
@@ -627,7 +627,7 @@ function getCacheTotal() {
627
627
  return CACHE_READTEXT.size + CACHE_READBUFFER.size + CACHE_READCJS.size;
628
628
  }
629
629
  function isMatch(key, value) {
630
- return pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') });
630
+ return pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') && !value.includes('/') });
631
631
  }
632
632
  function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
633
633
  const srcDir = path.join(src, ...paths);
@@ -917,6 +917,7 @@ function truncateStart(value, length = LOG_MIN_WIDTH, style = false) {
917
917
  function truncateEnd(value, length) {
918
918
  return (REGEXP_ANSIESCAPE.test(value) ? stripansi(value) : value).length > length ? '...' + value.substring(value.length - length + 3) : value;
919
919
  }
920
+ const isErrorNo = (value) => value instanceof Error && (0, types_1.isString)(value.code);
920
921
  const formatLogMessage = (type, message, unit, ident) => !ident && (type & 256) ? (unit + LOG_DIVIDER + message).trimEnd() : unit ? (type & 256) && ident ? unit + LOG_DIVIDER + message : (message + (ident ? '' : ' ') + unit).trimStart() : message;
921
922
  const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
922
923
  const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? (0, url_1.fileURLToPath)(value) : '';
@@ -959,7 +960,7 @@ class Module extends EventEmitter {
959
960
  this[_g] = null;
960
961
  }
961
962
  static get VERSION() {
962
- return "0.10.10";
963
+ return "0.10.12";
963
964
  }
964
965
  static get LOG_TYPE() {
965
966
  return types_1.LOG_TYPE;
@@ -1532,22 +1533,28 @@ class Module extends EventEmitter {
1532
1533
  filename = undefined;
1533
1534
  }
1534
1535
  if (typeof value === 'string') {
1535
- let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
1536
+ let pathname = PLATFORM_WIN32 ? value.trim() : value;
1536
1537
  if (normalize) {
1537
1538
  pathname = path.normalize(pathname);
1538
- convert = PLATFORM_WIN32;
1539
1539
  }
1540
- if (convert) {
1540
+ if (PLATFORM_WIN32) {
1541
1541
  pathname = pathname.replace(/(?:^\\|\\+)/g, '/');
1542
1542
  }
1543
- if (pathname = pathname.replace(/\/+$/, '')) {
1543
+ if (pathname) {
1544
+ pathname = pathname.replace(/(?<!^)\/+$/, '');
1544
1545
  if (normalize && PLATFORM_WIN32) {
1545
1546
  const match = /^([A-Z]):\//.exec(pathname);
1546
1547
  if (match) {
1547
1548
  pathname = match[1].toLowerCase() + pathname.substring(1);
1548
1549
  }
1549
1550
  }
1550
- return pathname + (filename ? '/' + filename : '');
1551
+ if (!filename) {
1552
+ return pathname;
1553
+ }
1554
+ if (pathname !== '/') {
1555
+ pathname += '/';
1556
+ }
1557
+ return pathname + filename;
1551
1558
  }
1552
1559
  }
1553
1560
  return filename || '';
@@ -1640,11 +1647,7 @@ class Module extends EventEmitter {
1640
1647
  }
1641
1648
  }
1642
1649
  static isErrorCode(err, ...code) {
1643
- if (err instanceof Error) {
1644
- const value = err.code;
1645
- return typeof value === 'string' && code.includes(value);
1646
- }
1647
- return false;
1650
+ return isErrorNo(err) && code.includes(err.code);
1648
1651
  }
1649
1652
  static resolveFile(value) {
1650
1653
  if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
@@ -1925,7 +1928,7 @@ class Module extends EventEmitter {
1925
1928
  if (!(outDir && this.isDir(outDir))) {
1926
1929
  return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1927
1930
  }
1928
- const pmOpts = { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32 };
1931
+ const pmOpts = PLATFORM_WIN32 ? { nocase: true, windows: true, posixSlashes: true } : {};
1929
1932
  let exclude, excludeDir, recursive;
1930
1933
  if ((0, types_1.isObject)(options)) {
1931
1934
  if (options.matchBase) {
@@ -1942,8 +1945,9 @@ class Module extends EventEmitter {
1942
1945
  const items = Array.isArray(exclude) ? exclude : [exclude];
1943
1946
  exclude = [];
1944
1947
  for (const value of items) {
1945
- if (/^[^\\/][^*]+[\\/]$/.test(value) && !(0, types_1.hasGlob)(value)) {
1946
- (excludeDir ||= []).push(this.normalizePath(value, 4));
1948
+ const dirEnd = value.endsWith('/') ? /^[^/][^*]+\/$/ : value.endsWith('\\') ? /^[^\\][^*]+\\$/ : null;
1949
+ if (dirEnd?.test(value) && !(0, types_1.hasGlob)(value)) {
1950
+ (excludeDir ||= []).push(this.toPosix(value, true));
1947
1951
  }
1948
1952
  else {
1949
1953
  exclude.push(value);
@@ -3475,10 +3479,13 @@ class Module extends EventEmitter {
3475
3479
  else if (result === false) {
3476
3480
  return;
3477
3481
  }
3478
- if (options.passThrough) {
3479
- message = null;
3480
- }
3481
- const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
3482
+ const args = [
3483
+ (type | 512),
3484
+ title,
3485
+ value,
3486
+ message,
3487
+ applyStyle(options, Module.LOG_STYLE_FAIL)
3488
+ ];
3482
3489
  applySessionId(this, options);
3483
3490
  if (options.queue !== false && !options.passThrough && !this._logFlushed) {
3484
3491
  if (VALUES["error.out"]) {
@@ -3607,11 +3614,11 @@ class Module extends EventEmitter {
3607
3614
  options = value;
3608
3615
  value = undefined;
3609
3616
  }
3610
- if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND && name) {
3617
+ if (name && isErrorNo(err) && err.code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
3611
3618
  if (typeof options === 'number') {
3612
3619
  options = undefined;
3613
3620
  }
3614
- 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] } });
3621
+ this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command: 'npm', args: ['i', name] } });
3615
3622
  return true;
3616
3623
  }
3617
3624
  if (value) {
@@ -3620,38 +3627,32 @@ class Module extends EventEmitter {
3620
3627
  return false;
3621
3628
  }
3622
3629
  checkFail(message, options) {
3623
- const code = options.code;
3624
- if (code && message instanceof Error) {
3625
- const valid = message.code === code;
3626
- switch (code) {
3627
- case types_1.ERR_CODE.MODULE_NOT_FOUND: {
3628
- const exec = options.exec;
3629
- if (exec) {
3630
- if (valid && !this.aborted) {
3631
- const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3632
- const target = this.host || this;
3633
- let session = CACHE_EXEC.get(target);
3634
- if (!session) {
3635
- CACHE_EXEC.set(target, session = []);
3636
- }
3637
- if (session.includes(command)) {
3638
- return false;
3639
- }
3640
- session.push(command);
3641
- let type = options.type || 0;
3642
- type |= 4096;
3643
- type &= ~1;
3644
- if (options.passThrough) {
3645
- options.passThrough = false;
3646
- message = null;
3647
- }
3648
- return { type, value: ["Install required?", command], message };
3649
- }
3650
- delete options.exec;
3651
- }
3652
- break;
3630
+ let { code, exec } = options;
3631
+ if (!code && isErrorNo(message)) {
3632
+ code = message.code;
3633
+ }
3634
+ if (exec && code?.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
3635
+ if (!this.aborted) {
3636
+ const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3637
+ const target = this.host || this;
3638
+ let session = CACHE_EXEC.get(target);
3639
+ if (!session) {
3640
+ CACHE_EXEC.set(target, session = []);
3641
+ }
3642
+ if (session.includes(command)) {
3643
+ return false;
3644
+ }
3645
+ session.push(command);
3646
+ let type = options.type || 0;
3647
+ type |= 4096;
3648
+ type &= ~1;
3649
+ if (options.passThrough) {
3650
+ options.passThrough = false;
3651
+ message = null;
3653
3652
  }
3653
+ return { type, value: ["Install required?", command], message };
3654
3654
  }
3655
+ delete options.exec;
3655
3656
  }
3656
3657
  }
3657
3658
  writeLog(type, value, timeStamp, duration) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.10.10",
3
+ "version": "0.10.12",
4
4
  "description": "Module base class for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "license": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.10.10",
23
+ "@e-mc/types": "0.10.12",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "^18.7.0",
26
26
  "js-yaml": "^4.1.0",