Devmode: improve sourcemap when node_module is outside project#348
Devmode: improve sourcemap when node_module is outside project#348
Conversation
WalkthroughThe update changes how the Changes
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
internal/bundler/shim.go (2)
94-94: Logic looks correct for handling external node_modules, but consider code clarity.The conditional logic correctly addresses the case where source paths start with '../', which aligns with the PR objective of improving sourcemap handling when node_modules is outside the project. The appended '.agentuity' string maintains consistency with the existing pattern used throughout the codebase.
However, the line is becoming complex with nested conditional logic. Consider extracting this logic for better readability.
Consider refactoring for improved readability:
- const basedir = filename.substring(0, startIndex + offset) + (source.startsWith('../') ? '.agentuity' : ''); + const baseSubstring = filename.substring(0, startIndex + offset); + const basedir = source.startsWith('../') ? baseSubstring + '.agentuity' : baseSubstring;
89-95: Consider adding documentation for complex sourcemap logic.The sourcemap resolution logic is complex and handles multiple scenarios (different offsets, external dependencies, path construction). Adding inline comments explaining the purpose of each step would improve maintainability.
Consider adding comments to explain the logic:
if (pos && pos.source) { const startIndex = filename.indexOf('.agentuity/'); + // Determine offset based on whether we're dealing with node_modules const offset = filename.includes('../node_modules/') ? 11 : 0; const sourceOffset = pos.source.indexOf('src/'); const source = pos.source.substring(sourceOffset); + // Append .agentuity suffix when source references parent directories const basedir = filename.substring(0, startIndex + offset) + (source.startsWith('../') ? '.agentuity' : '');
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/bundler/shim.go(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Test CLI Upgrade Path (windows-latest)
- GitHub Check: Analyze (go)
Summary by CodeRabbit