Skip to content

Commit

Permalink
fix: use yarn global dir to find global modules (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
gera2ld authored and SBoudrias committed May 13, 2018
1 parent e650886 commit 8b620aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const os = require('os');
const _ = require('lodash');
const globby = require('globby');
const debug = require('debug')('yeoman:environment');
const spawn = require('cross-spawn');

const win32 = process.platform === 'win32';
const nvm = process.env.NVM_HOME;
Expand Down Expand Up @@ -139,13 +140,15 @@ resolver.getNpmPaths = function () {
// ~/.config/yarn/link/generator-i-made
//
// win32:
// %LOCALAPPDATA%\Yarn\config\global\node_modules\yo\
// %LOCALAPPDATA%\Yarn\config\link\generator-i-made
// %LOCALAPPDATA%\Yarn\Data\global\node_modules\yo\
// %LOCALAPPDATA%\Yarn\Data\link\generator-i-made
//
if (win32) {
paths.push(path.join(process.env.LOCALAPPDATA, 'Yarn/config/link/'));
} else {
paths.push(path.join(os.homedir(), '.config/yarn/link/'));
// Yarn has a command to get the directory of global modules:
// $ yarn global dir
// > '.../global\n'
const testYarn = spawn.sync('yarn', ['global', 'dir'], { encoding: 'utf8' });
if (!testYarn.error) {
paths.push(path.resolve(testYarn.stdout.strip(), '../link/');
}

// Adds support for generator resolving when yeoman-generator has been linked
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"dependencies": {
"chalk": "^2.1.0",
"cross-spawn": "^6.0.5",
"debug": "^3.1.0",
"diff": "^3.3.1",
"escape-string-regexp": "^1.0.2",
Expand Down

0 comments on commit 8b620aa

Please sign in to comment.