Is it possible in package.json to include the same dependency twice, but with different versions:
"dependencies": {
"projectX-v1.0.0": "ssh://[email protected]/xxx/projectX.git#v1.0.0",
"projectX-v1.0.1": "ssh://[email protected]/xxx/projectX.git#v1.0.1"
}
The best I could come up with is to change the name (see above) of the included projectX
to projectX-v1.0.0
and projectX-v1.0.1
in its releases/tags and package.json in order to end up with two separate folders in node_modules
folder.
The reason why I need this is the following omni-repository structure:
/omni/
/omni/frontend
/omni/frontend/projectA
/omni/frontend/projectB
...
/omni/package.json
projectA
would use projectX-v1.0.0
and projectB
would use projectX-v1.0.1
(bundling with browserify)
Thanks!
With npm or yarn, you can install a package under a custom alias. This enables you to install multiple versions of a package in the same project.
The good news is that you can have it done directly via NPM! What can be done in this case is an idea called "package alias". So you can have multiple versions of the same package running in your app and you can work on the upgrades mitigating possible issues.
In order to start, let's first create a folder called multiple-package-versions-in-project and, inside of this folder, initialize a node project by running npm init -y . After that, we can install the old and latest versions of the package.
Running npm install apart from the first time installs only the missing packages and those that need update. Save this answer. Show activity on this post. Running npm install after the first time only installs missing packages or updates existing ones.
"bundledDependencies" are exactly what their name implies. Dependencies that should be inside your project. So the functionality is basically the same as normal dependencies. They will also be packed when running npm pack .
Not with vanilla npm, although the community has talked about it extensively. That said, Scott Hardy's npm-install-version package will let you install node modules to versioned, or custom, directories.
NPM has said that they don't plan to implement this feature, but I've found a way around it. I forked the package repository on github and renamed it. Then I installed this new repo as a dependency in my project using:
npm i -S git+ssh://[email protected]:<org>/<renamed-project>.git
Now, I can upgrade the actual npm package and change all of the references to it in my project to the new, renamed-project git repo dependency. It's a lot of extra work, but I found it easier than switching to yarn or another package manager with package aliasing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With