Skip to content

Commit 1e71a58

Browse files
committed
fix: add support for third-party registry with version
1 parent 0305382 commit 1e71a58

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/cli/src/commands/init/version.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export async function createTemplateUri(
5858
// lower cadence). We have to assume the user is running against the latest nightly by pointing to the tag.
5959
return `${TEMPLATE_PACKAGE_COMMUNITY}@nightly`;
6060
}
61-
const templateVersion = await getTemplateVersion(version);
61+
const templateVersion = await getTemplateVersion(
62+
version,
63+
options.authToken,
64+
);
6265
return `${TEMPLATE_PACKAGE_COMMUNITY}@${templateVersion}`;
6366
}
6467

packages/cli/src/tools/npm.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,16 @@ const minorVersion = (version: string) => {
130130

131131
export async function getTemplateVersion(
132132
reactNativeVersion: string,
133+
authToken?: string,
133134
): Promise<TemplateVersion | undefined> {
134-
const json = await fetch(
135-
new URL('@react-native-community/template', getNpmRegistryUrl()),
136-
).then((resp) => resp.json() as Promise<NpmTemplateResponse>);
135+
const url = new URL(getNpmRegistryUrl());
136+
url.pathname = `${url.pathname}@react-native-community/template`;
137+
const headers = authToken
138+
? {Authorization: `Bearer ${authToken}`}
139+
: undefined;
140+
const json = await fetch(url, {headers}).then(
141+
(resp) => resp.json() as Promise<NpmTemplateResponse>,
142+
);
137143

138144
// We are abusing which npm metadata is publicly available through the registry. Scripts
139145
// is always captured, and we use this in the Github Action that manages our releases to

0 commit comments

Comments
 (0)