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

bug(create-next-app): cli unpacks files it shouldn't from example path #43130

Closed
1 task done
juliusmarminge opened this issue Nov 19, 2022 · 2 comments · Fixed by #43131
Closed
1 task done

bug(create-next-app): cli unpacks files it shouldn't from example path #43130

juliusmarminge opened this issue Nov 19, 2022 · 2 comments · Fixed by #43131
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application.

Comments

@juliusmarminge
Copy link
Contributor

juliusmarminge commented Nov 19, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

next info not valid since it's not related to any specific repo

npx create-next-app --version
13.0.5-canary.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

When using the --example-path flag with the CLI, create-next-app ends up unpacking files it shouldn't.

For example, given a repo contains next-prisma-starter and next-prisma-starter-websockets, running npx create-next-app --example https://github.com/trpc/trpc --example-path examples/next-prisma-starter, create-next-app would combine the output with all the files matching both these directories, since it will unpack any file whose name starts with examples/next-prisma-starter.

This is the failing logic:

filter: (p) =>
p.startsWith(
`${name}-${branch.replace(/\//g, '-')}${filePath ? `/${filePath}` : ''}`
),

Expected Behavior

When running

npx create-next-app@canary --example https://github.com/trpc/trpc --example-path examples/next-prisma-starter

I expect the output repository to be the same as this: https://github.com/trpc/trpc/tree/next/examples/next-prisma-starter

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://github.com/juliusmarminge/create-next-app-bug-repro

To Reproduce

Run

npx create-next-app@canary --example https://github.com/trpc/trpc --example-path examples/next-prisma-starter

and browse to src/pages/api/auth. This file does not exist in the template repo, but is included in the outputted project created by the CLI

comparison:

expected: https://github.com/trpc/trpc/tree/next/examples/next-prisma-starter/src/pages/api
actual: https://github.com/juliusmarminge/create-next-app-bug-repro/tree/main/src/pages/api

@juliusmarminge juliusmarminge added the bug Issue was opened via the bug report template. label Nov 19, 2022
@juliusmarminge
Copy link
Contributor Author

juliusmarminge commented Nov 20, 2022

Note: the repro no longer works (or fails if you look at it that way) since we renamed the example to not have this conflict, but it should be pretty easy to reproduce on any repo

trpc/trpc#3199

@balazsorban44 balazsorban44 added create-next-app Related to our CLI tool for quickly starting a new Next.js application. kind: bug and removed bug Issue was opened via the bug report template. labels Nov 21, 2022
ijjk pushed a commit that referenced this issue Nov 22, 2022
<!--
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)
jankaifer pushed a commit to jankaifer/next.js that referenced this issue Nov 23, 2022
<!--
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 vercel#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)
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants