Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Verify packageName when installing react-scripts from git #5709

wants to merge 1 commit into from

Conversation

mrmckeb
Copy link
Contributor

@mrmckeb mrmckeb commented Nov 4, 2018

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:

  "dependencies": {
    "@test/react-scripts": "git+ssh://git@github.com:mrmckeb/create-react-app.git#react-scripts",
  }

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.

npx git+ssh://git@github.com:mrmckeb/create-react-app.git#cra \
  test-app \
  --scripts-version=git+ssh://git@github.com:mrmckeb/create-react-app.git#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).

@facebook-github-bot
Copy link

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!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@stale
Copy link

stale bot commented Dec 22, 2018

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.

@stale stale bot added the stale label Dec 22, 2018
@stale
Copy link

stale bot commented Dec 27, 2018

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!

@stale stale bot closed this Dec 27, 2018
@Timer Timer reopened this Dec 27, 2018
@Timer Timer removed the stale label Dec 27, 2018
@stale
Copy link

stale bot commented Jan 30, 2019

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.

@mrmckeb
Copy link
Contributor Author

mrmckeb commented Jan 31, 2019

Still waiting for a review.

@stale
Copy link

stale bot commented Mar 2, 2019

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.

Comment on lines +416 to +420
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'));

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) {

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants