Skip to content

Commit

Permalink
Fix create-next-app failing without yarn installed (#35608)
Browse files Browse the repository at this point in the history
This fixes our package manager detection which was changed slightly in #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: #35607
Fixes: #35599
  • Loading branch information
ijjk committed Mar 26, 2022
1 parent d41f8a5 commit 3a313a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/create-next-app/index.ts
Expand Up @@ -129,7 +129,7 @@ async function run(): Promise<void> {
? 'npm'
: !!program.usePnpm
? 'pnpm'
: 'yarn'
: getPkgManager()

const example = typeof program.example === 'string' && program.example.trim()
try {
Expand Down
25 changes: 24 additions & 1 deletion test/integration/create-next-app/index.test.ts
Expand Up @@ -305,7 +305,30 @@ describe('create next app', () => {

it('should create a project in the current directory', async () => {
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)

const files = [
Expand Down

0 comments on commit 3a313a4

Please sign in to comment.