Skip to content

Commit b17b44a

Browse files
author
Luca Forstner
committed
Add explanations
1 parent ebd494a commit b17b44a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/bundler-plugin-core/src/debug-id-upload.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,18 @@ export async function prepareBundleForDebugIdUpload(
234234

235235
const uniqueSourceFileUploadPath = path.join(
236236
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
237243
`${chunkIndex}`,
238244
path.normalize(
239245
path
240246
.relative(process.cwd(), bundleFilePath)
241247
.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.
242249
.filter((segment) => segment !== ".." && segment !== ".")
243250
.join(path.sep)
244251
)
@@ -260,6 +267,7 @@ export async function prepareBundleForDebugIdUpload(
260267
path
261268
.join(uploadFolder, `${chunkIndex}`, path.relative(process.cwd(), sourceMapPath))
262269
.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.
263271
.filter((segment) => segment !== ".." && segment !== ".")
264272
.join(path.sep)
265273
),

0 commit comments

Comments
 (0)