"Is this an "only broken on my machine" thing?"
No, this is (almost) expected behaviour given your projects current configuration(s) - and no npm doesn't cache the .npmignore
file somewhere.
The reason I said "almost" previously is because in your last comment you said:
"So in this case, all paths in templates/*
are ignored, but the paths in common/contracts
are included in the package."
That should not be the case because according to npm's expected behaviour as stated in the docs, (see "Why is this happening?" section below), none of the patterns currently specified in your .npmignore file should be effective given your current package.json's files
configuration.
What you're encountering is odd behaviour, i.e. some patterns are being respected whilst others are not, however hopefully by following either of the two proposed solutions/approaches (below) you'll get the correct desired result.
Why is this happening?
The docs for package.json's files
field states the following which is pertinent to your issue:
Note: Bold emphasis added by me.
You can also provide a .npmignore
file in the root of your package or in subdirectories, which will keep files from being included. At the root of your package it will not override the “files” field, but in subdirectories it will.
So, the reason why the patterns currently specified in your .npmignore file are NOT being ignored is because they are trying to override the inclusion patterns currently specified in your package.json's files
field. Essentially, because your .npmignore file currently resides at the root of your package it will not override the “files" field.
Solutions
Here are a two different solutions/methods to consider (they're in no particular order):
Omit the files
entry from package.json and augment your current .npmignore file as necessary
i.e. Delete this from package.json:
"files": [
"/common",
"/templates"
],
Then create additional patterns in your current .npmignore file for any other directories/files that should also be excluded from packing/publishing. In other words add any patterns to .npmignore for assets that do not reside somewhere in /common
or /templates
that should also be excluded.
For example, after briefly looking at your repo, you'll need to add the pattern tests
to .npmignore too.
In summary, this first approach is a case of delete the files
field and specify all patterns for assets to be ignored in one place - in the .npmignore
file at the root of your project.
Or, keep the files
entry in package.json as-is and create additional .npmignore files in subdirectories
Given the patterns currently specified in your .npmignore file are:
common/contracts/rust/target
common/contracts/out
templates/*/.cache
templates/*/assembly
templates/*/contract
templates/*/package.json
templates/*/src/assets
templates/*/src/config.js
templates/*/src/global.css
templates/*/src/utils.js
and also given that the docs stated; "at the root of your package [.npmignore] will not override the “files” field, but in subdirectories it will" then you'll need to:
Create a .npmignore file in the common/contracts/
directory containing the following patterns:
rust/target
out
Create a .npmignore file in the templates/
directory containing the following patterns:
*/.cache
*/assembly
*/contract
*/package.json
*/src/assets
*/src/config.js
*/src/global.css
*/src/utils.js
The .npmignore
file currently residing at the root of your project directory (as-is) becomes redundant with this second method.
Note: Hopefully by following either of the two aforementioned solutions/methods, (which do closely adhere to npm's documented expectations), you'll get the desired result. However, if neither of those proposed solutions yield the desired result, then I suggest keeping one of the proposed solutions as a baseline starting point, then reading some of the answers in this SO thread. Yes, the question is the opposite of your issue, however you might gain further insight towards next steps particularly from this answer - it mentions "npm pack and publish respect any package.json files you have in the directory tree, not just at the root.".
templates/*
are ignored, but the paths incommon/contracts
are included in the package. – chadoh