Skip to content

feat(cli): add CLI version support and show @midscene/computer version in health check#2057

Open
yuyutaotao wants to merge 2 commits intomainfrom
codex/add-version-method-to-@midscene/computer
Open

feat(cli): add CLI version support and show @midscene/computer version in health check#2057
yuyutaotao wants to merge 2 commits intomainfrom
codex/add-version-method-to-@midscene/computer

Conversation

@yuyutaotao
Copy link
Collaborator

Motivation

  • Provide an easy way to show the CLI package version from the shared CLI so users can inspect versions via --version/-v/version and also surface the @midscene/computer package version during runtime health checks.

Description

  • Added a version() helper and export to @midscene/computer that prints and returns the package version (packages/computer/src/utils.ts and exported from packages/computer/src/index.ts).
  • Log the @midscene/computer package version at the start of the computer health check (packages/computer/src/device.ts).
  • Extended the shared CLI runner (packages/shared/src/cli/cli-runner.ts) to accept an optional version in CLIRunnerOptions, show the version in --help output, and support --version/-v/version to print the CLI version.
  • Wired each platform CLI entrypoint to pass its package version into the shared runner so every platform (computer, android, ios, harmony, web) inherits the behavior (packages/*/src/cli.ts).
  • Updated unit tests and snapshots for the CLI runner to cover the new version output and commands (packages/shared/tests/unit-test/cli-runner.test.ts, updated snapshot).

Testing

  • Ran pnpm --filter @midscene/shared exec vitest run tests/unit-test/cli-runner.test.ts and all tests passed (50 tests), snapshots updated accordingly.
  • Built shared package with pnpm --filter @midscene/shared build which succeeded.
  • Built computer package with pnpm --filter @midscene/computer build which succeeded.
  • Attempted to build Android (and full multi-package builds) but the environment could not download prebuilt assets during prebuild and the Android prebuild failed with network error ENETUNREACH; this is an environment/network issue unrelated to the changes.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cea1d812a7

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
}

const computerPkg = createRequire(import.meta.url)('../package.json') as {

Choose a reason for hiding this comment

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

P1 Badge Load package.json from package root, not dist parent

Using createRequire(import.meta.url)('../package.json') here is path-sensitive and breaks after build: this file is emitted under dist/lib, so the lookup resolves to dist/package.json instead of the package root package.json (the bin entrypoints load dist/lib/cli.js). In built/published artifacts this can throw MODULE_NOT_FOUND during module initialization, which prevents @midscene/computer imports and CLI startup from running at all; use a build-time injected version or a path that is stable from dist/lib.

Useful? React with 👍 / 👎.

for (const { name, def } of commands) {
console.log(` ${name.padEnd(30)} ${def.description}`);
}
console.log(` ${'version'.padEnd(30)} Show CLI version`);

Choose a reason for hiding this comment

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

P2 Badge Only advertise version when a version string is available

printHelp now always lists a version command, but runToolsCLI throws Failed to determine CLI version when options.version is unset. Callers that still use runToolsCLI without providing version get misleading help that documents a command guaranteed to fail, so the version entry (and command handling) should be conditional on options.version.

Useful? React with 👍 / 👎.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 3, 2026

Deploying midscene with  Cloudflare Pages  Cloudflare Pages

Latest commit: 73f3cdb
Status: ✅  Deploy successful!
Preview URL: https://c6cf3383.midscene.pages.dev
Branch Preview URL: https://codex-add-version-method-to.midscene.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants