Skip to content

Commit 6cce90a

Browse files
authored
Revert "feat(core): Use path instead of debug IDs as artifact names for debug ID upload (#700)" (#709)
1 parent a70ab2d commit 6cce90a

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

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

7+
## 3.2.4
8+
9+
- Revert "feat(core): Use path instead of debug IDs as artifact names for debug ID upload (#700)" (#709)
10+
- ref: Remove deprecated use of `useArtifacBundles` (#707)
11+
712
## 3.2.3
813

914
- feat(core): Use path instead of debug IDs as artifact names for debug ID upload (#700)

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

+10-29
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export async function prepareBundleForDebugIdUpload(
212212
logger: Logger,
213213
rewriteSourcesHook: RewriteSourcesHook
214214
) {
215-
let bundleContent: string;
215+
let bundleContent;
216216
try {
217217
bundleContent = await promisify(fs.readFile)(bundleFilePath, "utf8");
218218
} catch (e) {
@@ -231,11 +231,14 @@ export async function prepareBundleForDebugIdUpload(
231231
return;
232232
}
233233

234-
const uniqueSourceFileUploadPath = getUniqueUploadPath(uploadFolder, chunkIndex, bundleFilePath);
234+
const uniqueUploadName = `${debugId}-${chunkIndex}`;
235+
235236
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+
);
239242

240243
const writeSourceMapFilePromise = determineSourceMapPathFromBundle(
241244
bundleFilePath,
@@ -245,7 +248,7 @@ export async function prepareBundleForDebugIdUpload(
245248
if (sourceMapPath) {
246249
await prepareSourceMapForDebugIdUpload(
247250
sourceMapPath,
248-
getUniqueUploadPath(uploadFolder, chunkIndex, sourceMapPath),
251+
path.join(uploadFolder, `${uniqueUploadName}.js.map`),
249252
debugId,
250253
rewriteSourcesHook,
251254
logger
@@ -257,27 +260,6 @@ export async function prepareBundleForDebugIdUpload(
257260
await writeSourceMapFilePromise;
258261
}
259262

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-
281263
/**
282264
* Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
283265
* source and extracts the bundle's debug ID from it.
@@ -396,8 +378,7 @@ async function prepareSourceMapForDebugIdUpload(
396378
}
397379

398380
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), {
401382
encoding: "utf8",
402383
});
403384
} catch (e) {

0 commit comments

Comments
 (0)