plumb-lang 0.0.1 → 0.1.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/package.json +11 -29
- package/plumb.cjs +88 -0
- package/release.json +30 -0
- package/README.md +0 -23
- package/bin/plumb.js +0 -17
- package/lib/install.js +0 -147
package/package.json
CHANGED
|
@@ -1,40 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plumb-lang",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Plumb, a strict referee for empirical and theoretical physics",
|
|
5
5
|
"homepage": "https://plumb-lang.sh",
|
|
6
|
-
"license": "BSD-3-Clause",
|
|
7
6
|
"repository": {
|
|
8
7
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
10
|
-
},
|
|
11
|
-
"bugs": {
|
|
12
|
-
"url": "https://github.com/sprajs/plumb/issues"
|
|
8
|
+
"url": "git+https://github.com/plumblang/plumb.git"
|
|
13
9
|
},
|
|
14
|
-
"
|
|
15
|
-
"plumb",
|
|
16
|
-
"physics",
|
|
17
|
-
"formal-verification",
|
|
18
|
-
"lean4",
|
|
19
|
-
"cosmology",
|
|
20
|
-
"science",
|
|
21
|
-
"statistics",
|
|
22
|
-
"cli"
|
|
23
|
-
],
|
|
10
|
+
"license": "BSD-3-Clause",
|
|
24
11
|
"bin": {
|
|
25
|
-
"plumb": "
|
|
26
|
-
"plumb-lang": "
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"postinstall": "node lib/install.js"
|
|
12
|
+
"plumb": "plumb.cjs",
|
|
13
|
+
"plumb-lang": "plumb.cjs"
|
|
30
14
|
},
|
|
31
|
-
"files": [
|
|
32
|
-
"bin/plumb.js",
|
|
33
|
-
"lib/install.js",
|
|
34
|
-
"README.md",
|
|
35
|
-
"LICENSE"
|
|
36
|
-
],
|
|
37
15
|
"engines": {
|
|
38
16
|
"node": ">=18"
|
|
39
|
-
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"plumb.cjs",
|
|
20
|
+
"release.json"
|
|
21
|
+
]
|
|
40
22
|
}
|
package/plumb.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { execFileSync, spawnSync } = require('node:child_process');
|
|
3
|
+
const { createHash } = require('node:crypto');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
|
|
8
|
+
const release = require('./release.json');
|
|
9
|
+
const isSha256 = value => /^[a-f0-9]{64}$/.test(value);
|
|
10
|
+
|
|
11
|
+
function verifyBinary(binary, expected) {
|
|
12
|
+
if (!fs.lstatSync(binary).isFile() || createHash('sha256').update(fs.readFileSync(binary)).digest('hex') !== expected) {
|
|
13
|
+
throw new Error(`SHA-256 verification failed for ${binary}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function installBinary() {
|
|
18
|
+
const asset = release.assets[`${process.platform}-${process.arch}`];
|
|
19
|
+
if (!asset || !isSha256(asset.sha256) || !isSha256(asset.binarySha256)) {
|
|
20
|
+
throw new Error(`No verified release binary for ${process.platform}-${process.arch}`);
|
|
21
|
+
}
|
|
22
|
+
const windows = process.platform === 'win32';
|
|
23
|
+
const binaryName = windows ? 'plumb.exe' : 'plumb';
|
|
24
|
+
const cache = path.join(windows ? process.env.LOCALAPPDATA || os.homedir()
|
|
25
|
+
: process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache'), 'plumb-lang');
|
|
26
|
+
const destination = path.join(cache, asset.sha256);
|
|
27
|
+
const binary = path.join(destination, binaryName);
|
|
28
|
+
if (fs.existsSync(binary)) {
|
|
29
|
+
verifyBinary(binary, asset.binarySha256);
|
|
30
|
+
return binary;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fs.mkdirSync(cache, { recursive: true });
|
|
34
|
+
const scratch = fs.mkdtempSync(path.join(cache, 'download-'));
|
|
35
|
+
try {
|
|
36
|
+
const response = await fetch(`${release.url}/${asset.archive}`, {
|
|
37
|
+
signal: AbortSignal.timeout(120_000),
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) throw new Error(`Download of ${asset.archive} failed (HTTP ${response.status})`);
|
|
40
|
+
const archive = Buffer.from(await response.arrayBuffer());
|
|
41
|
+
if (createHash('sha256').update(archive).digest('hex') !== asset.sha256) {
|
|
42
|
+
throw new Error(`SHA-256 checksum mismatch for ${asset.archive}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const downloaded = path.join(scratch, asset.archive);
|
|
46
|
+
const extracted = path.join(scratch, 'binary');
|
|
47
|
+
fs.writeFileSync(downloaded, archive);
|
|
48
|
+
fs.mkdirSync(extracted);
|
|
49
|
+
const member = windows ? binaryName : `${asset.archive.slice(0, -'.tar.xz'.length)}/${binaryName}`;
|
|
50
|
+
const tarArgs = ['-xf', downloaded, '-C', extracted];
|
|
51
|
+
let tar = 'tar';
|
|
52
|
+
if (windows) {
|
|
53
|
+
tar = 'tar.exe';
|
|
54
|
+
if (process.env.SystemRoot) {
|
|
55
|
+
const systemTar = path.join(process.env.SystemRoot, 'System32', 'tar.exe');
|
|
56
|
+
if (fs.existsSync(systemTar)) tar = systemTar;
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
tarArgs.push('--strip-components=1');
|
|
60
|
+
}
|
|
61
|
+
execFileSync(tar, [...tarArgs, member], { stdio: 'inherit' });
|
|
62
|
+
const executable = path.join(extracted, binaryName);
|
|
63
|
+
verifyBinary(executable, asset.binarySha256);
|
|
64
|
+
if (!windows) fs.chmodSync(executable, 0o755);
|
|
65
|
+
try {
|
|
66
|
+
fs.renameSync(extracted, destination);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (!['EEXIST', 'ENOTEMPTY', 'EPERM'].includes(error.code) || !fs.existsSync(binary)) throw error;
|
|
69
|
+
verifyBinary(binary, asset.binarySha256);
|
|
70
|
+
}
|
|
71
|
+
return binary;
|
|
72
|
+
} finally {
|
|
73
|
+
fs.rmSync(scratch, { recursive: true, force: true });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function main() {
|
|
78
|
+
const binary = await installBinary();
|
|
79
|
+
const result = spawnSync(binary, process.argv.slice(2), { stdio: 'inherit' });
|
|
80
|
+
if (result.error) throw result.error;
|
|
81
|
+
if (result.signal) process.kill(process.pid, result.signal);
|
|
82
|
+
process.exitCode = result.status ?? 1;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
main().catch(error => {
|
|
86
|
+
console.error(`plumb: ${error.message}`);
|
|
87
|
+
process.exitCode = 1;
|
|
88
|
+
});
|
package/release.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"url": "https://github.com/plumblang/plumb/releases/download/v0.1.0",
|
|
3
|
+
"assets": {
|
|
4
|
+
"linux-x64": {
|
|
5
|
+
"archive": "plumb-x86_64-unknown-linux-musl.tar.xz",
|
|
6
|
+
"sha256": "436607cfc9fab3407c5525f84d38d44bfaf3698cab137e998ec15ccefc89ff13",
|
|
7
|
+
"binarySha256": "2cbd2df1e45d2a2e757a908fbf542d5210461d7930398d508ff977c61b9959f3"
|
|
8
|
+
},
|
|
9
|
+
"linux-arm64": {
|
|
10
|
+
"archive": "plumb-aarch64-unknown-linux-musl.tar.xz",
|
|
11
|
+
"sha256": "28112c591cc09e670147e40561ef725b16d3611a9bb2cf2260b422d8a8a08e4e",
|
|
12
|
+
"binarySha256": "bbef9d13e3dc6625c062fad478efe33bfc4319f56cb0e671d830c66470d51fe6"
|
|
13
|
+
},
|
|
14
|
+
"darwin-arm64": {
|
|
15
|
+
"archive": "plumb-aarch64-apple-darwin.tar.xz",
|
|
16
|
+
"sha256": "b8a4bd5be9cc2d2cce63565347f64b30c2c5dc84c5c38eb7d64204dba254eff7",
|
|
17
|
+
"binarySha256": "06c3e111baeb3b896651138bd76351cb3f14a4210822d4abf346723cc593ed0f"
|
|
18
|
+
},
|
|
19
|
+
"win32-x64": {
|
|
20
|
+
"archive": "plumb-x86_64-pc-windows-msvc.zip",
|
|
21
|
+
"sha256": "3cefb399dcb678f05c16a35460ac9165bd087297fc0e3809570da30d3addec11",
|
|
22
|
+
"binarySha256": "6b889b98fae1b095ed8f81655807d4c12d6f41b76b56d2339df36d502cd2173d"
|
|
23
|
+
},
|
|
24
|
+
"win32-arm64": {
|
|
25
|
+
"archive": "plumb-aarch64-pc-windows-msvc.zip",
|
|
26
|
+
"sha256": "c1df258854815f0eb5f0b8253829277b197d3b551ab6b4c4e9bfa14a7f7d9391",
|
|
27
|
+
"binarySha256": "ae362557493f9bbced84ed20beb60b2ff9c25ca1ebfda31436624e6faa202961"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/README.md
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# plumb-lang
|
|
2
|
-
|
|
3
|
-
CLI installer and runner for **[Plumb](https://plumb-lang.sh)** — a strict referee for empirical and theoretical physics.
|
|
4
|
-
|
|
5
|
-
## Install & Run
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm install -g plumb-lang
|
|
9
|
-
plumb --version
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
Or run directly with `npx`:
|
|
13
|
-
|
|
14
|
-
```sh
|
|
15
|
-
npx plumb-lang --version
|
|
16
|
-
npx plumb-lang doc quickstart
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
On install (or first run), this package downloads the prebuilt native `plumb` binary for your platform from [GitHub Releases](https://github.com/sprajs/plumb/releases), verifies its SHA-256 checksum, and runs it natively.
|
|
20
|
-
|
|
21
|
-
- Website & Docs: https://plumb-lang.sh
|
|
22
|
-
- Repository: https://github.com/sprajs/plumb
|
|
23
|
-
- License: BSD-3-Clause
|
package/bin/plumb.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
const { spawnSync } = require('node:child_process');
|
|
5
|
-
const { ensureBinary } = require('../lib/install.js');
|
|
6
|
-
|
|
7
|
-
(async () => {
|
|
8
|
-
try {
|
|
9
|
-
const bin = await ensureBinary();
|
|
10
|
-
const res = spawnSync(bin, process.argv.slice(2), { stdio: 'inherit' });
|
|
11
|
-
if (res.error) throw res.error;
|
|
12
|
-
process.exit(res.status ?? 1);
|
|
13
|
-
} catch (err) {
|
|
14
|
-
console.error(`[plumb-lang] ${err.message}`);
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
})();
|
package/lib/install.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
const crypto = require('node:crypto');
|
|
5
|
-
const fs = require('node:fs');
|
|
6
|
-
const https = require('node:https');
|
|
7
|
-
const os = require('node:os');
|
|
8
|
-
const path = require('node:path');
|
|
9
|
-
const { execFileSync } = require('node:child_process');
|
|
10
|
-
|
|
11
|
-
const VERSION = '0.0.1';
|
|
12
|
-
const BASE_URL = `https://github.com/sprajs/plumb/releases/download/v${VERSION}`;
|
|
13
|
-
|
|
14
|
-
const ARTIFACTS = {
|
|
15
|
-
'darwin-arm64': {
|
|
16
|
-
file: 'plumb-aarch64-apple-darwin.tar.xz',
|
|
17
|
-
sha256: '90a18f25954300d717006e73b0c6c7f54bfbf42ddbb2b1256395bcae622191ac',
|
|
18
|
-
ext: 'tar.xz',
|
|
19
|
-
},
|
|
20
|
-
'darwin-x64': {
|
|
21
|
-
file: 'plumb-x86_64-apple-darwin.tar.xz',
|
|
22
|
-
sha256: 'cd48204a45c94ba173467119ffb869c4f6b06eca29c89bc78aec10e08c3231a3',
|
|
23
|
-
ext: 'tar.xz',
|
|
24
|
-
},
|
|
25
|
-
'linux-x64': {
|
|
26
|
-
file: 'plumb-x86_64-unknown-linux-musl.tar.xz',
|
|
27
|
-
sha256: '6b22720960d9abaabb4eae9096003ba19488c6190117174f59d8bea5981e1168',
|
|
28
|
-
ext: 'tar.xz',
|
|
29
|
-
},
|
|
30
|
-
'linux-arm64': {
|
|
31
|
-
file: 'plumb-aarch64-unknown-linux-musl.tar.xz',
|
|
32
|
-
sha256: 'ad6dffc2de6d0a2eece38b07260f77e9a5941240bf9876a0cdc9991ae7d0e2a6',
|
|
33
|
-
ext: 'tar.xz',
|
|
34
|
-
},
|
|
35
|
-
'win32-x64': {
|
|
36
|
-
file: 'plumb-x86_64-pc-windows-msvc.zip',
|
|
37
|
-
sha256: 'aa3743f595f03fa7b08aac05984aa922888225a4bd767901221a356caa15839d',
|
|
38
|
-
ext: 'zip',
|
|
39
|
-
},
|
|
40
|
-
'win32-arm64': {
|
|
41
|
-
file: 'plumb-aarch64-pc-windows-msvc.zip',
|
|
42
|
-
sha256: 'a2f4dc8024983d86c3204d7edc535a77c68145647b349c581c0184e41f29aabf',
|
|
43
|
-
ext: 'zip',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
function binaryPath() {
|
|
48
|
-
const binName = process.platform === 'win32' ? 'plumb.exe' : 'plumb';
|
|
49
|
-
return path.join(__dirname, '..', 'vendor', binName);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function download(url, dest, redirects = 0) {
|
|
53
|
-
if (redirects > 5) return Promise.reject(new Error('Too many redirects'));
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
https
|
|
56
|
-
.get(url, { headers: { 'User-Agent': `plumb-lang-npm/${VERSION}` } }, (res) => {
|
|
57
|
-
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
58
|
-
res.resume();
|
|
59
|
-
resolve(download(res.headers.location, dest, redirects + 1));
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (res.statusCode !== 200) {
|
|
63
|
-
res.resume();
|
|
64
|
-
reject(new Error(`Failed to download ${url}: HTTP ${res.statusCode}`));
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const out = fs.createWriteStream(dest);
|
|
68
|
-
res.pipe(out);
|
|
69
|
-
out.on('finish', () => out.close(resolve));
|
|
70
|
-
out.on('error', reject);
|
|
71
|
-
})
|
|
72
|
-
.on('error', reject);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function sha256File(filePath) {
|
|
77
|
-
return crypto.createHash('sha256').update(fs.readFileSync(filePath)).digest('hex');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function findFile(dir, targetName) {
|
|
81
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
82
|
-
const full = path.join(dir, entry.name);
|
|
83
|
-
if (entry.isDirectory()) {
|
|
84
|
-
const hit = findFile(full, targetName);
|
|
85
|
-
if (hit) return hit;
|
|
86
|
-
} else if (entry.name === targetName) {
|
|
87
|
-
return full;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function ensureBinary() {
|
|
94
|
-
const destBin = binaryPath();
|
|
95
|
-
if (fs.existsSync(destBin)) return destBin;
|
|
96
|
-
|
|
97
|
-
const key = `${process.platform}-${process.arch}`;
|
|
98
|
-
const spec = ARTIFACTS[key];
|
|
99
|
-
if (!spec) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
`Unsupported platform ${key}. Download a release archive from https://github.com/sprajs/plumb/releases/tag/v${VERSION}`,
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'plumb-lang-'));
|
|
106
|
-
const archivePath = path.join(tmpDir, spec.file);
|
|
107
|
-
const extractDir = path.join(tmpDir, 'out');
|
|
108
|
-
fs.mkdirSync(extractDir);
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
await download(`${BASE_URL}/${spec.file}`, archivePath);
|
|
112
|
-
const actual = sha256File(archivePath);
|
|
113
|
-
if (actual !== spec.sha256) {
|
|
114
|
-
throw new Error(`SHA-256 mismatch for ${spec.file}: expected ${spec.sha256}, got ${actual}`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (spec.ext === 'zip') {
|
|
118
|
-
execFileSync(
|
|
119
|
-
'powershell',
|
|
120
|
-
['-NoProfile', '-Command', `Expand-Archive -Path '${archivePath}' -DestinationPath '${extractDir}' -Force`],
|
|
121
|
-
{ stdio: 'inherit' },
|
|
122
|
-
);
|
|
123
|
-
} else {
|
|
124
|
-
execFileSync('tar', ['-xJf', archivePath, '-C', extractDir], { stdio: 'inherit' });
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const binName = process.platform === 'win32' ? 'plumb.exe' : 'plumb';
|
|
128
|
-
const extracted = findFile(extractDir, binName);
|
|
129
|
-
if (!extracted) throw new Error(`Could not find ${binName} in ${spec.file}`);
|
|
130
|
-
|
|
131
|
-
fs.mkdirSync(path.dirname(destBin), { recursive: true });
|
|
132
|
-
fs.copyFileSync(extracted, destBin);
|
|
133
|
-
if (process.platform !== 'win32') fs.chmodSync(destBin, 0o755);
|
|
134
|
-
return destBin;
|
|
135
|
-
} finally {
|
|
136
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
module.exports = { ensureBinary, binaryPath };
|
|
141
|
-
|
|
142
|
-
if (require.main === module) {
|
|
143
|
-
ensureBinary().catch((err) => {
|
|
144
|
-
console.error(`[plumb-lang] ${err.message}`);
|
|
145
|
-
process.exit(1);
|
|
146
|
-
});
|
|
147
|
-
}
|