Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions packages/app/src/cli/models/app/app.test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,6 @@ export function testDeveloperPlatformClient(stubs: Partial<DeveloperPlatformClie
const clientStub: DeveloperPlatformClient = {
clientName: ClientName.AppManagement,
webUiName: 'Test Dashboard',
supportsAtomicDeployments: false,
organizationSource: OrganizationSource.BusinessPlatform,
bundleFormat: 'zip',
supportsDashboardManagedExtensions: true,
Expand Down Expand Up @@ -1412,12 +1411,7 @@ export function testDeveloperPlatformClient(stubs: Partial<DeveloperPlatformClie
retVal[
key as keyof Omit<
DeveloperPlatformClient,
| 'supportsAtomicDeployments'
| 'clientName'
| 'webUiName'
| 'organizationSource'
| 'bundleFormat'
| 'supportsDashboardManagedExtensions'
'clientName' | 'webUiName' | 'organizationSource' | 'bundleFormat' | 'supportsDashboardManagedExtensions'
>
] = vi.fn().mockImplementation(value)
}
Expand Down
31 changes: 11 additions & 20 deletions packages/app/src/cli/models/app/identifiers.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {updateAppIdentifiers, getAppIdentifiers} from './identifiers.js'
import {testApp, testAppWithConfig, testDeveloperPlatformClient, testUIExtension} from './app.test-data.js'
import {testApp, testAppWithConfig, testUIExtension} from './app.test-data.js'
import {describe, expect, test} from 'vitest'
import {readAndParseDotEnv} from '@shopify/cli-kit/node/dot-env'
import {fileExists, inTemporaryDirectory, readFile, writeFile} from '@shopify/cli-kit/node/fs'
import {joinPath} from '@shopify/cli-kit/node/path'

describe('updateAppIdentifiers', () => {
test('persists the ids that are not env variables when deploying, creating a new file', async () => {
test('updates ids in memory when deploying without creating a new env file', async () => {
await inTemporaryDirectory(async (tmpDir: string) => {
// Given
const uiExtension = await testUIExtension()
Expand All @@ -25,19 +25,15 @@ describe('updateAppIdentifiers', () => {
},
},
command: 'deploy',
developerPlatformClient: testDeveloperPlatformClient(),
})

// Then
const dotEnvFile = await readAndParseDotEnv(joinPath(tmpDir, '.env'))
expect(dotEnvFile.variables.SHOPIFY_API_KEY).toEqual('FOO')
expect(dotEnvFile.variables.SHOPIFY_MY_EXTENSION_ID).toEqual('BAR')
expect(gotApp.dotenv?.variables.SHOPIFY_API_KEY).toEqual('FOO')
expect(gotApp.dotenv?.variables.SHOPIFY_MY_EXTENSION_ID).toEqual('BAR')
await expect(fileExists(joinPath(tmpDir, '.env'))).resolves.toBe(false)
expect(gotApp.dotenv).toBeUndefined()
})
})

test('persists the ids in the config-specific env file when deploying, updating the existing file', async () => {
test('does not write ids to the config-specific env file when deploying', async () => {
await inTemporaryDirectory(async (tmpDir: string) => {
// Given
const dotEnvFilePath = joinPath(tmpDir, '.env.staging')
Expand All @@ -62,20 +58,17 @@ describe('updateAppIdentifiers', () => {
},
},
command: 'deploy',
developerPlatformClient: testDeveloperPlatformClient(),
})

// Then
const dotEnvFileContent = await readFile(dotEnvFilePath)
const dotEnvFile = await readAndParseDotEnv(dotEnvFilePath)
expect(dotEnvFileContent).toEqual(
'#comment\nEXISTING_VAR=value\nSHOPIFY_MY_EXTENSION_ID=BAR\n#anothercomment\nSHOPIFY_API_KEY=FOO',
)
expect(dotEnvFileContent).toEqual('#comment\nEXISTING_VAR=value\nSHOPIFY_MY_EXTENSION_ID=OLDID\n#anothercomment')
expect(dotEnvFile.variables.EXISTING_VAR).toEqual('value')
expect(dotEnvFile.variables.SHOPIFY_API_KEY).toEqual('FOO')
expect(dotEnvFile.variables.SHOPIFY_MY_EXTENSION_ID).toEqual('BAR')
expect(gotApp.dotenv?.variables.SHOPIFY_API_KEY).toEqual('FOO')
expect(gotApp.dotenv?.variables.SHOPIFY_MY_EXTENSION_ID).toEqual('BAR')
expect(dotEnvFile.variables.SHOPIFY_API_KEY).toBeUndefined()
expect(dotEnvFile.variables.SHOPIFY_MY_EXTENSION_ID).toEqual('OLDID')
expect(gotApp.dotenv?.variables.SHOPIFY_API_KEY).toBeUndefined()
expect(gotApp.dotenv?.variables.SHOPIFY_MY_EXTENSION_ID).toBeUndefined()
})
})

Expand All @@ -99,7 +92,6 @@ describe('updateAppIdentifiers', () => {
},
},
command: 'deploy',
developerPlatformClient: testDeveloperPlatformClient(),
},
{SHOPIFY_API_KEY: 'FOO', SHOPIFY_MY_EXTENSION_ID: 'BAR'},
)
Expand All @@ -115,7 +107,7 @@ describe('updateAppIdentifiers', () => {
})
})

