@isamisushi/yomi-cli 0.1.0 → 0.1.1

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/bin/yomi.js +6 -12
  2. package/install.js +56 -17
  3. package/package.json +1 -1
package/bin/yomi.js CHANGED
@@ -8,33 +8,27 @@ import { fileURLToPath } from "node:url";
8
8
  const PLATFORMS = {
9
9
  "linux-x64": {
10
10
  "target": "linux-x64",
11
- "assetName": "yomi-linux-x64",
12
- "checksum": "e97043723fa25335da2a0df4abb2875c3ba7f08ab2f0138dbd441ca96626f7c0"
11
+ "assetName": "yomi-linux-x64"
13
12
  },
14
13
  "linux-arm64": {
15
14
  "target": "linux-arm64",
16
- "assetName": "yomi-linux-arm64",
17
- "checksum": "542d333a489382592e72dde9015ddbc61a7b53f43e3ad46646727aa3023016ae"
15
+ "assetName": "yomi-linux-arm64"
18
16
  },
19
17
  "darwin-x64": {
20
18
  "target": "darwin-x64",
21
- "assetName": "yomi-darwin-x64",
22
- "checksum": "5b342f6d4b2b599950d57bfa7b4f2727f0b699e8368bfcb1109e9072f1c1efc9"
19
+ "assetName": "yomi-darwin-x64"
23
20
  },
24
21
  "darwin-arm64": {
25
22
  "target": "darwin-arm64",
26
- "assetName": "yomi-darwin-arm64",
27
- "checksum": "0f1f763a2eb0ca949b4f54043809a0d63c27f7b33842c69683a8551c57cd05fc"
23
+ "assetName": "yomi-darwin-arm64"
28
24
  },
29
25
  "win32-x64": {
30
26
  "target": "windows-x64",
31
- "assetName": "yomi-windows-x64.exe",
32
- "checksum": "74209a6f7797874468f1b0185435faf049f289e65a77ceee131a91f623fc9723"
27
+ "assetName": "yomi-windows-x64.exe"
33
28
  },
34
29
  "win32-arm64": {
35
30
  "target": "windows-arm64",
36
- "assetName": "yomi-windows-arm64.exe",
37
- "checksum": "94f906fb4704cf1453cc1c093b0b1e4b40f033a53e63c3a80ff17bb25f8da8c1"
31
+ "assetName": "yomi-windows-arm64.exe"
38
32
  }
39
33
  };
40
34
  const dir = dirname(fileURLToPath(import.meta.url));
package/install.js CHANGED
@@ -9,33 +9,27 @@ import { fileURLToPath } from "node:url";
9
9
  const PLATFORMS = {
10
10
  "linux-x64": {
11
11
  "target": "linux-x64",
12
- "assetName": "yomi-linux-x64",
13
- "checksum": "e97043723fa25335da2a0df4abb2875c3ba7f08ab2f0138dbd441ca96626f7c0"
12
+ "assetName": "yomi-linux-x64"
14
13
  },
15
14
  "linux-arm64": {
16
15
  "target": "linux-arm64",
17
- "assetName": "yomi-linux-arm64",
18
- "checksum": "542d333a489382592e72dde9015ddbc61a7b53f43e3ad46646727aa3023016ae"
16
+ "assetName": "yomi-linux-arm64"
19
17
  },
20
18
  "darwin-x64": {
21
19
  "target": "darwin-x64",
22
- "assetName": "yomi-darwin-x64",
23
- "checksum": "5b342f6d4b2b599950d57bfa7b4f2727f0b699e8368bfcb1109e9072f1c1efc9"
20
+ "assetName": "yomi-darwin-x64"
24
21
  },
25
22
  "darwin-arm64": {
26
23
  "target": "darwin-arm64",
27
- "assetName": "yomi-darwin-arm64",
28
- "checksum": "0f1f763a2eb0ca949b4f54043809a0d63c27f7b33842c69683a8551c57cd05fc"
24
+ "assetName": "yomi-darwin-arm64"
29
25
  },
30
26
  "win32-x64": {
31
27
  "target": "windows-x64",
32
- "assetName": "yomi-windows-x64.exe",
33
- "checksum": "74209a6f7797874468f1b0185435faf049f289e65a77ceee131a91f623fc9723"
28
+ "assetName": "yomi-windows-x64.exe"
34
29
  },
35
30
  "win32-arm64": {
36
31
  "target": "windows-arm64",
37
- "assetName": "yomi-windows-arm64.exe",
38
- "checksum": "94f906fb4704cf1453cc1c093b0b1e4b40f033a53e63c3a80ff17bb25f8da8c1"
32
+ "assetName": "yomi-windows-arm64.exe"
39
33
  }
40
34
  };
