Skip to content

Commit d5c6a28

Browse files
committed
Address review: explicit platform branch, channel check first, safe zip.close
1 parent 9468f39 commit d5c6a28

2 files changed

Lines changed: 43 additions & 7 deletions

File tree

packages/build-tools/src/utils/__tests__/expoUpdatesEmbedded.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('uploadEmbeddedBundleAsync', () => {
8888
expect(artifacts.findArtifacts).not.toHaveBeenCalled();
8989
});
9090

91-
it('warns when no channel is configured', async () => {
91+
it('warns when no channel is configured and does not look for the archive', async () => {
9292
const ctx = makeCtx({ platform: Platform.ANDROID });
9393

9494
await uploadEmbeddedBundleAsync(ctx);
@@ -97,6 +97,17 @@ describe('uploadEmbeddedBundleAsync', () => {
9797
'Skipping embedded bundle upload: no channel configured for this build profile.'
9898
);
9999
expect(ctx.markBuildPhaseHasWarnings).toHaveBeenCalled();
100+
expect(artifacts.findArtifacts).not.toHaveBeenCalled();
101+
});
102+
103+
it('throws for an unsupported platform', async () => {
104+
const ctx = makeCtx({ platform: Platform.ANDROID, channel: 'production' });
105+
(ctx.job as { platform: string }).platform = 'web';
106+
107+
await expect(uploadEmbeddedBundleAsync(ctx)).rejects.toThrow(
108+
'Uploading embedded updates is not supported for the web platform.'
109+
);
110+
expect(artifacts.findArtifacts).not.toHaveBeenCalled();
100111
});
101112

102113
it('uploads from Android APK archives', async () => {
@@ -243,4 +254,20 @@ describe('uploadEmbeddedBundleAsync', () => {
243254
);
244255
expect(ctx.markBuildPhaseHasWarnings).toHaveBeenCalled();
245256
});
257+
258+
it('swallows zip.close() failures so they do not mask the upload result', async () => {
259+
jest.mocked(artifacts.findArtifacts).mockResolvedValue(['/tmp/app-release.apk']);
260+
mockZipEntries.mockResolvedValue(
261+
zipEntryMap({
262+
'assets/index.android.bundle': true,
263+
'assets/app.manifest': true,
264+
})
265+
);
266+
mockZipClose.mockRejectedValue(new Error('close failed'));
267+
const ctx = makeCtx({ platform: Platform.ANDROID, channel: 'production' });
268+
269+
await expect(uploadEmbeddedBundleAsync(ctx)).resolves.toBeUndefined();
270+
expect(easCli.runEasCliCommand).toHaveBeenCalled();
271+
expect(mockZipClose).toHaveBeenCalled();
272+
});
246273
});

packages/build-tools/src/utils/expoUpdatesEmbedded.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Android, BuildJob, Ios, Platform } from '@expo/eas-build-job';
22
import { PipeMode } from '@expo/logger';
3+
import { asyncResult } from '@expo/results';
34
import fs from 'fs-extra';
45
import os from 'os';
56
import path from 'path';
@@ -24,15 +25,25 @@ export async function uploadEmbeddedBundleAsync(ctx: BuildContext<BuildJob>): Pr
2425
}
2526

2627
const channel = ctx.job.updates?.channel;
28+
if (!channel) {
29+
ctx.logger.warn(
30+
'Skipping embedded bundle upload: no channel configured for this build profile.'
31+
);
32+
ctx.markBuildPhaseHasWarnings();
33+
return;
34+
}
35+
2736
const projectDir = ctx.getReactNativeProjectDirectory();
2837

2938
let archivePattern: string;
3039
if (platform === Platform.IOS) {
3140
archivePattern = resolveArtifactPath(ctx as BuildContext<Ios.Job>);
32-
} else {
41+
} else if (platform === Platform.ANDROID) {
3342
archivePattern =
3443
(ctx as BuildContext<Android.Job>).job.applicationArchivePath ??
3544
'android/app/build/outputs/**/*.{apk,aab}';
45+
} else {
46+
throw new Error(`Uploading embedded updates is not supported for the ${platform} platform.`);
3647
}
3748

3849
const [archivePath] = await findArtifacts({
@@ -41,10 +52,8 @@ export async function uploadEmbeddedBundleAsync(ctx: BuildContext<BuildJob>): Pr
4152
logger: null,
4253
}).catch(() => [] as string[]);
4354

44-
if (!channel || !archivePath) {
45-
ctx.logger.warn(
46-
`Skipping embedded bundle upload: ${!channel ? 'no channel configured for this build profile' : 'build archive not found'}.`
47-
);
55+
if (!archivePath) {
56+
ctx.logger.warn('Skipping embedded bundle upload: build archive not found.');
4857
ctx.markBuildPhaseHasWarnings();
4958
return;
5059
}
@@ -104,6 +113,6 @@ export async function uploadEmbeddedBundleAsync(ctx: BuildContext<BuildJob>): Pr
104113
ctx.logger.warn({ err }, 'Failed to upload embedded bundle.');
105114
ctx.markBuildPhaseHasWarnings();
106115
} finally {
107-
await zip.close();
116+
await asyncResult(zip.close());
108117
}
109118
}

0 commit comments

Comments
 (0)