@e-mc/module 0.10.13 → 0.10.15

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 +47 -64
  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.10.13/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.10.15/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -407,11 +407,11 @@ interface LoggerModule {
407
407
 
408
408
  ## References
409
409
 
410
- - https://www.unpkg.com/@e-mc/types@0.10.13/lib/core.d.ts
411
- - https://www.unpkg.com/@e-mc/types@0.10.13/lib/logger.d.ts
412
- - https://www.unpkg.com/@e-mc/types@0.10.13/lib/module.d.ts
413
- - https://www.unpkg.com/@e-mc/types@0.10.13/lib/node.d.ts
414
- - https://www.unpkg.com/@e-mc/types@0.10.13/lib/settings.d.ts
410
+ - https://www.unpkg.com/@e-mc/types@0.10.15/lib/core.d.ts
411
+ - https://www.unpkg.com/@e-mc/types@0.10.15/lib/logger.d.ts
412
+ - https://www.unpkg.com/@e-mc/types@0.10.15/lib/module.d.ts
413
+ - https://www.unpkg.com/@e-mc/types@0.10.15/lib/node.d.ts
414
+ - https://www.unpkg.com/@e-mc/types@0.10.15/lib/settings.d.ts
415
415
 
416
416
  * https://www.npmjs.com/package/@types/node
417
417
 
package/index.js CHANGED
@@ -415,14 +415,14 @@ function tryCreateDir(value) {
415
415
  }
416
416
  return false;
417
417
  }
418
- function tryRemoveDir(value, empty, recursive) {
418
+ function tryRemoveDir(srcDir, empty, recursive) {
419
419
  const temp = typeof empty === 'number';
420
420
  let options;
421
421
  if (!temp) {
422
422
  try {
423
- fs.rmSync(value, { recursive, force: true });
423
+ fs.rmSync(srcDir, { recursive, force: true });
424
424
  if (empty) {
425
- fs.mkdirSync(value);
425
+ fs.mkdirSync(srcDir);
426
426
  }
427
427
  return [];
428
428
  }
@@ -430,30 +430,11 @@ function tryRemoveDir(value, empty, recursive) {
430
430
  }
431
431
  options = { recursive };
432
432
  }
433
- value = Module.normalizePath(value, 1);
434
433
  const failed = [];
435
- const nameMap = new WeakMap();
436
- let files;
437
- if (temp) {
438
- files = [];
439
- fs.readdirSync(value).forEach(name => {
440
- try {
441
- const stat = fs.statSync(value + name);
442
- nameMap.set(stat, name);
443
- files.push(stat);
444
- }
445
- catch {
446
- failed.push(value + name);
447
- }
448
- });
449
- }
450
- else {
451
- files = fs.readdirSync(value, { withFileTypes: true });
452
- }
453
434
  const current = Date.now();
454
- for (let i = 0, length = files.length; i < length; ++i) {
455
- const file = files[i];
456
- const pathname = value + (file.name || nameMap.get(file));
435
+ let entry;
436
+ fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
437
+ const pathname = path.join(srcDir, file.name);
457
438
  try {
458
439
  if (file.isDirectory()) {
459
440
  if (recursive) {
@@ -465,16 +446,16 @@ function tryRemoveDir(value, empty, recursive) {
465
446
  }
466
447
  }
467
448
  }
468
- else if (!temp || file.ctimeMs + empty <= current) {
449
+ else if (!temp || (entry = fs.statSync(pathname)) && entry.ctimeMs + empty <= current) {
469
450
  fs.unlinkSync(pathname);
470
451
  }
471
452
  }
472
453
  catch {
473
454
  failed.push(pathname);
474
455
  }
475
- }
456
+ });
476
457
  if (!empty && failed.length === 0) {
477
- fs.rmdirSync(value);
458
+ fs.rmdirSync(srcDir);
478
459
  }
479
460
  return failed;
480
461
  }
@@ -959,7 +940,7 @@ class Module extends EventEmitter {
959
940
  this[_g] = null;
960
941
  }
