Skip to content

Commit 5fd080c

Browse files
authored
Support sourcemaps in DevTools (#3140)
* Support sourcemaps in DevTools * Support Miniflare source mapping
1 parent 78530f4 commit 5fd080c

31 files changed

+355
-66
lines changed

.changeset/six-chicken-shave.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
feat: Support sourcemaps in DevTools
6+
7+
Intercept requests from DevTools in Wrangler to inject sourcemaps and enable folders in the Sources Panel of DevTools. When errors are thrown in your Worker, DevTools should now show your source file in the Sources panel, rather than Wrangler's bundled output.

fixtures/sites-app/wrangler.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
name = "sites-app"
22
site = { bucket = "./public" }
3+
main = "src/modules.js"

fixtures/worker-ts/package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "worker-ts",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"deploy": "wrangler publish",
7+
"start": "wrangler dev"
8+
},
9+
"devDependencies": {
10+
"@cloudflare/workers-types": "^4.20230419.0",
11+
"wrangler": "2.19.0"
12+
}
13+
}

fixtures/worker-ts/src/index.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Welcome to Cloudflare Workers! This is your first worker.
3+
*
4+
* - Run `wrangler dev src/index.ts` in your terminal to start a development server
5+
* - Open a browser tab at http://localhost:8787/ to see your worker in action
6+
* - Run `wrangler publish src/index.ts --name my-worker` to publish your worker
7+
*
8+
* Learn more at https://developers.cloudflare.com/workers/
9+
*/
10+
export interface Env {
11+
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
12+
// MY_KV_NAMESPACE: KVNamespace;
13+
//
14+
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
15+
// MY_DURABLE_OBJECT: DurableObjectNamespace;
16+
//
17+
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
18+
// MY_BUCKET: R2Bucket;
19+
//
20+
// Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
21+
// MY_SERVICE: Fetcher;
22+
}
23+
24+
export default {
25+
async fetch(
26+
request: Request,
27+
env: Env,
28+
ctx: ExecutionContext
29+
): Promise<Response> {
30+
const url = new URL(request.url);
31+
if (url.pathname === "/error") throw new Error("Hello Error");
32+
return new Response("Hello World!");
33+
},
34+
};

fixtures/worker-ts/tsconfig.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2021",
4+
"lib": ["es2021"],
5+
"module": "es2022",
6+
"types": ["@cloudflare/workers-types/2022-11-30"],
7+
"noEmit": true,
8+
"isolatedModules": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"strict": true,
11+
"skipLibCheck": true
12+
}
13+
}

fixtures/worker-ts/wrangler.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "worker-ts"
2+
main = "src/index.ts"
3+
compatibility_date = "2023-05-04"

package-lock.json

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wrangler-devtools/patches/0001-Add-README-detailing-the-setup-process.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From b2985a087935838fdf6a6f0dba21afed484849c7 Mon Sep 17 00:00:00 2001
22
From: Samuel Macleod <[email protected]>
33
Date: Wed, 11 Jan 2023 17:46:48 +0000
4-
Subject: [PATCH 01/14] Add README detailing the setup process
4+
Subject: [PATCH 01/15] Add README detailing the setup process
55

66
---
77
README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -74,5 +74,5 @@ index 8a057be23c..4e009509b2 100644
7474

7575
<!-- [START badges] -->
7676
--
77-
2.37.1 (Apple Git-137.1)
77+
2.39.2 (Apple Git-143)
7878

packages/wrangler-devtools/patches/0002-Support-viewing-files-over-the-network.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From cc7b688a2427d7506a2f4111887a5e243fb841d4 Mon Sep 17 00:00:00 2001
22
From: Samuel Macleod <[email protected]>
33
Date: Thu, 12 Jan 2023 15:33:43 +0000
4-
Subject: [PATCH 02/14] Support viewing files over the network
4+
Subject: [PATCH 02/15] Support viewing files over the network
55

66
---
77
front_end/core/sdk/Target.ts | 4 ++++
@@ -93,5 +93,5 @@ index ac0d4aaf68..29c726e185 100644
9393
]
9494
}
9595
--
96-
2.37.1 (Apple Git-137.1)
96+
2.39.2 (Apple Git-143)
9797

packages/wrangler-devtools/patches/0003-Show-fallback-image-on-Safari.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From a742a62c90c73c8c7e766eaaad9003200a447729 Mon Sep 17 00:00:00 2001
22
From: Samuel Macleod <[email protected]>
33
Date: Mon, 16 Jan 2023 16:51:11 +0000
4-
Subject: [PATCH 03/14] Show fallback image on Safari
4+
Subject: [PATCH 03/15] Show fallback image on Safari
55

