确定 npm 将为给定版本范围选择哪个版本的包
Determine which version of a package npm will pick for a given version range
当我运行npm install react@^15
时,它会自动选择满足^15
的最大版本。是否有 CLI 命令或节点 API 我可以用来确定要安装哪个版本 npm
,而无需实际安装它?
我可以执行以下操作,但我正在寻找更简洁的内容:
const semver = require('semver')
const {exec} = require('child-process-async')
async function resolveVersion(pkg: string, range: string): Promise<?string> {
const result = JSON.parse((await exec(`npm view --json ${pkg} verisons dist-tags`)).stdout)
return result['dist-tags'][range] || semver.maxSatisfying(versions, range)
}
是的,您可以使用 --dry-run 标志:
The --dry-run argument will report in the usual way what the install would have done without actually installing anything.
示例:
> npm install react@^15 --dry-run
+ react@15.6.2
added 18 packages in 0.673s
当我运行npm install react@^15
时,它会自动选择满足^15
的最大版本。是否有 CLI 命令或节点 API 我可以用来确定要安装哪个版本 npm
,而无需实际安装它?
我可以执行以下操作,但我正在寻找更简洁的内容:
const semver = require('semver')
const {exec} = require('child-process-async')
async function resolveVersion(pkg: string, range: string): Promise<?string> {
const result = JSON.parse((await exec(`npm view --json ${pkg} verisons dist-tags`)).stdout)
return result['dist-tags'][range] || semver.maxSatisfying(versions, range)
}
是的,您可以使用 --dry-run 标志:
The --dry-run argument will report in the usual way what the install would have done without actually installing anything.
示例:
> npm install react@^15 --dry-run
+ react@15.6.2
added 18 packages in 0.673s