Use function directory package manager for GraphQL typegen#7239
Use function directory package manager for GraphQL typegen#7239
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR updates GraphQL type generation for function builds to execute graphql-code-generator via the package manager inferred from the function’s directory (or its ancestors), rather than always using npm exec.
Changes:
- Added a directory-based package manager inference helper and a shared command builder for executing local binaries.
- Updated function type generation to use the new helper when running GraphQL codegen.
- Added unit tests for the new helper and updated function build tests to assert the helper is used.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/cli-kit/src/public/node/node-package-manager.ts | Adds directory-based package manager inference and builds the correct {command,args} to run a local binary via npm/pnpm/yarn/bun. |
| packages/cli-kit/src/public/node/node-package-manager.test.ts | Adds coverage for packageManagerBinaryCommandForDirectory across npm/pnpm/yarn/bun and fallback behavior. |
| packages/app/src/cli/services/function/build.ts | Switches GraphQL typegen execution to the shared package-manager-aware command builder. |
| packages/app/src/cli/services/function/build.test.ts | Mocks the shared helper and verifies buildGraphqlTypes executes the returned command. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
465b328 to
f955628
Compare
Detect the package manager from the function directory when running the default JavaScript GraphQL type generation path, instead of hardcoding npm.\n\nKeep the broader getPackageManager() behavior unchanged by adding a narrow cli-kit helper that resolves the correct package-manager-specific binary invocation for a project directory.
f955628 to
7cf64a7
Compare
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/node-package-manager.d.ts@@ -64,6 +64,14 @@ export declare function packageManagerFromUserAgent(env?: NodeJS.ProcessEnv): Pa
* @returns The dependency manager
*/
export declare function getPackageManager(fromDirectory: string): Promise<PackageManager>;
+/**
+ * Builds the command and argv needed to execute a local binary using the package manager
+ * detected from the provided directory or its ancestors.
+ */
+export declare function packageManagerBinaryCommandForDirectory(fromDirectory: string, binary: string, ...binaryArgs: string[]): Promise<{
+ command: string;
+ args: string[];
+}>;
interface InstallNPMDependenciesRecursivelyOptions {
/**
* The dependency manager to use to install the dependencies.
|
|
/snapit |
|
🫰✨ Thanks @dmerand! Your snapshot has been published to npm. Test the snapshot by installing your package globally: npm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260409214500Caution After installing, validate the version by running |

Stack context
This stack is not trying to reduce Shopify CLI's supported package managers or preserve every detail of npm's local-prefix behavior.
The real problem is that Shopify CLI answers several different package-manager questions through helpers that are too broad for the caller's intent.
The end state is to make callers choose intent, not implementation. Concretely, the codebase needs clearer helper boundaries for:
This PR establishes the directory-local execution boundary for function GraphQL typegen.
What
Use the function directory to choose the package manager for the default JavaScript GraphQL typegen path instead of always running
npm exec.Add a
cli-kithelper that builds the right command for running a project binary from a directory, and use it frombuildGraphqlTypes.Why
The current typegen path hardcodes
npm, which breaks apps whose function directories are managed bypnpm,yarn, orbun.This keeps the fix scoped to the function typegen problem. It does not change the broader
getPackageManager(...)contract for other callers.How
packageManagerBinaryCommandForDirectory(...)walks up from the function directory, looks for package-manager markers such as lockfiles andpnpm-workspace.yaml, and returns the right command shape fornpm,pnpm,yarn, orbun.Testing
To test manually:
pnpm,yarn, orbunshopify app function buildnpm