Yarn import now uses package-lock.json
转发自: https://yarnpkg.com/blog/2018/06/04/yarn-import-package-lock/?utm_source=tuicool&utm_medium=referral
Posted Jun 4, 2018 by Aram Drevekenin
For a while now, the JavaScript ecosystem is a host to a few different dependency lock file formats, including yarn’s yarn.lock and npm’s package-lock.json.
We are quite excited to announce that as of 1.7.0 yarn is able to import its dependency tree from npm’s package-lock.json natively, without external tools or clunky processes.
This will no doubt come as great news for developers working in mixed npm/yarn environments or wanting to try yarn out on existing projects.
All you need to do is issue the yarn import command in a repository with a package-lock.jsonfile, and yarn will use the resolution information from the existing package-lock.json file and a corresponding yarn.lock file will be created.
This feature is one of the first fruits of a continuing collaboration between the maintainers of the two package managers. We feel strongly about the two tools being aware of each other and providing an easy transition path between them. If you are interested or want to help, head over to the related GitHub issue.
How does it work under the hood
Previously, yarn import would rely on a package’s node_modules directory to determine the fixed versions to which the the new yarn.lock file needs to resolve its semver ranges. Now, it falls back to this behaviour if it cannot find a package-lock.json file.
When it does, yarn creates a dependency tree using npm-logical-tree from the package.json and package-lock.json in the project’s root directory. It then uses the fixed versions in that tree to create its own yarn.lock lockfile. The resulting yarn.lock will have all the exact fixed versions specified in package-lock.json. Ready to be installed and committed in your repository.
Limitations
The two lockfile formats and contents are different. Each have their own priorities, guarantees and trade-offs in terms of determinism, consistency and more. Since yarn.lock chooses only to store the logical dependency tree, preferring to future-proof for potential physical tree and hoisting optimizations, there are certain nuances that package-lock.json expresses that yarn.lockcannot.
One example would be:
// package-lock.json (slightly simplified for clarity)
{
"name": "nuanced-dependency-tree",
"dependencies": {
"a": {
"version": "9.9.9",
"requires": {
"c": "^1.0.0"
},
"dependencies": {
"c": {
"version": "1.0.1"
}
}
},
"b": {
"version": "8.8.8",
"requires": {
"c": "^1.0.0"
}
},
"c": {
"version": "1.0.5"
}
}
}
Here, we have both packages a and b which require the same semver range of package c: ^1.0.0 and get different versions: 1.0.1 and 1.0.5 respectively.
This would be imported to yarn as:
// yarn.lock (slightly simplified for clarity)
a@9.9.9
version "9.9.9"
dependencies:
c "^1.0.0"
b@8.8.8
version "8.8.8"
dependencies:
c "^1.0.0"
c@^1.0.0
version "1.0.5"
Here b’s dependency c would change its locked version from 1.0.1 to 1.0.5 because yarn.lock cannot express this duplication. Yarn chooses and aims to have a single resolved version for all compatible version ranges. While in most cases such minor changes should not have much effect - we encourage you to use this feature with care. You can still override ranges if you need to, using the selective version resolutions feature in yarn.
Future plans
Currently, we’re planning to add some warnings to users who use both yarn and npm in the same repository to install packages. If there’s a need, we might also try to expand this feature to other lock file formats. If you’d like to point out other issues of interoperability, or try your hand at fixing them - we encourage you to file an issue or better, fix one by sending a PR.
We highly recommend you to delete the package-lock.json file if you decide to use yarn in order to avoid future confusion and possible consistency issues.
Yarn import now uses package-lock.json的更多相关文章
- yarn import 使用package-lock.json
yarn 1.7(目前最新的版本)支持npm 的package-lock.json 了 环境准备 安装更新yarn sudo npm install -g yarn 查看版本 yarn version ...
- Python 相对导入attempted relative import beyond top-level package
ValueError: attempted relative import beyond top-level package 假设有如下层次包目录 project/ __init__.py mypac ...
- Python导入自定义类时显示错误:attempted relative import beyond top-level package
显示这个错误可能有两个原因: 1.文件夹中没有包含__init__.py文件,该文件可以为空,但必须存在该文件. 2.把该文件当成主函数入口,该文件所在文件夹不能被解释器视作package,所以可能导 ...
- python项目内import其他内部package的模块的正确方法
转载 :https://blog.csdn.net/u011089523/article/details/52931844 本文主要介绍如何在一个Python项目中,优雅的实现项目内各个package ...
- ValueError: attempted relative import beyond top-level package
python 项目 在pycharm中, 在某个文件夹下: 右键--> mark directory as --> source root 如何在python脚本或者shell中 用代码实 ...
- npm和yarn的区别,我们该如何选择?
首先,这两个都属于js包管理工具,都可以安装包或者模块yarn 是由facebook.google等联合开发推出的区别: npm 下载包的话 比如npm install它是按照包的排序,也就是队列挨个 ...
- npm和yarn使用
npm和yarn使用 他们都属于js包管理工具,都可以安装包或者模块yarn 是由facebook.google等联合开发推出的 区别: npm 下载包的话 比如npm install,它是按照包的排 ...
- vue.config.json CopyWebpackPlugin 没有生效
本地生效,服务器不生效. 因为是jenkinis构建,没有留意到报错.后来发现错误:ENOENT: no such file or directory, rename 解决方法就是:删除package ...
- 解决npm ERR!Unexpected end of JSON input while paring near (解析附近时JSON输入意外结束)'...."^2.0.0-rc.0","glob"'等npm install错误
摘要 最近更新了一次node,但是更新后npm的命令总是会报 npm WARN deprecated fsevents@2.0.6: Please update: there are crash fi ...
随机推荐
- Redis快速入门之简介
一.Redis是什么? Redis 是一个开源(BSD许可)基于内存数据结构存储系统,它可以用作数据库.缓存和消息中间件. 它支持多种类型的数据结构,如字符串(strings), 散列(hashes) ...
- 六.__FILE__ , __LINE__ 与调试日志
很多人可能不知道,C\C++编译器提供了一套针对代码文件的宏定义,它们能够帮助开发者更好的定位代码的BUG. __FILE__ 该宏定义是一个字符串,存储着当前代码文件的完整路径 __LINE__ 该 ...
- InstallShield的工程类型的选择
转载:http://blog.csdn.net/wuxiaoqrs/article/details/45717695 InstallScript vs. Basic MSI InstallScript ...
- 设置WebApi里面命名空间参数
在这种情况下: 如果没有特别处理,会报: 所以要像MVC中的控制器一下配置一个命名空间参数,webapi里面没有自带这个功能 代码: using System; using System.Collec ...
- RabbitMQ入门_03_推拉模式
我们知道,消费者有两种方式从消息中间件获取消息: 推模式:消息中间件主动将消息推送给消费者 拉模式:消费者主动从消息中间件拉取消息 推模式将消息提前推送给消费者,消费者必须设置一个缓冲区缓存这些消息. ...
- angular-cli 文档
Angular/angular-cli 原文来自:https://github.com/angular/angular-cli Angular/angular-cli 原文来自:https://git ...
- 安装Ubuntu版本linux过程中没有提示设置root用户密码问题的解决办法
原来ubunto不提倡设置root用户,系统安装成功后,root密码是随机的,那么在这种情况下如何得到root权限呐,具体方法如下: 终端中输入:sudo passwd root 此时重新设置原登录用 ...
- LINUX 操作记录到syslog,并发送到syslog服务器上
首先配置命令记录到syslog中: 在客户端的/etc/bashrc 下添加: logger -p local3.info \"`who am i` ================== ...
- java并发编程:线程安全管理类--原子操作类--AtomicIntegerArray
1.类 AtomicIntegerArray
- c/c++指针常见错误
一 #include <bits/stdc++.h> using namespace std; void f(char *str) { char *s = str; str[] = ' / ...