@e-mc/module 0.9.5 → 0.9.6

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 +40 -8
  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.9.5/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.6/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -391,11 +391,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
391
391
 
392
392
  ## References
393
393
 
394
- - https://www.unpkg.com/@e-mc/types@0.9.5/lib/core.d.ts
395
- - https://www.unpkg.com/@e-mc/types@0.9.5/lib/logger.d.ts
396
- - https://www.unpkg.com/@e-mc/types@0.9.5/lib/module.d.ts
397
- - https://www.unpkg.com/@e-mc/types@0.9.5/lib/node.d.ts
398
- - https://www.unpkg.com/@e-mc/types@0.9.5/lib/settings.d.ts
394
+ - https://www.unpkg.com/@e-mc/types@0.9.6/lib/core.d.ts
395
+ - https://www.unpkg.com/@e-mc/types@0.9.6/lib/logger.d.ts
396
+ - https://www.unpkg.com/@e-mc/types@0.9.6/lib/module.d.ts
397
+ - https://www.unpkg.com/@e-mc/types@0.9.6/lib/node.d.ts
398
+ - https://www.unpkg.com/@e-mc/types@0.9.6/lib/settings.d.ts
399
399
 
400
400
  * https://www.npmjs.com/package/@types/node
401
401
 
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");
@@ -532,7 +551,7 @@ function addCacheItem(map, key, data, cache) {
532
551
  }
533
552
  function checkFunction(value) {
534
553
  if (typeof value === 'function') {
535
- Object.defineProperty(value, "__cjs__", { value: true });
554
+ Object.defineProperty(value, "__cjs__", { value: true, writable: false, enumerable: false });
536
555
  return value;
537
556
  }
538
557
  return null;
@@ -645,9 +664,16 @@ function applyLogId(options) {
645
664
  }
646
665
  return options;
647
666
  }
648
- function withinDir(value, base) {
667
+ function withinDir(value, base, override = false) {
649
668
  value = path.normalize(value);
650
- return (PLATFORM_WIN32 ? value.toLowerCase() : value).startsWith(ensureDir(PLATFORM_WIN32 ? base.toLowerCase() : base));
669
+ if (PLATFORM_WIN32) {
670
+ value = value.toLowerCase();
671
+ base = ensureDir(base.toLowerCase());
672
+ }
673
+ else {
674
+ base = ensureDir(base);
675
+ }
676
+ return value.startsWith(base) && (value !== base || override);
651
677
  }
652
678
  function formatPercent(value, precision) {
653
679
  if (value <= 0) {
@@ -696,7 +722,7 @@ class Module extends EventEmitter {
696
722
  this[_f] = new AbortController();
697
723
  this[_g] = null;
698
724
  }
699
- static get VERSION() { return "0.9.5"; }
725
+ static get VERSION() { return "0.9.6"; }
700
726
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
701
727
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
702
728
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -1164,13 +1190,16 @@ class Module extends EventEmitter {
1164
1190
  return null;
1165
1191
  }
1166
1192
  static asString(value, cacheKey) {
1167
- if ((0, types_1.isEmpty)(value)) {
1193
+ if (value === undefined) {
1168
1194
  return '';
1169
1195
  }
1170
1196
  switch (typeof value) {
1171
1197
  case 'string':
1172
1198
  return value;
1173
1199
  case 'object':
1200
+ if (value === null) {
1201
+ return '';
1202
+ }
1174
1203
  if (value.constructor === Object || Object.getPrototypeOf(value) === null) {
1175
1204
  if (Object.keys(value).length === 0) {
1176
1205
  return '';
@@ -2132,6 +2161,9 @@ class Module extends EventEmitter {
2132
2161
  value = "'" + value.replace(/'/g, "'\\''") + "'";
2133
2162
  }
2134
2163
  }
2164
+ else if (RESERVED_SHELL.includes(value)) {
2165
+ value = "'" + value + "'";
2166
+ }
2135
2167
  }
2136
2168
  }
2137
2169
  else if (opt) {
@@ -2518,7 +2550,7 @@ class Module extends EventEmitter {
2518
2550
  }
2519
2551
  } while ((dir !== "tmp") && (dir = "tmp"));
2520
2552
  if (modified) {
2521
- this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
2553
+ this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
2522
2554
  }
2523
2555
  settings.temp_dir = dir;
2524
2556
  if ((0, types_1.isPlainObject)(temp)) {
@@ -2607,7 +2639,7 @@ class Module extends EventEmitter {
2607
2639
  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()))) {
2608
2640
  return true;
2609
2641
  }
2610
- return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR);
2642
+ return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR, true);
2611
2643
  }
2612
2644
  canWrite(uri, options) {
2613
2645
  let permission = this.permission, ownPermissionOnly = false;
@@ -2631,7 +2663,7 @@ class Module extends EventEmitter {
2631
2663
  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()))) {
2632
2664
  return true;
2633
2665
  }
2634
- return VALUES["temp.write"] && withinDir(uri, TEMP_DIR) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR);
2666
+ return VALUES["temp.write"] && withinDir(uri, TEMP_DIR, true) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR, true);
2635
2667
  }
2636
2668
  readFile(src, options = {}, callback) {
2637
2669
  let promises, outSrc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
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.9.5",
23
+ "@e-mc/types": "0.9.6",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "16.5.4",
26
26
  "js-yaml": "^4.1.0",