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 "create-react-app@3.4.0" 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 > eslint-config-react-app@5.2.0" has incorrect peer dependency "eslint-plugin-flowtype@3.x".
warning " > @testing-library/user-event@7.2.1" 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/jest-dom@4.2.4
├─ @testing-library/react@9.4.1
├─ @testing-library/user-event@7.2.1
├─ @types/jest@24.9.1
├─ @types/node@12.12.28
├─ @types/react-dom@16.9.5
├─ @types/react@16.9.22
├─ cra-template-typescript-husky@0.1.0
├─ husky@4.2.3
├─ lint-staged@10.0.7
├─ prettier@1.19.1
├─ react-dom@16.12.0
├─ react@16.12.0
└─ typescript@3.7.5

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