41
35
  const dir = dirname(fileURLToPath(import.meta.url));
@@ -60,18 +54,22 @@ const destination = resolve(vendorDir, process.platform === "win32" ? "yomi.exe"
60
54
 
61
55
  if (process.env.YOMI_BINARY_PATH) {
62
56
  copyLocalBinary(process.env.YOMI_BINARY_PATH, destination);
63
- verifyChecksum(destination, target.checksum);
64
57
  console.log("[yomi] Installed binary from YOMI_BINARY_PATH.");
65
58
  process.exit(0);
66
59
  }
67
60
 
68
- const version = "0.1.0";
61
+ const version = "0.1.1";
69
62
  const baseUrl = process.env.YOMI_RELEASE_BASE_URL || `https://github.com/isamisushi/yomi/releases/download/v${version}`;
70
63
  const url = `${baseUrl}/${target.assetName}`;
64
+ const checksumsUrl = `${baseUrl}/checksums.txt`;
71
65
 
72
- download(url, destination)
73
- .then(() => {
74
- verifyChecksum(destination, target.checksum);
66
+ downloadText(checksumsUrl)
67
+ .then((checksums) => {
68
+ const expected = findChecksum(checksums, target.assetName);
69
+ return download(url, destination).then(() => expected);
70
+ })
71
+ .then((expected) => {
72
+ verifyChecksum(destination, expected);
75
73
  console.log(`[yomi] Installed ${target.assetName}.`);
76
74
  })
77
75
  .catch((error) => {
@@ -95,6 +93,17 @@ function verifyChecksum(path, expected) {
95
93
  }
96
94
  }
97
95
 
96
+ function findChecksum(checksums, assetName) {
97
+ for (const line of checksums.split(/\r?\n/)) {
98
+ const match = line.trim().match(/^([a-f0-9]{64})\s+(.+)$/i);
99
+ if (match && match[2] === assetName) {
100
+ return match[1].toLowerCase();
101
+ }
102
+ }
103
+
104
+ throw new Error(`No checksum entry for ${assetName}`);
105
+ }
106
+
98
107
  function writeBinary(path, content) {
99
108
  const tempPath = `${path}.tmp-${process.pid}`;
100
109
  writeFileSync(tempPath, content, { mode: 0o755 });
@@ -139,3 +148,33 @@ function download(url, destinationPath, redirects = 0) {
139
148
  request.on("error", rejectPromise);
140
149
  });
141
150
  }
151
+
152
+ function downloadText(url, redirects = 0) {
153
+ return new Promise((resolvePromise, rejectPromise) => {
154
+ const request = get(url, (response) => {
155
+ if ([301, 302, 303, 307, 308].includes(response.statusCode ?? 0)) {
156
+ response.resume();
157
+ if (!response.headers.location || redirects > 5) {
158
+ rejectPromise(new Error("Too many redirects while downloading " + url));
159
+ return;
160
+ }
161
+ downloadText(response.headers.location, redirects + 1).then(resolvePromise, rejectPromise);
162
+ return;
163
+ }
164
+
165
+ if (response.statusCode !== 200) {
166
+ response.resume();
167
+ rejectPromise(new Error(`HTTP ${response.statusCode} for ${url}`));
168
+ return;
169
+ }
170
+
171
+ let content = "";
172
+ response.setEncoding("utf8");
173
+ response.on("data", (chunk) => {
174
+ content += chunk;
175
+ });
176
+ response.on("end", () => resolvePromise(content));
177
+ });
178
+ request.on("error", rejectPromise);
179
+ });
180
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isamisushi/yomi-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [