'Use different versions of the same package in dev or prod?

(not a native speaker, sorry if things don't seems clear)

We are devs for a clients and we work with others devs from another company. The other devs make us a package that we sometimes change this in it, then submit the changes in a pull request.

So we end up having a local version of the package and the official version. And so we want to use the local version in dev (where we might make little changes in the package to match what the client want), and the official in prod (where our changes and other devs changes are merges).

I will show an example that don't work but that can help understand the idea:

[...]
"dependencies"{
     [...]
     "package":"prod-package"
},
"devDependencies"{
     [...]
     "package":"local/version/of/package"
},

and so, we should have this:

npm build # use local/version/of/package
npm build --prod # use prod-package

I'm not really good with npm (in fact, beside npm install and npm remove, I basically know nothing), so I might ask something obvious, but I can't find the answer anywere.



Solution 1:[1]

Have you tried using npm-link to link to the local version of the package you are consuming? That way, you could still commit your changes to the package back to the vendor.

https://docs.npmjs.com/cli/v8/commands/npm-link

You would essentially run npm link in the checked-out-from-VCS (git?) package folder, then you switch back to your project where you are consuming that package and run npm link {name-of-npm-package}

This would allow you to develop on that version locally, make your changes (and they will show up on VCS for easy pull request management).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zedd45