Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .review/pr-8274
Submodule pr-8274 added at e46929
1 change: 1 addition & 0 deletions tmp/pr-8287-Roo-Code
Submodule pr-8287-Roo-Code added at 88a473
27 changes: 21 additions & 6 deletions webview-ui/src/vite-plugins/sourcemapPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,29 @@ export function sourcemapPlugin(): Plugin {
// Read the JS file
let jsContent = fs.readFileSync(jsPath, "utf8")

// Check if the source map is already referenced
if (!jsContent.includes("//# sourceMappingURL=")) {
// Check if the source map is already referenced or has incorrect reference
const sourceMappingURLRegex = /\/\/# sourceMappingURL=([^\s\n]+)/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

P3: Regex robustness: anchor to the line and use multiline to avoid partial matches.

Suggested change
const sourceMappingURLRegex = /\/\/# sourceMappingURL=([^\s\n]+)/
const sourceMappingURLRegex = /^\/\/# sourceMappingURL=(.+)$/m

const match = jsContent.match(sourceMappingURLRegex)

if (match) {
// Check if the existing reference is incorrect (e.g., index.sourcemap instead of index.js.map)
const currentMapRef = match[1]
const expectedMapRef = `${jsFile}.map`

if (currentMapRef !== expectedMapRef) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

P2: Avoid overwriting inline data URL sourcemaps (data:...). Guard before replacing.

Suggested change
if (currentMapRef !== expectedMapRef) {
if (!currentMapRef.startsWith("data:") && currentMapRef !== expectedMapRef) {

console.log(
`Fixing source map reference in ${jsFile}: ${currentMapRef} -> ${expectedMapRef}`,
)
jsContent = jsContent.replace(
sourceMappingURLRegex,
`//# sourceMappingURL=${expectedMapRef}`,
)
fs.writeFileSync(jsPath, jsContent)
}
} else {
console.log(`Adding source map reference to ${jsFile}`)

// Add source map reference
// Add source map reference with explicit .map extension
jsContent += `\n//# sourceMappingURL=${jsFile}.map\n`

// Write the updated JS file
fs.writeFileSync(jsPath, jsContent)
}

Expand Down
Loading