Unverified Commit 6c2ab2c2 authored by Benjamin Woodruff ‮'s avatar Benjamin Woodruff Committed by GitHub

Turbopack: `resolveFileUrl`/`placeholderFileUrl` is always called with a module path (#99560)

Follow-up from
https://github.com/vercel/next.js/pull/99511#discussion_r4161127192

This runtime function is only ever called from generated code, which
always passes this argument.
parent 9a9ea121
...@@ -43,7 +43,7 @@ Context.prototype.P = resolveAbsolutePath ...@@ -43,7 +43,7 @@ Context.prototype.P = resolveAbsolutePath
* The location of a named `root` isn't known at runtime (the output may have * The location of a named `root` isn't known at runtime (the output may have
* been moved away from the sources), so this returns a placeholder URL for it. * been moved away from the sources), so this returns a placeholder URL for it.
*/ */
function resolveFileUrl(modulePath?: string, root?: string): string { function resolveFileUrl(modulePath: string, root?: string): string {
if (root !== undefined) { if (root !== undefined) {
return placeholderFileUrl(modulePath, root) return placeholderFileUrl(modulePath, root)
} }
......
...@@ -120,7 +120,7 @@ type AsyncModule = ( ...@@ -120,7 +120,7 @@ type AsyncModule = (
) => void ) => void
type ResolveAbsolutePath = (modulePath?: string) => string type ResolveAbsolutePath = (modulePath?: string) => string
type ResolveFileUrl = (modulePath?: string) => string type ResolveFileUrl = (modulePath: string, root?: string) => string
type ExternalRequire = ( type ExternalRequire = (
id: DependencySpecifier, id: DependencySpecifier,
......
...@@ -849,11 +849,10 @@ function factoryNotAvailableMessage( ...@@ -849,11 +849,10 @@ function factoryNotAvailableMessage(
/** /**
* Returns a `file://` URL under a synthetic directory named after `root` * Returns a `file://` URL under a synthetic directory named after `root`
* (`ROOT` for the project root), for when the real filesystem path is unknown. * (`ROOT` for the project root), for when the real filesystem path is unknown.
* Without a `modulePath`, this is `file:///ROOT/`. The root name and path * The root name and path segments are percent-encoded so the result is always
* segments are percent-encoded so the result is always a valid file URI. * a valid file URI.
*/ */
function placeholderFileUrl(modulePath?: string, root?: string): string { function placeholderFileUrl(modulePath: string, root?: string): string {
if (modulePath === undefined) return 'file:///ROOT/'
return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath
.split('/') .split('/')
.map(encodeURIComponent) .map(encodeURIComponent)
......
;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="2022e681-3b00-13d9-2dc9-3315d13b4a9b")}catch(e){}}(); ;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="976638d9-7f7b-0f2e-7bd5-80a2f6b9ac86")}catch(e){}}();
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([ (globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/0rv8_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0bjegbrfzt05o.js", "output/0rv8_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0bjegbrfzt05o.js",
{"otherChunks":["output/0_9x_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_03ibyvsq4xsbk.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]} {"otherChunks":["output/0_9x_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_03ibyvsq4xsbk.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]}
...@@ -653,10 +653,9 @@ contextPrototype.U = relativeURL; ...@@ -653,10 +653,9 @@ contextPrototype.U = relativeURL;
/** /**
* Returns a `file://` URL under a synthetic directory named after `root` * Returns a `file://` URL under a synthetic directory named after `root`
* (`ROOT` for the project root), for when the real filesystem path is unknown. * (`ROOT` for the project root), for when the real filesystem path is unknown.
* Without a `modulePath`, this is `file:///ROOT/`. The root name and path * The root name and path segments are percent-encoded so the result is always
* segments are percent-encoded so the result is always a valid file URI. * a valid file URI.
*/ function placeholderFileUrl(modulePath, root) { */ function placeholderFileUrl(modulePath, root) {
if (modulePath === undefined) return 'file:///ROOT/';
return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`; return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`;
} }
/** /**
...@@ -2615,5 +2614,5 @@ chunkListsToRegister.forEach(registerChunkList); ...@@ -2615,5 +2614,5 @@ chunkListsToRegister.forEach(registerChunkList);
})(); })();
//# debugId=2022e681-3b00-13d9-2dc9-3315d13b4a9b //# debugId=976638d9-7f7b-0f2e-7bd5-80a2f6b9ac86
//# sourceMappingURL=0_9x_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0bjegbrfzt05o.js.map //# sourceMappingURL=0_9x_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0bjegbrfzt05o.js.map
\ No newline at end of file
...@@ -630,10 +630,9 @@ contextPrototype.U = relativeURL; ...@@ -630,10 +630,9 @@ contextPrototype.U = relativeURL;
/** /**
* Returns a `file://` URL under a synthetic directory named after `root` * Returns a `file://` URL under a synthetic directory named after `root`
* (`ROOT` for the project root), for when the real filesystem path is unknown. * (`ROOT` for the project root), for when the real filesystem path is unknown.
* Without a `modulePath`, this is `file:///ROOT/`. The root name and path * The root name and path segments are percent-encoded so the result is always
* segments are percent-encoded so the result is always a valid file URI. * a valid file URI.
*/ function placeholderFileUrl(modulePath, root) { */ function placeholderFileUrl(modulePath, root) {
if (modulePath === undefined) return 'file:///ROOT/';
return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`; return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`;
} }
/** /**
......
...@@ -630,10 +630,9 @@ contextPrototype.U = relativeURL; ...@@ -630,10 +630,9 @@ contextPrototype.U = relativeURL;
/** /**
* Returns a `file://` URL under a synthetic directory named after `root` * Returns a `file://` URL under a synthetic directory named after `root`
* (`ROOT` for the project root), for when the real filesystem path is unknown. * (`ROOT` for the project root), for when the real filesystem path is unknown.
* Without a `modulePath`, this is `file:///ROOT/`. The root name and path * The root name and path segments are percent-encoded so the result is always
* segments are percent-encoded so the result is always a valid file URI. * a valid file URI.
*/ function placeholderFileUrl(modulePath, root) { */ function placeholderFileUrl(modulePath, root) {
if (modulePath === undefined) return 'file:///ROOT/';
return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`; return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`;
} }
/** /**
......
...@@ -652,10 +652,9 @@ contextPrototype.U = relativeURL; ...@@ -652,10 +652,9 @@ contextPrototype.U = relativeURL;
/** /**
* Returns a `file://` URL under a synthetic directory named after `root` * Returns a `file://` URL under a synthetic directory named after `root`
* (`ROOT` for the project root), for when the real filesystem path is unknown. * (`ROOT` for the project root), for when the real filesystem path is unknown.
* Without a `modulePath`, this is `file:///ROOT/`. The root name and path * The root name and path segments are percent-encoded so the result is always
* segments are percent-encoded so the result is always a valid file URI. * a valid file URI.
*/ function placeholderFileUrl(modulePath, root) { */ function placeholderFileUrl(modulePath, root) {
if (modulePath === undefined) return 'file:///ROOT/';
return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`; return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`;
} }
/** /**
......
...@@ -880,10 +880,9 @@ contextPrototype.U = relativeURL; ...@@ -880,10 +880,9 @@ contextPrototype.U = relativeURL;
/** /**
* Returns a `file://` URL under a synthetic directory named after `root` * Returns a `file://` URL under a synthetic directory named after `root`
* (`ROOT` for the project root), for when the real filesystem path is unknown. * (`ROOT` for the project root), for when the real filesystem path is unknown.
* Without a `modulePath`, this is `file:///ROOT/`. The root name and path * The root name and path segments are percent-encoded so the result is always
* segments are percent-encoded so the result is always a valid file URI. * a valid file URI.
*/ function placeholderFileUrl(modulePath, root) { */ function placeholderFileUrl(modulePath, root) {
if (modulePath === undefined) return 'file:///ROOT/';
return `file:///${encodeURIComponent(root !== null && root !== void 0 ? root : 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`; return `file:///${encodeURIComponent(root !== null && root !== void 0 ? root : 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`;
} }
/** /**
......
...@@ -652,10 +652,9 @@ contextPrototype.U = relativeURL; ...@@ -652,10 +652,9 @@ contextPrototype.U = relativeURL;
/** /**
* Returns a `file://` URL under a synthetic directory named after `root` * Returns a `file://` URL under a synthetic directory named after `root`
* (`ROOT` for the project root), for when the real filesystem path is unknown. * (`ROOT` for the project root), for when the real filesystem path is unknown.
* Without a `modulePath`, this is `file:///ROOT/`. The root name and path * The root name and path segments are percent-encoded so the result is always
* segments are percent-encoded so the result is always a valid file URI. * a valid file URI.
*/ function placeholderFileUrl(modulePath, root) { */ function placeholderFileUrl(modulePath, root) {
if (modulePath === undefined) return 'file:///ROOT/';
return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`; return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`;
} }
/** /**
......
...@@ -652,10 +652,9 @@ contextPrototype.U = relativeURL; ...@@ -652,10 +652,9 @@ contextPrototype.U = relativeURL;
/** /**
* Returns a `file://` URL under a synthetic directory named after `root` * Returns a `file://` URL under a synthetic directory named after `root`
* (`ROOT` for the project root), for when the real filesystem path is unknown. * (`ROOT` for the project root), for when the real filesystem path is unknown.
* Without a `modulePath`, this is `file:///ROOT/`. The root name and path * The root name and path segments are percent-encoded so the result is always
* segments are percent-encoded so the result is always a valid file URI. * a valid file URI.
*/ function placeholderFileUrl(modulePath, root) { */ function placeholderFileUrl(modulePath, root) {
if (modulePath === undefined) return 'file:///ROOT/';
return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`; return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`;
} }
/** /**
......
...@@ -652,10 +652,9 @@ contextPrototype.U = relativeURL; ...@@ -652,10 +652,9 @@ contextPrototype.U = relativeURL;
/** /**
* Returns a `file://` URL under a synthetic directory named after `root` * Returns a `file://` URL under a synthetic directory named after `root`
* (`ROOT` for the project root), for when the real filesystem path is unknown. * (`ROOT` for the project root), for when the real filesystem path is unknown.
* Without a `modulePath`, this is `file:///ROOT/`. The root name and path * The root name and path segments are percent-encoded so the result is always
* segments are percent-encoded so the result is always a valid file URI. * a valid file URI.
*/ function placeholderFileUrl(modulePath, root) { */ function placeholderFileUrl(modulePath, root) {
if (modulePath === undefined) return 'file:///ROOT/';
return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`; return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`;
} }
/** /**
......
...@@ -652,10 +652,9 @@ contextPrototype.U = relativeURL; ...@@ -652,10 +652,9 @@ contextPrototype.U = relativeURL;
/** /**
* Returns a `file://` URL under a synthetic directory named after `root` * Returns a `file://` URL under a synthetic directory named after `root`
* (`ROOT` for the project root), for when the real filesystem path is unknown. * (`ROOT` for the project root), for when the real filesystem path is unknown.
* Without a `modulePath`, this is `file:///ROOT/`. The root name and path * The root name and path segments are percent-encoded so the result is always
* segments are percent-encoded so the result is always a valid file URI. * a valid file URI.
*/ function placeholderFileUrl(modulePath, root) { */ function placeholderFileUrl(modulePath, root) {
if (modulePath === undefined) return 'file:///ROOT/';
return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`; return `file:///${encodeURIComponent(root ?? 'ROOT')}/${modulePath.split('/').map(encodeURIComponent).join('/')}`;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment