Unverified Commit cd714d9f authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

[16.3.x] Fix Turbopack worker chunk loading with asset prefix (#97419)

Backports [Fix Turbopack worker chunk loading with asset
prefix](https://github.com/vercel/next.js/pull/96636) to `next-16-3`.

<!-- NEXT_JS_LLM -->
Co-authored-by: 's avatarTobias Koppers <tobias.koppers@googlemail.com>
parent 5ac2327e
import { Resvg, initWasm } from '@resvg/resvg-wasm'
type Props = {
svg: string
width: number
}
self.onmessage = async (event: MessageEvent<Props>) => {
const { svg, width } = event.data
try {
await initWasm(fetch('/wasms/resvg.wasm'))
const renderer = new Resvg(svg, {
fitTo: {
mode: 'width',
value: Math.round(width),
},
})
const pngBuffer = renderer.render().asPng()
const blob = new Blob([new Uint8Array(pngBuffer)], {
type: 'image/png',
})
self.postMessage({ success: true, blob })
} catch (error) {
self.postMessage({
success: false,
error: error instanceof Error ? error.message : String(error),
})
}
}
'use client'
import { useState } from 'react'
import { svgToPngFromWebWorker } from './svg-to-png-from-web-worker'
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="4">
<rect width="8" height="4" fill="red" />
</svg>
`
export default function ResvgWorkerPage() {
const [result, setResult] = useState({
state: 'default',
type: 'default',
dimensions: 'default',
size: '0',
})
return (
<main>
<button
onClick={async () => {
try {
const blob = await svgToPngFromWebWorker(svg, 8, 2)
const image = await createImageBitmap(blob)
setResult({
state: 'success',
type: blob.type,
dimensions: `${image.width}x${image.height}`,
size: String(blob.size),
})
image.close()
} catch (error) {
setResult((current) => ({
...current,
state: `error:${
error instanceof Error ? error.message : String(error)
}`,
}))
}
}}
>
Render SVG in worker
</button>
<p id="worker-state">{result.state}</p>
<p id="png-type">{result.type}</p>
<p id="png-dimensions">{result.dimensions}</p>
<p id="png-size">{result.size}</p>
</main>
)
}
export async function svgToPngFromWebWorker(
svg: string,
width: number,
multiplier?: number
): Promise<Blob> {
const worker = new Worker(new URL('../resvg-worker.ts', import.meta.url))
try {
return await new Promise<Blob>((resolve, reject) => {
worker.onmessage = (event) => {
if (event.data.success) {
resolve(event.data.blob)
} else {
reject(event.data.error)
}
}
worker.postMessage({
svg,
width: width * (multiplier ?? devicePixelRatio),
})
})
} finally {
worker.terminate()
}
}
import { isNextDeploy, isNextStart, nextTestSetup } from 'e2e-utils' import { FileRef, isNextDeploy, isNextStart, nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
import { join } from 'path'
import { Page } from 'playwright' import { Page } from 'playwright'
describe('app dir - workers', () => { describe('app dir - workers', () => {
const { next, isTurbopack } = nextTestSetup({ const { next, isTurbopack } = nextTestSetup({
files: __dirname, files: {
app: new FileRef(join(__dirname, 'app')),
public: new FileRef(join(__dirname, 'public')),
'next.config.js': new FileRef(join(__dirname, 'next.config.js')),
'public/wasms/resvg.wasm': new FileRef(
require.resolve('next/dist/compiled/@vercel/og/resvg.wasm')
),
},
dependencies: {
'@resvg/resvg-wasm': '2.4.0',
},
env: { env: {
NEXT_DEPLOYMENT_ID: isNextStart ? 'test-deployment-id' : undefined, NEXT_DEPLOYMENT_ID: isNextStart ? 'test-deployment-id' : undefined,
}, },
...@@ -117,6 +128,24 @@ describe('app dir - workers', () => { ...@@ -117,6 +128,24 @@ describe('app dir - workers', () => {
) )
}) })
it('should support rendering an SVG with a WASM package in a worker', async () => {
const browser = await next.browser('/resvg', {
beforePageLoad,
})
expect(await browser.elementByCss('#worker-state').text()).toBe('default')
await browser.elementByCss('button').click()
await retry(async () => {
expect(await browser.elementByCss('#worker-state').text()).toBe('success')
expect(await browser.elementByCss('#png-type').text()).toBe('image/png')
expect(await browser.elementByCss('#png-dimensions').text()).toBe('16x8')
expect(
Number(await browser.elementByCss('#png-size').text())
).toBeGreaterThan(0)
})
})
it('should support shared workers', async () => { it('should support shared workers', async () => {
if (!isTurbopack) { if (!isTurbopack) {
// webpack requires a magic attribute for shared workers to function // webpack requires a magic attribute for shared workers to function
......
...@@ -8,6 +8,7 @@ export default function ClientComponent() { ...@@ -8,6 +8,7 @@ export default function ClientComponent() {
const [pageOrigin, setPageOrigin] = useState<string>(NONE) const [pageOrigin, setPageOrigin] = useState<string>(NONE)
const [workerCtorUrl, setWorkerCtorUrl] = useState<string>(NONE) const [workerCtorUrl, setWorkerCtorUrl] = useState<string>(NONE)
const [workerCtorError, setWorkerCtorError] = useState<string>(NONE) const [workerCtorError, setWorkerCtorError] = useState<string>(NONE)
const [workerReply, setWorkerReply] = useState<string>(NONE)
useEffect(() => { useEffect(() => {
setPageOrigin(window.location.origin) setPageOrigin(window.location.origin)
...@@ -31,16 +32,22 @@ export default function ClientComponent() { ...@@ -31,16 +32,22 @@ export default function ClientComponent() {
} }
} }
let worker: Worker | undefined
try { try {
// Trigger the turbopack `new Worker(new URL(..., import.meta.url))` // Trigger the turbopack `new Worker(new URL(..., import.meta.url))`
// pattern. Result is intercepted by the patched Worker above. // pattern. Result is intercepted by the patched Worker above.
worker = new Worker(new URL('./worker.ts', import.meta.url))
new Worker(new URL('./worker.ts', import.meta.url)) worker.onmessage = (event) => {
setWorkerReply(event.data)
}
worker.postMessage('ping')
} catch { } catch {
// Already captured by the patched constructor; React state will // Already captured by the patched constructor; React state will
// reflect it on the next render. // reflect it on the next render.
} }
;(window as any).Worker = OriginalWorker ;(window as any).Worker = OriginalWorker
return () => worker?.terminate()
}, []) }, [])
return ( return (
...@@ -51,6 +58,8 @@ export default function ClientComponent() { ...@@ -51,6 +58,8 @@ export default function ClientComponent() {
<pre id="worker-ctor-url">{workerCtorUrl}</pre> <pre id="worker-ctor-url">{workerCtorUrl}</pre>
<p>Worker constructor error (if any):</p> <p>Worker constructor error (if any):</p>
<pre id="worker-ctor-error">{workerCtorError}</pre> <pre id="worker-ctor-error">{workerCtorError}</pre>
<p>Worker reply:</p>
<pre id="worker-reply">{workerReply}</pre>
</> </>
) )
} }
// Post back the worker's own origin so the main thread can verify whether the self.onmessage = (event: MessageEvent<string>) => {
// worker entrypoint was loaded same-origin or cross-origin. self.postMessage(`pong: ${event.data}`)
self.postMessage(self.location.origin) }
export {}
...@@ -103,6 +103,11 @@ describeTurbopack('turbopack-worker-asset-prefix', () => { ...@@ -103,6 +103,11 @@ describeTurbopack('turbopack-worker-asset-prefix', () => {
const error = await browser.elementByCss('#worker-ctor-error').text() const error = await browser.elementByCss('#worker-ctor-error').text()
expect(error).toBe('(none)') expect(error).toBe('(none)')
await retry(async () => {
const reply = await browser.elementByCss('#worker-reply').text()
expect(reply).toBe('pong: ping')
})
}) })
}) })
...@@ -148,5 +153,14 @@ describeTurbopack('turbopack-worker-asset-prefix', () => { ...@@ -148,5 +153,14 @@ describeTurbopack('turbopack-worker-asset-prefix', () => {
const error = await browser.elementByCss('#worker-ctor-error').text() const error = await browser.elementByCss('#worker-ctor-error').text()
expect(error).toBe('(none)') expect(error).toBe('(none)')
}) })
it('executes the worker and receives a reply', async () => {
const browser = await next.browser('/')
await retry(async () => {
const reply = await browser.elementByCss('#worker-reply').text()
expect(reply).toBe('pong: ping')
})
})
}) })
}) })
...@@ -21,7 +21,7 @@ use crate::BrowserChunkingContext; ...@@ -21,7 +21,7 @@ use crate::BrowserChunkingContext;
/// A pre-compiled worker entrypoint that bootstraps workers by reading config from URL params. /// A pre-compiled worker entrypoint that bootstraps workers by reading config from URL params.
/// ///
/// The worker receives a JSON array via URL params of the following structure: /// The worker receives a JSON array via URL params of the following structure:
/// `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...forwarded_global_values]` /// `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...forwarded_global_values]`
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(ValueToString)] #[derive(ValueToString)]
#[value_to_string("Ecmascript Browser Worker Entrypoint")] #[value_to_string("Ecmascript Browser Worker Entrypoint")]
...@@ -148,7 +148,7 @@ impl GenerateSourceMap for EcmascriptBrowserWorkerEntrypoint { ...@@ -148,7 +148,7 @@ impl GenerateSourceMap for EcmascriptBrowserWorkerEntrypoint {
/// Generates the worker bootstrap code as inline JavaScript. /// Generates the worker bootstrap code as inline JavaScript.
/// ///
/// The worker receives a JSON array via URL params of the following structure: /// The worker receives a JSON array via URL params of the following structure:
/// `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...forwarded_global_values]` /// `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...forwarded_global_values]`
fn generate_worker_bootstrap_code( fn generate_worker_bootstrap_code(
forwarded_globals: &[RcStr], forwarded_globals: &[RcStr],
shared_runtime: bool, shared_runtime: bool,
...@@ -156,14 +156,16 @@ fn generate_worker_bootstrap_code( ...@@ -156,14 +156,16 @@ fn generate_worker_bootstrap_code(
let mut code: CodeBuilder = CodeBuilder::default(); let mut code: CodeBuilder = CodeBuilder::default();
// Generate the Object.assign properties for forwarded globals // Generate the Object.assign properties for forwarded globals
// params[0] = chunk URLs, params[1] = ASSET_SUFFIX, params[2+] = forwarded globals // params[0] = chunk URLs, params[1] = ASSET_SUFFIX,
// params[2] = WORKER_CHUNK_BASE_PATH, params[3+] = forwarded globals
let mut global_assignments = vec![ let mut global_assignments = vec![
"TURBOPACK_NEXT_CHUNK_URLS: chunkUrls".to_string(), "TURBOPACK_NEXT_CHUNK_URLS: chunkUrls".to_string(),
"TURBOPACK_ASSET_SUFFIX: param(1)".to_string(), "TURBOPACK_ASSET_SUFFIX: param(1)".to_string(),
"TURBOPACK_CHUNK_BASE_PATH: param(2)".to_string(),
]; ];
for (i, name) in forwarded_globals.iter().enumerate() { for (i, name) in forwarded_globals.iter().enumerate() {
// Forwarded globals start at params[2] // Forwarded globals start at params[3]
global_assignments.push(format!("{name}: param({n})", n = i + 2)); global_assignments.push(format!("{name}: param({n})", n = i + 3));
} }
let globals_js = global_assignments.join(",\n "); let globals_js = global_assignments.join(",\n ");
......
...@@ -17,6 +17,9 @@ declare var TURBOPACK_ASSET_SUFFIX: string ...@@ -17,6 +17,9 @@ declare var TURBOPACK_ASSET_SUFFIX: string
// can't be detected via `document.currentScript`. Note it's stored in reversed // can't be detected via `document.currentScript`. Note it's stored in reversed
// order to use `push` and `pop` // order to use `push` and `pop`
declare var TURBOPACK_NEXT_CHUNK_URLS: ChunkUrl[] | undefined declare var TURBOPACK_NEXT_CHUNK_URLS: ChunkUrl[] | undefined
// Used in WebWorkers to override the regular chunk base path with the base
// used for the worker entrypoint and its initial chunks.
declare var TURBOPACK_CHUNK_BASE_PATH: string | undefined
// Injected by rust code // Injected by rust code
declare var CHUNK_BASE_PATH: string declare var CHUNK_BASE_PATH: string
...@@ -34,6 +37,11 @@ interface TurbopackBrowserBaseContext<M> extends TurbopackBaseContext<M> { ...@@ -34,6 +37,11 @@ interface TurbopackBrowserBaseContext<M> extends TurbopackBaseContext<M> {
const browserContextPrototype = const browserContextPrototype =
Context.prototype as TurbopackBrowserBaseContext<unknown> Context.prototype as TurbopackBrowserBaseContext<unknown>
const RUNTIME_CHUNK_BASE_PATH =
typeof TURBOPACK_CHUNK_BASE_PATH === 'string'
? TURBOPACK_CHUNK_BASE_PATH
: CHUNK_BASE_PATH
// Provided by build or dev base // Provided by build or dev base
declare function instantiateModule( declare function instantiateModule(
id: ModuleId, id: ModuleId,
...@@ -341,7 +349,9 @@ function loadChunkByUrlInternal( ...@@ -341,7 +349,9 @@ function loadChunkByUrlInternal(
function chunkUrlToPath(chunkUrl: ChunkUrl): ChunkPath { function chunkUrlToPath(chunkUrl: ChunkUrl): ChunkPath {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')) const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''))
return ( return (
src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src src.startsWith(RUNTIME_CHUNK_BASE_PATH)
? src.slice(RUNTIME_CHUNK_BASE_PATH.length)
: src
) as ChunkPath ) as ChunkPath
} }
...@@ -486,7 +496,7 @@ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/ ...@@ -486,7 +496,7 @@ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/
*/ */
function getChunkRelativeUrl( function getChunkRelativeUrl(
chunkPath: ChunkPath | ChunkListPath, chunkPath: ChunkPath | ChunkListPath,
basePath: string = CHUNK_BASE_PATH basePath: string = RUNTIME_CHUNK_BASE_PATH
): ChunkUrl { ): ChunkUrl {
// Most chunk paths need no escaping. // Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath)
...@@ -497,7 +507,7 @@ function getChunkRelativeUrl( ...@@ -497,7 +507,7 @@ function getChunkRelativeUrl(
// Shared runtime primitives consumed by the bundled `createWorker` helper, // Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`. // exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH as ChunkBasePath browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH as ChunkBasePath
browserContextPrototype.X = ASSET_SUFFIX as AssetSuffix browserContextPrototype.X = ASSET_SUFFIX as AssetSuffix
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker // Shared runtime primitive: build a chunk's URL. Used by the bundled worker
...@@ -519,8 +529,8 @@ function getPathFromScript( ...@@ -519,8 +529,8 @@ function getPathFromScript(
} }
const chunkUrl = chunkScript.src! const chunkUrl = chunkScript.src!
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')) const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''))
const path = src.startsWith(CHUNK_BASE_PATH) const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH)
? src.slice(CHUNK_BASE_PATH.length) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length)
: src : src
return path as ChunkPath | ChunkListPath return path as ChunkPath | ChunkListPath
} }
......
...@@ -130,7 +130,7 @@ let DEV_BACKEND: DevRuntimeBackend ...@@ -130,7 +130,7 @@ let DEV_BACKEND: DevRuntimeBackend
function _eval({ code, url, map }: EcmascriptModuleEntry): ModuleFactory { function _eval({ code, url, map }: EcmascriptModuleEntry): ModuleFactory {
code += `\n\n//# sourceURL=${encodeURI( code += `\n\n//# sourceURL=${encodeURI(
location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX
)}` )}`
if (map) { if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa( code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(
......
...@@ -32,7 +32,7 @@ type WorkerChunkData = string | { path: string } ...@@ -32,7 +32,7 @@ type WorkerChunkData = string | { path: string }
* which module chunks to load and which module to run as the entry point. * which module chunks to load and which module to run as the entry point.
* *
* The params are a JSON array of the following structure: * The params are a JSON array of the following structure:
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...workerForwardedGlobals values]` * `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...workerForwardedGlobals values]`
* *
* @param WorkerConstructor The Worker or SharedWorker constructor * @param WorkerConstructor The Worker or SharedWorker constructor
* @param entrypoint path to the worker entrypoint chunk * @param entrypoint path to the worker entrypoint chunk
...@@ -62,7 +62,11 @@ function createWorker( ...@@ -62,7 +62,11 @@ function createWorker(
) )
) )
.reverse() .reverse()
const params: unknown[] = [chunkUrls, __turbopack_chunk_asset_suffix__] const params: unknown[] = [
chunkUrls,
__turbopack_chunk_asset_suffix__,
workerBasePath,
]
const globals = _TURBOPACK_WORKER_FORWARDED_GLOBALS_ const globals = _TURBOPACK_WORKER_FORWARDED_GLOBALS_
for (let i = 0; i < globals.length; i++) { for (let i = 0; i < globals.length; i++) {
params.push((globalThis as Record<string, unknown>)[globals[i]]) params.push((globalThis as Record<string, unknown>)[globals[i]])
......
;!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]="8be33d93-70f0-5795-483a-8e4593e9e07e")}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]="f34f4684-6127-f0e7-0897-822ba1e1eea2")}catch(e){}}();
(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([ (globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
"output/1i9t_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js", "output/1i9t_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js",
{"otherChunks":["output/1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_03ibyvs.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]} {"otherChunks":["output/1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_03ibyvs.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]}
...@@ -684,6 +684,7 @@ contextPrototype.a = asyncModule; ...@@ -684,6 +684,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" /> /// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix // Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype; const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map(); const moduleFactories = new Map();
contextPrototype.M = moduleFactories; contextPrototype.M = moduleFactories;
const availableModules = new Map(); const availableModules = new Map();
...@@ -863,7 +864,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) { ...@@ -863,7 +864,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`. // match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) { function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
} }
/** /**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its * When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
...@@ -955,14 +956,14 @@ browserContextPrototype.q = exportUrl; ...@@ -955,14 +956,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/; */ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/** /**
* Returns the URL relative to the origin where a chunk can be fetched from. * Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) { */ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping. // Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath; const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`; return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
} }
// Shared runtime primitives consumed by the bundled `createWorker` helper, // Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`. // exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH; browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX; browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker // Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`. // helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
...@@ -973,7 +974,7 @@ function getPathFromScript(chunkScript) { ...@@ -973,7 +974,7 @@ function getPathFromScript(chunkScript) {
} }
const chunkUrl = chunkScript.src; const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/** /**
...@@ -2463,7 +2464,7 @@ let DEV_BACKEND; ...@@ -2463,7 +2464,7 @@ let DEV_BACKEND;
} }
})(); })();
function _eval({ code, url, map }) { function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`; code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) { if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875 // See https://stackoverflow.com/a/26603875
...@@ -2481,5 +2482,5 @@ chunkListsToRegister.forEach(registerChunkList); ...@@ -2481,5 +2482,5 @@ chunkListsToRegister.forEach(registerChunkList);
})(); })();
//# debugId=8be33d93-70f0-5795-483a-8e4593e9e07e //# debugId=f34f4684-6127-f0e7-0897-822ba1e1eea2
//# sourceMappingURL=1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js.map //# sourceMappingURL=1do3_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_19boa0e.js.map
\ No newline at end of file
...@@ -25,7 +25,8 @@ var chunkUrls = Array.isArray(params[0]) ? params[0] : []; ...@@ -25,7 +25,8 @@ var chunkUrls = Array.isArray(params[0]) ? params[0] : [];
Object.assign(self, { Object.assign(self, {
TURBOPACK_NEXT_CHUNK_URLS: chunkUrls, TURBOPACK_NEXT_CHUNK_URLS: chunkUrls,
TURBOPACK_ASSET_SUFFIX: param(1) TURBOPACK_ASSET_SUFFIX: param(1),
TURBOPACK_CHUNK_BASE_PATH: param(2)
}); });
if (chunkUrls.length > 0) { if (chunkUrls.length > 0) {
......
...@@ -73,7 +73,7 @@ __turbopack_context__.s([ ...@@ -73,7 +73,7 @@ __turbopack_context__.s([
* which module chunks to load and which module to run as the entry point. * which module chunks to load and which module to run as the entry point.
* *
* The params are a JSON array of the following structure: * The params are a JSON array of the following structure:
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...workerForwardedGlobals values]` * `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...workerForwardedGlobals values]`
* *
* @param WorkerConstructor The Worker or SharedWorker constructor * @param WorkerConstructor The Worker or SharedWorker constructor
* @param entrypoint path to the worker entrypoint chunk * @param entrypoint path to the worker entrypoint chunk
...@@ -89,7 +89,8 @@ __turbopack_context__.s([ ...@@ -89,7 +89,8 @@ __turbopack_context__.s([
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse(); const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse();
const params = [ const params = [
chunkUrls, chunkUrls,
/*TURBOPACK member replacement*/ __turbopack_context__.X /*TURBOPACK member replacement*/ __turbopack_context__.X,
workerBasePath
]; ];
const globals = []; const globals = [];
for(let i = 0; i < globals.length; i++){ for(let i = 0; i < globals.length; i++){
......
...@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule; ...@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" /> /// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix // Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype; const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map(); const moduleFactories = new Map();
contextPrototype.M = moduleFactories; contextPrototype.M = moduleFactories;
const availableModules = new Map(); const availableModules = new Map();
...@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) { ...@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`. // match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) { function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
} }
/** /**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its * When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
...@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl; ...@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/; */ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/** /**
* Returns the URL relative to the origin where a chunk can be fetched from. * Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) { */ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping. // Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath; const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`; return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
} }
// Shared runtime primitives consumed by the bundled `createWorker` helper, // Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`. // exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH; browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX; browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker // Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`. // helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
...@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) { ...@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) {
} }
const chunkUrl = chunkScript.src; const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/** /**
...@@ -2462,7 +2463,7 @@ let DEV_BACKEND; ...@@ -2462,7 +2463,7 @@ let DEV_BACKEND;
} }
})(); })();
function _eval({ code, url, map }) { function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`; code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) { if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875 // See https://stackoverflow.com/a/26603875
......
...@@ -958,6 +958,7 @@ function _ts_generator(thisArg, body) { ...@@ -958,6 +958,7 @@ function _ts_generator(thisArg, body) {
} }
} }
var browserContextPrototype = Context.prototype; var browserContextPrototype = Context.prototype;
var RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
var moduleFactories = new Map(); var moduleFactories = new Map();
contextPrototype.M = moduleFactories; contextPrototype.M = moduleFactories;
var availableModules = new Map(); var availableModules = new Map();
...@@ -1237,7 +1238,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) { ...@@ -1237,7 +1238,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`. // match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) { function chunkUrlToPath(chunkUrl) {
var src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); var src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
} }
/** /**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its * When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
...@@ -1350,14 +1351,14 @@ browserContextPrototype.q = exportUrl; ...@@ -1350,14 +1351,14 @@ browserContextPrototype.q = exportUrl;
/** /**
* Returns the URL relative to the origin where a chunk can be fetched from. * Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath) { */ function getChunkRelativeUrl(chunkPath) {
var basePath = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : CHUNK_BASE_PATH; var basePath = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : RUNTIME_CHUNK_BASE_PATH;
// Most chunk paths need no escaping. // Most chunk paths need no escaping.
var encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath; var encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`; return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
} }
// Shared runtime primitives consumed by the bundled `createWorker` helper, // Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`. // exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH; browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX; browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker // Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`. // helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
...@@ -1368,7 +1369,7 @@ function getPathFromScript(chunkScript) { ...@@ -1368,7 +1369,7 @@ function getPathFromScript(chunkScript) {
} }
var chunkUrl = chunkScript.src; var chunkUrl = chunkScript.src;
var src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); var src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
var path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; var path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/** /**
......
...@@ -25,7 +25,8 @@ var chunkUrls = Array.isArray(params[0]) ? params[0] : []; ...@@ -25,7 +25,8 @@ var chunkUrls = Array.isArray(params[0]) ? params[0] : [];
Object.assign(self, { Object.assign(self, {
TURBOPACK_NEXT_CHUNK_URLS: chunkUrls, TURBOPACK_NEXT_CHUNK_URLS: chunkUrls,
TURBOPACK_ASSET_SUFFIX: param(1) TURBOPACK_ASSET_SUFFIX: param(1),
TURBOPACK_CHUNK_BASE_PATH: param(2)
}); });
if (chunkUrls.length > 0) { if (chunkUrls.length > 0) {
......
...@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule; ...@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" /> /// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix // Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype; const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map(); const moduleFactories = new Map();
contextPrototype.M = moduleFactories; contextPrototype.M = moduleFactories;
const availableModules = new Map(); const availableModules = new Map();
...@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) { ...@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`. // match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) { function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
} }
/** /**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its * When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
...@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl; ...@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/; */ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/** /**
* Returns the URL relative to the origin where a chunk can be fetched from. * Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) { */ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping. // Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath; const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`; return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
} }
// Shared runtime primitives consumed by the bundled `createWorker` helper, // Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`. // exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH; browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX; browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker // Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`. // helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
...@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) { ...@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) {
} }
const chunkUrl = chunkScript.src; const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/** /**
...@@ -2462,7 +2463,7 @@ let DEV_BACKEND; ...@@ -2462,7 +2463,7 @@ let DEV_BACKEND;
} }
})(); })();
function _eval({ code, url, map }) { function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`; code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) { if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875 // See https://stackoverflow.com/a/26603875
......
...@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule; ...@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" /> /// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix // Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype; const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map(); const moduleFactories = new Map();
contextPrototype.M = moduleFactories; contextPrototype.M = moduleFactories;
const availableModules = new Map(); const availableModules = new Map();
...@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) { ...@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`. // match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) { function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
} }
/** /**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its * When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
...@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl; ...@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/; */ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/** /**
* Returns the URL relative to the origin where a chunk can be fetched from. * Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) { */ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping. // Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath; const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`; return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
} }
// Shared runtime primitives consumed by the bundled `createWorker` helper, // Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`. // exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH; browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX; browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker // Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`. // helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
...@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) { ...@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) {
} }
const chunkUrl = chunkScript.src; const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/** /**
...@@ -2462,7 +2463,7 @@ let DEV_BACKEND; ...@@ -2462,7 +2463,7 @@ let DEV_BACKEND;
} }
})(); })();
function _eval({ code, url, map }) { function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`; code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) { if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875 // See https://stackoverflow.com/a/26603875
......
...@@ -49,7 +49,7 @@ __turbopack_context__.s([ ...@@ -49,7 +49,7 @@ __turbopack_context__.s([
* which module chunks to load and which module to run as the entry point. * which module chunks to load and which module to run as the entry point.
* *
* The params are a JSON array of the following structure: * The params are a JSON array of the following structure:
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...workerForwardedGlobals values]` * `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...workerForwardedGlobals values]`
* *
* @param WorkerConstructor The Worker or SharedWorker constructor * @param WorkerConstructor The Worker or SharedWorker constructor
* @param entrypoint path to the worker entrypoint chunk * @param entrypoint path to the worker entrypoint chunk
...@@ -65,7 +65,8 @@ __turbopack_context__.s([ ...@@ -65,7 +65,8 @@ __turbopack_context__.s([
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse(); const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse();
const params = [ const params = [
chunkUrls, chunkUrls,
/*TURBOPACK member replacement*/ __turbopack_context__.X /*TURBOPACK member replacement*/ __turbopack_context__.X,
workerBasePath
]; ];
const globals = []; const globals = [];
for(let i = 0; i < globals.length; i++){ for(let i = 0; i < globals.length; i++){
......
...@@ -25,7 +25,8 @@ var chunkUrls = Array.isArray(params[0]) ? params[0] : []; ...@@ -25,7 +25,8 @@ var chunkUrls = Array.isArray(params[0]) ? params[0] : [];
Object.assign(self, { Object.assign(self, {
TURBOPACK_NEXT_CHUNK_URLS: chunkUrls, TURBOPACK_NEXT_CHUNK_URLS: chunkUrls,
TURBOPACK_ASSET_SUFFIX: param(1) TURBOPACK_ASSET_SUFFIX: param(1),
TURBOPACK_CHUNK_BASE_PATH: param(2)
}); });
if (chunkUrls.length > 0) { if (chunkUrls.length > 0) {
......
...@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule; ...@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" /> /// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix // Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype; const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map(); const moduleFactories = new Map();
contextPrototype.M = moduleFactories; contextPrototype.M = moduleFactories;
const availableModules = new Map(); const availableModules = new Map();
...@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) { ...@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`. // match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) { function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
} }
/** /**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its * When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
...@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl; ...@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/; */ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/** /**
* Returns the URL relative to the origin where a chunk can be fetched from. * Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) { */ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping. // Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath; const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`; return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
} }
// Shared runtime primitives consumed by the bundled `createWorker` helper, // Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`. // exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH; browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX; browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker // Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`. // helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
...@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) { ...@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) {
} }
const chunkUrl = chunkScript.src; const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/** /**
...@@ -2462,7 +2463,7 @@ let DEV_BACKEND; ...@@ -2462,7 +2463,7 @@ let DEV_BACKEND;
} }
})(); })();
function _eval({ code, url, map }) { function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`; code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) { if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875 // See https://stackoverflow.com/a/26603875
......
...@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule; ...@@ -683,6 +683,7 @@ contextPrototype.a = asyncModule;
/// <reference path="../../../shared/runtime/runtime-utils.ts" /> /// <reference path="../../../shared/runtime/runtime-utils.ts" />
// Used in WebWorkers to tell the runtime about the chunk suffix // Used in WebWorkers to tell the runtime about the chunk suffix
const browserContextPrototype = Context.prototype; const browserContextPrototype = Context.prototype;
const RUNTIME_CHUNK_BASE_PATH = typeof TURBOPACK_CHUNK_BASE_PATH === 'string' ? TURBOPACK_CHUNK_BASE_PATH : CHUNK_BASE_PATH;
const moduleFactories = new Map(); const moduleFactories = new Map();
contextPrototype.M = moduleFactories; contextPrototype.M = moduleFactories;
const availableModules = new Map(); const availableModules = new Map();
...@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) { ...@@ -862,7 +863,7 @@ function loadChunkByUrlInternal(sourceType, sourceData, chunkEntry) {
// match the keys stored in `chunkComponents`. // match the keys stored in `chunkComponents`.
function chunkUrlToPath(chunkUrl) { function chunkUrlToPath(chunkUrl) {
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
return src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; return src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
} }
/** /**
* When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its * When a merged chunk finishes registering (e.g. an initial-load `<script>`), mark its
...@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl; ...@@ -954,14 +955,14 @@ browserContextPrototype.q = exportUrl;
*/ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/; */ const CHUNK_PATH_NEEDS_ENCODING = /[^A-Za-z0-9\-_.!~*'()/]/;
/** /**
* Returns the URL relative to the origin where a chunk can be fetched from. * Returns the URL relative to the origin where a chunk can be fetched from.
*/ function getChunkRelativeUrl(chunkPath, basePath = CHUNK_BASE_PATH) { */ function getChunkRelativeUrl(chunkPath, basePath = RUNTIME_CHUNK_BASE_PATH) {
// Most chunk paths need no escaping. // Most chunk paths need no escaping.
const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath; const encodedPath = CHUNK_PATH_NEEDS_ENCODING.test(chunkPath) ? chunkPath.split('/').map(encodeURIComponent).join('/') : chunkPath;
return `${basePath}${encodedPath}${ASSET_SUFFIX}`; return `${basePath}${encodedPath}${ASSET_SUFFIX}`;
} }
// Shared runtime primitives consumed by the bundled `createWorker` helper, // Shared runtime primitives consumed by the bundled `createWorker` helper,
// exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`. // exposed as `__turbopack_chunk_base_path__` and `__turbopack_chunk_asset_suffix__`.
browserContextPrototype.b = CHUNK_BASE_PATH; browserContextPrototype.b = RUNTIME_CHUNK_BASE_PATH;
browserContextPrototype.X = ASSET_SUFFIX; browserContextPrototype.X = ASSET_SUFFIX;
// Shared runtime primitive: build a chunk's URL. Used by the bundled worker // Shared runtime primitive: build a chunk's URL. Used by the bundled worker
// helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`. // helper and the WASM helper, exposed as `__turbopack_chunk_relative_url__`.
...@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) { ...@@ -972,7 +973,7 @@ function getPathFromScript(chunkScript) {
} }
const chunkUrl = chunkScript.src; const chunkUrl = chunkScript.src;
const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, '')); const src = decodeURIComponent(chunkUrl.replace(/[?#].*$/, ''));
const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src; const path = src.startsWith(RUNTIME_CHUNK_BASE_PATH) ? src.slice(RUNTIME_CHUNK_BASE_PATH.length) : src;
return path; return path;
} }
/** /**
...@@ -2462,7 +2463,7 @@ let DEV_BACKEND; ...@@ -2462,7 +2463,7 @@ let DEV_BACKEND;
} }
})(); })();
function _eval({ code, url, map }) { function _eval({ code, url, map }) {
code += `\n\n//# sourceURL=${encodeURI(location.origin + CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`; code += `\n\n//# sourceURL=${encodeURI(location.origin + RUNTIME_CHUNK_BASE_PATH + url + ASSET_SUFFIX)}`;
if (map) { if (map) {
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(// btoa doesn't handle nonlatin characters, so escape them as \x sequences
// See https://stackoverflow.com/a/26603875 // See https://stackoverflow.com/a/26603875
......
...@@ -48,7 +48,7 @@ __turbopack_context__.s([ ...@@ -48,7 +48,7 @@ __turbopack_context__.s([
* which module chunks to load and which module to run as the entry point. * which module chunks to load and which module to run as the entry point.
* *
* The params are a JSON array of the following structure: * The params are a JSON array of the following structure:
* `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...workerForwardedGlobals values]` * `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, WORKER_CHUNK_BASE_PATH, ...workerForwardedGlobals values]`
* *
* @param WorkerConstructor The Worker or SharedWorker constructor * @param WorkerConstructor The Worker or SharedWorker constructor
* @param entrypoint path to the worker entrypoint chunk * @param entrypoint path to the worker entrypoint chunk
...@@ -64,7 +64,8 @@ __turbopack_context__.s([ ...@@ -64,7 +64,8 @@ __turbopack_context__.s([
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse(); const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.h(typeof chunk === 'string' ? chunk : chunk.path, workerBasePath)).reverse();
const params = [ const params = [
chunkUrls, chunkUrls,
/*TURBOPACK member replacement*/ __turbopack_context__.X /*TURBOPACK member replacement*/ __turbopack_context__.X,
workerBasePath
]; ];
const globals = []; const globals = [];
for(let i = 0; i < globals.length; i++){ for(let i = 0; i < globals.length; i++){
......
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