News for hackers. Stuff that matters.
Re:NPMprune: Remove unnecessary files from node_modules to o... by c0n5pir4cy on Wednesday November 29, 2023 @12:40PM (#38462427)
Just for package authors (or people looking for some easy pull requests) out there that might not know this exists.

NPMs package.json has a `files` field which allows you to define which files are included on an npm install: https://docs.npmjs.com/cli/v6/configuring-npm/package-json#f....

This also extends to an .npmignore file that works similar to a .gitignore file.

Re:NPMprune: Remove unnecessary files from node_modules to o... by creatonez on Wednesday November 29, 2023 @12:47PM (#38462547)
Just beware that some files may seem unnecessary but are expected from an idiomatic npm package. Three things that come to mind -- a markdown file named README.md, any generated typescript definitions, and typescript/babel sourcemaps. And something I've seen far too often: please don't give a minified, rolled up bundle as the only option, otherwise you are chucking your library's users back into the dark ages of Bower.js.
Re:NPMprune: Remove unnecessary files from node_modules to o... by josephg on Wednesday November 29, 2023 @03:02PM (#38464481)
Yep. And if you’re writing typescript, please include type definitions, source maps, type definition source maps and the original typescript source.

Having all of this stuff makes it possible to ctrl+click on functions in my libraries and read the corresponding source code. That’s a godsend during development - well worth a few extra kb of files in the npm module.

tsconfig.json:

    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    ...
package.json (assuming typescript compiles src/ to dist/):

    "files": [
      "dist/*",
      "src/*"
    ],
Re:NPMprune: Remove unnecessary files from node_modules to o... by shepherdjerred on Wednesday November 29, 2023 @03:23PM (#38464752)
It makes me wonder why these are even configurable. These should all be emitted by default.
Re:NPMprune: Remove unnecessary files from node_modules to o... by nfriedly on Wednesday November 29, 2023 @01:25PM (#38463086)
The readme gets included automatically even if you don't specify it in the files field, ditto for the changelog license, and package.json.

Compare https://github.com/express-rate-limit/express-rate-limit/blo... to https://www.npmjs.com/package/express-rate-limit?activeTab=c...

Agree with you about the other points.

Re:NPMprune: Remove unnecessary files from node_modules to o... by rezonant on Wednesday November 29, 2023 @02:41PM (#38464216)
Strongly agree on minification. You should not minify or bundle anything in your NPM package. That decision should only be made by the top level project if it wishes.
Re:NPMprune: Remove unnecessary files from node_modules to o... by arthurwhite on Wednesday November 29, 2023 @01:20PM (#38463027)
If everyone used the `file` field, the world would be a better place, for sure.