Everduin94 / better-commits

A CLI for creating better commits following the conventional commits specification
MIT License
1.88k stars 69 forks source link

How to use better-commits package locally within repository #79

Closed krupis closed 5 months ago

krupis commented 5 months ago

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:

image

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

krupis commented 5 months ago

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

Everduin94 commented 5 months ago

Short Answer: npm run better-commits or npx better-commits.

Long answer

better-commits utilizes

Better Commits Repository-Level Config

On startup, better-commits

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 :)