@@ -232,24 +232,7 @@ export async function prepareBundleForDebugIdUpload(
232232 return ;
233233 }
234234
235- const uniqueSourceFileUploadPath = path . join (
236- uploadFolder ,
237- // We add a "chunk index" segment to the path that is a simple incrementing number to avoid name collisions.
238- // Name collisions can happen when files are located "outside" of the current working directory, at different levels but they share a subpath.
239- // Example:
240- // - CWD: /root/foo/cwd
241- // - File 1: /root/foo/index.js -> ../foo/index.js -> foo/index.js
242- // - File 2: /foo/index.js -> ../../foo/index.js -> foo/index.js
243- `${ chunkIndex } ` ,
244- path . normalize (
245- path
246- . relative ( process . cwd ( ) , bundleFilePath )
247- . split ( path . sep )
248- // We filter out these "navigation" segments because a) they look ugly b) they will cause us to break out of the upload folder.
249- . filter ( ( segment ) => segment !== ".." && segment !== "." )
250- . join ( path . sep )
251- )
252- ) ;
235+ const uniqueSourceFileUploadPath = getUniqueUploadPath ( uploadFolder , chunkIndex , bundleFilePath ) ;
253236 bundleContent += `\n//# debugId=${ debugId } ` ;
254237 const writeSourceFilePromise = fs . promises
255238 . mkdir ( path . dirname ( uniqueSourceFileUploadPath ) , { recursive : true } )
@@ -263,14 +246,7 @@ export async function prepareBundleForDebugIdUpload(
263246 if ( sourceMapPath ) {
264247 await prepareSourceMapForDebugIdUpload (
265248 sourceMapPath ,
266- path . normalize (
267- path
268- . join ( uploadFolder , `${ chunkIndex } ` , path . relative ( process . cwd ( ) , sourceMapPath ) )
269- . split ( path . sep )
270- // We filter out these "navigation" segments because a) they look ugly b) they will cause us to break out of the upload folder.
271- . filter ( ( segment ) => segment !== ".." && segment !== "." )
272- . join ( path . sep )
273- ) ,
249+ getUniqueUploadPath ( uploadFolder , chunkIndex , sourceMapPath ) ,
274250 debugId ,
275251 rewriteSourcesHook ,
276252 logger
@@ -282,6 +258,27 @@ export async function prepareBundleForDebugIdUpload(
282258 await writeSourceMapFilePromise ;
283259}
284260
261+ function getUniqueUploadPath ( uploadFolder : string , chunkIndex : number , filePath : string ) {
262+ return path . join (
263+ uploadFolder ,
264+ // We add a "chunk index" segment to the path that is a simple incrementing number to avoid name collisions.
265+ // Name collisions can happen when files are located "outside" of the current working directory, at different levels but they share a subpath.
266+ // Example:
267+ // - CWD: /root/foo/cwd
268+ // - File 1: /root/foo/index.js -> ../foo/index.js -> foo/index.js
269+ // - File 2: /foo/index.js -> ../../foo/index.js -> foo/index.js
270+ `${ chunkIndex } ` ,
271+ path . normalize (
272+ path
273+ . relative ( process . cwd ( ) , filePath )
274+ . split ( path . sep )
275+ // We filter out these "navigation" segments because a) they look ugly b) they will cause us to break out of the upload folder.
276+ . filter ( ( segment ) => segment !== ".." && segment !== "." )
277+ . join ( path . sep )
278+ )
279+ ) ;
280+ }
281+
285282/**
286283 * Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
287284 * source and extracts the bundle's debug ID from it.
0 commit comments