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

🐛 Bug: Parse mode doesn't like org-scoped registries #25

Closed
3 tasks done
james-nash opened this issue Dec 9, 2024 · 5 comments · Fixed by #26
Closed
3 tasks done

🐛 Bug: Parse mode doesn't like org-scoped registries #25

james-nash opened this issue Dec 9, 2024 · 5 comments · Fixed by #26
Labels
type: bug Something isn't working :( 🐛

Comments

@james-nash
Copy link

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Expected

Running npx -y --registry https://registry.npmjs.org azdo-npm-auth on a project whose .npmrc uses an org-scoped registry config, like:

@myorg:registry=https://pkgs.internal-repo.myorg.com/foo/bar/baz

...should just work™️ as per the README.

Actual

The command fails with the error: Error parsing project .npmrc.

Additional Info

I presume this is to do with the org scoping, because when I removed the @orgname: prefix in my .npmrc, it worked fine.

@james-nash james-nash added the type: bug Something isn't working :( 🐛 label Dec 9, 2024
@johnnyreilly
Copy link
Owner

johnnyreilly commented Dec 9, 2024

You might be onto something here! I think I need to better understand org scoping. This is instructive:

; bad config
_authToken=MYTOKEN

; good config
@myorg:registry=https://somewhere-else.com/myorg
@another:registry=https://somewhere-else.com/another
//registry.npmjs.org/:_authToken=MYTOKEN
; would apply to both @myorg and @another
; //somewhere-else.com/:_authToken=MYTOKEN
; would apply only to @myorg
//somewhere-else.com/myorg/:_authToken=MYTOKEN1
; would apply only to @another
//somewhere-else.com/another/:_authToken=MYTOKEN2

Consider the kind of thing azdo-npm-auth makes now:

; begin auth token
//pkgs.dev.azure.com/org-name/_packaging/org-feed-name/npm/registry/:username=org-name
//pkgs.dev.azure.com/org-name/_packaging/org-feed-name/npm/registry/:_password=BASE64ENCODEDPAT
//pkgs.dev.azure.com/org-name/_packaging/org-feed-name/npm/registry/:email=npm requires email to be set but doesn't use the value
//pkgs.dev.azure.com/org-name/_packaging/org-feed-name/npm/:username=org-name
//pkgs.dev.azure.com/org-name/_packaging/org-feed-name/npm/:_password=BASE64ENCODEDPAT
//pkgs.dev.azure.com/org-name/_packaging/org-feed-name/npm/:email=npm requires email to be set but doesn't use the value
; end auth token

and consider your example of:

@myorg:registry=https://pkgs.internal-repo.myorg.com/foo/bar/baz

what would we expect? Perhaps:

; begin auth token
@myorg:registry=https://pkgs.internal-repo.myorg.com/foo/bar/baz
//pkgs.internal-repo.myorg.com/foo/bar/baz/:username=org-name
//pkgs.internal-repo.myorg.com/foo/bar/baz/:_password=BASE64ENCODEDPAT
//pkgs.internal-repo.myorg.com/foo/bar/baz/:email=npm requires email to be set but doesn't use the value
//pkgs.internal-repo.myorg.com/foo/bar/:username=org-name
//pkgs.internal-repo.myorg.com/foo/bar/:_password=BASE64ENCODEDPAT
//pkgs.internal-repo.myorg.com/foo/bar/:email=npm requires email to be set but doesn't use the value
; end auth token

Would this work for your use case?

@james-nash james-nash changed the title 🐛 Bug: Parse mode does't like org-scoped registries 🐛 Bug: Parse mode doesn't like org-scoped registries Dec 9, 2024
@james-nash
Copy link
Author

james-nash commented Dec 9, 2024

I think, you shouldn't duplicate the @myorg:registry=URL bit in the user's ~/.npmrc. IMHO, that's a per-project choice between the unscoped "I want npm to load all packages from this custom registry" versus "I want only packages whose names begin with @myorg/... to be loaded from this custom registry, and anything else comes from npmjs.com as usual".

All we need in the user's ~/.npmrc is the auth details for each registry.

So, I would suggest the behaviour should be:

  • Look for registry=[URL] and @[org-name]:registery=[URL] lines in the project .npmrc.
  • For each URL that you find, add a corresponding...
    ; begin auth token
    //[URL]:username=...
    ...
    ; end auth token
    ...block to the user's .npmrc.

Considering that folks might be using azdo-npm-auth with multiple projects on their machine, it would be nice if it was smart enough to not overwrite the user's ~/.npmrc , but intelligently find and update existing entries with a matching URL, and only add new ones when needed.

@johnnyreilly
Copy link
Owner

So it's just the parsing that you think should be amended?

So if it could cope with

@myorg:registry=https://pkgs.internal-repo.myorg.com/foo/bar/baz

as well as

registry=https://pkgs.internal-repo.myorg.com/foo/bar/baz

it'd be fine?

Considering that folks might be using azdo-npm-auth with multiple projects on their machine, it would be nice if it was smart enough to not overwrite the user's ~/.npmrc , but intelligently find and update existing entries with a matching URL, and only add new ones when needed.

I take you're point on this, but I'd like to tackle this separately

@james-nash
Copy link
Author

Yup, I think that's correct.

Agreed that the multi registry auth stuff feels more like an enhancement. I'm happy to write up a separate issue for that if it helps.

Copy link

🎉 This is included in version v1.2.0 🎉

The release is available on:

Cheers! 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working :( 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants