@moltcorp/cli 1.0.1 → 1.0.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 (3) hide show
  1. package/README.md +21 -0
  2. package/install.js +15 -29
  3. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # moltcorp
2
+
3
+ CLI tool — auto-generated by [InstantCLI](https://instantcli.com).
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install -g @moltcorp/cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```sh
14
+ moltcorp --help
15
+ ```
16
+
17
+ ## How it works
18
+
19
+ This npm package downloads the correct pre-compiled binary for your platform at install time. No build tools or Go runtime required.
20
+
21
+ Supported platforms: macOS (x64, ARM64), Linux (x64, ARM64), Windows (x64).
package/install.js CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
 
4
- const https = require("https");
5
- const http = require("http");
6
4
  const fs = require("fs");
7
5
  const path = require("path");
8
6
 
@@ -33,30 +31,6 @@ function getBinaryName() {
33
31
  return `cli-${platform}-${arch}${ext}`;
34
32
  }
35
33
 
36
- function download(url) {
37
- return new Promise((resolve, reject) => {
38
- const client = url.startsWith("https") ? https : http;
39
- client
40
- .get(url, (res) => {
41
- // Follow redirects
42
- if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
43
- return download(res.headers.location).then(resolve, reject);
44
- }
45
-
46
- if (res.statusCode !== 200) {
47
- reject(new Error(`Download failed with status ${res.statusCode}`));
48
- return;
49
- }
50
-
51
- const chunks = [];
52
- res.on("data", (chunk) => chunks.push(chunk));
53
- res.on("end", () => resolve(Buffer.concat(chunks)));
54
- res.on("error", reject);
55
- })
56
- .on("error", reject);
57
- });
58
- }
59
-
60
34
  async function main() {
61
35
  try {
62
36
  const binaryName = getBinaryName();
@@ -67,9 +41,22 @@ async function main() {
67
41
  );
68
42
 
69
43
  console.log(`Downloading ${binaryName}...`);
70
- const data = await download(url);
71
44
 
72
- fs.writeFileSync(dest, data);
45
+ const controller = new AbortController();
46
+ const timeout = setTimeout(() => controller.abort(), 60000);
47
+
48
+ const res = await fetch(url, {
49
+ redirect: "follow",
50
+ signal: controller.signal,
51
+ });
52
+ clearTimeout(timeout);
53
+
54
+ if (!res.ok) {
55
+ throw new Error(`Download failed with status ${res.status}`);
56
+ }
57
+
58
+ const buffer = Buffer.from(await res.arrayBuffer());
59
+ fs.writeFileSync(dest, buffer);
73
60
 
74
61
  if (process.platform !== "win32") {
75
62
  fs.chmodSync(dest, 0o755);
@@ -79,7 +66,6 @@ async function main() {
79
66
  } catch (err) {
80
67
  console.warn(`Warning: failed to download binary: ${err.message}`);
81
68
  console.warn("You may need to install the binary manually.");
82
- // Exit 0 so npm install doesn't fail
83
69
  process.exit(0);
84
70
  }
85
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moltcorp/cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "CLI tool (auto-generated by InstantCLI)",
5
5
  "bin": {
6
6
  "moltcorp": "./run.js"
@@ -11,7 +11,7 @@
11
11
  "os": ["darwin", "linux", "win32"],
12
12
  "cpu": ["x64", "arm64"],
13
13
  "engines": {
14
- "node": ">=16"
14
+ "node": ">=18"
15
15
  },
16
- "files": ["install.js", "run.js", "package.json"]
16
+ "files": ["install.js", "run.js", "package.json", "README.md"]
17
17
  }