Skip to content

Commit

Permalink
Update UID locally when the extension exists in the server
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloriestra committed Nov 25, 2024
1 parent 8d41ba3 commit 32ee3ef
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 17 deletions.
3 changes: 2 additions & 1 deletion packages/app/src/cli/models/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ export class App<
type: module.externalType,
handle: module.handle,
uid: module.uid,
uuid: identifiers?.extensions[module.localIdentifier] ?? undefined,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
uuid: identifiers?.extensions[module.localIdentifier] || undefined,
assets: module.configuration.uid ?? module.handle,
target: module.contextValue,
config: (config ?? {}) as JsonMapType,
Expand Down
5 changes: 4 additions & 1 deletion packages/app/src/cli/models/app/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export async function updateAppIdentifiers(
})

const contentIsEqual = deepCompare(dotenvFile.variables, updatedVariables)
const writeToFile = !contentIsEqual && (command === 'deploy' || command === 'release')
const writeToFile =
!contentIsEqual &&
(command === 'deploy' || command === 'release') &&
!developerPlatformClient.supportsAtomicDeployments
dotenvFile.variables = updatedVariables

if (writeToFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('patchAppConfigurationFile', () => {
},
}

await patchAppConfigurationFile({path: configPath, patch, schema})
patchAppConfigurationFile({path: configPath, patch, schema})

const updatedTomlFile = await readFile(configPath)
expect(updatedTomlFile)
Expand Down Expand Up @@ -85,7 +85,7 @@ api_version = "2023-04"
},
}

await patchAppConfigurationFile({path: configPath, patch, schema})
patchAppConfigurationFile({path: configPath, patch, schema})

const updatedTomlFile = await readFile(configPath)
expect(updatedTomlFile)
Expand Down Expand Up @@ -125,7 +125,7 @@ dev_store_url = "example.myshopify.com"
},
}

await patchAppConfigurationFile({path: configPath, patch, schema})
patchAppConfigurationFile({path: configPath, patch, schema})

const updatedTomlFile = await readFile(configPath)
expect(updatedTomlFile)
Expand Down Expand Up @@ -164,7 +164,7 @@ random_toml_field = "random_value"
)
const patch = {name: 123}

await patchAppConfigurationFile({path: configPath, patch, schema: undefined})
patchAppConfigurationFile({path: configPath, patch, schema: undefined})

