patch npm node_modules & patch-package All In One
如何安全地修改
node_modules下的第三方 package 中的代码
如何安全地给 node_modules 下的第三方 package 打补丁
patch-package 实现原理剖析
- 备份过程:执行命令 npx pacth-package
package_name,先复制一份修改后的 package 文件,然后命名为package_name+package_version.patch, 最后放到项目的根目录下的 patchs 文件夹下; - 安装过程: npm install 时候,通过 npm scripts 的
postinstall钩子,执行覆盖操作,使用package_name+package_version.patch 把package_name覆盖掉,实现文件自动替换;
patch-package
# npm
$ npm i -D pacth-package
# yarn v1
$ yarn add patch-package postinstall-postinstall
# yarn v2, https://yarnpkg.com/cli/patch
$ yarn patch <package>
# pnpm, https://pnpm.io/cli/patch
$ pnpm patch <pkg>
https://www.npmjs.com/package/patch-package

https://github.com/ds300/patch-package
demos


patch-package in action
https://github.com/web-fullstack/patch-package-in-action
(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
tsc --init
$ npx tsc --init
This is not the tsc command you are looking for
To get access to the TypeScript compiler, tsc, from the command line either:
- Use npm install typescript to first add TypeScript to your project before using npx
- Use yarn to avoid accidentally running code from un-installed packages

# ?
$ npm i -g typescript
# ✅
$ tsc --init
$ npm i -S typescript
# ❌
$ tsc --init
# ✅
$ npx tsc --init

refs
https://www.liguo.run/hack-node-modules-code
https://www.cnblogs.com/xgqfrms/p/16559401.html
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!