66
---
77
config/gni/devtools_grd_files.gni | 1 +
@@ -1815,5 +1815,5 @@ index 1edaec9604..945aa6d816 100644
18151815
+</script>
18161816
<body class="undocked" id="-blink-dev-tools">
18171817
--
1818-
2.37.1 (Apple Git-137.1)
1818+
2.39.2 (Apple Git-143)
18191819

packages/wrangler-devtools/patches/0004-Support-previewing-subrequest-responses.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 6c4581cd2e985e8e94aa3c9091faec45743da6e4 Mon Sep 17 00:00:00 2001
22
From: bcoll <[email protected]>
33
Date: Mon, 16 Jan 2023 14:26:52 +0000
4-
Subject: [PATCH 04/14] Support previewing subrequest responses
4+
Subject: [PATCH 04/15] Support previewing subrequest responses
55

66
---
77
front_end/core/sdk/NetworkManager.ts | 9 +++++++--
@@ -61,5 +61,5 @@ index 213ca7fecd..ef5c568e96 100644
6161
import '../../panels/js_profiler/js_profiler-meta.js';
6262

6363
--
64-
2.37.1 (Apple Git-137.1)
64+
2.39.2 (Apple Git-143)
6565

packages/wrangler-devtools/patches/0005-Better-Firefox-support-for-network-tab.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From b91cdddb4b2576149ba2c184f011073140f16e9b Mon Sep 17 00:00:00 2001
22
From: Samuel Macleod <[email protected]>
33
Date: Thu, 19 Jan 2023 15:47:52 +0000
4-
Subject: [PATCH 05/14] Better Firefox support for network tab
4+
Subject: [PATCH 05/15] Better Firefox support for network tab
55

66
---
77
front_end/entrypoints/js_app/js_app.ts | 2 ++
@@ -45,5 +45,5 @@ index a7ec8ccf32..fc80d2769d 100644
4545
return;
4646
}
4747
--
48-
2.37.1 (Apple Git-137.1)
48+
2.39.2 (Apple Git-143)
4949

packages/wrangler-devtools/patches/0006-DEVX-292-Remove-unsupported-network-UI.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 1a267cd3d143892fb0886907a75e3eb295b5b150 Mon Sep 17 00:00:00 2001
22
From: bcoll <[email protected]>
33
Date: Mon, 16 Jan 2023 15:43:50 +0000
4-
Subject: [PATCH 06/14] DEVX-292 Remove unsupported network UI
4+
Subject: [PATCH 06/15] DEVX-292 Remove unsupported network UI
55

