Skip to content

Commit

Permalink
Add --use-yarn flag to create-next-app (#49407)
Browse files Browse the repository at this point in the history
# Add `--use-yarn` flag to `create-next-app`

fixes #49405

- [x] Implement `--use-yarn` flag
- [x] Update docs
- [x] Add tests

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
  • Loading branch information
akd-io and sokra committed May 10, 2023
1 parent 54ea0d9 commit 428342d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
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

0 comments on commit 428342d

Please sign in to comment.