在项目开发中,随着项目迭代,我们需要更新我们的项目包,但是有心的同学就会发现,在更新包的时候仅仅使用 yarn upgrade
或者 npm upgrade
时,只有 yarn.lock
文件或者 package-lock.json
文件更新,而我们的包文件 package.json
却没有表示出新的包版本,那么我们如何解决呢?
-
输入更新的命令
注意这里的更新命令不是upgrade
哦,而是使用upgrade-interactive
命令,我们看看这个命令有何神奇之处使用
yarn help upgrade-interactive
查看帮助信息Usage: yarn upgrade-interactive [flags] Provides an easy way to update outdated packages. Options: -v, --version output the version number --no-default-rc prevent Yarn from automatically detecting yarnrc and npmrc files --use-yarnrc <path> specifies a yarnrc file that Yarn should use (.yarnrc only, not .npmrc) (default: ) --verbose output verbose messages on internal operations --offline trigger an error if any required dependencies are not available in local cache --prefer-offline use network only if dependencies are not available in local cache --enable-pnp, --pnp enable the Plug'n'Play installation --disable-pnp disable the Plug'n'Play installation --strict-semver --json format Yarn log messages as lines of JSON (see jsonlines.org) --ignore-scripts don't run lifecycle scripts --har save HAR output of network traffic --ignore-platform ignore platform checks --ignore-engines ignore engines check --ignore-optional ignore optional dependencies --force install and build packages even if they were built before, overwrite lockfile --skip-integrity-check run install without checking if node_modules is installed --check-files install will verify file tree of packages for consistency --no-bin-links don't generate bin links when setting up packages --flat only allow one version of a package --prod, --production [prod] --no-lockfile don't read or generate a lockfile --pure-lockfile don't generate a lockfile --frozen-lockfile don't generate a lockfile and fail if an update is needed --update-checksums update package checksums from current repository --link-duplicates create hardlinks to the repeated modules in node_modules --link-folder <path> specify a custom folder to store global links --global-folder <path> specify a custom folder to store global packages --modules-folder <path> rather than installing modules into the node_modules folder relative to the cwd, output them here --preferred-cache-folder <path> specify a custom folder to store the yarn cache if possible --cache-folder <path> specify a custom folder that must be used to store the yarn cache --mutex <type>[:specifier] use a mutex to ensure only one yarn instance is executing --emoji [bool] enable emoji in output (default: true) -s, --silent skip Yarn console logs, other types of logs (script output) will be printed --cwd <cwd> working directory to use (default: /Users/mengjun/Documents/repository/start) --proxy <host> --https-proxy <host> --registry <url> override configuration registry --no-progress disable progress bar --network-concurrency <number> maximum number of concurrent network requests --network-timeout <milliseconds> TCP timeout for network requests --non-interactive do not show interactive prompts --scripts-prepend-node-path [bool] prepend the node executable dir to the PATH in scripts --no-node-version-check do not warn when using a potentially unsupported Node version --focus Focus on a single workspace by installing remote copies of its sibling workspaces. --otp <otpcode> one-time password for two factor authentication -S, --scope <scope> upgrade packages under the specified scope --latest list the latest version of packages, ignoring version ranges in package.json -E, --exact install exact version. Only used when --latest is specified. -T, --tilde install most recent release with the same minor version. Only used when --latest is specified. -C, --caret install most recent release with the same major version. Only used when --latest is specified. -h, --help output usage information Visit https://yarnpkg.com/en/docs/cli/upgrade-interactive for documentation about this command.
-
简单的使用
--latest
代表将安装包更新到最新版本yarn upgrade-interactive --latest
-
然后就可以看到可更新的安装包列表,此时我们输入
a
代表全选,然后回车即可;或者我们使用空格键选择想要更新的包,然后回车。 -
到这里就大功告成了,快看一看你的
package.json
是否已经同步更新了
更多内容
前端开发转全栈,目前的技术栈是 Node.js、Python,日常研究 C、C++ 和 Rust,孜孜啃食系统开发和网络设计中~
更多的内容请移步GitHub@ruxf,知乎@如小非,掘金@如小非,或者关注我的公众号@全栈开发师,欢迎来撩~
学到老,写到老,生命不停,编程不止~
加油,打工人~