aws-amplify / aws-amplify/amplify-cli
improve Node.js package manager detection
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### Is this feature request related to a new or existing Amplify category?
_No response_
### Is this related to another service?
_No response_
### Describe the feature you'd like to request
Improve detection of the developer's chosen Node.js package manager, which applies to the following workflows:
- auto-installing Node.js Function dependencies on build/push
- auto-installing dependencies in the [Sandbox workflow](https://sandbox.amplifyapp.com/)
examples:
- Next.js is looking at `process.env.npm_config_user_agent` https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/get-pkg-manager.ts
- Vite is looking at `process.env.npm_config_user_agent` https://github.com/vitejs/vite/blob/main/packages/create-vite/src/index.ts#L312
- https://www.npmjs.com/package/preferred-pm
- [Astro is using a package](https://github.com/withastro/astro/blob/main/packages/create-astro/package.json#L46), https://www.npmjs.com/package/which-pm-runs
### Describe the solution you'd like
Amplify CLI automatically detects the package manager of choice for JavaScript projects
```ts
// https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/get-pkg-manager.ts
export type PackageManager = 'npm' | 'pnpm' | 'yarn'
export function getPkgManager(): PackageManager {
const userAgent = process.env.npm_config_user_agent
if (userAgent) {
if (userAgent.startsWith('yarn')) {
return 'yarn'
} else if (userAgent.startsWith('pnpm')) {
return 'pnpm'
} else {
return 'npm'
}
} else {
return 'npm'
}
}
```
### Describe alternatives you've considered
n/a
### Additional context
- https://github.com/aws-amplify/amplify-cli/issues/6382
- https://github.com/aws-amplify/amplify-cli/issues/4830
- https://github.com/aws-amplify/amplify-cli/issues/6035
- https://github.com/aws-amplify/amplify-cli/issues/9726
### Is this something that you'd be interested in working on?
- [ ] 👋 I may be able to implement this feature request
### Would this feature include a breaking change?
- [ ] ⚠️ This feature might incur a breaking change
Contributor guide
Research direction
Start by tracing the CLI paths for auto-installing Node.js Function dependencies during build/push and dependency installation in the Sandbox workflow. Review the referenced npm_config_user_agent approach and package-manager examples, then verify that JavaScript projects consistently detect npm, pnpm, or yarn in both workflows.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- cli, developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100