Skip to content

Commit 3d9b3a0

Browse files
Fix startup profiling with sourcemaps (#9991)
Co-authored-by: Samuel Macleod <[email protected]>
1 parent 31513e6 commit 3d9b3a0

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

.changeset/yummy-parents-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Fix startup profiling when sourcemaps are enabled

packages/wrangler/src/__tests__/startup-profiling.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ describe("wrangler check startup", () => {
3030
readFile("worker-startup.cpuprofile", "utf8")
3131
).resolves.toContain("callFrame");
3232
});
33+
test("generates profile for basic worker w/ sourcemaps", async () => {
34+
writeWranglerConfig({ main: "index.js", upload_source_maps: true });
35+
writeWorkerSource();
36+
37+
await runWrangler("check startup");
38+
39+
expect(std.out).toContain(
40+
`CPU Profile written to worker-startup.cpuprofile`
41+
);
42+
43+
await expect(
44+
readFile("worker-startup.cpuprofile", "utf8")
45+
).resolves.toContain("callFrame");
46+
});
3347
test("--outfile works", async () => {
3448
writeWranglerConfig({ main: "index.js" });
3549
writeWorkerSource();

packages/wrangler/src/check/commands.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,19 @@ async function convertWorkerBundleToModules(
166166
workerBundle: FormData
167167
): Promise<ModuleDefinition[]> {
168168
return await Promise.all(
169-
[...workerBundle.entries()].map(
170-
async (m) =>
171-
({
172-
type: getModuleType(m[1]),
173-
path: m[0],
174-
contents: await getEntryValue(m[1]),
175-
}) as ModuleDefinition
176-
)
169+
[...workerBundle.entries()]
170+
// Sourcemaps aren't "real" modules in the application and won't be imported by user code, so lets not load them when analyzing the bundle
171+
.filter(
172+
(m) => m[1] instanceof Blob && m[1].type !== "application/source-map"
173+
)
174+
.map(
175+
async (m) =>
176+
({
177+
type: getModuleType(m[1]),
178+
path: m[0],
179+
contents: await getEntryValue(m[1]),
180+
}) as ModuleDefinition
181+
)
177182
);
178183
}
179184

0 commit comments

Comments
 (0)