cli icon indicating copy to clipboard operation
cli copied to clipboard

Passing registry for different package managers

Open lunaleaps opened this issue 1 year ago • 5 comments

Describe the Feature

Currently we use --yarn-config-options in React Native to e2e testing to use privately published monorepo packages when running our template app tests See: https://github.com/facebook/react-native/blob/main/scripts/e2e/init-template-e2e.js#L125

We've recently switched to using npm because Yarn v3 doesn't respect the npmRegistryConfig set. See https://github.com/facebook/react-native/pull/43130

yarnConfigOptions is only used when the package manager is yarn -- from my understanding there isn't a way to pass a registry for npm` See https://github.com/react-native-community/cli/blob/main/docs/commands.md#init

Possible Implementations

Introduce another flag for npm specifically, or let me know if there is a way to do this.

lunaleaps avatar Mar 05 '24 01:03 lunaleaps

hey @lunaleaps! :wave: to make Yarn working with custom npmRegistryServer we can do it by just adding another argument to --yarn-config-options:

❯ yarn config get npmRegistryServer
Alias tip: y config get npmRegistryServer
https://registry.yarnpkg.com

❯ yarn config set npmRegistryServer localhost:4732
Alias tip: y config set npmRegistryServer localhost:4732
➤ YN0000: Successfully set npmRegistryServer to 'localhost:4732'

So I think that would work for Core's use case for now, right? Let me know if I'm missing something.

Edit: I see @huntie referenced this issue inside Yarn repo, I believe it is fixed inside newer Yarn versions (?) Do you have any CI jobs that are showing that it isn't working? 🤔

szymonrybczak avatar Mar 05 '24 18:03 szymonrybczak

@szymonrybczak Thanks for looking, my question is how do we set a registry for npm specifically. Because as I understand it using --yarn-config-options only affects using the package manager yarn, is that right?

We want to use npm and use a custom registry. My understanding is that we need a flag like registry <registryhost>

Here is the only place I see where yarnConfigOptions is used: https://github.com/react-native-community/cli/blob/7284ea5eaf61f4967966329b0e474578997f1416/packages/cli/src/commands/init/template.ts#L33 CleanShot 2024-03-05 at 11 09 49@2x

lunaleaps avatar Mar 05 '24 19:03 lunaleaps

@szymonrybczak Thanks for looking, my question is how do we set a registry for npm specifically. Because as I understand it using --yarn-config-options only affects using the package manager yarn, is that right?

Yes, I think we can create also more generic --registry option 👍

I have doubts why you moved there from Yarn to NPM? Since Yarn 3.x seems to support npmRegistryServer as of my testing, do you have any CI jobs that were failing or anything?

szymonrybczak avatar Mar 05 '24 19:03 szymonrybczak

Yea these are the CI tests that were failing: https://app.circleci.com/pipelines/github/facebook/react-native/42789/workflows/9

CleanShot 2024-03-05 at 14 00 44@2x d0e9e3f-afac-43c4-be30-e008e8d407da/jobs/1401065?invite=true#step-116-157494_82

It looks like yarn v1.22.19, yea it sounds worthwhile to try upgrading.

lunaleaps avatar Mar 06 '24 00:03 lunaleaps

Yea, because while creating project with CLI we're installing package in temporary path, and in React Native case on CI there's Yarn v1 installed so it is ignoring npmRegistryServer :< Are there any things that blocks upgrading global version in CI? 🤔

szymonrybczak avatar Mar 06 '24 19:03 szymonrybczak

There hasn't been any activity on this issue 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.

github-actions[bot] avatar Jun 05 '24 03:06 github-actions[bot]