Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --use-yarn flag to create-next-app #49407

Merged
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/api-reference/create-next-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ Options:

Explicitly tell the CLI to bootstrap the app using pnpm

--use-yarn

Explicitly tell the CLI to bootstrap the app using Yarn

-e, --example [name]|[github-url]

An example to bootstrap the app with. You can use an example name
Expand Down
4 changes: 4 additions & 0 deletions packages/create-next-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Options:

Explicitly tell the CLI to bootstrap the app using pnpm

--use-yarn

Explicitly tell the CLI to bootstrap the app using Yarn

-e, --example [name]|[github-url]

An example to bootstrap the app with. You can use an example name
Expand Down
9 changes: 9 additions & 0 deletions packages/create-next-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ const program = new Commander.Command(packageJson.name)
`

Explicitly tell the CLI to bootstrap the application using pnpm
`
)
.option(
'--use-yarn',
`

Explicitly tell the CLI to bootstrap the application using Yarn
`
)
.option(
Expand Down Expand Up @@ -134,6 +141,8 @@ const packageManager = !!program.useNpm
? 'npm'
: !!program.usePnpm
? 'pnpm'
: !!program.useYarn
? 'yarn'
: getPkgManager()

async function run(): Promise<void> {
Expand Down
73 changes: 73 additions & 0 deletions test/integration/create-next-app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,79 @@ describe('create next app', () => {
})
})

it('should use Yarn as the package manager on supplying --use-yarn', async () => {
await useTempDir(async (cwd) => {
const projectName = 'use-yarn'
const res = await run(
[
projectName,
'--js',
'--no-tailwind',
'--eslint',
'--use-yarn',
'--no-src-dir',
'--app',
`--import-alias=@/*`,
],
{
cwd,
}
)

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files: [
'package.json',
'app/page.js',
'.gitignore',
'.eslintrc.json',
'yarn.lock',
'node_modules/next',
],
})
})
})

it('should use Yarn as the package manager on supplying --use-yarn with example', async () => {
try {
await execa('yarn', ['--version'])
} catch (_) {
// install yarn if not available
await execa('npm', ['i', '-g', 'yarn'])
}

await useTempDir(async (cwd) => {
const projectName = 'use-yarn'
const res = await run(
[
projectName,
'--js',
'--no-tailwind',
'--eslint',
'--use-yarn',
'--example',
`${exampleRepo}/${examplePath}`,
],
{ cwd }
)

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files: [
'package.json',
'pages/index.tsx',
'.gitignore',
'yarn.lock',
'node_modules/next',
],
})
})
})

it('should use pnpm as the package manager on supplying --use-pnpm', async () => {
await useTempDir(async (cwd) => {
const projectName = 'use-pnpm'
Expand Down