@dif.sh/cli 0.4.0 → 0.4.1

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/install.js +28 -2
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -74,6 +74,21 @@ function extract(archivePath, ext, destDir) {
74
74
  throw new Error(`unknown archive type: ${ext}`);
75
75
  }
76
76
 
77
+ // Release archives wrap the binary in a top-level `dif-<target>/` directory so
78
+ // Homebrew (which auto-cds into a single top-level dir) can consume them. Walk
79
+ // the extracted tree and return the first file whose basename matches.
80
+ function findBinary(dir, name) {
81
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
82
+ const full = path.join(dir, entry.name);
83
+ if (entry.isFile() && entry.name === name) return full;
84
+ if (entry.isDirectory()) {
85
+ const nested = findBinary(full, name);
86
+ if (nested) return nested;
87
+ }
88
+ }
89
+ return null;
90
+ }
91
+
77
92
  async function main() {
78
93
  const key = platformKey();
79
94
  const target = TARGETS[key];
@@ -94,18 +109,29 @@ async function main() {
94
109
  fs.mkdirSync(BIN_DIR, { recursive: true });
95
110
 
96
111
  const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${target.archive}`;
97
- const tmp = path.join(os.tmpdir(), `${PKG.name.replace(/[^a-z0-9]/gi, "_")}-${VERSION}.${target.ext}`);
112
+ const slug = PKG.name.replace(/[^a-z0-9]/gi, "_");
113
+ const tmp = path.join(os.tmpdir(), `${slug}-${VERSION}.${target.ext}`);
114
+ const staging = fs.mkdtempSync(path.join(os.tmpdir(), `${slug}-${VERSION}-`));
98
115
 
99
116
  try {
100
117
  console.log(`@dif.sh/cli: downloading ${url}`);
101
118
  await download(url, tmp);
102
- extract(tmp, target.ext, BIN_DIR);
119
+ extract(tmp, target.ext, staging);
120
+ const found = findBinary(staging, target.binary);
121
+ if (!found) {
122
+ throw new Error(`binary ${target.binary} not found in ${target.archive}`);
123
+ }
124
+ // copy+unlink (not rename) survives EXDEV when tmpdir is on a different
125
+ // filesystem from the package — common on Linux where /tmp is tmpfs.
126
+ fs.copyFileSync(found, binaryPath);
127
+ fs.unlinkSync(found);
103
128
  fs.chmodSync(binaryPath, 0o755);
104
129
  console.log(`@dif.sh/cli: installed dif v${VERSION} for ${key}`);
105
130
  } catch (err) {
106
131
  fail(`installation failed: ${err.message}`);
107
132
  } finally {
108
133
  try { fs.unlinkSync(tmp); } catch (_) { /* best-effort */ }
134
+ try { fs.rmSync(staging, { recursive: true, force: true }); } catch (_) { /* best-effort */ }
109
135
  }
110
136
  }
111
137
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dif.sh/cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "The dif.sh CLI. Experiments live in the repo. This package downloads the matching Rust binary on install.",
5
5
  "license": "MIT",
6
6
  "bin": {