From fab560582649da622776e4d8ccffe5a8ee287a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isaac=20Rold=C3=A1n?= Date: Mon, 6 Feb 2023 15:54:14 +0100 Subject: [PATCH 1/2] Normalize the directory used as key before saving data into the local conf store --- packages/app/src/cli/services/conf.test.ts | 14 +++++++++++++ packages/app/src/cli/services/conf.ts | 24 ++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/app/src/cli/services/conf.test.ts b/packages/app/src/cli/services/conf.test.ts index 0015a841b0..515d73d099 100644 --- a/packages/app/src/cli/services/conf.test.ts +++ b/packages/app/src/cli/services/conf.test.ts @@ -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({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 () => { diff --git a/packages/app/src/cli/services/conf.ts b/packages/app/src/cli/services/conf.ts index b8986445e9..b55f2bc540 100644 --- a/packages/app/src/cli/services/conf.ts +++ b/packages/app/src/cli/services/conf.ts @@ -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 @@ -26,13 +27,15 @@ function appConf() { } export function getAppInfo(directory: string, config: Conf = 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 = 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 = appConf()): void { @@ -41,15 +44,14 @@ export function clearAllAppInfo(config: Conf = appConf()): void { } export function setAppInfo(options: CachedAppInfo, config: Conf = 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, @@ -58,6 +60,6 @@ export function setAppInfo(options: CachedAppInfo, config: Conf = tunnelPlugin: options.tunnelPlugin ?? savedApp.tunnelPlugin, }) } else { - config.set(options.directory, options) + config.set(normalized, options) } } From 3314a972b552d69f529510fe80c4a1eb24346518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isaac=20Rold=C3=A1n?= Date: Mon, 6 Feb 2023 16:08:50 +0100 Subject: [PATCH 2/2] Add changeset --- .changeset/forty-cobras-warn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/forty-cobras-warn.md diff --git a/.changeset/forty-cobras-warn.md b/.changeset/forty-cobras-warn.md new file mode 100644 index 0000000000..bb01866372 --- /dev/null +++ b/.changeset/forty-cobras-warn.md @@ -0,0 +1,5 @@ +--- +'@shopify/app': patch +--- + +Fix windows not storing dev selected values correctly