1

I installed a package from npm, but I needed to customize it. The problem is that, when the team install or update npm packages, the customization is overwritten.

I would like to know if there is anyway to preserve this customization or if I need to upload another package with the customization...

semanser
  • 2,310
  • 2
  • 15
  • 33
Felipe Avelar
  • 177
  • 3
  • 14

2 Answers2

3

as semanser says, you need fork the project, but the right way for include this in your package.json file is

"package-name": "<your user name>/<your package name>#<your branch>"

you can find additional information here

clagccs
  • 2,224
  • 2
  • 21
  • 33
2
  1. Create a Github fork of a package that you need to customize.
  2. Make changes that you want in your fork (don't forget to commit and push them).
  3. Add the link to the fork to your package.json file in the following format:

    "dependencies": {
      "bar": "git://github.com/foo/bar.git"
    }
    
  4. (optional) Create a Pull Request and wait until your changes will be approved in the original repo.

semanser
  • 2,310
  • 2
  • 15
  • 33
  • I tried this, but it is not installing my package. :/ – Felipe Avelar Oct 30 '17 at 14:31
  • Connection timeout when trying to connect to github, I think it is something with the firewall, but I could clone the repo normally when tried locally, but, when I try `npm install`, it can't connect to github. – Felipe Avelar Oct 30 '17 at 14:50
  • @FelipeAvelar maybe try another URL format, like `mygithubuser/project` or `github:mygithubuser/project` or `git+https://git@github.com/mygithubuser/project.git` or `https://github.com/mygithubuser/project.git` – semanser Oct 30 '17 at 14:55
  • When I tried `git+https://git@github.com/mygithubuser/project.git`, it executed `npm install`, but only get md files. :/ – Felipe Avelar Oct 30 '17 at 15:57
  • @FelipeAvelar can you share the link to your repo? – semanser Oct 30 '17 at 16:17
  • 1
    @FelipeAvelar Right, you are getting only `.md` files because your lib requires some build steps. Check out `package.json` of your installed lib, there is `prepublish` step, but it's not triggered in your case. For more details check also this link: https://stackoverflow.com/questions/40880642/prepublish-not-working-as-expected As documentation said, `prepublish` "Run BEFORE the package is packed and published, as well as on local npm install without any arguments." So to build lib you can trigger that event manually in your project. – semanser Oct 30 '17 at 16:51
  • There is no prepublish step on mine `package.json` and the other packages are fine, the only problem is on ng2-table package. :~ – Felipe Avelar Oct 30 '17 at 17:29