Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit d260585

Browse files
authored
Use existing //# sourceURL comments if present (#706)
With Wrangler's new `find_additional_modules` support, there are cases where we'd like `//# sourceURL` not to be resolved from the module name/path. This change makes sure we don't insert this comment if it's already present, so Wrangler can add it.
1 parent 5869396 commit d260585

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

packages/miniflare/src/plugins/core/modules.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ function moduleName(modulesRoot: string, modulePath: string) {
134134
return path.sep === "\\" ? name.replaceAll("\\", "/") : name;
135135
}
136136
export function withSourceURL(script: string, scriptPath: string): string {
137+
// If we've already got a `//# sourceURL` comment, return `script` as is
138+
// (searching from the end as that's where we'd expect it)
139+
if (script.lastIndexOf("//# sourceURL=") !== -1) return script;
140+
137141
let scriptURL: URL | string = scriptPath;
138142
if (maybeGetStringScriptPathIndex(scriptPath) === undefined) {
139143
scriptURL = pathToFileURL(scriptPath);

0 commit comments

Comments
 (0)