How to test an `npm publish` result, without actually publishing to NPM?

后端 未结 4 876
暖寄归人
暖寄归人 2021-01-30 08:53

One common problem I have, is that sometimes my .npmignore file is too aggressive, and I ignore files that I actually will to include in the NPM tarball.

My question is

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 09:39

    I had the exact same problem, so I created a package called package-preview. What package-preview does is:

    1. packs your package (it is what npm does before publish)
    2. installs your package in a temp location
    3. links the package to your project's node_modules

    This allows you to basically require the package as a dependency in your tests. So in tests of "awesome-pkg", intead of require('../lib') you write require('awesome-pkg')

    I use this package in all the pnpm repos for several months and it works really well. I also posted an article about this package that explains all the different errors that it can catch: Never ever forget to install a dependency

提交回复
热议问题