Skip to content

Conversation

@Ansonhkg
Copy link
Collaborator

WHAT

guard getCurrentModulePath() so both bundlers and runtime fall back to __filename when import.meta.url isn’t available

Copilot AI review requested due to automatic review settings October 31, 2025 14:59
@Ansonhkg Ansonhkg added 🐞 Bug Fix Something isn't working v8 | Naga labels Oct 31, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds fallback handling for module path resolution to support both ESM and CJS bundles. The main purpose is to improve compatibility when bundlers strip import.meta.url by falling back to __filename.

  • Introduced a new getCurrentModulePath() helper function that safely resolves module paths with fallback logic
  • Updated getBaseDirectory() to use the new helper and handle cases where module path cannot be resolved
  • Updated the CLI script detection logic to gracefully handle undefined module paths

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

try {
return fileURLToPath(moduleUrl);
} catch (error) {
console.warn('Failed to resolve fileURLToPath from import.meta.url:', error);
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

The error message should include guidance on the fallback behavior. Consider updating to: 'Failed to resolve fileURLToPath from import.meta.url, attempting fallback to __filename:' to better inform users that the error is handled gracefully.

Suggested change
console.warn('Failed to resolve fileURLToPath from import.meta.url:', error);
console.warn('Failed to resolve fileURLToPath from import.meta.url, attempting fallback to __filename:', error);

Copilot uses AI. Check for mistakes.
}
}

if (typeof __filename === 'string') {
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

The check typeof __filename === 'string' is redundant. In Node.js/Bun environments where __filename exists, it is always a string. The check should be typeof __filename !== 'undefined' to detect its existence, consistent with line 97.

Suggested change
if (typeof __filename === 'string') {
if (typeof __filename !== 'undefined') {

Copilot uses AI. Check for mistakes.
@Ansonhkg Ansonhkg merged commit 3bf4166 into naga Oct 31, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 Bug Fix Something isn't working v8 | Naga

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants