@e-mc/module 0.7.18 → 0.7.20

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.7.18"; }
591
+ static get VERSION() { return "0.7.20"; }
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"];
@@ -1170,7 +1172,7 @@ class Module extends EventEmitter {
1170
1172
  filename = undefined;
1171
1173
  }
1172
1174
  if (typeof value === 'string') {
1173
- let pathname = value.trim(), convert = true;
1175
+ let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
1174
1176
  if (normalize) {
1175
1177
  pathname = path.normalize(pathname);
1176
1178
  convert = PLATFORM_WIN32;
@@ -1277,7 +1279,7 @@ class Module extends EventEmitter {
1277
1279
  return false;
1278
1280
  }
1279
1281
  static resolveFile(value) {
1280
- if (isFileURL(value = value instanceof URL ? value.toString() : value.trim())) {
1282
+ if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
1281
1283
  try {
1282
1284
  return url.fileURLToPath(value);
1283
1285
  }
@@ -1292,7 +1294,7 @@ class Module extends EventEmitter {
1292
1294
  }
1293
1295
  static resolvePath(value, base) {
1294
1296
  try {
1295
- if (this.isURL(value = value.trim())) {
1297
+ if (this.isURL(value)) {
1296
1298
  return isFileURL(value) ? url.fileURLToPath(value) : new URL(value).href;
1297
1299
  }
1298
1300
  if (base instanceof URL || this.isURL(base)) {
@@ -1324,7 +1326,7 @@ class Module extends EventEmitter {
1324
1326
  if (typeof flags === 'boolean') {
1325
1327
  flags = flags ? 2 : 0;
1326
1328
  }
1327
- let result = value.trim();
1329
+ let result = PLATFORM_WIN32 ? value.trim() : value;
1328
1330
  result = flags & 1 ? path.resolve(result) : path.normalize(result);
1329
1331
  if ((flags & 3) && result.length) {
1330
1332
  result = ensureDir(result);
@@ -1900,12 +1902,10 @@ class Module extends EventEmitter {
1900
1902
  }
1901
1903
  static sanitizeArgs(values, doubleQuote) {
1902
1904
  const result = typeof values === 'string' ? [values] : values;
1903
- const pattern = /[^\w+-.,/:@]/g;
1904
- const sanitize = (value) => value.replace(pattern, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
1905
1905
  for (let i = 0; i < result.length; ++i) {
1906
1906
  let value = result[i].trim(), leading = '';
1907
1907
  if (value !== '--') {
1908
- const opt = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/.exec(value);
1908
+ const opt = REGEXP_CLIOPTION.exec(value);
1909
1909
  if (opt) {
1910
1910
  if (!opt[2] && !opt[3]) {
1911
1911
  result[i] = opt[1];
@@ -1915,7 +1915,7 @@ class Module extends EventEmitter {
1915
1915
  value = opt[3];
1916
1916
  }
1917
1917
  if (value) {
1918
- const quoted = /^(["'])(.*)\1$/.exec(value);
1918
+ const quoted = /^(["'])(.*)\1$/s.exec(value);
1919
1919
  if (PLATFORM_WIN32) {
1920
1920
  if (quoted) {
1921
1921
  if (quoted[1] === '"') {
@@ -1928,33 +1928,19 @@ class Module extends EventEmitter {
1928
1928
  value = wrapQuote(value);
1929
1929
  }
1930
1930
  }
1931
- else {
1932
- let type = doubleQuote;
1933
- if (quoted) {
1934
- if (quoted[1] === "'") {
1935
- result[i] = leading + value;
1936
- continue;
1937
- }
1938
- value = quoted[2];
1939
- type = true;
1940
- }
1941
- if (pattern.test(value)) {
1942
- if (type) {
1943
- value = '"' + sanitize(value) + '"';
1944
- }
1945
- else {
1946
- value = "'" + value.replace(/'/g, "'\\''") + "'";
1947
- }
1931
+ else if (!quoted) {
1932
+ if (REGEXP_CLIESCAPE.test(value)) {
1933
+ value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replace(/'/g, "'\\''")}'`;
1948
1934
  }
1949
1935
  else if (RESERVED_SHELL.includes(value)) {
1950
- value = "'" + value + "'";
1936
+ value = `'${value}'`;
1951
1937
  }
1952
1938
  }
1953
1939
  }
1954
1940
  else if (opt) {
1955
1941
  leading = leading.trim();
1956
1942
  if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
1957
- leading = sanitize(leading);
1943
+ leading.replace(REGEXP_CLIESCAPE, capture => '\\' + capture);
1958
1944
  }
1959
1945
  }
1960
1946
  }
@@ -3131,12 +3117,12 @@ class Module extends EventEmitter {
3131
3117
  }
3132
3118
  }
3133
3119
  writeLog(type, value, timeStamp, duration) {
3134
- let queue;
3120
+ let queue = false;
3135
3121
  if ((0, types_1.isObject)(type)) {
3136
3122
  if (typeof value === 'boolean') {
3137
3123
  queue = value;
3138
3124
  }
3139
- ({ type = types_1.STATUS_TYPE.UNKNOWN, value, timeStamp, duration } = type);
3125
+ value = type.value;
3140
3126
  }
3141
3127
  const output = Module.asString(value);
3142
3128
  if (output) {
@@ -3164,7 +3150,7 @@ class Module extends EventEmitter {
3164
3150
  from = timeStamp;
3165
3151
  timeStamp = 0;
3166
3152
  }
3167
- else if ((0, types_1.isObject)(timeStamp)) {
3153
+ else if ((0, types_1.isPlainObject)(timeStamp)) {
3168
3154
  ({ timeStamp, duration, from, source } = timeStamp);
3169
3155
  }
3170
3156
  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.7.18",
3
+ "version": "0.7.20",
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.7.18",
23
+ "@e-mc/types": "0.7.20",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",