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

fix: Remove hardcoded npm registry url #2520

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/cli/src/tools/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@
}
}

const TEMPLATE_VERSIONS_URL =
'https://registry.npmjs.org/@react-native-community/template';
const minorVersion = (version: string) => {
const v = semver.parse(version)!;
return `${v.major}.${v.minor}`;
Expand All @@ -129,7 +127,7 @@
export async function getTemplateVersion(
reactNativeVersion: string,
): Promise<TemplateVersion | undefined> {
const json = await fetch(TEMPLATE_VERSIONS_URL).then(
const json = await fetch(getNpmRegistryUrl() + '@react-native-community/template').then(

Check failure on line 130 in packages/cli/src/tools/npm.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `getNpmRegistryUrl()·+·'@react-native-community/template').then(⏎····(resp)·=>·resp.json()·as·Promise<NpmTemplateResponse>,⏎··` with `⏎····getNpmRegistryUrl()·+·'@react-native-community/template',⏎··).then((resp)·=>·resp.json()·as·Promise<NpmTemplateResponse>`
Copy link
Collaborator

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.

Suggested change
const json = await fetch(getNpmRegistryUrl() + '@react-native-community/template').then(
const json = await fetch(new URL('@react-native-community/template', getNpmRegistryUrl())).then(

(resp) => resp.json() as Promise<NpmTemplateResponse>,
);

Expand Down
Loading