Skip to content

Set of fixes for better npmrc parameters support #12284

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

Merged
merged 3 commits into from
Sep 26, 2018

Conversation

smnbbrv
Copy link
Contributor

@smnbbrv smnbbrv commented Sep 15, 2018

Heavily related to a hot topic #10624. This issue is really annoying for lots of people.

Targets two points:

  1. Support for per-project .npmrc file. This is done for the projects that include bundled .npmrc with readonly permissions, see https://docs.npmjs.com/files/npmrc
  2. Support for private repositories like Nexus and Artifactory. I did not test with Artifactory because currently I have none, however Nexus works perfectly with the applied changes. Artifactory has a similar way of authentication, so it should also be covered.

Changes type:

  • alwaysAuth is changed to always-auth, which is a proper name, see https://docs.npmjs.com/misc/config#always-auth
  • added email parameter
  • _auth is normally a base64 encoded token:password string => added extracting those credentials from the token and left a fallback token assignment in case something else is stored in _auth

Thank you in advance.

// attempt to parse username and password from base64 token
// to enable Artifactory / Nexus-like repositories support
const parsedToken = Buffer.from(token, 'base64').toString('ascii');
const [extractedUsername, extractedPassword] = parsedToken.split(':');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it cannot have : in the password. Is this expected? You might want to use this instead:

const delimiter = ':';
const [extractedUsername, ...passwordArr] = parsedToken.split(delimiter);
const extractedPassword = passwordArr.join(delimiter);

Just slightly more ugly, but there's no native function that does it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, good point. Thanks for reviewing! I will apply the changes soon

Copy link
Contributor

@hansl hansl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @smnbbrv ,

Great PR, love it. One nit, and also the validate test will pass if you squash the lint commit into its previous commit.

Once that's done I'll approve it. Thanks!

Copy link
Contributor

@hansl hansl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant to request the changes above.

@smnbbrv
Copy link
Contributor Author

smnbbrv commented Sep 15, 2018

@hansl updated the PR according to your comments and going to sleep :) If you have more comments / there is something more to fix, I'm glad to help

@hansl hansl added the target: major This PR is targeted for the next major release label Sep 15, 2018
hansl
hansl previously approved these changes Sep 15, 2018
@mrmaxsteel
Copy link

FYI tested with Artifactory, did not work, see: #10624 (comment)

@mrmaxsteel
Copy link

mrmaxsteel commented Sep 17, 2018

@smnbbrv I found the issue, nothing to do with Artifactory. Your code to parse the username:password from the base64 _auth token doesn't work when there is whitespace between key and value in .npmrc.

For example, it works when .npmrc looks like:

_auth=<base64 user:pass>

But not when:

_auth = <base64 user:base>

@smnbbrv
Copy link
Contributor Author

smnbbrv commented Sep 17, 2018

@hansl I added another fix that adds support of whitespaces around '='. Could you, please, revalidate?

@mrmaxsteel it's not really my code, I'm just a random stranger who wants the issue to be fixed :D Added fix to your findings. That's really cool that Artifactory works as well 👍

@mrmaxsteel
Copy link

Validated latest change, all works 👍

@smnbbrv
Copy link
Contributor Author

smnbbrv commented Sep 19, 2018

@hansl I can't really understand the ci failures... Does not seem to me like it is the issue connected to the changes I made

}

if (fs.existsSync(perProjectNpmrc)) {
npmrc = fs.readFileSync(perProjectNpmrc).toString('utf-8');
} else {
Copy link

@aguacongas aguacongas Sep 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should parse both .npmrc files because the repository url can be in the per project file and credentials in the user file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.

However if we are too picky here we enter the pain zone. First, then we need to support the global npmrc + userconfig flag / env variable as well. Second, we need to properly resolve the collisions between _authToken and _auth (because both could be present and we need to pick). Finally, the current approach is reading npmrc every time the package info is getting resolved which is not a standard npm behavior. Etc.

I'm not yet talking about having two different ways of getting NPM parameters.

The whole approach is not perfect and this PR does not pretend to be a fully working solution; at least it would be way more helpful than the current approach. Probably one needs to deeply rethink the concept.

Copy link

@aguacongas aguacongas Sep 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. However, IMHO, user file should be read first then because people having open source projects will propably share the project .npmrc without credentials

Copy link
Contributor Author

@smnbbrv smnbbrv Sep 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The private repos are nearly never used in the open source, hence no auth is required. Also if you change the order of resolving those files then you go in clear conflict with Npm itself

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#10624 is regarding an issue with fontawesome pro, so I guess it's used in open source. and npm don't need authentication nor .npmrc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://fontawesome.com/pro - 60$ per license for 5 seats. What open source projects are you talking about?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

angular-fontawesome for sample
Open source does not means free, anybody can share code on github but use a private repo with tokens they obvioulsly don't want to share.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have more arguments, but the discussion went away from the issue. What we discuss is only the cases when there is a project-specific .npmrc which is not containing _auth or _authToken, but there is one in some of the .npmrc above right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, in that case, your PR doesn't fix the issue I guess

@hansl
Copy link
Contributor

hansl commented Sep 26, 2018

I'm going to let this in, but we should fix the local/global issue in RC.

@hansl hansl merged commit b19a348 into angular:master Sep 26, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants