[Feature] Add build.typegen_command support for non-JS Shopify Functions#6870
[Feature] Add build.typegen_command support for non-JS Shopify Functions#6870davejcameron merged 3 commits intomainfrom
Conversation
|
We detected some changes at Caution DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release. |
Coverage report
Test suite run success3774 tests passing in 1448 suites. Report generated by 🧪jest coverage report action from 64cb7a9 |
58d6dfa to
acd9b69
Compare
d1d70cd to
9cf1e5d
Compare
9cf1e5d to
40c3b83
Compare
5ccee3c to
47cf622
Compare
| get typegenCommand() { | ||
| const config = this.configuration as unknown as FunctionConfigType | ||
| return config.build?.typegen_command | ||
| } |
There was a problem hiding this comment.
I'll ping @ryancbahan here for an unrelated project discussion.
This is the kind of thing that shouldn't be in the generic extension-instance, but is an existing pattern with no real alternative right now.
The specification for Functions (or appmodule definition, or whatever we end up calling it) should own its build process, including the typegen step.
47cf622 to
ed41c58
Compare
ed41c58 to
e35df76
Compare
| const commandComponents = fun.typegenCommand.split(' ') | ||
| return runWithTimer('cmd_all_timing_network_ms')(async () => { | ||
| return exec(commandComponents[0]!, commandComponents.slice(1), { | ||
| cwd: fun.directory, |
There was a problem hiding this comment.
Broken command parsing for typegen_command (quotes/escaping/Windows) + possible empty command crash
The new custom typegen flow parses typegen_command with split(' '), which is not a shell parser. This breaks common valid commands:
- Quoted args:
typegen_command = "tool --out 'generated types.ts'"→ gets split into["tool","--out","'generated","types.ts'"] - Windows paths:
C:\Program Files\Tool\tool.exe --flag→ split into["C:\\Program","Files\\Tool\\tool.exe", ...] - Extra spaces / tabs produce empty tokens;
typegen_command = " npx foo"makescommandComponents[0]an empty string, andexec(commandComponents[0]!, ...)can throw or attempt to spawn''.
This will cause typegen to fail for many real-world configs, including the exact reason this feature exists (non-JS toolchains often require quoted paths).
Evidence:
const commandComponents = fun.typegenCommand.split(' ')
return exec(commandComponents[0]!, commandComponents.slice(1), ...)Impact:
- Users:
shopify app function typegen/shopify app function buildcan fail for valid configs (especially on Windows), blocking builds/deploys. - Support/CI: increased failures and confusing errors from spawning an empty/nonexistent executable.
- Scale: affects any user with spaces/quoting in commands (very common).
|
🤖 Code Review · #projects-dev-ai for questions ✅ Complete - 1 findings 📋 History✅ 2 findings → ✅ 1 findings |


WHY are these changes introduced?
Currently, typegen for Shopify Functions is hardcoded to run
npm exec -- graphql-code-generator --config package.json, which only works for JavaScript functions. For other languages (Rust, Zig, C), users must bundle their typegen step inside abuild.shscript alongside their actual build command. This makes it impossible to run typegen independently viashopify app function typegenfor non-JS functions.WHAT is this pull request doing?
Adds a
build.typegen_commandTOML field so users can specify a custom typegen command that runs both viashopify app function typegenand automatically before the build command.Example TOML:
Changes:
typegen_commandas an optional string field in the function extension schematypegenCommandgetter onExtensionInstancebuildGraphqlTypesto run custom command when set, falling back to the existing JS codegen flowtypegen_commandis configuredtypegenCLI command description to be language-agnosticHow to test your changes?
npx vitest run packages/app/src/cli/services/function/build.test.tsnpx vitest run packages/app/src/cli/services/build/extension.test.tsnpx vitest run packages/app/src/cli/models/extensions/specifications/function.test.tsTo test manually with a non-JS function:
typegen_command = "echo typegen running"under[build]in a function's TOMLshopify app function typegen— should execute the custom commandshopify app function build— should run typegen before the build commandMeasuring impact
How do we know this change was effective? Please choose one:
Checklist