-
-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Verify packageName
when installing react-scripts from git
#5709
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
This pull request has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue. Thank you for your contribution! |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Still waiting for a review. |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
const packageJson = require(path.join(process.cwd(), 'package.json')); | ||
const packageNames = Object.keys(packageJson.dependencies); | ||
const packageIndex = Object.values( | ||
packageJson.dependencies | ||
).findIndex(version => version.includes(packageName + '.git')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you try to make the try/catch as atomic as possible?
packageJson.dependencies | ||
).findIndex(version => version.includes(packageName + '.git')); | ||
return packageIndex >= 0 ? packageNames[packageIndex] : packageName; | ||
} catch (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you should throw a warning if an exception is thrown.
This resolves an issue where a package name may not reflect a git repository name when using a custom react scripts package (
--scripts-version
). By default, CRA uses the repository name which causes it to throw an error when a package is installed like the below:To test this fix, I've created an example repository here, and tested locally with the following command, where my package is named
@test/react-scripts
.This worked well. It installed correctly, using the package name I had defined.
I'm of course open to a better way of solving this! I did some research into pulling the file from a remote, but I couldn't see a reliable solution for this (I could have missed something).