@e-mc/module 0.12.8 → 0.12.10

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 -7
  2. package/index.js +35 -52
  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.12.7/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.10/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -93,7 +93,9 @@ interface IModule extends EventEmitter, IAbortComponent {
93
93
  checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
94
94
  writeLog(component: LogComponent, queue?: boolean): void;
95
95
  writeLog(type: StatusType, value: unknown, options: LogOptions): void;
96
- writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
96
+ writeLog(type: StatusType, value: unknown, from: string, source?: string): void;
97
+ writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
98
+ writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
97
99
  addLog(component: LogComponent, queue?: boolean): void;
98
100
  addLog(type: StatusType, value: unknown, options: LogOptions): void;
99
101
  addLog(type: StatusType, value: unknown, from: string, source?: string): void;
@@ -414,11 +416,11 @@ interface LoggerModule {
414
416
 
415
417
  ## References
416
418
 
417
- - https://www.unpkg.com/@e-mc/types@0.12.7/lib/core.d.ts
418
- - https://www.unpkg.com/@e-mc/types@0.12.7/lib/logger.d.ts
419
- - https://www.unpkg.com/@e-mc/types@0.12.7/lib/module.d.ts
420
- - https://www.unpkg.com/@e-mc/types@0.12.7/lib/node.d.ts
421
- - https://www.unpkg.com/@e-mc/types@0.12.7/lib/settings.d.ts
419
+ - https://www.unpkg.com/@e-mc/types@0.12.10/lib/core.d.ts
420
+ - https://www.unpkg.com/@e-mc/types@0.12.10/lib/logger.d.ts
421
+ - https://www.unpkg.com/@e-mc/types@0.12.10/lib/module.d.ts
422
+ - https://www.unpkg.com/@e-mc/types@0.12.10/lib/node.d.ts
423
+ - https://www.unpkg.com/@e-mc/types@0.12.10/lib/settings.d.ts
422
424
 
423
425
  * https://www.npmjs.com/package/@types/node
424
426
 
package/index.js CHANGED
@@ -159,7 +159,7 @@ function setPnpmVer() {
159
159
  let baseDir;
160
160
  try {
161
161
  let pathname = path.resolve("node_modules/.modules.yaml"), config;
162
- if (fs.existsSync(pathname) && (0, types_1.isPlainObject)(config = parseYaml(pathname))) {
162
+ if (fs.existsSync(pathname) && (0, types_1.isObject)(config = parseYaml(pathname))) {
163
163
  if (config.nodeLinker === 'hoisted') {
164
164
  return PNPM_VER = true;
165
165
  }
@@ -175,7 +175,7 @@ function setPnpmVer() {
175
175
  if (!fs.existsSync(pathname = path.resolve(baseDir, "lock.yaml"))) {
176
176
  baseDir = undefined;
177
177
  }
178
- else if ((0, types_1.isPlainObject)(config = parseYaml(pathname))) {
178
+ else if ((0, types_1.isObject)(config = parseYaml(pathname))) {
179
179
  for (const name in config.packages) {
180
180
  addPnpmPackage(items, name);
181
181
  }
@@ -208,7 +208,7 @@ function setYarnVer() {
208
208
  try {
209
209
  const pathname = path.resolve(".yarnrc.yml");
210
210
  let config;
211
- if (fs.existsSync(pathname) && (0, types_1.isPlainObject)(config = parseYaml(pathname)) && config.nodeLinker === 'node-modules') {
211
+ if (fs.existsSync(pathname) && (0, types_1.isObject)(config = parseYaml(pathname)) && config.nodeLinker === 'node-modules') {
212
212
  return YARN_VER = true;
213
213
  }
214
214
  }
@@ -393,14 +393,14 @@ function tryCreateDir(value) {
393
393
  }
394
394
  return false;
395
395
  }
396
- function tryRemoveDir(value, empty, recursive) {
396
+ function tryRemoveDir(srcDir, empty, recursive) {
397
397
  const temp = typeof empty === 'number';
398
398
  let options;
399
399
  if (!temp) {
400
400
  try {
401
- fs.rmSync(value, { recursive, force: true });
401
+ fs.rmSync(srcDir, { recursive, force: true });
402
402
  if (empty) {
403
- fs.mkdirSync(value);
403
+ fs.mkdirSync(srcDir);
404
404
  }
405
405
  return [];
406
406
  }
@@ -408,30 +408,11 @@ function tryRemoveDir(value, empty, recursive) {
408
408
  }
409
409
  options = { recursive };
410
410
  }
411
- value = Module.normalizePath(value, 1);
412
411
  const failed = [];
413
- const nameMap = new WeakMap();
414
- let files;
415
- if (temp) {
416
- files = [];
417
- fs.readdirSync(value).forEach(name => {
418
- try {
419
- const stat = fs.statSync(value + name);
420
- nameMap.set(stat, name);
421
- files.push(stat);
422
- }
423
- catch {
424
- failed.push(value + name);
425
- }
426
- });
427
- }
428
- else {
429
- files = fs.readdirSync(value, { withFileTypes: true });
430
- }
431
412
  const current = Date.now();
432
- for (let i = 0, length = files.length; i < length; ++i) {
433
- const file = files[i];
434
- const pathname = value + (file.name || nameMap.get(file));
413
+ let entry;
414
+ fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
415
+ const pathname = path.join(srcDir, file.name);
435
416
  try {
436
417
  if (file.isDirectory()) {
437
418
  if (recursive) {
@@ -443,16 +424,16 @@ function tryRemoveDir(value, empty, recursive) {
443
424
  }
444
425
  }
445
426
  }
446
- else if (!temp || file.ctimeMs + empty <= current) {
427
+ else if (!temp || (entry = fs.statSync(pathname)) && entry.ctimeMs + empty <= current) {
447
428
  fs.unlinkSync(pathname);
448
429
  }
449
430
  }
450
431
  catch {
451
432
  failed.push(pathname);
452
433
  }
453
- }
434
+ });
454
435
  if (!empty && failed.length === 0) {
455
- fs.rmdirSync(value);
436
+ fs.rmdirSync(srcDir);
456
437
  }
457
438
  return failed;
458
439
  }
@@ -869,7 +850,7 @@ class Module extends EventEmitter {
869
850
  static LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
870
851
  static LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
871
852
  static get VERSION() {
872
- return "0.12.8";
853
+ return "0.12.10";
873
854
  }
874
855
  static get LOG_TYPE() {
875
856
  return types_1.LOG_TYPE;
@@ -1141,8 +1122,8 @@ class Module extends EventEmitter {
1141
1122
  i = sessionIdColor || sessionIdBgColor || sessionIdBold ? formatLogColumn(i, sessionIdColor, sessionIdBgColor, sessionIdBold) : chalk.grey(i);
1142
1123
  }
1143
1124
  if ((m || unit) && SETTINGS.message !== false) {
1125
+ const formatMessage = format.message;
1144
1126
  if (!error) {
1145
- const formatMessage = format.message;
1146
1127
  if (!messageColor && !messageBgColor) {
1147
1128
  ({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
1148
1129
  messageBold ??= formatMessage.bold;
@@ -1192,6 +1173,7 @@ class Module extends EventEmitter {
1192
1173
  catch {
1193
1174
  m = chalk.redBright(L) + chalk.bgWhite.blackBright(m) + (R && chalk.redBright(R));
1194
1175
  }
1176
+ m = chalk.blackBright(formatMessage.braces[0]) + m;
1195
1177
  }
1196
1178
  }
1197
1179
  else {
@@ -1476,8 +1458,7 @@ class Module extends EventEmitter {
1476
1458
  }
1477
1459
  static isFile(value, type) {
1478
1460
  if (!type) {
1479
- value = asFile(value);
1480
- return !!value && this.isPath(value, true);
1461
+ return this.isPath(value = asFile(value), true);
1481
1462
  }
1482
1463
  if (typeof value === 'string') {
1483
1464
  switch (type) {
@@ -1527,7 +1508,11 @@ class Module extends EventEmitter {
1527
1508
  }
1528
1509
  static isDir(value) {
1529
1510
  try {
1530
- return fs.statSync(value).isDirectory();
1511
+ let target = fs.statSync(value);
1512
+ if (target.isSymbolicLink()) {
1513
+ target = fs.statSync(fs.realpathSync(value));
1514
+ }
1515
+ return target.isDirectory();
1531
1516
  }
1532
1517
  catch {
1533
1518
  return false;
@@ -1696,11 +1681,11 @@ class Module extends EventEmitter {
1696
1681
  }
1697
1682
  static async copyDir(src, dest, move, recursive) {
1698
1683
  const srcOut = sanitizePath(asFile(src));
1699
- if (!(srcOut && this.isDir(srcOut))) {
1684
+ if (!this.isDir(srcOut)) {
1700
1685
  return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1701
1686
  }
1702
1687
  const destOut = sanitizePath(asFile(dest));
1703
- if (!(destOut && this.createDir(destOut))) {
1688
+ if (!this.createDir(destOut)) {
1704
1689
  return Promise.reject(errorDirectory(asFile(dest) || "Unknown"));
1705
1690
  }
1706
1691
  let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
@@ -1837,7 +1822,7 @@ class Module extends EventEmitter {
1837
1822
  }
1838
1823
  static async globDir(src, pattern, options) {
1839
1824
  const outDir = sanitizePath(asFile(src));
1840
- if (!(outDir && this.isDir(outDir))) {
1825
+ if (!this.isDir(outDir)) {
1841
1826
  return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1842
1827
  }
1843
1828
  const pmOpts = PLATFORM_WIN32 ? { nocase: true, posixSlashes: true, windows: true } : {};
@@ -1911,7 +1896,7 @@ class Module extends EventEmitter {
1911
1896
  ({ minStreamSize = 0, encoding, signal, cache } = options);
1912
1897
  }
1913
1898
  const src = sanitizePath(asFile(value));
1914
- if (src && this.isPath(src, true)) {
1899
+ if (this.isPath(src, true)) {
1915
1900
  return new Promise(async (resolve) => {
1916
1901
  const fileSize = fs.statSync(src).size;
1917
1902
  let data;
@@ -1948,7 +1933,7 @@ class Module extends EventEmitter {
1948
1933
  ({ minStreamSize, encoding, cache } = options);
1949
1934
  }
1950
1935
  const src = sanitizePath(asFile(value));
1951
- if (src && this.isPath(src, true)) {
1936
+ if (this.isPath(src, true)) {
1952
1937
  let result;
1953
1938
  if (cache && (result = getCacheItem(CACHE_READTEXT, src))) {
1954
1939
  return (minStreamSize !== undefined ? Promise.resolve(result) : result);
@@ -1977,7 +1962,7 @@ class Module extends EventEmitter {
1977
1962
  ({ minStreamSize, cache } = options);
1978
1963
  }
1979
1964
  const src = sanitizePath(asFile(value));
1980
- if (src && this.isPath(src, true)) {
1965
+ if (this.isPath(src, true)) {
1981
1966
  let result;
1982
1967
  if (cache && (result = getCacheItem(CACHE_READBUFFER, src))) {
1983
1968
  return (minStreamSize !== undefined ? Promise.resolve(result) : result);
@@ -2559,7 +2544,7 @@ class Module extends EventEmitter {
2559
2544
  case 'process': {
2560
2545
  const proc = logger.process;
2561
2546
  if (proc) {
2562
- if ((0, types_1.isObject)(proc)) {
2547
+ if ((0, types_1.isPlainObject)(proc)) {
2563
2548
  if ('cpu_bar_color' in proc) {
2564
2549
  const barColor = proc.cpu_bar_color;
2565
2550
  if (Array.isArray(barColor) && barColor.length === 3 && barColor.every(color => isBackgroundColor(color))) {
@@ -3270,7 +3255,7 @@ class Module extends EventEmitter {
3270
3255
  }
3271
3256
  writeFail(value, message, options) {
3272
3257
  let type;
3273
- if ((0, types_1.isPlainObject)(options)) {
3258
+ if ((0, types_1.isObject)(options)) {
3274
3259
  ({ type } = options);
3275
3260
  }
3276
3261
  else {
@@ -3558,7 +3543,7 @@ class Module extends EventEmitter {
3558
3543
  break;
3559
3544
  }
3560
3545
  }
3561
- writeLog(type, value, timeStamp, duration) {
3546
+ writeLog(type, value, timeStamp, duration, from, source) {
3562
3547
  let queue = false;
3563
3548
  if ((0, types_1.isObject)(type)) {
3564
3549
  if (typeof value === 'boolean') {
@@ -3575,7 +3560,7 @@ class Module extends EventEmitter {
3575
3560
  writeLine(output);
3576
3561
  }
3577
3562
  }
3578
- this.addLog(type, value, timeStamp, duration);
3563
+ this.addLog(type, value, timeStamp, duration, from, source);
3579
3564
  }
3580
3565
  addLog(type, value, timeStamp, duration, from, source) {
3581
3566
  if (!this._logEnabled || SETTINGS.production && process.env.NODE_ENV === 'production' && (SETTINGS.production.includes(this.moduleName) || from && SETTINGS.production.includes(from))) {
@@ -3817,8 +3802,7 @@ class Module extends EventEmitter {
3817
3802
  options.sessionId ??= this.sessionId;
3818
3803
  let value = options.broadcastId;
3819
3804
  if (value === undefined) {
3820
- value = this.broadcastId;
3821
- if (value) {
3805
+ if (value = this.broadcastId) {
3822
3806
  options.broadcastId = this.supports('stripAnsi') ? value : { value, stripAnsi: false };
3823
3807
  }
3824
3808
  }
@@ -3866,20 +3850,19 @@ class Module extends EventEmitter {
3866
3850
  this.#sessionId = value;
3867
3851
  }
3868
3852
  get sessionId() {
3869
- return this.#sessionId || (this.host ? this.host.sessionId : '');
3853
+ return this.#sessionId || this.host?.sessionId || '';
3870
3854
  }
3871
3855
  set broadcastId(value) {
3872
3856
  this.#broadcastId = value;
3873
3857
  }
3874
3858
  get broadcastId() {
3875
- return this.#broadcastId || (this.host ? this.host.broadcastId : '');
3859
+ return this.#broadcastId || this.host?.broadcastId || '';
3876
3860
  }
3877
3861
  set permission(value) {
3878
3862
  this.#permission = value;
3879
3863
  }
3880
3864
  get permission() {
3881
- let host;
3882
- return this.#permission || (host = this.host) && host.permission;
3865
+ return this.#permission || this.host?.permission || null;
3883
3866
  }
3884
3867
  get signal() {
3885
3868
  return this.#abortController.signal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.12.8",
3
+ "version": "0.12.10",
4
4
  "description": "Module base class for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/types": "0.12.8",
22
+ "@e-mc/types": "0.12.10",
23
23
  "chalk": "4.1.2",
24
24
  "file-type": "^18.7.0",
25
25
  "js-yaml": "^4.1.0",