Unverified Commit 428342db authored by Anders Kjær Damgaard's avatar Anders Kjær Damgaard Committed by GitHub

Add `--use-yarn` flag to `create-next-app` (#49407)

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

fixes #49405

- [x] Implement `--use-yarn` flag
- [x] Update docs
- [x] Add tests
Co-authored-by: 's avatarTobias Koppers <tobias.koppers@googlemail.com>
parent 54ea0d95
...@@ -77,6 +77,10 @@ Options: ...@@ -77,6 +77,10 @@ Options:
Explicitly tell the CLI to bootstrap the app using pnpm 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] -e, --example [name]|[github-url]
An example to bootstrap the app with. You can use an example name An example to bootstrap the app with. You can use an example name
......
...@@ -49,6 +49,10 @@ Options: ...@@ -49,6 +49,10 @@ Options:
Explicitly tell the CLI to bootstrap the app using pnpm 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] -e, --example [name]|[github-url]
An example to bootstrap the app with. You can use an example name An example to bootstrap the app with. You can use an example name
......
...@@ -99,6 +99,13 @@ const program = new Commander.Command(packageJson.name) ...@@ -99,6 +99,13 @@ const program = new Commander.Command(packageJson.name)
` `
Explicitly tell the CLI to bootstrap the application using pnpm Explicitly tell the CLI to bootstrap the application using pnpm
`
)
.option(
'--use-yarn',
`
Explicitly tell the CLI to bootstrap the application using Yarn
` `
) )
.option( .option(
...@@ -134,6 +141,8 @@ const packageManager = !!program.useNpm ...@@ -134,6 +141,8 @@ const packageManager = !!program.useNpm
? 'npm' ? 'npm'
: !!program.usePnpm : !!program.usePnpm
? 'pnpm' ? 'pnpm'
: !!program.useYarn
? 'yarn'
: getPkgManager() : getPkgManager()
async function run(): Promise<void> { async function run(): Promise<void> {
......
...@@ -536,6 +536,79 @@ describe('create next app', () => { ...@@ -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 () => { it('should use pnpm as the package manager on supplying --use-pnpm', async () => {
await useTempDir(async (cwd) => { await useTempDir(async (cwd) => {
const projectName = 'use-pnpm' const projectName = 'use-pnpm'
......
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