Skip to content

fix: ensure custom resolver resolve() is called when shouldForceResolve returns true - #10342

Closed
TrevorBurnham wants to merge 1 commit into
pnpm:mainfrom
TrevorBurnham:prevent-custom-resolve-skip
Closed

TrevorBurnham wants to merge 1 commit into
pnpm:mainfrom
TrevorBurnham:prevent-custom-resolve-skip

Conversation

@TrevorBurnham

@TrevorBurnham TrevorBurnham commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor

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:

  1. My custom resolver's resolve function wasn't running if there was a matching lockfile entry for the dependency, even when shouldForceResolve returned true. (The install process would say "Already up to date".)
  2. If I returned a new custom resolution from resolve with the same ID as the existing resolution, my custom fetcher wouldn't run, even if I changed the integrity field.

This PR fixes both issues by treating custom: dependencies as potentially mutable, just like file: dependencies. Specific changes:

  • Never skip resolution for dependencies with custom resolution type (type: 'custom:*') if the custom resolver's shouldForceResolve returns true
  • Force re-fetch when a custom dependency's integrity changes
  • Fix checkCustomResolverForceResolve to read manifest when allProjects is empty

Copilot AI review requested due to automatic review settings December 19, 2025 23:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@TrevorBurnham
TrevorBurnham force-pushed the prevent-custom-resolve-skip branch from e2a94aa to 1e4c01f Compare December 20, 2025 02:33
@zkochan

zkochan commented Dec 21, 2025

Copy link
Copy Markdown
Member

are you sure about this? This will make installation with a lockfile much slower.

@TrevorBurnham
TrevorBurnham force-pushed the prevent-custom-resolve-skip branch from 1e4c01f to d0b0db7 Compare December 21, 2025 20:12
@TrevorBurnham

Copy link
Copy Markdown
Contributor Author

This will make installation with a lockfile much slower.

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 shouldForceResolve returns true.

@TrevorBurnham
TrevorBurnham force-pushed the prevent-custom-resolve-skip branch 2 times, most recently from bb3b330 to b9cff33 Compare December 22, 2025 01:20
@zkochan

zkochan commented Dec 22, 2025

Copy link
Copy Markdown
Member

I do wonder if this makes sense at all for the install command. This is more like an update.

@TrevorBurnham

Copy link
Copy Markdown
Contributor Author

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 shouldForceResolve method.

@zkochan

zkochan commented Dec 22, 2025

Copy link
Copy Markdown
Member

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 pnpm refresh.

@TrevorBurnham

Copy link
Copy Markdown
Contributor Author

Hmm. Putting on my user hat, I agree that it'd be frustrating if I ran pnpm install, a dependency got updated, and I didn't understand why. On the other hand, having to run a different command like pnpm refresh for some projects wouldn't be great either; pnpm install is in my muscle memory.

I think the solution is transparency. pnpm could emit a message during install like this:

`@my-company/foo@^2` was forced to re-resolve by a custom resolver.

Better still, if custom resolvers had a name property (like Yarn plugins do), we could use that in the message:

`@my-company/foo@^2` was forced to re-resolve by custom resolver `MyCompanyCriticalUpdates`.

That would make the process clear to users while keeping it automatic.

@zkochan

zkochan commented Dec 22, 2025 •

Copy link
Copy Markdown
Member

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.

@TrevorBurnham

Copy link
Copy Markdown
Contributor Author

I can think of a couple of use cases that are immediately relevant to my needs:

  • An org wants to push out a critical patch to one of their internal packages. Using a custom resolver with shouldForceResolve, they can apply that update automatically as part of the normal install process.
  • An org wants to synchronize code changes for multiple languages. They set up a system that takes a snapshot of related package versions, e.g. Python package [email protected] goes with JavaScript package [email protected]. You specify the snapshot version, then run pnpm install. A custom resolver then ensures that the version of frontend that's installed matches the one in the snapshot system.
  • An org wants to make it easy for developers to work on changes involving multiple packages in separate repos, so they create a system for linking packages that are being worked on together. The link system works both locally and when doing dry runs in CI. A custom resolver can create and update those links automatically on pnpm install without mutating package.json and package-lock.json, which is really helpful for reducing git diff noise.

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.

Comment thread deps/status/src/checkDepsStatus.ts Resolved
@KSXGitHub

KSXGitHub commented Jan 7, 2026 •

Copy link
Copy Markdown
Contributor

@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 checkDepsStatus.ts and workspace/state/src/types.rs.

First, pnpm loads the workspace state. This state file includes:

  • lastValidatedTimestamp: The timestamp of the last time the check has run.
  • projects: Collection of all the paths to all workspace packages (also containing name and version, but they're not relevant for the topic at hands).
  • The snapshot of other settings (they're also not relevant here, so I group them into a single item).

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 lastValidatedTimestamp comes into the picture. It would be compared against the mtime of each package.json file of every workspace package.

It also check other things, but I'm not sure if they are relevant. Just read the file to be sure.

@zkochan

zkochan commented Jan 7, 2026

Copy link
Copy Markdown
Member

@KSXGitHub

KSXGitHub commented Jan 7, 2026 •

Copy link
Copy Markdown
Contributor

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?

@zkochan

zkochan commented Jan 7, 2026

Copy link
Copy Markdown
Member

Add it to the readme of the package in that case.

@TrevorBurnham
TrevorBurnham force-pushed the prevent-custom-resolve-skip branch from b9cff33 to c87b7c2 Compare January 7, 2026 14:21
Comment thread pkg-manager/core/src/api.ts Resolved
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is forceResolve also checked? Seems unrelated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@zkochan zkochan Jan 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also cc @gluxon as he worked with this code recently. See my previous comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does #10440 address that concern? The idea is that this PR would be closed in favor of that one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Both PRs are needed to support what Trevor requested. At first glance #10440 seems alright but I'll review it more thoroughly after #10439 gets merged.

@TrevorBurnham
TrevorBurnham force-pushed the prevent-custom-resolve-skip branch 2 times, most recently from 816ee91 to b65c2a9 Compare January 9, 2026 19:35
@zkochan

zkochan commented Jan 9, 2026

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you don't need this new forceResolve option. You can do this:

Suggested change
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
@TrevorBurnham
TrevorBurnham force-pushed the prevent-custom-resolve-skip branch from b65c2a9 to 23d0fc4 Compare January 10, 2026 00:20
@TrevorBurnham

Copy link
Copy Markdown
Contributor Author

Closing in favor of #10440, per discussion above.

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.

5 participants