Skip to content

Commit ebd494a

Browse files
author
Luca Forstner
committed
feat(core): Don't name bundles after debug IDs for upload
1 parent 9a7257d commit ebd494a

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export async function prepareBundleForDebugIdUpload(
213213
logger: Logger,
214214
rewriteSourcesHook: RewriteSourcesHook
215215
) {
216-
let bundleContent;
216+
let bundleContent: string;
217217
try {
218218
bundleContent = await promisify(fs.readFile)(bundleFilePath, "utf8");
219219
} catch (e) {
@@ -232,14 +232,21 @@ export async function prepareBundleForDebugIdUpload(
232232
return;
233233
}
234234

235-
const uniqueUploadName = `${debugId}-${chunkIndex}`;
236-
237-
bundleContent += `\n//# debugId=${debugId}`;
238-
const writeSourceFilePromise = fs.promises.writeFile(
239-
path.join(uploadFolder, `${uniqueUploadName}.js`),
240-
bundleContent,
241-
"utf-8"
235+
const uniqueSourceFileUploadPath = path.join(
236+
uploadFolder,
237+
`${chunkIndex}`,
238+
path.normalize(
239+
path
240+
.relative(process.cwd(), bundleFilePath)
241+
.split(path.sep)
242+
.filter((segment) => segment !== ".." && segment !== ".")
243+
.join(path.sep)
244+
)
242245
);
246+
bundleContent += `\n//# debugId=${debugId}`;
247+
const writeSourceFilePromise = fs.promises
248+
.mkdir(path.dirname(uniqueSourceFileUploadPath), { recursive: true })
249+
.then(() => fs.promises.writeFile(uniqueSourceFileUploadPath, bundleContent, "utf-8"));
243250

244251
const writeSourceMapFilePromise = determineSourceMapPathFromBundle(
245252
bundleFilePath,
@@ -249,7 +256,13 @@ export async function prepareBundleForDebugIdUpload(
249256
if (sourceMapPath) {
250257
await prepareSourceMapForDebugIdUpload(
251258
sourceMapPath,
252-
path.join(uploadFolder, `${uniqueUploadName}.js.map`),
259+
path.normalize(
260+
path
261+
.join(uploadFolder, `${chunkIndex}`, path.relative(process.cwd(), sourceMapPath))
262+
.split(path.sep)
263+
.filter((segment) => segment !== ".." && segment !== ".")
264+
.join(path.sep)
265+
),
253266
debugId,
254267
rewriteSourcesHook,
255268
logger
@@ -379,7 +392,8 @@ async function prepareSourceMapForDebugIdUpload(
379392
}
380393

381394
try {
382-
await util.promisify(fs.writeFile)(targetPath, JSON.stringify(map), {
395+
await fs.promises.mkdir(path.dirname(targetPath), { recursive: true });
396+
await fs.promises.writeFile(targetPath, JSON.stringify(map), {
383397
encoding: "utf8",
384398
});
385399
} catch (e) {

0 commit comments

Comments
 (0)