The devDependencies section of npm's package.json documentation says to list your test dependencies there so that users of your package don't have to pull down extra dependencies. Would it make sense to also add my test directory to .npmignore in that case?
-
See related: stackoverflow.com/questions/25124844/…Eric Bock– Eric Bock2017-07-10 20:42:29 +00:00Commented Jul 10, 2017 at 20:42
3 Answers
Yes that's what most people do, here are some npmignore files for popular Node.js modules:
https://github.com/socketio/socket.io/blob/ab46351a8446516fb4eea3b8333f7c0f18afaac5/.npmignore
Other people allowlist what they want published in their package.json files setting:
https://github.com/senchalabs/connect/blob/master/package.json
https://github.com/strongloop/express/blob/master/package.json
3 Comments
npm test module if for some reason something isn't working and they want to test the modules they're using.npm install so they get all the actual development dependencies. It sucks big time when you start depending on some module that happens to have about 20 megabytes of autogenerated test code published to npm (e.g. moment-timezone <= 0.0.3), along with a bunch of test frameworks that I don't need in order to use the module.One thing that I haven't been able to find explicitly mentioned anywhere is the fact that the "files" entry in package.json supports using a ! prefix on an entry. So, for example, I have a "files" entry that looks like this:
{
"files": [
"lib/**/*",
"!lib/**/*.map"
],
}
I do that because my lib directory includes .map files that I don't want to include in the package, and this includes everything but the *.map files.
6 Comments
!/src/**/__tests__/*.test.ts worked for me.Another approach is to use a lib folder and store everything in there. Then you can configure your package.json to consider only that folder.
In order to work you need also to move your main file inside lib and specify it in the package.json. See example below:
{
"name": "your-package",
"main": "./lib/index.js",
"files": [
"/lib"
]
}
More info are available on this nice article