Skip to content

Revert "feat(core): Use path instead of debug IDs as artifact names for debug ID upload (#700)" #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

- "You know what they say ‘Fool me once, strike one, but fool me twice… strike three.’" — Michael Scott

## 3.2.4

- Revert "feat(core): Use path instead of debug IDs as artifact names for debug ID upload (#700)" (#709)
- ref: Remove deprecated use of `useArtifacBundles` (#707)

## 3.2.3

- feat(core): Use path instead of debug IDs as artifact names for debug ID upload (#700)
Expand Down
39 changes: 10 additions & 29 deletions packages/bundler-plugin-core/src/debug-id-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export async function prepareBundleForDebugIdUpload(
logger: Logger,
rewriteSourcesHook: RewriteSourcesHook
) {
let bundleContent: string;
let bundleContent;
try {
bundleContent = await promisify(fs.readFile)(bundleFilePath, "utf8");
} catch (e) {
Expand All @@ -231,11 +231,14 @@ export async function prepareBundleForDebugIdUpload(
return;
}

const uniqueSourceFileUploadPath = getUniqueUploadPath(uploadFolder, chunkIndex, bundleFilePath);
const uniqueUploadName = `${debugId}-${chunkIndex}`;

bundleContent += `\n//# debugId=${debugId}`;
const writeSourceFilePromise = fs.promises
.mkdir(path.dirname(uniqueSourceFileUploadPath), { recursive: true })
.then(() => fs.promises.writeFile(uniqueSourceFileUploadPath, bundleContent, "utf-8"));
const writeSourceFilePromise = fs.promises.writeFile(
path.join(uploadFolder, `${uniqueUploadName}.js`),
bundleContent,
"utf-8"
);

const writeSourceMapFilePromise = determineSourceMapPathFromBundle(
bundleFilePath,
Expand All @@ -245,7 +248,7 @@ export async function prepareBundleForDebugIdUpload(
if (sourceMapPath) {
await prepareSourceMapForDebugIdUpload(
sourceMapPath,
getUniqueUploadPath(uploadFolder, chunkIndex, sourceMapPath),
path.join(uploadFolder, `${uniqueUploadName}.js.map`),
debugId,
rewriteSourcesHook,
logger
Expand All @@ -257,27 +260,6 @@ export async function prepareBundleForDebugIdUpload(
await writeSourceMapFilePromise;
}

function getUniqueUploadPath(uploadFolder: string, chunkIndex: number, filePath: string) {
return path.join(
uploadFolder,
// We add a "chunk index" segment to the path that is a simple incrementing number to avoid name collisions.
// Name collisions can happen when files are located "outside" of the current working directory, at different levels but they share a subpath.
// Example:
// - CWD: /root/foo/cwd
// - File 1: /root/foo/index.js -> ../foo/index.js -> foo/index.js
// - File 2: /foo/index.js -> ../../foo/index.js -> foo/index.js
`${chunkIndex}`,
path.normalize(
path
.relative(process.cwd(), filePath)
.split(path.sep)
// We filter out these "navigation" segments because a) they look ugly b) they will cause us to break out of the upload folder.
.filter((segment) => segment !== ".." && segment !== ".")
.join(path.sep)
)
);
}

/**
* Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
* source and extracts the bundle's debug ID from it.
Expand Down Expand Up @@ -396,8 +378,7 @@ async function prepareSourceMapForDebugIdUpload(
}

try {
await fs.promises.mkdir(path.dirname(targetPath), { recursive: true });
await fs.promises.writeFile(targetPath, JSON.stringify(map), {
await util.promisify(fs.writeFile)(targetPath, JSON.stringify(map), {
encoding: "utf8",
});
} catch (e) {
Expand Down
Loading