Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:npm install does not detect engine-compatible package properly #7825

Open
wants to merge 1 commit into
base: latest
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions workspaces/arborist/lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
const { depth } = require('treeverse')
const { log, time } = require('proc-log')
const { redact } = require('@npmcli/redact')
const semver = require('semver')

const {
OK,
Expand Down Expand Up @@ -1185,23 +1186,64 @@
return problems
}

async #fetchManifest (spec) {
async #fetchManifest(spec) {

Check failure on line 1189 in workspaces/arborist/lib/arborist/build-ideal-tree.js

View workflow job for this annotation

GitHub Actions / Lint

Missing space before function parentheses
const options = {
...this.options,
avoid: this.#avoidRange(spec.name),
fullMetadata: true,
fullMetadata: true, // Ensure full metadata is fetched
}
// get the intended spec and stored metadata from yarn.lock file,
// if available and valid.

Check failure on line 1195 in workspaces/arborist/lib/arborist/build-ideal-tree.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
// Check for stored metadata from yarn.lock if available and valid
spec = this.idealTree.meta.checkYarnLock(spec, options)

Check failure on line 1198 in workspaces/arborist/lib/arborist/build-ideal-tree.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
if (this.#manifests.has(spec.raw)) {
return this.#manifests.get(spec.raw)
} else {
log.silly('fetch manifest', spec.raw.replace(spec.rawSpec, redact(spec.rawSpec)))
const mani = await pacote.manifest(spec, options)
this.#manifests.set(spec.raw, mani)
return mani

Check failure on line 1203 in workspaces/arborist/lib/arborist/build-ideal-tree.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
if (this.options.engineStrict) {
// Fetch the packument (all versions' metadata)
const packument = await pacote.packument(spec, options)

Check failure on line 1207 in workspaces/arborist/lib/arborist/build-ideal-tree.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
// Get the list of available versions
let versions = Object.keys(packument.versions)

Check failure on line 1210 in workspaces/arborist/lib/arborist/build-ideal-tree.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
// Filter versions based on `engines.node`
versions = versions.filter(version => {
const pkg = packument.versions[version]
const nodeEngine = pkg.engines && pkg.engines.node
if (!nodeEngine) {
return true // No `engines.node` means compatible
}
return semver.satisfies(process.version, nodeEngine)
})

Check failure on line 1220 in workspaces/arborist/lib/arborist/build-ideal-tree.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
// Determine the best version that satisfies the spec
const range = spec.fetchSpec || '*'
const maxSatisfyingVersion = semver.maxSatisfying(versions, range)

Check failure on line 1224 in workspaces/arborist/lib/arborist/build-ideal-tree.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
if (!maxSatisfyingVersion) {
throw new Error(
`No compatible version found for ${spec.name}@${spec.rawSpec} with current Node.js version ${process.version}`
)
}

Check failure on line 1230 in workspaces/arborist/lib/arborist/build-ideal-tree.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
// Get the manifest of the selected version
const mani = packument.versions[maxSatisfyingVersion]
this.#manifests.set(spec.raw, mani)
return mani
} else {
// engine-strict not enabled, proceed as usual
try {
const mani = await pacote.manifest(spec, options)
this.#manifests.set(spec.raw, mani)
return mani
} catch (error) {
// Handle errors
error.requiredBy = spec.from || '.'
throw error
}
}
}
}

Expand Down
Loading