@e-mc/module 0.11.0 → 0.11.2

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 +9 -6
  2. package/index.js +26 -14
  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.11.0/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.11.2/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -263,6 +263,9 @@ interface NodeModule {
263
263
  npm?: boolean;
264
264
  inline?: boolean;
265
265
  };
266
+ posix?: {
267
+ strict?: boolean;
268
+ };
266
269
  settings?: {
267
270
  package_manager?: "npm" | "yarn" | "pnpm";
268
271
  };
@@ -407,11 +410,11 @@ interface LoggerModule {
407
410
 
408
411
  ## References
409
412
 
410
- - https://www.unpkg.com/@e-mc/types@0.11.0/lib/core.d.ts
411
- - https://www.unpkg.com/@e-mc/types@0.11.0/lib/logger.d.ts
412
- - https://www.unpkg.com/@e-mc/types@0.11.0/lib/module.d.ts
413
- - https://www.unpkg.com/@e-mc/types@0.11.0/lib/node.d.ts
414
- - https://www.unpkg.com/@e-mc/types@0.11.0/lib/settings.d.ts
413
+ - https://www.unpkg.com/@e-mc/types@0.11.2/lib/core.d.ts
414
+ - https://www.unpkg.com/@e-mc/types@0.11.2/lib/logger.d.ts
415
+ - https://www.unpkg.com/@e-mc/types@0.11.2/lib/module.d.ts
416
+ - https://www.unpkg.com/@e-mc/types@0.11.2/lib/node.d.ts
417
+ - https://www.unpkg.com/@e-mc/types@0.11.2/lib/settings.d.ts
415
418
 
416
419
  * https://www.npmjs.com/package/@types/node
417
420
 
package/index.js CHANGED
@@ -116,6 +116,7 @@ const VALUES = {
116
116
  ["node.process.cpu_usage"]: true,
117
117
  ["node.process.memory_usage"]: true,
118
118
  ["node.process.inline"]: true,
119
+ ["node.posix.strict"]: false,
119
120
  ["node.settings.package_manager"]: '',
120
121
  ["temp.dir"]: "tmp",
121
122
  ["temp.write"]: false,
@@ -139,12 +140,13 @@ const MEMORY_CACHE_DISK = {
139
140
  include: null,
140
141
  exclude: null
141
142
  };
142
- const SUPPORTED_CANPARSE = (0, types_1.supported)(19, 9) || (0, types_1.supported)(18, 17, 0, true);
143
+ const SUPPORTED_CANPARSE = (0, types_1.supported)(19, 9) || (0, types_1.supported)(18, 17, true);
143
144
  const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
144
145
  const REGEXP_PROTOCOL = /^([a-z][a-z\d+-.]*):\/\/[^@:[\]\\^<>|\s]/i;
145
146
  const REGEXP_CLIESCAPE = /[^\w+-.,/:@]/g;
146
147
  const REGEXP_CLIOPTION = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/;
147
148
  const REGEXP_ANSIESCAPE = /[\u001B\u009B]/;
149
+ const REGEXP_PATHEND = new RegExp(`${path.sep}+$`);
148
150
  const LOG_CPUBARCOLOR = SETTINGS.process.cpu_bar_color;
149
151
  const LOG_DIVIDER = chalk.blackBright('|');
150
152
  const RESERVED_SHELL = [
@@ -935,6 +937,10 @@ function truncateStart(value, length = LOG_MIN_WIDTH, style = false) {
935
937
  function truncateEnd(value, length) {
936
938
  return (REGEXP_ANSIESCAPE.test(value) ? (0, node_util_1.stripVTControlCharacters)(value) : value).length > length ? '...' + value.substring(value.length - length + 3) : value;
937
939
  }
940
+ function isPathUNC(value) {
941
+ value = value.toString();
942
+ return (VALUES["node.posix.strict"] && value.includes('/') ? /^\/\/[\w.-]+\/[\w-]+\$?\/[^\n]*?[^/]$/ : /^(?:\\\\|\/\/)[\w.-]+[\\/][\w-]+\$?[\\/][^\n]*?[^\\/]$/).test(value);
943
+ }
938
944
  const escapeArg = (value) => value.replace(REGEXP_CLIESCAPE, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
939
945
  const isMeterUnit = (type, ident) => (type & 256) === 256 && !ident;
940
946
  const formatLogMessage = (type, message, unit, ident) => isMeterUnit(type, ident) ? (unit + LOG_DIVIDER + message).trimEnd() : unit ? (message + (ident ? '' : ' ') + unit).trimStart() : message;
@@ -944,7 +950,7 @@ const wrapQuote = (value) => '"' + value.replaceAll('"', '\\"') + '"';
944
950
  const isFunction = (value) => typeof value === 'function';
945
951
  const isFileURL = (value) => /^file:\/\//i.test(value);
946
952
  const sanitizePath = (value) => value ? path.resolve(value) : '';
947
- const stripPath = (value) => path.normalize(value).replace(/[\\/]+$/, '');
953
+ const stripPath = (value) => path.normalize(value).replace(REGEXP_PATHEND, '');
948
954
  const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
949
955
  const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
950
956
  const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
@@ -979,7 +985,7 @@ class Module extends EventEmitter {
979
985
  this[_g] = null;
980
986
  }
981
987
  static get VERSION() {
982
- return "0.11.0";
988
+ return "0.11.2";
983
989
  }
984
990
  static get LOG_TYPE() {
985
991
  return types_1.LOG_TYPE;
@@ -1017,6 +1023,7 @@ class Module extends EventEmitter {
1017
1023
  case "node.process.cpu_usage":
1018
1024
  case "node.process.memory_usage":
1019
1025
  case "node.process.inline":
1026
+ case "node.posix.strict":
1020
1027
  case "temp.write":
1021
1028
  case "permission.home_read":
1022
1029
  case "permission.home_write":
@@ -1594,7 +1601,7 @@ class Module extends EventEmitter {
1594
1601
  case 'http/s':
1595
1602
  return /^https?:\/\/[^/]/i.test(value);
1596
1603
  case 'unc':
1597
- return /^(?:\\\\|\/\/)[\w.-]+[\\/][\w-]+\$?[\\/][^\n]*?[^\\/]$/.test(value);
1604
+ return isPathUNC(value);
1598
1605
  case 'ftp':
1599
1606
  return /^ftp:\/\/[^/]/i.test(value);
1600
1607
  case 'sftp':
@@ -1616,7 +1623,7 @@ class Module extends EventEmitter {
1616
1623
  case 'http/s':
1617
1624
  return value.protocol === 'http:' || value.protocol === 'https:';
1618
1625
  case 'unc':
1619
- return /^(?:\\\\|\/\/)[\w.-]+[\\/][\w-]+\$?[\\/][^\n]*?[^\\/]$/.test(value.toString());
1626
+ return isPathUNC(value);
1620
1627
  case 'ftp':
1621
1628
  return value.protocol === 'ftp:';
1622
1629
  case 'sftp':
@@ -1653,7 +1660,8 @@ class Module extends EventEmitter {
1653
1660
  return false;
1654
1661
  }
1655
1662
  case 'unc':
1656
- return /^(?:\\\\|\/\/)[\w.-]+[\\/][\w-]+\$?(?:[\\/]?|[\\/][^\n]+)$/.test(asFile(value));
1663
+ value = asFile(value);
1664
+ return (VALUES["node.posix.strict"] && value.includes('/') ? /^\/\/[\w.-]+\/[\w-]+\$?(?:\/?|\/[^\n]+)$/ : /^(?:\\\\|\/\/)[\w.-]+[\\/][\w-]+\$?(?:[\\/]?|[\\/][^\n]+)$/).test(value);
1657
1665
  }
1658
1666
  }
1659
1667
  catch (err) {
@@ -1726,7 +1734,7 @@ class Module extends EventEmitter {
1726
1734
  }
1727
1735
  static fromLocalPath(value) {
1728
1736
  const ch = value[0];
1729
- if (ch === '.' && /^\.{1,2}[\\/][^\\/]/.test(value)) {
1737
+ if (ch === '.' && (VALUES["node.posix.strict"] && value.includes('/') ? /^\.{1,2}\/[^/]/ : /^\.{1,2}[\\/][^\\/]/).test(value)) {
1730
1738
  return path.join(PROCESS_CWD, value);
1731
1739
  }
1732
1740
  if (ch === '~' && value[1] === '/') {
@@ -1964,7 +1972,8 @@ class Module extends EventEmitter {
1964
1972
  const items = Array.isArray(exclude) ? exclude : [exclude];
1965
1973
  exclude = [];
1966
1974
  for (const value of items) {
1967
- if (/^[^\\/][^*]+[\\/]$/.test(value) && !(0, types_1.hasGlob)(value)) {
1975
+ const dirEnd = value.endsWith('/') ? /^[^/][^*]+\/$/ : value.endsWith('\\') ? /^[^\\][^*]+\\$/ : null;
1976
+ if (dirEnd?.test(value) && !(0, types_1.hasGlob)(value)) {
1968
1977
  (excludeDir ||= []).push(this.normalizePath(value, 4));
1969
1978
  }
1970
1979
  else {
@@ -2226,7 +2235,7 @@ class Module extends EventEmitter {
2226
2235
  }
2227
2236
  const folders = [PROCESS_CWD];
2228
2237
  if (startDir && withinDir(startDir = path.normalize(startDir), PROCESS_CWD)) {
2229
- startDir = startDir.replace(/[\\/]+$/, '');
2238
+ startDir = startDir.replace(REGEXP_PATHEND, '');
2230
2239
  let i = -1, j = PROCESS_CWD.length + 1;
2231
2240
  while ((i = startDir.indexOf(path.sep, j)) !== -1) {
2232
2241
  const current = startDir.substring(0, i);
@@ -2398,14 +2407,14 @@ class Module extends EventEmitter {
2398
2407
  }
2399
2408
  if (REGEXP_CLIESCAPE.test(value)) {
2400
2409
  if (type) {
2401
- value = '"' + escapeArg(value) + '"';
2410
+ value = `"${escapeArg(value)}"`;
2402
2411
  }
2403
2412
  else {
2404
- value = "'" + value.replaceAll("'", "'\\''") + "'";
2413
+ value = `'${value.replaceAll("'", "'\\''")}'`;
2405
2414
  }
2406
2415
  }
2407
2416
  else if (RESERVED_SHELL.includes(value)) {
2408
- value = "'" + value + "'";
2417
+ value = `'${value}'`;
2409
2418
  }
2410
2419
  }
2411
2420
  }
@@ -2491,7 +2500,7 @@ class Module extends EventEmitter {
2491
2500
  }
2492
2501
  const { temp, node, permission, memory, error, logger } = settings;
2493
2502
  if (node) {
2494
- const { process: proc, require: req } = node;
2503
+ const { process: proc, require: req, posix } = node;
2495
2504
  if (proc) {
2496
2505
  const { cpu_usage, memory_usage, inline } = proc;
2497
2506
  if (typeof cpu_usage === 'boolean') {
@@ -2526,6 +2535,9 @@ class Module extends EventEmitter {
2526
2535
  VALUES["node.require.inline"] = inline;
2527
2536
  }
2528
2537
  }
2538
+ if (typeof posix?.strict === 'boolean') {
2539
+ VALUES["node.posix.strict"] = posix.strict;
2540
+ }
2529
2541
  const manager = node.settings?.package_manager;
2530
2542
  switch (manager) {
2531
2543
  case 'npm':
@@ -3429,7 +3441,7 @@ class Module extends EventEmitter {
3429
3441
  const increment = options.meterIncrement || (http ? meter.http
3430
3442
  : type & 2048 ? meter.image
3431
3443
  : type & 8 ? meter.compress
3432
- : meter.process) || 250;
3444
+ : meter.process) || types_1.THRESHOLD.LOGGER_METER_INCREMENT;
3433
3445
  const duration = getTimeOffset(startTime, 0);
3434
3446
  let meterTime = duration, delayTime = options.delayTime;
3435
3447
  if (typeof delayTime === 'bigint' || Array.isArray(delayTime)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
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.11.0",
23
+ "@e-mc/types": "0.11.2",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "^18.7.0",
26
26
  "js-yaml": "^4.1.0",