From ea87c3cff1641c8b6bc6ed994c855f3d1c4424cd Mon Sep 17 00:00:00 2001 From: Cato <41178744+catomean@users.noreply.github.com> Date: Fri, 13 Nov 2026 13:06:10 +0100 Subject: [PATCH] fix(currency): a consumer that installs a package from npm stays on npm (#533) When a package's verified Git release was newer than its npm release, the updater rewrote an npm range to github:#. 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 --- scripts/ci/package-release-target.mjs | 3 +++ scripts/ci/preferred-package-update.mjs | 28 ++++++++++++++++++++ scripts/ci/preferred-package-update.test.mjs | 15 +++++++++++ 3 files changed, 46 insertions(+) diff --git a/scripts/ci/package-release-target.mjs b/scripts/ci/package-release-target.mjs index 300959c..3d9652f 100644 --- a/scripts/ci/package-release-target.mjs +++ b/scripts/ci/package-release-target.mjs @@ -29,6 +29,9 @@ export function releasedPackage(pkg, npmVersion, gitRelease) { 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 { diff --git a/scripts/ci/preferred-package-update.mjs b/scripts/ci/preferred-package-update.mjs index c2513b3..377c511 100644 --- a/scripts/ci/preferred-package-update.mjs +++ b/scripts/ci/preferred-package-update.mjs @@ -4,6 +4,20 @@ const compare = (a, b) => { return 0; }; +/** An npm range raised to `version`, keeping the operator and any alias. */ +function npmUpdate({ repo, path, name, from, identity, have, version, sourceSha }) { + const want = parse(version); + const oldRange = identity.range; + const op = typeof oldRange === 'string' ? oldRange.match(/^[~^]/)?.[0] ?? '' : '^'; + const to = name === identity.packageName ? `${op}${version}` : `npm:${identity.packageName}@${op}${version}`; + if (from === to) return null; + const floor = parse(identity.range?.replace(/^[~^]/, '')); + if (floor && compare(floor, want) > 0) return null; + return { repo, path, name, packageName: identity.packageName, from, to, + latest: version, source: 'npm', sourceSha, + crossesMajor: have[0] !== want[0], stranded: have[0] === 0 && have[0] !== want[0] }; +} + /** The target is a fresh published/CI-verified artifact, not the registry snapshot. */ export function preferredPackageUpdate({ repo, path, name, from, identity, currentVersion, target, sourceSha }) { const have = parse(currentVersion), want = parse(target?.version); @@ -16,6 +30,20 @@ export function preferredPackageUpdate({ repo, path, name, from, identity, curre if (!/^[0-9a-f]{40}$/.test(sha ?? '') || !/^[\w.-]+\/[\w.-]+$/.test(gitRepo ?? '')) throw new Error('Unverified Git target'); const installedGit = /^(?:github:|git\+https:\/\/github\.com\/)([\w.-]+\/[\w.-]+?)(?:\.git)?#(v\d+\.\d+\.\d+|[0-9a-f]{40})$/.exec(from ?? ''); if (sameVersion && (!installedGit || installedGit[1] !== gitRepo || installedGit[2] === sha)) return null; + if (!installedGit && target.npmVersion) { + // A consumer that installs from npm stays on npm while the package is + // published there. (A package with no npm release at all is still + // adopted from its verified Git release.) A Git release leads + // the npm publish by minutes or days; moving `^0.6.1` to + // `github:bitbaum/bip-kit#` in that window made the install build + // the package from source, which pnpm refuses unless the app allows it + // (ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED), and the whole bump failed for + // eight repositories on 2026-11-13. It takes the newest npm version + // instead, or waits for the publish. + const npm = parse(target.npmVersion); + if (!npm || compare(have, npm) >= 0) return null; + return npmUpdate({ repo, path, name, from, identity, have, version: target.npmVersion, sourceSha }); + } to = `github:${gitRepo}#${sha}`; } else if (target.release?.source === 'npm') { // Preserve the dependency key, including aliases; a Git alias may differ. diff --git a/scripts/ci/preferred-package-update.test.mjs b/scripts/ci/preferred-package-update.test.mjs index 22a7a7c..f896fa3 100644 --- a/scripts/ci/preferred-package-update.test.mjs +++ b/scripts/ci/preferred-package-update.test.mjs @@ -243,3 +243,18 @@ test('automatic currency events are not suppressed by the manual dry-run input', const workflow = readFileSync(new URL('../../.github/workflows/internal-currency.yml', import.meta.url), 'utf8'); assert.match(workflow, /if:\s*\$\{\{\s*needs\.plan\.outputs\.any == 'true' && \(github\.event_name != 'workflow_dispatch' \|\| inputs\.go == true\)\s*\}\}/); }); + +test('an npm consumer of a package that is on npm stays on npm while Git leads the publish', () => { + // 2026-11-13: bip-kit's Git release (0.7.1) led npm (0.6.1); `^0.6.1` was + // rewritten to github:bitbaum/bip-kit#, pnpm refused to build it, and + // the whole bump failed for eight repositories. + const lead = { ...target, name: '@bitbaum/bip-kit', repo: 'https://github.com/bitbaum/bip-kit', version: '0.7.1', npmVersion: '0.6.1' }; + const consumer = { repo: 'app', path: 'package.json', name: '@bitbaum/bip-kit', from: '^0.6.1', identity: { packageName: '@bitbaum/bip-kit', range: '^0.6.1' }, currentVersion: '0.6.1', target: lead, sourceSha }; + assert.equal(preferredPackageUpdate(consumer), null, 'npm has nothing newer: wait for the publish'); + const behind = preferredPackageUpdate({ ...consumer, from: '^0.5.0', identity: { packageName: '@bitbaum/bip-kit', range: '^0.5.0' }, currentVersion: '0.5.0' }); + assert.equal(behind.to, '^0.6.1', 'npm has something newer: take that, not the Git artifact'); + assert.equal(behind.source, 'npm'); + // A consumer already on Git still advances along Git. + const onGit = preferredPackageUpdate({ ...consumer, from: `github:bitbaum/bip-kit#${'c'.repeat(40)}`, identity: { packageName: '@bitbaum/bip-kit' } }); + assert.equal(onGit.to, `github:bitbaum/bip-kit#${sha}`); +});