Skip to content

Run @shopify/shopify_function's check before building JavaScript functions - #8829

Closed
saga-dasgupta wants to merge 1 commit into
mainfrom
sd.prepare_variables_check
Closed

saga-dasgupta wants to merge 1 commit into
mainfrom
sd.prepare_variables_check

Conversation

@saga-dasgupta

@saga-dasgupta saga-dasgupta commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

A JavaScript function's prepare target returns variables for its run target's input query, and nothing checks them. The earlier version of this PR checked them in the CLI at deploy, so the check, and any change to it, lived in the CLI.

WHAT is this pull request doing?

Before building a JavaScript function, the CLI runs check.js from the function's @shopify/shopify_function, when the package has it. It passes a JSON file describing the function: its handle, directory, entry and schema, and each target's input query and the export the bundle imports. If the check fails, so does the build, including in app dev and app deploy:

The function extension "delivery-customization" returns prepare variables its run query doesn't accept
src/cart_delivery_options_transform_prepare.js:26:23 `variables.ruleQueri` isn't declared by src/cart_delivery_options_transform_run.graphql

The checker this PR used to add now lives in the package (Shopify/shopify-function-javascript#140), so changes to it ship by updating the package. Warnings the package prints, such as for variables it can't check, don't stop the build. Code generation is unchanged, and packages without check.js build as before.

How to test your changes?

  1. Pack Fail the build when a prepare target's variables don't match its run query shopify-function-javascript#140 (gh pr checkout 140 && npm pack). Install the tarball as @shopify/shopify_function in a JavaScript function with prepare and run targets.
  2. Misspell a variable the prepare target returns, and run shopify app function build from a /snapit build. It fails, naming the file, line and variable.
  3. Fix it. It builds.

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing — I've identified the correct bump type (patch for bug fixes · minor for new features · major for breaking changes) and added a changeset with pnpm changeset add

@github-actions github-actions Bot added the Area: @shopify/cli @shopify/cli package issues label Oct 7, 2026
@saga-dasgupta

Copy link
Copy Markdown
Contributor Author

/snapit

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

🫰✨ Thanks @saga-dasgupta! Your snapshot has been published to npm.

Built from a22f4cac9a3143405e041d7877601c00b1868708. Workflow run.

Test the snapshot by installing your package globally:

pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20261008004212

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

@Shopify Shopify deleted a comment from github-actions Bot Oct 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

This PR seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action.
→ If there's no activity within a week, then a bot will automatically close this.
Thanks for helping to improve Shopify's dev tooling and experience.

@saga-dasgupta
saga-dasgupta force-pushed the sd.prepare_variables_check branch from a22f4ca to 2f6337f Compare November 9, 2026 15:56
@saga-dasgupta
saga-dasgupta force-pushed the sd.prepare_variables_check branch from 2f6337f to 82a033c Compare November 10, 2026 16:47
saga-dasgupta added a commit to Shopify/shopify-function-javascript that referenced this pull request Nov 10, 2026
Add typegen.js, which Shopify CLI runs instead of graphql-code-generator
when this package has it (Shopify/cli#8829). It generates the function's
types with the codegen plugins this package depends on, gives each prepare
result's variables its run query's variables type, and exits non-zero,
failing the build, when a prepare target returns variables its run query
doesn't accept.

The check is moved here from Shopify/cli#8829: it follows what the prepare
export returns, ignoring type annotations and casts, and validates it
against the run query's variable definitions.
@saga-dasgupta saga-dasgupta changed the title Check JavaScript function prepare variables against the run query on deploy Let @shopify/shopify_function generate JavaScript function types Nov 10, 2026
@saga-dasgupta
saga-dasgupta force-pushed the sd.prepare_variables_check branch from 82a033c to 668c0b1 Compare November 10, 2026 16:56
saga-dasgupta added a commit to Shopify/shopify-function-javascript that referenced this pull request Nov 10, 2026
…query

Add typegen.js, which Shopify CLI runs instead of graphql-code-generator
when this package has it (Shopify/cli#8829). It generates the function's
types with the codegen plugins this package depends on, whatever the app's
package manager hoists. It then exits non-zero, failing the build, when a
prepare target returns variables its run query doesn't accept.

The check is moved here from Shopify/cli#8829: it follows what the prepare
export returns, ignoring type annotations and casts, and validates it
against the run query's variable definitions.
saga-dasgupta added a commit to Shopify/shopify-function-javascript that referenced this pull request Nov 10, 2026
…query

Add check.js, which Shopify CLI runs before building a JavaScript function
when this package has it (Shopify/cli#8829). It exits non-zero, failing the
build, when a prepare target returns variables its run query doesn't
accept.

The check is moved here from Shopify/cli#8829: it follows what the prepare
export returns, ignoring type annotations and casts, and validates it
against the run query's variable definitions.
…nction

When the function's @shopify/shopify_function has check.js, run it before
generating types and bundling, with a JSON file describing the function:
its handle, directory, entry and schema, and each target's input query and
the export the bundle imports. The package fails the build when a prepare
target returns variables its run query doesn't accept.

Code generation is unchanged.
@saga-dasgupta
saga-dasgupta force-pushed the sd.prepare_variables_check branch from 668c0b1 to 690413e Compare November 10, 2026 20:24
@saga-dasgupta saga-dasgupta changed the title Let @shopify/shopify_function generate JavaScript function types Run @shopify/shopify_function's check before building JavaScript functions Nov 10, 2026
saga-dasgupta added a commit to Shopify/shopify-function-javascript that referenced this pull request Nov 10, 2026
…query

Add check.js, which Shopify CLI runs before building a JavaScript function
when this package has it (Shopify/cli#8829). It exits non-zero, failing the
build, when a prepare target returns variables its run query doesn't
accept, and warns about variables it can't check.

The check is moved here from Shopify/cli#8829: it follows what the prepare
export returns, ignoring type annotations and casts, and validates it
against the run query's variable definitions. Values it can't follow, such
as parsed JSON, are warnings rather than errors, so valid code still
builds.
saga-dasgupta added a commit to Shopify/shopify-function-javascript that referenced this pull request Nov 10, 2026
…query

Add check.js, which Shopify CLI runs before building a JavaScript function
when this package has it (Shopify/cli#8829). It exits non-zero, failing the
build, when a prepare target returns variables its run query doesn't
accept, and warns about variables it can't check.

The check is moved here from Shopify/cli#8829: it follows what the prepare
export returns, ignoring type annotations and casts, and validates it
against the run query's variable definitions. Values it can't follow, such
as parsed JSON, are warnings rather than errors, so valid code still
builds.
saga-dasgupta added a commit to Shopify/shopify-function-javascript that referenced this pull request Nov 12, 2026
…query

Add check.js, which Shopify CLI runs before building a JavaScript function
when this package has it (Shopify/cli#8829). It exits non-zero, failing the
build, when a prepare target returns variables its run query doesn't
accept, and warns about variables it can't check.

The check is moved here from Shopify/cli#8829: it follows what the prepare
export returns, ignoring type annotations and casts, and validates it
against the run query's variable definitions. Values it can't follow, such
as parsed JSON, are warnings rather than errors, so valid code still
builds.
saga-dasgupta added a commit to Shopify/shopify-function-javascript that referenced this pull request Nov 12, 2026
…query

Add check.js, which Shopify CLI runs before building a JavaScript function
when this package has it (Shopify/cli#8829). It exits non-zero, failing the
build, when a prepare target returns variables its run query doesn't
accept, and warns about variables it can't check.

The check is moved here from Shopify/cli#8829: it follows what the prepare
export returns, ignoring type annotations and casts, and validates it
against the run query's variable definitions. Values it can't follow, such
as parsed JSON, are warnings rather than errors, so valid code still
builds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: @shopify/cli @shopify/cli package issues no-pr-activity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants