salamlang 0.4.3
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/bin/salam.js +42 -0
- package/install.js +146 -0
- package/package.json +46 -0
package/bin/salam.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const os = require("node:os");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const { spawnSync } = require("node:child_process");
|
|
7
|
+
|
|
8
|
+
const VENDOR = path.join(__dirname, "..", "vendor");
|
|
9
|
+
|
|
10
|
+
function locate() {
|
|
11
|
+
if (!fs.existsSync(VENDOR)) return null;
|
|
12
|
+
for (const entry of fs.readdirSync(VENDOR)) {
|
|
13
|
+
for (const exe of ["salam", "salam.exe"]) {
|
|
14
|
+
const candidate = path.join(VENDOR, entry, exe);
|
|
15
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const bin = locate();
|
|
22
|
+
if (!bin) {
|
|
23
|
+
console.error(
|
|
24
|
+
"salam: the compiler is not unpacked; re-run `npm install salamlang`",
|
|
25
|
+
);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The compiler derives std/ from its own location, which is reliable here
|
|
30
|
+
// because bin is an absolute path, but pin it anyway.
|
|
31
|
+
const env = { ...process.env };
|
|
32
|
+
if (!env.SALAM_STD) {
|
|
33
|
+
const std = path.join(path.dirname(bin), "std");
|
|
34
|
+
if (fs.existsSync(std)) env.SALAM_STD = std;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit", env });
|
|
38
|
+
if (result.error) {
|
|
39
|
+
console.error(`salam: ${result.error.message}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
process.exit(result.status === null ? 1 : result.status);
|
package/install.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const os = require("node:os");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const zlib = require("node:zlib");
|
|
7
|
+
const { execFileSync } = require("node:child_process");
|
|
8
|
+
const { pipeline } = require("node:stream/promises");
|
|
9
|
+
|
|
10
|
+
const VERSION = require("./package.json").version;
|
|
11
|
+
const BASE = `https://github.com/SalamLang/Salam/releases/download/v${VERSION}`;
|
|
12
|
+
const VENDOR = path.join(__dirname, "vendor");
|
|
13
|
+
|
|
14
|
+
function target() {
|
|
15
|
+
const platform = os.platform();
|
|
16
|
+
const arch = os.arch();
|
|
17
|
+
|
|
18
|
+
if (platform === "darwin") {
|
|
19
|
+
if (arch !== "arm64") {
|
|
20
|
+
throw new Error("salam publishes macOS builds for Apple Silicon only");
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
slug: "macos-arm64",
|
|
24
|
+
dir: "salam-macos-arm64",
|
|
25
|
+
exe: "salam",
|
|
26
|
+
ext: "tar.gz",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (platform === "linux") {
|
|
31
|
+
const map = { x64: "x86_64", arm64: "aarch64", arm: "armhf", ia32: "i686" };
|
|
32
|
+
const rel = map[arch];
|
|
33
|
+
if (!rel) throw new Error(`salam has no Linux build for ${arch}`);
|
|
34
|
+
return {
|
|
35
|
+
slug: `linux-${rel}`,
|
|
36
|
+
dir: `salam-linux-${rel}`,
|
|
37
|
+
exe: "salam",
|
|
38
|
+
ext: "tar.gz",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (platform === "win32") {
|
|
43
|
+
if (arch === "x64") {
|
|
44
|
+
return {
|
|
45
|
+
slug: "windows-x86_64",
|
|
46
|
+
dir: "salam-windows",
|
|
47
|
+
exe: "salam.exe",
|
|
48
|
+
ext: "zip",
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (arch === "ia32") {
|
|
52
|
+
return {
|
|
53
|
+
slug: "windows-i686",
|
|
54
|
+
dir: "salam-windows-i686",
|
|
55
|
+
exe: "salam.exe",
|
|
56
|
+
ext: "zip",
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`salam has no Windows build for ${arch}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
throw new Error(`salam has no build for ${platform}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function download(url, dest) {
|
|
66
|
+
const res = await fetch(url, { redirect: "follow" });
|
|
67
|
+
if (!res.ok) throw new Error(`${url} -> HTTP ${res.status}`);
|
|
68
|
+
await pipeline(res.body, fs.createWriteStream(dest));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function verify(archive, url) {
|
|
72
|
+
const res = await fetch(`${url}.sha256`, { redirect: "follow" });
|
|
73
|
+
if (!res.ok) {
|
|
74
|
+
console.warn(
|
|
75
|
+
`salam: no published checksum for ${path.basename(archive)}; skipping verification`,
|
|
76
|
+
);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const expected = (await res.text()).trim().split(/\s+/)[0].toLowerCase();
|
|
80
|
+
const actual = require("node:crypto")
|
|
81
|
+
.createHash("sha256")
|
|
82
|
+
.update(fs.readFileSync(archive))
|
|
83
|
+
.digest("hex");
|
|
84
|
+
if (expected !== actual) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`checksum mismatch for ${path.basename(archive)}: expected ${expected}, got ${actual}`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function extract(archive, into, ext) {
|
|
92
|
+
fs.mkdirSync(into, { recursive: true });
|
|
93
|
+
if (ext === "zip") {
|
|
94
|
+
// tar handles zip on Windows 10+ (bsdtar); PowerShell is the fallback.
|
|
95
|
+
try {
|
|
96
|
+
execFileSync("tar", ["-xf", archive, "-C", into], { stdio: "inherit" });
|
|
97
|
+
} catch {
|
|
98
|
+
execFileSync(
|
|
99
|
+
"powershell",
|
|
100
|
+
[
|
|
101
|
+
"-NoProfile",
|
|
102
|
+
"-NonInteractive",
|
|
103
|
+
"-Command",
|
|
104
|
+
`Expand-Archive -LiteralPath '${archive}' -DestinationPath '${into}' -Force`,
|
|
105
|
+
],
|
|
106
|
+
{ stdio: "inherit" },
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
execFileSync("tar", ["-xzf", archive, "-C", into], { stdio: "inherit" });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function main() {
|
|
115
|
+
const t = target();
|
|
116
|
+
const name = `salam-${VERSION}-${t.slug}.${t.ext}`;
|
|
117
|
+
const url = `${BASE}/${name}`;
|
|
118
|
+
|
|
119
|
+
if (fs.existsSync(path.join(VENDOR, t.dir, t.exe))) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "salam-"));
|
|
124
|
+
const archive = path.join(tmp, name);
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
console.log(`salam ${VERSION}: downloading ${name}`);
|
|
128
|
+
await download(url, archive);
|
|
129
|
+
await verify(archive, url);
|
|
130
|
+
fs.rmSync(VENDOR, { recursive: true, force: true });
|
|
131
|
+
extract(archive, VENDOR, t.ext);
|
|
132
|
+
|
|
133
|
+
const exe = path.join(VENDOR, t.dir, t.exe);
|
|
134
|
+
if (!fs.existsSync(exe))
|
|
135
|
+
throw new Error(`${name} did not contain ${t.dir}/${t.exe}`);
|
|
136
|
+
if (os.platform() !== "win32") fs.chmodSync(exe, 0o755);
|
|
137
|
+
console.log(`salam ${VERSION}: installed`);
|
|
138
|
+
} finally {
|
|
139
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
main().catch((err) => {
|
|
144
|
+
console.error(`salam: install failed: ${err.message}`);
|
|
145
|
+
process.exit(1);
|
|
146
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "salamlang",
|
|
3
|
+
"version": "0.4.3",
|
|
4
|
+
"description": "General-purpose systems programming language with a built-in DSL",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"salam",
|
|
7
|
+
"compiler",
|
|
8
|
+
"programming-language",
|
|
9
|
+
"llvm",
|
|
10
|
+
"systems-programming"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/SalamLang/Salam",
|
|
13
|
+
"bugs": "https://github.com/SalamLang/Salam/issues",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/SalamLang/Salam.git",
|
|
17
|
+
"directory": "packaging/npm"
|
|
18
|
+
},
|
|
19
|
+
"license": "GPL-3.0-or-later",
|
|
20
|
+
"author": "Seyyed Ali Mohammadiyeh and the Salam Team",
|
|
21
|
+
"bin": {
|
|
22
|
+
"salam": "bin/salam.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"bin/",
|
|
26
|
+
"install.js",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"postinstall": "node install.js"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"os": [
|
|
36
|
+
"darwin",
|
|
37
|
+
"linux",
|
|
38
|
+
"win32"
|
|
39
|
+
],
|
|
40
|
+
"cpu": [
|
|
41
|
+
"x64",
|
|
42
|
+
"arm64",
|
|
43
|
+
"arm",
|
|
44
|
+
"ia32"
|
|
45
|
+
]
|
|
46
|
+
}
|