From 3a6cdaa1aac2e7221e5981531be619b357e16e69 Mon Sep 17 00:00:00 2001 From: Ariel Caplan Date: Tue, 20 Feb 2024 16:18:10 +0200 Subject: [PATCH 1/3] Remove zod schemas from app info JSON format --- packages/app/src/cli/services/info.ts | 42 +++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/packages/app/src/cli/services/info.ts b/packages/app/src/cli/services/info.ts index e9b912350b..1498c31b09 100644 --- a/packages/app/src/cli/services/info.ts +++ b/packages/app/src/cli/services/info.ts @@ -45,11 +45,47 @@ export async function infoWeb(app: AppInterface, {format}: InfoOptions): Promise export async function infoApp(app: AppInterface, options: InfoOptions): Promise { if (options.format === 'json') { - const appWithSupportedExtensions = { + function objectWithoutSchema(obj: T): Omit { + const {schema, ...rest} = obj + return rest + } + + function withPurgedSchemas(extensions: T[]): T[] { + return extensions.map((ext) => { + if ('specification' in ext) { + const specification = ext.specification! + const specificationWithoutSchema = objectWithoutSchema(specification) + return {...ext, specification: specificationWithoutSchema} + } else { + return ext + } + }) + } + const extensionsInfo = withPurgedSchemas(app.allExtensions.filter((ext) => ext.isReturnedAsInfo())) + let appWithSupportedExtensions = { ...app, - allExtensions: app.allExtensions.filter((ext) => ext.isReturnedAsInfo()), + allExtensions: extensionsInfo, + } + if ('realExtensions' in appWithSupportedExtensions) { + appWithSupportedExtensions.realExtensions = withPurgedSchemas(appWithSupportedExtensions.realExtensions as ExtensionInstance[]) + } + if ('specifications' in appWithSupportedExtensions) { + appWithSupportedExtensions = { + ...appWithSupportedExtensions, + specifications: appWithSupportedExtensions.specifications?.map((spec) => { + // We are choosing to leave appWithSupportedExtensions as close to the original as possible, + // instead allowing this one change in the type specifically. + // + // eslint-disable-next-line no-explicit-any + return objectWithoutSchema(spec) as any + }) + } } - return outputContent`${JSON.stringify(appWithSupportedExtensions, null, 2)}` + return outputContent`${JSON.stringify( + Object.fromEntries( + Object.entries(appWithSupportedExtensions).filter(([key]) => key !== 'configSchema'), + ) + , null, 2)}` } else { const appInfo = new AppInfo(app, options) return appInfo.output() From c9cbf05b4d8ef54ed0cc2cd230aae144e986cde0 Mon Sep 17 00:00:00 2001 From: Ariel Caplan Date: Tue, 20 Feb 2024 17:28:41 +0200 Subject: [PATCH 2/3] Add changeset --- .changeset/strange-drinks-move.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strange-drinks-move.md diff --git a/.changeset/strange-drinks-move.md b/.changeset/strange-drinks-move.md new file mode 100644 index 0000000000..6d3e40559f --- /dev/null +++ b/.changeset/strange-drinks-move.md @@ -0,0 +1,5 @@ +--- +'@shopify/app': minor +--- + +Remove zod schemas from app info (JSON format) From 3e4e39834aa29f6d37b95cbbd28836788ee0ea9c Mon Sep 17 00:00:00 2001 From: Ariel Caplan Date: Tue, 20 Feb 2024 17:32:13 +0200 Subject: [PATCH 3/3] Lint fixes --- packages/app/src/cli/services/info.ts | 49 ++++++++++++++------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/packages/app/src/cli/services/info.ts b/packages/app/src/cli/services/info.ts index 1498c31b09..69dc511613 100644 --- a/packages/app/src/cli/services/info.ts +++ b/packages/app/src/cli/services/info.ts @@ -45,29 +45,15 @@ export async function infoWeb(app: AppInterface, {format}: InfoOptions): Promise export async function infoApp(app: AppInterface, options: InfoOptions): Promise { if (options.format === 'json') { - function objectWithoutSchema(obj: T): Omit { - const {schema, ...rest} = obj - return rest - } - - function withPurgedSchemas(extensions: T[]): T[] { - return extensions.map((ext) => { - if ('specification' in ext) { - const specification = ext.specification! - const specificationWithoutSchema = objectWithoutSchema(specification) - return {...ext, specification: specificationWithoutSchema} - } else { - return ext - } - }) - } const extensionsInfo = withPurgedSchemas(app.allExtensions.filter((ext) => ext.isReturnedAsInfo())) let appWithSupportedExtensions = { ...app, allExtensions: extensionsInfo, } if ('realExtensions' in appWithSupportedExtensions) { - appWithSupportedExtensions.realExtensions = withPurgedSchemas(appWithSupportedExtensions.realExtensions as ExtensionInstance[]) + appWithSupportedExtensions.realExtensions = withPurgedSchemas( + appWithSupportedExtensions.realExtensions as ExtensionInstance[], + ) } if ('specifications' in appWithSupportedExtensions) { appWithSupportedExtensions = { @@ -76,22 +62,39 @@ export async function infoApp(app: AppInterface, options: InfoOptions): Promise< // We are choosing to leave appWithSupportedExtensions as close to the original as possible, // instead allowing this one change in the type specifically. // - // eslint-disable-next-line no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any return objectWithoutSchema(spec) as any - }) + }), } } return outputContent`${JSON.stringify( - Object.fromEntries( - Object.entries(appWithSupportedExtensions).filter(([key]) => key !== 'configSchema'), - ) - , null, 2)}` + Object.fromEntries(Object.entries(appWithSupportedExtensions).filter(([key]) => key !== 'configSchema')), + null, + 2, + )}` } else { const appInfo = new AppInfo(app, options) return appInfo.output() } } +function objectWithoutSchema(obj: T): Omit { + const {schema, ...rest} = obj + return rest +} + +function withPurgedSchemas(extensions: T[]): T[] { + return extensions.map((ext) => { + if ('specification' in ext) { + const specification = ext.specification! + const specificationWithoutSchema = objectWithoutSchema(specification) + return {...ext, specification: specificationWithoutSchema} + } else { + return ext + } + }) +} + const UNKNOWN_TEXT = outputContent`${outputToken.italic('unknown')}`.value const NOT_CONFIGURED_TEXT = outputContent`${outputToken.italic('Not yet configured')}`.value