From 8dce7d3c96d990fd8b80f0919a7ef20f9135605a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isaac=20Rold=C3=A1n?= Date: Fri, 25 Oct 2024 10:54:42 +0200 Subject: [PATCH 1/4] Fix bug updating urls in toml --- .../cli/services/app/patch-app-configuration-file.test.ts | 7 +++++-- .../src/cli/services/app/patch-app-configuration-file.ts | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/app/src/cli/services/app/patch-app-configuration-file.test.ts b/packages/app/src/cli/services/app/patch-app-configuration-file.test.ts index 87d0eedabf..d0f1fde2c6 100644 --- a/packages/app/src/cli/services/app/patch-app-configuration-file.test.ts +++ b/packages/app/src/cli/services/app/patch-app-configuration-file.test.ts @@ -42,6 +42,9 @@ describe('patchAppConfigurationFile', () => { access_scopes: { use_legacy_install_flow: false, }, + auth: { + redirect_urls: ['https://example.com/redirect3', 'https://example.com/redirect4'], + }, } await patchAppConfigurationFile({path: configPath, patch, schema}) @@ -61,8 +64,8 @@ use_legacy_install_flow = false [auth] redirect_urls = [ - "https://example.com/redirect", - "https://example.com/redirect2" + "https://example.com/redirect3", + "https://example.com/redirect4" ] [webhooks] diff --git a/packages/app/src/cli/services/app/patch-app-configuration-file.ts b/packages/app/src/cli/services/app/patch-app-configuration-file.ts index 5bb533407b..e504563ce9 100644 --- a/packages/app/src/cli/services/app/patch-app-configuration-file.ts +++ b/packages/app/src/cli/services/app/patch-app-configuration-file.ts @@ -22,7 +22,7 @@ export interface PatchTomlOptions { export async function patchAppConfigurationFile({path, patch, schema}: PatchTomlOptions) { const tomlContents = await readFile(path) const configuration = decodeToml(tomlContents) - const updatedConfig = deepMergeObjects(configuration, patch) + const updatedConfig = deepMergeObjects(configuration, patch, replaceArrayStrategy) // Re-parse the config with the schema to validate the patch and keep the same order in the file // Make every field optional to not crash on invalid tomls that are missing fields. @@ -33,3 +33,7 @@ export async function patchAppConfigurationFile({path, patch, schema}: PatchToml encodedString = addDefaultCommentsToToml(encodedString) await writeFile(path, encodedString) } + +function replaceArrayStrategy(_: unknown[], sourceArray: unknown[]): unknown[] { + return sourceArray +} From 1aed352f46895080269c431cc6b6da475356a164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isaac=20Rold=C3=A1n?= Date: Fri, 25 Oct 2024 10:55:44 +0200 Subject: [PATCH 2/4] Fix bug updating urls in toml --- .changeset/eighty-ads-enjoy.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eighty-ads-enjoy.md diff --git a/.changeset/eighty-ads-enjoy.md b/.changeset/eighty-ads-enjoy.md new file mode 100644 index 0000000000..2d7084bb5b --- /dev/null +++ b/.changeset/eighty-ads-enjoy.md @@ -0,0 +1,5 @@ +--- +'@shopify/app': patch +--- + +Fix redirect_urls being appended instead of replaced during app dev From 606e83f3f5f788dbcdd7a4ce3be6527252e2bcbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isaac=20Rold=C3=A1n?= Date: Fri, 25 Oct 2024 11:24:46 +0200 Subject: [PATCH 3/4] Avoid reordering --- .../app/src/cli/services/app/patch-app-configuration-file.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app/src/cli/services/app/patch-app-configuration-file.ts b/packages/app/src/cli/services/app/patch-app-configuration-file.ts index e504563ce9..dc07a8d627 100644 --- a/packages/app/src/cli/services/app/patch-app-configuration-file.ts +++ b/packages/app/src/cli/services/app/patch-app-configuration-file.ts @@ -27,9 +27,9 @@ export async function patchAppConfigurationFile({path, patch, schema}: PatchToml // Re-parse the config with the schema to validate the patch and keep the same order in the file // Make every field optional to not crash on invalid tomls that are missing fields. const validSchema = schema ?? zod.object({}).passthrough() - const validatedConfig = validSchema.partial().parse(updatedConfig) - let encodedString = encodeToml(validatedConfig) + validSchema.partial().parse(updatedConfig) + let encodedString = encodeToml(updatedConfig) encodedString = addDefaultCommentsToToml(encodedString) await writeFile(path, encodedString) } From 90bfd9bea7f1058b41ea3484588f6e9a4dde09a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isaac=20Rold=C3=A1n?= Date: Fri, 25 Oct 2024 11:30:23 +0200 Subject: [PATCH 4/4] Update tests --- .../services/app/patch-app-configuration-file.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/app/src/cli/services/app/patch-app-configuration-file.test.ts b/packages/app/src/cli/services/app/patch-app-configuration-file.test.ts index d0f1fde2c6..cfefd43a2a 100644 --- a/packages/app/src/cli/services/app/patch-app-configuration-file.test.ts +++ b/packages/app/src/cli/services/app/patch-app-configuration-file.test.ts @@ -8,6 +8,7 @@ import {describe, expect, test} from 'vitest' const defaultToml = `# Learn more about configuring your app at https://shopify.dev/docs/apps/tools/cli/configuration client_id = "12345" name = "app1" +application_url = "https://example.com" embedded = true [access_scopes] @@ -95,9 +96,6 @@ name = "app1" application_url = "https://example.com" embedded = true -[build] -dev_store_url = "example.myshopify.com" - [access_scopes] # Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes use_legacy_install_flow = true @@ -110,6 +108,9 @@ redirect_urls = [ [webhooks] api_version = "2023-04" + +[build] +dev_store_url = "example.myshopify.com" `) }) }) @@ -137,8 +138,8 @@ embedded = true [access_scopes] # Learn more at https://shopify.dev/docs/apps/tools/cli/configuration#access_scopes -scopes = "read_products" use_legacy_install_flow = true +scopes = "read_products" [auth] redirect_urls = [