Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: conf store not saving some values on windows #1297

Merged
merged 2 commits into from
Feb 6, 2023
Merged
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
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)
}
}