@e-mc/module 0.9.10 → 0.9.12

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.
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.9.10/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.12/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -17,7 +17,7 @@ import type { LogStatus } from "./squared";
17
17
  import type { IHost } from "./index";
18
18
  import type { IAbortComponent, IPermission } from "./core";
19
19
  import type { LOG_TYPE, STATUS_TYPE, ExecCommand, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, LoggerFormat, StatusType } from "./logger";
20
- import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GetTempDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, WriteFileOptions } from "./module";
20
+ import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GetTempDirOptions, GlobDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, WriteFileOptions } from "./module";
21
21
  import type { Settings } from "./node";
22
22
  import type { LoggerFormatSettings } from "/settings";
23
23
 
@@ -200,6 +200,8 @@ interface ModuleConstructor {
200
200
  removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
201
201
  copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
202
202
  copyDir(src: string | URL, dest: string | URL, options?: CopyDirOptions): Promise<CopyDirResult>;
203
+ globDir(src: string | URL, pattern: string | string[], recursive: boolean | number): Promise<string[]>;
204
+ globDir(src: string | URL, pattern: string | string[], options?: GlobDirOptions): Promise<string[]>;
203
205
  renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
204
206
  streamFile(src: string, cache: boolean): Promise<Buffer | string>;
205
207
  streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
@@ -256,6 +258,9 @@ interface NodeModule {
256
258
  npm?: boolean;
257
259
  inline?: boolean;
258
260
  };
261
+ settings?: {
262
+ package_manager?: "npm" | "yarn" | "pnpm";
263
+ };
259
264
  }
260
265
 
261
266
  interface ProcessModule {
@@ -389,11 +394,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
389
394
 
390
395
  ## References
391
396
 
392
- - https://www.unpkg.com/@e-mc/types@0.9.10/lib/core.d.ts
393
- - https://www.unpkg.com/@e-mc/types@0.9.10/lib/logger.d.ts
394
- - https://www.unpkg.com/@e-mc/types@0.9.10/lib/module.d.ts
395
- - https://www.unpkg.com/@e-mc/types@0.9.10/lib/node.d.ts
396
- - https://www.unpkg.com/@e-mc/types@0.9.10/lib/settings.d.ts
397
+ - https://www.unpkg.com/@e-mc/types@0.9.12/lib/core.d.ts
398
+ - https://www.unpkg.com/@e-mc/types@0.9.12/lib/logger.d.ts
399
+ - https://www.unpkg.com/@e-mc/types@0.9.12/lib/module.d.ts
400
+ - https://www.unpkg.com/@e-mc/types@0.9.12/lib/node.d.ts
401
+ - https://www.unpkg.com/@e-mc/types@0.9.12/lib/settings.d.ts
397
402
 
398
403
  * https://www.npmjs.com/package/@types/node
399
404
 
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ModuleConstructor } from '../types/lib';
2
-
3
- declare const Module: ModuleConstructor;
4
-
1
+ import type { ModuleConstructor } from '@e-mc/types/lib';
2
+
3
+ declare const Module: ModuleConstructor;
4
+
5
5
  export = Module;
