mirror of
https://github.com/bitbaum/fleet.git
synced 2026-12-04 05:30:18 +01:00
When a package's verified Git release was newer than its npm release, the updater rewrote an npm range to github:<repo>#<sha>. For bip-kit that window was open on 2026-11-13 (Git 0.7.1, npm 0.6.1): pnpm refused to build the Git artifact (ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED) and the whole bump failed for eight repositories, so none of their other packages moved either (among them ai-kit 1.27, the fleet usage log). releasedPackage now carries npmVersion beside a Git target. A consumer on an npm range takes the newest npm version, or waits for the publish; a package with no npm release is still adopted from Git, and a consumer already on Git still advances along Git. Claude-Session: https://claude.ai/code/session_019MDtmtUQb9BM11ycpApwGq Co-authored-by: Claude <noreply@anthropic.com>
91 lines
2.9 KiB
JavaScript
91 lines
2.9 KiB
JavaScript
import { latestVerifiedGitRelease } from "./git-package-currency.mjs";
|
|
|
|
const stable = (v) => /^\d+\.\d+\.\d+$/.test(v ?? "");
|
|
const compare = (a, b) => {
|
|
const left = a.split(".").map(Number),
|
|
right = b.split(".").map(Number);
|
|
for (let i = 0; i < 3; i++)
|
|
if (left[i] !== right[i]) return left[i] - right[i];
|
|
return 0;
|
|
};
|
|
|
|
/** Recommend an actual release, never an unpublished repository manifest. */
|
|
export function releasedPackage(pkg, npmVersion, gitRelease) {
|
|
const npm = stable(npmVersion) ? npmVersion : null;
|
|
const git =
|
|
stable(gitRelease?.version) && /^[0-9a-f]{40}$/.test(gitRelease?.sha ?? "")
|
|
? gitRelease
|
|
: null;
|
|
if (!npm && !git)
|
|
throw new Error(
|
|
`${pkg.name}: no stable published or verified Git artifact`,
|
|
);
|
|
if (git && (!npm || compare(git.version, npm) > 0)) {
|
|
const repo = pkg.repo
|
|
.replace(/^https:\/\/github\.com\//, "")
|
|
.replace(/\.git$/, "");
|
|
return {
|
|
...pkg,
|
|
version: git.version,
|
|
install: { source: "git", command: `pnpm add github:${repo}#${git.sha}` },
|
|
release: { source: "git", tag: git.tag, commit: git.sha },
|
|
// What npm has, for consumers that install from npm and stay there
|
|
// (preferred-package-update.mjs).
|
|
npmVersion: npm,
|
|
};
|
|
}
|
|
return {
|
|
...pkg,
|
|
version: npm,
|
|
install: { source: "npm", command: `pnpm add ${pkg.name}@^${npm}` },
|
|
release: { source: "npm", version: npm },
|
|
};
|
|
}
|
|
|
|
export async function releaseTargets(
|
|
packages,
|
|
fetchImpl = fetch,
|
|
gitRelease = latestVerifiedGitRelease,
|
|
) {
|
|
// Finish asynchronous registry reads before synchronous gh verification.
|
|
// Otherwise gh can block the event loop past another fetch's deadline.
|
|
const versions = await Promise.all(
|
|
packages.map(async (pkg) => {
|
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
let response;
|
|
try {
|
|
response = await fetchImpl(
|
|
`https://registry.npmjs.org/${encodeURIComponent(pkg.name)}`,
|
|
{ signal: AbortSignal.timeout(10_000) },
|
|
);
|
|
if (response.status === 404) return null;
|
|
if (response.ok)
|
|
return (await response.json())?.["dist-tags"]?.latest;
|
|
} catch (error) {
|
|
if (attempt === 2)
|
|
throw new Error(`${pkg.name}: npm release lookup unavailable`, {
|
|
cause: error,
|
|
});
|
|
continue;
|
|
}
|
|
if (
|
|
attempt === 2 ||
|
|
(response.status !== 429 && response.status < 500)
|
|
) {
|
|
throw new Error(
|
|
`${pkg.name}: npm release lookup returned HTTP ${response.status}`,
|
|
);
|
|
}
|
|
}
|
|
}),
|
|
);
|
|
const targets = [];
|
|
for (const [index, pkg] of packages.entries()) {
|
|
const repo = pkg.repo
|
|
.replace(/^https:\/\/github\.com\//, "")
|
|
.replace(/\.git$/, "");
|
|
targets.push(releasedPackage(pkg, versions[index], await gitRelease(repo)));
|
|
}
|
|
return targets;
|
|
}
|