feat(cli): add CLI version support and show @midscene/computer version in health check#2057
feat(cli): add CLI version support and show @midscene/computer version in health check#2057yuyutaotao wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
💡 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".
packages/computer/src/device.ts
Outdated
| } | ||
| } | ||
|
|
||
| const computerPkg = createRequire(import.meta.url)('../package.json') as { |
There was a problem hiding this comment.
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`); |
There was a problem hiding this comment.
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 👍 / 👎.
Deploying midscene with
|
| 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 |
Motivation
--version/-v/versionand also surface the@midscene/computerpackage version during runtime health checks.Description
version()helper and export to@midscene/computerthat prints and returns the package version (packages/computer/src/utils.tsand exported frompackages/computer/src/index.ts).@midscene/computerpackage version at the start of the computer health check (packages/computer/src/device.ts).packages/shared/src/cli/cli-runner.ts) to accept an optionalversioninCLIRunnerOptions, show the version in--helpoutput, and support--version/-v/versionto print the CLI version.computer,android,ios,harmony,web) inherits the behavior (packages/*/src/cli.ts).packages/shared/tests/unit-test/cli-runner.test.ts, updated snapshot).Testing
pnpm --filter @midscene/shared exec vitest run tests/unit-test/cli-runner.test.tsand all tests passed (50 tests), snapshots updated accordingly.pnpm --filter @midscene/shared buildwhich succeeded.pnpm --filter @midscene/computer buildwhich succeeded.prebuildand the Android prebuild failed with network errorENETUNREACH; this is an environment/network issue unrelated to the changes.Codex Task