@hayasaka7/go-arch-xray 0.5.9 → 0.5.10
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/go-arch-xray.js +61 -30
- package/install.js +18 -2
- package/package.json +1 -1
package/bin/go-arch-xray.js
CHANGED
|
@@ -1,46 +1,77 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Thin launcher: locates the platform-specific go-arch-xray binary downloaded
|
|
3
|
-
// by install.js (or pointed to by GO_ARCH_XRAY_BIN) and execs it with the
|
|
4
|
-
// caller's argv, inheriting stdio and exit code.
|
|
5
|
-
|
|
6
2
|
"use strict";
|
|
7
3
|
|
|
8
|
-
const fs = require("fs");
|
|
9
|
-
const path = require("path");
|
|
10
4
|
const { spawnSync } = require("child_process");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
|
|
9
|
+
// Resolve package.json from the package root (not bin directory)
|
|
10
|
+
const pkgPath = path.join(__dirname, "..", "package.json");
|
|
11
|
+
const pkg = require(pkgPath);
|
|
12
|
+
const VERSION = pkg.version;
|
|
13
|
+
const TAG = `v${VERSION}`;
|
|
14
|
+
|
|
15
|
+
const PLATFORM_MAP = {
|
|
16
|
+
"win32-x64": { goos: "windows", goarch: "amd64", ext: ".exe" },
|
|
17
|
+
"win32-arm64": { goos: "windows", goarch: "arm64", ext: ".exe" },
|
|
18
|
+
"darwin-x64": { goos: "darwin", goarch: "amd64", ext: "" },
|
|
19
|
+
"darwin-arm64": { goos: "darwin", goarch: "arm64", ext: "" },
|
|
20
|
+
"linux-x64": { goos: "linux", goarch: "amd64", ext: "" },
|
|
21
|
+
"linux-arm64": { goos: "linux", goarch: "arm64", ext: "" },
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function log(msg) {
|
|
25
|
+
process.stderr.write(`[go-arch-xray] ${msg}\n`);
|
|
26
|
+
}
|
|
11
27
|
|
|
12
|
-
|
|
28
|
+
function detectTarget() {
|
|
29
|
+
const key = `${process.platform}-${process.arch}`;
|
|
30
|
+
const target = PLATFORM_MAP[key];
|
|
31
|
+
if (!target) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Unsupported platform ${key}. Supported: ${Object.keys(PLATFORM_MAP).join(", ")}.\n` +
|
|
34
|
+
`Build from source: https://github.com/HAYASAKA7/go-arch-xray#build-from-source`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return target;
|
|
38
|
+
}
|
|
13
39
|
|
|
14
|
-
function
|
|
40
|
+
function getBinaryPath() {
|
|
41
|
+
// Check for GO_ARCH_XRAY_BIN override first
|
|
15
42
|
if (process.env.GO_ARCH_XRAY_BIN) {
|
|
16
43
|
return process.env.GO_ARCH_XRAY_BIN;
|
|
17
44
|
}
|
|
18
|
-
const ext = process.platform === "win32" ? ".exe" : "";
|
|
19
|
-
return path.join(__dirname, `go-arch-xray${ext}`);
|
|
20
|
-
}
|
|
21
45
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
`[go-arch-xray] binary not found at ${binPath}\n` +
|
|
27
|
-
`The npm postinstall step did not run or failed.\n` +
|
|
28
|
-
`Try one of:\n` +
|
|
29
|
-
` npm rebuild @hayasaka7/go-arch-xray\n` +
|
|
30
|
-
` download the asset manually from https://github.com/${REPO}/releases and set GO_ARCH_XRAY_BIN\n`
|
|
31
|
-
);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
46
|
+
const target = detectTarget();
|
|
47
|
+
const binaryName = `go-arch-xray-${target.goos}-${target.goarch}${target.ext}`;
|
|
48
|
+
const binDir = path.join(__dirname, "bin");
|
|
49
|
+
const binPath = path.join(binDir, binaryName);
|
|
34
50
|
|
|
35
|
-
|
|
51
|
+
if (!fs.existsSync(binPath)) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Binary not found at ${binPath}.\n` +
|
|
54
|
+
`Run 'npm rebuild @hayasaka7/go-arch-xray' to re-download, or set GO_ARCH_XRAY_BIN to an existing binary path.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
36
57
|
|
|
37
|
-
|
|
38
|
-
process.stderr.write(`[go-arch-xray] failed to spawn binary: ${result.error.message}\n`);
|
|
39
|
-
process.exit(1);
|
|
58
|
+
return binPath;
|
|
40
59
|
}
|
|
41
60
|
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
function main() {
|
|
62
|
+
const binPath = getBinaryPath();
|
|
63
|
+
const args = process.argv.slice(2);
|
|
64
|
+
|
|
65
|
+
const result = spawnSync(binPath, args, {
|
|
66
|
+
stdio: "inherit",
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (result.error) {
|
|
70
|
+
log(`Failed to launch: ${result.error.message}`);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
process.exit(result.status ?? 0);
|
|
44
75
|
}
|
|
45
76
|
|
|
46
|
-
|
|
77
|
+
main();
|
package/install.js
CHANGED
|
@@ -128,8 +128,22 @@ async function main() {
|
|
|
128
128
|
const target = detectTarget();
|
|
129
129
|
const { binDir, binPath } = binaryPath(target);
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
// Check for version mismatch on upgrades
|
|
132
|
+
const versionFilePath = path.join(binDir, "version.txt");
|
|
133
|
+
let needsDownload = true;
|
|
134
|
+
if (fs.existsSync(binPath) && fs.existsSync(versionFilePath)) {
|
|
135
|
+
const installedVersion = fs.readFileSync(versionFilePath, "utf8").trim();
|
|
136
|
+
if (installedVersion === VERSION) {
|
|
137
|
+
log(`binary already present at ${binPath}; skipping download.`);
|
|
138
|
+
needsDownload = false;
|
|
139
|
+
} else {
|
|
140
|
+
log(`upgrading from ${installedVersion} to ${VERSION}`);
|
|
141
|
+
}
|
|
142
|
+
} else if (fs.existsSync(binPath)) {
|
|
143
|
+
log(`binary exists but no version file; re-downloading ${VERSION}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!needsDownload) {
|
|
133
147
|
return;
|
|
134
148
|
}
|
|
135
149
|
|
|
@@ -163,6 +177,8 @@ async function main() {
|
|
|
163
177
|
if (process.platform !== "win32") {
|
|
164
178
|
fs.chmodSync(binPath, 0o755);
|
|
165
179
|
}
|
|
180
|
+
// Write version file for upgrade detection
|
|
181
|
+
fs.writeFileSync(versionFilePath, VERSION, "utf8");
|
|
166
182
|
log(`installed ${binPath}`);
|
|
167
183
|
} catch (err) {
|
|
168
184
|
fail(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hayasaka7/go-arch-xray",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"description": "Model Context Protocol server for static analysis of Go codebases (call graphs, import graphs, interface topology, struct lifecycle, endpoints, maintainability metrics, and repo-aware config).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|