Skip to content

Commit 73c7be2

Browse files
authored
Merge pull request #6274 from Shopify/08-14-refactor-writeManifestToBundle
Simplify writeManifestToBundle by not re-creating the manifest
2 parents ed5bfbe + 952470a commit 73c7be2

File tree

6 files changed

+76
-47
lines changed

6 files changed

+76
-47
lines changed

packages/app/src/cli/services/bundle.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ describe('writeManifestToBundle', () => {
2424
manifest: async () => manifestContent,
2525
} as unknown as AppInterface
2626

27+
const appManifest = await mockApp.manifest(undefined)
28+
2729
// When
28-
await writeManifestToBundle(mockApp, tmpDir, undefined)
30+
await writeManifestToBundle(appManifest, tmpDir)
2931

3032
// Then
3133
const manifestPath = joinPath(tmpDir, 'manifest.json')

packages/app/src/cli/services/bundle.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
// import {AppInterface} from '../models/app/app.js'
2-
import {AppInterface} from '../models/app/app.js'
2+
import {AppManifest} from '../models/app/app.js'
33
import {AssetUrlSchema, DeveloperPlatformClient} from '../utilities/developer-platform-client.js'
44
import {MinimalAppIdentifiers} from '../models/organization.js'
5-
import {Identifiers} from '../models/app/identifiers.js'
65
import {joinPath} from '@shopify/cli-kit/node/path'
76
import {brotliCompress, zip} from '@shopify/cli-kit/node/archiver'
87
import {formData, fetch} from '@shopify/cli-kit/node/http'
98
import {readFileSync} from '@shopify/cli-kit/node/fs'
109
import {AbortError} from '@shopify/cli-kit/node/error'
1110
import {writeFile} from 'fs/promises'
1211

13-
export async function writeManifestToBundle(
14-
app: AppInterface,
15-
bundlePath: string,
16-
identifiers: Identifiers | undefined,
17-
) {
18-
const appManifest = await app.manifest(identifiers)
12+
export async function writeManifestToBundle(appManifest: AppManifest, bundlePath: string) {
1913
const manifestPath = joinPath(bundlePath, 'manifest.json')
2014
await writeFile(manifestPath, JSON.stringify(appManifest, null, 2))
2115
}

packages/app/src/cli/services/deploy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export async function deploy(options: DeployOptions) {
211211

212212
await bundleAndBuildExtensions({
213213
app,
214+
appManifest,
214215
bundlePath,
215216
identifiers,
216217
skipBuild: options.skipBuild,

packages/app/src/cli/services/deploy/bundle.test.ts

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {bundleAndBuildExtensions} from './bundle.js'
22
import {testApp, testFunctionExtension, testThemeExtensions, testUIExtension} from '../../models/app/app.test-data.js'
3-
import {AppInterface} from '../../models/app/app.js'
3+
import {AppInterface, AppManifest} from '../../models/app/app.js'
44
import * as bundle from '../bundle.js'
55
import * as functionBuild from '../function/build.js'
66
import {describe, expect, test, vi} from 'vitest'
@@ -11,6 +11,7 @@ vi.mock('../function/build.js')
1111

1212
describe('bundleAndBuildExtensions', () => {
1313
let app: AppInterface
14+
let appManifest: AppManifest
1415

1516
test('generates a manifest.json', async () => {
1617
await file.inTemporaryDirectory(async (tmpDir: string) => {
@@ -36,39 +37,21 @@ describe('bundleAndBuildExtensions', () => {
3637
extensionIds: {},
3738
extensionsNonUuidManaged: {},
3839
}
39-
const expectedManifest = {
40-
name: 'App',
41-
handle: '',
42-
modules: [
43-
{
44-
type: 'web_pixel_extension_external',
45-
handle: 'test-ui-extension',
46-
uid: 'test-ui-extension-uid',
47-
assets: 'test-ui-extension-uid',
48-
target: '',
49-
config: {},
50-
},
51-
{
52-
type: 'theme_external',
53-
handle: 'theme-extension-name',
54-
uid: themeExtension.uid,
55-
assets: themeExtension.uid,
56-
target: '',
57-
config: {
58-
theme_extension: {
59-
files: {},
60-
},
61-
},
62-
},
63-
],
64-
}
40+
appManifest = await app.manifest(identifiers)
6541

6642
// When
67-
await bundleAndBuildExtensions({app, identifiers, bundlePath, skipBuild: false, isDevDashboardApp: false})
43+
await bundleAndBuildExtensions({
44+
app,
45+
appManifest,
46+
identifiers,
47+
bundlePath,
48+
skipBuild: false,
49+
isDevDashboardApp: false,
50+
})
6851

6952
// Then
7053
expect(extensionBundleMock).toHaveBeenCalledTimes(2)
71-
expect(bundle.writeManifestToBundle).toHaveBeenCalledWith(app, bundleDirectory, identifiers)
54+
expect(bundle.writeManifestToBundle).toHaveBeenCalledWith(appManifest, bundleDirectory)
7255

7356
await expect(file.fileExists(bundlePath)).resolves.toBeTruthy()
7457
})
@@ -96,9 +79,17 @@ describe('bundleAndBuildExtensions', () => {
9679
extensionIds: {},
9780
extensionsNonUuidManaged: {},
9881
}
82+
appManifest = await app.manifest(identifiers)
9983

10084
// When
101-
await bundleAndBuildExtensions({app, identifiers, bundlePath, skipBuild: false, isDevDashboardApp: false})
85+
await bundleAndBuildExtensions({
86+
app,
87+
appManifest,
88+
identifiers,
89+
bundlePath,
90+
skipBuild: false,
91+
isDevDashboardApp: false,
92+
})
10293

10394
// Then
10495
await expect(file.fileExists(bundlePath)).resolves.toBeTruthy()
@@ -129,9 +120,17 @@ describe('bundleAndBuildExtensions', () => {
129120
extensionIds: {},
130121
extensionsNonUuidManaged: {},
131122
}
123+
appManifest = await app.manifest(identifiers)
132124

133125
// When
134-
await bundleAndBuildExtensions({app, identifiers, bundlePath, skipBuild: true, isDevDashboardApp: false})
126+
await bundleAndBuildExtensions({
127+
app,
128+
appManifest,
129+
identifiers,
130+
bundlePath,
131+
skipBuild: true,
132+
isDevDashboardApp: false,
133+
})
135134

136135
// Then
137136
expect(extensionBuildMock).not.toHaveBeenCalled()
@@ -159,9 +158,17 @@ describe('bundleAndBuildExtensions', () => {
159158
extensionIds: {},
160159
extensionsNonUuidManaged: {},
161160
}
161+
appManifest = await app.manifest(identifiers)
162162

163163
// When
164-
await bundleAndBuildExtensions({app, identifiers, bundlePath, skipBuild: true, isDevDashboardApp: false})
164+
await bundleAndBuildExtensions({
165+
app,
166+
appManifest,
167+
identifiers,
168+
bundlePath,
169+
skipBuild: true,
170+
isDevDashboardApp: false,
171+
})
165172

166173
// Then
167174
expect(mockInstallJavy).not.toHaveBeenCalled()
@@ -187,9 +194,17 @@ describe('bundleAndBuildExtensions', () => {
187194
extensionIds: {},
188195
extensionsNonUuidManaged: {},
189196
}
197+
appManifest = await app.manifest(identifiers)
190198

191199
// When
192-
await bundleAndBuildExtensions({app, identifiers, bundlePath, skipBuild: false, isDevDashboardApp: false})
200+
await bundleAndBuildExtensions({
201+
app,
202+
appManifest,
203+
identifiers,
204+
bundlePath,
205+
skipBuild: false,
206+
isDevDashboardApp: false,
207+
})
193208

194209
// Then
195210
expect(mockInstallJavy).toHaveBeenCalledWith(app)
@@ -220,9 +235,17 @@ describe('bundleAndBuildExtensions', () => {
220235
extensionIds: {},
221236
extensionsNonUuidManaged: {},
222237
}
238+
appManifest = await app.manifest(identifiers)
223239

224240
// When
225-
await bundleAndBuildExtensions({app, identifiers, bundlePath, skipBuild: true, isDevDashboardApp: false})
241+
await bundleAndBuildExtensions({
242+
app,
243+
appManifest,
244+
identifiers,
245+
bundlePath,
246+
skipBuild: true,
247+
isDevDashboardApp: false,
248+
})
226249

227250
// Then
228251
expect(extensionBuildMock).not.toHaveBeenCalled()
@@ -280,9 +303,17 @@ describe('bundleAndBuildExtensions', () => {
280303
extensionIds: {},
281304
extensionsNonUuidManaged: {},
282305
}
306+
appManifest = await app.manifest(identifiers)
283307

284308
// When
285-
await bundleAndBuildExtensions({app, identifiers, bundlePath, skipBuild: true, isDevDashboardApp: false})
309+
await bundleAndBuildExtensions({
310+
app,
311+
appManifest,
312+
identifiers,
313+
bundlePath,
314+
skipBuild: true,
315+
isDevDashboardApp: false,
316+
})
286317

287318
// Then - verify none of the build methods were called
288319
expect(functionBuildMock).not.toHaveBeenCalled()

packages/app/src/cli/services/deploy/bundle.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {AppInterface} from '../../models/app/app.js'
1+
import {AppInterface, AppManifest} from '../../models/app/app.js'
22
import {Identifiers} from '../../models/app/identifiers.js'
33
import {installJavy} from '../function/build.js'
44
import {compressBundle, writeManifestToBundle} from '../bundle.js'
@@ -10,6 +10,7 @@ import {Writable} from 'stream'
1010

1111
interface BundleOptions {
1212
app: AppInterface
13+
appManifest: AppManifest
1314
bundlePath?: string
1415
identifiers?: Identifiers
1516
skipBuild: boolean
@@ -21,7 +22,7 @@ export async function bundleAndBuildExtensions(options: BundleOptions) {
2122
await rmdir(bundleDirectory, {force: true})
2223
await mkdir(bundleDirectory)
2324

24-
await writeManifestToBundle(options.app, bundleDirectory, options.identifiers)
25+
await writeManifestToBundle(options.appManifest, bundleDirectory)
2526

2627
// Force the download of the javy binary in advance to avoid later problems,
2728
// as it might be done multiple times in parallel. https://github.com/Shopify/cli/issues/2877

packages/app/src/cli/services/dev/processes/dev-session/dev-session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class DevSession {
333333
if (this.statusManager.status.isReady) {
334334
appManifest.modules = appManifest.modules.filter((module) => updatedUids.includes(module.uid))
335335
} else {
336-
await writeManifestToBundle(appEvent.app, this.bundlePath, undefined)
336+
await writeManifestToBundle(appManifest, this.bundlePath)
337337
}
338338

339339
const existingDirs = await readdir(this.bundlePath)

0 commit comments

Comments
 (0)