feat: expose readPackageVersion as a public export - #6
Merged
Merged
Conversation
The plain package.json "version" field, unconditionally and with no git access, is a genuinely different question from resolveBuildIdentity's own version, which is a release-or-commit identity and answers with a short commit hash whenever no tag points at HEAD. A consumer wanting a stable semver regardless of tag state (an OpenAPI document's required info.version, a user agent string) had no way to ask for it, so it reimplemented the read-parse-guard by hand alongside its call into this package. The function already existed here, shared by resolveBuildIdentity and predictNextVersion; it was simply not exported. Adds its own test coverage, since it now carries a public contract: the version it reads back, and a throw rather than a placeholder for a missing file, an absent, non-string or empty field, and a package.json that is not an object at all.
Mearman
marked this pull request as ready for review
September 8, 2026 15:10
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
🎉 This PR is included in version 2.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
readPackageVersionalready exists in this package (src/package-version.ts), shared byresolveBuildIdentityandpredictNextVersion, but it was never exported. That leaves a consumer wanting the plainpackage.jsonversion with nowhere to get it:resolveBuildIdentity(...).versiondeliberately answers with a short commit hash whenever no tag points at HEAD, which is the right answer to "what is this build" and the wrong answer to "what is the last released version".acelo-ros hit exactly this. It needs a stable semver for its OpenAPI document's
info.versionregardless of tag state, so it kept a hand-rolled read-parse-guard of its own directly alongside its call into this package, with a comment explaining why it could not delegate. That is the gap this closes.One line in
index.ts, plus a README section and real test coverage now that the function carries a public contract: the version it reads back, and a throw rather than a placeholder for a missing file, an absent/non-string/empty field, and apackage.jsonthat is not an object at all.defaultTagNameis covered in the same file since it is the shared convention applied to that value.No behaviour change to anything already published.