## Summary
- CI publish workflow fails when re-run after a partial publish because
npm rejects republishing an existing version
- Add version-published checks to `check-npm-packages.js` so
already-published packages are skipped in the dry-run step
- Extract a shared `publish-if-needed.sh` script that checks the npm
registry before publishing, used by all three trusted publish steps
- Consolidate the old `checkPackageExists` and new version check into a
single `npmViewVersion` helper to avoid redundant npm registry calls
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
npm Trusted Publishing requires the package to already exist on npm
before it can be published in a “trusted” workflow.
The current workflow looks like this, for example, if we have 10 NAPI
packages:
* I added a new NAPI package and forgot about it.
* During release, CI tries to release 5 packages.
* CI encounters the missing package, errors out with “package not
found,” and exits.
* I then publish the missing package locally.
* I can’t retry the CI publish process, because the retry immediately
fails with “package already published.”
So we need to check that *all* packages exist on npm **before**
publishing anything. This allows us to publish any missed packages
without breaking the entire release process.
Co-authored-by: Claude <noreply@anthropic.com>