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

Remove zod schemas from app info JSON format #3458

Merged
merged 3 commits into from
Mar 4, 2024
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/strange-drinks-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': minor
---

Remove zod schemas from app info (JSON format)
45 changes: 42 additions & 3 deletions packages/app/src/cli/services/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,56 @@ export async function infoWeb(app: AppInterface, {format}: InfoOptions): Promise

export async function infoApp(app: AppInterface, options: InfoOptions): Promise<OutputMessage> {
if (options.format === 'json') {
const appWithSupportedExtensions = {
const extensionsInfo = withPurgedSchemas(app.allExtensions.filter((ext) => ext.isReturnedAsInfo()))
let appWithSupportedExtensions = {
...app,
allExtensions: app.allExtensions.filter((ext) => ext.isReturnedAsInfo()),
allExtensions: extensionsInfo,
}
return outputContent`${JSON.stringify(appWithSupportedExtensions, null, 2)}`
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 @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,
)}`
} else {
const appInfo = new AppInfo(app, options)
return appInfo.output()
}
}

function objectWithoutSchema<T extends {schema?: unknown}>(obj: T): Omit<T, 'schema'> {
const {schema, ...rest} = obj
return rest
}

function withPurgedSchemas<T extends {specification?: {schema?: unknown}}>(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

Expand Down