@@ -212,7 +212,7 @@ export async function prepareBundleForDebugIdUpload(
212
212
logger : Logger ,
213
213
rewriteSourcesHook : RewriteSourcesHook
214
214
) {
215
- let bundleContent : string ;
215
+ let bundleContent ;
216
216
try {
217
217
bundleContent = await promisify ( fs . readFile ) ( bundleFilePath , "utf8" ) ;
218
218
} catch ( e ) {
@@ -231,11 +231,14 @@ export async function prepareBundleForDebugIdUpload(
231
231
return ;
232
232
}
233
233
234
- const uniqueSourceFileUploadPath = getUniqueUploadPath ( uploadFolder , chunkIndex , bundleFilePath ) ;
234
+ const uniqueUploadName = `${ debugId } -${ chunkIndex } ` ;
235
+
235
236
bundleContent += `\n//# debugId=${ debugId } ` ;
236
- const writeSourceFilePromise = fs . promises
237
- . mkdir ( path . dirname ( uniqueSourceFileUploadPath ) , { recursive : true } )
238
- . then ( ( ) => fs . promises . writeFile ( uniqueSourceFileUploadPath , bundleContent , "utf-8" ) ) ;
237
+ const writeSourceFilePromise = fs . promises . writeFile (
238
+ path . join ( uploadFolder , `${ uniqueUploadName } .js` ) ,
239
+ bundleContent ,
240
+ "utf-8"
241
+ ) ;
239
242
240
243
const writeSourceMapFilePromise = determineSourceMapPathFromBundle (
241
244
bundleFilePath ,
@@ -245,7 +248,7 @@ export async function prepareBundleForDebugIdUpload(
245
248
if ( sourceMapPath ) {
246
249
await prepareSourceMapForDebugIdUpload (
247
250
sourceMapPath ,
248
- getUniqueUploadPath ( uploadFolder , chunkIndex , sourceMapPath ) ,
251
+ path . join ( uploadFolder , ` ${ uniqueUploadName } .js.map` ) ,
249
252
debugId ,
250
253
rewriteSourcesHook ,
251
254
logger
@@ -257,27 +260,6 @@ export async function prepareBundleForDebugIdUpload(
257
260
await writeSourceMapFilePromise ;
258
261
}
259
262
260
- function getUniqueUploadPath ( uploadFolder : string , chunkIndex : number , filePath : string ) {
261
- return path . join (
262
- uploadFolder ,
263
- // We add a "chunk index" segment to the path that is a simple incrementing number to avoid name collisions.
264
- // Name collisions can happen when files are located "outside" of the current working directory, at different levels but they share a subpath.
265
- // Example:
266
- // - CWD: /root/foo/cwd
267
- // - File 1: /root/foo/index.js -> ../foo/index.js -> foo/index.js
268
- // - File 2: /foo/index.js -> ../../foo/index.js -> foo/index.js
269
- `${ chunkIndex } ` ,
270
- path . normalize (
271
- path
272
- . relative ( process . cwd ( ) , filePath )
273
- . split ( path . sep )
274
- // We filter out these "navigation" segments because a) they look ugly b) they will cause us to break out of the upload folder.
275
- . filter ( ( segment ) => segment !== ".." && segment !== "." )
276
- . join ( path . sep )
277
- )
278
- ) ;
279
- }
280
-
281
263
/**
282
264
* Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
283
265
* source and extracts the bundle's debug ID from it.
@@ -396,8 +378,7 @@ async function prepareSourceMapForDebugIdUpload(
396
378
}
397
379
398
380
try {
399
- await fs . promises . mkdir ( path . dirname ( targetPath ) , { recursive : true } ) ;
400
- await fs . promises . writeFile ( targetPath , JSON . stringify ( map ) , {
381
+ await util . promisify ( fs . writeFile ) ( targetPath , JSON . stringify ( map ) , {
401
382
encoding : "utf8" ,
402
383
} ) ;
403
384
} catch ( e ) {
0 commit comments