Skip to content

feat: expose readPackageVersion as a public export - #6

Merged
Mearman merged 1 commit into
mainfrom
feat/export-read-package-version
Sep 8, 2026
Merged

Mearman merged 1 commit into
mainfrom
feat/export-read-package-version

Conversation

@Mearman

@Mearman Mearman commented Sep 8, 2026

Copy link
Copy Markdown
Member

readPackageVersion already exists in this package (src/package-version.ts), shared by resolveBuildIdentity and predictNextVersion, but it was never exported. That leaves a consumer wanting the plain package.json version with nowhere to get it: resolveBuildIdentity(...).version deliberately 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.version regardless 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 a package.json that is not an object at all. defaultTagName is covered in the same file since it is the shared convention applied to that value.

No behaviour change to anything already published.

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
Mearman marked this pull request as ready for review September 8, 2026 15:10
@Mearman
Mearman merged commit 04724b9 into main Sep 8, 2026
4 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review Completed 2026-09-08T15:14:30.382693Z b3e8e45 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Mearman
Mearman deleted the feat/export-read-package-version branch September 8, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant