What is the best practice for checking node dependencies and starting plugin services on demand?


Let's say I have a plugin to provide support for a certain javascript library and I want to implement:

1. Only start the plug-in function when a certain dependency is installed
2. Ability to respond to user installation/uninstallation of dependencies after project startup

I searched and found that PackageJsonUtil can provide relevant verification, but:
1. It should be slow to operate
2. How to detect when dependencies are dynamically installed and uninstalled?

what should I do? Are there any relevant extension points?

1 comment

Unfortunately, no such API at the moment. You can use the following approach: listen to package.json file add/remove/modify events  using `com.intellij.javascript.nodejs.packageJson.PackageJsonFileManager#CHANGES_TOPIC`. On change event, iterate over `com.intellij.javascript.nodejs.packageJson.PackageJsonFileManager#getValidPackageJsonFiles` and search for a needed dependency.


Please sign in to leave a comment.