@xcanwin/manyoyo 3.8.2 → 3.8.3
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/bin/manyoyo.js +15 -2
- package/package.json +1 -1
package/bin/manyoyo.js
CHANGED
|
@@ -8,6 +8,7 @@ const { execSync, spawnSync } = require('child_process');
|
|
|
8
8
|
const fs = require('fs');
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const os = require('os');
|
|
11
|
+
const crypto = require('crypto');
|
|
11
12
|
const readline = require('readline');
|
|
12
13
|
const { Command } = require('commander');
|
|
13
14
|
const JSON5 = require('json5');
|
|
@@ -76,6 +77,18 @@ function sleep(ms) {
|
|
|
76
77
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
/**
|
|
81
|
+
* 计算文件的 SHA256 哈希值(跨平台)
|
|
82
|
+
* @param {string} filePath - 文件路径
|
|
83
|
+
* @returns {string} SHA256 哈希值(十六进制)
|
|
84
|
+
*/
|
|
85
|
+
function getFileSha256(filePath) {
|
|
86
|
+
const fileBuffer = fs.readFileSync(filePath);
|
|
87
|
+
const hashSum = crypto.createHash('sha256');
|
|
88
|
+
hashSum.update(fileBuffer);
|
|
89
|
+
return hashSum.digest('hex');
|
|
90
|
+
}
|
|
91
|
+
|
|
79
92
|
/**
|
|
80
93
|
* 敏感信息脱敏(用于 --show-config 输出)
|
|
81
94
|
* @param {Object} obj - 配置对象
|
|
@@ -614,8 +627,8 @@ async function prepareBuildCache(imageTool) {
|
|
|
614
627
|
// 下载文件
|
|
615
628
|
runCmd('curl', ['-fsSL', nodeUrl, '-o', nodeTargetPath], { stdio: 'inherit' });
|
|
616
629
|
|
|
617
|
-
// SHA256
|
|
618
|
-
const actualHash =
|
|
630
|
+
// SHA256 校验(使用 Node.js crypto 模块,跨平台)
|
|
631
|
+
const actualHash = getFileSha256(nodeTargetPath);
|
|
619
632
|
if (actualHash !== expectedHash) {
|
|
620
633
|
console.log(`${RED}SHA256 校验失败,删除文件${NC}`);
|
|
621
634
|
fs.unlinkSync(nodeTargetPath);
|