Skip to content

Commit 0ad9b5c

Browse files
⚡ perf: async sourcemap operations (#64)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
1 parent d9146c1 commit 0ad9b5c

5 files changed

Lines changed: 44 additions & 35 deletions

File tree

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,10 @@ lib/
107107
.DS_Store
108108
# react-native-update
109109
.update
110-
.pushy
110+
.pushytest-output/
111+
test-output2/
112+
bench.ts
113+
bench2.ts
114+
test-output3/
115+
test-output4/
116+
bench-node.js

bun.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"compare-versions": "^6.1.1",
6868
"filesize-parser": "^1.5.1",
6969
"form-data": "^4.0.5",
70-
"fs-extra": "8",
70+
"fs-extra": "^11.3.5",
7171
"global-dirs": "^4.0.0",
7272
"gradle-to-js": "^2.0.1",
7373
"i18next": "^26.0.4",

src/bundle-runner.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,11 @@ export async function copyDebugidForSentry(
596596
fs.removeSync(path.join(outputFolder, `${bundleName}.txt.map`));
597597
}
598598

599-
export function prepareSentryUploadArtifacts(
599+
export async function prepareSentryUploadArtifacts(
600600
bundleName: string,
601601
outputFolder: string,
602602
platform: string,
603-
): SentryUploadArtifacts {
603+
): Promise<SentryUploadArtifacts> {
604604
const bundlePath = path.join(outputFolder, bundleName);
605605
const sourcemapPath = path.join(outputFolder, `${bundleName}.map`);
606606

@@ -616,26 +616,26 @@ export function prepareSentryUploadArtifacts(
616616
outputFolder,
617617
`${ANDROID_SENTRY_BUNDLE_NAME}.map`,
618618
);
619-
fs.copyFileSync(bundlePath, androidBundlePath);
619+
await fs.promises.copyFile(bundlePath, androidBundlePath);
620620

621621
const sourcemap = JSON.parse(
622-
fs.readFileSync(sourcemapPath, 'utf8'),
622+
await fs.promises.readFile(sourcemapPath, 'utf8'),
623623
) as Record<string, unknown>;
624624
sourcemap.file = ANDROID_SENTRY_BUNDLE_NAME;
625-
fs.writeFileSync(androidSourcemapPath, JSON.stringify(sourcemap));
625+
await fs.promises.writeFile(androidSourcemapPath, JSON.stringify(sourcemap));
626626

627627
return {
628628
bundlePath: androidBundlePath,
629629
sourcemapPath: androidSourcemapPath,
630630
};
631631
}
632632

633-
export function readSourcemapDebugId(
633+
export async function readSourcemapDebugId(
634634
sourcemapPath: string,
635-
): string | undefined {
635+
): Promise<string | undefined> {
636636
try {
637637
const sourcemap = JSON.parse(
638-
fs.readFileSync(sourcemapPath, 'utf8'),
638+
await fs.promises.readFile(sourcemapPath, 'utf8'),
639639
) as Record<string, unknown>;
640640
const debugId = sourcemap.debugId ?? sourcemap.debug_id;
641641
return typeof debugId === 'string' ? normalizeString(debugId) : undefined;
@@ -658,10 +658,10 @@ function resolveSentryReleaseFromValues(
658658
};
659659
}
660660

661-
export function resolveSentryUploadMode(
661+
export async function resolveSentryUploadMode(
662662
sourcemapPath: string,
663663
options: SentryUploadOptions = {},
664-
): SentryUploadMode {
664+
): Promise<SentryUploadMode> {
665665
const optionRelease = resolveSentryReleaseFromValues(
666666
options.sentryRelease,
667667
options.sentryDist,
@@ -673,7 +673,7 @@ export function resolveSentryUploadMode(
673673
};
674674
}
675675

676-
const debugId = readSourcemapDebugId(sourcemapPath);
676+
const debugId = await readSourcemapDebugId(sourcemapPath);
677677
if (debugId) {
678678
return {
679679
type: 'debug-id',
@@ -848,12 +848,15 @@ export async function uploadSourcemapForSentry(
848848
return;
849849
}
850850

851-
const { bundlePath, sourcemapPath } = prepareSentryUploadArtifacts(
851+
const { bundlePath, sourcemapPath } = await prepareSentryUploadArtifacts(
852852
bundleName,
853853
outputFolder,
854854
platform,
855855
);
856-
const uploadMode = resolveSentryUploadMode(sourcemapPath, sentryOptions);
856+
const uploadMode = await resolveSentryUploadMode(
857+
sourcemapPath,
858+
sentryOptions,
859+
);
857860
const useStandaloneSourcemapsCommand =
858861
supportsStandaloneSentrySourcemapsUpload(sentryCliPath);
859862

tests/bundle-runner.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,40 +299,40 @@ describe('Sentry Debug ID upload mode', () => {
299299
}
300300
});
301301

302-
test('reads debugId from source maps', () => {
302+
test('reads debugId from source maps', async () => {
303303
const sourcemapPath = path.join(tempRoot, 'index.bundlejs.map');
304304
writeJson(sourcemapPath, {
305305
version: 3,
306306
debugId: '85314830-023f-4cf1-a267-535f4e37bb17',
307307
});
308308

309-
expect(readSourcemapDebugId(sourcemapPath)).toBe(
309+
expect(await readSourcemapDebugId(sourcemapPath)).toBe(
310310
'85314830-023f-4cf1-a267-535f4e37bb17',
311311
);
312312
});
313313

314-
test('prefers Debug ID upload when the source map has a Debug ID', () => {
314+
test('prefers Debug ID upload when the source map has a Debug ID', async () => {
315315
const sourcemapPath = path.join(tempRoot, 'index.bundlejs.map');
316316
writeJson(sourcemapPath, {
317317
version: 3,
318318
debug_id: '85314830-023f-4cf1-a267-535f4e37bb17',
319319
});
320320

321-
expect(resolveSentryUploadMode(sourcemapPath)).toEqual({
321+
expect(await resolveSentryUploadMode(sourcemapPath)).toEqual({
322322
type: 'debug-id',
323323
debugId: '85314830-023f-4cf1-a267-535f4e37bb17',
324324
});
325325
});
326326

327-
test('uses explicit release and dist before Debug ID for legacy self-hosted fallback', () => {
327+
test('uses explicit release and dist before Debug ID for legacy self-hosted fallback', async () => {
328328
const sourcemapPath = path.join(tempRoot, 'index.bundlejs.map');
329329
writeJson(sourcemapPath, {
330330
version: 3,
331331
debug_id: '85314830-023f-4cf1-a267-535f4e37bb17',
332332
});
333333

334334
expect(
335-
resolveSentryUploadMode(sourcemapPath, {
335+
await resolveSentryUploadMode(sourcemapPath, {
336336
sentryRelease: 'com.example@1.0.0+10+pushy:4.1',
337337
sentryDist: 'pushy:4.1',
338338
}),
@@ -343,14 +343,14 @@ describe('Sentry Debug ID upload mode', () => {
343343
});
344344
});
345345

346-
test('falls back to explicit release and dist when no Debug ID exists', () => {
346+
test('falls back to explicit release and dist when no Debug ID exists', async () => {
347347
const sourcemapPath = path.join(tempRoot, 'index.bundlejs.map');
348348
writeJson(sourcemapPath, {
349349
version: 3,
350350
});
351351

352352
expect(
353-
resolveSentryUploadMode(sourcemapPath, {
353+
await resolveSentryUploadMode(sourcemapPath, {
354354
sentryRelease: 'com.example@1.0.0+10+pushy:hash',
355355
sentryDist: 'pushy:hash',
356356
}),
@@ -361,28 +361,28 @@ describe('Sentry Debug ID upload mode', () => {
361361
});
362362
});
363363

364-
test('uses SENTRY_RELEASE and SENTRY_DIST for legacy fallback', () => {
364+
test('uses SENTRY_RELEASE and SENTRY_DIST for legacy fallback', async () => {
365365
process.env.SENTRY_RELEASE = 'com.example@1.0.0+10+pushy:hash';
366366
process.env.SENTRY_DIST = 'pushy:hash';
367367
const sourcemapPath = path.join(tempRoot, 'index.bundlejs.map');
368368
writeJson(sourcemapPath, {
369369
version: 3,
370370
});
371371

372-
expect(resolveSentryUploadMode(sourcemapPath)).toEqual({
372+
expect(await resolveSentryUploadMode(sourcemapPath)).toEqual({
373373
type: 'release',
374374
release: 'com.example@1.0.0+10+pushy:hash',
375375
dist: 'pushy:hash',
376376
});
377377
});
378378

379-
test('fails loudly when neither Debug ID nor explicit release is available', () => {
379+
test('fails loudly when neither Debug ID nor explicit release is available', async () => {
380380
const sourcemapPath = path.join(tempRoot, 'index.bundlejs.map');
381381
writeJson(sourcemapPath, {
382382
version: 3,
383383
});
384384

385-
expect(() => resolveSentryUploadMode(sourcemapPath)).toThrow(
385+
await expect(resolveSentryUploadMode(sourcemapPath)).rejects.toThrow(
386386
'Generated source map does not contain a Debug ID',
387387
);
388388
});
@@ -401,15 +401,15 @@ describe('prepareSentryUploadArtifacts', () => {
401401
}
402402
});
403403

404-
test('aliases Android OTA bundles to the default Android bundle name', () => {
404+
test('aliases Android OTA bundles to the default Android bundle name', async () => {
405405
_writeFile(path.join(tempRoot, 'index.bundlejs'), 'bundle');
406406
writeJson(path.join(tempRoot, 'index.bundlejs.map'), {
407407
version: 3,
408408
file: 'index.bundlejs',
409409
sources: ['src/App.tsx'],
410410
});
411411

412-
const artifacts = prepareSentryUploadArtifacts(
412+
const artifacts = await prepareSentryUploadArtifacts(
413413
'index.bundlejs',
414414
tempRoot,
415415
'android',
@@ -429,8 +429,8 @@ describe('prepareSentryUploadArtifacts', () => {
429429
});
430430
});
431431

432-
test('keeps non-Android artifacts unchanged', () => {
433-
const artifacts = prepareSentryUploadArtifacts(
432+
test('keeps non-Android artifacts unchanged', async () => {
433+
const artifacts = await prepareSentryUploadArtifacts(
434434
'index.bundlejs',
435435
tempRoot,
436436
'ios',

0 commit comments

Comments
 (0)