Skip to content

Commit

Permalink
Use existing //# sourceURL comments if present (#706)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mrbbot committed Nov 1, 2023
1 parent 77ac0d5 commit 7530e7e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/miniflare/src/plugins/core/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ function moduleName(modulesRoot: string, modulePath: string) {
return path.sep === "\\" ? name.replaceAll("\\", "/") : name;
}
export function withSourceURL(script: string, scriptPath: string): string {
// If we've already got a `//# sourceURL` comment, return `script` as is
// (searching from the end as that's where we'd expect it)
if (script.lastIndexOf("//# sourceURL=") !== -1) return script;

let scriptURL: URL | string = scriptPath;
if (maybeGetStringScriptPathIndex(scriptPath) === undefined) {
scriptURL = pathToFileURL(scriptPath);
Expand Down

0 comments on commit 7530e7e

Please sign in to comment.