-
Notifications
You must be signed in to change notification settings - Fork 932
fix: Remove hardcoded npm registry url #2520
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
fix: Remove hardcoded npm registry url #2520
Conversation
packages/cli/src/tools/npm.ts
Outdated
| reactNativeVersion: string, | ||
| ): Promise<TemplateVersion | undefined> { | ||
| const json = await fetch(TEMPLATE_VERSIONS_URL).then( | ||
| const json = await fetch(getNpmRegistryUrl() + '@react-native-community/template').then( |
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.
I'd prefer leveraging here new URL() to make sure URL is always in a correct format, e.g. when getNpmRegistryUrl()'d return value without / at the end, previous would've fail.
| const json = await fetch(getNpmRegistryUrl() + '@react-native-community/template').then( | |
| const json = await fetch(new URL('@react-native-community/template', getNpmRegistryUrl())).then( |
szymonrybczak
left a comment
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.
Makes a lot of sense, thanks! 👍
|
cc @blakef |
blakef
left a comment
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.
This is a really nice change. Couple of small things before you land it:
- update the URL handling to use
URLas @szymonrybczak suggested - fix the formatting
|
There hasn't been any activity on this pull request in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days. |
Summary:
fixes: #2519
Official npm registry url is hardcoded, the "cli" can't run successfully in a closed environment.
Following error is displayed when running
npx @react-native-community/cli@latest init AwesomeProject --verbose.My solution is using
getNpmRegistryUrl()to get real npm registry url in user's local environment, then it can avoid using official npm registry directly.Test Plan:
Build and run
node /path/to/react-native-cli/packages/cli/build/bin.js init AwesomeProjectChecklist