Skip to content

Commit

Permalink
Resolve packages relative to the package.json file instead of to the …
Browse files Browse the repository at this point in the history
…root

Fixes #47
  • Loading branch information
sindresorhus committed May 7, 2018
1 parent e6797ad commit 470335a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions index.js
Expand Up @@ -8,10 +8,13 @@ const resolvePkg = require('resolve-pkg');
module.exports = (grunt, options = {}) => {
const pattern = arrify(options.pattern || ['grunt-*', '@*/grunt-*']);
const scope = arrify(options.scope || ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']);
let config = options.config || pkgUp.sync();

let cwd = process.cwd();
let config = options.config || pkgUp.sync();
if (typeof config === 'string') {
config = require(path.resolve(config));
const configPath = path.resolve(config);
cwd = path.dirname(configPath);
config = require(configPath);
}

pattern.push('!grunt', '!grunt-cli');
Expand All @@ -24,7 +27,7 @@ module.exports = (grunt, options = {}) => {
for (const packageName of multimatch(names, pattern)) {
if (options.requireResolution === true) {
try {
grunt.loadTasks(resolvePkg(path.join(packageName, 'tasks')));
grunt.loadTasks(resolvePkg(path.join(packageName, 'tasks'), {cwd}));
} catch (err) {
grunt.log.error(`npm package \`${packageName}\` not found. Is it installed?`);
}
Expand Down

0 comments on commit 470335a

Please sign in to comment.