Commit graph

43 commits

Author SHA1 Message Date
Colin McDonnell
57ce466502
Add --use-bun to create-next-app (#53467)
This adds support for `--use-bun` to `create-next-app` to use `bun
install` when bootstrapping a new project.

```
npx create-next-app --use-bun
```

As with Yarn and pnpm, it reads from `npm_config_user_agent` to
determine if the user ran `bunx create-next-app`. If so, it defaults to
using Bun.

```sh
bunx create-next-app
```

## For Contributors

### Improving Documentation

- [x] Run `pnpm prettier-fix`
- [x] `pnpm build && pnpm lint` 
- [x] Added test to
`test/integration/create-next-app/package-manager.test.ts`

---------
2023-08-03 18:00:38 -07:00
Sukka
127e30ed42
refactor(cna): make create-next-app even smaller (#53241)
The PR follows #53146 and #53115.

The PR does 3 things:

- Replaces a [very heavy dependency `cpy`](https://github.com/vercel/next.js/pull/53146#issuecomment-1649193789) with a more lightweight copy helper.
  - The `fs.cp(src, dest, {recursive: true})` API is not used, as it is still experimental:
  <img width="1630" alt="image" src="https://github.com/vercel/next.js/assets/40715044/c61a454a-3a96-4658-a389-fbb68c241f18">
- Update `cross-spawn` to the latest version `7.0.3`
  - The only breaking change introduced in `cross-spawn@7.x` is dropping Node.js 8 supports, which allows `cross-spawn` to drop a dependency. Since `create-next-app` requires Node.js 16.8.0, I assume bumping `cross-spawn` would be safe.
- Update `fast-glob` to the latest version `3.3.1` to remove more KiBs (pointed out by @imranbarbhuiya)
  - The breaking change introduced in `fast-glob@3.x` is dropping Node.js 8 supports and some options changes.

Together the PR removes another 202 KiB from the `create-next-app/dist/index.js`. The size of `create-next-app/dist/index.js` is now 616 KiB.

<img width="583" alt="image" src="https://github.com/vercel/next.js/assets/40715044/4deb5e36-a63b-4501-b67c-29ea06e30578">
2023-07-28 17:21:58 +00:00
Sukka
66ffc3cd39
refactor(cna): replace chalk with picocolors, glob with fast-glob@2.2.7 (#53146)
Follows #53115

- Replace `chalk` with `picocolors`
  - Note that `chalk.hex('#007acc')` has been replaced with `picocolors.blue`
- Replace `glob` with `fast-glob@2.2.7`
  - Not only does `fast-glob` is a faster drop-in replacement of `glob` with first-party `Promise`-based API support, but also `fast-glob` is already a dependency of `cpy`:
 
  <img width="812" alt="image" src="https://github.com/vercel/next.js/assets/40715044/8efa24c4-5312-4b1c-bf8d-68255ca30b60">


Together the PR removes about `50 KiB` from the `create-next-app/dist/index.js`:

<img width="570" alt="image" src="https://github.com/vercel/next.js/assets/40715044/db2f3723-14cc-48ce-9cb2-8aa1fb1d5e95">


Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-07-26 18:16:13 +00:00
vinay
c2d7bbd1b8
change(create-next-app): Get-pkg-manager logic change. (#50372)
Simplified Get-pkg-manager logic.

---------

Co-authored-by: Steven <steven@ceriously.com>
2023-06-05 19:31:10 -04:00
Abhishek Kadam
a8621c7bb2
[create-next-app]: respecting the user's init.defaultBranch git con… (#49960)
### What?
This commit makes sure `create-next-app` doesn't ignore user's git configuration (`init.defaultBranch`).
### Why?
Hard coding configurations of a user is annoying (for the user).


Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-05-20 23:53:58 +00:00
Steven
11a7117d40
chore: cross-platform rm -rf script (#49529)
- Closes https://github.com/vercel/next.js/issues/42433
- Closes https://github.com/vercel/next.js/pull/43105
- Closes https://github.com/vercel/next.js/pull/49522
2023-05-10 01:14:37 +00:00
JJ Kasper
b0d951bccd
Fix nested example setup with create-next-app (#45390)
Noticed in https://github.com/vercel/next.js/pull/45387 we aren't
properly setting up nested examples due to not stripping to the right
level so this ensures we handle that case properly.
2023-01-29 11:54:28 -08:00
Julius Marminge
9f93d34061
fix: create-next-app copies files it shouldn't (#43131)
<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

Closes #43130

This fixes the bug where the CLI copies files it shouldn't, by adding a
`/` separator at the end of the directory name.

Given `examples/next-prisma-starter` and
`examples/next-prisma-starter-websockets`, only files inside the
`examples/next-prisma-starter` will now be copied.

Here is a repo created by the CLI after this fix, using

```bash
# Inside packages/create-next-app
pnpm build
node dist/index.js --example https://github.com/trpc/trpc --example-path examples/next-prisma-starter
```

https://github.com/juliusmarminge/create-next-app-bugfix

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-11-21 16:51:57 -08:00
Néstor
5cd31e41ca
Add npm to create-next-app environment package manager parser (#41279)
Gracefully parse the environment package manager when calling
`create-next-app` instead of passing extra arguments.

Reference: #41090

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

Co-authored-by: Balázs Orbán <info@balazsorban.com>
2022-10-13 14:34:55 -07:00
Balázs Orbán
a4ff041242
fix(cli): tune filter for extracting example .tar (#40513)
As pointed out in
https://github.com/vercel/next.js/issues/40389#issuecomment-1243039792,
the `filter` matched more files than necessary and merged different
example directories together. This change makes the filter match the
example directory name precisely.

Fixes #40389

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-09-13 13:51:44 -07:00
Balázs Orbán
fa08a17768
fix(cli): delete temp file after extraction (#40259)
Follow-up on the review comment https://github.com/vercel/next.js/pull/40182#discussion_r963036314 since the PR was merged.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-09-06 11:29:25 +00:00
Balázs Orbán
5a04e82ba9
fix(cli): do not throw error when extracting examples in Node 18+ (#40182)
`create-next-app` currently cannot extract examples/git repos in Node 18+, because of an issue with `node-tar` (https://github.com/npm/node-tar/issues/321). The files are extracted, but an error is thrown that the stream has been prematurely closed. To prevent `create-next-app` from not being able to finish, ~for now, we can swallow this error, and hopefully `node-tar` will be patched soon.~
we can save the tar in the `tmp` folder and extract it from there as suggested: https://github.com/vercel/next.js/pull/40182#pullrequestreview-1095216714

I cannot reproduce this on earlier Node.js versions. More context: https://github.com/vercel/next.js/issues/39321#issuecomment-1235642058

Fixes #39321



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-09-05 16:11:12 +00:00
JJ Kasper
ec25b4742b
Add handling for auto installing TypeScript deps and HMRing tsconfig (#39838)
This adds handling for auto-detecting TypeScript being added to a project and installing the necessary dependencies instead of printing the command and requiring the user run the command. We have been testing the auto install handling for a while now with the `next lint` command and it has worked out pretty well. 

This also adds HMR handling for `jsconfig.json`/`tsconfig.json` in development so if the `baseURL` or `paths` configs are modified it doesn't require a dev server restart for the updates to be picked up. 

This also corrects our required dependencies detection as previously an incorrect `paths: []` value was being passed to `require.resolve` causing it to fail in specific situations.

Closes: https://github.com/vercel/next.js/issues/36201

### `next build` before

https://user-images.githubusercontent.com/22380829/186039578-75f8c128-a13d-4e07-b5da-13bf186ee011.mp4

### `next build` after


https://user-images.githubusercontent.com/22380829/186039662-57af22a4-da5c-4ede-94ea-96541a032cca.mp4

### `next dev` automatic setup and HMR handling

https://user-images.githubusercontent.com/22380829/186039678-d78469ef-d00b-4ee6-8163-a4706394a7b4.mp4


## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-08-23 13:16:47 -05:00
Sukka
7fe5c883fc
fix(create-app): support github url has trailing slash (#39665)
## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

The PR fixes #39642, by supporting GitHub repo URLs with a trailing slash while without branch and path.
2022-08-17 01:59:32 +00:00
Sicarius
b30ae643a4
Add yarn 2 Setup Files to Valid Files for create-next-app (#30936)
* added yarn 2 based files/dirs to valid files

* remove package.json

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-08-07 22:05:48 -05:00
Balázs Orbán
f15fb7c65a
feat(cli): support examples without package.json (#37910)
Previously our CLI assumed that when using an `--example` flag, the example contains a `package.json` file. There are examples though, like `with-docker-compose` which does not have one. In that case, we can simply clone the directory and show a success message.

<details>
<summary>
Full list of examples without <code>package.json</code>:
</summary>
<ul>
<li>custom-server</li>
<li>page-transitions</li>
<li>parameterized-routing</li>
<li>reproduction-template</li>
<li>with-chakra-ui-typescript</li>
<li>with-cookie-auth</li>
<li>with-docker-compose</li>
<li>with-dotenv</li>
<li>with-facebook-chat-plugin</li>
<li>with-firebase-authentication</li>
<li>with-firebase-authentication-serverless</li>
<li>with-glamorous</li>
<li>with-global-stylesheet</li>
<li>with-global-stylesheet-simple</li>
<li>with-graphql-faunadb</li>
<li>with-markdown</li>
<li>with-material-ui</li>
<li>with-next-auth</li>
<li>with-next-i18next</li>
<li>with-next-multilingual</li>
<li>with-next-routes</li>
<li>with-now-env</li>
<li>with-pretty-url-routing</li>
<li>with-prisma</li>
<li>with-redux-toolkit</li>
<li>with-redux-toolkit-typescript</li>
<li>with-sentry-simple</li>
<li>with-strict-csp-hash</li>
<li>with-styled-jsx-postcss</li>
<li>with-sw-precache</li>
<li>with-typescript-styled-components</li>
<li>with-universal-configuration-build-time</li>
<li>with-universal-configuration-runtime</li>
</ul>
</details>

Fixes #37884

In a follow-up PR, we can try to detect if an example contains a README.md file only, and if the example was moved, we could either try getting it from the new location or at least show a better message. (Eg.: using a magic comment that we can parse)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-06-23 17:28:14 +00:00
Andrew Matthews
f1d1c46b99
Fix example extraction when branch name contains slash (#37140)
* convert slashes to dashes for accurate filename

* Apply suggestions from code review

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-05-23 18:54:07 -05:00
Balázs Orbán
62c33c1eb7
feat: support pnpm with create-next-app (#34947)
* feat: support `pnpm` with `create-next-app`

* test: add `--use-pnpm` tests

* docs: mention `--use-pnpm` flag in docs

* test: remove `only`

* Update test/integration/create-next-app/index.test.ts

Co-authored-by: Steven <steven@ceriously.com>

* chore: add pnpm action setup to tests

* chore: use latest pnpm

* chore: debug

* chore: debug

* fix: fall back to `yarn` instead of `npm`

* test: run all tests

Co-authored-by: Steven <steven@ceriously.com>
2022-03-04 00:49:24 +01:00
zhoulixiang
6dfe02d22f
Optimize offline condition judgment (#33238)
* perf: optimize offline condition judgment

* lint-fix

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-02-02 10:17:29 -06:00
JJ Kasper
5544adc481
Update to latest babel versions (#28174) 2021-08-17 09:18:08 +02:00
JJ Kasper
c0a07aa9e0
Ensure CNA install succeeds with npm and example flags (#25267)
* Ensure CNA install succeeds with npm and example flags
2021-05-19 15:27:41 -05:00
C. Lewis
9c77cda6c5
feat(create-next-app): add --ts, --typescript support (#24655)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2021-05-07 10:08:16 +02:00
Dinesh Balaji
19febb10c0
feat: update create-next-app to init with main as initial branch (#17745)
When `create-next-app` is initialized a git repo, it now uses 'main' as the initial branch.

The branch master does not actually exist initially. The branches don't get created only when they have at least one commit. Until the branch gets created, the branch only exists in .git/HEAD. So there is no master branch initialized in the repo.

Closes: https://github.com/vercel/next.js/issues/17733

<img width="639" alt="Screenshot 2020-10-09 at 17 26 30" src="https://user-images.githubusercontent.com/4656109/95580229-9f3c6c80-0a54-11eb-967f-180eb9601c1a.png">
2020-11-07 14:46:17 +00:00
matamatanot
0226e7872a
CNA: Add warning about permission (#14889)
close #14744

<img width="851" alt="screen_shot" src="https://user-images.githubusercontent.com/39780486/86603491-06bec800-bfdf-11ea-9928-ee85cbad86a7.png">


I have some concerns.

- `import { isWriteable } from '../next/build/is-writeable'` **not** from `create-next-app ` package.
- The warning sentence is from npm. Not for Next.js. I'm not a native English speaker. I'd like to know the natural expression for this.
2020-08-19 17:09:34 +00:00
Cristian Dominguez
f4f6fea71f
CNA: replace make-dir with core recursive mkdir (#15006)
Fix #14902 

I created a separated helper that wraps `fs.promises.mkdir` and sets `recursive` option to `true` by default.

I'm not sure if this is the right approach (maybe it should just call `fs.promises.mkdir` from `create-app.ts`?), any thoughts?
2020-07-10 01:29:03 +00:00
Cristian Dominguez
887d436043
Use HEAD req for isUrlOk check (#14994)
Co-authored-by: Cristian Dominguez <cristiand391@users.noreply.github.com>
2020-07-09 11:52:49 -04:00
James Mosier
d51fef5fc9
chore(create-next-app): remove example picker (#13977)
If a user does not specify `--example` when using create-next-app then just spin up the default template and only prompt them for the name of their project.

if a user does specify `--example` (with no string after it) then show them the example picker. 

Closes #13960
2020-06-10 03:14:24 +00:00
Shu Uesugi
1f49400a32
Remove unnecessary catch (#13639)
This undoes https://github.com/vercel/next.js/pull/13138 as the rename is done.
2020-06-01 19:27:05 +00:00
Joe Haddad
bee8c31b87
Lint for invalid imports (#13482)
This adds a lint rule to ensure we don't import dev dependencies by accident.
2020-05-28 08:23:10 +00:00
Joe Haddad
b7e17e09e5
Update references to zeit/next.js (#13463) 2020-05-27 17:51:11 -04:00
Marco Moretti
b3e45fab5e
feat(cli): use default template when GH is offline (#12194)
fix #12136 

I add a prompt if there is an error when trying to download example files.
Maybe could be better to add an error class and in create-app.ts on every "console.error" trow a new Exception and manage it in catch. What you think ? 👯
2020-05-26 16:39:18 +00:00
JJ Kasper
b325f15e61
Update Create Next App to handle rename of org (#13138)
* Update Create Next App to handle rename

* Rethrow if we dont handle the error
2020-05-20 11:52:32 -05:00
Joe Haddad
86160a5190
Upgrade to Prettier 2 (#13061) 2020-05-18 15:24:37 -04:00
Maxi Gimenez
ce830af202
chore(create-next-app): add missing types (#12691) 2020-05-10 17:51:47 -04:00
Maxi Gimenez
cf0b1d9472
chore(create-next-app): add missing return types on helpers (#12616)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2020-05-10 12:55:46 +02:00
Dylan Brookes
bc7d18367b
Confirm if user wants example when creating app (#10543)
* Confirm if user wants example when creating app

* Only ask user to choose example if they provide --example flag

* Simplify the search

* Added test

* Use a select to pick the template

* Updated test

* check for lowercase and updated no example message

* Add message if no template is selected

* Updated tests

* Handle error if fetching the examples fails

* Fixed tests

* Updated test timeout

* Update examples.ts

Co-authored-by: merelinguist <merelinguist@users.noreply.github.com>
Co-authored-by: Luis Alvarez <luis@zeit.co>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-04-07 13:11:29 -04:00
matamatanot
c89ddc97e2
Remove node-promisepipe library (#11700)
* remove promisepipe

* commit yarn.lock

Co-authored-by: “kosuke_matano” <kosuke_matano@cyberagent.co.jp>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-04-06 10:46:04 -04:00
Brandon Duffany
1fbd20dc37
Allow top-level GitHub repo URLs as examples (#11691)
* Support top-level GitHub repo URLs

Adds support for top-level GitHub repo URLs, e.g.
https://github.com/username/my-cool-next-example.

This is already possible, but you have to enter "/tree/master" (or the
desired branch name) after the repo URL.

The change itself simply expands that URL to
https://github.com/username/cool-next-example/tree/$DEFAULT_BRANCH_NAME
where DEFAULT_BRANCH_NAME is the default branch configured for the repo
in GitHub.

* Fix formatting issues
2020-04-06 15:57:19 +02:00
Sriram Thiagarajan
eec18ecafe
[create-next-app] update logic for shouldUseYarn function (#11683)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-04-06 09:32:20 +02:00
Luis Alvarez D
75559f1431
Add --example=<github-url> to create-next-app (#10226)
* Initial support for URLs

* Added folder support

* Added --example-path

* Bug fix

* Also install deps

* Updated error message

* Bug fix and replace the file path

* Added tests

Co-authored-by: Shu Uesugi <shu@chibicode.com>
2020-02-27 16:32:32 +01:00
Joe Haddad
00badd4d58
Initialize Git repo on app creation (#9376)
* Initialize Git repo on app creation
This PR initializes a Git repository after Create Next App runs.

We ensure the app was not created in an already-existing Git or Mercurial repo.

Failures of setup (no Git installed) do not fail the application bootstrapping.

Closes #9077 (replaces)

* Add test

* Update index.test.js
2019-11-10 21:42:51 -08:00
Joe Haddad
1d9fd6a51b
Adjust Create Next App install env (#8431) 2019-08-20 00:41:51 -04:00
Joe Haddad
104d18c607
Rewrite Create Next App (#8030)
* Completely rewrite Create Next App

* Sort imports

* Show what package manager is being used

* Fix project name suggestion

* Update tests for new implementation

* Use normal prepublish command for on-install

* Upgrade Node version

* Switch to 8.16

* Disable v8 cache

* Swap out update check package and fix CLI boot
2019-07-19 15:55:30 -04:00