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

docs: document special meaning of registry.npmjs.com #3784

Merged
merged 1 commit into from Sep 23, 2021

Conversation

everett1992
Copy link

This behavior has been present in npm for a while, but I haven't found
where it's documented. This is my attempt at documenting the behavior
based on my understanding of it. I think a SME should contribute to this
so the documentation is correct.

npm/feedback#544
#3783
https://github.com/npm/arborist/blob/478871bf0a44a8ec516b9057585b8707e60b0349/lib/arborist/reify.js#L687-L693

I'd really like to discus improving this behavior. Packages should have more control over the resolved url, at-least packages using a custom registry should be able to record a resolved value in the lockfile that means 'the currently configured registry'. An easy and compatible option may be a configuration for the registry to record. npm would replace NPM_CONFIG_REGISTRY with NPM_CONFIG_REGISTRY_TO_RECORD when writing the lock. The comment in arborist suggests a plan to remove the special behavior of registry.npmjs.org which I support but I think it would require a new lock file format.

npm will install packages from the new registry, but if you create a lock
file while using a custom registry packages will be installed from that
registry even after you change to another registry. To update the registry in a
lock file you can remove the file or remove or modify the resolved key.
Copy link
Member

Choose a reason for hiding this comment

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

The package-lock is not something we want folks editing, it's assumed that the cli "owns" this. As such we should not suggest modifying the key directly.

Copy link
Author

Choose a reason for hiding this comment

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

Hows this? Or delete the sentence?

You should delete the file if you would like to change the custom registry.

Copy link
Member

Choose a reason for hiding this comment

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

Just delete "or modify the resolved key"

Copy link
Member

Choose a reason for hiding this comment

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

Or perhaps yes just deleting the sentence for now. Best to add something more clarifying later than put something in now that's not right.

This behavior has been present in npm for a while, but I haven't found
where it's documented. This is my attempt at documenting the behavior
based on my understanding of it. I think a SME should contribute to this
so the documentation is correct.

npm/feedback#544
npm#3783
https://github.com/npm/arborist/blob/478871bf0a44a8ec516b9057585b8707e60b0349/lib/arborist/reify.js#L687-L693

PR-URL: npm#3784
Credit: @everett1992
Close: npm#3784
Reviewed-by: @wraithgar
@wraithgar wraithgar changed the base branch from latest to release-next September 23, 2021 14:33
@wraithgar wraithgar merged commit dae5ce3 into npm:release-next Sep 23, 2021
@wraithgar wraithgar mentioned this pull request Sep 23, 2021
@josh18
Copy link

josh18 commented Sep 23, 2021

When the default registry is used in a package-lock or shrinkwrap is has the
special meaning of "the currently configured registry". If you create a lock
file while using the default registry you can switch to another registry and
npm will install packages from the new registry, but if you create a lock
file while using a custom registry packages will be installed from that
registry even after you change to another registry.

Note that this doesn't seem to apply when using a registry scope with .npmrc e.g.

@scope:registry=http://localhost:4873/

and then try to npm install while having a scoped package with resolved value https://registry.npmjs.org/ it will attempt to resolve it from https://registry.npmjs.org/ instead of from localhost.

If anyone knows if that is intended let me know and I'll make a PR to update the documentation.

@@ -201,7 +202,8 @@ Dependency objects have the following fields:

* resolved: For registry sources this is path of the tarball relative to
the registry URL. If the tarball URL isn't on the same server as the
registry URL then this is a complete URL.
registry URL then this is a complete URL. `registry.npmjs.org` is a magic
value meaning "the currently configured registry".

Choose a reason for hiding this comment

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

😱😱😱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants