Skip to content

fix: search both Unix and Windows paths for npm global module#11

Merged
elrrrrrrr merged 1 commit into
mainfrom
fix/windows-getversion
Mar 25, 2026
Merged

fix: search both Unix and Windows paths for npm global module#11
elrrrrrrr merged 1 commit into
mainfrom
fix/windows-getversion

Conversation

@elrrrrrrr
Copy link
Copy Markdown
Contributor

@elrrrrrrr elrrrrrrr commented Mar 25, 2026

Summary

getUtooVersion() only searched {prefix}/lib/node_modules/utoo/package.json (Unix layout), but Windows npm uses {prefix}/node_modules/utoo/package.json (no lib/).

This caused "Utoo was installed but package.json could not be found or read" on all Windows CI runners.

Now tries both candidate paths.

Test plan

  • Windows CI job (utoopm-ci-x86_64-pc-windows-msvc) passes Setup Utoo step

🤖 Generated with Claude Code

npm global install layout differs by platform:
  Unix:    {prefix}/lib/node_modules/utoo/package.json
  Windows: {prefix}/node_modules/utoo/package.json

getUtooVersion() now tries both candidates, fixing "package.json
could not be found or read" on Windows runners.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where the getUtooVersion function failed to correctly identify the utoo module's version on Windows environments. The change introduces a more robust path resolution mechanism that accounts for differences in npm's global package layout between operating systems, ensuring the package.json can be found regardless of the installation structure and resolving related CI failures.

Highlights

  • Cross-platform compatibility: Modified the getUtooVersion function to correctly locate the utoo package's package.json on both Unix and Windows systems.
  • Path resolution: Implemented a search strategy that checks both {prefix}/lib/node_modules (Unix) and {prefix}/node_modules (Windows) paths for the package.json file.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@elrrrrrrr elrrrrrrr merged commit a9d68d0 into main Mar 25, 2026
8 checks passed
Copy link
Copy Markdown

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

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 improves the getUtooVersion function by adding support for different npm global layouts on Unix and Windows, allowing it to correctly locate the package.json file. The review feedback suggests further improvements to the implementation, specifically addressing the dynamic import within a loop, the mixing of synchronous and asynchronous I/O operations, and the silent swallowing of errors, to enhance robustness and clarity.

Comment thread src/action.ts
Comment on lines +222 to 234
for (const candidate of candidates) {
try {
if (!existsSync(candidate)) continue;

// Read and parse package.json
const fs = await import("node:fs/promises");
const content = await fs.readFile(packageJsonPath, "utf-8");
const packageJson = JSON.parse(content);
const fs = await import("node:fs/promises");
const content = await fs.readFile(candidate, "utf-8");
const packageJson = JSON.parse(content);

return packageJson.version;
} catch (error) {
// If reading package.json fails, utoo might not be properly installed
return undefined;
if (packageJson.version) return packageJson.version;
} catch {
continue;
}
}
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

This implementation can be improved in a few ways for better robustness and clarity:

  • Dynamic import in loop: The import("node:fs/promises") is called inside the loop. It's more efficient to call it once outside.
  • Mixing sync/async IO: The code mixes a synchronous existsSync with asynchronous readFile. It's cleaner to use a fully asynchronous approach by removing existsSync and handling the 'file not found' error in the catch block.
  • Silent error swallowing: The empty catch block hides potentially useful error information (e.g., for malformed JSON or permission errors), making debugging harder.

Here is a suggested refactoring that addresses these points:

  const fs = await import("node:fs/promises");
  for (const candidate of candidates) {
    try {
      const content = await fs.readFile(candidate, "utf-8");
      const packageJson = JSON.parse(content);

      if (packageJson.version) {
        return packageJson.version;
      }
    } catch (error: any) {
      // It's expected that a candidate path might not exist (ENOENT).
      // However, other errors like parsing or permission issues are worth reporting.
      if (error.code !== 'ENOENT') {
        warning(`Failed to process package.json candidate '${candidate}': ${error.message}`);
      }
    }
  }

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