Repository navigation
fix: ensure custom resolver resolve() is called when shouldForceResolve returns true - #10342
TrevorBurnham wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes issues with the custom resolvers and fetchers feature where custom resolver's resolve() function wasn't being called when shouldForceResolve() returned true, and custom dependencies weren't being re-fetched when their integrity changed. The fix treats custom dependencies as mutable (similar to file dependencies), ensuring they are always re-resolved and re-fetched when appropriate.
- Never skip resolution for
custom:*dependencies - Force re-fetch when custom dependency integrity changes
- Add logic to check
shouldForceResolve()when install reports "Already up to date"
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds @pnpm/lockfile.fs dependency for plugin-commands-installation |
| pkg-manager/plugin-commands-installation/tsconfig.json | Adds reference to @pnpm/lockfile.fs package |
| pkg-manager/plugin-commands-installation/package.json | Adds @pnpm/lockfile.fs as a dependency |
| pkg-manager/plugin-commands-installation/src/installDeps.ts | Implements custom resolver force resolve check before early exit when "Already up to date" |
| pkg-manager/package-requester/src/packageRequester.ts | Treats custom dependencies like file dependencies by never skipping resolution and forcing re-fetch on integrity change |
| pkg-manager/package-requester/test/index.ts | Adds three tests for custom dependency resolution behavior and modifies type assertions in existing tests |
| pkg-manager/core/src/api.ts | Exports checkCustomResolverForceResolve function |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e2a94aa to
1e4c01f
Compare
|
are you sure about this? This will make installation with a lockfile much slower. |
1e4c01f to
d0b0db7
Compare
Good point: The change was overly broad. I've updated it so that we stick to the existing custom resolution unless the custom resolver's |
bb3b330 to
b9cff33
Compare
|
I do wonder if this makes sense at all for the install command. This is more like an update. |
|
A major category of use cases for custom resolvers involve "live" dependencies, where you want the dependency to be updated on every install. It's certainly one of the use cases I'm most interested in; it's why custom resolvers have a |
|
OK but that kind of goes against the current architecture. We have the lockfile that should produce a reproducible node_modules directory. So, these custom dependencies will have random content regardless of the lockfile? I know the local tarball dependencies behaved somewhat differently but maybe that was also a mistake. The special local tarballs behaviour was added because rush team asked for it. Maybe there should be a new command for this. Something like |
|
Hmm. Putting on my user hat, I agree that it'd be frustrating if I ran I think the solution is transparency. pnpm could emit a message during install like this: Better still, if custom resolvers had a That would make the process clear to users while keeping it automatic. |
|
I really don't know what you are trying to achieve. Why these custom resolvers can't behave the same as the standard ones? For live updates there are linked dependencies, where the dependencies are just symlinks. |
|
I can think of a couple of use cases that are immediately relevant to my needs:
Symlinks don't work for these use cases because they don't carry across systems: I can't symlink a dependency and then push my changes up to share with a colleague or build in CI. I'm happy to discuss further on Discord if you like. |
|
@zkochan tagged me so I assume he was asking for my knowledge regarding the mechanism to detect changed workspace packages. The core of it is in First, pnpm loads the workspace state. This state file includes:
By the time pnpm has loaded the state file, it already has information regarding the workspace packages graph, so it can easily compare whether workspace packages have been added or removed. If the lists remain identical, continue to the next check. This is where It also check other things, but I'm not sure if they are relevant. Just read the file to be sure. |
|
Thanks @KSXGitHub, could you document these details here: https://pnpm.io/settings#optimisticrepeatinstall ? |
Shouldn't that be implementation details. Do the users really need those details? I guess it make sense to document what information we keep track of in the state file? |
|
Add it to the readme of the package in that case. |
b9cff33 to
c87b7c2
Compare
| const skipResolution = resolution && !options.update | ||
| const isCustomDep = (resolution as CustomResolution)?.type?.startsWith('custom:') | ||
| // Custom dependencies skip resolution only if forceResolve is not set | ||
| const skipResolution = resolution && !options.update && (!isCustomDep || !options.forceResolve) |
There was a problem hiding this comment.
why is forceResolve also checked? Seems unrelated.
There was a problem hiding this comment.
also, it feels like your resolution is a special case but now it will be impossible to create a custom resolver that skips resolution like the standard resolvers. Shouldn't it be opt-in?
There was a problem hiding this comment.
The isCustomDep check was redundant, obscuring what was going on here. I've updated the PR to streamline this logic.
The only thing that actually matters is options.forceResolve, which is set by shouldForceResolve. If a custom resolver doesn't have shouldForceResolve, or its shouldForceResolve returns false, then resolution can still be skipped. The tests in test/install/checkCustomResolverForceResolve.test.ts confirm this.
There was a problem hiding this comment.
If a custom resolver doesn't have shouldForceResolve, or its shouldForceResolve returns false, then resolution can still be skipped. The tests in test/install/checkCustomResolverForceResolve.test.ts confirm this.
Right, but if a resolution will be needed due to some other reason, the packages from custom sources will always be re-resolved. This is not the case with packages from the standard sources.
Maybe we should let the resolver itself decide if a re-resolution is needed? I mean, remove the skipResolution logic completely from packageRequester and always run the resolver. The resolver then could decide if the previous resolution should be returned. I am not sure yet if it is a good idea.
There was a problem hiding this comment.
also cc @gluxon as he worked with this code recently. See my previous comment.
There was a problem hiding this comment.
Your solution won't work for subdependencies from custom sources because you only go through the direct dependencies of projects.
Good catch! We certainly want to allow subdependencies to force resolution, too.
Unfortunately, #10439 appears to have the same problem: shouldForceResolve only gets called for direct dependencies. I've opened a separate PR that uses #10439 as a starting point but addresses the subdependency case: #10440
There was a problem hiding this comment.
also cc @gluxon as he worked with this code recently. See my previous comment.
It seems we're mostly on the same page now, but I definitely agree with @zkochan's suggestion. Like the builtin resolvers, custom resolvers should support some form of resolution skipping. Otherwise pnpm install with custom resolvers will be slower than it needs to be. I also agree it feels most correct for this to be a property of the custom resolver that needs to be implemented.
There was a problem hiding this comment.
Does #10440 address that concern? The idea is that this PR would be closed in favor of that one.
There was a problem hiding this comment.
Gotcha! I haven't done a full read of #10440's implementation, but it seems like the right direction based on the title.
I believe @zkochan is working on something similar for builtin resolvers (linked above as #10439). You may see some merge conflicts when #10439 goes in, but I suspect it'll make the custom resolver case easier to implement overall when builtin resolvers also implement resolution skipping themselves.
816ee91 to
b65c2a9
Compare
|
some tests are failing |
| let resolution = options.currentPkg?.resolution as Resolution | ||
| let pkgId = options.currentPkg?.id | ||
| const skipResolution = resolution && !options.update | ||
| const skipResolution = resolution && !options.update && !options.forceResolve |
There was a problem hiding this comment.
I think you don't need this new forceResolve option. You can do this:
| const skipResolution = resolution && !options.update && !options.forceResolve | |
| const skipResolution = resolution && !options.update && !isLocalOrCustomDep |
…ve returns true - Never skip resolution for dependencies with custom resolution type (type: 'custom:*') - Force re-fetch when custom dependency integrity changes - Add unit tests for custom resolution skip and integrity change detection
b65c2a9 to
23d0fc4
Compare
|
Closing in favor of #10440, per discussion above. |
This PR is a follow-up for the new custom resolvers and fetchers feature added by #10246.
When trying to integrate that feature (newly released in v11.0.0-alpha.2) into one of my projects, I was surprised to find that:
resolvefunction wasn't running if there was a matching lockfile entry for the dependency, even whenshouldForceResolvereturnedtrue. (The install process would say "Already up to date".)resolvewith the same ID as the existing resolution, my custom fetcher wouldn't run, even if I changed theintegrityfield.This PR fixes both issues by treating
custom:dependencies as potentially mutable, just likefile:dependencies. Specific changes:shouldForceResolvereturnstrueintegritychangescheckCustomResolverForceResolveto read manifest whenallProjectsis empty