Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchDickinson committed Jul 29, 2024
1 parent e7416ae commit 80d5514
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
3 changes: 1 addition & 2 deletions packages/app/src/cli/services/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,8 +1065,7 @@ describe('ensureDeploy Context', () => {
const got = await ensureDeployContext(opts)

// Then
// TODO: try to assert exact arguments.
expect(link).toHaveBeenCalled()
expect(link).toBeCalledWith({directory: app.directory}, false)

expect(updateAppIdentifiers).toBeCalledWith({
app,
Expand Down
44 changes: 12 additions & 32 deletions packages/app/src/cli/services/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,7 @@ export async function ensureDeployContext(options: DeployContextOptions): Promis
let developerPlatformClient = options.developerPlatformClient
// do the link here
// MITCH: do a refactor to call getAppContext directly and not do this.
const performAppLink = await decideOnLinkStrategy(options.app.directory, options.reset, true)
const [remoteApp] = await fetchAppAndIdentifiers(options, developerPlatformClient, true, performAppLink)
const [remoteApp] = await fetchAppAndIdentifiers(options, developerPlatformClient, true, true)

developerPlatformClient = remoteApp.developerPlatformClient ?? developerPlatformClient

Expand Down Expand Up @@ -558,7 +557,7 @@ function includeConfigOnDeployPrompt(configPath: string): Promise<boolean> {
export async function ensureReleaseContext(options: ReleaseContextOptions): Promise<ReleaseContextOutput> {
let developerPlatformClient =
options.developerPlatformClient ?? selectDeveloperPlatformClient({configuration: options.app.configuration})
const [remoteApp, envIdentifiers] = await fetchAppAndIdentifiers(options, developerPlatformClient)
const [remoteApp, envIdentifiers] = await fetchAppAndIdentifiers(options, developerPlatformClient, true, true)
developerPlatformClient = remoteApp.developerPlatformClient ?? developerPlatformClient
const identifiers: Identifiers = envIdentifiers as Identifiers

Expand Down Expand Up @@ -643,36 +642,18 @@ export async function fetchAppAndIdentifiers(
},
initialDeveloperPlatformClient: DeveloperPlatformClient,
reuseFromDev = true,
performAppLink = false,
enableLinkingPrompt = false,
): Promise<[OrganizationApp, Partial<UuidOnlyIdentifiers>]> {
let developerPlatformClient = initialDeveloperPlatformClient
const app = options.app
let reuseDevCache = reuseFromDev
let envIdentifiers = getAppIdentifiers({app}, developerPlatformClient)
let remoteApp: OrganizationApp | undefined

const previousCachedInfo = getCachedAppInfo(app.directory)

/**
* TODO:
* - Clean up this refactor to the extent possible (and file an issue for further improvements)
* - Fixing existing tests
* - Add test that link is called on a new deploy
* - More tophatting.
* - Test dev flow with partners
*/
if (performAppLink) {
const configuration = await linkIfNecessary(app.directory, options.reset, enableLinkingPrompt)
if (configuration !== undefined) {
envIdentifiers = {app: undefined, extensions: {}}
reuseDevCache = false
// TODO: should we pass this in? We read the cached info outside this.
const configuration = await link(
{
directory: app.directory,
baseConfigName: previousCachedInfo?.configFile,
developerPlatformClient,
},
false,
)
app.configuration = configuration
developerPlatformClient = selectDeveloperPlatformClient({configuration})
}
Expand Down Expand Up @@ -782,12 +763,9 @@ export async function getAppContext({
configName?: string
enableLinkingPrompt?: boolean
}): Promise<AppContext> {
const performAppLink = await decideOnLinkStrategy(directory, reset, enableLinkingPrompt)
let cachedInfo = getCachedAppInfo(directory)
await linkIfNecessary(directory, reset, enableLinkingPrompt)

if (performAppLink) {
await link({directory, baseConfigName: cachedInfo?.configFile}, false)
}
let cachedInfo = getCachedAppInfo(directory)

const {configuration} = await loadAppConfiguration({
directory,
Expand Down Expand Up @@ -823,11 +801,11 @@ export async function getAppContext({
}
}

export async function decideOnLinkStrategy(
async function linkIfNecessary(
directory: string,
reset: boolean,
enableLinkingPrompt: boolean,
): Promise<boolean | undefined> {
): Promise<CurrentAppConfiguration | undefined> {
const previousCachedInfo = getCachedAppInfo(directory)

if (reset) clearCachedAppInfo(directory)
Expand All @@ -838,7 +816,9 @@ export async function decideOnLinkStrategy(
previousCachedInfo?.configFile !== undefined && (await glob(joinPath(directory, 'shopify.app*.toml'))).length === 0

const performAppLink = enableLinkingPrompt && (firstTimeSetup || usingConfigAndResetting || usingConfigWithNoTomls)
return performAppLink
if (performAppLink) {
return link({directory, baseConfigName: previousCachedInfo?.configFile}, false)
}
}

/**
Expand Down

0 comments on commit 80d5514

Please sign in to comment.