facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.77k stars 26.87k forks source link

`--template` cannot load a GItHub repository #8166

Open JasonEtco opened 4 years ago

JasonEtco commented 4 years ago

Describe the bug

Hey folks πŸ‘‹ I'm not positive that this is a bug, talking with @iansu this seems to be more of a feature that doesn't (yet!) exist. I was wondering if --template owner/repo would work in the same way as npm i owner/repo, where it looks for a package on GitHub. For example:

npm install -g facebook/create-react-app

Would grab the code, as-is, from master of this repo.

Environment

create-react-app@3.3.0

Steps to reproduce

  1. Run npx create-react-app wheeler-mode --template iansu/cra-template-wheeler-mode

Any owner/repo string should work in the same way!

  1. Observe the error message as shown below!

Expected behavior

I'd expect yarn to resolve the template similar to how it grabs it from npm, when given an owner/repo string that maps to a GitHub repository. Aside from being able to function similar to yarn under the hood, this even enables private templates by implementing existing git credentials πŸ™Œ πŸ”’

Actual behavior

❯ npx create-react-app wheeler-mode --template iansu/cra-template-wheeler-mode 

Here's the output:

Creating a new React app in /Users/jasonetco/dev/wheeler-mode.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template-iansu/cra-template-wheeler-mode...

yarn add v1.17.3
[1/4] πŸ”  Resolving packages...
error Command failed.
Exit code: 128
Command: git
Arguments: ls-remote --tags --heads ssh://git@github.com/cra-template-iansu/cra-template-wheeler-mode.git
Directory: /Users/jasonetco/dev/wheeler-mode
Output:
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Aborting installation.
  yarnpkg add --exact react react-dom react-scripts cra-template-iansu/cra-template-wheeler-mode --cwd /Users/jasonetco/dev/wheeler-mode has failed.

Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting wheeler-mode/ from /Users/jasonetco/dev
Done.

Worth noting that yarn tried to clone the GitHub repo, but got the SSH URL wrong:

ssh://git@github.com/cra-template-iansu/cra-template-wheeler-mode.git

Should be:

- ssh://git@github.com/cra-template-iansu/cra-template-wheeler-mode.git
+ ssh://git@github.com/iansu/cra-template-wheeler-mode.git

Let me know how I can help! If y'all are open to a PR here, my first inclination would be to look for / in the provided template string and just not prepend cra-template before giving it over to yarn.

iansu commented 4 years ago

We’re definitely interested in a PR to fix this! I think your proposed change makes sense. We already leave the template name alone if it starts with cra-template so this would probably just be another check in that same function.

JasonEtco commented 4 years ago

Looks like that's here:

https://github.com/facebook/create-react-app/blob/8d1a4f2fce291c5ebe236b92ff79fe72a8c48a3b/packages/create-react-app/createReactApp.js#L657-L660

PR incoming πŸ’ͺ

jasonleehodges commented 4 years ago

@iansu / @ianschmitz any interest in picking this back up? Looks like the PR was opened and just never reviewed. Was automatically closed due to inactivity? I'd really like to use the result of the PR (#8167) if possible. Even happy to jump in and open a new PR if you think it will end up getting merged. Let me know!

ImanMh commented 2 years ago

@JasonEtco does this work with a mono repo where the template is sitting in sub-directory of the repository not in the root?