4

Yarn would like to add a git tag when publishing a node module. However this folder is added to gitignore.

 yarn publish dist

Output:
    The following paths are ignored by one of your .gitignore files:
    dist/package.json
    Use -f if you really want to add them.
    info Visit https://yarnpkg.com/en/docs/cli/publish for documentation about this command.

How can you keep dist in gitignore, but make an exception for yarn to be able to add the dist folder to a git commit?

I've tried:

-.npmignore without dist folder (-->ignored by yarn)

-add a files array to package.json

-anyone has other suggestions?

tk421
  • 5,775
  • 6
  • 23
  • 34
Vincent
  • 6,058
  • 15
  • 52
  • 94
  • I'm not clear how `yarn publish` and a Git commit are related. Is adding `dist/` to a Git commit actually your goal, as stated? – Jake Worth Jul 31 '19 at 14:15
  • 1
    Yarn publish also pushes git tags whenever you run the publish command – Vincent Jul 31 '19 at 14:16
  • Interesting; thanks for clarifying @Vincent! – Jake Worth Jul 31 '19 at 14:49
  • Possible duplicate of [How to publish a npm package with distribution files?](https://stackoverflow.com/questions/31642477/how-to-publish-a-npm-package-with-distribution-files) – Jake Worth Jul 31 '19 at 14:50
  • 2
    Not really because that question is about what sources to publish and doesnt clarify about yarn doing automatically git tagging – Vincent Jul 31 '19 at 14:52

1 Answers1

3

My solution to this (more of a work-around, I suppose), is to call yarn publish with the --no-git-tag-version option, e.g.

yarn publish dist/ --no-git-tag-version
simon
  • 15,344
  • 5
  • 45
  • 67
  • This also works. I ended up splitting the publishing step in two. 1) yarn pack which builds a gzip archive and 2)yarn publish that archive. Than git tagging is also skipped – Vincent Jan 04 '21 at 10:20