@e-mc/module 0.13.5 → 0.13.7

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 +13 -7
  2. package/index.js +32 -13
  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.13.5/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.13.7/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -35,7 +35,7 @@ interface IModule extends EventEmitter, IAbortComponent {
35
35
  readonly status: LogStatus<StatusType>[];
36
36
  readonly errors: unknown[];
37
37
  supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
38
- supports(name: string, value?: boolean): boolean;
38
+ supports(name: string, value?: boolean, locked?: boolean): boolean;
39
39
  getTempDir(options: TempDirOptions): string;
40
40
  getTempDir(uuidDir: boolean, createDir: boolean): string;
41
41
  getTempDir(pathname: string, createDir: boolean): string;
@@ -247,6 +247,7 @@ interface ModuleConstructor {
247
247
  purgeMemory(percent: number, parent: boolean): Promise<number>;
248
248
  purgeMemory(percent: number, limit: number, parent?: boolean): Promise<number>;
249
249
  purgeMemory(percent?: number, limit?: number | boolean, parent?: unknown): Promise<number>;
250
+ availableParallelism(factor?: number): number;
250
251
  canWrite(name: "temp" | "home"): boolean;
251
252
  loadSettings(settings: Settings, password?: string): boolean;
252
253
  readonly prototype: IModule<IHost>;
@@ -305,6 +306,11 @@ interface MemoryModule {
305
306
  exclude?: string[];
306
307
  expires?: number | string;
307
308
  };
309
+ gc?: {
310
+ expires?: number | string;
311
+ expires_limit?: number | string;
312
+ interval?: number | string;
313
+ };
308
314
  };
309
315
  }
310
316
 
