-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wrangler] chore: bump
miniflare
to 3.20231002.1
and fix `find_ad…
…ditional_modules` source maps (#4107) * chore: bump `miniflare` to `3.20231002.1` * fix: use correct `//# sourceURL` with `find_additional_modules` Previously, the automatically inserted `//# sourceURL` comments for modules found using `find_additional_modules` referenced the temporary directory, not the original source directory the modules were from. This change makes sure they use the correct on-disk path, ensuring source maps are resolved correctly, and breaking debugging in IDEs works.
- Loading branch information
Showing
10 changed files
with
169 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@cloudflare/pages-shared": patch | ||
"wrangler": patch | ||
--- | ||
|
||
chore: bump `miniflare` to [`3.20231002.1`](https://github.com/cloudflare/miniflare/releases/tag/v3.20231002.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import fs from "node:fs"; | ||
import { pathToFileURL } from "url"; | ||
import type { CfModule } from "./worker"; | ||
|
||
function withSourceURL(source: string, sourcePath: string) { | ||
return `${source}\n//# sourceURL=${pathToFileURL(sourcePath)}`; | ||
} | ||
|
||
/** | ||
* Adds `//# sourceURL` comments so V8 knows where source files are on disk. | ||
* These URLs are returned in `Debugger.scriptParsed` events, ensuring inspector | ||
* clients resolve source mapping URLs correctly. They also appear in stack | ||
* traces, allowing users to click through to where errors are thrown. | ||
*/ | ||
export function withSourceURLs( | ||
entrypointPath: string, | ||
modules: CfModule[] | ||
): { entrypointSource: string; modules: CfModule[] } { | ||
let entrypointSource = fs.readFileSync(entrypointPath, "utf8"); | ||
entrypointSource = withSourceURL(entrypointSource, entrypointPath); | ||
|
||
modules = modules.map((module) => { | ||
if ( | ||
module.filePath !== undefined && | ||
(module.type === "esm" || module.type === "commonjs") | ||
) { | ||
// `module.content` may be a `Buffer` | ||
let newContent = module.content.toString(); | ||
newContent = withSourceURL(newContent, module.filePath); | ||
return { ...module, content: newContent }; | ||
} else { | ||
return module; | ||
} | ||
}); | ||
|
||
return { entrypointSource, modules }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.