66
---
77
front_end/panels/network/NetworkPanel.ts | 35 ------------------------
@@ -75,5 +75,5 @@ index 304bb09af1..aaf80fbd50 100644
7575
this.rightToolbar.appendSeparator();
7676
this.rightToolbar.appendToolbarItem(new UI.Toolbar.ToolbarSettingToggle(
7777
--
78-
2.37.1 (Apple Git-137.1)
78+
2.39.2 (Apple Git-143)
7979

packages/wrangler-devtools/patches/0007-Remove-unsupported-profiler-UI.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 7312af32a23a62acc2f5661187ef90b01381c0de Mon Sep 17 00:00:00 2001
22
From: bcoll <[email protected]>
33
Date: Mon, 16 Jan 2023 16:32:45 +0000
4-
Subject: [PATCH 07/14] Remove unsupported profiler UI
4+
Subject: [PATCH 07/15] Remove unsupported profiler UI
55

66
---
77
front_end/panels/profiler/HeapProfilerPanel.ts | 2 +-
@@ -35,5 +35,5 @@ index c4680b48be..c2fe5b775f 100644
3535
this.profileViewToolbar = new UI.Toolbar.Toolbar('', this.toolbarElement);
3636
this.profileViewToolbar.makeWrappable(true);
3737
--
38-
2.37.1 (Apple Git-137.1)
38+
2.39.2 (Apple Git-143)
3939

packages/wrangler-devtools/patches/0008-Show-an-overlay-on-the-memory-tab-in-Firefox.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 70e79d4a4e1821021d0df627a23d62ede6c558ba Mon Sep 17 00:00:00 2001
22
From: Samuel Macleod <[email protected]>
33
Date: Thu, 19 Jan 2023 18:49:47 +0000
4-
Subject: [PATCH 08/14] Show an overlay on the memory tab in Firefox
4+
Subject: [PATCH 08/15] Show an overlay on the memory tab in Firefox
55

66
---
77
front_end/entrypoint_template.html | 18 ++++++++++++++++--
@@ -71,5 +71,5 @@ index 693621a273..9b330e7cf0 100644
7171
flex: auto;
7272
position: relative;
7373
--
74-
2.37.1 (Apple Git-137.1)
74+
2.39.2 (Apple Git-143)
7575

packages/wrangler-devtools/patches/0009-Support-theme-url-parameter-for-forcing-the-theme-fr.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 0edd0dbfe2704ef6bc527cbfa68dd35989d95cc5 Mon Sep 17 00:00:00 2001
22
From: Samuel Macleod <[email protected]>
33
Date: Fri, 20 Jan 2023 19:19:37 +0000
4-
Subject: [PATCH 09/14] Support theme= url parameter for forcing the theme from
4+
Subject: [PATCH 09/15] Support theme= url parameter for forcing the theme from
55
outside
66

77
---
@@ -41,5 +41,5 @@ index 05736bc0b8..530028d5b0 100644
4141
this.customSheets.clear();
4242
this.dispatchEvent(new ThemeChangeEvent());
4343
--
44-
2.37.1 (Apple Git-137.1)
44+
2.39.2 (Apple Git-143)
4545

packages/wrangler-devtools/patches/0010-Basic-support-for-text-colour-in-dark-mode-in-browse.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 9d34de7c9010659ece1be008ee852a21e06bff55 Mon Sep 17 00:00:00 2001
22
From: Samuel Macleod <[email protected]>
33
Date: Mon, 23 Jan 2023 15:12:38 +0000
4-
Subject: [PATCH 10/14] Basic support for text colour in dark mode in browsers
4+
Subject: [PATCH 10/15] Basic support for text colour in dark mode in browsers
55
that don't implement :host-context
66

77
---
@@ -46,5 +46,5 @@ index b451da60eb..8828dd8f07 100644
4646
<meta http-equiv="Content-Security-Policy"
4747
content="object-src 'none'; script-src 'sha256-yYUen+rS0+K2iGZTeGzgeav9eHB7hosjob+ahEOInok=' 'self' 'unsafe-eval' https://chrome-devtools-frontend.appspot.com">
4848
--
49-
2.37.1 (Apple Git-137.1)
49+
2.39.2 (Apple Git-143)
5050

packages/wrangler-devtools/patches/0011-Fallback-to-location-for-domain.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 0091abac4c9631649485198cc36b49ebd4fd40dd Mon Sep 17 00:00:00 2001
22
From: Samuel Macleod <[email protected]>
33
Date: Thu, 26 Jan 2023 15:27:04 +0000
4-
Subject: [PATCH 11/14] Fallback to location for domain
4+
Subject: [PATCH 11/15] Fallback to location for domain
55

66
---
77
front_end/panels/sources/NavigatorView.ts | 3 ++-
@@ -22,5 +22,5 @@ index c7a64ab432..ca32b5202e 100644
2222

2323
const parsedURL = new Common.ParsedURL.ParsedURL(projectOrigin);
2424
--
25-
2.37.1 (Apple Git-137.1)
25+
2.39.2 (Apple Git-143)
2626

packages/wrangler-devtools/patches/0012-Hide-unsupported-settings-UI.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From deeac26dadb8f2d7f5653c1994eed41f9e220af2 Mon Sep 17 00:00:00 2001
22
From: bcoll <[email protected]>
33
Date: Thu, 26 Jan 2023 15:30:34 +0000
4-
Subject: [PATCH 12/14] Hide unsupported settings UI
4+
Subject: [PATCH 12/15] Hide unsupported settings UI
55

66
- Show CORS errors in console setting
77
- Show XHR requests in console setting
@@ -62,5 +62,5 @@ index df0806e90d..0b20193865 100644
6262
+ display: none;
6363
+}
6464
--
65-
2.37.1 (Apple Git-137.1)
65+
2.39.2 (Apple Git-143)
6666

packages/wrangler-devtools/patches/0013-DEVX-380-Hide-debugger-sidebar-and-disable-breakpoin.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From cde74d1233f0e89563cfe4d458af197f21c22f18 Mon Sep 17 00:00:00 2001
22
From: bcoll <[email protected]>
33
Date: Wed, 15 Feb 2023 15:07:45 +0000
4-
Subject: [PATCH 13/14] DEVX-380 Hide debugger sidebar and disable breakpoints
4+
Subject: [PATCH 13/15] DEVX-380 Hide debugger sidebar and disable breakpoints
55

66
- Hides debugger sidebar
77
- Removes toggle debugger sidebar command
@@ -87,5 +87,5 @@ index c5e95ab535..9c53bca1b3 100644
8787
settingName: 'navigatorGroupByFolder',
8888
settingType: Common.Settings.SettingType.BOOLEAN,
8989
--
90-
2.37.1 (Apple Git-137.1)
90+
2.39.2 (Apple Git-143)
9191

0 commit comments

Comments
 (0)