admin管理员组文章数量:1418659
I have a npm dependency (e.g. ngx-infinite-scroll
) that I'm currently trying to fork (for bug fixes) and include my forked version as a dependency in my application. Below an example of the include in my package.json
:
"dependencies": {
"ngx-infinite-scroll": "github:jcroll/ngx-infinite-scroll#bugfixes",
},
In the above I've forked the repo at github and created a new branch called bugfixes
.
My problem is that the maintainer runs a build process that creates an artifact in a ./dist
directory and then publishes this flat directory to npm using $ npm run publish ./dist
. However, when I install my new forked repo via $ npm i ngx-infinite-scroll
the entire repo is downloaded and not the dist
dir.
Now I know this should be expected. One thing I was hoping to do was at least get the dist
dir to be created on install by adding to the scripts of the library's package.json
:
"scripts": {
...
"prepare": "npm run build"
},
However I still do not see the dist
directory on install. Even then I would still have to alter the package.json to point the module
key to this new nested directory entry point.
What I would like instead is when I install this library from github is to have it publish its flattened dist
directory as the top level directory of the library just like how the original library installs by the maintainer building the library and running $ npm rub publish ./dist
. Is there any way to do this?
Edit: I am also aware via this answer that I could build the dist and mit the code to this new branch but I'd like a more elegant way, hence the question.
I have a npm dependency (e.g. ngx-infinite-scroll
) that I'm currently trying to fork (for bug fixes) and include my forked version as a dependency in my application. Below an example of the include in my package.json
:
"dependencies": {
"ngx-infinite-scroll": "github:jcroll/ngx-infinite-scroll#bugfixes",
},
In the above I've forked the repo at github and created a new branch called bugfixes
.
My problem is that the maintainer runs a build process that creates an artifact in a ./dist
directory and then publishes this flat directory to npm using $ npm run publish ./dist
. However, when I install my new forked repo via $ npm i ngx-infinite-scroll
the entire repo is downloaded and not the dist
dir.
Now I know this should be expected. One thing I was hoping to do was at least get the dist
dir to be created on install by adding to the scripts of the library's package.json
:
"scripts": {
...
"prepare": "npm run build"
},
However I still do not see the dist
directory on install. Even then I would still have to alter the package.json to point the module
key to this new nested directory entry point.
What I would like instead is when I install this library from github is to have it publish its flattened dist
directory as the top level directory of the library just like how the original library installs by the maintainer building the library and running $ npm rub publish ./dist
. Is there any way to do this?
Edit: I am also aware via this answer that I could build the dist and mit the code to this new branch but I'd like a more elegant way, hence the question.
Share Improve this question asked Mar 12, 2018 at 19:09 jcrolljcroll 7,1759 gold badges55 silver badges68 bronze badges 1-
1
Shouldn't your mand be
"prepare": "cd node_modules/ngx-infinite-scroll && npm i && npm run build"
? – Tarun Lalwani Commented Mar 15, 2018 at 5:31
2 Answers
Reset to default 5 +50There are two things you can do
Changes to your package
You have a event prepare
, postinstall
or install
and use the below in the same
"postinstall": "cd node_modules/ngx-infinite-scroll && npm i && npm run build"
Then if you really want to use dist, you could do something like below
"postinstall": "cd node_modules/ngx-infinite-scroll && npm i && npm run build && mv dist ../ngx-infinite-scroll-dist && cd .. && rm -rf ngx-infinite-scroll && mv ngx-infinite-scroll-dist ngx-infinite-scroll && cd ngx-infinite-scroll && npm i",
Build in fork
Another option is to change the fork and update the postinstall
of the package.json to do the npm run build
and create the dist
folder when the forked package is installed
Edit: 20-Mar-2018
You were right, if we use postinstall
then it will create infinite loop. You can do that in a prepack
event.
"prepack": "node build.js",
Below is a sample github project you can actual test
https://github./tarunlalwani/ngx-infinite-scroll/tree/so49242809
Test it using
npm add tarunlalwani/ngx-infinite-scroll#so49242809
And it will have the dist folder once installed
There is this simpler way: patch-package
patch-package lets app authors instantly make and keep fixes to npm dependencies. It's a vital band-aid for those of us living on the bleeding edge.
Patches created by patch-package are automatically and gracefully applied when you use npm(>=5) or yarn.
No more waiting around for pull requests to be merged and published. No more forking repos just to fix that one tiny thing preventing your app from working.
本文标签:
版权声明:本文标题:javascript - Is there a way to fork a npm library in package.json and run its build process on install? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745295401a2652045.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论