@e-mc/module 0.6.14 → 0.6.16

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 (2) hide show
  1. package/index.js +19 -33
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -117,6 +117,8 @@ const VALUES = {
117
117
  ["logger.level"]: -1
118
118
  };
119
119
  const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
120
+ const REGEXP_CLIESCAPE = /[^\w+-.,/:@]/g;
121
+ const REGEXP_CLIOPTION = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/s;
120
122
  const RESERVED_SHELL = [
121
123
  'if',
122
124
  'then',
@@ -553,7 +555,7 @@ function tryIncrementDir(value, increment) {
553
555
  } while (increment-- > 0);
554
556
  return [outErr, -1];
555
557
  }
556
- const asFile = (value) => value instanceof URL ? value.protocol === 'file:' ? url.fileURLToPath(value) : '' : value;
558
+ const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
557
559
  const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
558
560
  const isFunction = (value) => typeof value === 'function';
559
561
  const isFileURL = (value) => /^file:\/\//i.test(value);
@@ -586,7 +588,7 @@ class Module extends EventEmitter {
586
588
  this[_f] = new AbortController();
587
589
  this[_g] = null;
588
590
  }
589
- static get VERSION() { return "0.6.14"; }
591
+ static get VERSION() { return "0.6.16"; }
590
592
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
591
593
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
592
594
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -666,7 +668,7 @@ class Module extends EventEmitter {
666
668
  }
667
669
  static formatMessage(type, title, value, message, options = {}) {
668
670
  var _h, _j, _k, _l;
669
- if (options.type) {
671
+ if (typeof options.type === 'number') {
670
672
  type |= options.type;
671
673
  }
672
674
  const BROADCAST_OUT = VALUES["broadcast.out"];
@@ -1139,7 +1141,7 @@ class Module extends EventEmitter {
1139
1141
  filename = undefined;
1140
1142
  }
1141
1143
  if (typeof value === 'string') {
1142
- let pathname = value.trim(), convert = true;
1144
+ let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
1143
1145
  if (normalize) {
1144
1146
  pathname = path.normalize(pathname);
1145
1147
  convert = PLATFORM_WIN32;
@@ -1246,7 +1248,7 @@ class Module extends EventEmitter {
1246
1248
  return false;
1247
1249
  }
1248
1250
  static resolveFile(value) {
1249
- if (isFileURL(value = value instanceof URL ? value.toString() : value.trim())) {
1251
+ if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
1250
1252
  try {
1251
1253
  return url.fileURLToPath(value);
1252
1254
  }
@@ -1261,7 +1263,7 @@ class Module extends EventEmitter {
1261
1263
  }
1262
1264
  static resolvePath(value, base) {
1263
1265
  try {
1264
- if (this.isURL(value = value.trim())) {
1266
+ if (this.isURL(value)) {
1265
1267
  return isFileURL(value) ? url.fileURLToPath(value) : new URL(value).href;
1266
1268
  }
1267
1269
  if (base instanceof URL || this.isURL(base)) {
@@ -1293,7 +1295,7 @@ class Module extends EventEmitter {
1293
1295
  if (typeof flags === 'boolean') {
1294
1296
  flags = flags ? 2 : 0;
1295
1297
  }
1296
- let result = value.trim();
1298
+ let result = PLATFORM_WIN32 ? value.trim() : value;
1297
1299
  result = flags & 1 ? path.resolve(result) : path.normalize(result);
1298
1300
  if ((flags & 3) && result.length) {
1299
1301
  result = ensureDir(result);
@@ -1869,12 +1871,10 @@ class Module extends EventEmitter {
1869
1871
  }
1870
1872
  static sanitizeArgs(values, doubleQuote) {
1871
1873
  const result = typeof values === 'string' ? [values] : values;
1872
- const pattern = /[^\w+-.,/:@]/g;
1873
- const sanitize = (value) => value.replace(pattern, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
1874
1874
  for (let i = 0; i < result.length; ++i) {
1875
1875
  let value = result[i].trim(), leading = '';
1876
1876
  if (value !== '--') {
1877
- const opt = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/.exec(value);
1877
+ const opt = REGEXP_CLIOPTION.exec(value);
1878
1878
  if (opt) {
1879
1879
  if (!opt[2] && !opt[3]) {
1880
1880
  result[i] = opt[1];
@@ -1884,7 +1884,7 @@ class Module extends EventEmitter {
1884
1884
  value = opt[3];
1885
1885
  }
1886
1886
  if (value) {
1887
- const quoted = /^(["'])(.*)\1$/.exec(value);
1887
+ const quoted = /^(["'])(.*)\1$/s.exec(value);
1888
1888
  if (PLATFORM_WIN32) {
1889
1889
  if (quoted) {
1890
1890
  if (quoted[1] === '"') {
@@ -1897,33 +1897,19 @@ class Module extends EventEmitter {
1897
1897
  value = wrapQuote(value);
1898
1898
  }
1899
1899
  }
1900
- else {
1901
- let type = doubleQuote;
1902
- if (quoted) {
1903
- if (quoted[1] === "'") {
1904
- result[i] = leading + value;
1905
- continue;
1906
- }
1907
- value = quoted[2];
1908
- type = true;
1909
- }
1910
- if (pattern.test(value)) {
1911
- if (type) {
1912
- value = '"' + sanitize(value) + '"';
1913
- }
1914
- else {
1915
- value = "'" + value.replace(/'/g, "'\\''") + "'";
1916
- }
1900
+ else if (!quoted) {
1901
+ if (REGEXP_CLIESCAPE.test(value)) {
1902
+ value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replace(/'/g, "'\\''")}'`;
1917
1903
  }
1918
1904
  else if (RESERVED_SHELL.includes(value)) {
1919
- value = "'" + value + "'";
1905
+ value = `'${value}'`;
1920
1906
  }
1921
1907
  }
1922
1908
  }
1923
1909
  else if (opt) {
1924
1910
  leading = leading.trim();
1925
1911
  if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
1926
- leading = sanitize(leading);
1912
+ leading.replace(REGEXP_CLIESCAPE, capture => '\\' + capture);
1927
1913
  }
1928
1914
  }
1929
1915
  }
@@ -3099,12 +3085,12 @@ class Module extends EventEmitter {
3099
3085
  }
3100
3086
  }
3101
3087
  writeLog(type, value, timeStamp, duration) {
3102
- let queue;
3088
+ let queue = false;
3103
3089
  if ((0, types_1.isObject)(type)) {
3104
3090
  if (typeof value === 'boolean') {
3105
3091
  queue = value;
3106
3092
  }
3107
- ({ type = types_1.STATUS_TYPE.UNKNOWN, value, timeStamp, duration } = type);
3093
+ value = type.value;
3108
3094
  }
3109
3095
  const output = Module.asString(value);
3110
3096
  if (output) {
@@ -3132,7 +3118,7 @@ class Module extends EventEmitter {
3132
3118
  from = timeStamp;
3133
3119
  timeStamp = 0;
3134
3120
  }
3135
- else if ((0, types_1.isObject)(timeStamp)) {
3121
+ else if ((0, types_1.isPlainObject)(timeStamp)) {
3136
3122
  ({ timeStamp, duration, from, source } = timeStamp);
3137
3123
  }
3138
3124
  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.6.14",
3
+ "version": "0.6.16",
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.6.14",
23
+ "@e-mc/types": "0.6.16",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",