mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-28 12:01:37 -04:00
* fix(npm-resolver): respect version constraints when falling back to workspace packages When link-workspace-packages=true, the fallback resolution paths (registry 404 and no matching registry version) pass update: Boolean(opts.update) to tryResolveFromWorkspacePackages. On fresh installs without a lockfile entry, opts.update is 'compatible' (truthy), which overrides the version spec to '*' and matches any workspace package regardless of version. Change both fallback call sites to pass update: false so version constraints are always respected for non-workspace-protocol dependencies. The workspace: protocol path returns before these blocks and correctly continues to use opts.update. Close #10173 * test: clarify npm-resolver test names for workspace version mismatch scenarios --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
@pnpm/npm-resolver
Resolver for npm-hosted packages
Installation
pnpm add @pnpm/npm-resolver
Usage
'use strict'
const createResolveFromNpm = require('@pnpm/npm-resolver').default
const resolveFromNpm = createResolveFromNpm({
store: '.store',
offline: false,
rawConfig: {
registry: 'https://registry.npmjs.org/',
},
})
resolveFromNpm({alias: 'is-positive', bareSpecifier: '1.0.0'}, {
registry: 'https://registry.npmjs.org/',
})
.then(resolveResult => console.log(JSON.stringify(resolveResult, null, 2)))
//> {
// "id": "registry.npmjs.org/is-positive/1.0.0",
// "latest": "3.1.0",
// "package": {
// "name": "is-positive",
// "version": "1.0.0",
// "devDependencies": {
// "ava": "^0.0.4"
// },
// "_hasShrinkwrap": false,
// "directories": {},
// "dist": {
// "shasum": "88009856b64a2f1eb7d8bb0179418424ae0452cb",
// "tarball": "https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz"
// },
// "engines": {
// "node": ">=0.10.0"
// }
// },
// "resolution": {
// "integrity": "sha1-iACYVrZKLx632LsBeUGEJK4EUss=",
// "registry": "https://registry.npmjs.org/",
// "tarball": "https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz"
// },
// "resolvedVia": "npm-registry"
// }
License
MIT