Skip to content

Commit e9d9dfa

Browse files
committed
Fix matching when using uids
1 parent 55b0880 commit e9d9dfa

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export async function updateAppIdentifiers(
7171
})
7272

7373
const contentIsEqual = deepCompare(dotenvFile.variables, updatedVariables)
74-
const writeToFile = !contentIsEqual && (command === 'deploy' || command === 'release')
74+
const writeToFile =
75+
!contentIsEqual &&
76+
(command === 'deploy' || command === 'release') &&
77+
!developerPlatformClient.supportsAtomicDeployments
7578
dotenvFile.variables = updatedVariables
7679

7780
if (writeToFile) {
@@ -108,9 +111,9 @@ export function getAppIdentifiers(
108111
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
109112
extensionsIdentifiers[extension.localIdentifier] = envVariables[extension.idEnvironmentVariableName]!
110113
}
111-
if (developerPlatformClient.supportsAtomicDeployments) {
112-
extensionsIdentifiers[extension.localIdentifier] = extension.uid
113-
}
114+
// if (developerPlatformClient.supportsAtomicDeployments) {
115+
// extensionsIdentifiers[extension.localIdentifier] = extension.uid
116+
// }
114117
}
115118
app.allExtensions.forEach(processExtension)
116119

packages/app/src/cli/services/context/breakdown-extensions.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,24 @@ function loadExtensionsIdentifiersBreakdown(
368368
(ext) => extensionTypeStrategy(specs, ext.specification?.identifier) === 'uuid',
369369
)
370370

371+
function moduleHasUUIDorUID(module: AppModuleVersion, identifier: string) {
372+
return module.registrationUuid === identifier || module.registrationId === identifier
373+
}
374+
371375
const extensionsToUpdate = Object.entries(localRegistration)
372-
.filter(([_identifier, uuid]) => extensionModules.map((module) => module.registrationUuid!).includes(uuid))
376+
.filter(([_identifier, uuid]) => extensionModules.some((module) => moduleHasUUIDorUID(module, uuid)))
373377
.map(([identifier, _uuid]) => identifier)
374378

375379
let extensionsToCreate = Object.entries(localRegistration)
376-
.filter(([_identifier, uuid]) => !extensionModules.map((module) => module.registrationUuid!).includes(uuid))
380+
.filter(([_identifier, uuid]) => !extensionModules.some((module) => moduleHasUUIDorUID(module, uuid)))
377381
.map(([identifier, _uuid]) => identifier)
378382
extensionsToCreate = Array.from(new Set(extensionsToCreate.concat(toCreate.map((source) => source.localIdentifier))))
379383

380384
const extensionsOnlyRemote = extensionModules
381385
.filter(
382386
(module) =>
383-
!Object.values(localRegistration).includes(module.registrationUuid!) &&
384-
!toCreate.map((source) => source.localIdentifier).includes(module.registrationUuid!),
387+
!Object.values(localRegistration).some((uuid) => moduleHasUUIDorUID(module, uuid)) &&
388+
!toCreate.map((source) => source.localIdentifier).some((identifier) => moduleHasUUIDorUID(module, identifier)),
385389
)
386390
.map((module) => module.registrationTitle)
387391

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,37 @@ function matchByNameAndType(
7272
function matchByUUID(
7373
local: LocalSource[],
7474
remote: RemoteSource[],
75+
ids: IdentifiersExtensions,
7576
): {
7677
matched: IdentifiersExtensions
7778
toCreate: LocalSource[]
7879
toConfirm: {local: LocalSource; remote: RemoteSource}[]
7980
toManualMatch: {local: LocalSource[]; remote: RemoteSource[]}
8081
} {
81-
const notMigratedRemoteExtensions = remote.filter((remoteSource) => !remoteSource.id)
82-
83-
const {matched, toCreate, toConfirm, toManualMatch} = matchByNameAndType(local, notMigratedRemoteExtensions)
82+
const matched: IdentifiersExtensions = {}
83+
const pendingLocal: LocalSource[] = []
8484

85+
// First, match by UID
8586
local.forEach((localSource) => {
86-
const possibleMatch = remote.find((remoteSource) => remoteSource.uuid === localSource.uid)
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+
})
92+
93+
// Then, match by UUID
94+
pendingLocal.forEach((localSource) => {
95+
const possibleMatch = remote.find((remoteSource) => remoteSource.uuid === ids[localSource.localIdentifier])
8796
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8897
if (possibleMatch) matched[localSource.localIdentifier] = possibleMatch.uuid!
8998
})
9099

91-
toCreate.concat(local.filter((elem) => !matched[elem.localIdentifier]))
100+
// The rest, are either to be created or deleted.
101+
// const {matched, toCreate, toConfirm, toManualMatch} = matchByNameAndType(local, notMigratedRemoteExtensions)
92102

93-
return {matched, toCreate, toConfirm, toManualMatch}
103+
const toCreate = local.filter((elem) => !matched[elem.localIdentifier])
104+
105+
return {matched, toCreate, toConfirm: [], toManualMatch: {local: [], remote: []}}
94106
}
95107

96108
function migrateLegacyFunctions(
@@ -229,7 +241,7 @@ export async function automaticMatchmaking(
229241
const {local, remote} = pendingAfterMigratingFunctions
230242

231243
const {matched, toCreate, toConfirm, toManualMatch} = useUuidMatching
232-
? matchByUUID(local, remote)
244+
? matchByUUID(localSources, remoteSources, ids)
233245
: matchByNameAndType(local, remote)
234246

235247
return {

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ export async function ensureDeploymentIdsPresence(options: EnsureDeploymentIdsPr
7070
extensionsToConfirm,
7171
)
7272

73-
// Update the matched local extensions with the remote UIDs
74-
Object.keys(extensionsToConfirm.validMatches).forEach((handle) => {
75-
const extension = options.app.allExtensions.find((ext) => ext.handle === handle)
76-
if (!extension) return
77-
extension.configuration.uid = extension.uid
78-
})
79-
8073
return {
8174
app: options.appId,
8275
extensions: result.extensions,

packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ function mapBusinessPlatformStoresToOrganizationStores(
13071307
function appModuleVersion(mod: ReleasedAppModuleFragment): Required<AppModuleVersion> {
13081308
return {
13091309
registrationId: mod.userIdentifier,
1310-
registrationUuid: mod.userIdentifier,
1310+
registrationUuid: mod.uuid,
13111311
registrationTitle: mod.handle,
13121312
type: mod.specification.externalIdentifier,
13131313
config: mod.config,

0 commit comments

Comments
 (0)