I currently have a shared eslint config that's kept in the npm module #my-scope/eslint-config. This is working well, but I was hoping that including the .eslintignore file in that npm module would also be shared but it doesn't look like it is shared. What's the best way to share this .eslintignore file between projects?
Have you explicitly added the .eslintignore file to the files array of your package.json?
https://docs.npmjs.com/files/package.json#files
Have you tried specifying an --ignore-path pointing to your other .eslintignore? As described here:
http://eslint.org/docs/user-guide/configuring#using-an-alternate-file
I replaced my .eslintignore file with the ignorePatterns in the config file. And then I share the config file between repositories.
Definitely cleaner than pointing to node_modules folder.
Documentation: https://eslint.org/docs/latest/use/configure/ignore#ignorepatterns-in-config-files
Related
For reference, the repo is https://github.com/microsoftly/luis-response-builder.
The node module files are generated with tsc and output to the dist folder. I have a prepublishOnly step that removes the dist folder, runs tsc, then runs the test against the transpiled js. The tests pass when I publish just fine.
The problem is, when I install the project anywhere else, the dist folder contains only the file with the path dist/src/index.js.
I cannot for the life of me figure out why the file is missing when installed but not when published.
Quoting from npm-publish Documentation:
All files in the package directory are included if no local .gitignore or .npmignore file exists. If both files exist and a file is ignored by .gitignore but not by .npmignore then it will be included.
Your repository's .gitignore file contains the following:
node_modules
dist
*.env
yarn-error.log
Since dist is being ignored, it's not committed with npm publish, as per the documentation.
Check out the package.json documentation about files.
Since you haven't included the files key, it will only include the file specified in main (along with some other default files).
The files value is an array so you can include multiple files and/or folders.
eg:
files: [
"dist",
"config/somefile.js"
]
Yarn has created yarn.lock and yarn-error.log.
I have been told not to add yarn.lock to my .gitignore file because it locks down the packages.
Should I ignore the latter?
It makes sense to ignore the yarn-error.log—log files are only useful to debug your own copy of the code, so there's no need to upload it to the repository.
File should be uploaded to your repo when they are useful or needed to build your project. The yarn-error.log (as the name suggests) is an error log, so it's never read by Yarn. The whole point of it is that you read the log to find out what went wrong, and if you've not had any errors, it might not even exist at all.
gitignore.io, a service which generates .gitignore files, include yarn-error.log and yarn-debug.log in their .gitignore file for Node:
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
It may be wise to follow their example if you're not sure what you need—most pre-made .gitignore files have thought this issue through and concluded that logs should generally be ignored.
Since writing this I realise all log files are typically ignored in the .gitignore file with this entry:
*.log
Its system specific log file for the user. So it should be added to gitignore.
some times we find error that is "cannot find symbol" when build the project.
to solve that problem we add this file to our root project.
we can use it in our project where all all files and folder are available.
just above to yarn.log file
I've placed a .eslintignore file in the root of my create-react-app installation, so I can ignore warnings from vendor libs.
It works fine if I run eslint from the commandline:
./node_modules/.bin/eslint src/js/vendor/jquery.js
...warnings ignored...
However running npm start and npm run build seem to ignore the ignore file.
How can I achieve what I want to do here - without editing individual vendor files to add eslint options?
This was fixed with this commit in CRA codebase: https://github.com/facebook/create-react-app/commit/6f5221c2d7df0b7a097cfdd461967422c3013e12#diff-dc0c4e7c623b73660da1809fc60cf6ba
Simply add EXTEND_ESLINT=true to a .env file in your project root.
YES .eslintignore is ignored. According to this issue.
CRA 1.x+ purposely does not support .eslintignore. Sorry!
Workarround
add /* eslint-disable */ to the beginning of the file.
move vendor files into public/ or use a NPM package.
Seems to work if I exclude complete directories from the .eslintignore in the root. Here is my .eslintignore
src/js/vendor/
src/vendor/
I have a project that uses babel, and I was curious if a .babelrc file is typically gitignored or not. I am using a couple of presets that are apart of the package.json file that I have in the .babelrc file so it seems like a .babelrc file should be in source control, but not totally sure.
tldr; you should not ignore it.
In case you have some codebase which can be compiled only under relevant babel configuration, you need to specify appropriate configuration for babel. So it becomes obvious that everyone who will run this project from scratch will need to have that pre-defined to run an application properly.
I have a file that is generated by npm install command (using preinstall task). I don't want to add it in the git repository, nor in the NPM project.
Supposing the file name is foo.json, I added it in .gitignore file as foo.json.
Is this enough to avoid uploading it on NPM registry?
I know I can add .npmignore file that will surely ignore the file, but I won't add it if .gitignore already does this.
If a project has both an .npmignore and .gitignore file, npm will only use the .npmignore file.
From the documentation:
Use a .npmignore file to keep stuff out of your package. If there's no .npmignore file, but there is a .gitignore file, then npm will ignore the stuff matched by the .gitignore file. If you want to include something that is excluded by your .gitignore file, you can create an empty .npmignore file to override it.
In simpler terms, npm prefers the .npmignore file if it is there, but will fall back to the .gitignore file.
In many cases, both Git and npm can ignore the same files, so it makes sense to just use a .gitignore file on its own. If there's ever a discrepancy (i.e. npm and Git need to ignore different files), then you need to maintain separate .gitignore and .npmignore files.
More information on what to put in .npmignore files: Should I .npmignore my tests?
For anyone reading this trying to ignore a file/dir from git but wish to include it in npm publish and have tried using an empty .npmignore file with no luck. This works.
In your .gitignore file, add the file/dir you wish to exclude **/build for example and in your .npmignore file make sure you specify the same file/dir but with the ! prefix so for the build example you would include !**/build