@@ -421,11 +427,11 @@ interface LoggerModule {
421
427
 
422
428
  ## References
423
429
 
424
- - https://www.unpkg.com/@e-mc/types@0.13.5/lib/core.d.ts
425
- - https://www.unpkg.com/@e-mc/types@0.13.5/lib/logger.d.ts
426
- - https://www.unpkg.com/@e-mc/types@0.13.5/lib/module.d.ts
427
- - https://www.unpkg.com/@e-mc/types@0.13.5/lib/node.d.ts
428
- - https://www.unpkg.com/@e-mc/types@0.13.5/lib/settings.d.ts
430
+ - https://www.unpkg.com/@e-mc/types@0.13.7/lib/core.d.ts
431
+ - https://www.unpkg.com/@e-mc/types@0.13.7/lib/logger.d.ts
432
+ - https://www.unpkg.com/@e-mc/types@0.13.7/lib/module.d.ts
433
+ - https://www.unpkg.com/@e-mc/types@0.13.7/lib/node.d.ts
434
+ - https://www.unpkg.com/@e-mc/types@0.13.7/lib/settings.d.ts
429
435
 
430
436
  * https://www.npmjs.com/package/@types/node
431
437
 
package/index.js CHANGED
@@ -411,7 +411,7 @@ function tryRemoveDir(srcDir, empty, recursive) {
411
411
  const failed = [];
412
412
  const current = Date.now();
413
413
  let entry;
414
- fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
414
+ for (const file of fs.readdirSync(srcDir, { withFileTypes: true })) {
415
415
  const pathname = path.join(srcDir, file.name);
416
416
  try {
417
417
  if (file.isDirectory()) {
@@ -431,7 +431,7 @@ function tryRemoveDir(srcDir, empty, recursive) {
431
431
  catch {
432
432
  failed.push(pathname);
433
433
  }
434
- });
434
+ }
435
435
  if (!empty && failed.length === 0) {
436
436
  fs.rmdirSync(srcDir);
437
437
  }
@@ -632,7 +632,7 @@ function isMatch(value, globs) {
632
632
  function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
633
633
  const srcDir = path.join(src, ...paths);
634
634
  try {
635
- fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
635
+ for (const file of fs.readdirSync(srcDir, { withFileTypes: true })) {
636
636
  if (file.isFile()) {
637
637
  const pathname = path.join(srcDir, file.name);
638
638
  const pathglob = pathname.substring(src.length);
@@ -646,7 +646,7 @@ function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
646
646
  listDir(src, subDirs, depth - 1, include, exclude, excludeDir, outFiles);
647
647
  }
648
648
  }
649
- });
649
+ }
650
650
  }
651
651
  catch {
652
652
  }
@@ -878,7 +878,7 @@ class Module extends EventEmitter {
878
878
  static LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
879
879
  static LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
880
880
  static get VERSION() {
881
- return "0.13.5";
881
+ return "0.13.7";
882
882
  }
883
883
  static get LOG_TYPE() {
884
884
  return types_1.LOG_TYPE;
@@ -2302,6 +2302,9 @@ class Module extends EventEmitter {
2302
2302
  }
2303
2303
  return result;
2304
2304
  }
2305
+ static availableParallelism(factor = 1) {
2306
+ return Math.ceil(((0, types_1.supported)(19, 4) || (0, types_1.supported)(18, 14, true) ? os.availableParallelism() : os.cpus().length) * factor);
2307
+ }
2305
2308
  static canWrite(name) {
2306
2309
  switch (name) {
2307
2310
  case 'temp':
@@ -2699,20 +2702,27 @@ class Module extends EventEmitter {
2699
2702
  #tempDir = VALUES["temp.dir"];
2700
2703
  #broadcastId = '';
2701
2704
  #permission = null;
2702
- #supports = { stripAnsi: { value: true, modified: false } };
2705
+ #supports = { stripAnsi: { value: true, modified: false, locked: false } };
2703
2706
  #abortController = new AbortController();
2704
2707
  #abortEvent = null;
2705
2708
  supported(major, minor, patch, lts) {
2706
2709
  return (0, types_1.supported)(major, minor, patch, lts);
2707
2710
  }
2708
- supports(name, value) {
2711
+ supports(name, value, locked) {
2709
2712
  if (typeof value === 'boolean') {
2710
- this.#supports[name] = { value, modified: true };
2713
+ const item = this.#supports[name];
2714
+ if (item?.locked) {
2715
+ return item.value;
2716
+ }
2717
+ this.#supports[name] = { value, modified: true, locked: !!locked };
2711
2718
  return value;
2712
2719
  }
2713
2720
  const host = this.host;
2714
2721
  const item = this.#supports[name];
2715
- return host && !item?.modified ? host.supports(name) : item?.value === true;
2722
+ if (item && (item.modified || !host)) {
2723
+ return item.value;
2724
+ }
2725
+ return host ? host.supports(name) : false;
2716
2726
  }
2717
2727
  getTempDir(pathname, filename, createDir) {
2718
2728
  let increment = 0, moduleDir, uuidDir;
@@ -3553,7 +3563,7 @@ class Module extends EventEmitter {
3553
3563
  return false;
3554
3564
  }
3555
3565
  checkFail(message, options) {
3556
- switch (options.code || message.code) {
3566
+ switch (options.code || message instanceof Error && message.code) {
3557
3567
  case types_1.ERR_CODE.MODULE_NOT_FOUND:
3558
3568
  case types_1.ERR_CODE.ERR_MODULE_NOT_FOUND:
3559
3569
  if (options.exec) {
@@ -3855,6 +3865,9 @@ class Module extends EventEmitter {
3855
3865
  }
3856
3866
  return options;
3857
3867
  }
3868
+ supportsProperty(name) {
3869
+ return !(name in this.#supports) || this.supports(name);
3870
+ }
3858
3871
  get moduleName() {
3859
3872
  return this._moduleName;
3860
3873
  }
@@ -3884,19 +3897,25 @@ class Module extends EventEmitter {
3884
3897
  return this._host;
3885
3898
  }
3886
3899
  set sessionId(value) {
3887
- this.#sessionId = value;
3900
+ if (this.supportsProperty('sessionId')) {
3901
+ this.#sessionId = value;
3902
+ }
3888
3903
  }
3889
3904
  get sessionId() {
3890
3905
  return this.#sessionId || this.host?.sessionId || '';
3891
3906
  }
3892
3907
  set broadcastId(value) {
3893
- this.#broadcastId = value;
3908
+ if (this.supportsProperty('broadcastId')) {
3909
+ this.#broadcastId = value;
3910
+ }
3894
3911
  }
3895
3912
  get broadcastId() {
3896
3913
  return this.#broadcastId || this.host?.broadcastId || '';
3897
3914
  }
3898
3915
  set permission(value) {
3899
- this.#permission = value;
3916
+ if (this.supportsProperty('permission')) {
3917
+ this.#permission = value;
3918
+ }
3900
3919
  }
3901
3920
  get permission() {
3902
3921
  return this.#permission || this.host?.permission || null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.13.5",
3
+ "version": "0.13.7",
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.13.5",
22
+ "@e-mc/types": "0.13.7",
23
23
  "chalk": "4.1.2",
24
24
  "file-type": "^20.5.0",
25
25
  "js-yaml": "^4.1.1",