@agentfare/forge 0.2.0 → 0.2.2

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 (2) hide show
  1. package/install.js +28 -27
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -28,21 +28,27 @@ function getBinaryName() {
28
28
  }
29
29
 
30
30
  async function download(url, dest) {
31
- const res = await new Promise((resolve, reject) => {
32
- https
33
- .get(url, { timeout: 30000 }, (res) => {
34
- if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
35
- return download(res.headers.location, dest).then(resolve).catch(reject);
36
- }
37
- if (res.statusCode !== 200) {
38
- return reject(new Error(`Download failed: HTTP ${res.statusCode}`));
39
- }
40
- resolve(res);
41
- })
42
- .on("error", reject);
43
- });
44
-
45
- await pipeline(res, createWriteStream(dest));
31
+ let currentUrl = url;
32
+ while (true) {
33
+ const res = await new Promise((resolve, reject) => {
34
+ https
35
+ .get(currentUrl, { timeout: 30000 }, resolve)
36
+ .on("error", reject);
37
+ });
38
+
39
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
40
+ res.destroy();
41
+ currentUrl = res.headers.location;
42
+ continue;
43
+ }
44
+ if (res.statusCode !== 200) {
45
+ res.destroy();
46
+ throw new Error(`Download failed: HTTP ${res.statusCode}`);
47
+ }
48
+
49
+ await pipeline(res, createWriteStream(dest));
50
+ return;
51
+ }
46
52
  }
47
53
 
48
54
  async function main() {
@@ -50,8 +56,7 @@ async function main() {
50
56
  fs.mkdirSync(binDir, { recursive: true });
51
57
 
52
58
  const { goos, goarch } = getPlatform();
53
- const ext = goos === "windows" ? "zip" : "tar.gz";
54
- const archiveName = `forge_${VERSION}_${goos}_${goarch}.${ext}`;
59
+ const archiveName = `forge_${VERSION}_${goos}_${goarch}.tar.gz`;
55
60
  const url = `https://github.com/MjxUpUp/forge/releases/download/v${VERSION}/${archiveName}`;
56
61
 
57
62
  const archivePath = path.join(binDir, archiveName);
@@ -60,16 +65,12 @@ async function main() {
60
65
  await download(url, archivePath);
61
66
  console.log(`Downloaded to ${archivePath}`);
62
67
 
63
- // Extract
64
- if (ext === "zip") {
65
- if (process.platform === "win32") {
66
- execSync(`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${binDir}' -Force"`, { stdio: "inherit" });
67
- } else {
68
- execSync(`unzip -o "${archivePath}" -d "${binDir}"`, { stdio: "inherit" });
69
- }
70
- } else {
71
- execSync(`tar xzf "${archivePath}" -C "${binDir}"`, { stdio: "inherit" });
72
- }
68
+ // Extract (tar.gz works on all platforms: Linux, macOS, Windows 10+)
69
+ // Normalize backslashes to forward slashes for tar compatibility on Windows
70
+ // --force-local prevents GNU tar from treating "X:/path" as a remote host
71
+ const normArchivePath = archivePath.replace(/\\/g, "/");
72
+ const normBinDir = binDir.replace(/\\/g, "/");
73
+ execSync(`tar xzf "${normArchivePath}" -C "${normBinDir}" --force-local`, { stdio: "inherit" });
73
74
 
74
75
  // Make executable
75
76
  const binaryName = getBinaryName();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentfare/forge",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "AI 开发质量门禁引擎 — 结构化门禁管道,在 AI 生成的代码进入仓库前进行质量锻造",
5
5
  "bin": {
6
6
  "forge": "run.js"