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

implement options affecting resolved value in lock files. #4264

Closed
wants to merge 3 commits into from

Conversation

everett1992
Copy link

This PR implements two options that affect t he resolved value in lock files described in npm/rfcs#486. There are more details in the RFC but the gist is that the lock file records information from the registry used when packages were added to the lock file. This can cause undesired behaviors including install failures when changing the configured registry.

This is very much a work in progress and I'm eager for any feedback, especially the names of the options, alternate solutions to these problems, and how I've plumbed 'options' thru the Shrinkwrap class.

omit-lockfile-registry-resolved

This option omits the resolved value from the registry. On subsequent installs npm will resolve the tarball url from the registry. This supports any kind of registry, and guarantees the registry is the authority on the location of tarballs, but makes installs slower.

record-default-registry

This option uses the magic properties of the default registry https://registry.npmjs.com. When the lockfile is read npm replaces the default registry with the currently configured registry. This magic behavior allows users to switch from the default registry to a custom registry - but you can't switch from a custom registry to another registry once a custom registry is recorded in a lock file.

This option does the opposite transform of the magic default, replacing the custom registry with the default registry when recording the lock file.

There were other proposals to record lock files with a sigil that explicitly means 'the current registry'

"resolved": "${registry}/npm/-/npm-8.3.1.tgz"

But this isn't cross compatible with other npm versions or clients. This option effectively uses https://registry.npmjs.com as that sigil, which is compatible with earlier versions of npm.

The main downside with this option is that the lockfile records the path portion of the resolved url which can change between registries. This option only supports switching between registries that host tarballs at the same relative path. This downside is already present in npm's magic handling of the default registry.

The other downside is that it hangs more weight on the magic behavior of the default registry.

References

Related to npm/rfcs#486

@everett1992 everett1992 requested a review from a team as a code owner January 19, 2022 18:58
@ruyadorno ruyadorno added the Needs Discussion is pending a discussion label Jan 26, 2022
@wraithgar wraithgar changed the base branch from release-next to latest March 9, 2022 18:24
@darcyclarke darcyclarke added the Agenda will be discussed at the Open RFC call label Mar 31, 2022
Caleb ツ Everett added 3 commits April 4, 2022 14:53
Implement `$disable-write-resolves` described in npm/rfcs#486.  I named
the option `omitLockfileRegistryResolved` but that can be changed later.

Put simply, this option causes npm to create lock files without a
`resolved` key for registry dependencies forcing npm to use the current
configured registry and resolve package tarball urls on install. This
fixes install errors when users change registries and the recorded
resolved url is incorrect.

This option causes slower installs because npm must fetch each packages
manifest to find the tarball url, but it's the most comprehensive
solution to this problem. Options like recording always the default
registry, or recording a special 'current registry' sigil will break if
registries host tarballs at different paths. For example
`${REGISTRY}/npm/-/npm-8.3.0.tgz` only works if all registries host
tarballs at `npm/-/npm-8.3.0.tgz`.
Create shrinkwrap files with resolved urls modified to replace the
configured registry with the default registry,
https://registry.npmjs.org.

The default registry is a magic value meaning the current registry, so
recording resolved with the default registry allows users to switch to a
different registry without removing their lockfile. The path portion of
the acutal resolved url is preserved so this trick only works when the
different registries host tarballs at the same relative paths. It's
faster than the omitLockfileRegistryResolved option because npm doesn't
need to fetch each pacument to resolve the tarball url.
@darcyclarke
Copy link
Contributor

Removing Agenda label as we have work-in-flight to address this.

@nlf
Copy link
Contributor

nlf commented Aug 2, 2022

closing, this was implemented in #4874 and #4860

@nlf nlf closed this Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Discussion is pending a discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants