@feds01/zenith 0.1.0 → 0.2.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/README.md CHANGED
@@ -1,80 +1,42 @@
1
- # Zenith
1
+ # zenith
2
2
 
3
- > An architecture linter for TypeScript and JavaScript codebases, built for monorepos.
4
-
5
- Zenith enforces *contracts* about which parts of a codebase may import which
6
- other parts, such as layers, forbidden dependencies, independent modules,
7
- protected modules, acyclic packages and public entry points. You declare them
8
- in `zenith.toml`, and `zenith check` fails when the code breaks them, pointing
9
- at the exact import, or the full import chain when the dependency is indirect.
10
-
11
- The contract model comes from Python's
12
- [import-linter](https://github.com/seddonym/import-linter), and the graph
13
- algorithms are ports of its engine [grimp](https://github.com/python-grimp/grimp).
14
- Both are adapted to how JS/TS projects are organised: files and directories,
15
- workspace packages, `tsconfig` path aliases, `exports` maps, type-only imports,
16
- and `"use client"` and `"use server"` boundaries. Zenith is a single Rust
17
- binary built on [oxc](https://oxc.rs).
18
-
19
- ## Status
20
-
21
- Zenith is under construction. The design is settled in
22
- [docs/SPEC.md](docs/SPEC.md), and the implementation lands on `main` one
23
- reviewed pull request at a time (see the spec's roadmap, §13).
24
-
25
- ## Installation
26
-
27
- There are three ways to install zenith. npm and Homebrew download the
28
- binaries of a release, so they work once the first version is released and the
29
- repository is public. Until then, install from source, which needs access to
30
- the repository.
31
-
32
- ### npm
33
-
34
- ```sh
35
- npm install --global @feds01/zenith
36
- ```
37
-
38
- Or run it without installing: `npx @feds01/zenith check`.
39
-
40
- ### Homebrew
41
-
42
- ```sh
43
- brew install feds01/tap/zenith
44
- ```
45
-
46
- ### From source
3
+ An architecture linter for TypeScript and JavaScript codebases, built for
4
+ monorepos. Zenith enforces *contracts* about which parts of a codebase may
5
+ import which other parts, declared in `zenith.toml`, and `zenith check` fails
6
+ when the code breaks them.
47
7
 
48
8
  ```sh
49
- cargo install --git https://github.com/feds01/zenith zenith
9
+ npm install --save-dev @feds01/zenith
10
+ npx zenith check
50
11
  ```
51
12
 
52
- Each [GitHub release](https://github.com/feds01/zenith/releases) also has the
53
- prebuilt binaries, with shell and PowerShell installers.
54
-
55
- ## Development
56
-
57
- Zenith builds with a pinned nightly toolchain (see `rust-toolchain.toml`) and
58
- uses [just](https://github.com/casey/just):
13
+ See the [user guide](https://feds01.github.io/zenith/) for the contracts, the
14
+ configuration and the command line.
59
15
 
60
- ```sh
61
- just setup # install the toolchain and the pre-commit hooks
62
- just test # all tests
63
- just lint # clippy (deny warnings) and the formatting check
64
- just run # run the CLI from source, e.g. `just run version`
65
- ```
16
+ ## How it is installed
66
17
 
67
- The user guide is in [docs/book](docs/book/src/introduction.md), published to
68
- [GitHub Pages](https://feds01.github.io/zenith/).
18
+ Zenith is a native binary. This package has none itself, nor any install
19
+ script: the binary for each platform is in a package of its own, which this
20
+ one lists as an optional dependency, and the package manager installs only
21
+ the one for your platform:
69
22
 
70
- See [CLAUDE.md](CLAUDE.md) for the architecture and conventions.
23
+ | Package | Platform |
24
+ |---|---|
25
+ | `@feds01/zenith-darwin-arm64` | macOS, Apple silicon |
26
+ | `@feds01/zenith-darwin-x64` | macOS, Intel |
27
+ | `@feds01/zenith-linux-arm64` | Linux, ARM64 (static, any libc) |
28
+ | `@feds01/zenith-linux-x64` | Linux, x86-64 (static, any libc) |
29
+ | `@feds01/zenith-win32-x64` | Windows, x86-64 |
71
30
 
72
- ## Releasing
31
+ So it installs offline from a package manager's cache, the lockfile's
32
+ integrity hashes cover the binary, and bun needs no `trustedDependencies`
33
+ entry for it. Don't leave optional dependencies out of the install, e.g. with
34
+ `npm install --omit=optional`, or the `zenith` command has no binary to run.
73
35
 
74
- Bump `version` in `crates/zenith/Cargo.toml`, merge to `main`, then run
75
- `just release` to tag it. [cargo-dist](https://opensource.axo.dev/cargo-dist/)
76
- builds the binaries and installers and publishes the GitHub release.
36
+ On another platform, build zenith from source with
37
+ `cargo install --locked --git https://github.com/feds01/zenith zenith`, and
38
+ set `ZENITH_BINARY` to the path of the binary.
77
39
 
78
- ## License
40
+ ## Licence
79
41
 
80
42
  MIT
package/bin/zenith.js ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ // The `zenith` command of the npm package. It runs the binary from the
3
+ // package for this platform, e.g. `@feds01/zenith-darwin-arm64`, which the
4
+ // package manager installed as one of its optional dependencies. The binary
5
+ // gets the arguments, stdin, stdout and stderr, and the command exits as the
6
+ // binary does.
7
+
8
+ "use strict";
9
+
10
+ const { spawn } = require("child_process");
11
+ const path = require("path");
12
+
13
+ const { name: main, version, optionalDependencies } = require("../package.json");
14
+
15
+ /** The exit code of a usage or internal error, as zenith's own. */
16
+ const ERROR_EXIT_CODE = 2;
17
+
18
+ /** The signals that are passed on to the binary, as when the launcher is stopped on its own. */
19
+ const FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
20
+
21
+ /** Print `message` to stderr, and exit with an error. */
22
+ function fail(message) {
23
+ process.stderr.write(`error: ${message}\n`);
24
+ process.exit(ERROR_EXIT_CODE);
25
+ }
26
+
27
+ /** The path of the binary to run. */
28
+ function binaryPath() {
29
+ // 1. A binary of the user's own, e.g. one built from source for a
30
+ // platform without a package.
31
+ const override = process.env.ZENITH_BINARY;
32
+ if (override) {
33
+ return override;
34
+ }
35
+
36
+ // 2. The package for this platform, which must be one that is published.
37
+ const target = `${process.platform}-${process.arch}`;
38
+ const platformPackage = `${main}-${target}`;
39
+ if (!Object.prototype.hasOwnProperty.call(optionalDependencies, platformPackage)) {
40
+ const supported = Object.keys(optionalDependencies)
41
+ .map((name) => name.slice(main.length + 1))
42
+ .join(", ");
43
+ fail(
44
+ `${main} has no binary for this platform, ${target}; it has binaries for ${supported}.\n` +
45
+ "Build zenith from source with " +
46
+ "`cargo install --locked --git https://github.com/feds01/zenith zenith`,\n" +
47
+ "and set ZENITH_BINARY to the path of the binary.",
48
+ );
49
+ }
50
+
51
+ // 3. Where the package manager installed it.
52
+ let manifest;
53
+ try {
54
+ manifest = require.resolve(`${platformPackage}/package.json`);
55
+ } catch {
56
+ fail(
57
+ `${platformPackage}, which has the binary for this platform, isn't installed.\n` +
58
+ `It is an optional dependency of ${main}, so it is left out when optional dependencies are,\n` +
59
+ "e.g. with `npm install --omit=optional`. Install again without leaving them out,\n" +
60
+ `or add ${platformPackage}@${version} to your dependencies.`,
61
+ );
62
+ }
63
+ return path.join(path.dirname(manifest), process.platform === "win32" ? "zenith.exe" : "zenith");
64
+ }
65
+
66
+ // 1. Run the binary with the launcher's arguments and streams.
67
+ const binary = binaryPath();
68
+ const child = spawn(binary, process.argv.slice(2), { stdio: "inherit" });
69
+
70
+ // 2. Pass on the signals that would stop the launcher alone, so that the
71
+ // binary stops with it rather than running on.
72
+ const forward = (signal) => child.kill(signal);
73
+ for (const signal of FORWARDED_SIGNALS) {
74
+ process.on(signal, forward);
75
+ }
76
+
77
+ child.on("error", (error) => fail(`could not run ${binary}: ${error.message}`));
78
+
79
+ // 3. Exit as the binary did: with its exit code, or by the signal that
80
+ // stopped it.
81
+ child.on("exit", (code, signal) => {
82
+ for (const forwarded of FORWARDED_SIGNALS) {
83
+ process.removeListener(forwarded, forward);
84
+ }
85
+ if (signal) {
86
+ process.kill(process.pid, signal);
87
+ } else {
88
+ process.exit(code);
89
+ }
90
+ });
package/package.json CHANGED
@@ -1,118 +1,37 @@
1
1
  {
2
- "artifactDownloadUrls": [
3
- "https://github.com/feds01/zenith/releases/download/v0.1.0"
2
+ "name": "@feds01/zenith",
3
+ "version": "0.2.0",
4
+ "description": "An architecture linter for TypeScript and JavaScript codebases",
5
+ "keywords": [
6
+ "architecture",
7
+ "linter",
8
+ "imports",
9
+ "monorepo",
10
+ "typescript",
11
+ "javascript"
4
12
  ],
13
+ "homepage": "https://feds01.github.io/zenith/",
14
+ "bugs": "https://github.com/feds01/zenith/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/feds01/zenith.git"
18
+ },
19
+ "license": "MIT",
5
20
  "author": "Alexander Fedotov <alexander.fedotov.uk@gmail.com>",
6
21
  "bin": {
7
- "zenith": "run-zenith.js"
8
- },
9
- "dependencies": {
10
- "detect-libc": "^2.1.2"
11
- },
12
- "description": "An architecture linter for TypeScript and JavaScript codebases",
13
- "devDependencies": {
14
- "prettier": "^3.9.6"
22
+ "zenith": "bin/zenith.js"
15
23
  },
24
+ "files": [
25
+ "bin"
26
+ ],
16
27
  "engines": {
17
- "node": ">=14.14",
18
- "npm": ">=6"
19
- },
20
- "glibcMinimum": {
21
- "major": 2,
22
- "series": 31
23
- },
24
- "homepage": "https://github.com/feds01/zenith",
25
- "license": "MIT",
26
- "name": "@feds01/zenith",
27
- "preferUnplugged": true,
28
- "repository": "https://github.com/feds01/zenith",
29
- "scripts": {
30
- "fmt": "prettier --write **/*.js",
31
- "fmt:check": "prettier --check **/*.js",
32
- "postinstall": "node ./install.js"
33
- },
34
- "supportedPlatforms": {
35
- "aarch64-apple-darwin": {
36
- "artifactName": "zenith-aarch64-apple-darwin.tar.xz",
37
- "bins": {
38
- "zenith": "zenith"
39
- },
40
- "zipExt": ".tar.xz"
41
- },
42
- "aarch64-pc-windows-msvc": {
43
- "artifactName": "zenith-x86_64-pc-windows-msvc.zip",
44
- "bins": {
45
- "zenith": "zenith.exe"
46
- },
47
- "zipExt": ".zip"
48
- },
49
- "aarch64-unknown-linux-gnu": {
50
- "artifactName": "zenith-aarch64-unknown-linux-musl.tar.xz",
51
- "bins": {
52
- "zenith": "zenith"
53
- },
54
- "zipExt": ".tar.xz"
55
- },
56
- "aarch64-unknown-linux-musl-dynamic": {
57
- "artifactName": "zenith-aarch64-unknown-linux-musl.tar.xz",
58
- "bins": {
59
- "zenith": "zenith"
60
- },
61
- "zipExt": ".tar.xz"
62
- },
63
- "aarch64-unknown-linux-musl-static": {
64
- "artifactName": "zenith-aarch64-unknown-linux-musl.tar.xz",
65
- "bins": {
66
- "zenith": "zenith"
67
- },
68
- "zipExt": ".tar.xz"
69
- },
70
- "x86_64-apple-darwin": {
71
- "artifactName": "zenith-x86_64-apple-darwin.tar.xz",
72
- "bins": {
73
- "zenith": "zenith"
74
- },
75
- "zipExt": ".tar.xz"
76
- },
77
- "x86_64-pc-windows-gnu": {
78
- "artifactName": "zenith-x86_64-pc-windows-msvc.zip",
79
- "bins": {
80
- "zenith": "zenith.exe"
81
- },
82
- "zipExt": ".zip"
83
- },
84
- "x86_64-pc-windows-msvc": {
85
- "artifactName": "zenith-x86_64-pc-windows-msvc.zip",
86
- "bins": {
87
- "zenith": "zenith.exe"
88
- },
89
- "zipExt": ".zip"
90
- },
91
- "x86_64-unknown-linux-gnu": {
92
- "artifactName": "zenith-x86_64-unknown-linux-musl.tar.xz",
93
- "bins": {
94
- "zenith": "zenith"
95
- },
96
- "zipExt": ".tar.xz"
97
- },
98
- "x86_64-unknown-linux-musl-dynamic": {
99
- "artifactName": "zenith-x86_64-unknown-linux-musl.tar.xz",
100
- "bins": {
101
- "zenith": "zenith"
102
- },
103
- "zipExt": ".tar.xz"
104
- },
105
- "x86_64-unknown-linux-musl-static": {
106
- "artifactName": "zenith-x86_64-unknown-linux-musl.tar.xz",
107
- "bins": {
108
- "zenith": "zenith"
109
- },
110
- "zipExt": ".tar.xz"
111
- }
28
+ "node": ">=14"
112
29
  },
113
- "version": "0.1.0",
114
- "volta": {
115
- "node": "18.14.1",
116
- "npm": "9.5.0"
30
+ "optionalDependencies": {
31
+ "@feds01/zenith-darwin-arm64": "0.2.0",
32
+ "@feds01/zenith-darwin-x64": "0.2.0",
33
+ "@feds01/zenith-linux-arm64": "0.2.0",
34
+ "@feds01/zenith-linux-x64": "0.2.0",
35
+ "@feds01/zenith-win32-x64": "0.2.0"
117
36
  }
118
- }
37
+ }
package/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- /node_modules
2
-
package/binary-install.js DELETED
@@ -1,348 +0,0 @@
1
- const {
2
- createWriteStream,
3
- existsSync,
4
- mkdirSync,
5
- mkdtemp,
6
- rmSync,
7
- } = require("fs");
8
- const { join, sep } = require("path");
9
- const { spawnSync } = require("child_process");
10
- const { tmpdir } = require("os");
11
-
12
- const https = require("node:https");
13
- const http = require("node:http");
14
-
15
- const tmpDir = tmpdir();
16
-
17
- const error = (msg) => {
18
- console.error(msg);
19
- process.exit(1);
20
- };
21
-
22
- function getProxyForUrl(urlString) {
23
- const url = new URL(urlString);
24
- const isHttps = url.protocol === "https:";
25
-
26
- const noProxy = process.env.NO_PROXY || process.env.no_proxy || "";
27
- if (noProxy === "*") return null;
28
- if (noProxy) {
29
- const hostname = url.hostname.toLowerCase();
30
- const noProxyList = noProxy.split(",").map((s) => s.trim().toLowerCase());
31
- for (const entry of noProxyList) {
32
- if (hostname === entry || hostname.endsWith("." + entry)) {
33
- return null;
34
- }
35
- }
36
- }
37
-
38
- const proxyEnv = isHttps
39
- ? process.env.HTTPS_PROXY || process.env.https_proxy
40
- : process.env.HTTP_PROXY || process.env.http_proxy;
41
-
42
- if (!proxyEnv) return null;
43
-
44
- const proxyUrl = new URL(proxyEnv);
45
-
46
- let auth = null;
47
- if (proxyUrl.username || proxyUrl.password) {
48
- auth = `${proxyUrl.username}:${proxyUrl.password}`;
49
- }
50
-
51
- return {
52
- hostname: proxyUrl.hostname,
53
- port: proxyUrl.port || (proxyUrl.protocol === "https:" ? 443 : 80),
54
- auth: auth,
55
- };
56
- }
57
-
58
- function connectThroughProxy(proxy, target) {
59
- return new Promise((resolve, reject) => {
60
- const headers = {};
61
- if (proxy.auth) {
62
- headers["Proxy-Authorization"] =
63
- "Basic " + Buffer.from(proxy.auth).toString("base64");
64
- }
65
-
66
- const connectReq = http.request({
67
- hostname: proxy.hostname,
68
- port: proxy.port,
69
- method: "CONNECT",
70
- path: `${target.hostname}:${target.port || 443}`,
71
- headers,
72
- });
73
- connectReq.on("connect", (res, socket) => {
74
- if (res.statusCode === 200) {
75
- resolve(socket);
76
- } else {
77
- reject(new Error(`Proxy CONNECT failed with status ${res.statusCode}`));
78
- }
79
- });
80
- connectReq.on("error", reject);
81
- connectReq.end();
82
- });
83
- }
84
-
85
- function download(urlString, maxRedirects) {
86
- if (maxRedirects === undefined) maxRedirects = 5;
87
- return new Promise((resolve, reject) => {
88
- if (maxRedirects < 0) {
89
- return reject(new Error("Too many redirects"));
90
- }
91
-
92
- const parsed = new URL(urlString);
93
- const isHttps = parsed.protocol === "https:";
94
- const mod = isHttps ? https : http;
95
- const proxy = getProxyForUrl(urlString);
96
-
97
- const doRequest = (extraOptions) => {
98
- const options = Object.assign(
99
- {
100
- hostname: parsed.hostname,
101
- port: parsed.port || (isHttps ? 443 : 80),
102
- path: parsed.pathname + parsed.search,
103
- method: "GET",
104
- headers: { "User-Agent": "cargo-dist-npm-installer" },
105
- },
106
- extraOptions || {},
107
- );
108
-
109
- if (proxy && !isHttps) {
110
- // HTTP through HTTP proxy: request the full URL via the proxy
111
- options.hostname = proxy.hostname;
112
- options.port = proxy.port;
113
- options.path = urlString;
114
- if (proxy.auth) {
115
- options.headers["Proxy-Authorization"] =
116
- "Basic " + Buffer.from(proxy.auth).toString("base64");
117
- }
118
- }
119
-
120
- const req = mod.request(options, (res) => {
121
- if (
122
- res.statusCode >= 300 &&
123
- res.statusCode < 400 &&
124
- res.headers.location
125
- ) {
126
- res.resume();
127
- const nextUrl = new URL(res.headers.location, urlString).toString();
128
- return download(nextUrl, maxRedirects - 1).then(resolve, reject);
129
- }
130
- if (res.statusCode < 200 || res.statusCode >= 300) {
131
- res.resume();
132
- return reject(new Error(`HTTP ${res.statusCode} from ${urlString}`));
133
- }
134
- resolve(res);
135
- });
136
- req.on("error", reject);
137
- req.end();
138
- };
139
-
140
- if (proxy && isHttps) {
141
- connectThroughProxy(proxy, parsed).then(
142
- (socket) => doRequest({ socket, agent: false }),
143
- reject,
144
- );
145
- } else {
146
- doRequest();
147
- }
148
- });
149
- }
150
-
151
- class Package {
152
- constructor(platform, name, url, filename, zipExt, binaries) {
153
- let errors = [];
154
- if (typeof url !== "string") {
155
- errors.push("url must be a string");
156
- } else {
157
- try {
158
- new URL(url);
159
- } catch (e) {
160
- errors.push(e);
161
- }
162
- }
163
- if (name && typeof name !== "string") {
164
- errors.push("package name must be a string");
165
- }
166
- if (!name) {
167
- errors.push("You must specify the name of your package");
168
- }
169
- if (binaries && typeof binaries !== "object") {
170
- errors.push("binaries must be a string => string map");
171
- }
172
- if (!binaries) {
173
- errors.push("You must specify the binaries in the package");
174
- }
175
-
176
- if (errors.length > 0) {
177
- let errorMsg =
178
- "One or more of the parameters you passed to the Binary constructor are invalid:\n";
179
- errors.forEach((error) => {
180
- errorMsg += error;
181
- });
182
- errorMsg +=
183
- '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})';
184
- error(errorMsg);
185
- }
186
-
187
- this.platform = platform;
188
- this.url = url;
189
- this.name = name;
190
- this.filename = filename;
191
- this.zipExt = zipExt;
192
- this.installDirectory = join(__dirname, "node_modules", ".bin_real");
193
- this.binaries = binaries;
194
-
195
- if (!existsSync(this.installDirectory)) {
196
- mkdirSync(this.installDirectory, { recursive: true });
197
- }
198
- }
199
-
200
- exists() {
201
- for (const binaryName in this.binaries) {
202
- const binRelPath = this.binaries[binaryName];
203
- const binPath = join(this.installDirectory, binRelPath);
204
- if (!existsSync(binPath)) {
205
- return false;
206
- }
207
- }
208
- return true;
209
- }
210
-
211
- install(suppressLogs = false) {
212
- if (this.exists()) {
213
- if (!suppressLogs) {
214
- console.error(
215
- `${this.name} is already installed, skipping installation.`,
216
- );
217
- }
218
- return Promise.resolve();
219
- }
220
-
221
- try {
222
- rmSync(this.installDirectory, { recursive: true, force: true });
223
- } catch {
224
- // ignore - directory may not exist
225
- }
226
-
227
- mkdirSync(this.installDirectory, { recursive: true });
228
-
229
- if (!suppressLogs) {
230
- console.error(`Downloading release from ${this.url}`);
231
- }
232
-
233
- return download(this.url)
234
- .then((res) => {
235
- return new Promise((resolve, reject) => {
236
- mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
237
- if (err) return reject(err);
238
- let tempFile = join(directory, this.filename);
239
- const sink = res.pipe(createWriteStream(tempFile));
240
- sink.on("error", (err) => reject(err));
241
- sink.on("close", () => {
242
- if (/\.tar\.*/.test(this.zipExt)) {
243
- const result = spawnSync("tar", [
244
- "xf",
245
- tempFile,
246
- // The tarballs are stored with a leading directory
247
- // component; we strip one component in the
248
- // shell installers too.
249
- "--strip-components",
250
- "1",
251
- "-C",
252
- this.installDirectory,
253
- ]);
254
- if (result.status == 0) {
255
- resolve();
256
- } else if (result.error) {
257
- reject(result.error);
258
- } else {
259
- reject(
260
- new Error(
261
- `An error occurred untarring the artifact: stdout: ${result.stdout}; stderr: ${result.stderr}`,
262
- ),
263
- );
264
- }
265
- } else if (this.zipExt == ".zip") {
266
- let result;
267
- if (this.platform.artifactName.includes("windows")) {
268
- // Windows does not have "unzip" by default on many installations, instead
269
- // we use Expand-Archive from powershell
270
- result = spawnSync("powershell.exe", [
271
- "-NoProfile",
272
- "-NonInteractive",
273
- "-Command",
274
- `& {
275
- param([string]$LiteralPath, [string]$DestinationPath)
276
- Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force
277
- }`,
278
- tempFile,
279
- this.installDirectory,
280
- ]);
281
- } else {
282
- result = spawnSync("unzip", [
283
- "-q",
284
- tempFile,
285
- "-d",
286
- this.installDirectory,
287
- ]);
288
- }
289
-
290
- if (result.status == 0) {
291
- resolve();
292
- } else if (result.error) {
293
- reject(result.error);
294
- } else {
295
- reject(
296
- new Error(
297
- `An error occurred unzipping the artifact: stdout: ${result.stdout}; stderr: ${result.stderr}`,
298
- ),
299
- );
300
- }
301
- } else {
302
- reject(
303
- new Error(`Unrecognized file extension: ${this.zipExt}`),
304
- );
305
- }
306
- });
307
- });
308
- });
309
- })
310
- .then(() => {
311
- if (!suppressLogs) {
312
- console.error(`${this.name} has been installed!`);
313
- }
314
- })
315
- .catch((e) => {
316
- error(`Error fetching release: ${e.message}`);
317
- });
318
- }
319
-
320
- run(binaryName) {
321
- const promise = !this.exists() ? this.install(true) : Promise.resolve();
322
-
323
- promise
324
- .then(() => {
325
- const [, , ...args] = process.argv;
326
-
327
- const options = { cwd: process.cwd(), stdio: "inherit" };
328
-
329
- const binRelPath = this.binaries[binaryName];
330
- if (!binRelPath) {
331
- error(`${binaryName} is not a known binary in ${this.name}`);
332
- }
333
- const binPath = join(this.installDirectory, binRelPath);
334
- const result = spawnSync(binPath, args, options);
335
-
336
- if (result.error) {
337
- error(result.error);
338
- }
339
-
340
- process.exit(result.status);
341
- })
342
- .catch((e) => {
343
- error(e.message);
344
- });
345
- }
346
- }
347
-
348
- module.exports.Package = Package;
package/binary.js DELETED
@@ -1,124 +0,0 @@
1
- const { Package } = require("./binary-install");
2
- const os = require("os");
3
- const libc = require("detect-libc");
4
-
5
- const error = (msg) => {
6
- console.error(msg);
7
- process.exit(1);
8
- };
9
-
10
- const {
11
- name,
12
- artifactDownloadUrls,
13
- supportedPlatforms,
14
- glibcMinimum,
15
- } = require("./package.json");
16
-
17
- // FIXME: implement NPM installer handling of fallback download URLs
18
- const artifactDownloadUrl = artifactDownloadUrls[0];
19
- const builderGlibcMajorVersion = glibcMinimum.major;
20
- const builderGlibcMinorVersion = glibcMinimum.series;
21
-
22
- const getPlatform = () => {
23
- const rawOsType = os.type();
24
- const rawArchitecture = os.arch();
25
-
26
- // We want to use rust-style target triples as the canonical key
27
- // for a platform, so translate the "os" library's concepts into rust ones
28
- let osType = "";
29
- switch (rawOsType) {
30
- case "Windows_NT":
31
- osType = "pc-windows-msvc";
32
- break;
33
- case "Darwin":
34
- osType = "apple-darwin";
35
- break;
36
- case "Linux":
37
- osType = "unknown-linux-gnu";
38
- break;
39
- }
40
-
41
- let arch = "";
42
- switch (rawArchitecture) {
43
- case "x64":
44
- arch = "x86_64";
45
- break;
46
- case "arm64":
47
- arch = "aarch64";
48
- break;
49
- }
50
-
51
- if (rawOsType === "Linux") {
52
- if (libc.familySync() == "musl") {
53
- osType = "unknown-linux-musl-dynamic";
54
- } else if (libc.isNonGlibcLinuxSync()) {
55
- console.warn(
56
- "Your libc is neither glibc nor musl; trying static musl binary instead",
57
- );
58
- osType = "unknown-linux-musl-static";
59
- } else {
60
- let libcVersion = libc.versionSync();
61
- let splitLibcVersion = libcVersion.split(".");
62
- let libcMajorVersion = splitLibcVersion[0];
63
- let libcMinorVersion = splitLibcVersion[1];
64
- if (
65
- libcMajorVersion != builderGlibcMajorVersion ||
66
- libcMinorVersion < builderGlibcMinorVersion
67
- ) {
68
- // We can't run the glibc binaries, but we can run the static musl ones
69
- // if they exist
70
- console.warn(
71
- "Your glibc isn't compatible; trying static musl binary instead",
72
- );
73
- osType = "unknown-linux-musl-static";
74
- }
75
- }
76
- }
77
-
78
- // Assume the above succeeded and build a target triple to look things up with.
79
- // If any of it failed, this lookup will fail and we'll handle it like normal.
80
- let targetTriple = `${arch}-${osType}`;
81
- let platform = supportedPlatforms[targetTriple];
82
-
83
- if (!platform) {
84
- error(
85
- `Platform with type "${rawOsType}" and architecture "${rawArchitecture}" is not supported by ${name}.\nYour system must be one of the following:\n\n${Object.keys(
86
- supportedPlatforms,
87
- ).join(",")}`,
88
- );
89
- }
90
-
91
- return platform;
92
- };
93
-
94
- const getPackage = () => {
95
- const platform = getPlatform();
96
- const url = `${artifactDownloadUrl}/${platform.artifactName}`;
97
- let filename = platform.artifactName;
98
- let ext = platform.zipExt;
99
- let binary = new Package(platform, name, url, filename, ext, platform.bins);
100
-
101
- return binary;
102
- };
103
-
104
- const install = (suppressLogs) => {
105
- if (!artifactDownloadUrl || artifactDownloadUrl.length === 0) {
106
- console.warn("in demo mode, not installing binaries");
107
- return;
108
- }
109
- const pkg = getPackage();
110
-
111
- return pkg.install(suppressLogs);
112
- };
113
-
114
- const run = (binaryName) => {
115
- const pkg = getPackage();
116
-
117
- pkg.run(binaryName);
118
- };
119
-
120
- module.exports = {
121
- install,
122
- run,
123
- getPackage,
124
- };
package/install.js DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { install } = require("./binary");
4
- install(false);
@@ -1,52 +0,0 @@
1
- {
2
- "lockfileVersion": 3,
3
- "name": "@feds01/zenith",
4
- "packages": {
5
- "": {
6
- "bin": {
7
- "zenith": "run-zenith.js"
8
- },
9
- "dependencies": {
10
- "detect-libc": "^2.1.2"
11
- },
12
- "devDependencies": {
13
- "prettier": "^3.9.6"
14
- },
15
- "engines": {
16
- "node": ">=14.14",
17
- "npm": ">=6"
18
- },
19
- "hasInstallScript": true,
20
- "license": "MIT",
21
- "name": "@feds01/zenith",
22
- "version": "0.1.0"
23
- },
24
- "node_modules/detect-libc": {
25
- "engines": {
26
- "node": ">=8"
27
- },
28
- "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
29
- "license": "Apache-2.0",
30
- "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
31
- "version": "2.1.2"
32
- },
33
- "node_modules/prettier": {
34
- "bin": {
35
- "prettier": "bin/prettier.cjs"
36
- },
37
- "dev": true,
38
- "engines": {
39
- "node": ">=14"
40
- },
41
- "funding": {
42
- "url": "https://github.com/prettier/prettier?sponsor=1"
43
- },
44
- "integrity": "sha512-OpN0zzVdiaiAhxpuuj5efpIS4sY9j7bY6uR5mnj5yPzGkdkjNKSJeUThPb60Jw29QuAZgA4o+/iB49kFiaBX6g==",
45
- "license": "MIT",
46
- "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.6.tgz",
47
- "version": "3.9.6"
48
- }
49
- },
50
- "requires": true,
51
- "version": "0.1.0"
52
- }
package/run-zenith.js DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { run } = require("./binary");
4
- run("zenith");