@e-mc/module 0.8.12 → 0.8.14

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 +5 -5
  2. package/index.js +46 -13
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.12/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.14/lib/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -232,10 +232,10 @@ interface ModuleConstructor {
232
232
 
233
233
  ## References
234
234
 
235
- - https://www.unpkg.com/@e-mc/types@0.8.12/lib/core.d.ts
236
- - https://www.unpkg.com/@e-mc/types@0.8.12/lib/logger.d.ts
237
- - https://www.unpkg.com/@e-mc/types@0.8.12/lib/module.d.ts
238
- - https://www.unpkg.com/@e-mc/types@0.8.12/lib/node.d.ts
235
+ - https://www.unpkg.com/@e-mc/types@0.8.14/lib/core.d.ts
236
+ - https://www.unpkg.com/@e-mc/types@0.8.14/lib/logger.d.ts
237
+ - https://www.unpkg.com/@e-mc/types@0.8.14/lib/module.d.ts
238
+ - https://www.unpkg.com/@e-mc/types@0.8.14/lib/node.d.ts
239
239
 
240
240
  ## LICENSE
241
241
 
package/index.js CHANGED
@@ -129,6 +129,25 @@ const MEMORY_CACHE_DISK = {
129
129
  exclude: null
130
130
  };
131
131
  const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
132
+ const RESERVED_SHELL = [
133
+ 'if',
134
+ 'then',
135
+ 'elif',
136
+ 'else',
137
+ 'fi',
138
+ 'time',
139
+ 'for',
140
+ 'in',
141
+ 'until',
142
+ 'while',
143
+ 'do',
144
+ 'done',
145
+ 'case',
146
+ 'esac',
147
+ 'coproc',
148
+ 'select',
149
+ 'function'
150
+ ];
132
151
  let LOG_NEWLINE = true;
133
152
  let LOG_EMPTYLINE = false;
134
153
  let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
@@ -535,7 +554,7 @@ function addCacheItem(map, key, data, cache) {
535
554
  }
536
555
  function checkFunction(value) {
537
556
  if (typeof value === 'function') {
538
- Object.defineProperty(value, "__cjs__", { value: true });
557
+ Object.defineProperty(value, "__cjs__", { value: true, writable: false, enumerable: false });
539
558
  return value;
540
559
  }
541
560
  return null;
@@ -638,9 +657,16 @@ function applyLogId(options) {
638
657
  }
639
658
  return options;
640
659
  }
641
- function withinDir(value, base) {
660
+ function withinDir(value, base, override = false) {
642
661
  value = path.normalize(value);
643
- return (PLATFORM_WIN32 ? value.toLowerCase() : value).startsWith(ensureDir(PLATFORM_WIN32 ? base.toLowerCase() : base));
662
+ if (PLATFORM_WIN32) {
663
+ value = value.toLowerCase();
664
+ base = ensureDir(base.toLowerCase());
665
+ }
666
+ else {
667
+ base = ensureDir(base);
668
+ }
669
+ return value.startsWith(base) && (value !== base || override);
644
670
  }
645
671
  function formatPercent(value, precision) {
646
672
  if (value <= 0) {
@@ -688,7 +714,7 @@ class Module extends EventEmitter {
688
714
  this[_f] = new AbortController();
689
715
  this[_g] = null;
690
716
  }
691
- static get VERSION() { return "0.8.12"; }
717
+ static get VERSION() { return "0.8.14"; }
692
718
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
693
719
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
694
720
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -982,10 +1008,14 @@ class Module extends EventEmitter {
982
1008
  ({ color: hintColor, bgColor: hintBgColor } = formatHint);
983
1009
  hintBold !== null && hintBold !== void 0 ? hintBold : (hintBold = formatHint.bold);
984
1010
  }
985
- value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
986
- }
987
- else if (title) {
988
1011
  value = getValue();
1012
+ hint = coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`;
1013
+ }
1014
+ else {
1015
+ if (title) {
1016
+ value = getValue();
1017
+ }
1018
+ hint = '';
989
1019
  }
990
1020
  const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
991
1021
  const getMessage = (m, u) => type & 256 && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
@@ -1030,19 +1060,19 @@ class Module extends EventEmitter {
1030
1060
  }
1031
1061
  }
1032
1062
  else {
1033
- if (!i) {
1063
+ if (!i && !hint) {
1034
1064
  v = v.trim();
1035
1065
  }
1036
1066
  m = '';
1037
1067
  }
1038
- output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + (i ? i : ' ') + m;
1068
+ output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + hint + (i ? i : ' ') + m;
1039
1069
  }
1040
1070
  catch {
1041
1071
  }
1042
1072
  }
1043
1073
  if (!output) {
1044
- const m = truncateStart(this.asString(message), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
1045
- output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + value + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
1074
+ const m = truncateStart(stripansi(this.asString(message)), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
1075
+ output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + stripansi(hint) + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
1046
1076
  }
1047
1077
  if (broadcastId) {
1048
1078
  if (BROADCAST_OUT) {
@@ -2112,6 +2142,9 @@ class Module extends EventEmitter {
2112
2142
  value = "'" + value.replace(/'/g, "'\\''") + "'";
2113
2143
  }
2114
2144
  }
2145
+ else if (RESERVED_SHELL.includes(value)) {
2146
+ value = "'" + value + "'";
2147
+ }
2115
2148
  }
2116
2149
  }
2117
2150
  else if (opt) {
@@ -2583,7 +2616,7 @@ class Module extends EventEmitter {
2583
2616
  if (permission && (Module.isFile(uri, 'unc') ? permission.hasUNCRead(path.normalize(uri)) || ownPermissionOnly && !permission.getUNCRead() : path.isAbsolute(uri = path.resolve(uri)) && (permission.hasDiskRead(uri) || ownPermissionOnly && !permission.getDiskRead()))) {
2584
2617
  return true;
2585
2618
  }
2586
- return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR);
2619
+ return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR, true);
2587
2620
  }
2588
2621
  canWrite(uri, options) {
2589
2622
  let permission = this.permission, ownPermissionOnly = false;
@@ -2604,7 +2637,7 @@ class Module extends EventEmitter {
2604
2637
  if (permission && (Module.isFile(uri, 'unc') ? permission.hasUNCWrite(path.normalize(uri)) || ownPermissionOnly && !permission.getUNCWrite() : path.isAbsolute(uri = path.resolve(uri)) && (permission.hasDiskWrite(uri) || ownPermissionOnly && !permission.getDiskWrite()))) {
2605
2638
  return true;
2606
2639
  }
2607
- return VALUES["temp.write"] && withinDir(uri, TEMP_DIR) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR);
2640
+ return VALUES["temp.write"] && withinDir(uri, TEMP_DIR, true) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR, true);
2608
2641
  }
2609
2642
  readFile(src, options = {}, callback) {
2610
2643
  let promises, outSrc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.8.12",
3
+ "version": "0.8.14",
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": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.8.12",
23
+ "@e-mc/types": "0.8.14",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",