Skip to content

Commit efb2e3b

Browse files
authored
Merge pull request #6333 from Shopify/08-28-fix_config_flag_handling_in_config_link
Fix configName flag handling in config:link
2 parents 3a2f619 + 09eb323 commit efb2e3b

File tree

2 files changed

+86
-7
lines changed

2 files changed

+86
-7
lines changed

packages/app/src/cli/services/app/config/link.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,85 @@ use_legacy_install_flow = true
16831683
[auth]
16841684
redirect_urls = [ "https://example.com/callback1" ]
16851685
1686+
[webhooks]
1687+
api_version = "2023-07"
1688+
1689+
[[webhooks.subscriptions]]
1690+
topics = [ "products/create" ]
1691+
uri = "https://my-app.com/webhooks"
1692+
1693+
[pos]
1694+
embedded = false
1695+
`
1696+
expect(content).toEqual(expectedContent)
1697+
})
1698+
})
1699+
1700+
test('existing config is respected when isNewApp is true, config is current and client_id is not the same as remote app and config name is provided', async () => {
1701+
await inTemporaryDirectory(async (tmp) => {
1702+
// Given
1703+
const developerPlatformClient = buildDeveloperPlatformClient()
1704+
const options: LinkOptions = {
1705+
directory: tmp,
1706+
developerPlatformClient,
1707+
isNewApp: true,
1708+
configName: 'staging',
1709+
}
1710+
const localApp = {
1711+
configuration: {
1712+
path: joinPath(tmp, 'shopify.app.staging.toml'),
1713+
name: 'my app',
1714+
client_id: 'invalid_client_id_from_template',
1715+
webhooks: {
1716+
api_version: '2023-04',
1717+
subscriptions: [{topics: ['products/create'], uri: 'https://my-app.com/webhooks'}],
1718+
},
1719+
application_url: 'https://myapp.com',
1720+
build: {
1721+
automatically_update_urls_on_dev: true,
1722+
dev_store_url: 'my-store.myshopify.com',
1723+
include_config_on_deploy: true,
1724+
},
1725+
access_scopes: {
1726+
scopes: 'write_products',
1727+
},
1728+
} as CurrentAppConfiguration,
1729+
}
1730+
1731+
vi.mocked(loadApp).mockResolvedValue(await mockApp(tmp, localApp, [], 'current'))
1732+
vi.mocked(fetchOrCreateOrganizationApp).mockResolvedValue(mockRemoteApp({developerPlatformClient}))
1733+
const remoteConfiguration = {
1734+
...DEFAULT_REMOTE_CONFIGURATION,
1735+
handle: 'handle',
1736+
}
1737+
vi.mocked(fetchAppRemoteConfiguration).mockResolvedValue(remoteConfiguration)
1738+
1739+
// When
1740+
await link(options)
1741+
1742+
// Then
1743+
const content = await readFile(joinPath(tmp, 'shopify.app.staging.toml'))
1744+
const expectedContent = `# Learn more about configuring your app at https://shopify.dev/docs/apps/tools/cli/configuration
1745+
1746+
client_id = "12345"
1747+
name = "app1"
1748+
handle = "handle"
1749+
application_url = "https://example.com"
1750+
embedded = true
1751+
1752+
[build]
1753+
automatically_update_urls_on_dev = true
1754+
dev_store_url = "my-store.myshopify.com"
1755+
include_config_on_deploy = true
1756+
1757+
[access_scopes]
1758+
# Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes
1759+
scopes = "write_products"
1760+
use_legacy_install_flow = true
1761+
1762+
[auth]
1763+
redirect_urls = [ "https://example.com/callback1" ]
1764+
16861765
[webhooks]
16871766
api_version = "2023-07"
16881767

packages/app/src/cli/services/app/config/link.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export interface LinkOptions {
4545
appId?: string
4646
organizationId?: string
4747
configName?: string
48-
baseConfigName?: string
4948
developerPlatformClient?: DeveloperPlatformClient
5049
isNewApp?: boolean
5150
}
@@ -178,7 +177,7 @@ async function getAppCreationDefaultsFromLocalApp(options: LinkOptions): Promise
178177
specifications: await loadLocalExtensionsSpecifications(),
179178
directory: options.directory,
180179
mode: 'report',
181-
userProvidedConfigName: options.baseConfigName,
180+
userProvidedConfigName: options.configName,
182181
remoteFlags: undefined,
183182
})
184183

@@ -253,7 +252,7 @@ async function loadLocalAppOptions(
253252
specifications,
254253
directory: options.directory,
255254
mode: 'report',
256-
userProvidedConfigName: options.baseConfigName,
255+
userProvidedConfigName: options.configName,
257256
remoteFlags,
258257
})
259258
const configuration = app.configuration
@@ -321,14 +320,15 @@ async function loadConfigurationFileName(
321320
format: 'legacy' | 'current'
322321
},
323322
): Promise<AppConfigurationFileName> {
324-
// If the user has already selected a config name, use that
325-
const cache = getCachedCommandInfo()
326-
if (cache?.selectedToml) return cache.selectedToml as AppConfigurationFileName
327-
323+
// config name from the options takes precedence over everything else
328324
if (options.configName) {
329325
return getAppConfigurationFileName(options.configName)
330326
}
331327

328+
// otherwise, use the cached config name if it exists
329+
const cache = getCachedCommandInfo()
330+
if (cache?.selectedToml) return cache.selectedToml as AppConfigurationFileName
331+
332332
if (localAppInfo.format === 'legacy') {
333333
return configurationFileNames.app
334334
}

0 commit comments

Comments
 (0)