Skip to content

fix: read actual package version for srt --version output#217

Open
javabrett wants to merge 1 commit into
anthropic-experimental:mainfrom
javabrett:fix/version-string
Open

fix: read actual package version for srt --version output#217
javabrett wants to merge 1 commit into
anthropic-experimental:mainfrom
javabrett:fix/version-string

Conversation

@javabrett

Copy link
Copy Markdown

Problem

srt --version always returns 1.0.0 regardless of the installed package version.

The current code relies on process.env.npm_package_version:

.version(process.env.npm_package_version || '1.0.0')

npm_package_version is only populated by npm when running package scripts via
npm run or npx. It is not set when executing the compiled binary directly
(e.g. srt --version, srt -c "..."), which is how srt is used in practice.
The hardcoded '1.0.0' fallback is therefore always reached.

Fix

Read the version from package.json at runtime, relative to the compiled
dist/cli.js via import.meta.url:

.version(
  (
    JSON.parse(
      fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'),
    ) as { version: string }
  ).version,
)

package.json is always present in an installed npm package, so this is
reliable in all execution contexts. The npm_package_version env var is not
kept as a fallback - when it IS set (npm scripts, npx), the package.json read
returns the same value anyway, making the fallback chain redundant.

Testing

npm run build
node dist/cli.js --version   # now returns the actual version, not 1.0.0

process.env.npm_package_version is only set when running via npm scripts
(npm run, npx), not when executing the compiled binary directly. This caused
`srt --version` to always return the hardcoded fallback "1.0.0" regardless
of the installed package version.

Fix reads the version from package.json at runtime via import.meta.url,
which correctly resolves relative to dist/cli.js in the installed package.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant