Functions 'schema' and 'replay' commands - fix dependence on `.env`
WHY are these changes introduced?
Fixes: https://github.com/Shopify/shopify-functions/issues/411
WHAT is this pull request doing?
Summary of Changes
This PR addresses an issue where the absence of a .env file (and consequently an API key) triggers a prompt for the user to select an app every time a command is executed. This behavior is due to the condition checked in the following code segment: https://github.com/Shopify/cli/blob/037598517bc4cc282ac57dd841fcdbe71034e346/packages/app/src/cli/services/generate-schema.ts#L40.
Proposed Solution
To resolve this, the solution I have currently, uses the already fetched API key (using an existing call with fetchOrCreateOrganizationApp), and we cache that data using setCachedAppInfo (from here)
With this change, once the API key is cached, subsequent command executions will not prompt the user to select an organization, thereby streamlining the workflow.
How to Test Your Changes
-
Ensure that there is no
.envfile in your app directory. -
Execute the schema command:
SHOPIFY_CLI_ENABLE_APP_LOG_POLLING=1 NODE_TLS_REJECT_UNAUTHORIZED=0 SPIN=1 SPIN_INSTANCE=XXX pnpm run shopify app function schema --path=./app-name -
Execute the replay command:
SHOPIFY_CLI_ENABLE_APP_LOG_POLLING=1 NODE_TLS_REJECT_UNAUTHORIZED=0 SPIN=1 SPIN_INSTANCE=XXX pnpm run shopify app function replay --path=./app-name
During a new cli replay or schema command run, you will encounter the app selection prompt. However, for subsequent runs, the cli should use the cached API key, bypassing the need for manual selection.
TODO: current just setting the apikey as the appId
Notes:
- better way to get and store api key, do we create an
.envfor them? - currently i just set it on the appId
Post-release steps
Measuring impact
How do we know this change was effective? Please choose one:
- [ ] n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
- [ ] Existing analytics will cater for this addition
- [ ] PR includes analytics changes to measure impact
Checklist
- [ ] I've considered possible cross-platform impacts (Mac, Linux, Windows)
- [ ] I've considered possible documentation changes
Thanks for your contribution!
Depending on what you are working on, you may want to request a review from a Shopify team:
- Themes: @shopify/advanced-edits
- UI extensions: @shopify/ui-extensions-cli
- Checkout UI extensions: @shopify/checkout-ui-extensions-api-stewardship
- Hydrogen: @shopify/hydrogen
- Other: @shopify/app-inner-loop
Coverage report
St.:grey_question: |
Category | Percentage | Covered / Total |
|---|---|---|---|
| π‘ | Statements | 72.6% (-0.05% π») |
8523/11739 |
| π‘ | Branches | 69.53% (-0.11% π») |
4178/6009 |
| π‘ | Functions | 71.61% (-0.06% π») |
2205/3079 |
| π‘ | Lines | 72.92% (-0.06% π») |
8065/11060 |
Show files with reduced coverage π»
St.:grey_question: |
File | Statements | Branches | Functions | Lines |
|---|---|---|---|---|---|
| π΄ | ... / dev.ts |
9.65% (-10.35% π») |
1.56% (-13.36% π») |
15.79% (-8.6% π») |
9.52% (-11.35% π») |
| π’ | ... / ConcurrentOutput.tsx |
98.39% (-1.61% π») |
90.91% (-4.55% π») |
100% | 98.33% (-1.67% π») |
Test suite run success
1940 tests passing in 873 suites.
Report generated by π§ͺjest coverage report action from ad69102bca86ea068368b8fae87b3c02e867e192
We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset. If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.