961
942
  static get VERSION() {
962
- return "0.10.13";
943
+ return "0.10.15";
963
944
  }
964
945
  static get LOG_TYPE() {
965
946
  return types_1.LOG_TYPE;
@@ -1227,8 +1208,8 @@ class Module extends EventEmitter {
1227
1208
  i = sessionIdColor || sessionIdBgColor || sessionIdBold ? formatLogColumn(i, sessionIdColor, sessionIdBgColor, sessionIdBold) : chalk.grey(i);
1228
1209
  }
1229
1210
  if ((m || unit) && SETTINGS.message !== false) {
1211
+ const formatMessage = format.message;
1230
1212
  if (!error) {
1231
- const formatMessage = format.message;
1232
1213
  if (!messageColor && !messageBgColor) {
1233
1214
  ({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
1234
1215
  messageBold ??= formatMessage.bold;
@@ -1278,6 +1259,7 @@ class Module extends EventEmitter {
1278
1259
  catch {
1279
1260
  m = chalk.redBright(L) + chalk.bgWhite.blackBright(m) + (R && chalk.redBright(R));
1280
1261
  }
1262
+ m = chalk.blackBright(formatMessage.braces[0]) + m;
1281
1263
  }
1282
1264
  }
1283
1265
  else {
@@ -1459,35 +1441,35 @@ class Module extends EventEmitter {
1459
1441
  return cacheKey ? crypto.randomUUID() : '';
1460
1442
  }
1461
1443
  static asHash(data, algorithm, digest) {
1462
- if (!algorithm && !digest) {
1463
- return crypto.createHash("sha256").update(data).digest("hex");
1464
- }
1465
- let options;
1466
- if ((0, types_1.isObject)(algorithm)) {
1467
- options = { ...algorithm };
1468
- if ('algorithm' in options) {
1469
- algorithm = options.algorithm;
1470
- delete options.algorithm;
1444
+ try {
1445
+ if (!algorithm && !digest) {
1446
+ return crypto.createHash("sha256").update(data).digest("hex");
1471
1447
  }
1472
- else {
1473
- algorithm = undefined;
1448
+ let options;
1449
+ if ((0, types_1.isObject)(algorithm)) {
1450
+ options = { ...algorithm };
1451
+ if ('algorithm' in options) {
1452
+ algorithm = options.algorithm;
1453
+ delete options.algorithm;
1454
+ }
1455
+ else {
1456
+ algorithm = undefined;
1457
+ }
1458
+ if ('digest' in options) {
1459
+ digest = options.digest;
1460
+ delete options.digest;
1461
+ }
1462
+ else {
1463
+ digest = undefined;
1464
+ }
1474
1465
  }
1475
- if ('digest' in options) {
1476
- digest = options.digest;
1477
- delete options.digest;
1466
+ else if ((0, types_1.isObject)(digest)) {
1467
+ options = digest;
1468
+ digest = undefined;
1478
1469
  }
1479
- else {
1470
+ else if (typeof digest !== 'string') {
1480
1471
  digest = undefined;
1481
1472
  }
1482
- }
1483
- else if ((0, types_1.isObject)(digest)) {
1484
- options = digest;
1485
- digest = undefined;
1486
- }
1487
- else if (typeof digest !== 'string') {
1488
- digest = undefined;
1489
- }
1490
- try {
1491
1473
  return crypto.createHash(algorithm || "sha256", options).update(data).digest(digest || "hex");
1492
1474
  }
1493
1475
  catch {
@@ -1564,8 +1546,7 @@ class Module extends EventEmitter {
1564
1546
  }
1565
1547
  static isFile(value, type) {
1566
1548
  if (!type) {
1567
- value = asFile(value);
1568
- return !!value && this.isPath(value, true);
1549
+ return this.isPath(value = asFile(value), true);
1569
1550
  }
1570
1551
  if (typeof value === 'string') {
1571
1552
  switch (type) {
@@ -1680,11 +1661,13 @@ class Module extends EventEmitter {
1680
1661
  if (typeof values[values.length - 1] === 'boolean') {
1681
1662
  normalize = values.pop();
1682
1663
  }
1683
- const paths = values.map(item => typeof item === 'string' ? item.trim() : '').filter(item => item).map(value => this.toPosix(value, normalize));
1664
+ const paths = values.filter(item => (0, types_1.isString)(item)).map(value => this.toPosix(value, normalize));
1684
1665
  let result = paths[0] || '';
1685
1666
  for (let i = 1; i < paths.length; ++i) {
1686
1667
  const trailing = paths[i];
1687
- result += (!trailing.startsWith('/') && !result.endsWith('/') ? '/' : '') + trailing;
1668
+ if (trailing) {
1669
+ result += (!trailing.startsWith('/') && !result.endsWith('/') ? '/' : '') + trailing;
1670
+ }
1688
1671
  }
1689
1672
  return result;
1690
1673
  }
@@ -1781,11 +1764,11 @@ class Module extends EventEmitter {
1781
1764
  }
1782
1765
  static async copyDir(src, dest, move, recursive = true) {
1783
1766
  const srcOut = sanitizePath(asFile(src));
1784
- if (!(srcOut && this.isDir(srcOut))) {
1767
+ if (!this.isDir(srcOut)) {
1785
1768
  return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1786
1769
  }
1787
1770
  const destOut = sanitizePath(asFile(dest));
1788
- if (!(destOut && this.createDir(destOut))) {
1771
+ if (!this.createDir(destOut)) {
1789
1772
  return Promise.reject(errorDirectory(asFile(dest) || "Unknown"));
1790
1773
  }
1791
1774
  let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
@@ -1921,7 +1904,7 @@ class Module extends EventEmitter {
1921
1904
  }
1922
1905
  static async globDir(src, pattern, options) {
1923
1906
  const outDir = sanitizePath(asFile(src));
1924
- if (!(outDir && this.isDir(outDir))) {
1907
+ if (!this.isDir(outDir)) {
1925
1908
  return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1926
1909
  }
1927
1910
  const pmOpts = PLATFORM_WIN32 ? { nocase: true, windows: true, posixSlashes: true } : {};
@@ -1995,7 +1978,7 @@ class Module extends EventEmitter {
1995
1978
  ({ minStreamSize = 0, encoding, signal, cache } = options);
1996
1979
  }
1997
1980
  const src = sanitizePath(asFile(value));
1998
- if (src && this.isPath(src, true)) {
1981
+ if (this.isPath(src, true)) {
1999
1982
  return new Promise(async (resolve) => {
2000
1983
  const fileSize = fs.statSync(src).size;
2001
1984
  let data;
@@ -2032,7 +2015,7 @@ class Module extends EventEmitter {
2032
2015
  ({ minStreamSize, encoding, cache } = options);
2033
2016
  }
2034
2017
  const src = sanitizePath(asFile(value));
2035
- if (src && this.isPath(src, true)) {
2018
+ if (this.isPath(src, true)) {
2036
2019
  let result;
2037
2020
  if (cache && (result = getCacheItem(CACHE_READTEXT, src))) {
2038
2021
  return (minStreamSize !== undefined ? Promise.resolve(result) : result);
@@ -2061,7 +2044,7 @@ class Module extends EventEmitter {
2061
2044
  ({ minStreamSize, cache } = options);
2062
2045
  }
2063
2046
  const src = sanitizePath(asFile(value));
2064
- if (src && this.isPath(src, true)) {
2047
+ if (this.isPath(src, true)) {
2065
2048
  let result;
2066
2049
  if (cache && (result = getCacheItem(CACHE_READBUFFER, src))) {
2067
2050
  return (minStreamSize !== undefined ? Promise.resolve(result) : result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.10.13",
3
+ "version": "0.10.15",
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.10.13",
23
+ "@e-mc/types": "0.10.15",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "^18.7.0",
26
26
  "js-yaml": "^4.1.0",