Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include/exclude globs cannot be rooted, yet .gitignore globs often *should* be #754

Open
cspotcode opened this issue Oct 12, 2024 · 0 comments

Comments

@cspotcode
Copy link

This is not a huge problem, but it's a point of confusion that caught me when setting up my first JSR project.
Using rooted /foo.ext globs in publish.include will silently fail, effectively excluding everything from your package. But .gitignore supports them. 1

My project publishes to npmjs.com using yarn w/a package.json files array telling it which files to bundle. I also have a .gitignore.

https://github.com/cspotcode/outdent/blob/957909edffb94a9a619368373eb3800cd8ef8829/package.json#L55-L65
https://github.com/cspotcode/outdent/blob/main/.gitignore

Both use rooted paths starting with /. This is because a .gitignore rule foo.ts will ignore <root>/foo.ts, <root>/lib/foo.ts, <root>/test/foo.ts whereas a rooted ignore rule /foo.ts will only ignore <root>/foo.ts. I use rooted patterns habitually, only using a non-rooted pattern when that is really what I want, for example node_modules. 2

However, when configuring my jsr.jsonc, I was caught off guard because /src was not including my /src directory. So my package was empty. Removing the leading slashes fixed it: https://github.com/cspotcode/outdent/blob/957909edffb94a9a619368373eb3800cd8ef8829/jsr.jsonc#L6-L9

deno publish --dry-run made this easy to diagnose, and I love how fast it is! The confusion stemmed from assuming, incorrectly, that I could use identical syntax to my gitignore, since include and gitignore are so often mentioned in the same breath. I realize exact corner-case parity with git is probably not a reasonable requirement, but perhaps a quick mention in the docs would help?

Footnotes

  1. Not sure if "rooted" is the correct terminology.

  2. A slash anywhere in the pattern makes it rooted.
    https://git-scm.com/docs/gitignore
    "If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs Triage
Development

No branches or pull requests

1 participant