-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wrangler] Changes for the next Miniflare version (#3951)
* Use Miniflare's magic proxy for `wrangler kv --local` commands `miniflare` no longer provides Node APIs for accessing its persistent storage directly, as simulators are now implemented as Workers. This change updates the `wrangler kv --local` commands to use `Miniflare#getKVNamespace()` instead, proxying through the Worker simulator. * Use Miniflare's magic proxy for `wrangler r2 --local` commands As with KV, this change updates the `wrangler kv --local` commands to use `Miniflare#getR2Bucket()` instead, proxying through the Worker simulator. * Use Miniflare's magic proxy for `wrangler d1 --local` commands As with KV and R2, this change updates the `wrangler d1 --local` commands to use `Miniflare#getD1Database()` instead, proxying through the Worker simulator. This removes Wrangler's dependency on `better-sqlite3`, meaning we no longer have any native dependencies. * Update `pages-workerjs-directory` tests for new persistence layout Namespace IDs are now encoded into Durable Object IDs, so we cannot check for their existence directly. * Include `//# sourceURL` comments in remote mode Adds `//# sourceURL` comments to source files in `--remote` dev so V8 knows where source files are on disk. This URL is returned in `Debugger.scriptParsed` events, ensuring inspector clients resolve source mapping URLs correctly. It also appears in stack traces, allowing users to click through to where errors are thrown, and making it easier for us to source map them. Note, Miniflare already includes similar code, so we only need to do this in remote mode. This is a pre-requisite to enabling breakpoint debugging in remote. * Only enable Miniflare's JSON error middleware in local mode This middleware returns a machine-readable JSON response for uncaught errors. This is only intended for Miniflare's pretty error page and shouldn't be used in remote mode. We may want to add a pretty error page to remote mode eventually, but that should be a separate change. * Use `realpath`ed temporary directories to generate valid source maps On macOS, `os.tmpdir()` returns a symlink. This causes `esbuild` to generate invalid source maps, as the number of `../` in relative paths changes depending on whether you evaluate symlinks. We previously fixed a similar issue for the middleware loader (https://github.com/cloudflare/workers-sdk/pull/2249/files#diff-17e01c57aa611bb9e0b392a15fd63b5d18602e3a6c9a97c4a34e891bbfdcb7f3R496-R498), but the issue is more widespread than that. This change ensures all temporary directories are `realpath`ed and symlink free. * Serve source maps and source files from inspector proxy Previously, Wrangler would respond to `Network.loadNetworkResource` requests with the bundled `esbuild` source map in `--remote` mode. In local mode, Wrangler relied on Miniflare rewriting source mapping URLs to its loopback server. Unfortunately, this breaks breakpoint debugging in VSCode, so was removed in cloudflare/miniflare#681 in favour of a `//# sourceURL`-based approach. With the previous changes to include `//# sourceURL` comments in remote mode too, this means all source mapping URLs from Miniflare and remote dev will now have `file:` protocols. These cannot be fetched from our DevTools hosted on a `https:` origin. IDEs like VSCode and WebStorm expect these though. To fix hosted DevTools, this PR rewrites `Debugger.scriptParsed` events to include `worker:`-scheme URLs, only if the connected inspector client is DevTools. Wrangler will then respond to `Network.loadNetworkResource` with the source map. As noted above, Wrangler used to only respond with the source map from the internal `esbuild` bundle step. When using `--no-bundle`, users may bring their own source map**s**. Previously, these weren't served, preventing these users from using DevTools. With the new `//# sourceURL` comments, we're able to work out which source map corresponds to which source file, meaning Wrangler can now serve multiple source maps. These source maps may not include `sourcesContent` fields. In this case, DevTools sends additional `Network.loadNetworkResource` requests for sources, which Wrangler now responds to too. * Source map `Runtime.exceptionThrown` events with multiple sources When `Runtime.exceptionThrown` events are dispatched by V8, Wrangler previously only used the source map produced by `esbuild` to source map the stack trace. In `--no-bundle` mode, it's possible there might be multiple user provided source maps needed to source map the stack trace. This change switches to using the `source-map-support` package to source map stack traces. Miniflare uses this already, so we're not adding a new dependency. This relies on file URLs in stack traces, something we now have from adding `//# sourceURL` comments. * Enable DevTools breakpoint debugging in remote mode Now that we're adding `//# sourceURL` comments in remote mode, breakpoint debugging just works in remote mode, including in IDEs. This change sets the `?debugger=true` query param when opening DevTools regardless of the runtime in-use. * Bump `miniflare` version to `3.20230918` --------- Co-authored-by: jjohnson <jjohnson@cloudflare.com>
- Loading branch information
Showing
32 changed files
with
1,188 additions
and
851 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,12 @@ | ||
--- | ||
"wrangler": minor | ||
--- | ||
|
||
feat: add support for breakpoint debugging to `wrangler dev`'s `--remote` and `--no-bundle` modes | ||
|
||
Previously, breakpoint debugging using Wrangler's DevTools was only supported | ||
in local mode, when using Wrangler's built-in bundler. This change extends that | ||
to remote development, and `--no-bundle`. | ||
|
||
When using `--remote` and `--no-bundle` together, uncaught errors will now be | ||
source-mapped when logged too. |
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,27 @@ | ||
--- | ||
"wrangler": minor | ||
--- | ||
|
||
feat: add support for Visual Studio Code's built-in breakpoint debugger | ||
|
||
Wrangler now supports breakpoint debugging with Visual Studio Code's debugger. | ||
Create a `.vscode/launch.json` file with the following contents... | ||
|
||
```json | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Wrangler", | ||
"type": "node", | ||
"request": "attach", | ||
"port": 9229, | ||
"cwd": "/", | ||
"resolveSourceMapLocations": null, | ||
"attachExistingChildren": false, | ||
"autoAttachChildProcesses": false | ||
} | ||
] | ||
} | ||
``` | ||
|
||
...then run `wrangler dev`, and launch the configuration. |
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
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
Oops, something went wrong.