@go-hare/claude-code 2.6.8 → 2.6.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/README.md +317 -317
- package/bin/claude.exe +11 -11
- package/cli-wrapper.cjs +103 -103
- package/install.cjs +187 -187
- package/package.json +240 -240
package/bin/claude.exe
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
echo "Error: claude native binary not installed." >&2
|
|
2
|
-
echo "" >&2
|
|
3
|
-
echo "Either postinstall did not run (--ignore-scripts, some pnpm configs)" >&2
|
|
4
|
-
echo "or the platform-native optional dependency was not downloaded" >&2
|
|
5
|
-
echo "(--omit=optional)." >&2
|
|
6
|
-
echo "" >&2
|
|
7
|
-
echo "Run the postinstall manually (adjust path for local vs global install):" >&2
|
|
8
|
-
echo " node node_modules/@go-hare/claude-code/install.cjs" >&2
|
|
9
|
-
echo "" >&2
|
|
10
|
-
echo "Or reinstall without --ignore-scripts / --omit=optional." >&2
|
|
11
|
-
exit 1
|
|
1
|
+
echo "Error: claude native binary not installed." >&2
|
|
2
|
+
echo "" >&2
|
|
3
|
+
echo "Either postinstall did not run (--ignore-scripts, some pnpm configs)" >&2
|
|
4
|
+
echo "or the platform-native optional dependency was not downloaded" >&2
|
|
5
|
+
echo "(--omit=optional)." >&2
|
|
6
|
+
echo "" >&2
|
|
7
|
+
echo "Run the postinstall manually (adjust path for local vs global install):" >&2
|
|
8
|
+
echo " node node_modules/@go-hare/claude-code/install.cjs" >&2
|
|
9
|
+
echo "" >&2
|
|
10
|
+
echo "Or reinstall without --ignore-scripts / --omit=optional." >&2
|
|
11
|
+
exit 1
|
package/cli-wrapper.cjs
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Fallback launcher for the claude wrapper package.
|
|
3
|
-
//
|
|
4
|
-
// Normally the postinstall script copies the native binary over bin/claude.exe,
|
|
5
|
-
// so this file is never invoked. It exists for environments where postinstall
|
|
6
|
-
// doesn't run (--ignore-scripts).
|
|
7
|
-
|
|
8
|
-
const { spawnSync } = require("child_process");
|
|
9
|
-
const { arch, constants } = require("os");
|
|
10
|
-
const path = require("path");
|
|
11
|
-
|
|
12
|
-
const PACKAGE_PREFIX = "@go-hare/claude-code";
|
|
13
|
-
const BINARY_NAME = "claude";
|
|
14
|
-
const WRAPPER_NAME = require("./package.json").name;
|
|
15
|
-
|
|
16
|
-
const PLATFORMS = {
|
|
17
|
-
"darwin-arm64": { pkg: PACKAGE_PREFIX + "-darwin-arm64", bin: BINARY_NAME },
|
|
18
|
-
"darwin-x64": { pkg: PACKAGE_PREFIX + "-darwin-x64", bin: BINARY_NAME },
|
|
19
|
-
"linux-x64": { pkg: PACKAGE_PREFIX + "-linux-x64", bin: BINARY_NAME },
|
|
20
|
-
"linux-arm64": { pkg: PACKAGE_PREFIX + "-linux-arm64", bin: BINARY_NAME },
|
|
21
|
-
"linux-x64-musl": {
|
|
22
|
-
pkg: PACKAGE_PREFIX + "-linux-x64-musl",
|
|
23
|
-
bin: BINARY_NAME,
|
|
24
|
-
},
|
|
25
|
-
"linux-arm64-musl": {
|
|
26
|
-
pkg: PACKAGE_PREFIX + "-linux-arm64-musl",
|
|
27
|
-
bin: BINARY_NAME,
|
|
28
|
-
},
|
|
29
|
-
"win32-x64": {
|
|
30
|
-
pkg: PACKAGE_PREFIX + "-win32-x64",
|
|
31
|
-
bin: BINARY_NAME + ".exe",
|
|
32
|
-
},
|
|
33
|
-
"win32-arm64": {
|
|
34
|
-
pkg: PACKAGE_PREFIX + "-win32-arm64",
|
|
35
|
-
bin: BINARY_NAME + ".exe",
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
function detectMusl() {
|
|
40
|
-
if (process.platform !== "linux") return false;
|
|
41
|
-
const report =
|
|
42
|
-
typeof process.report?.getReport === "function"
|
|
43
|
-
? process.report.getReport()
|
|
44
|
-
: null;
|
|
45
|
-
return report != null && report.header?.glibcVersionRuntime === undefined;
|
|
46
|
-
}
|
|
47
|
-
function getPlatformKey() {
|
|
48
|
-
const platform = process.platform;
|
|
49
|
-
let cpu = arch();
|
|
50
|
-
if (platform === "linux") return "linux-" + cpu + (detectMusl() ? "-musl" : "");
|
|
51
|
-
if (platform === "darwin" && cpu === "x64") {
|
|
52
|
-
const r = spawnSync("sysctl", ["-n", "sysctl.proc_translated"], {
|
|
53
|
-
encoding: "utf8",
|
|
54
|
-
});
|
|
55
|
-
if (r.stdout?.trim() === "1") cpu = "arm64";
|
|
56
|
-
}
|
|
57
|
-
return platform + "-" + cpu;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function getBinaryPath() {
|
|
61
|
-
const platformKey = getPlatformKey();
|
|
62
|
-
const info = PLATFORMS[platformKey];
|
|
63
|
-
if (!info) {
|
|
64
|
-
console.error(
|
|
65
|
-
`[${WRAPPER_NAME}] Unsupported platform: ${process.platform} ${arch()}`,
|
|
66
|
-
);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
const pkgDir = path.dirname(require.resolve(info.pkg + "/package.json"));
|
|
71
|
-
return path.join(pkgDir, info.bin);
|
|
72
|
-
} catch {
|
|
73
|
-
console.error(
|
|
74
|
-
`[${WRAPPER_NAME}] Could not find native binary package "${info.pkg}".`,
|
|
75
|
-
);
|
|
76
|
-
console.error(" Try reinstalling with: npm install");
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function main() {
|
|
82
|
-
const binaryPath = getBinaryPath();
|
|
83
|
-
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
|
84
|
-
stdio: "inherit",
|
|
85
|
-
env: { ...process.env, CLAUDE_CODE_INSTALLED_VIA_NPM_WRAPPER: "1" },
|
|
86
|
-
});
|
|
87
|
-
if (result.error) {
|
|
88
|
-
console.error(
|
|
89
|
-
`[${WRAPPER_NAME}] Failed to execute native binary at ` + binaryPath,
|
|
90
|
-
);
|
|
91
|
-
console.error(" " + result.error.message);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
if (result.signal) {
|
|
95
|
-
const signum = constants.signals[result.signal] ?? 0;
|
|
96
|
-
process.exit(128 + signum);
|
|
97
|
-
} else {
|
|
98
|
-
process.exit(result.status ?? 1);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
main();
|
|
103
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Fallback launcher for the claude wrapper package.
|
|
3
|
+
//
|
|
4
|
+
// Normally the postinstall script copies the native binary over bin/claude.exe,
|
|
5
|
+
// so this file is never invoked. It exists for environments where postinstall
|
|
6
|
+
// doesn't run (--ignore-scripts).
|
|
7
|
+
|
|
8
|
+
const { spawnSync } = require("child_process");
|
|
9
|
+
const { arch, constants } = require("os");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
|
|
12
|
+
const PACKAGE_PREFIX = "@go-hare/claude-code";
|
|
13
|
+
const BINARY_NAME = "claude";
|
|
14
|
+
const WRAPPER_NAME = require("./package.json").name;
|
|
15
|
+
|
|
16
|
+
const PLATFORMS = {
|
|
17
|
+
"darwin-arm64": { pkg: PACKAGE_PREFIX + "-darwin-arm64", bin: BINARY_NAME },
|
|
18
|
+
"darwin-x64": { pkg: PACKAGE_PREFIX + "-darwin-x64", bin: BINARY_NAME },
|
|
19
|
+
"linux-x64": { pkg: PACKAGE_PREFIX + "-linux-x64", bin: BINARY_NAME },
|
|
20
|
+
"linux-arm64": { pkg: PACKAGE_PREFIX + "-linux-arm64", bin: BINARY_NAME },
|
|
21
|
+
"linux-x64-musl": {
|
|
22
|
+
pkg: PACKAGE_PREFIX + "-linux-x64-musl",
|
|
23
|
+
bin: BINARY_NAME,
|
|
24
|
+
},
|
|
25
|
+
"linux-arm64-musl": {
|
|
26
|
+
pkg: PACKAGE_PREFIX + "-linux-arm64-musl",
|
|
27
|
+
bin: BINARY_NAME,
|
|
28
|
+
},
|
|
29
|
+
"win32-x64": {
|
|
30
|
+
pkg: PACKAGE_PREFIX + "-win32-x64",
|
|
31
|
+
bin: BINARY_NAME + ".exe",
|
|
32
|
+
},
|
|
33
|
+
"win32-arm64": {
|
|
34
|
+
pkg: PACKAGE_PREFIX + "-win32-arm64",
|
|
35
|
+
bin: BINARY_NAME + ".exe",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function detectMusl() {
|
|
40
|
+
if (process.platform !== "linux") return false;
|
|
41
|
+
const report =
|
|
42
|
+
typeof process.report?.getReport === "function"
|
|
43
|
+
? process.report.getReport()
|
|
44
|
+
: null;
|
|
45
|
+
return report != null && report.header?.glibcVersionRuntime === undefined;
|
|
46
|
+
}
|
|
47
|
+
function getPlatformKey() {
|
|
48
|
+
const platform = process.platform;
|
|
49
|
+
let cpu = arch();
|
|
50
|
+
if (platform === "linux") return "linux-" + cpu + (detectMusl() ? "-musl" : "");
|
|
51
|
+
if (platform === "darwin" && cpu === "x64") {
|
|
52
|
+
const r = spawnSync("sysctl", ["-n", "sysctl.proc_translated"], {
|
|
53
|
+
encoding: "utf8",
|
|
54
|
+
});
|
|
55
|
+
if (r.stdout?.trim() === "1") cpu = "arm64";
|
|
56
|
+
}
|
|
57
|
+
return platform + "-" + cpu;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getBinaryPath() {
|
|
61
|
+
const platformKey = getPlatformKey();
|
|
62
|
+
const info = PLATFORMS[platformKey];
|
|
63
|
+
if (!info) {
|
|
64
|
+
console.error(
|
|
65
|
+
`[${WRAPPER_NAME}] Unsupported platform: ${process.platform} ${arch()}`,
|
|
66
|
+
);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const pkgDir = path.dirname(require.resolve(info.pkg + "/package.json"));
|
|
71
|
+
return path.join(pkgDir, info.bin);
|
|
72
|
+
} catch {
|
|
73
|
+
console.error(
|
|
74
|
+
`[${WRAPPER_NAME}] Could not find native binary package "${info.pkg}".`,
|
|
75
|
+
);
|
|
76
|
+
console.error(" Try reinstalling with: npm install");
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function main() {
|
|
82
|
+
const binaryPath = getBinaryPath();
|
|
83
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
|
84
|
+
stdio: "inherit",
|
|
85
|
+
env: { ...process.env, CLAUDE_CODE_INSTALLED_VIA_NPM_WRAPPER: "1" },
|
|
86
|
+
});
|
|
87
|
+
if (result.error) {
|
|
88
|
+
console.error(
|
|
89
|
+
`[${WRAPPER_NAME}] Failed to execute native binary at ` + binaryPath,
|
|
90
|
+
);
|
|
91
|
+
console.error(" " + result.error.message);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
if (result.signal) {
|
|
95
|
+
const signum = constants.signals[result.signal] ?? 0;
|
|
96
|
+
process.exit(128 + signum);
|
|
97
|
+
} else {
|
|
98
|
+
process.exit(result.status ?? 1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
main();
|
|
103
|
+
|
package/install.cjs
CHANGED
|
@@ -1,187 +1,187 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Postinstall for the claude wrapper package.
|
|
3
|
-
//
|
|
4
|
-
// In development (monorepo with .git), delegates to the dev postinstall scripts.
|
|
5
|
-
// In production (npm install from registry), copies the native binary from the
|
|
6
|
-
// platform-specific optionalDependency into bin/claude.exe.
|
|
7
|
-
//
|
|
8
|
-
// Platform detection + PLATFORMS map is duplicated in cli-wrapper.cjs — keep in sync.
|
|
9
|
-
|
|
10
|
-
const { spawnSync } = require("child_process");
|
|
11
|
-
const {
|
|
12
|
-
copyFileSync,
|
|
13
|
-
existsSync,
|
|
14
|
-
linkSync,
|
|
15
|
-
unlinkSync,
|
|
16
|
-
chmodSync,
|
|
17
|
-
readFileSync,
|
|
18
|
-
writeFileSync,
|
|
19
|
-
statSync,
|
|
20
|
-
} = require("fs");
|
|
21
|
-
const { arch } = require("os");
|
|
22
|
-
const path = require("path");
|
|
23
|
-
|
|
24
|
-
// Dev environment detection: if .git exists at package root, we're in the monorepo
|
|
25
|
-
if (existsSync(path.join(__dirname, ".git"))) {
|
|
26
|
-
const r = spawnSync(
|
|
27
|
-
"node",
|
|
28
|
-
[
|
|
29
|
-
"scripts/run-parallel.mjs",
|
|
30
|
-
"scripts/postinstall.cjs",
|
|
31
|
-
"scripts/setup-chrome-mcp.mjs",
|
|
32
|
-
],
|
|
33
|
-
{ cwd: __dirname, stdio: "inherit" },
|
|
34
|
-
);
|
|
35
|
-
process.exit(r.status ?? 0);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const PACKAGE_PREFIX = "@go-hare/claude-code";
|
|
39
|
-
const BINARY_NAME = "claude";
|
|
40
|
-
const WRAPPER_NAME = require("./package.json").name;
|
|
41
|
-
|
|
42
|
-
const PLATFORMS = {
|
|
43
|
-
"darwin-arm64": { pkg: PACKAGE_PREFIX + "-darwin-arm64", bin: BINARY_NAME },
|
|
44
|
-
"darwin-x64": { pkg: PACKAGE_PREFIX + "-darwin-x64", bin: BINARY_NAME },
|
|
45
|
-
"linux-x64": { pkg: PACKAGE_PREFIX + "-linux-x64", bin: BINARY_NAME },
|
|
46
|
-
"linux-arm64": { pkg: PACKAGE_PREFIX + "-linux-arm64", bin: BINARY_NAME },
|
|
47
|
-
"linux-x64-musl": {
|
|
48
|
-
pkg: PACKAGE_PREFIX + "-linux-x64-musl",
|
|
49
|
-
bin: BINARY_NAME,
|
|
50
|
-
},
|
|
51
|
-
"linux-arm64-musl": {
|
|
52
|
-
pkg: PACKAGE_PREFIX + "-linux-arm64-musl",
|
|
53
|
-
bin: BINARY_NAME,
|
|
54
|
-
},
|
|
55
|
-
"linux-arm64-android": {
|
|
56
|
-
pkg: PACKAGE_PREFIX + "-linux-arm64-android",
|
|
57
|
-
bin: BINARY_NAME,
|
|
58
|
-
},
|
|
59
|
-
"linux-x64-android": {
|
|
60
|
-
pkg: PACKAGE_PREFIX + "-linux-x64-android",
|
|
61
|
-
bin: BINARY_NAME,
|
|
62
|
-
},
|
|
63
|
-
"freebsd-x64": { pkg: PACKAGE_PREFIX + "-freebsd-x64", bin: BINARY_NAME },
|
|
64
|
-
"freebsd-arm64": {
|
|
65
|
-
pkg: PACKAGE_PREFIX + "-freebsd-arm64",
|
|
66
|
-
bin: BINARY_NAME,
|
|
67
|
-
},
|
|
68
|
-
"win32-x64": {
|
|
69
|
-
pkg: PACKAGE_PREFIX + "-win32-x64",
|
|
70
|
-
bin: BINARY_NAME + ".exe",
|
|
71
|
-
},
|
|
72
|
-
"win32-arm64": {
|
|
73
|
-
pkg: PACKAGE_PREFIX + "-win32-arm64",
|
|
74
|
-
bin: BINARY_NAME + ".exe",
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
function detectMusl() {
|
|
79
|
-
if (process.platform !== "linux") return false;
|
|
80
|
-
const report =
|
|
81
|
-
typeof process.report?.getReport === "function"
|
|
82
|
-
? process.report.getReport()
|
|
83
|
-
: null;
|
|
84
|
-
return report != null && report.header?.glibcVersionRuntime === undefined;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function getPlatformKey() {
|
|
88
|
-
const platform = process.platform;
|
|
89
|
-
let cpu = arch();
|
|
90
|
-
if (platform === "android") return "linux-" + cpu + "-android";
|
|
91
|
-
if (platform === "linux") return "linux-" + cpu + (detectMusl() ? "-musl" : "");
|
|
92
|
-
if (platform === "darwin" && cpu === "x64") {
|
|
93
|
-
const r = spawnSync("sysctl", ["-n", "sysctl.proc_translated"], {
|
|
94
|
-
encoding: "utf8",
|
|
95
|
-
});
|
|
96
|
-
if (r.stdout?.trim() === "1") cpu = "arm64";
|
|
97
|
-
}
|
|
98
|
-
return platform + "-" + cpu;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function placeBinary(src, dest) {
|
|
102
|
-
try {
|
|
103
|
-
linkSync(src, dest);
|
|
104
|
-
} catch (err) {
|
|
105
|
-
if (err.code === "EEXIST") {
|
|
106
|
-
const stub = statSync(dest).size < 4096 ? readFileSync(dest) : null;
|
|
107
|
-
unlinkSync(dest);
|
|
108
|
-
try {
|
|
109
|
-
linkSync(src, dest);
|
|
110
|
-
} catch {
|
|
111
|
-
try {
|
|
112
|
-
copyFileSync(src, dest);
|
|
113
|
-
} catch (copyErr) {
|
|
114
|
-
if (stub) {
|
|
115
|
-
try { writeFileSync(dest, stub, { mode: 0o755 }); } catch {}
|
|
116
|
-
}
|
|
117
|
-
throw copyErr;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
} else if (err.code === "EXDEV" || err.code === "EPERM") {
|
|
121
|
-
copyFileSync(src, dest);
|
|
122
|
-
} else {
|
|
123
|
-
throw err;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (process.platform !== "win32") chmodSync(dest, 0o755);
|
|
127
|
-
}
|
|
128
|
-
function main() {
|
|
129
|
-
const platformKey = getPlatformKey();
|
|
130
|
-
const info = PLATFORMS[platformKey];
|
|
131
|
-
|
|
132
|
-
if (!info) {
|
|
133
|
-
console.error(
|
|
134
|
-
`[${WRAPPER_NAME} postinstall] Unsupported platform: ${process.platform} ${arch()}`,
|
|
135
|
-
);
|
|
136
|
-
console.error(` Supported: ${Object.keys(PLATFORMS).join(", ")}`);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const optionalDeps = require("./package.json").optionalDependencies || {};
|
|
141
|
-
if (!optionalDeps[info.pkg]) {
|
|
142
|
-
console.error(
|
|
143
|
-
`[${WRAPPER_NAME} postinstall] Native binaries for ${platformKey} are not available on this release channel.`,
|
|
144
|
-
);
|
|
145
|
-
console.error(
|
|
146
|
-
` Available: ${Object.keys(optionalDeps).map((p) => p.replace(PACKAGE_PREFIX + "-", "")).join(", ")}`,
|
|
147
|
-
);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
let src;
|
|
152
|
-
try {
|
|
153
|
-
const pkgDir = path.dirname(require.resolve(info.pkg + "/package.json"));
|
|
154
|
-
src = path.join(pkgDir, info.bin);
|
|
155
|
-
} catch {
|
|
156
|
-
console.error(
|
|
157
|
-
`[${WRAPPER_NAME} postinstall] Native package "${info.pkg}" not found.`,
|
|
158
|
-
);
|
|
159
|
-
console.error(
|
|
160
|
-
" This happens with --omit=optional or when the download failed.",
|
|
161
|
-
);
|
|
162
|
-
console.error(
|
|
163
|
-
" The `claude` command will print instructions when invoked.",
|
|
164
|
-
);
|
|
165
|
-
console.error(
|
|
166
|
-
" Fallback: node " + path.join(__dirname, "cli-wrapper.cjs"),
|
|
167
|
-
);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const dest = path.join(__dirname, "bin", "claude.exe");
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
placeBinary(src, dest);
|
|
175
|
-
} catch (err) {
|
|
176
|
-
console.error(
|
|
177
|
-
`[${WRAPPER_NAME} postinstall] Failed to place binary: ${err.message}`,
|
|
178
|
-
);
|
|
179
|
-
console.error(
|
|
180
|
-
" Fallback: node " + path.join(__dirname, "cli-wrapper.cjs"),
|
|
181
|
-
);
|
|
182
|
-
process.exitCode = 1;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
main();
|
|
187
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Postinstall for the claude wrapper package.
|
|
3
|
+
//
|
|
4
|
+
// In development (monorepo with .git), delegates to the dev postinstall scripts.
|
|
5
|
+
// In production (npm install from registry), copies the native binary from the
|
|
6
|
+
// platform-specific optionalDependency into bin/claude.exe.
|
|
7
|
+
//
|
|
8
|
+
// Platform detection + PLATFORMS map is duplicated in cli-wrapper.cjs — keep in sync.
|
|
9
|
+
|
|
10
|
+
const { spawnSync } = require("child_process");
|
|
11
|
+
const {
|
|
12
|
+
copyFileSync,
|
|
13
|
+
existsSync,
|
|
14
|
+
linkSync,
|
|
15
|
+
unlinkSync,
|
|
16
|
+
chmodSync,
|
|
17
|
+
readFileSync,
|
|
18
|
+
writeFileSync,
|
|
19
|
+
statSync,
|
|
20
|
+
} = require("fs");
|
|
21
|
+
const { arch } = require("os");
|
|
22
|
+
const path = require("path");
|
|
23
|
+
|
|
24
|
+
// Dev environment detection: if .git exists at package root, we're in the monorepo
|
|
25
|
+
if (existsSync(path.join(__dirname, ".git"))) {
|
|
26
|
+
const r = spawnSync(
|
|
27
|
+
"node",
|
|
28
|
+
[
|
|
29
|
+
"scripts/run-parallel.mjs",
|
|
30
|
+
"scripts/postinstall.cjs",
|
|
31
|
+
"scripts/setup-chrome-mcp.mjs",
|
|
32
|
+
],
|
|
33
|
+
{ cwd: __dirname, stdio: "inherit" },
|
|
34
|
+
);
|
|
35
|
+
process.exit(r.status ?? 0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const PACKAGE_PREFIX = "@go-hare/claude-code";
|
|
39
|
+
const BINARY_NAME = "claude";
|
|
40
|
+
const WRAPPER_NAME = require("./package.json").name;
|
|
41
|
+
|
|
42
|
+
const PLATFORMS = {
|
|
43
|
+
"darwin-arm64": { pkg: PACKAGE_PREFIX + "-darwin-arm64", bin: BINARY_NAME },
|
|
44
|
+
"darwin-x64": { pkg: PACKAGE_PREFIX + "-darwin-x64", bin: BINARY_NAME },
|
|
45
|
+
"linux-x64": { pkg: PACKAGE_PREFIX + "-linux-x64", bin: BINARY_NAME },
|
|
46
|
+
"linux-arm64": { pkg: PACKAGE_PREFIX + "-linux-arm64", bin: BINARY_NAME },
|
|
47
|
+
"linux-x64-musl": {
|
|
48
|
+
pkg: PACKAGE_PREFIX + "-linux-x64-musl",
|
|
49
|
+
bin: BINARY_NAME,
|
|
50
|
+
},
|
|
51
|
+
"linux-arm64-musl": {
|
|
52
|
+
pkg: PACKAGE_PREFIX + "-linux-arm64-musl",
|
|
53
|
+
bin: BINARY_NAME,
|
|
54
|
+
},
|
|
55
|
+
"linux-arm64-android": {
|
|
56
|
+
pkg: PACKAGE_PREFIX + "-linux-arm64-android",
|
|
57
|
+
bin: BINARY_NAME,
|
|
58
|
+
},
|
|
59
|
+
"linux-x64-android": {
|
|
60
|
+
pkg: PACKAGE_PREFIX + "-linux-x64-android",
|
|
61
|
+
bin: BINARY_NAME,
|
|
62
|
+
},
|
|
63
|
+
"freebsd-x64": { pkg: PACKAGE_PREFIX + "-freebsd-x64", bin: BINARY_NAME },
|
|
64
|
+
"freebsd-arm64": {
|
|
65
|
+
pkg: PACKAGE_PREFIX + "-freebsd-arm64",
|
|
66
|
+
bin: BINARY_NAME,
|
|
67
|
+
},
|
|
68
|
+
"win32-x64": {
|
|
69
|
+
pkg: PACKAGE_PREFIX + "-win32-x64",
|
|
70
|
+
bin: BINARY_NAME + ".exe",
|
|
71
|
+
},
|
|
72
|
+
"win32-arm64": {
|
|
73
|
+
pkg: PACKAGE_PREFIX + "-win32-arm64",
|
|
74
|
+
bin: BINARY_NAME + ".exe",
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function detectMusl() {
|
|
79
|
+
if (process.platform !== "linux") return false;
|
|
80
|
+
const report =
|
|
81
|
+
typeof process.report?.getReport === "function"
|
|
82
|
+
? process.report.getReport()
|
|
83
|
+
: null;
|
|
84
|
+
return report != null && report.header?.glibcVersionRuntime === undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getPlatformKey() {
|
|
88
|
+
const platform = process.platform;
|
|
89
|
+
let cpu = arch();
|
|
90
|
+
if (platform === "android") return "linux-" + cpu + "-android";
|
|
91
|
+
if (platform === "linux") return "linux-" + cpu + (detectMusl() ? "-musl" : "");
|
|
92
|
+
if (platform === "darwin" && cpu === "x64") {
|
|
93
|
+
const r = spawnSync("sysctl", ["-n", "sysctl.proc_translated"], {
|
|
94
|
+
encoding: "utf8",
|
|
95
|
+
});
|
|
96
|
+
if (r.stdout?.trim() === "1") cpu = "arm64";
|
|
97
|
+
}
|
|
98
|
+
return platform + "-" + cpu;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function placeBinary(src, dest) {
|
|
102
|
+
try {
|
|
103
|
+
linkSync(src, dest);
|
|
104
|
+
} catch (err) {
|
|
105
|
+
if (err.code === "EEXIST") {
|
|
106
|
+
const stub = statSync(dest).size < 4096 ? readFileSync(dest) : null;
|
|
107
|
+
unlinkSync(dest);
|
|
108
|
+
try {
|
|
109
|
+
linkSync(src, dest);
|
|
110
|
+
} catch {
|
|
111
|
+
try {
|
|
112
|
+
copyFileSync(src, dest);
|
|
113
|
+
} catch (copyErr) {
|
|
114
|
+
if (stub) {
|
|
115
|
+
try { writeFileSync(dest, stub, { mode: 0o755 }); } catch {}
|
|
116
|
+
}
|
|
117
|
+
throw copyErr;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} else if (err.code === "EXDEV" || err.code === "EPERM") {
|
|
121
|
+
copyFileSync(src, dest);
|
|
122
|
+
} else {
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (process.platform !== "win32") chmodSync(dest, 0o755);
|
|
127
|
+
}
|
|
128
|
+
function main() {
|
|
129
|
+
const platformKey = getPlatformKey();
|
|
130
|
+
const info = PLATFORMS[platformKey];
|
|
131
|
+
|
|
132
|
+
if (!info) {
|
|
133
|
+
console.error(
|
|
134
|
+
`[${WRAPPER_NAME} postinstall] Unsupported platform: ${process.platform} ${arch()}`,
|
|
135
|
+
);
|
|
136
|
+
console.error(` Supported: ${Object.keys(PLATFORMS).join(", ")}`);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const optionalDeps = require("./package.json").optionalDependencies || {};
|
|
141
|
+
if (!optionalDeps[info.pkg]) {
|
|
142
|
+
console.error(
|
|
143
|
+
`[${WRAPPER_NAME} postinstall] Native binaries for ${platformKey} are not available on this release channel.`,
|
|
144
|
+
);
|
|
145
|
+
console.error(
|
|
146
|
+
` Available: ${Object.keys(optionalDeps).map((p) => p.replace(PACKAGE_PREFIX + "-", "")).join(", ")}`,
|
|
147
|
+
);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let src;
|
|
152
|
+
try {
|
|
153
|
+
const pkgDir = path.dirname(require.resolve(info.pkg + "/package.json"));
|
|
154
|
+
src = path.join(pkgDir, info.bin);
|
|
155
|
+
} catch {
|
|
156
|
+
console.error(
|
|
157
|
+
`[${WRAPPER_NAME} postinstall] Native package "${info.pkg}" not found.`,
|
|
158
|
+
);
|
|
159
|
+
console.error(
|
|
160
|
+
" This happens with --omit=optional or when the download failed.",
|
|
161
|
+
);
|
|
162
|
+
console.error(
|
|
163
|
+
" The `claude` command will print instructions when invoked.",
|
|
164
|
+
);
|
|
165
|
+
console.error(
|
|
166
|
+
" Fallback: node " + path.join(__dirname, "cli-wrapper.cjs"),
|
|
167
|
+
);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const dest = path.join(__dirname, "bin", "claude.exe");
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
placeBinary(src, dest);
|
|
175
|
+
} catch (err) {
|
|
176
|
+
console.error(
|
|
177
|
+
`[${WRAPPER_NAME} postinstall] Failed to place binary: ${err.message}`,
|
|
178
|
+
);
|
|
179
|
+
console.error(
|
|
180
|
+
" Fallback: node " + path.join(__dirname, "cli-wrapper.cjs"),
|
|
181
|
+
);
|
|
182
|
+
process.exitCode = 1;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
main();
|
|
187
|
+
|