Skip to content

[baseline practices] .npmignore or package.json files #164

Closed

Description

@jchip

Do we have something for specifying the included files for publishing yet?

I just happen to look through some of the files in node_modules for one of my apps and this is what I found:

  • coverage, .nyc_output
  • .idea
  • .eslintrc, .travis.yml, etc
  • quite a few packages include their full test files.
  • also for packages written in ts, some are including the TS source, is that needed?

Kind of related to #77

We should have some thing that suggest ensuring files exist in package.json and include essential files for publishing.

Activity

  1. ljharb commented on Feb 14, 2019

    @ljharb
    SponsorMember

    First of all, "files" is super dangerous - forgetting to add a new file causes breakage. Nobody should ever use it.

    .npmignore is fine, but also, imo npm explore foo && npm install && npm test should always work - i consider it a best practice to always ship full tests with every package.

  2. jchip commented on Feb 15, 2019

    @jchip
    ContributorAuthor

    I have no opinion about .npmignore or files except .npmignore should be in .npmignore itself. We should have some mention about being mindful to publish without extra files and npm offers two ways.

    I approach this from practical stand point and prefer my node_modules smaller. I think publishing packages without extra files is one of the most overlooked thing and I've installed packages that publish demo images or temp files in the 10s of MB size. I think if there are a lot of tests it's better to leave them, but it's up to individual package owner. The practice I follow is prepublishOnly runs npm test.

  3. ljharb commented on Feb 15, 2019

    @ljharb
    SponsorMember

    The cost of publishing an extra file is slower install times; the cost of omitting a needed file is breakage. There’s no semver contract around package sizes to break.

  4. jchip commented on Feb 15, 2019

    @jchip
    ContributorAuthor

    as a user, I prefer both: faster install and no breakage.

  5. ljharb commented on Feb 15, 2019

    @ljharb
    SponsorMember

    In the better case, sure! But in the worse case, which would you prefer, a fast broken install, or a slow working one?

  6. jchip commented on Feb 15, 2019

    @jchip
    ContributorAuthor

    I'd like to clarify what you actually have issue with.

    It's clear you are against files and that test should be published. I am sure we can word it to your satisfaction.

    Do you actually have issue with the fact that we should have guideline about the broader topic I raised?

  7. ljharb commented on Feb 15, 2019

    @ljharb
    SponsorMember

    In general, yes - there are very few files I think should ever be excluded from the published tarball, and I'd be concerned that we'd be unable to come up with guidance that wouldn't over-weight "package size" as a consideration.

    In other words, I don't think that package authors should be solving this problem - I think npm should (and, with their "tink" project, they are).

  8. jchip commented on Feb 15, 2019

    @jchip
    ContributorAuthor

    OK, let me clarify. The primary motivation for bringing this up is because I don't think files like these should be published:

    • .DS_Store, .nyc_output, coverage, .idea, .vscode

    I don't think tink is solving that.

    npm could default to ignore those files, but I imagine that's not something they want to do either.

    I think having a guideline regarding be mindful of what files you published make sense.

  9. ljharb commented on Feb 15, 2019

    @ljharb
    SponsorMember

    oh sure. But those should all be gitignored - which makes them ignored by npm by default.

  10. dominykas commented on Feb 15, 2019

    @dominykas
    Member

    Depending on how you structure your project, you can have files be very safe. Basically, put stuff in lib/ and bin/ and you're grand. And docs/ as well.

    Re tests - that's very debatable. I wish there was tooling to easily "switch to use this deep dep to be installed from their git" so that you can get tests, but shipping tests together with the package is an antipattern in my eyes, partly because it complicates security efforts as there is more code to review/analyse - and that is code that's never going to be used in production (yes, it's a tradeoff between dev needs and prod needs). Keep in mind, that the payload for event-stream was hidden inside tests... Either way, because it's debatable, I agree that we can't say that it's a "best practice".

    Re other files - as a random one-off contributor I find it very uncomfortable when I need to add .idea to someone's .gitignore... and I know there's people who don't like it... so having that as a baseline would be very nice, but I'm not sure that's going to fly, because the list of common files is very large and it bloats the .gitignores. Instead, I'd really like it if npm actually respected a global .gitignore as well as the local one... There's an issue open for years.

  11. mcollina commented on Feb 15, 2019

    @mcollina
    SponsorMember

    I think @styfle should join this discussion. Mainly because we sit on the opposite side of this fence: he wrote https://packagephobia.now.sh/ and I'm a strict believer that sources, docs, tests and examples are key part of a package. Specifically, I think I should be able to build/test that package without having to open up git. I'm a huge fan of "show source feature" of the 90s web.

    Reducing the size of packages is important to reduce the size of the artifacts that we deploy. I think we should build a tool that traverse node_modules and remove not-needed files for production (tests, docs). This would be very nice to build as part of this group.

  12. styfle commented on Feb 15, 2019

    @styfle
    SponsorMember

    packages written in ts, some are including the TS source, is that needed?

    No, it is not needed. You can publish a just the type declaration file (think header file if you use C++) which is perfect for anyone installing your package.

    i consider it a best practice to always ship full tests with every package.

    I disagree. I think npm publish should be the minimum build artifacts only. When I run npm install yourpackage, I can't even run your tests because npm only installs the production dependencies, not the devDependencies from yourpackage. And I can tell you from experience, that most people who publish tests to npm do so by accident, not on purpose. That's why I built Package Phobia.

    I'm a huge fan of "show source feature" of the 90s web.

    Met too! But that's not realistic because people who are publishing to npm are not necessarily writing JavaScript. They might be writing Rust and compiling to WASM and then deploying the WASM to npm. They don't need to deploy the Rust source code, nor do I want them too. Their tests are probably written in Rust too.

    Probably a better approach to this "show the source feature" is to somehow enforce a build step when publishing to npm so that the source is guaranteed to match the build artifacts. Something like ZEIT Now Builders. But that's problem/topic for a different thread.

    Depending on how you structure your project, you can have files be very safe.

    I like files because I can just add files: ["dist"] and only the compiled output is going to be published. However, there is a known bug that is only affecting files but not .npmignore filtering. https://npm.community/t/ds-store-files-show-up-after-npm-publish/831

  13. ljharb commented on Feb 15, 2019

    @ljharb
    SponsorMember

    npm’s tink project will allow you to publish gigabytes if you like, but consumers will only install what they need - so this “phobia” will go away soon anyways, without forcing everyone to hamstring offline usage.

    Again, even if you want to restrict what shows up on npm, the “files” field is very dangerous, and i do not want this project to endorse its use in any way.

  14. jchip commented on Feb 16, 2019

    @jchip
    ContributorAuthor

    While a few things are debatable with opinions on either sides of the fence, I hope we can agree on the basic things that a guideline about having the proper setup to ensure some files are not published is a good practice.

    The guideline should only refer to the methods npm provides to do this, and avoid having any preferences on files or .npmignore.

    Maybe note some gotchas and tips:

    Other than that, I think we would leave the choice of whether to publish things like docs and test, or other files, to the individual package owner and their preferences.

  15. jchip commented on Feb 16, 2019

    @jchip
    ContributorAuthor

    also suggest to run a npm pack to inspect the tgz files content before doing a real publishing. I think there are tools out there that makes the publish process better. Maybe we can suggest one.

  16. 27 remaining items

  17. ghinks commented on Jul 19, 2019

    @ghinks
    Contributor

    I am going to go back to the original intent for this issue as raised by @jchip which is advice on which files should be ignored. I will open separate issues for the discussion points

    • github repos can be deleted
    • final bundle size impact != package size
    • tooling
    • minimalist vs fully inclusive

    these items I summarized above and we shall come back to them but Joel’s initial intent was just to get a list of regular files such as .vscode and log files etc that should be ignored. My intent is to look at the existing github git ignore repo and see what additional files should be ignored. It may even be a good idea to raise a PR against the node gitignore that is being used.

  18. craftninja commented on Jul 29, 2019

    @craftninja
    Contributor

    From meeting: Maybe we give people pros and cons of choices, multiple best practices (plural) - offer different perspectives of different solutions. A blog post and updates to NPM docs? The blog post asks the question, doesn't necessarily provide The Solution. We could outline several use cases and examples for different paths.

  19. ghinks commented on Jul 31, 2019

    @ghinks
    Contributor

    agreed @craftninja . I am looking at using the gitignore.git from http://github.com/github/gitignore as a base ignore with modifications and adding, as you said a number of options, I am going off grid for 10 days though.

  20. wesleytodd commented on Jul 31, 2019

    @wesleytodd
    Member

    Since you mentioned http://github.com/github/gitignore maybe I can plug this module I maintain.

    https://www.npmjs.com/package/create-git

    The module uses those gitignore templates and lets you select multiple. If we want to make a "best practice" for .gitignore in node packages I agree we should PR there, and then I can add it as the default for this package. This might be the start of the "tooling" we want for this as well.

  21. lholmquist commented on Aug 1, 2019

    @lholmquist
    Contributor

    agree with the blog post showing the different solutions. Showing the pros and cons of each solution is a good compromise on the different schools of thought.

    while i don't like to compare node modules to maven packages, there is something nice about being able to "go download the source" of a particular package, at least in development

  22. mhdawson commented on Aug 13, 2019

    @mhdawson
    Member

    From discussion in the meeting this week, sound like the next steps might be a PR for the guidance and then a blog post to publicize but the guidance might be more around discussing the options versus making a specific recommendation.

  23. ahmadnassri commented on Aug 13, 2019

    @ahmadnassri

    I like the blog post idea, and would support it further in hosting (or cross-posting) it on the official npm blog as a guest post by whoever wants to author it.

  24. mhdawson commented on Aug 13, 2019

    @mhdawson
    Member

    @jchip will you have time to put together a PR, authoring a blog post?

  25. jchip commented on Aug 15, 2019

    @jchip
    ContributorAuthor

    @mhdawson yes, I can work on it next week (end of summer, which was usually busy for me with kids).

  26. added
    articleNeed to spread this information
    on Aug 31, 2019
  27. mhdawson commented on Nov 5, 2019

    @mhdawson
    Member

    Close as PR has landed

  28. styfle commented on Nov 5, 2019

    @styfle
    SponsorMember

    @mhdawson Can you link to the PR and the final web page?

  29. Eomm commented on Nov 5, 2019

    @Eomm
    Member
  30. GrosSacASac commented on Dec 5, 2019

    @GrosSacASac

    When I use an external dependencies I like it to be as small as possible. I want to see more I can always use npm info ws repository.url. But there are problems when git and npm are out of sync, so at the end including everything in the npm package is also ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    articleNeed to spread this informationpackage-maintenance-agendaAgenda items for package-maintenance team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions