Make npm ignore folders starting by certain prefix - npm

Right now my .gitignore files has the following rule:
demos/test**
Which seems to be working fine with Git (and github) and ignoring the following folders:
./demos/test-whatever/
./demos/test/
But when publishing to npm, those folders are not ignored and are being published.
Any way to exclude them from npm?

You may want .npmignore to keep files out of your package.

Create a .npmignore file in your root directory and add your demos/test** ignore rule to this file. For reference:
.npmignore
demos/test**

Try a .npmignore file More info

Related

Files missing with npm pack

I am building a npm module, in which I want to include two directories : /dist and /demo.
So far, my approach was to use the 'files' attribute, in package.json :
"files": [
"dist",
"demo"
]
When running npm pack, the tgz files successfully contains the demo folder, and the built files in /dist.
However, during the build phase, I added a shell script that is copying some files (generated mylib.js and mylib.css) to the /demo directory. And my problem is that npm pack does not care about these specific files, which are not included in the tgz (despite I can see them in my explorer).
However, if the shell script make changes to the content of /demo/index.html, these changes are included in the tgz.
How could I include the missing files?
Seems that I misinterpretated the problem:
if the files were not in the tgz, it is because I add a .gitignore in /demo, ignoring js and css files.
As I really don't want this files to be commited, the solution was to add a .npmignore file, with no rule matching css/js

How to force npm publish to include files (that are not required by the entry)?

I have an npm project for generating packages. It contains a folder called templates. The files in templates are not required by the entry point index.js instead they are collected using fs. They are not appearing in the published version. I have tried adding files: ["templates"] to the package.json (and various combinations ("templates/*", "templates/**/*", "templates/something/somefile.js") but the files are never included. The only files in templates folder that appear are Licence and package.json.
How do I make npm include these files in the published version?
Edit: My project directory has a .gitignore file but that does not include the templates folder. It does not have an .npmignore file.
The reason that the License and package.json files are appearing in your templates folder, is because npm ignores any attempt to exclude these files.
I would check that you don’t have any .ignore files in your templates folder and also check further up the filesystem, does the folder that contains your project have one? What about it’s parent and so on?
Then try temporarily removing the .gitignore file as well.
Lastly try publishing from another machine if nothing else works.

GIT ignoring files in project/bin/debug folder except few files (Visual Studio Project)

This is how my .gitignore looks like:
# User-specific files
*.userprefs
!*.ini
!*.gitkeep
!*.bat
# Build results
[Bb]in/
[Dd]ebug/
What I want to achieve is to ignore all files in project/bin/debug but keep the files like *.ini *.bat and etc.
.gitignore is location in root folder:
rootfolder\project name\bin\Debug
This works well for me. Add wildcard to your folders, and define the exceptions at the bottom.
# Build results
[Bb]in/*
[Dd]ebug/*
# User-specific files
*.userprefs
!*.ini
!*.gitkeep
!*.bat
Use ! operator to negate pattern:
*.bat
!myfile.bat
In your case it's better to use .gitignore in specific directory. You should make .gitignore file in project/bin/debug with a content:
*.*
!*.bat
Or you can do it in your project main .gitignore:
MyFolder/*
!MyFolder/NotIgnored.txt
Without * it won't work.
Keep in mind that already staged files won't be ignored. You need to unstage them using git rm --cached <file>
I solved this by modifying the .gitignore of my root folder to:
# User-specific files
*.userprefs
!*.ini
# Build results
![Bb]in/
[Bb]in/*
![Dd]ebug/
Then creating another .gitignore file inside rootfolder/project/bin/debug/ directory with the ff:
*
!*.ini
!*.bat
Hope this can help someone in the future.
And btw, I got my .gitignore file from: https://www.gitignore.io/api/visualstudio

Multiple .npmignore files nested

I have a solution where I have 2 .npmignore files. One packages only the bare essentials for creating a project. The second is one directory hire and is intended to include everything beneath it.
What appears to be happening is when publishing at the higher level the lower level .npmignore settings are used. This gives me the wrong package.
Is it possible to specify which .npmignore file to use or at least tell npm to ignore any .npmignore file not in the root directory of where the publish is occurring?
Thanks,
Bob
You can't specify which .npmignore file to use. Every one in your directory tree is used, like you have discovered. However, if you need specific files allowed/ignored you can specify relative paths.

Git and XCode: Merging .xcodeproj gives binary warning

I am working with branches and wanting to merge with my master, but the files inside of my .xcodeproj are causing huge issues.
Constantly getting errors about overriding them, that they are binary files, etc etc.
What do I need to do to never have to worry about this? It is driving me nuts!
NOTE: I have a .gitignore file in my master that ignores these files, but not in my branch. Not sure what to do about that.
In the root of the project (eg, same directory as .git), add a git ignore file
.gitignore
With a line that says
.xcodeproj
Then remove the .xcodeproj file from the repo...
git rm --cached /path/to/.xcodeproj
Then add the .gitignore file
git add .gitignore
Then commit
git commit -m "Removed .xcodeproj; added ignore pattern to excluded it"
You can use a .gitignore file to specify that file to be ignored by git.