Skip to content

fix: read version from package.json instead of hardcoded string#18

Merged
manufacturist merged 1 commit into
mainfrom
fix/version-flag
Jun 19, 2026
Merged

fix: read version from package.json instead of hardcoded string#18
manufacturist merged 1 commit into
mainfrom
fix/version-flag

Conversation

@manufacturist

Copy link
Copy Markdown
Contributor

Summary

  • codacy --version was always printing 1.0.0 because the version string in src/index.ts was hardcoded and never updated with each release
  • Fixed by replacing the literal with a runtime require("../package.json").version so it stays in sync automatically

Test plan

  • npm run build && node dist/index.js --version should print 1.3.1 (after changeset version bump) or 1.3.0 on the current branch
  • Verify the build output structure is unchanged (dist/index.js at root of dist, not nested under dist/src/)

🤖 Generated with Claude Code

The --version flag was always printing "1.0.0" because the version
string in src/index.ts was never updated alongside package.json bumps.
Replaced it with a runtime require("../package.json").version so future
releases automatically reflect the correct version.

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 19, 2026 12:48

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the CLI to dynamically load its version from package.json rather than using a hardcoded value. Feedback on the changes suggests moving the require statement below all ES import statements to maintain standard import ordering and prevent potential hoisting issues.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/index.ts
Comment on lines +4 to +5
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { version } = require("../package.json") as { version: string };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Mixing require statements with ES import statements violates standard import ordering practices (such as the ESLint import/first rule).

In TypeScript/JavaScript, import statements are hoisted to the top of the module scope during compilation, whereas require is executed at runtime in the order it appears. This means the import statements below this line will actually execute before this require statement.

To maintain clean code structure and avoid potential linting or formatting issues, please move this require statement below all the import statements (after the import of registerLogoutCommand on line 19).

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@manufacturist manufacturist merged commit 7b09b5b into main Jun 19, 2026
5 checks passed
@manufacturist manufacturist deleted the fix/version-flag branch June 19, 2026 12:50

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

The PR successfully addresses the goal of dynamically reading the project version from package.json, ensuring the --version flag remains synchronized with the release version. Codacy analysis indicates the changes are up to standards.

However, there are two primary concerns: the use of require for JSON loading in a file otherwise using ES Module imports (which can cause runtime issues and hoisting confusion), and a total reliance on manual testing. There is no automated verification that the relative path resolution will function correctly once the project is compiled to the dist folder, which is a high-risk area for this type of change.

About this PR

  • The PR currently lacks automated tests to verify the version output and relative path resolution. Given that pathing often breaks between source and build directories, it is recommended to add a unit or integration test that executes the CLI with the --version flag.

Test suggestions

  • Verify that executing the CLI with the --version flag returns the exact version string present in the project's package.json
  • Verify that the build process does not nest the output (e.g., dist/src/index.js) which would break the relative require path
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify that executing the CLI with the `--version` flag returns the exact version string present in the project's package.json
2. Verify that the build process does not nest the output (e.g., dist/src/index.js) which would break the relative require path
Low confidence findings
  • The use of require for a JSON file may cause issues if the project transitions to a strict ES Module (ESM) setup in the future. While currently suppressed by ESLint, this inconsistency should be addressed to avoid future compatibility issues.

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment thread src/index.ts
Comment on lines +4 to +5
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { version } = require("../package.json") as { version: string };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

Suggestion: Mixing require and import is inconsistent and will crash in native ES Module environments. Furthermore, because import statements are hoisted, they will always execute before this require call.

A more modern and type-safe approach is to use TypeScript's native import syntax. Try the following:

  1. Ensure resolveJsonModule is enabled in tsconfig.json.
  2. Replace the require call with a standard import: import { version } from '../package.json';.
  3. Move the import to the top of the file and remove the ESLint override.

@github-actions github-actions Bot mentioned this pull request Jun 19, 2026
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