Skip to content

refactor: replace Bun APIs with standard Node.js equivalents#9

Merged
iHildy merged 1 commit into
mainfrom
feat/node-compatibility
Dec 31, 2025
Merged

refactor: replace Bun APIs with standard Node.js equivalents#9
iHildy merged 1 commit into
mainfrom
feat/node-compatibility

Conversation

@iHildy

@iHildy iHildy commented Dec 31, 2025

Copy link
Copy Markdown
Owner

This pull request updates the command loading logic in src/index.ts to improve compatibility across Node.js and Bun, and removes Bun-specific dependencies. The most important changes are grouped below:

Cross-Platform Compatibility:

  • Added a getModuleDir function to reliably get the current module directory in both Bun and Node.js environments, replacing direct usage of import.meta.dir.
  • Replaced the Bun-specific Bun.Glob and Bun.file APIs with a new scanMdFiles function that recursively scans for .md files using Node's fs.promises and reads files with fs.readFile.

Dependency Updates:

  • Imported fs/promises and fileURLToPath from Node.js modules to support the new file scanning and path resolution methods.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @iHildy, 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 refactors the command loading logic to enhance cross-platform compatibility by replacing Bun-specific APIs with standard Node.js equivalents. The changes ensure that the application's file system operations and module path resolution work seamlessly in both Bun and Node.js environments, improving robustness and reducing reliance on a single runtime's unique features.

Highlights

  • Cross-Platform Compatibility: Introduced a getModuleDir function to ensure reliable module directory resolution across both Bun and Node.js environments, replacing direct usage of import.meta.dir.
  • File System Operations: Replaced Bun-specific Bun.Glob and Bun.file APIs with a new scanMdFiles function that leverages Node.js's fs.promises for recursive .md file scanning and reading.
  • Dependency Management: Updated imports to include fs/promises and fileURLToPath from Node.js modules, aligning with the new file system and path resolution methods.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@iHildy iHildy merged commit 6f9a49f into main Dec 31, 2025
3 checks passed
@iHildy iHildy deleted the feat/node-compatibility branch December 31, 2025 05:54

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

Copy link
Copy Markdown
Contributor

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 does a great job of refactoring the codebase to remove Bun-specific APIs and use standard Node.js equivalents, which significantly improves cross-platform compatibility. The introduction of getModuleDir is a clean way to handle differences between JavaScript runtimes. I've identified an opportunity to improve the new scanMdFiles function for better performance and robustness. My suggestion refactors it to scan directories in parallel and gracefully handle missing directories, which makes it more efficient and resilient.

Comment thread src/index.ts
Comment on lines +61 to +78
async function scanMdFiles(dir: string): Promise<string[]> {
const files: string[] = [];

async function walk(currentDir: string): Promise<void> {
const entries = await fs.readdir(currentDir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(currentDir, entry.name);
if (entry.isDirectory()) {
await walk(fullPath);
} else if (entry.isFile() && entry.name.endsWith('.md')) {
files.push(fullPath);
}
}
}

await walk(dir);
return files;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The scanMdFiles function can be improved for performance, robustness, and readability.

  1. Performance: The current implementation processes subdirectories sequentially. This can be inefficient for directories with many subdirectories. The suggested change uses Promise.all to process directory entries in parallel, speeding up file scanning.
  2. Robustness: The current implementation will throw an error if a directory doesn't exist or can't be read. This is likely a regression from Bun.Glob, which would typically find no files. The suggestion adds error handling to return an empty array in these cases, making the function more resilient.
  3. Readability: The suggested version is more functional and avoids shared mutable state (the files array), which makes the code cleaner and easier to reason about.
async function scanMdFiles(dir: string): Promise<string[]> {
  const entries = await fs.readdir(dir, { withFileTypes: true }).catch(err => {
    // If directory is not readable, treat as empty to mimic glob behavior.
    if (err.code === 'ENOENT' || err.code === 'EACCES') {
      return [];
    }
    throw err;
  });

  const filePromises = entries.map(async (entry) => {
    const fullPath = path.join(dir, entry.name);
    if (entry.isDirectory()) {
      return scanMdFiles(fullPath);
    }
    if (entry.isFile() && entry.name.endsWith('.md')) {
      return [fullPath];
    }
    return [];
  });

  const nestedFiles = await Promise.all(filePromises);
  return nestedFiles.flat();
}

@jules-relay

jules-relay Bot commented Dec 31, 2025

Copy link
Copy Markdown

🤖 Review Jules Relay

I found 1 Gemini suggestion so far.

Type /relay batch to send all suggestions to Jules.

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