@@ -21,22 +21,6 @@ declare var TURBOPACK_NEXT_CHUNK_URLS: ChunkUrl[] | undefined
2121declare var CHUNK_BASE_PATH : string
2222declare var CHUNK_SUFFIX_PATH : string
2323
24- function normalizeChunkPath ( path : string ) {
25- if ( path . startsWith ( '/' ) ) {
26- path = path . substring ( 1 )
27- } else if ( path . startsWith ( './' ) ) {
28- path = path . substring ( 2 )
29- }
30-
31- if ( ! path . endsWith ( '/' ) ) {
32- path += '/'
33- }
34-
35- return path
36- }
37-
38- const NORMALIZED_CHUNK_BASE_PATH = normalizeChunkPath ( CHUNK_BASE_PATH )
39-
4024interface TurbopackBrowserBaseContext < M > extends TurbopackBaseContext < M > {
4125 R : ResolvePathFromModule
4226}
@@ -340,8 +324,8 @@ function getWorkerBlobURL(chunks: ChunkPath[]): string {
340324 // It is important to reverse the array so when bootstrapping we can infer what chunk is being
341325 // evaluated by poping urls off of this array. See `getPathFromScript`
342326 let bootstrap = `self.TURBOPACK_WORKER_LOCATION = ${ JSON . stringify ( location . origin ) } ;
343- self.TURBOPACK_NEXT_CHUNK_URLS = ${ JSON . stringify ( chunks . reverse ( ) , null , 2 ) } ;
344- importScripts(...self.TURBOPACK_NEXT_CHUNK_URLS.map(c => self.TURBOPACK_WORKER_LOCATION + "/" + c).reverse());`
327+ self.TURBOPACK_NEXT_CHUNK_URLS = ${ JSON . stringify ( chunks . reverse ( ) . map ( getChunkRelativeUrl ) , null , 2 ) } ;
328+ importScripts(...self.TURBOPACK_NEXT_CHUNK_URLS.map(c => self.TURBOPACK_WORKER_LOCATION + c).reverse());`
345329 let blob = new Blob ( [ bootstrap ] , { type : 'text/javascript' } )
346330 return URL . createObjectURL ( blob )
347331}
@@ -360,7 +344,7 @@ function instantiateRuntimeModule(
360344 * Returns the URL relative to the origin where a chunk can be fetched from.
361345 */
362346function getChunkRelativeUrl ( chunkPath : ChunkPath | ChunkListPath ) : ChunkUrl {
363- return `${ NORMALIZED_CHUNK_BASE_PATH } ${ chunkPath
347+ return `${ CHUNK_BASE_PATH } ${ chunkPath
364348 . split ( '/' )
365349 . map ( ( p ) => encodeURIComponent ( p ) )
366350 . join ( '/' ) } ${ CHUNK_SUFFIX_PATH } ` as ChunkUrl
@@ -379,18 +363,13 @@ function getPathFromScript(
379363 if ( typeof chunkScript === 'string' ) {
380364 return chunkScript as ChunkPath | ChunkListPath
381365 }
382- let chunkUrl =
366+ const chunkUrl =
383367 typeof TURBOPACK_NEXT_CHUNK_URLS !== 'undefined'
384368 ? TURBOPACK_NEXT_CHUNK_URLS . pop ( ) !
385369 : chunkScript . getAttribute ( 'src' ) !
386- if ( chunkUrl . startsWith ( '/' ) ) {
387- chunkUrl = chunkUrl . substring ( 1 )
388- } else if ( chunkUrl . startsWith ( './' ) ) {
389- chunkUrl = chunkUrl . substring ( 2 )
390- }
391370 const src = decodeURIComponent ( chunkUrl . replace ( / [ ? # ] .* $ / , '' ) )
392- const path = src . startsWith ( NORMALIZED_CHUNK_BASE_PATH )
393- ? src . slice ( NORMALIZED_CHUNK_BASE_PATH . length )
371+ const path = src . startsWith ( CHUNK_BASE_PATH )
372+ ? src . slice ( CHUNK_BASE_PATH . length )
394373 : src
395374 return path as ChunkPath | ChunkListPath
396375}
0 commit comments