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 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..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] @@ -42,6 +43,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 +65,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] @@ -92,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 @@ -107,6 +108,9 @@ redirect_urls = [ [webhooks] api_version = "2023-04" + +[build] +dev_store_url = "example.myshopify.com" `) }) }) @@ -134,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 = [ 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..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 @@ -22,14 +22,18 @@ 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. 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) } + +function replaceArrayStrategy(_: unknown[], sourceArray: unknown[]): unknown[] { + return sourceArray +}