const updatedTomlFile = await readFile(configPath)
expect(updatedTomlFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {addDefaultCommentsToToml} from './write-app-configuration-file.js'
import {deepMergeObjects} from '@shopify/cli-kit/common/object'
import {readFile, writeFile} from '@shopify/cli-kit/node/fs'
import {readFileSync} from '@shopify/cli-kit/node/fs'
import {zod} from '@shopify/cli-kit/node/schema'
import {decodeToml, encodeToml} from '@shopify/cli-kit/node/toml'
import {writeFileSync} from 'fs'

export interface PatchTomlOptions {
path: string
Expand All @@ -22,8 +23,8 @@ export interface PatchTomlOptions {
* @param patch - The patch to apply to the app configuration file.
* @param schema - The schema to validate the patch against. If not provided, the toml will not be validated.
*/
export async function patchAppConfigurationFile({path, patch, schema}: PatchTomlOptions) {
const tomlContents = await readFile(path)
export function patchAppConfigurationFile({path, patch, schema}: PatchTomlOptions) {
const tomlContents = readFileSync(path).toString()
const configuration = decodeToml(tomlContents)

// Deep merge the configuration with the patch.
Expand All @@ -37,7 +38,7 @@ export async function patchAppConfigurationFile({path, patch, schema}: PatchToml

let encodedString = encodeToml(updatedConfig)
encodedString = addDefaultCommentsToToml(encodedString)
await writeFile(path, encodedString)
writeFileSync(path, encodedString)
}

export function replaceArrayStrategy(_: unknown[], newArray: unknown[]): unknown[] {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/cli/services/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async function removeIncludeConfigOnDeployField(localApp: AppInterface) {
if (includeConfigOnDeploy === undefined) return

const patch = {build: {include_config_on_deploy: undefined}}
await patchAppConfigurationFile({path: localApp.configuration.path, patch, schema: localApp.configSchema})
patchAppConfigurationFile({path: localApp.configuration.path, patch, schema: localApp.configSchema})

includeConfigOnDeploy ? renderInfoAboutIncludeConfigOnDeploy() : renderWarningAboutIncludeConfigOnDeploy()
}
Expand Down Expand Up @@ -219,7 +219,7 @@ async function promptIncludeConfigOnDeploy(options: ShouldOrPromptIncludeConfigD
include_config_on_deploy: shouldIncludeConfigDeploy,
}
const patch = {build: {include_config_on_deploy: shouldIncludeConfigDeploy}}
await patchAppConfigurationFile({path: localConfiguration.path, patch, schema: options.localApp.configSchema})
patchAppConfigurationFile({path: localConfiguration.path, patch, schema: options.localApp.configSchema})
await metadata.addPublicMetadata(() => ({cmd_deploy_confirm_include_config_used: shouldIncludeConfigDeploy}))
}

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/cli/services/context/id-matching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function matchByNameAndType(
if (possibleMatch) matched[localSource.localIdentifier] = possibleMatch.uuid
})

const pendingLocal = local.filter((elem) => !matched[elem.localIdentifier])
const pendingLocal = local.filter((elem) => matched[elem.localIdentifier] === undefined)
const pendingRemote = remote.filter((registration) => !Object.values(matched).includes(registration.uuid))

// Now we try to find a match between a local source and remote one if they have
Expand Down
11 changes: 11 additions & 0 deletions packages/app/src/cli/services/context/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {MinimalOrganizationApp} from '../../models/organization.js'
import {deployOrReleaseConfirmationPrompt} from '../../prompts/deploy-release.js'
import {AppVersion, DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {AbortSilentError} from '@shopify/cli-kit/node/error'
import {randomUUID} from '@shopify/cli-kit/node/crypto'

export type PartnersAppForIdentifierMatching = MinimalOrganizationApp

Expand Down Expand Up @@ -70,6 +71,16 @@ export async function ensureDeploymentIdsPresence(options: EnsureDeploymentIdsPr
extensionsToConfirm,
)

// Update the matched local extensions with the remote UIDs
Object.keys(extensionsToConfirm.validMatches).forEach((handle) => {
const extension = options.app.allExtensions.find((ext) => ext.handle === handle)
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const uid = extensionsToConfirm.validMatches[handle] || randomUUID()
if (!extension || !uid) return
extension.uid = uid
extension.configuration.uid = uid
})

return {
app: options.appId,
extensions: result.extensions,
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/cli/services/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async function prepareForDev(commandOptions: DevOptions): Promise<DevConfig> {
dev_store_url: store.shopDomain,
}
const patch = {build: {dev_store_url: store.shopDomain}}
await patchAppConfigurationFile({path: app.configuration.path, patch, schema: app.configSchema})
patchAppConfigurationFile({path: app.configuration.path, patch, schema: app.configSchema})
}

if (!commandOptions.skipDependenciesInstallation && !app.usesWorkspaces) {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/cli/services/dev/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export async function updateURLs(
: {}),
}

await patchAppConfigurationFile({path: localApp.configuration.path, patch, schema: localApp.configSchema})
patchAppConfigurationFile({path: localApp.configuration.path, patch, schema: localApp.configSchema})
}
}

Expand Down Expand Up @@ -266,7 +266,7 @@ export async function shouldOrPromptUpdateURLs(options: ShouldOrPromptUpdateURLs
}
const patch = {build: {automatically_update_urls_on_dev: shouldUpdateURLs}}
const path = options.localApp.configuration.path
await patchAppConfigurationFile({path, patch, schema: options.localApp.configSchema})
patchAppConfigurationFile({path, patch, schema: options.localApp.configSchema})
} else {
setCachedAppInfo({directory: options.appDirectory, updateURLs: shouldUpdateURLs})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-kit/src/public/node/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export async function writeFile(
* @param data - Content to be written.
*/
export function writeFileSync(path: string, data: string): void {
outputDebug(outputContent`File-writing some content to file at ${outputToken.path(path)}...`)
outputDebug(outputContent`Sync-writing some content to file at ${outputToken.path(path)}...`)
fsWriteFileSync(path, data)
}

Expand Down

0 comments on commit 32ee3ef

Please sign in to comment.