topaz-lang 5.2.1 → 5.4.0
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/install.js +22 -9
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// postinstall: download the prebuilt `topaz` binary that matches THIS package
|
|
2
|
-
// version (so `npm i topaz-lang@5.
|
|
2
|
+
// version (so `npm i topaz-lang@5.4.0` pins topaz v5.4.0), verify its SHA256,
|
|
3
3
|
// and drop it next to the bin shim. No Rust source, no build.
|
|
4
4
|
'use strict';
|
|
5
5
|
const { mkdir, writeFile, chmod, rename } = require('node:fs/promises');
|
|
@@ -8,7 +8,10 @@ const path = require('node:path');
|
|
|
8
8
|
|
|
9
9
|
const VERSION = require('./package.json').version;
|
|
10
10
|
const TAG = `v${VERSION}`;
|
|
11
|
-
const DL_BASE = (process.env.TOPAZ_DL_BASE || 'https://topaz.ooo/dl').replace(
|
|
11
|
+
const DL_BASE = (process.env.TOPAZ_DL_BASE || 'https://topaz.ooo/dl').replace(
|
|
12
|
+
/\/$/,
|
|
13
|
+
''
|
|
14
|
+
);
|
|
12
15
|
const TIMEOUT_MS = 60_000;
|
|
13
16
|
const MAX_BYTES = 100 * 1024 * 1024; // a sane ceiling for a single CLI binary
|
|
14
17
|
|
|
@@ -26,7 +29,7 @@ function linuxAsset(name) {
|
|
|
26
29
|
if (!glibc) {
|
|
27
30
|
throw new Error(
|
|
28
31
|
'this looks like a musl/Alpine system; the published Linux binaries are ' +
|
|
29
|
-
'glibc-based. Use a glibc distro or
|
|
32
|
+
'glibc-based. Use a glibc distro or container, or the browser playground at https://topaz.ooo/playground.'
|
|
30
33
|
);
|
|
31
34
|
}
|
|
32
35
|
return name;
|
|
@@ -39,7 +42,8 @@ function assetName() {
|
|
|
39
42
|
if (p === 'linux' && a === 'arm64') return linuxAsset('topaz-linux-aarch64');
|
|
40
43
|
if (p === 'darwin' && a === 'arm64') return 'topaz-macos-aarch64';
|
|
41
44
|
if (p === 'darwin' && a === 'x64') return 'topaz-macos-x86_64';
|
|
42
|
-
if (p === 'win32' && (a === 'x64' || a === 'arm64'))
|
|
45
|
+
if (p === 'win32' && (a === 'x64' || a === 'arm64'))
|
|
46
|
+
return 'topaz-windows-x86_64.exe';
|
|
43
47
|
throw new Error(`unsupported platform ${p}/${a}`);
|
|
44
48
|
}
|
|
45
49
|
|
|
@@ -50,7 +54,8 @@ async function get(url) {
|
|
|
50
54
|
const res = await fetch(url, { signal: ctrl.signal }); // node >=18, follows redirects
|
|
51
55
|
if (!res.ok) throw new Error(`fetch ${res.status} for ${url}`);
|
|
52
56
|
const len = Number(res.headers.get('content-length'));
|
|
53
|
-
if (len && len > MAX_BYTES)
|
|
57
|
+
if (len && len > MAX_BYTES)
|
|
58
|
+
throw new Error(`refusing ${len} bytes from ${url}`);
|
|
54
59
|
return res;
|
|
55
60
|
} finally {
|
|
56
61
|
clearTimeout(timer);
|
|
@@ -61,15 +66,23 @@ async function main() {
|
|
|
61
66
|
const name = assetName();
|
|
62
67
|
const url = `${DL_BASE}/${TAG}/${name}`;
|
|
63
68
|
const binDir = path.join(__dirname, 'bin');
|
|
64
|
-
const out = path.join(
|
|
69
|
+
const out = path.join(
|
|
70
|
+
binDir,
|
|
71
|
+
process.platform === 'win32' ? 'topaz.exe' : 'topaz-bin'
|
|
72
|
+
);
|
|
65
73
|
|
|
66
74
|
const buf = Buffer.from(await (await get(url)).arrayBuffer());
|
|
67
|
-
if (buf.length > MAX_BYTES)
|
|
75
|
+
if (buf.length > MAX_BYTES)
|
|
76
|
+
throw new Error(`downloaded ${buf.length} bytes (over the cap)`);
|
|
68
77
|
|
|
69
|
-
const want = (await (await get(`${url}.sha256`)).text())
|
|
78
|
+
const want = (await (await get(`${url}.sha256`)).text())
|
|
79
|
+
.trim()
|
|
80
|
+
.split(/\s+/)[0]
|
|
81
|
+
.toLowerCase();
|
|
70
82
|
if (!/^[0-9a-f]{64}$/.test(want)) throw new Error('malformed checksum');
|
|
71
83
|
const got = createHash('sha256').update(buf).digest('hex');
|
|
72
|
-
if (got !== want)
|
|
84
|
+
if (got !== want)
|
|
85
|
+
throw new Error(`checksum mismatch (expected ${want}, got ${got})`);
|
|
73
86
|
|
|
74
87
|
await mkdir(binDir, { recursive: true });
|
|
75
88
|
const tmp = `${out}.tmp`;
|