Skip to content
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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,10 @@ lib/
.DS_Store
# react-native-update
.update
.pushy
.pushytest-output/
test-output2/
bench.ts
bench2.ts
test-output3/
test-output4/
bench-node.js
8 changes: 4 additions & 4 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"compare-versions": "^6.1.1",
"filesize-parser": "^1.5.1",
"form-data": "^4.0.5",
"fs-extra": "8",
"fs-extra": "^11.3.5",
"global-dirs": "^4.0.0",
"gradle-to-js": "^2.0.1",
"i18next": "^26.0.4",
Expand Down
29 changes: 16 additions & 13 deletions src/bundle-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,11 @@ export async function copyDebugidForSentry(
fs.removeSync(path.join(outputFolder, `${bundleName}.txt.map`));
}

export function prepareSentryUploadArtifacts(
export async function prepareSentryUploadArtifacts(
bundleName: string,
outputFolder: string,
platform: string,
): SentryUploadArtifacts {
): Promise<SentryUploadArtifacts> {
const bundlePath = path.join(outputFolder, bundleName);
const sourcemapPath = path.join(outputFolder, `${bundleName}.map`);

Expand All @@ -616,26 +616,26 @@ export function prepareSentryUploadArtifacts(
outputFolder,
`${ANDROID_SENTRY_BUNDLE_NAME}.map`,
);
fs.copyFileSync(bundlePath, androidBundlePath);
await fs.promises.copyFile(bundlePath, androidBundlePath);

const sourcemap = JSON.parse(
fs.readFileSync(sourcemapPath, 'utf8'),
await fs.promises.readFile(sourcemapPath, 'utf8'),
) as Record<string, unknown>;
sourcemap.file = ANDROID_SENTRY_BUNDLE_NAME;
fs.writeFileSync(androidSourcemapPath, JSON.stringify(sourcemap));
await fs.promises.writeFile(androidSourcemapPath, JSON.stringify(sourcemap));

return {
bundlePath: androidBundlePath,
sourcemapPath: androidSourcemapPath,
};
}

export function readSourcemapDebugId(
export async function readSourcemapDebugId(
sourcemapPath: string,
): string | undefined {
): Promise<string | undefined> {
try {
const sourcemap = JSON.parse(
fs.readFileSync(sourcemapPath, 'utf8'),
await fs.promises.readFile(sourcemapPath, 'utf8'),
) as Record<string, unknown>;
const debugId = sourcemap.debugId ?? sourcemap.debug_id;
return typeof debugId === 'string' ? normalizeString(debugId) : undefined;
Expand All @@ -658,10 +658,10 @@ function resolveSentryReleaseFromValues(
};
}

export function resolveSentryUploadMode(
export async function resolveSentryUploadMode(
sourcemapPath: string,
options: SentryUploadOptions = {},
): SentryUploadMode {
): Promise<SentryUploadMode> {
const optionRelease = resolveSentryReleaseFromValues(
options.sentryRelease,
options.sentryDist,
Expand All @@ -673,7 +673,7 @@ export function resolveSentryUploadMode(
};
}

const debugId = readSourcemapDebugId(sourcemapPath);
const debugId = await readSourcemapDebugId(sourcemapPath);
if (debugId) {
return {
type: 'debug-id',
Expand Down Expand Up @@ -848,12 +848,15 @@ export async function uploadSourcemapForSentry(
return;
}

const { bundlePath, sourcemapPath } = prepareSentryUploadArtifacts(
const { bundlePath, sourcemapPath } = await prepareSentryUploadArtifacts(
bundleName,
outputFolder,
platform,
);
const uploadMode = resolveSentryUploadMode(sourcemapPath, sentryOptions);
const uploadMode = await resolveSentryUploadMode(
sourcemapPath,
sentryOptions,
);
const useStandaloneSourcemapsCommand =
supportsStandaloneSentrySourcemapsUpload(sentryCliPath);

Expand Down
32 changes: 16 additions & 16 deletions tests/bundle-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,40 +299,40 @@ describe('Sentry Debug ID upload mode', () => {
}
});

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

expect(readSourcemapDebugId(sourcemapPath)).toBe(
expect(await readSourcemapDebugId(sourcemapPath)).toBe(
'85314830-023f-4cf1-a267-535f4e37bb17',
);
});

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

expect(resolveSentryUploadMode(sourcemapPath)).toEqual({
expect(await resolveSentryUploadMode(sourcemapPath)).toEqual({
type: 'debug-id',
debugId: '85314830-023f-4cf1-a267-535f4e37bb17',
});
});

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

expect(
resolveSentryUploadMode(sourcemapPath, {
await resolveSentryUploadMode(sourcemapPath, {
sentryRelease: 'com.example@1.0.0+10+pushy:4.1',
sentryDist: 'pushy:4.1',
}),
Expand All @@ -343,14 +343,14 @@ describe('Sentry Debug ID upload mode', () => {
});
});

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

expect(
resolveSentryUploadMode(sourcemapPath, {
await resolveSentryUploadMode(sourcemapPath, {
sentryRelease: 'com.example@1.0.0+10+pushy:hash',
sentryDist: 'pushy:hash',
}),
Expand All @@ -361,28 +361,28 @@ describe('Sentry Debug ID upload mode', () => {
});
});

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

expect(resolveSentryUploadMode(sourcemapPath)).toEqual({
expect(await resolveSentryUploadMode(sourcemapPath)).toEqual({
type: 'release',
release: 'com.example@1.0.0+10+pushy:hash',
dist: 'pushy:hash',
});
});

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

expect(() => resolveSentryUploadMode(sourcemapPath)).toThrow(
await expect(resolveSentryUploadMode(sourcemapPath)).rejects.toThrow(
'Generated source map does not contain a Debug ID',
);
});
Expand All @@ -401,15 +401,15 @@ describe('prepareSentryUploadArtifacts', () => {
}
});

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

const artifacts = prepareSentryUploadArtifacts(
const artifacts = await prepareSentryUploadArtifacts(
'index.bundlejs',
tempRoot,
'android',
Expand All @@ -429,8 +429,8 @@ describe('prepareSentryUploadArtifacts', () => {
});
});

test('keeps non-Android artifacts unchanged', () => {
const artifacts = prepareSentryUploadArtifacts(
test('keeps non-Android artifacts unchanged', async () => {
const artifacts = await prepareSentryUploadArtifacts(
'index.bundlejs',
tempRoot,
'ios',
Expand Down