Multiple .npmignore files nested - npm

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.

Related

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.

Do I need to copy-paste stuff form ".gitignore" to ".npmignore"

So I was reading this.
And I'm a bit confuse how it's works, as I understood it:
If I only have .gitignore in my repo npm will use .gitignore but If I have both .gitignore and .npmignore npm will only read .npmignore, right? Or it will read both?
Need to know, if it's only reading .npmignore I have to copy-paste stuff from .gitignore as well.
Or it will read both
As mentioned here, it will read only the .npmignore
If you want to include something that is excluded by your .gitignore file, you can create an empty .npmignore file to override it.
Although, Jeff Dickey advocates for: "For the love of god, don’t use .npmignore"
However, what you probably don’t know is that my little action of adding the npmignore file actually causes npm to now consult that file instead of the gitignore files.
This is a major issue—I’ve now leaked all my AWS credentials out to the public just by adding this .npmignore to hide my test directory.
What’s worse is I probably have no idea this happened. npm publish doesn’t show the files that were packed (it actually does with npm 6).
I don’t see the files on the npm registry.
The only real way to see the files is by adding the package to a project and manually looking inside node_modules.
I might do that someday out of curiosity and discover my AWS credentials have been sitting out in the open for months.
Solution/safer alternative:
npm supports whitelisting though, just add a files attribute to package.json with everything you intend to add to the project.
Now only the files that are specified in files will be included in the project and your dotfiles will be ignored.

Make npm ignore folders starting by certain prefix

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

PhpStorm automatically ignore files from .gitignore

I'm new to PhpStorm, and I'm trying to get it to automatically ignore files specified in my .gitignore file when adding a file tree to git. I know you can add ignore rules to PhpStorm itself, but I want it to use the rules from my .gitignore file.
Basically I already have a .gitignore file with ignore rules, I just want PhpStorm to follow those rules when adding files (git add) so that none of the files matching the .gitignore rules will be accidentally added to a commit.
I know in the past this has happened to me as well, so it seems a bit fragile. I never do a git add for the entire directory since it has done things like add files in the /vendor directory (which is always in the gitignore file).
But having said that, I was curious, so I did a test as I think it might be related to when things happen (like when git is engaged, or when the .gitignore is added).
I did the following steps on a new project and it worked appropriately, so maybe that will help, you can give it a try and see if it works for you as well. I am working with 2016.1.2
Create the project
Select VCS...Enable Version Control Integration and select Git
Create the .gitignore in the root directory
In the project, create a new directory called ignore
In the .gitignore, add ignore/ and the ignore directory should turn light gray
Create a.txt in the root directory
create b.txt in the /ignore directory
right click on whole project and select git add and b.txt under the ignore directory is not added, but a.txt is

AccuRev is ignoring my .acignore file

I have an .acignore file that looks like this:
**\build
**\build\**
**\.gradle
**\.gradle\**
My file structure is as follows:
AccuRev Workspaces
.accurev
Workspace1
Workspace 2
I placed my .acignore file into the .accurev folder under AccuRev Workspaces and restarted AccuRev. It didn't start ignoring any of the files that I expected it to (and they are all external). I then put it directly under the AccuRev Workspaces folder and restarted; still no luck. I even put it in both of those places under an individual workspace and it didn't work. I'm at my wits' end. What is going on here????
The .acignore file must be in the workspace top directory. In other words, you would need an .acignore in the Workspace1 directory and another in Workspace2. This allows you to have different ignore rules for each workspace. Alternatively, you could add it to source control if you have standard ignore rules applicable to all workspaces.