当前位置:网站首页>How does yarn link help developers debug NPM packages?
How does yarn link help developers debug NPM packages?
2022-07-03 07:47:00 【Front end watermelon brother】
Hello everyone , I'm brother watermelon . Recent research React Source code , Yes yarn link Command to link two items .
I became interested in its underlying principles , So I wrote such an article , I hope that through the form of story , Let us understand yarn link Usage scenarios and usage .
in addition npm link and yarn link The effect is the same , Not mentioned below npm link 了 .
one day , A name maintained by xiaogua is xigua Of NPM package , Was mentioned issue. Melon looked at the problem description , With familiarity with the project , He probably knows what went wrong .
In order to test , Melon built a demo-project project , And this project passed yarn add xiga Installed this package , And used it in the code .
└── demo-project
└── node_modules
├── apple
└── xigua
├── old.js
└── package.json
Theoretically , Melon, go to this demo-project Project node_module/xigua Just modify the code directly under the directory .
But unfortunately , The code inside is compiled , It's not possible to modify .
Little melon then ran xigua-project Package source code project , Run a generation that can monitor source code modification npm Command of package content . Melon modified a code , Then it is automatically compiled to xigua-project/build/ in .
└── xigua-project
└── build
└── xigua( Compiled folder )
├── fix.js
└── package.json
Then melon copies the compiled code , Cover up the original demo-project/node_module/xigua , Then see if the effect is wrong . Melon found something wrong , Re reform , And then copy , Repeated several times in a row .
“ I can't bear it , We need to find a way .” Melon said . Copy manually after each compilation , It's too annoying .
Witty little melon, think about it , Finally came up with a way .
take demo-project Under the xigua Dependent package deletion
And then create a xigua Soft link file , link to xigua-project Compile folder under ( Soft links can be understood as shortcut files , You can redirect the file location )
├── demo-project
│ └── node_modules
│ ├── apple
│ └── xigua( Redirect ) -> /xigua/build/node_modules/xigua
└── xigua-project
└── build
└── xigua( Linked location )
├── fix.js
└── package.json
Use soft links , We linked the two projects .
yarn link
here , Roommate xiaorun passed by with his cuddle , Yu is the name of his cat .
Melon is complacent about his wonderful ideas , Immediately boast to Xiao run .
Xiaorun :“ This requirement , Package manager is supported by related commands .”
Melon :“ Unexpectedly ! Expand and talk about how to use .”
Xiao run then explained .
It's very simple , We enter xigua/build/xigua Under the table of contents , perform yarn link
$ yarn link
yarn link v1.22.17
success Registered "xigua".
info You can now run `yarn link "xigua"` in the projects where you want to use this package and it will be used instead.
Done in 0.01s.
such , The package management tool will Register a global name xiuga Link to .
Specifically, create a xigua Soft link file , Point to this xigua Catalog . stay macOS in , Is in ~/.config/yarn/link/xigua Under the table of contents .
The link points to the following :
~/.config/yarn/link/xigua -> /xigua-project/build/xigua
More precisely ,yarn link It will look up from the current working directory, and the first one will be correct package.json File directory , As a linked object , because npm There must be package.json.
Next we'll run to demo-project Project directory , perform yarn link xigua.
$ yarn link xigua
yarn link v1.22.17
success Using linked package for "xigua".
Done in 0.01s.
It can do two operations :
take demo-project Under the xigua Dependent package deletion
And then create a xigua Soft link file , link to yarn/link/xigua. formation
demo-project -> yarn/link -> xigua-projectChain .
Melon was shocked :“ This operation is the same as mine ? But one more A middleman yarn”
Yes , but yarn More convenient .
yarn unlink
you are here demo-project The test is over , Want to disconnect the link , It needs to be executed at this time :
$ yarn unlink xigua
yarn unlink v1.22.17
success Removed linked package "xigua".
info You will need to run `yarn install --force` to re-install the package that was linked.
Done in 0.01s.
After breaking the link , Because the original package was deleted and a link file was changed , So we need to pack this again , You need to perform yarn install --force.
You said I delete node_modules, And then execute yarn OK? .
Sure , The premise is that your node_modules There are no links to other packages , Otherwise, the links of other packages will be killed .
If you want to delete the global registration, the name is xigua Of link, You need to enter the linked directory , perform yarn unlink
$ yarn unlink
yarn unlink v1.22.17
success Unregistered "xigua".
info You can now run `yarn unlink "xigua"` in the projects where you no longer want to use this package.
Done in 0.01s.
ending
yarn link The function of is to help us debug and develop NPM package .
Because the dependent package installation of ordinary projects is downloaded and installed from the network , If you want to use locally compiled NPM package , A better way is to delete the dependent package , Link our local compilation package through shortcuts .
To simplify this process ,yarn link There is , Through the middle of the form , To achieve fast link and unlink.
I'm brother watermelon , Welcome to follow me , Learn the front end together .
边栏推荐
- Pgadmin 4 v6.11 release, PostgreSQL open source graphical management tool
- 【LeetCode】3. Merge Two Sorted Lists·合并两个有序链表
- 技术干货|昇思MindSpore创新模型EPP-MVSNet-高精高效的三维重建
- Pat class a 1032 sharing
- Go language foundation ----- 18 ----- collaboration security, mutex lock, read-write lock, anonymous lock, sync Once
- An article for you to understand - Manchester code
- [coppeliasim4.3] C calls UR5 in the remoteapi control scenario
- 技术干货|百行代码写BERT,昇思MindSpore能力大赏
- 技术干货|昇思MindSpore可变序列长度的动态Transformer已发布!
- 项目经验分享:基于昇思MindSpore实现手写汉字识别
猜你喜欢

項目經驗分享:實現一個昇思MindSpore 圖層 IR 融合優化 pass

Pat class a 1030 travel plan

技术干货|昇思MindSpore Lite1.5 特性发布,带来全新端侧AI体验

Usage of requests module

PAT甲级 1029 Median

Go language foundation ----- 15 ----- reflection

技术干货|昇思MindSpore创新模型EPP-MVSNet-高精高效的三维重建

密西根大学张阳教授受聘中国上海交通大学客座教授(图)

Project experience sharing: handwritten Chinese character recognition based on Shengsi mindspire

Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
随机推荐
Go language foundation ----- 15 ----- reflection
[at] ABC 258g - Triangle triples reachable - violence
Epoll related references
【LeetCode】2. Valid Parentheses·有效的括号
The concept of C language pointer
LwIP learning socket (API)
项目经验分享:基于昇思MindSpore实现手写汉字识别
技术干货 | AlphaFold/ RoseTTAFold开源复现(2)—AlphaFold流程分析和训练构建
Project experience sharing: realize an IR Fusion optimization pass of Shengsi mindspire layer
Differences between tp3.2 and tp5.0
HDMI2.1与HDMI2.0的区别以及转换PD信号。
Technical dry goods Shengsi mindspire operator parallel + heterogeneous parallel, enabling 32 card training 242 billion parameter model
项目经验分享:实现一个昇思MindSpore 图层 IR 融合优化 pass
华为交换机Console密码重置、设备初始化、默认密码
Leetcode 198: house raiding
Go language foundation ----- 06 ----- anonymous fields, fields with the same name
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
Go language foundation ----- 18 ----- collaboration security, mutex lock, read-write lock, anonymous lock, sync Once
哪一刻你才发现青春结束了
GoLang之结构体