@paulnsorensen/tilth-nightly 0.0.0-experimental.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.
Files changed (3) hide show
  1. package/install.js +103 -0
  2. package/package.json +27 -0
  3. package/run.js +21 -0
package/install.js ADDED
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const https = require("https");
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+ const { execSync } = require("child_process");
9
+
10
+ const PLATFORM_MAP = {
11
+ "linux-x64": "x86_64-unknown-linux-musl",
12
+ "linux-arm64": "aarch64-unknown-linux-musl",
13
+ "darwin-x64": "x86_64-apple-darwin",
14
+ "darwin-arm64": "aarch64-apple-darwin",
15
+ "win32-x64": "x86_64-pc-windows-msvc",
16
+ };
17
+
18
+ const key = `${process.platform}-${process.arch}`;
19
+ const target = PLATFORM_MAP[key];
20
+
21
+ if (!target) {
22
+ console.error(`tilth: unsupported platform ${key}`);
23
+ console.error(`Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`);
24
+ process.exit(1);
25
+ }
26
+
27
+ const isWindows = process.platform === "win32";
28
+ const ext = isWindows ? "zip" : "tar.gz";
29
+ const binName = isWindows ? "tilth.exe" : "tilth";
30
+ // Fork rolling build: assets live on the fixed `nightly` prerelease, not a
31
+ // per-version tag, so this URL is version-independent.
32
+ const url = `https://github.com/paulnsorensen/tilth/releases/download/nightly/tilth-${target}.${ext}`;
33
+
34
+ const binDir = path.join(__dirname, "bin");
35
+ const binPath = path.join(binDir, binName);
36
+
37
+ // Always refresh: each npm version maps to a fresh nightly build, so never
38
+ // short-circuit on an existing (stale) binary.
39
+ fs.mkdirSync(binDir, { recursive: true });
40
+
41
+ console.log(`tilth: downloading ${target} nightly binary...`);
42
+
43
+ const MAX_REDIRECTS = 5;
44
+
45
+ // HTTPS-only, depth-capped: this binary is executed after download, so never
46
+ // let a redirect downgrade to plaintext or loop.
47
+ function follow(url, depth, callback) {
48
+ if (!url.startsWith("https:")) {
49
+ console.error(`tilth: refusing non-HTTPS download URL: ${url}`);
50
+ process.exit(1);
51
+ }
52
+ if (depth > MAX_REDIRECTS) {
53
+ console.error(`tilth: too many redirects (>${MAX_REDIRECTS})`);
54
+ process.exit(1);
55
+ }
56
+ https.get(url, { headers: { "User-Agent": "tilth-npm" } }, (res) => {
57
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
58
+ follow(res.headers.location, depth + 1, callback);
59
+ } else if (res.statusCode !== 200) {
60
+ console.error(`tilth: download failed (HTTP ${res.statusCode})`);
61
+ console.error(`URL: ${url}`);
62
+ console.error("Install manually: cargo install --git https://github.com/paulnsorensen/tilth");
63
+ process.exit(1);
64
+ } else {
65
+ callback(res);
66
+ }
67
+ }).on("error", (err) => {
68
+ console.error(`tilth: download failed: ${err.message}`);
69
+ console.error("Install manually: cargo install --git https://github.com/paulnsorensen/tilth");
70
+ process.exit(1);
71
+ });
72
+ }
73
+
74
+ follow(url, 0, (res) => {
75
+ if (isWindows) {
76
+ const tmpZip = path.join(binDir, "tilth.zip");
77
+ const out = fs.createWriteStream(tmpZip);
78
+ res.pipe(out);
79
+ out.on("finish", () => {
80
+ out.close();
81
+ try {
82
+ execSync(`tar -xf "${tmpZip}" -C "${binDir}"`, { stdio: "ignore" });
83
+ fs.unlinkSync(tmpZip);
84
+ } catch {
85
+ console.error("tilth: failed to extract.");
86
+ process.exit(1);
87
+ }
88
+ });
89
+ } else {
90
+ const tar = require("child_process").spawn("tar", ["xz", "-C", binDir], {
91
+ stdio: ["pipe", "inherit", "inherit"],
92
+ });
93
+ res.pipe(tar.stdin);
94
+ tar.on("close", (code) => {
95
+ if (code !== 0) {
96
+ console.error("tilth: failed to extract.");
97
+ process.exit(1);
98
+ }
99
+ fs.chmodSync(binPath, 0o755);
100
+ console.log("tilth: installed successfully");
101
+ });
102
+ }
103
+ });
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@paulnsorensen/tilth-nightly",
3
+ "version": "0.0.0-experimental.0",
4
+ "description": "EXPERIMENTAL rolling build of paulnsorensen/tilth off main — unofficial fork, NOT the official `tilth` package",
5
+ "bin": {
6
+ "tilth": "run.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "files": [
12
+ "install.js",
13
+ "run.js"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/paulnsorensen/tilth.git"
18
+ },
19
+ "keywords": [
20
+ "mcp",
21
+ "code-search",
22
+ "tree-sitter",
23
+ "developer-tools",
24
+ "ai-agents"
25
+ ],
26
+ "license": "MIT"
27
+ }
package/run.js ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { execFileSync } = require("child_process");
6
+ const path = require("path");
7
+
8
+ const isWindows = process.platform === "win32";
9
+ const binName = isWindows ? "tilth.exe" : "tilth";
10
+ const bin = path.join(__dirname, "bin", binName);
11
+
12
+ try {
13
+ execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
14
+ } catch (err) {
15
+ if (err.status != null) {
16
+ process.exit(err.status);
17
+ }
18
+ console.error(`tilth: failed to run binary at ${bin}`);
19
+ console.error(err.message);
20
+ process.exit(1);
21
+ }