Skip to content

Commit

Permalink
Merge pull request #1297 from Shopify/fix-app-conf-store
Browse files Browse the repository at this point in the history
Fix: conf store not saving some values on windows
  • Loading branch information
isaacroldan authored Feb 6, 2023
2 parents a8ae2c2 + 3314a97 commit 50c3606
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-cobras-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

Fix windows not storing dev selected values correctly
14 changes: 14 additions & 0 deletions packages/app/src/cli/services/conf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ describe('setAppInfo', async () => {
expect(got).toEqual(APP2)
})
})

it('creates new info normalizing the path', async () => {
await inTemporaryDirectory(async (cwd) => {
// Given
const conf = new Conf<AppConfSchema>({cwd})

// When
setAppInfo({appId: 'app2', directory: '\\app2\\something', storeFqdn: APP2.storeFqdn, orgId: APP2.orgId}, conf)
const got = conf.get('/app2/something')

// Then
expect(got.appId).toEqual(APP2.appId)
})
})
})

describe('clearAppInfo', async () => {
Expand Down
24 changes: 13 additions & 11 deletions packages/app/src/cli/services/conf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Conf} from '@shopify/cli-kit/node/conf'
import {outputDebug, outputContent, outputToken} from '@shopify/cli-kit/node/output'
import {normalizePath} from '@shopify/cli-kit/node/path'

export interface CachedAppInfo {
directory: string
Expand All @@ -26,13 +27,15 @@ function appConf() {
}

export function getAppInfo(directory: string, config: Conf<AppConfSchema> = appConf()): CachedAppInfo | undefined {
outputDebug(outputContent`Reading cached app information for directory ${outputToken.path(directory)}...`)
return config.get(directory)
const normalized = normalizePath(directory)
outputDebug(outputContent`Reading cached app information for directory ${outputToken.path(normalized)}...`)
return config.get(normalized)
}

export function clearAppInfo(directory: string, config: Conf<AppConfSchema> = appConf()): void {
outputDebug(outputContent`Clearing app information for directory ${outputToken.path(directory)}...`)
config.delete(directory)
const normalized = normalizePath(directory)
outputDebug(outputContent`Clearing app information for directory ${outputToken.path(normalized)}...`)
config.delete(normalized)
}

export function clearAllAppInfo(config: Conf<AppConfSchema> = appConf()): void {
Expand All @@ -41,15 +44,14 @@ export function clearAllAppInfo(config: Conf<AppConfSchema> = appConf()): void {
}

export function setAppInfo(options: CachedAppInfo, config: Conf<AppConfSchema> = appConf()): void {
const normalized = normalizePath(options.directory)
outputDebug(
outputContent`Storing app information for directory ${outputToken.path(options.directory)}:${outputToken.json(
options,
)}`,
outputContent`Storing app information for directory ${outputToken.path(normalized)}:${outputToken.json(options)}`,
)
const savedApp = config.get(options.directory)
const savedApp = config.get(normalized)
if (savedApp) {
config.set(options.directory, {
directory: options.directory,
config.set(normalized, {
directory: normalized,
appId: options.appId ?? savedApp.appId,
title: options.title ?? savedApp.title,
storeFqdn: options.storeFqdn ?? savedApp.storeFqdn,
Expand All @@ -58,6 +60,6 @@ export function setAppInfo(options: CachedAppInfo, config: Conf<AppConfSchema> =
tunnelPlugin: options.tunnelPlugin ?? savedApp.tunnelPlugin,
})
} else {
config.set(options.directory, options)
config.set(normalized, options)
}
}

0 comments on commit 50c3606

Please sign in to comment.