当我运行npm install react@^15
时,它会自动选择满足^15
的最大版本。我可以使用 CLI 命令或 Node 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
关于node.js - 确定 npm 将为给定版本范围选择哪个版本的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47542609/