How to easily verify correct npm dependencies installed?

后端 未结 6 961
北海茫月
北海茫月 2020-12-07 01:52

How can I know when to prompt user to run npm install if there are any unmet package.json dependencies?

I would like to do this, because if any re

6条回答
  •  一个人的身影
    2020-12-07 02:39

    Another solution

    function dependenciesNeedUpdating() {
      const childProcess = require('child_process');
      const result = JSON.parse(childProcess.execSync('npm install --dry-run --json').toString());
      return result.added.length > 0 || result.updated.length > 0 || result.removed > 0;
    }
    

    Call it like this

    if (dependenciesNeedUpdating()) {
      console.error('dependencies need updating. Please run `npm install`');
      process.exit(1);
    }
    

    If you want to install this as a dependency

提交回复
热议问题