How to use better-commits package locally within repository
krupis opened this issue · comments
Hello. I have been using globally installed better-commits
(using npm install -g better-commits
) and everything was fine.
Since we have many people on the team working on the same project (repository), I would like to install the better-commits
package locally to the repository and upload the node_modules
and package.json
to git to ensure that all team members can just simply use the package out of the box
I cd
into my repository and installed the better-commits
locally using npm install better-commits
and uninstalled the global package using npm uninstall -g better-commits
. After that, I uploaded all the generated node files to the git.
After I uninstalled the better-commits
globally, I have tried to use the locally installed better-commits
but that does not seem to work even though the npm list
says that I have the package installed:
Could someone clarify to me what could be an issue and how to correctly use locally installed package?
My guess is that when I run better-commits
it is looking for node_modules
in the local directory which is:
C:\Users\petrikas.lu\AppData\Roaming\npm\node_modules
However, node_modules
exist in the project directory
I have figured out what was the issue.
If I use the command:
npx better-commits
Then it will work as expected.
I believe npx tells that this package is local
Short Answer: npm run better-commits
or npx better-commits
.
Long answer
better-commits utilizes
- A repository or global config
- A global or package npm version. (package npm version being specific to projects using package.json)
Better Commits Repository-Level Config
On startup, better-commits
- looks for your git root. If found, it will try to find your config there. If successful, it will use your repository-level config.
- If it can't find it, it will check your
$HOME
directory. If it finds a config in the$HOME
directory, it will use your global config. - If it can't find it there, it will create a new global config in your
$HOME
directory.
I mention this first part, because you can run better-commits
on a per-repository basis, in any project. It doesn't have to be a project with package.json
or even a javascript/nodejs project.
For example, you can even install better-commits via the AUR, without directly installing npm (technically, under the hood, this still uses npm 😅).
Better Commits NPM Version
To use better-commits
as a project-level package.json dependency. (This is specific to projects using package.json
)
npm install better-commits
(in your project directory)
Then add a script to your package.json
"scripts": {
"commit": "npm run better-commits"
}
Caveat: The script name can be anything, I just used commit
here.
Then in your project directory npm run commit
. This will run better-commits
using your projects node_modules
instead of your global `node_modules.
Hope this helps :)