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

Initialize git repo before template dependecies are installed #8280

Closed
lukaszfiszer opened this issue Jan 3, 2020 · 6 comments
Closed

Initialize git repo before template dependecies are installed #8280

lukaszfiszer opened this issue Jan 3, 2020 · 6 comments

Comments

@lukaszfiszer
Copy link
Contributor

lukaszfiszer commented Jan 3, 2020

Is your proposal related to a problem?

When creating a react app with a template that include a dependency requiring a git repo to work, the installation can fail or be incorrect for the developer that executes create-react-app on their machine. This is because the git repo is initialized after template dependencies are installed.

An example is a very popular package husky which adds git hooks to .git directory as part of its postinstall scripts. Those hooks won't be added for the person setting up the app with npx create-react-app ...

Describe the solution you'd like

  • split tryGitInit() into 2 separate functions - one that initializes the repo, second that creates commit.
  • move execution of the first function up, possible at the beginning of main init.js function

If you are OK with the proposed solution I'll be happy to prepare PR with the implementation.

@mrmckeb
Copy link
Contributor

mrmckeb commented Jan 3, 2020

Hi @lukaszfiszer, good pick-up. Would you be interested in raising a PR for this?

@lukaszfiszer
Copy link
Contributor Author

Thanks @mrmckeb. PR created: #8282

@lukaszfiszer
Copy link
Contributor Author

Fixed in 3.4.0. Closing

@nathanrpage97
Copy link

I'm trying to create a template that uses husky. It looks like husky is properly installed after the git repo is initialized, however, the hooks are not properly installed.

success Installed "[email protected]" with binaries:
      - create-react-app
[######################################################################################################################] 158/158
Creating a new React app in /Users/nathanpage/Documents/projects/npm_packages/test-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template-typescript-husky

...

Initialized a git repository.

Installing template dependencies using yarnpkg...
yarn add v1.22.0
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "react-scripts > [email protected]" has incorrect peer dependency "[email protected]".
warning " > @testing-library/[email protected]" has unmet peer dependency "@testing-library/dom@>=5".
[4/4] 🔨  Building fresh packages...
success Saved lockfile.
success Saved 51 new dependencies.
info Direct dependencies
├─ @testing-library/[email protected]
├─ @testing-library/[email protected]
├─ @testing-library/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ @types/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]

In order to fix i have to re-install husky after 'create' finishes.

@lukaszfiszer
Copy link
Contributor Author

@nathanrpage97 Just retested with following commands and it seems to be working fine:

> npx create-react-app my-app --template custom-template
> cd my-app
> vim src\index.tsx
# ...editing file...
> git add .
> git commit -m "test"
husky > pre-commit (node v12.16.0)
�  Finding changed files since git revision 3b61d04.
�  Found 1 changed file.
✍️  Fixing up src/index.tsx.
✅  Everything is awesome!
[master d9c45e9] test

@nathanrpage97
Copy link

@lukaszfiszer Thanks for the response. Would you mind sharing the custom-template you are using? I've experienced this issue with both yarn and npx. For reference, I've published the package on npm under cra-template-typescript-husky.

@lock lock bot locked and limited conversation to collaborators Mar 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants