What should be ignored in Dart's .pubignore?

Issue

With the Dart 2.14 release, pub now support a .pubignore file similar to .gitignore.

The docs don’t seem to mention what’s appropriate to include in it… are there any guidelines?

My immediate thought is that I shouldn’t include tests, which currently get published with my packages. And probably other dev-related stuff that’s not needed when just compiling the production code?!

Is this correct? Any other things that are good to ignore?

Solution

I work on dart pub, and the short answer is: Most developers probably won’t need to use .pubignore.

If you have files locally (caches or credentials) that you don’t want to publish, you probably also don’t want to commit them to git. So in most cases it is easiest to simply use .gitignore.

If you don’t use git, or you have some files that you want in git, but not published to pub.dev, then .pubignore is useful. Maybe you have a private repository that includes files with proprietary code that is only used for development / testing, or something like that. Or maybe your repository includes huge data files used for testing, which hits the size limitations when publishing to pub.dev.

Most of then time, if you don’t mind making a file public, and the file has a meaningful relation to the package, then I would suggest you include it.
Even if users of your package are unlikely to download it from pub.dev and run tests, it is IMO nice that the tests are included. This makes the package more complete and self-contained. We could even imagine a future where tests from a package are analyzed on pub.dev.

I think that if it was (or becomes) the opinion of the Dart team that files in test/ should not be included when a package is published, then the Dart team should modify the dart pub publish command to not publish such files by default (or at-least warn users against doing so).

Answered By – jonasfj

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *