Skip to content

Commit 7a09ce3

Browse files
committed
Some cleanup
1 parent e9d9dfa commit 7a09ce3

File tree

9 files changed

+37
-66
lines changed

9 files changed

+37
-66
lines changed

packages/app/src/cli/models/app/app.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,12 @@ describe('manifest', () => {
616616
})
617617

618618
// When
619-
const manifest = await app.manifest()
619+
const manifest = await app.manifest({
620+
app: 'API_KEY',
621+
extensions: {app_access: 'UUID_A'},
622+
extensionIds: {},
623+
extensionsNonUuidManaged: {},
624+
})
620625

621626
// Then
622627
expect(manifest).toEqual({
@@ -627,6 +632,7 @@ describe('manifest', () => {
627632
type: 'app_access_external',
628633
handle: 'app_access',
629634
uid: appAccessModule.uid,
635+
uuid: 'UUID_A',
630636
assets: appAccessModule.uid,
631637
target: appAccessModule.contextValue,
632638
config: expect.objectContaining({
@@ -664,7 +670,7 @@ describe('manifest', () => {
664670
})
665671

666672
// When
667-
const manifest = await app.manifest()
673+
const manifest = await app.manifest(undefined)
668674

669675
// Then
670676
expect(manifest).toEqual({
@@ -722,7 +728,7 @@ describe('manifest', () => {
722728
})
723729

724730
// When
725-
const manifest = await app.manifest()
731+
const manifest = await app.manifest(undefined)
726732

727733
// Then
728734
expect(manifest).toEqual({

packages/app/src/cli/models/app/identifiers.test.ts

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,9 @@ describe('getAppIdentifiers', () => {
208208
})
209209

210210
// When
211-
const got = getAppIdentifiers(
212-
{
213-
app,
214-
},
215-
testDeveloperPlatformClient(),
216-
)
211+
const got = getAppIdentifiers({
212+
app,
213+
})
217214

218215
// Then
219216
expect(got.app).toEqual('FOO')
@@ -238,7 +235,6 @@ describe('getAppIdentifiers', () => {
238235
{
239236
app,
240237
},
241-
testDeveloperPlatformClient(),
242238
{SHOPIFY_API_KEY: 'FOO', SHOPIFY_TEST_UI_EXTENSION_ID: 'BAR'},
243239
)
244240

@@ -247,34 +243,4 @@ describe('getAppIdentifiers', () => {
247243
expect((got.extensions ?? {})['test-ui-extension']).toEqual('BAR')
248244
})
249245
})
250-
251-
test('returns the UIDs when Atomic Deployments is enabled', async () => {
252-
await inTemporaryDirectory(async (tmpDir: string) => {
253-
// Given
254-
const uiExtension = await testUIExtension({
255-
directory: '/tmp/project/extensions/my-extension',
256-
idEnvironmentVariableName: 'SHOPIFY_MY_EXTENSION_ID',
257-
})
258-
const app = testApp({
259-
directory: tmpDir,
260-
dotenv: {
261-
path: joinPath(tmpDir, '.env'),
262-
variables: {SHOPIFY_API_KEY: 'FOO', SHOPIFY_TEST_UI_EXTENSION_ID: 'BAR'},
263-
},
264-
allExtensions: [uiExtension],
265-
})
266-
267-
// When
268-
const got = getAppIdentifiers(
269-
{
270-
app,
271-
},
272-
testDeveloperPlatformClient({supportsAtomicDeployments: true}),
273-
)
274-
275-
// Then
276-
expect(got.app).toEqual('FOO')
277-
expect((got.extensions ?? {})['test-ui-extension']).toEqual(uiExtension.uid)
278-
})
279-
})
280246
})

packages/app/src/cli/models/app/identifiers.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ interface GetAppIdentifiersOptions {
9898
*/
9999
export function getAppIdentifiers(
100100
{app}: GetAppIdentifiersOptions,
101-
developerPlatformClient: DeveloperPlatformClient,
102101
systemEnvironment = process.env,
103102
): Partial<UuidOnlyIdentifiers> {
104103
const envVariables = {
@@ -111,9 +110,6 @@ export function getAppIdentifiers(
111110
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
112111
extensionsIdentifiers[extension.localIdentifier] = envVariables[extension.idEnvironmentVariableName]!
113112
}
114-
// if (developerPlatformClient.supportsAtomicDeployments) {
115-
// extensionsIdentifiers[extension.localIdentifier] = extension.uid
116-
// }
117113
}
118114
app.allExtensions.forEach(processExtension)
119115

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('writeManifestToBundle', () => {
2525
} as unknown as AppInterface
2626

2727
// When
28-
await writeManifestToBundle(mockApp, tmpDir)
28+
await writeManifestToBundle(mockApp, tmpDir, undefined)
2929

3030
// Then
3131
const manifestPath = joinPath(tmpDir, 'manifest.json')

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export async function ensureDeployContext(options: DeployOptions): Promise<Ident
153153
force,
154154
release: !noRelease,
155155
developerPlatformClient,
156-
envIdentifiers: getAppIdentifiers({app}, developerPlatformClient),
156+
envIdentifiers: getAppIdentifiers({app}),
157157
remoteApp,
158158
activeAppVersion,
159159
})

packages/app/src/cli/services/context/id-matching.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ describe('automaticMatchmaking: with Atomic Deployments enabled', () => {
781781
const got = await automaticMatchmaking(
782782
[EXTENSION_A, EXTENSION_A_2],
783783
[REGISTRATION_A],
784-
{},
784+
{'extension-a': 'UUID_A'},
785785
testDeveloperPlatformClient({supportsAtomicDeployments: true}),
786786
)
787787

@@ -792,6 +792,7 @@ describe('automaticMatchmaking: with Atomic Deployments enabled', () => {
792792
toCreate: [EXTENSION_A_2],
793793
toManualMatch: {local: [], remote: []},
794794
}
795+
795796
expect(got).toEqual(expected)
796797
})
797798
})

packages/app/src/cli/services/context/id-matching.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function matchByNameAndType(
6969
/**
7070
* Automatically match local and remote sources if they have the same UID
7171
*/
72-
function matchByUUID(
72+
function matchByUIDandUUID(
7373
local: LocalSource[],
7474
remote: RemoteSource[],
7575
ids: IdentifiersExtensions,
@@ -82,27 +82,29 @@ function matchByUUID(
8282
const matched: IdentifiersExtensions = {}
8383
const pendingLocal: LocalSource[] = []
8484

85-
// First, match by UID
85+
// First, try to match by UID, then by UUID.
8686
local.forEach((localSource) => {
87-
const possibleMatch = remote.find((remoteSource) => remoteSource.id === localSource.uid)
88-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
89-
if (possibleMatch) matched[localSource.localIdentifier] = possibleMatch.id!
90-
else pendingLocal.push(localSource)
91-
})
87+
const matchByUID = remote.find((remoteSource) => remoteSource.id === localSource.uid)
88+
const matchByUUID = remote.find((remoteSource) => remoteSource.uuid === ids[localSource.localIdentifier])
9289

93-
// Then, match by UUID
94-
pendingLocal.forEach((localSource) => {
95-
const possibleMatch = remote.find((remoteSource) => remoteSource.uuid === ids[localSource.localIdentifier])
96-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
97-
if (possibleMatch) matched[localSource.localIdentifier] = possibleMatch.uuid!
90+
if (matchByUID) {
91+
matched[localSource.localIdentifier] = matchByUID.id
92+
} else if (matchByUUID) {
93+
matched[localSource.localIdentifier] = matchByUUID.uuid
94+
} else {
95+
pendingLocal.push(localSource)
96+
}
9897
})
9998

100-
// The rest, are either to be created or deleted.
101-
// const {matched, toCreate, toConfirm, toManualMatch} = matchByNameAndType(local, notMigratedRemoteExtensions)
99+
const pendingRemote = remote.filter(
100+
(remoteSource) =>
101+
!Object.values(matched).includes(remoteSource.uuid) && !Object.values(matched).includes(remoteSource.id),
102+
)
102103

103-
const toCreate = local.filter((elem) => !matched[elem.localIdentifier])
104+
// Then, try to match by name and type as a last resort.
105+
const {matched: matchedByName, toCreate, toConfirm, toManualMatch} = matchByNameAndType(pendingLocal, pendingRemote)
104106

105-
return {matched, toCreate, toConfirm: [], toManualMatch: {local: [], remote: []}}
107+
return {matched: {...matched, ...matchedByName}, toCreate, toConfirm, toManualMatch}
106108
}
107109

108110
function migrateLegacyFunctions(
@@ -241,7 +243,7 @@ export async function automaticMatchmaking(
241243
const {local, remote} = pendingAfterMigratingFunctions
242244

243245
const {matched, toCreate, toConfirm, toManualMatch} = useUuidMatching
244-
? matchByUUID(localSources, remoteSources, ids)
246+
? matchByUIDandUUID(localSources, remoteSources, ids)
245247
: matchByNameAndType(local, remote)
246248

247249
return {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('bundleAndBuildExtensions', () => {
6868

6969
// Then
7070
expect(extensionBundleMock).toHaveBeenCalledTimes(2)
71-
expect(bundle.writeManifestToBundle).toHaveBeenCalledWith(app, bundleDirectory)
71+
expect(bundle.writeManifestToBundle).toHaveBeenCalledWith(app, bundleDirectory, identifiers)
7272

7373
await expect(file.fileExists(bundlePath)).resolves.toBeTruthy()
7474
})

packages/app/src/cli/services/dev/processes/draftable-extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export async function setupDraftableExtensionsProcess({
7777
return
7878
}
7979

80-
const prodEnvIdentifiers = getAppIdentifiers({app: localApp}, developerPlatformClient)
80+
const prodEnvIdentifiers = getAppIdentifiers({app: localApp})
8181

8282
const {extensionIds: remoteExtensionIds, extensions: extensionsUuids} = await ensureDeploymentIdsPresence({
8383
app: localApp,

0 commit comments

Comments
 (0)