diff --git a/packages/create-next-app/index.ts b/packages/create-next-app/index.ts index 8d7f25427610..3c16c40a7dd6 100644 --- a/packages/create-next-app/index.ts +++ b/packages/create-next-app/index.ts @@ -129,7 +129,7 @@ async function run(): Promise { ? 'npm' : !!program.usePnpm ? 'pnpm' - : 'yarn' + : getPkgManager() const example = typeof program.example === 'string' && program.example.trim() try { diff --git a/test/integration/create-next-app/index.test.ts b/test/integration/create-next-app/index.test.ts index 1f68f56875c0..b0707196dedf 100644 --- a/test/integration/create-next-app/index.test.ts +++ b/test/integration/create-next-app/index.test.ts @@ -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 = [