@cjohnhanson/zttl 0.2.5

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 (2) hide show
  1. package/bin/run.js +81 -0
  2. package/package.json +26 -0
package/bin/run.js ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ // The binary lives in a per-platform package under optionalDependencies,
3
+ // so a package manager installs only the one that matches. This resolves
4
+ // it through node's own lookup rather than a hardcoded node_modules path,
5
+ // and execs it.
6
+ //
7
+ // Nothing is downloaded at install time. There is no postinstall, so an
8
+ // offline install, an air-gapped runner, and `--ignore-scripts` all work.
9
+ const { platform, arch, env } = process;
10
+ const { spawnSync } = require("child_process");
11
+ const { existsSync } = require("fs");
12
+ const os = require("os");
13
+
14
+ // The Linux binaries are static musl, which runs on a musl host and on
15
+ // a glibc host alike. One Linux entry serves both, and no probe of the
16
+ // host libc is needed.
17
+ const PLATFORMS = {
18
+ darwin: {
19
+ arm64: "@cjohnhanson/zttl-darwin-arm64/zettel",
20
+ x64: "@cjohnhanson/zttl-darwin-x64/zettel",
21
+ },
22
+ linux: {
23
+ arm64: "@cjohnhanson/zttl-linux-arm64-musl/zettel",
24
+ x64: "@cjohnhanson/zttl-linux-x64-musl/zettel",
25
+ },
26
+ };
27
+
28
+ const rel = env.ZTTL_BINARY ? null : PLATFORMS?.[platform]?.[arch];
29
+ let bin = env.ZTTL_BINARY || null;
30
+ let unresolved = false;
31
+ if (!bin && rel) {
32
+ // The platform is built, so a failure here means the package did not
33
+ // install. That is a different problem from an unsupported platform
34
+ // and it gets a different message.
35
+ try {
36
+ bin = require.resolve(rel);
37
+ } catch {
38
+ unresolved = true;
39
+ }
40
+ }
41
+
42
+ // An override that does not exist is a reader's typo, not a platform
43
+ // they are stuck on. It gets its own message naming the path.
44
+ if (bin && !existsSync(bin)) {
45
+ console.error(`ZTTL_BINARY is set to ${bin}, and no file is there.`);
46
+ process.exitCode = 1;
47
+ } else if (unresolved) {
48
+ console.error(
49
+ `zttl supports ${platform} ${arch}, and its binary package is not ` +
50
+ "installed. Reinstall with `npm install --include=optional`.",
51
+ );
52
+ process.exitCode = 1;
53
+ } else if (!bin) {
54
+ console.error(
55
+ `zttl ships no prebuilt binary for ${platform} ${arch}. ` +
56
+ "Install it with `cargo install zttl`, or set ZTTL_BINARY to a path.",
57
+ );
58
+ process.exitCode = 1;
59
+ } else {
60
+ const result = spawnSync(bin, process.argv.slice(2), {
61
+ shell: false,
62
+ stdio: "inherit",
63
+ });
64
+ if (result.error) {
65
+ // A path that is a directory, or a file without the execute bit,
66
+ // fails here. Reported raw it is a ten-frame stack trace naming
67
+ // this file, which tells a reader nothing about their own setup.
68
+ console.error(`zttl cannot run ${bin}: ${result.error.message}`);
69
+ process.exitCode = 1;
70
+ } else if (result.signal) {
71
+ // A binary killed by a signal has a null status. Assigning that
72
+ // null exits 0, so a crash reads as a pass to the git hooks and the
73
+ // continuous integration that call this. Report it the way a shell
74
+ // does, as 128 plus the signal number.
75
+ const number = os.constants.signals[result.signal];
76
+ console.error(`zttl: ${bin} was killed by ${result.signal}`);
77
+ process.exitCode = number ? 128 + number : 1;
78
+ } else {
79
+ process.exitCode = result.status;
80
+ }
81
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@cjohnhanson/zttl",
3
+ "description": "Zettelkasten note management on frontmattered markdown",
4
+ "bin": {
5
+ "zttl": "bin/run.js",
6
+ "zettel": "bin/run.js"
7
+ },
8
+ "files": [
9
+ "bin/run.js"
10
+ ],
11
+ "engines": {
12
+ "node": ">=18"
13
+ },
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/cjohnhanson/zettel.git"
18
+ },
19
+ "optionalDependencies": {
20
+ "@cjohnhanson/zttl-darwin-arm64": "0.2.5",
21
+ "@cjohnhanson/zttl-darwin-x64": "0.2.5",
22
+ "@cjohnhanson/zttl-linux-arm64-musl": "0.2.5",
23
+ "@cjohnhanson/zttl-linux-x64-musl": "0.2.5"
24
+ },
25
+ "version": "0.2.5"
26
+ }