Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-version-flag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codacy/codacy-cloud-cli": patch
---

Fix `--version` flag reporting hardcoded `1.0.0` instead of the actual package version. The CLI now reads the version dynamically from `package.json` at runtime via `require`, so the reported version stays in sync with every release automatically.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node
import { Command } from "commander";
import { OpenAPI } from "./api/client/core/OpenAPI";
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { version } = require("../package.json") as { version: string };
Comment on lines +4 to +5

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).

Comment on lines +4 to +5

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.

import { registerInfoCommand } from "./commands/info";
import { registerRepositoriesCommand } from "./commands/repositories";
import { registerRepositoryCommand } from "./commands/repository";
Expand All @@ -27,7 +29,7 @@ OpenAPI.HEADERS = {
program
.name("codacy-cloud-cli")
.description("A CLI tool to interact with the Codacy API")
.version("1.0.0")
.version(version)
.option("-o, --output <format>", "output format (table or json)", "table");

registerInfoCommand(program);
Expand Down
Loading