-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix source mapping of service workers (#572)
cloudflare/workerd#190 changed the script name for service workers to their service name. This change updates Miniflare's heuristics for locating source maps to work with this. It also adds some tests to ensure source mapping is working correctly for the different ways of specifying a script.
- Loading branch information
Showing
10 changed files
with
242 additions
and
60 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
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,23 @@ | ||
export const CORE_PLUGIN_NAME = "core"; | ||
|
||
// Service for HTTP socket entrypoint (for checking runtime ready, routing, etc) | ||
export const SERVICE_ENTRY = `${CORE_PLUGIN_NAME}:entry`; | ||
// Service prefix for all regular user workers | ||
const SERVICE_USER_PREFIX = `${CORE_PLUGIN_NAME}:user`; | ||
// Service prefix for `workerd`'s builtin services (network, external, disk) | ||
const SERVICE_BUILTIN_PREFIX = `${CORE_PLUGIN_NAME}:builtin`; | ||
// Service prefix for custom fetch functions defined in `serviceBindings` option | ||
const SERVICE_CUSTOM_PREFIX = `${CORE_PLUGIN_NAME}:custom`; | ||
|
||
export function getUserServiceName(workerName = "") { | ||
return `${SERVICE_USER_PREFIX}:${workerName}`; | ||
} | ||
export function getBuiltinServiceName( | ||
workerIndex: number, | ||
bindingName: string | ||
) { | ||
return `${SERVICE_BUILTIN_PREFIX}:${workerIndex}:${bindingName}`; | ||
} | ||
export function getCustomServiceName(workerIndex: number, bindingName: string) { | ||
return `${SERVICE_CUSTOM_PREFIX}:${workerIndex}:${bindingName}`; | ||
} |
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,11 @@ | ||
import { reduceError } from "./reduce"; | ||
|
||
export default <ExportedHandler<{ MESSAGE: string }>>{ | ||
fetch(request, env) { | ||
const error = new Error(env.MESSAGE); | ||
return Response.json(reduceError(error), { | ||
status: 500, | ||
headers: { "MF-Experimental-Error-Stack": "true" }, | ||
}); | ||
}, | ||
}; |
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,7 @@ | ||
export function reduceError(e: any) { | ||
return { | ||
name: e?.name, | ||
message: e?.message ?? String(e), | ||
stack: e?.stack, | ||
}; | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/miniflare/test/fixtures/source-maps/service-worker.ts
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,13 @@ | ||
import { reduceError } from "./reduce"; | ||
|
||
declare const MESSAGE: string; | ||
|
||
addEventListener("fetch", (event) => { | ||
const error = new Error(MESSAGE); | ||
event.respondWith( | ||
Response.json(reduceError(error), { | ||
status: 500, | ||
headers: { "MF-Experimental-Error-Stack": "true" }, | ||
}) | ||
); | ||
}); |
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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"target": "esnext", | ||
"lib": ["esnext"], | ||
"strict": true, | ||
"moduleResolution": "node16", | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"types": ["@cloudflare/workers-types/experimental"] | ||
}, | ||
"include": ["**/*"] | ||
} |
Oops, something went wrong.