Skip to content

Commit

Permalink
improve how to get globalNodeModules
Browse files Browse the repository at this point in the history
  • Loading branch information
lcxfs1991 committed Jul 28, 2017
1 parent d0010d6 commit 29cb715
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.2.12
- improve how to get globalNodeModules

## 1.2.11
- expose fs and chalk

Expand Down
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const os = require('os'),
fs = require('fs-extra'),
chalk = require('chalk'),
_ = require('lodash'),
spawn = require('cross-spawn');
// spawnSync = require('child_process').spawnSync;
spawn = require('cross-spawn'),
globalModules = require('global-modules');

function pluginUtils(pluginName) {

Expand All @@ -21,14 +21,24 @@ function pluginUtils(pluginName) {
// global home directory, usually for global config
this.globalHome = this._getGlobalHome();

this.globalNodeModules = process.env.NODE_PATH || this._getNodePath() || '';
this.globalNodeModules = this._getNodePath() || '';
}

/**
* get NODE_PATH
* @return {String} [NODE_PATH]
*/
pluginUtils.prototype._getNodePath = function() {
var env = process.env;

if (env.NODE_PATH) {
return env.NODE_PATH;
}

if (fs.existsSync(globalModules)) {
return globalModules;
}

// global node module path
var ps = spawn.sync('npm', ['root', '-g'], {}),
npmRoot = (ps && ps.stdout) ? ps.stdout.toString().replace(/[\n\t\r]/g,"") : "";
Expand Down Expand Up @@ -396,5 +406,6 @@ pluginUtils.prototype.log = function(str, color) {

pluginUtils.prototype.fs = fs;
pluginUtils.prototype.chalk = chalk;
pluginUtils.prototype._ = _;

module.exports = pluginUtils;
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "steamer-pluginutils",
"version": "1.2.11",
"version": "1.2.12",
"description": "steamer plugin utils",
"main": "index.js",
"scripts": {
Expand All @@ -26,6 +26,7 @@
"chalk": "^2.0.1",
"cross-spawn": "^5.1.0",
"fs-extra": "^4.0.0",
"global-modules": "^1.0.0",
"lodash": "^4.17.4"
},
"devDependencies": {
Expand All @@ -35,6 +36,6 @@
"istanbul": "^0.4.5",
"mocha": "^3.4.2",
"mocha-lcov-reporter": "^1.3.0",
"sinon": "^2.3.8"
"sinon": "^2.4.1"
}
}

0 comments on commit 29cb715

Please sign in to comment.