|
11 | 11 | /// <reference path="../base/globals.d.ts" />
|
12 | 12 | /// <reference path="../../../shared/runtime-utils.ts" />
|
13 | 13 |
|
| 14 | +// Used in WebWorkers to tell the runtime about the chunk base path |
14 | 15 | declare var TURBOPACK_WORKER_LOCATION: string;
|
| 16 | +// Used in WebWorkers to tell the runtime about the current chunk url since it can't be detected via document.currentScript |
| 17 | +// Note it's stored in reversed order to use push and pop |
| 18 | +declare var TURBOPACK_NEXT_CHUNK_URLS: ChunkUrl[] | undefined; |
| 19 | + |
| 20 | +// Injected by rust code |
15 | 21 | declare var CHUNK_BASE_PATH: string;
|
16 | 22 | declare var CHUNK_SUFFIX_PATH: string;
|
| 23 | + |
| 24 | +// Provided by build or dev base |
17 | 25 | declare function instantiateModule(id: ModuleId, source: SourceInfo): Module;
|
18 | 26 |
|
19 | 27 | type RuntimeParams = {
|
@@ -245,7 +253,9 @@ function resolveAbsolutePath(modulePath?: string): string {
|
245 | 253 | }
|
246 | 254 |
|
247 | 255 | function getWorkerBlobURL(chunks: ChunkPath[]): string {
|
248 |
| - let bootstrap = `self.TURBOPACK_WORKER_LOCATION = ${JSON.stringify(location.origin)};importScripts(${chunks.map(c => (`self.TURBOPACK_WORKER_LOCATION + ${JSON.stringify(getChunkRelativeUrl(c))}`)).join(", ")});`; |
| 256 | + let bootstrap = `self.TURBOPACK_WORKER_LOCATION = ${JSON.stringify(location.origin)}; |
| 257 | +self.TURBOPACK_NEXT_CHUNK_URLS = ${JSON.stringify(chunks.reverse().map(getChunkRelativeUrl), null, 2)}; |
| 258 | +importScripts(...self.TURBOPACK_NEXT_CHUNK_URLS.map(c => self.TURBOPACK_WORKER_LOCATION + c).reverse());`; |
249 | 259 | let blob = new Blob([bootstrap], { type: "text/javascript" });
|
250 | 260 | return URL.createObjectURL(blob);
|
251 | 261 | }
|
@@ -313,7 +323,10 @@ function getPathFromScript(chunkScript: ChunkPath | ChunkListPath | ChunkScript
|
313 | 323 | if (typeof chunkScript === "string") {
|
314 | 324 | return chunkScript as ChunkPath | ChunkListPath;
|
315 | 325 | }
|
316 |
| - const src = decodeURIComponent(chunkScript.getAttribute("src")!); |
| 326 | + const chunkUrl = typeof TURBOPACK_NEXT_CHUNK_URLS !== "undefined" |
| 327 | + ? TURBOPACK_NEXT_CHUNK_URLS.pop()! |
| 328 | + : chunkScript.getAttribute("src")!; |
| 329 | + const src = decodeURIComponent(chunkUrl); |
317 | 330 | const path = src.startsWith(CHUNK_BASE_PATH) ? src.slice(CHUNK_BASE_PATH.length) : src;
|
318 | 331 | return path as ChunkPath | ChunkListPath;
|
319 | 332 | }
|
|
0 commit comments