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

Fix template flag for extensions #1002

Merged
merged 5 commits into from
Jan 5, 2023
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/short-kids-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

Fix extension generate not accepting some template values
31 changes: 31 additions & 0 deletions packages/app/src/cli/prompts/generate/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,35 @@ describe('extension prompt', async () => {

expect(got).toEqual({...options, ...answers})
})

it('when extensionFlavor is passed, only compatible extensions are shown', async () => {
// Given
const prompt = vi.fn()
const answers = {}
const options = {
name: 'my-product-discount',
directory: '/',
app: testApp(),
reset: false,
extensionFlavor: 'rust',
extensionSpecifications: [...allFunctionSpecs, ...allUISpecs],
}

// only function types should be shown if flavor is rust
const functionTypes = {
type: 'select',
name: 'extensionType',
message: 'Type of extension?',
choices: buildChoices(allFunctionSpecs),
}

prompt.mockResolvedValue(answers)

// When
const got = await generateExtensionPrompt(options, prompt)

// Then
expect(prompt).toHaveBeenCalledWith([functionTypes])
expect(got).toEqual({...options, ...answers})
})
})
2 changes: 1 addition & 1 deletion packages/app/src/cli/prompts/generate/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const generateExtensionPrompt = async (
if (!options.extensionType) {
if (options.extensionFlavor) {
const flavor = options.extensionFlavor
allExtensions = allExtensions.filter((spec) => spec.supportedFlavors.map((elem) => elem.name).includes(flavor))
allExtensions = allExtensions.filter((spec) => spec.supportedFlavors.map((elem) => elem.value).includes(flavor))
}

questions.push({
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/cli/services/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('after extension command finishes correctly', () => {
const got = generate({directory: '/', reset: false, config: mockConfig, type: 'checkout_ui', template: 'unknown'})

// Then
await expect(got).rejects.toThrow(/Specified extension template on invalid extension type/)
await expect(got).rejects.toThrow(/Invalid template for extension type/)
})
})

Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/cli/services/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ function findSpecification(type: string | undefined, specifications: GenericSpec
function validateExtensionFlavor(specification: GenericSpecification | undefined, flavor: string | undefined) {
if (!flavor || !specification) return

const possibleFlavors = specification.supportedFlavors.map((flavor) => flavor.name)
const possibleFlavors = specification.supportedFlavors.map((flavor) => flavor.value)
if (!possibleFlavors.includes(flavor)) {
throw new error.Abort(
'Specified extension template on invalid extension type',
`You can only specify a template for these extension types: ${possibleFlavors.join(', ')}.`,
'Invalid template for extension type',
`Expected template to be one of the following: ${possibleFlavors.join(', ')}.`,
)
}
}
Expand Down