test('does not change a unified config TOML with multiple when the uid is already present for atomic deployments', async () => {
test('does not change a unified config TOML with multiple when the uid is already present', async () => {
await inTemporaryDirectory(async (tmpDir: string) => {
// Given
const uiExtension1 = await testUIExtension({
Expand Down Expand Up @@ -167,7 +159,6 @@ type = "ui_extension"`,
},
},
command: 'deploy',
developerPlatformClient: testDeveloperPlatformClient({supportsAtomicDeployments: true}),
},
{SHOPIFY_API_KEY: 'FOO', SHOPIFY_MY_EXTENSION_ID: 'BAR'},
)
Expand Down
12 changes: 2 additions & 10 deletions packages/app/src/cli/models/app/identifiers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {getDotEnvFileName} from './loader.js'
import {ExtensionInstance} from '../extensions/extension-instance.js'
import {DeveloperPlatformClient} from '../../utilities/developer-platform-client.js'
import {patchEnvFile} from '@shopify/cli-kit/node/dot-env'
import {constantize} from '@shopify/cli-kit/common/string'
import {joinPath} from '@shopify/cli-kit/node/path'
import {fileExists, readFile, writeFile} from '@shopify/cli-kit/node/fs'
import {deepCompare} from '@shopify/cli-kit/common/object'
import type {AppInterface} from './app.js'

export interface IdentifiersExtensions {
Expand Down Expand Up @@ -38,7 +36,6 @@ interface UpdateAppIdentifiersOptions {
app: AppInterface
identifiers: UuidOnlyIdentifiers
command: UpdateAppIdentifiersCommand
developerPlatformClient: DeveloperPlatformClient
}

/**
Expand All @@ -47,7 +44,7 @@ interface UpdateAppIdentifiersOptions {
* @returns An copy of the app with the environment updated to reflect the updated identifiers.
*/
export async function updateAppIdentifiers(
{app, identifiers, command, developerPlatformClient}: UpdateAppIdentifiersOptions,
{app, identifiers, command}: UpdateAppIdentifiersOptions,
systemEnvironment = process.env,
): Promise<AppInterface> {
let dotenvFile = app.dotenv
Expand All @@ -67,12 +64,7 @@ export async function updateAppIdentifiers(
}
})

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

dotenvFile.variables = updatedVariables

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,11 @@
import {addUidToTomlsIfNecessary} from './add-uid-to-extension-toml.js'
import {ExtensionInstance} from '../../models/extensions/extension-instance.js'
import {testDeveloperPlatformClient, testUIExtension} from '../../models/app/app.test-data.js'
import {testDeveloperPlatformClient} from '../../models/app/app.test-data.js'
import {describe, test, expect} from 'vitest'
import {writeFile, readFile, inTemporaryDirectory} from '@shopify/cli-kit/node/fs'
import {joinPath} from '@shopify/cli-kit/node/path'

describe('addUidToTomlsIfNecessary', () => {
test('skips if platform does not support atomic deployments', async () => {
await inTemporaryDirectory(async (tmpDir) => {
// Given
const tomlPath = joinPath(tmpDir, 'extension.toml')
const tomlContent = `
type = "checkout_ui_extension"
handle = "my-extension"
`
await writeFile(tomlPath, tomlContent)

const extension = await testUIExtension({
directory: tmpDir,
configuration: {
handle: 'my-extension',
type: 'checkout_ui_extension',
name: 'test',
},
configurationPath: tomlPath,
uid: '123',
})

const client = testDeveloperPlatformClient({supportsAtomicDeployments: false})

// When
await addUidToTomlsIfNecessary([extension], client)

// Then
const updatedContent = await readFile(tomlPath)
expect(updatedContent).toBe(tomlContent)
})
})

test('adds uid to single extension TOML', async () => {
await inTemporaryDirectory(async (tmpDir) => {
// Given
Expand All @@ -56,7 +24,7 @@ describe('addUidToTomlsIfNecessary', () => {
configuration: {},
} as ExtensionInstance

const client = testDeveloperPlatformClient({supportsAtomicDeployments: true})
const client = testDeveloperPlatformClient({})

// When
await addUidToTomlsIfNecessary([extension], client)
Expand Down Expand Up @@ -97,7 +65,7 @@ scopes = "write_metaobject_definitions,write_metaobjects,write_products"
configuration: {},
} as ExtensionInstance

const client = testDeveloperPlatformClient({supportsAtomicDeployments: true})
const client = testDeveloperPlatformClient({})

// When
await addUidToTomlsIfNecessary([extension], client)
Expand Down Expand Up @@ -155,7 +123,7 @@ scopes = "write_metaobject_definitions,write_metaobjects,write_products"
configuration: {},
} as ExtensionInstance

const client = testDeveloperPlatformClient({supportsAtomicDeployments: true})
const client = testDeveloperPlatformClient({})

// When
await addUidToTomlsIfNecessary([extension, extension1], client)
Expand Down Expand Up @@ -197,7 +165,7 @@ scopes = "write_metaobject_definitions,write_metaobjects,write_products"
},
} as ExtensionInstance

const client = testDeveloperPlatformClient({supportsAtomicDeployments: true})
const client = testDeveloperPlatformClient({})

// When
await addUidToTomlsIfNecessary([extension], client)
Expand Down Expand Up @@ -226,7 +194,7 @@ scopes = "write_metaobject_definitions,write_metaobjects,write_products"
configuration: {},
} as ExtensionInstance

const client = testDeveloperPlatformClient({supportsAtomicDeployments: true})
const client = testDeveloperPlatformClient({})

// When
await addUidToTomlsIfNecessary([extension], client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import {getPathValue} from '@shopify/cli-kit/common/object'

export async function addUidToTomlsIfNecessary(
extensions: ExtensionInstance[],
developerPlatformClient: DeveloperPlatformClient,
_developerPlatformClient: DeveloperPlatformClient,
) {
if (!developerPlatformClient.supportsAtomicDeployments) return

// We can't update the TOML files in parallel because some extensions might share the same file
for (const extension of extensions) {
// eslint-disable-next-line no-await-in-loop
Expand Down
Loading
Loading