-
Notifications
You must be signed in to change notification settings - Fork 0
Reworking runFunction to invoke function-runner directly #30
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0f77e16
Using function runner directly
saga-dasgupta fe12442
using info command to get relevant info from CLI
saga-dasgupta 711d863
target based query selection and adding a second target and fixture f…
saga-dasgupta e24dd93
moving function info to a helper method
saga-dasgupta 9a7a806
making it spawn instead of execsync because thats what we have used i…
saga-dasgupta bfbf934
reformating run-function args and function runner output handling
saga-dasgupta 95b7712
tests for get-function-info method
saga-dasgupta 6f7ce70
Simplifying import and mocking for spawn, deconstructing getFunctionI…
saga-dasgupta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /** | ||
| * Retrieve function information from the Shopify CLI | ||
| */ | ||
|
|
||
| import { spawn } from 'child_process'; | ||
| import path from 'path'; | ||
|
|
||
| /** | ||
| * Information about a Shopify function | ||
| */ | ||
| export interface FunctionInfo { | ||
| schemaPath: string; | ||
| functionRunnerPath: string; | ||
| wasmPath: string; | ||
| targeting: Record<string, any>; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves function information from the Shopify CLI | ||
| * @param {string} functionDir - The directory path of the function | ||
| * @returns {Promise<FunctionInfo>} Function information including schemaPath, functionRunnerPath, wasmPath, and targeting | ||
| * @throws {Error} If the CLI command is not available or fails | ||
| */ | ||
| export async function getFunctionInfo(functionDir: string): Promise<FunctionInfo> { | ||
| const resolvedFunctionDir = path.resolve(functionDir); | ||
| const appRootDir = path.dirname(resolvedFunctionDir); | ||
| const functionName = path.basename(resolvedFunctionDir); | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
| const shopifyProcess = spawn('shopify', [ | ||
| 'app', 'function', 'info', | ||
| '--json', | ||
| '--path', functionName | ||
| ], { | ||
| cwd: appRootDir, | ||
| stdio: ['pipe', 'pipe', 'pipe'] | ||
| }); | ||
|
|
||
| let stdout = ''; | ||
| let stderr = ''; | ||
|
|
||
| shopifyProcess.stdout.on('data', (data) => { | ||
| stdout += data.toString(); | ||
| }); | ||
|
|
||
| shopifyProcess.stderr.on('data', (data) => { | ||
| stderr += data.toString(); | ||
| }); | ||
|
|
||
| shopifyProcess.on('close', (code) => { | ||
| if (code !== 0) { | ||
| // Check if the error is due to the command not being found | ||
| if (stderr.includes('Command app function info not found') || stderr.includes('command not found')) { | ||
| reject(new Error( | ||
| 'The "shopify app function info" command is not available in your CLI version.\n' + | ||
| 'Please upgrade to the latest version:\n' + | ||
| ' npm install -g @shopify/cli@latest\n\n' | ||
| )); | ||
| return; | ||
| } | ||
| reject(new Error(`Function info command failed with exit code ${code}: ${stderr}`)); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const functionInfo = JSON.parse(stdout.trim()) as FunctionInfo; | ||
| resolve(functionInfo); | ||
| } catch (error) { | ||
| const errorMessage = error instanceof Error ? error.message : String(error); | ||
| reject(new Error(`Failed to parse function info JSON: ${errorMessage}\nOutput: ${stdout}`)); | ||
| } | ||
| }); | ||
|
|
||
| shopifyProcess.on('error', (error) => { | ||
| reject(new Error(`Failed to start shopify function info command: ${error.message}`)); | ||
| }); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
test-app/extensions/cart-validation-js/tests/fixtures/cda6d1.json
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
test-app/extensions/cart-validation-js/tests/fixtures/checkout-validation-valid-fixture.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just renamed this file, I dont know why it doesn't show as a rename. |
||
| "payload": { | ||
| "export": "cart-validations-generate-run", | ||
| "target": "cart.validations.generate.run", | ||
| "input": { | ||
| "cart": { | ||
| "lines": [ | ||
| { | ||
| "quantity": 1 | ||
| }, | ||
| { | ||
| "quantity": 1 | ||
| }, | ||
| { | ||
| "quantity": 1 | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "output": { | ||
| "operations": [{ "validationAdd": { "errors": [] } }] | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.