fix(cli-kit): respect package manager when installNodeModules adds specific packages#7299
Open
andromia3 wants to merge 1 commit intoShopify:mainfrom
Open
fix(cli-kit): respect package manager when installNodeModules adds specific packages#7299andromia3 wants to merge 1 commit intoShopify:mainfrom
andromia3 wants to merge 1 commit intoShopify:mainfrom
Conversation
…ecific packages (Shopify#7042) `installNodeModules()` always ran `<pm> install <args>`, but `yarn`, `pnpm`, and `bun` all require the `add` subcommand to install a specific package with a version specifier — their `install` subcommand installs from the lockfile. So a call like installNodeModules({packageManager: 'yarn', args: ['@shopify/hydrogen@2025.7.1']}) produced `yarn install @shopify/hydrogen@2025.7.1`, which yarn rejects. The same applied to pnpm. Hydrogen PR Shopify#3462 worked around this by bypassing `installNodeModules()` with a direct `exec()` call that mapped the subcommand per package manager; this upstream fix lets that workaround be removed. Rather than silently change the meaning of `args` (which breaks `init/template/npm.ts`, which uses it for flags like `['--network-concurrency', '1']`), added a new optional `packages?: string[]` field to `InstallNodeModulesOptions`. When `packages` is provided: - `npm` keeps using `install` (no change, and npm supports both). - `yarn`, `pnpm`, and `bun` use `add`, matching the existing internal helpers `argumentsToAddDependenciesWith{Yarn,PNPM,Bun}` further down the same file. When `packages` is omitted the function behaves identically to the old implementation, so every existing call site is unaffected. Added six new tests in `node-package-manager.test.ts` covering: - npm with packages (`install`) - yarn with packages (`add`) - pnpm with packages (`add`) - bun with packages (`add`) - packages + args ordering (packages first, then flags) - yarn with `args` only (no packages) — unchanged `install` behaviour Fixes Shopify#7042.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
WHY are these changes introduced?
Fixes #7042.
`installNodeModules()` in `packages/cli-kit/src/public/node/node-package-manager.ts` always ran ` install `, but `yarn`, `pnpm`, and `bun` all require the `add` subcommand to install a specific package with a version specifier — their `install` subcommand installs from the lockfile.
So a call like
```ts
installNodeModules({packageManager: 'yarn', args: ['@shopify/hydrogen@2025.7.1']})
```
produced `yarn install @shopify/hydrogen@2025.7.1`, which yarn rejects. Same for pnpm. Hydrogen PR #3462 worked around this by bypassing `installNodeModules()` with a direct `exec()` call that mapped the subcommand per package manager; this upstream fix lets that workaround be removed (@kdaviduik's original suggestion).
WHAT is this pull request doing?
Rather than silently change the meaning of `args` — which would break `packages/app/src/cli/services/init/template/npm.ts`, the only other call site, which uses `args` for flags like `['--network-concurrency', '1']` — added a new optional `packages?: string[]` field to `InstallNodeModulesOptions`.
When `packages` is provided:
When `packages` is omitted the function behaves identically to before, so every existing call site is unaffected.
```diff
if (options.args) {
args = args.concat(options.args)
}
```
Full-path trace
How to test your changes?
Six new tests in `packages/cli-kit/src/public/node/node-package-manager.test.ts`:
Run locally:
```bash
pnpm --filter @shopify/cli-kit test node-package-manager
```
Post-release steps
None in this repo. Downstream note: Hydrogen's `upgrade.ts` workaround can be removed once this change ships in a `@shopify/cli-kit` release and a matching Hydrogen PR is opened.
Checklist