mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
fix: print a better error message when "time" is missing from metadata (#8059)
This commit is contained in:
7
.changeset/ninety-jokes-watch.md
Normal file
7
.changeset/ninety-jokes-watch.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@pnpm/npm-resolver": patch
|
||||
"@pnpm/default-reporter": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Print a better error message when `resolution-mode` is set to `time-based` and the registry fails to return the `"time"` field in the package's metadata.
|
||||
@@ -67,6 +67,8 @@ function getErrorInfo (logObj: Log, config?: Config, peerDependencyRules?: PeerD
|
||||
return reportLockfileBreakingChange(err, logObj)
|
||||
case 'ERR_PNPM_RECURSIVE_RUN_NO_SCRIPT':
|
||||
return { title: err.message }
|
||||
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':
|
||||
return formatNoMatchingVersion(err, logObj)
|
||||
case 'ERR_PNPM_RECURSIVE_FAIL':
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
import { type VersionSelectors } from '@pnpm/resolver-base'
|
||||
import semver from 'semver'
|
||||
import util from 'util'
|
||||
import { type RegistryPackageSpec } from './parsePref'
|
||||
import { type PackageInRegistry, type PackageMeta } from './pickPackage'
|
||||
|
||||
@@ -50,7 +51,15 @@ export function pickPackageFromMeta (
|
||||
manifest.name = meta['name']
|
||||
}
|
||||
return manifest
|
||||
} catch (err: any) { // eslint-disable-line
|
||||
} catch (err: unknown) {
|
||||
if (
|
||||
util.types.isNativeError(err) &&
|
||||
'code' in err &&
|
||||
typeof err.code === 'string' &&
|
||||
err.code.startsWith('ERR_PNPM_')
|
||||
) {
|
||||
throw err
|
||||
}
|
||||
throw new PnpmError('MALFORMED_METADATA',
|
||||
`Received malformed metadata for "${spec.name}"`,
|
||||
{ hint: 'This might mean that the package was unpublished from the registry' }
|
||||
@@ -128,6 +137,9 @@ export function pickVersionByVersionRange (
|
||||
|
||||
let versions = Object.keys(meta.versions)
|
||||
if (publishedBy) {
|
||||
if (meta.time == null) {
|
||||
throw new PnpmError('MISSING_TIME', `The metadata of ${meta.name} is missing the "time" field`)
|
||||
}
|
||||
versions = versions.filter(version => new Date(meta.time![version]) <= publishedBy)
|
||||
if (!versions.includes(latest)) {
|
||||
latest = undefined
|
||||
|
||||
Reference in New Issue
Block a user