@abtnode/util 1.6.22 → 1.6.25

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/lib/can-pkg-rw.js CHANGED
@@ -3,7 +3,7 @@ const locateNpmGlobalByBinary = require('./locate-npm-global-by-binary');
3
3
  const { canReadAndWriteDir } = require('./fs');
4
4
 
5
5
  module.exports = (cmdName, packageName) => {
6
- const installDir = locateNpmGlobalByBinary(cmdName);
6
+ const installDir = locateNpmGlobalByBinary(cmdName, packageName);
7
7
  if (!installDir) {
8
8
  throw new Error(`${packageName} is not installed as a global package`);
9
9
  }
@@ -1,22 +1,32 @@
1
- /* eslint-disable no-unused-vars, no-console */
2
-
3
1
  const fs = require('fs');
4
2
  const path = require('path');
5
- const shelljs = require('shelljs');
3
+ const shell = require('shelljs');
6
4
 
7
- module.exports = (binaryName) => {
5
+ module.exports = (binaryName, packageName) => {
8
6
  if (!binaryName) {
9
7
  throw new Error('binaryName is required');
10
8
  }
11
9
 
12
- const result = shelljs.which(binaryName);
10
+ let result = shell.which(binaryName);
13
11
  if (!result || !result.stdout) {
14
12
  return '';
15
13
  }
16
14
 
17
- const binPath = result.stdout;
15
+ const binPath = result.stdout.trim();
18
16
 
17
+ // Check if the package is installed via pnpm: only if we have packageName set
19
18
  let binDir = path.dirname(fs.realpathSync(binPath));
19
+ if (packageName) {
20
+ const { stdout: pnpmPath } = shell.which('pnpm') || {};
21
+ if (pnpmPath) {
22
+ result = shell.exec('pnpm bin -g', { silent: true });
23
+ const pnpmBinDir = result.stdout.trim();
24
+ if (binDir === pnpmBinDir) {
25
+ result = shell.exec(`pnpm root -g ${packageName}`, { silent: true });
26
+ return path.join(result.stdout.trim(), packageName);
27
+ }
28
+ }
29
+ }
20
30
 
21
31
  while (binDir && binDir !== path.sep && path.basename(binDir) !== 'node_modules') {
22
32
  const packageJsonPath = path.join(binDir, 'package.json');
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.6.22",
6
+ "version": "1.6.25",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,9 +18,9 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@ocap/mcrypto": "^1.14.16",
22
- "@ocap/util": "^1.14.16",
23
- "@ocap/wallet": "^1.14.16",
21
+ "@ocap/mcrypto": "^1.14.19",
22
+ "@ocap/util": "^1.14.19",
23
+ "@ocap/wallet": "^1.14.19",
24
24
  "axios": "^0.25.0",
25
25
  "axios-mock-adapter": "^1.20.0",
26
26
  "axon": "^2.0.3",
@@ -41,7 +41,6 @@
41
41
  "semver-sort": "^0.0.4",
42
42
  "shelljs": "^0.8.4",
43
43
  "stream-to-promise": "^3.0.0",
44
- "systeminformation": "^5.6.12",
45
44
  "through2-filter": "^3.0.0",
46
45
  "through2-map": "^3.0.0",
47
46
  "to-semver": "^3.0.0",
@@ -54,5 +53,5 @@
54
53
  "fs-extra": "^10.0.0",
55
54
  "jest": "^27.4.5"
56
55
  },
57
- "gitHead": "18ac52a439dbd04e4ace98d796b6de517503fb14"
56
+ "gitHead": "bd2ad7d90fbd1b3786702dfca1ab28dcec9a7bc7"
58
57
  }
package/lib/sys-info.js DELETED
@@ -1,56 +0,0 @@
1
- const si = require('systeminformation');
2
-
3
- const systemConfig = {
4
- cpu: 'cores',
5
- mem: '*',
6
- currentLoad: '*',
7
- fsSize: '*',
8
- diskLayout: '*',
9
- osInfo: 'platform',
10
- };
11
-
12
- const get = async () => {
13
- const info = await si.get(systemConfig); // prettier-ignore
14
-
15
- // 物理磁盘。一些VM,或者Docker环境下无
16
- const physicalDisk = (info.diskLayout || []).filter((x) => Number(x.size) > 0);
17
- const fsSizeInfo = (info.fsSize || []).filter((x) => Number(x.size) > 0);
18
-
19
- // HACK 目前我们支持的系统是 Mac Vm Docker 如果支持windows 下面代码可能会有问题
20
- // 目前强制过滤出苹果文件系统(APFS) 其他的都是 mount 的文件系统
21
- // 这样有物理磁盘(Mac) 磁盘总计为 physicalDisk + mountFsSize
22
- // 无物理磁盘的 磁盘总计为 fsSizeInfo
23
- const mountFsSize = (info.fsSize || []).filter((x) => x.type.toUpperCase() !== 'APFS');
24
-
25
- const getTotalFn = (data, key) => data.reduce((total, x) => total + Number(x[key]), 0);
26
- const fsTotalFn = (key) => getTotalFn(fsSizeInfo, key);
27
-
28
- const baseSystemInfo = {
29
- cpu: {
30
- ...info.currentLoad,
31
- ...info.cpu,
32
- },
33
- mem: info.mem,
34
- osInfo: info.osInfo,
35
- };
36
-
37
- if (info.osInfo.platform === 'darwin') {
38
- return {
39
- ...baseSystemInfo,
40
- disk: {
41
- total: getTotalFn(physicalDisk, 'size') + getTotalFn(mountFsSize, 'size'),
42
- used: fsTotalFn('used'),
43
- },
44
- };
45
- }
46
-
47
- return {
48
- ...baseSystemInfo,
49
- disk: {
50
- total: fsTotalFn('size'),
51
- used: fsTotalFn('used'),
52
- },
53
- };
54
- };
55
-
56
- module.exports = { get };