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

fix(create-app): support github url has trailing slash #39665

Merged
merged 5 commits into from Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 9 additions & 3 deletions packages/create-next-app/helpers/examples.ts
Expand Up @@ -25,9 +25,15 @@ export async function getRepoInfo(
const [, username, name, t, _branch, ...file] = url.pathname.split('/')
const filePath = examplePath ? examplePath.replace(/^\//, '') : file.join('/')

// Support repos whose entire purpose is to be a NextJS example, e.g.
// https://github.com/:username/:my-cool-nextjs-example-repo-name.
if (t === undefined) {
if (
// Support repos whose entire purpose is to be a NextJS example, e.g.
// https://github.com/:username/:my-cool-nextjs-example-repo-name.
t === undefined ||
// Support GitHub URL that ends with a trailing slash, e.g.
// https://github.com/:username/:my-cool-nextjs-example-repo-name/
// In this case "t" will be an empty string while the next part "_branch" will be undefined
(t === '' && _branch === undefined)
) {
const infoResponse = await got(
`https://api.github.com/repos/${username}/${name}`
).catch((e) => e)
Expand Down
30 changes: 30 additions & 0 deletions test/integration/create-next-app/index.test.ts
Expand Up @@ -186,6 +186,36 @@ describe('create next app', () => {
})
})

it('should allow example with GitHub URL with trailing slash', async () => {
await usingTempDir(async (cwd) => {
const projectName = 'github-app'
const res = await run(
[
projectName,
'--example',
'https://github.com/vercel/nextjs-portfolio-starter/',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both vercel/next.js and vercel/exmaples are not the "entire repo is a bootstrap template" case, so another vercel example repo https://github.com/vercel/nextjs-portfolio-starter is being used for the test.

],
{
cwd,
}
)

expect(res.exitCode).toBe(0)
expect(
fs.existsSync(path.join(cwd, projectName, 'package.json'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/index.mdx'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

it('should allow example with GitHub URL and example-path', async () => {
await usingTempDir(async (cwd) => {
const projectName = 'github-example-path'
Expand Down