Skip to content

Use execa over spawn#48

Merged
lopert merged 1 commit intomainfrom
lopert.execa
Feb 5, 2026
Merged

Use execa over spawn#48
lopert merged 1 commit intomainfrom
lopert.execa

Conversation

@lopert
Copy link
Collaborator

@lopert lopert commented Feb 5, 2026

Problem

The test helpers fail on Windows because child_process.spawn() cannot resolve .cmd files (which npm uses for executables on Windows). This causes the library to fail when trying to execute the Shopify CLI on Windows systems. (#46)

Solution

Shopify CLI also has cross-platform requirements, so I looked at that repo for a solution. Instead of using spawn, it instead uses execa.
This PR migrates us from child_process.spawn to execa (version 7.2.0, matching Shopify CLI).

Changes

Implementation

  • Added dependency: execa@^7.2.0 to package.json
  • Updated build-function.ts: Replaced spawn with execa, maintained exact error message compatibility
  • Updated get-function-info.ts: Replaced spawn with execa, maintained exact error message compatibility

Tests

  • Updated test mocks: Changed from EventEmitter-based spawn mocks to simple promise-based execa mocks
  • Maintained behavior: All error messages and throwing behavior remain identical for backward compatibility

Tophat 🎩

  • Clone the repo, checkout this branch.
  • pnpm install
  • pnpm pack -> should give you a tarball.
  • In a standalone app/function, update the function's devDependency to point at the tarball. Something like:
  "devDependencies": {
    "@shopify/shopify-function-test-helpers": "file:/Users/lopert/src/github.com/Shopify/shopify-function-test-helpers/shopify-shopify-function-test-helpers-1.0.0.tgz",
    "vitest": "^3.2.4"
  }
  • confirm the code that was pulled into the node_modules of the app/function contains the updated execa using code.
  • run npx vitest run

Alternative

We could pass the shell arg to spawn when on windows, #47

@lopert lopert force-pushed the lopert.execa branch 2 times, most recently from d24373f to cd1414a Compare February 5, 2026 17:17
@lopert lopert changed the title [WIP] use execa Use execa over spawn Feb 5, 2026
@lopert lopert requested a review from saga-dasgupta February 5, 2026 18:30
Copy link
Contributor

@saga-dasgupta saga-dasgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for fixing this.

@lopert lopert merged commit d66b1fb into main Feb 5, 2026
11 checks passed
@lopert lopert mentioned this pull request Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants