I have an NPM package (package A) that compiles itself with the last stable version of itself. It does this through an intermediary Grunt task (package B) that itself depends on package A. Thus, the dependency chain is:
Package A -> Package B (as devDependency
) -> Package A (as dependency
)
However, when Package A is installed through npm install
, NPM won't install Package A as a dependency of Package B, presumedly by design - I assume it's trying to prevent circular dependencies, even though because Package B is only a devDependency
, it won't be installed on the child Package A anyways.
What's the least-hacky/recommended way of installing the child Package A? My first solution was to just add an postinstall
script that simply ran cd node_modules/package-B && npm install package-A
, but this breaks because the CWD of postinstall
isn't always the package's root directory.
What about running making an js file for such a task?
var spawn = require("child_process").spawn;
spawn("npm", [ "install", "package-A" ], {
cwd: process.cwd() + "/node_modules/package-B/",
env: process.env
});
I'm not sure whether this will work, but maybe it inspire you to do more things with it ;)
Figured out a nice automated way of doing this:
cyclic.js
Add the following to your package.json
files:
"scripts": {
"preinstall": "node ./cyclic.js"
}
With this solution, when you run npm install
it will automatically force install the cyclic depencies for you without error.
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