package/index.js CHANGED
@@ -106,6 +106,7 @@ const VALUES = {
106
106
  ["node.process.cpu_usage"]: true,
107
107
  ["node.process.memory_usage"]: true,
108
108
  ["node.process.inline"]: true,
109
+ ["node.settings.package_manager"]: '',
109
110
  ["temp.dir"]: "tmp",
110
111
  ["temp.write"]: false,
111
112
  ["process.password"]: '',
@@ -171,12 +172,12 @@ function setPnpmVer() {
171
172
  return false;
172
173
  }
173
174
  const addPackage = (value) => {
174
- let index = value.indexOf('(');
175
+ let index = (value = value.replace(/^\//, '')).indexOf('(');
175
176
  if (index !== -1) {
176
177
  value = value.substring(0, index);
177
178
  }
178
- index = value.lastIndexOf(value.indexOf('@', 2) !== -1 ? '@' : '/');
179
- const name = value.substring(1, index);
179
+ index = value.lastIndexOf(value.indexOf('@', 1) !== -1 ? '@' : '/');
180
+ const name = value.substring(0, index);
180
181
  const version = value.substring(index + 1);
181
182
  if (!items.find(item => item[0] === name && item[1] === version)) {
182
183
  items.push([name, version]);
@@ -548,6 +549,20 @@ function addCacheItem(map, key, data, cache) {
548
549
  map.set(key, [Date.now(), data]);
549
550
  }
550
551
  }
552
+ function listDir(src, paths, depth, include, exclude, outFiles) {
553
+ const srcDir = path.join(src, ...paths);
554
+ fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
555
+ if (file.isFile()) {
556
+ const pathname = path.join(srcDir, file.name);
557
+ if (include(pathname) && !exclude?.(pathname)) {
558
+ outFiles.push(pathname);
559
+ }
560
+ }
561
+ else if (depth > 0 && file.isDirectory()) {
562
+ listDir(src, paths.concat(file.name), depth - 1, include, exclude, outFiles);
563
+ }
564
+ });
565
+ }
551
566
  function checkFunction(value) {
552
567
  if (typeof value === 'function') {
553
568
  Object.defineProperty(value, "__cjs__", { value: true, writable: false, enumerable: false });
@@ -720,7 +735,7 @@ class Module extends EventEmitter {
720
735
  this[_f] = new AbortController();
721
736
  this[_g] = null;
722
737
  }
723
- static get VERSION() { return "0.9.10"; }
738
+ static get VERSION() { return "0.9.12"; }
724
739
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
725
740
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
726
741
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -763,6 +778,7 @@ class Module extends EventEmitter {
763
778
  case "error.fatal":
764
779
  return VALUES[key];
765
780
  case "node.require.ext":
781
+ case "node.settings.package_manager":
766
782
  case "process.password":
767
783
  case "process.cipher.algorithm":
768
784
  return VALUES[key] !== '';
@@ -1685,6 +1701,33 @@ class Module extends EventEmitter {
1685
1701
  });
1686
1702
  });
1687
1703
  }
1704
+ static async globDir(src, pattern, options) {
1705
+ const outDir = sanitizePath(asFile(src));
1706
+ if (!(outDir && this.isDir(outDir))) {
1707
+ return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1708
+ }
1709
+ const pmOpts = { posixSlashes: true, windows: true, nocase: PLATFORM_WIN32 };
1710
+ let exclude, recursive;
1711
+ if ((0, types_1.isObject)(options)) {
1712
+ if (options.matchBase) {
1713
+ pmOpts.matchBase = true;
1714
+ }
1715
+ if (options.contains) {
1716
+ pmOpts.contains = true;
1717
+ }
1718
+ if (options.dot) {
1719
+ pmOpts.dot = true;
1720
+ }
1721
+ ({ exclude, recursive } = options);
1722
+ }
1723
+ else {
1724
+ recursive = options;
1725
+ }
1726
+ recursive ??= true;
1727
+ const result = [];
1728
+ listDir(outDir, [], !recursive ? 0 : typeof recursive === 'number' ? recursive : Infinity, pm(pattern, pmOpts), exclude ? pm(exclude, pmOpts) : undefined, result);
1729
+ return result;
1730
+ }
1688
1731
  static renameFile(src, dest, throws = true) {
1689
1732
  try {
1690
1733
  fs.renameSync(src, dest);
@@ -2072,7 +2115,7 @@ class Module extends EventEmitter {
2072
2115
  maxVersion = [Infinity];
2073
2116
  }
2074
2117
  else {
2075
- maxVersion = [max - 1];
2118
+ maxVersion = [(max | 0) - 1];
2076
2119
  maxRange = true;
2077
2120
  }
2078
2121
  let version = this.getPackageVersion(name, unstable, startDir);
@@ -2107,8 +2150,8 @@ class Module extends EventEmitter {
2107
2150
  }
2108
2151
  static sanitizeArgs(values, doubleQuote) {
2109
2152
  const result = typeof values === 'string' ? [values] : values;
2110
- const pattern = /[^0-9a-z%+-./:=@_]/gi;
2111
- const sanitize = (value) => value.replace(pattern, capture => (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
2153
+ const pattern = /[^\w+-.,/:@]/g;
2154
+ const sanitize = (value) => value.replace(pattern, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
2112
2155
  for (let i = 0; i < result.length; ++i) {
2113
2156
  let value = result[i].trim(), leading = '';
2114
2157
  if (value !== '--') {
@@ -2277,6 +2320,17 @@ class Module extends EventEmitter {
2277
2320
  VALUES["node.require.inline"] = inline;
2278
2321
  }
2279
2322
  }
2323
+ const manager = node.settings?.package_manager;
2324
+ switch (manager) {
2325
+ case 'npm':
2326
+ case 'yarn':
2327
+ case 'pnpm':
2328
+ VALUES["node.settings.package_manager"] = manager;
2329
+ break;
2330
+ default:
2331
+ VALUES["node.settings.package_manager"] = '';
2332
+ break;
2333
+ }
2280
2334
  }
2281
2335
  if ((0, types_1.isPlainObject)(settings.process)) {
2282
2336
  const { env, cipher, password: pwd } = settings.process;
@@ -3369,7 +3423,7 @@ class Module extends EventEmitter {
3369
3423
  if (typeof options === 'number') {
3370
3424
  options = undefined;
3371
3425
  }
3372
- this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: 'npm', args: ['i', name] } });
3426
+ this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: VALUES["node.settings.package_manager"] || (setPnpmVer() ? 'pnpm' : setYarnVer() ? 'yarn' : 'npm'), args: ['install', name] } });
3373
3427
  return true;
3374
3428
  }
3375
3429
  if (value) {
package/lib-v4.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { IModuleLibV4 } from '../types/lib/compat-v4';
2
-
3
- declare const LibV4: IModuleLibV4;
4
-
1
+ import type { IModuleLibV4 } from '@e-mc/types/lib/compat-v4';
2
+
3
+ declare const LibV4: IModuleLibV4;
4
+
5
5
  export = LibV4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.9.10",
3
+ "version": "0.9.12",
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.9.10",
23
+ "@e-mc/types": "0.9.12",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "16.5.4",
26
26
  "js-yaml": "^4.1.0",