From d4085d165d2610f565ec16254c22bd581fbf869c Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 17 Aug 2022 01:19:59 +0800 Subject: [PATCH 1/2] fix(create-app): support github url has trailing slash --- packages/create-next-app/helpers/examples.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/create-next-app/helpers/examples.ts b/packages/create-next-app/helpers/examples.ts index 62b3d3cd6afb..44af47b2acff 100644 --- a/packages/create-next-app/helpers/examples.ts +++ b/packages/create-next-app/helpers/examples.ts @@ -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) From c87c7795aa8f62ca0a704d3b6beb651aa07a5eff Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 17 Aug 2022 01:35:42 +0800 Subject: [PATCH 2/2] test(create-app): add intergration test case --- .../integration/create-next-app/index.test.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/integration/create-next-app/index.test.ts b/test/integration/create-next-app/index.test.ts index 2b7ba01131b7..ba7fd5df86c7 100644 --- a/test/integration/create-next-app/index.test.ts +++ b/test/integration/create-next-app/index.test.ts @@ -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/', + ], + { + 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'