Skip to content

Commit

Permalink
cleanup #44
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Dec 19, 2015
1 parent 0c4c0e7 commit 06afe94
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
14 changes: 4 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var path = require('path');
var pkgUp = require('pkg-up');
var multimatch = require('multimatch');
var arrify = require('arrify');
var resolveCwd = require('resolve-cwd');
var resolvePkg = require('resolve-pkg');

module.exports = function (grunt, opts) {
opts = opts || {};
Expand All @@ -25,15 +25,9 @@ module.exports = function (grunt, opts) {

multimatch(names, pattern).forEach(function (pkgName) {
if (opts.requireResolution === true) {
// This resolution is complicated because most grunt plugins are written
// in violation of package.json conventions. And example is not having a
// `main` field defined, which will cause `require` or `resolve`
// to fail. So better to lookup a guaranteed file, such as package.json.
var pkg = resolveCwd(path.join(pkgName, 'package.json'));
var root = path.dirname(pkg);
pkgName = path.join(root, 'tasks');
grunt.loadTasks(resolvePkg(path.join(pkgName, 'tasks')));
} else {
grunt.loadNpmTasks(pkgName);
}

grunt.loadTasks(pkgName);
});
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
"arrify": "^1.0.0",
"multimatch": "^2.0.0",
"pkg-up": "^1.0.0",
"resolve-cwd": "^1.0.0"
"resolve-pkg": "^0.1.0"
},
"devDependencies": {
"grunt": "^0.4.2",
"grunt-cli": "^0.1.13",
"grunt-svgmin": "^2.0.0",
"grunt-svgmin": "^3.1.0",
"xo": "*"
},
"engines": {
Expand Down
17 changes: 6 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $ npm install --save-dev load-grunt-tasks

```js
// Gruntfile.js
module.exports = function (grunt) {
module.exports = grunt => {
// load all grunt tasks matching the ['grunt-*', '@*/grunt-*'] patterns
require('load-grunt-tasks')(grunt);

Expand Down Expand Up @@ -101,20 +101,14 @@ require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
require('load-grunt-tasks')(grunt, {scope: ['devDependencies', 'dependencies']});
```

### Load from all `node_modules` in the current hierarchy

```js
require('load-grunt-tasks')(grunt, {requireResolution: true});
```

### All options in use

```js
require('load-grunt-tasks')(grunt, {
pattern: 'grunt-contrib-*',
config: '../package.json',
scope: 'devDependencies',
requireResolution: false
requireResolution: true
});
```

Expand All @@ -139,11 +133,12 @@ Values: `'dependencies'`, `'devDependencies'`, `'peerDependencies'`, `'optionalD

### requireResolution

Traverse the file hierarchy, just like node does when requiring modules.

Type: `boolean`
Type: `boolean`
Default: `false`

Traverse up the file hierarchy looking for dependencies like `require()`, rather than the default grunt-like behavior of loading tasks only in the immediate `node_modules` directory.


## License

MIT © [Sindre Sorhus](http://sindresorhus.com)

0 comments on commit 06afe94

Please sign in to comment.