
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
将常见的其它格式的npm包转成cjs的npm包的cli.
在开发cjs包时, 如果想使用esm包 (如inquirer最新版本、chalk等), 难免需要配置复杂的打包配置来支持. 但也可以另辟蹊径, 用cli的方式自动将这些包转换为cjs包, 并用自己的账户存到npm仓库上. 同时也便于以后的开发.
注意: 打包后npm包的README文件会自动加上来源信息, 以表示对原作者产权的尊重
npm i npm2cjs -g or yarn global add npm2cjs
npm2cjs config set reformNameType=suffix reformNameValue=-cjs 给包名添加-cjs的后缀, 如: 要打包的包名为chalk, 发布之后的npm包即为chalk-cjs
更多配置项请使用npm2cjs config -h查看
npm2cjs do <pkg-name> 将包名为<pkg-name>的包转换为cjs, 并发布
也可 npm2cjs do <pkg-name@version>
npm2cjs do <pkg-name> -d <output-dir> --no-publish 将包名为<pkg-name>的包转换为cjs, 并保存到<output-dir>目录下, 不发布
请使用npm2cjs -h查看
目标包不能用top-level-await, babel不会解析top-level-await且直接保留代码, webpack解析top-level-await会有bug. 需要单独的解析器(详细看文章mjs转译为cjs(快来造轮子)), 尚未开始开发, 欢迎一起搞
不支持多个入口文件, 目前是只打算支持一个入口文件的转换
不支持多个导出文件, 功能尚未完成
FAQs
将常见的其它格式的npm包转成cjs的npm包的cli
The npm package npm2cjs receives a total of 22 weekly downloads. As such, npm2cjs popularity was classified as not popular.
We found that npm2cjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.