hanzo-node 0.6.50 → 0.6.51
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/package.json +6 -6
- package/postinstall.js +117 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hanzo-node",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.51",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Hanzo Dev CLI - AI-powered development assistant for Node.js projects",
|
|
6
6
|
"bin": {
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"prettier": "^3.3.3"
|
|
46
46
|
},
|
|
47
47
|
"optionalDependencies": {
|
|
48
|
-
"hanzo-node-darwin-arm64": "0.6.
|
|
49
|
-
"hanzo-node-darwin-x64": "0.6.
|
|
50
|
-
"hanzo-node-linux-x64-musl": "0.6.
|
|
51
|
-
"hanzo-node-linux-arm64-musl": "0.6.
|
|
52
|
-
"hanzo-node-win32-x64": "0.6.
|
|
48
|
+
"hanzo-node-darwin-arm64": "0.6.51",
|
|
49
|
+
"hanzo-node-darwin-x64": "0.6.51",
|
|
50
|
+
"hanzo-node-linux-x64-musl": "0.6.51",
|
|
51
|
+
"hanzo-node-linux-arm64-musl": "0.6.51",
|
|
52
|
+
"hanzo-node-win32-x64": "0.6.51"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/postinstall.js
CHANGED
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
import { platform as nodePlatform, arch as nodeArch } from "os";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
existsSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
copyFileSync,
|
|
10
|
+
chmodSync,
|
|
11
|
+
readFileSync,
|
|
12
|
+
unlinkSync,
|
|
13
|
+
createWriteStream,
|
|
14
|
+
} from "fs";
|
|
7
15
|
import { execSync } from "child_process";
|
|
8
16
|
import { get as httpsGet } from "https";
|
|
9
17
|
|
|
@@ -79,38 +87,45 @@ const getCacheDir = (version) => {
|
|
|
79
87
|
return dir;
|
|
80
88
|
};
|
|
81
89
|
|
|
82
|
-
const httpsDownload = (url, dest) =>
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
const httpsDownload = (url, dest) =>
|
|
91
|
+
new Promise((resolve, reject) => {
|
|
92
|
+
const req = httpsGet(url, (res) => {
|
|
93
|
+
const status = res.statusCode || 0;
|
|
94
|
+
if (status >= 300 && status < 400 && res.headers.location) {
|
|
95
|
+
return resolve(httpsDownload(res.headers.location, dest));
|
|
96
|
+
}
|
|
97
|
+
if (status !== 200) {
|
|
98
|
+
return reject(new Error(`HTTP ${status}`));
|
|
99
|
+
}
|
|
100
|
+
const out = createWriteStream(dest);
|
|
101
|
+
res.pipe(out);
|
|
102
|
+
out.on("finish", () => out.close(resolve));
|
|
103
|
+
out.on("error", (e) => {
|
|
104
|
+
try {
|
|
105
|
+
unlinkSync(dest);
|
|
106
|
+
} catch {}
|
|
107
|
+
reject(e);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
req.on("error", (e) => {
|
|
111
|
+
try {
|
|
112
|
+
unlinkSync(dest);
|
|
113
|
+
} catch {}
|
|
96
114
|
reject(e);
|
|
97
115
|
});
|
|
116
|
+
req.setTimeout(120000, () => {
|
|
117
|
+
req.destroy(new Error("download timed out"));
|
|
118
|
+
});
|
|
98
119
|
});
|
|
99
|
-
req.on("error", (e) => {
|
|
100
|
-
try { unlinkSync(dest); } catch {}
|
|
101
|
-
reject(e);
|
|
102
|
-
});
|
|
103
|
-
req.setTimeout(120000, () => {
|
|
104
|
-
req.destroy(new Error("download timed out"));
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
120
|
|
|
108
121
|
export async function runPostinstall(opts = {}) {
|
|
109
122
|
const { invokedByRuntime = false, skipGlobalAlias = false } = opts;
|
|
110
123
|
|
|
111
124
|
if (!targetTriple) {
|
|
112
125
|
if (!invokedByRuntime) {
|
|
113
|
-
console.log(
|
|
126
|
+
console.log(
|
|
127
|
+
`hanzo-node: unsupported platform ${platform}/${arch}, skipping postinstall`,
|
|
128
|
+
);
|
|
114
129
|
}
|
|
115
130
|
return;
|
|
116
131
|
}
|
|
@@ -140,7 +155,9 @@ export async function runPostinstall(opts = {}) {
|
|
|
140
155
|
if (existsSync(src)) {
|
|
141
156
|
copyFileSync(src, binaryPath);
|
|
142
157
|
if (platform !== "win32") {
|
|
143
|
-
try {
|
|
158
|
+
try {
|
|
159
|
+
chmodSync(binaryPath, 0o755);
|
|
160
|
+
} catch {}
|
|
144
161
|
}
|
|
145
162
|
if (!invokedByRuntime) {
|
|
146
163
|
console.log(`hanzo-node: installed from ${pkgName}`);
|
|
@@ -154,14 +171,23 @@ export async function runPostinstall(opts = {}) {
|
|
|
154
171
|
|
|
155
172
|
// Download from GitHub release
|
|
156
173
|
try {
|
|
157
|
-
const pkg = JSON.parse(
|
|
174
|
+
const pkg = JSON.parse(
|
|
175
|
+
readFileSync(path.join(__dirname, "package.json"), "utf8"),
|
|
176
|
+
);
|
|
158
177
|
const version = pkg.version;
|
|
159
178
|
|
|
160
179
|
const isWin = platform === "win32";
|
|
161
180
|
const binaryName = `code-${targetTriple}`;
|
|
162
181
|
const archiveName = isWin
|
|
163
182
|
? `${binaryName}.zip`
|
|
164
|
-
: (() => {
|
|
183
|
+
: (() => {
|
|
184
|
+
try {
|
|
185
|
+
execSync("zstd --version", { stdio: "ignore", shell: true });
|
|
186
|
+
return `${binaryName}.zst`;
|
|
187
|
+
} catch {
|
|
188
|
+
return `${binaryName}.tar.gz`;
|
|
189
|
+
}
|
|
190
|
+
})();
|
|
165
191
|
const url = `https://github.com/hanzoai/dev/releases/download/v${version}/${archiveName}`;
|
|
166
192
|
|
|
167
193
|
if (!invokedByRuntime) {
|
|
@@ -172,30 +198,78 @@ export async function runPostinstall(opts = {}) {
|
|
|
172
198
|
await httpsDownload(url, tmp);
|
|
173
199
|
|
|
174
200
|
if (isWin) {
|
|
175
|
-
const sysRoot =
|
|
176
|
-
|
|
201
|
+
const sysRoot =
|
|
202
|
+
process.env.SystemRoot || process.env.windir || "C:\\Windows";
|
|
203
|
+
const psFull = path.join(
|
|
204
|
+
sysRoot,
|
|
205
|
+
"System32",
|
|
206
|
+
"WindowsPowerShell",
|
|
207
|
+
"v1.0",
|
|
208
|
+
"powershell.exe",
|
|
209
|
+
);
|
|
177
210
|
const psCmd = `Expand-Archive -Path '${tmp}' -DestinationPath '${binDir}' -Force`;
|
|
178
211
|
let ok = false;
|
|
179
|
-
try {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
212
|
+
try {
|
|
213
|
+
execSync(`"${psFull}" -NoProfile -NonInteractive -Command "${psCmd}"`, {
|
|
214
|
+
stdio: "ignore",
|
|
215
|
+
});
|
|
216
|
+
ok = true;
|
|
217
|
+
} catch {}
|
|
218
|
+
if (!ok) {
|
|
219
|
+
try {
|
|
220
|
+
execSync(
|
|
221
|
+
`powershell -NoProfile -NonInteractive -Command "${psCmd}"`,
|
|
222
|
+
{ stdio: "ignore" },
|
|
223
|
+
);
|
|
224
|
+
ok = true;
|
|
225
|
+
} catch {}
|
|
226
|
+
}
|
|
227
|
+
if (!ok) {
|
|
228
|
+
try {
|
|
229
|
+
execSync(`pwsh -NoProfile -NonInteractive -Command "${psCmd}"`, {
|
|
230
|
+
stdio: "ignore",
|
|
231
|
+
});
|
|
232
|
+
ok = true;
|
|
233
|
+
} catch {}
|
|
234
|
+
}
|
|
235
|
+
if (!ok) {
|
|
236
|
+
execSync(`tar -xf "${tmp}" -C "${binDir}"`, {
|
|
237
|
+
stdio: "ignore",
|
|
238
|
+
shell: true,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
unlinkSync(tmp);
|
|
243
|
+
} catch {}
|
|
184
244
|
} else {
|
|
185
245
|
if (archiveName.endsWith(".zst")) {
|
|
186
|
-
execSync(`zstd -d '${tmp}' -o '${binaryPath}'`, {
|
|
187
|
-
|
|
246
|
+
execSync(`zstd -d '${tmp}' -o '${binaryPath}'`, {
|
|
247
|
+
stdio: "ignore",
|
|
248
|
+
shell: true,
|
|
249
|
+
});
|
|
250
|
+
try {
|
|
251
|
+
unlinkSync(tmp);
|
|
252
|
+
} catch {}
|
|
188
253
|
} else {
|
|
189
|
-
execSync(`tar -xzf '${tmp}' -C '${binDir}'`, {
|
|
190
|
-
|
|
254
|
+
execSync(`tar -xzf '${tmp}' -C '${binDir}'`, {
|
|
255
|
+
stdio: "ignore",
|
|
256
|
+
shell: true,
|
|
257
|
+
});
|
|
258
|
+
try {
|
|
259
|
+
unlinkSync(tmp);
|
|
260
|
+
} catch {}
|
|
191
261
|
}
|
|
192
|
-
try {
|
|
262
|
+
try {
|
|
263
|
+
chmodSync(binaryPath, 0o755);
|
|
264
|
+
} catch {}
|
|
193
265
|
}
|
|
194
266
|
|
|
195
267
|
// Cache for future use
|
|
196
268
|
const cacheDir = getCacheDir(version);
|
|
197
269
|
const cachePath = path.join(cacheDir, `hanzo-${targetTriple}`);
|
|
198
|
-
try {
|
|
270
|
+
try {
|
|
271
|
+
copyFileSync(binaryPath, cachePath);
|
|
272
|
+
} catch {}
|
|
199
273
|
|
|
200
274
|
if (!invokedByRuntime) {
|
|
201
275
|
console.log("hanzo-node: installation complete");
|
|
@@ -203,7 +277,9 @@ export async function runPostinstall(opts = {}) {
|
|
|
203
277
|
} catch (e) {
|
|
204
278
|
if (!invokedByRuntime) {
|
|
205
279
|
console.error(`hanzo-node: postinstall failed: ${e.message}`);
|
|
206
|
-
console.error(
|
|
280
|
+
console.error(
|
|
281
|
+
"You can try running the CLI directly, which will attempt to bootstrap the binary.",
|
|
282
|
+
);
|
|
207
283
|
}
|
|
208
284
|
throw e;
|
|
209
285
|
}
|