How can I read a flag passed in when installing a npm package

27 views Asked by At

I am looking for a way to support optional dependencies installation. I manage a npm package and want to provide users with the option to include supported "plugins" but not include them in the main package installation code.

Imagine my package name is my-package, when others install it they run pnpm install my-package. I want to provide an option for them to run pnpm install my-package --plugin my-plugin and then based on that provided plugin install my-plugin dependency.

Obviously I will handle the check of whether the dependency has been installed or not in my code base.

I was looking at

  • optionalDependencies but this is not the functionality I am looking for.
  • preinstall script but since I am using pnpm this script runs after the dependencies have been installed. Also it does not seem to run when installing a package but only when installing the dependencies in a package.
  • pnpm hooks.readPackage same as preinstall
0

There are 0 answers