Skip to content

Commit 25baed5

Browse files
committed
Match by both type and externalType
1 parent f7a5f18 commit 25baed5

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ const REGISTRATION_D: RemoteSource = {
5959
type: 'web_pixel_extension',
6060
}
6161

62+
// Same as REGISTRATION_D but with a different type using external_identifier
63+
const REGISTRATION_D_WITH_EXTERNAL_ID: RemoteSource = {
64+
uuid: 'UUID_D',
65+
id: 'D',
66+
title: 'EXTENSION_D',
67+
type: 'web_pixel_extension_external',
68+
}
69+
6270
const REGISTRATION_FUNCTION_A: RemoteSource = {
6371
uuid: 'FUNCTION_UUID_A',
6472
id: 'FUNCTION_A',
@@ -575,6 +583,28 @@ describe('automaticMatchmaking: more remote of different types than local', () =
575583
})
576584
})
577585

586+
describe('automaticMatchmaking: same name but different remote type (but still matches)', () => {
587+
test('matches automatically', async () => {
588+
// When
589+
const got = await automaticMatchmaking(
590+
[EXTENSION_D],
591+
[REGISTRATION_D_WITH_EXTERNAL_ID],
592+
{},
593+
testDeveloperPlatformClient(),
594+
)
595+
596+
// Then
597+
const expected = {
598+
identifiers: {'extension-d': 'UUID_D'},
599+
toConfirm: [],
600+
toCreate: [],
601+
toManualMatch: {local: [], remote: []},
602+
}
603+
604+
expect(got).toEqual(expected)
605+
})
606+
})
607+
578608
describe('automaticMatchmaking: some sources have uuid, others can be matched', () => {
579609
test('matches automatically', async () => {
580610
// When

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {RemoteSource, LocalSource} from './identifiers.js'
22
import {IdentifiersExtensions} from '../../models/app/identifiers.js'
33
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
4+
import {ExtensionInstance} from '../../models/extensions/extension-instance.js'
45
import {groupBy, partition} from '@shopify/cli-kit/common/collection'
56
import {uniqBy, difference} from '@shopify/cli-kit/common/array'
67
import {pickBy} from '@shopify/cli-kit/common/object'
@@ -24,9 +25,14 @@ interface MatchResult {
2425
* Filter function to match a local and a remote source by type and handle
2526
*/
2627
const sameTypeAndName = (local: LocalSource, remote: RemoteSource) => {
27-
return (
28-
remote.type.toLowerCase() === local.graphQLType.toLowerCase() && slugify(remote.title) === slugify(local.handle)
29-
)
28+
const isSameType =
29+
remote.type.toLowerCase() === local.graphQLType.toLowerCase() ||
30+
remote.type.toLowerCase() === (local as ExtensionInstance).externalType.toLowerCase() ||
31+
remote.type.toLowerCase() === (local as ExtensionInstance).type.toLowerCase()
32+
33+
// In this case, remote.title represents the remote handle.
34+
// This needs to be cleaned up in the future in the `AppModuleVersion` transformation
35+
return isSameType && slugify(remote.title) === slugify(local.handle)
3036
}
3137

3238
/**

0 commit comments

Comments
 (0)