clawreform 0.3.1 → 0.3.2

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/lib/install.js +59 -5
  2. package/package.json +1 -1
package/lib/install.js CHANGED
@@ -52,13 +52,32 @@ async function downloadToFile(url, destination) {
52
52
  });
53
53
 
54
54
  if (!response.ok) {
55
- throw new Error(`Download failed (${response.status}): ${url}`);
55
+ const error = new Error(`Download failed (${response.status}): ${url}`);
56
+ error.status = response.status;
57
+ throw error;
56
58
  }
57
59
 
58
60
  const arrayBuffer = await response.arrayBuffer();
59
61
  fs.writeFileSync(destination, Buffer.from(arrayBuffer));
60
62
  }
61
63
 
64
+ async function fetchLatestReleaseTag() {
65
+ const url = `https://api.github.com/repos/${REPO}/releases/latest`;
66
+ const response = await fetch(url, {
67
+ headers: {
68
+ "User-Agent": "clawreform-npm-installer"
69
+ }
70
+ });
71
+ if (!response.ok) {
72
+ throw new Error(`Failed to fetch latest release tag (${response.status})`);
73
+ }
74
+ const payload = await response.json();
75
+ if (!payload || typeof payload.tag_name !== "string" || !payload.tag_name.trim()) {
76
+ throw new Error("Latest release payload did not include tag_name.");
77
+ }
78
+ return payload.tag_name.trim();
79
+ }
80
+
62
81
  function extractArchive(archivePath, destinationPath, ext) {
63
82
  if (ext === "tar.gz") {
64
83
  const result = spawnSync("tar", ["-xzf", archivePath, "-C", destinationPath], {
@@ -120,9 +139,8 @@ function installedBinaryPath() {
120
139
 
121
140
  async function installBinary(options = {}) {
122
141
  const log = typeof options.log === "function" ? options.log : console.log;
123
- const version = normalizeVersion(options.version || process.env.CLAWREFORM_VERSION || require("../package.json").version);
142
+ const preferredVersion = normalizeVersion(options.version || process.env.CLAWREFORM_VERSION || require("../package.json").version);
124
143
  const { target, ext, binName } = resolveTarget();
125
- const downloadUrl = assetUrl(version, target, ext);
126
144
 
127
145
  const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "clawreform-npm-"));
128
146
  const archivePath = path.join(tmpRoot, `clawreform.${ext}`);
@@ -130,8 +148,44 @@ async function installBinary(options = {}) {
130
148
  fs.mkdirSync(extractPath, { recursive: true });
131
149
 
132
150
  try {
133
- log(`clawreform npm: downloading ${version} (${target})`);
134
- await downloadToFile(downloadUrl, archivePath);
151
+ let downloadedVersion = null;
152
+ const versionsToTry = [preferredVersion];
153
+ try {
154
+ const latestTag = normalizeVersion(await fetchLatestReleaseTag());
155
+ if (!versionsToTry.includes(latestTag)) {
156
+ versionsToTry.push(latestTag);
157
+ }
158
+ } catch (error) {
159
+ const message = error instanceof Error ? error.message : String(error);
160
+ log(`clawreform npm: warning: unable to resolve latest release tag (${message})`);
161
+ }
162
+
163
+ let lastError = null;
164
+ for (const version of versionsToTry) {
165
+ const downloadUrl = assetUrl(version, target, ext);
166
+ try {
167
+ log(`clawreform npm: downloading ${version} (${target})`);
168
+ await downloadToFile(downloadUrl, archivePath);
169
+ downloadedVersion = version;
170
+ break;
171
+ } catch (error) {
172
+ lastError = error;
173
+ const status = error && typeof error === "object" ? error.status : null;
174
+ if (status === 404) {
175
+ continue;
176
+ }
177
+ throw error;
178
+ }
179
+ }
180
+
181
+ if (!downloadedVersion) {
182
+ throw lastError || new Error("Could not download a matching clawreform release asset.");
183
+ }
184
+
185
+ if (downloadedVersion !== preferredVersion) {
186
+ log(`clawreform npm: release ${preferredVersion} was unavailable, using ${downloadedVersion} instead`);
187
+ }
188
+
135
189
  extractArchive(archivePath, extractPath, ext);
136
190
 
137
191
  const sourceBinary = findFileRecursively(extractPath, binName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawreform",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Cross-platform npm launcher for clawREFORM by aegntic.ai CLI",
5
5
  "license": "MIT",
6
6
  "author": "clawREFORM by aegntic.ai Team",