fix: don't silently skip an optional dependency if it cannot be resolved from a mature version (#10289)

close #10270
This commit is contained in:
Zoltan Kochan
2025-12-08 11:18:24 +01:00
parent 98b00f4348
commit 17d34fab8c
7 changed files with 19 additions and 5 deletions

View File

@@ -0,0 +1,8 @@
---
"@pnpm/resolve-dependencies": patch
"@pnpm/npm-resolver": patch
"@pnpm/default-reporter": patch
"@pnpm/outdated": patch
---
Don't silently skip an optional dependency if it cannot be resolved from a version that satisfies the `minimumReleaseAge` setting [#10270](https://github.com/pnpm/pnpm/issues/10270).

View File

@@ -0,0 +1,5 @@
---
"@pnpm/npm-resolver": major
---
Changed the error code for no matching version that satisfies the maturity configuration.

View File

@@ -70,6 +70,7 @@ function getErrorInfo (logObj: Log, config?: Config): ErrorInfo | null {
case 'ERR_PNPM_MISSING_TIME':
return { title: err.message, body: 'If you cannot fix this registry issue, then set "resolution-mode" to "highest".' }
case 'ERR_PNPM_NO_MATCHING_VERSION':
case 'ERR_PNPM_NO_MATURE_MATCHING_VERSION':
return formatNoMatchingVersion(err, logObj as unknown as { packageMeta: PackageMeta, immatureVersion?: string })
case 'ERR_PNPM_RECURSIVE_FAIL':
return formatRecursiveCommandSummary(logObj as any) // eslint-disable-line @typescript-eslint/no-explicit-any

View File

@@ -1359,7 +1359,7 @@ async function resolveDependency (
bareSpecifier: wantedDependency.bareSpecifier,
version: wantedDependency.alias ? wantedDependency.bareSpecifier : undefined,
}
if (wantedDependency.optional && err.code !== 'ERR_PNPM_TRUST_DOWNGRADE') {
if (wantedDependency.optional && err.code !== 'ERR_PNPM_TRUST_DOWNGRADE' && err.code !== 'ERR_PNPM_NO_MATURE_MATCHING_VERSION') {
skippedOptionalDependencyLogger.debug({
details: err.toString(),
package: wantedDependencyDetails,

View File

@@ -73,7 +73,7 @@ export class NoMatchingVersionError extends PnpmError {
} else {
errorMessage = `No matching version found for ${dep} while fetching it from ${opts.registry}`
}
super('NO_MATCHING_VERSION', errorMessage)
super(opts.publishedBy ? 'NO_MATURE_MATCHING_VERSION' : 'NO_MATCHING_VERSION', errorMessage)
this.packageMeta = opts.packageMeta
this.immatureVersion = opts.immatureVersion
}

View File

@@ -63,7 +63,7 @@ export async function getManifest (
})
return resolution?.manifest ?? null
} catch (err) {
if ((err as { code?: string }).code === 'ERR_PNPM_NO_MATCHING_VERSION' && opts.publishedBy) {
if ((err as { code?: string }).code === 'ERR_PNPM_NO_MATURE_MATCHING_VERSION' && opts.publishedBy) {
// No versions found that meet the minimumReleaseAge requirement
return null
}

View File

@@ -62,7 +62,7 @@ test('getManifest() with minimumReleaseAge filters latest when too new', async (
// Simulate latest version being too new
const error = new Error('No matching version found') as Error & { code?: string }
error.code = 'ERR_PNPM_NO_MATCHING_VERSION'
error.code = 'ERR_PNPM_NO_MATURE_MATCHING_VERSION'
throw error
})
@@ -109,7 +109,7 @@ test('getManifest() handles NO_MATCHING_VERSION error gracefully', async () => {
const resolve: ResolveFunction = jest.fn(async function () {
const error = new Error('No matching version found') as Error & { code?: string }
error.code = 'ERR_PNPM_NO_MATCHING_VERSION'
error.code = 'ERR_PNPM_NO_MATURE_MATCHING_VERSION'
throw error
})