Unverified Commit 3a313a4c authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix create-next-app failing without yarn installed (#35608)

This fixes our package manager detection which was changed slightly in https://github.com/vercel/next.js/pull/34947 for `pnpm` support to ensure the default case still attempts detecting the available package manager if no preference is specified in the command args. This also adds a test case to ensure the install succeeds when we fail to detect a valid `yarn` binary and no preference is set via the `npm_config_user_agent` env variable. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: https://github.com/vercel/next.js/issues/35607
Fixes: https://github.com/vercel/next.js/issues/35599
parent d41f8a5e
...@@ -129,7 +129,7 @@ async function run(): Promise<void> { ...@@ -129,7 +129,7 @@ async function run(): Promise<void> {
? 'npm' ? 'npm'
: !!program.usePnpm : !!program.usePnpm
? 'pnpm' ? 'pnpm'
: 'yarn' : getPkgManager()
const example = typeof program.example === 'string' && program.example.trim() const example = typeof program.example === 'string' && program.example.trim()
try { try {
......
...@@ -305,7 +305,30 @@ describe('create next app', () => { ...@@ -305,7 +305,30 @@ describe('create next app', () => {
it('should create a project in the current directory', async () => { it('should create a project in the current directory', async () => {
await usingTempDir(async (cwd) => { await usingTempDir(async (cwd) => {
const res = await run(['.'], { cwd }) const env = { ...process.env }
const tmpBin = path.join(__dirname, 'bin')
const tmpYarn = path.join(tmpBin, 'yarn')
if (process.platform !== 'win32') {
// ensure install succeeds with invalid yarn binary
// which simulates no yarn binary being available as
// an alternative to removing the binary and reinstalling
await fs.remove(tmpBin)
await fs.mkdir(tmpBin)
await fs.writeFile(tmpYarn, '#!/bin/sh\nexit 1')
await fs.chmod(tmpYarn, '755')
env.PATH = `${tmpBin}:${env.PATH}`
delete env.npm_config_user_agent
}
const res = await run(['.'], {
cwd,
env,
extendEnv: false,
stdio: 'inherit',
})
await fs.remove(tmpBin)
expect(res.exitCode).toBe(0) expect(res.exitCode).toBe(0)
const files = [ const files = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment