grunt-loadnpmtasks
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -25,3 +25,4 @@ /* | ||
// Validate the input | ||
if (!( | ||
if (! | ||
( | ||
grunt && | ||
@@ -31,3 +32,4 @@ typeof grunt.loadNpmTasks === 'function' && | ||
grunt.file && typeof grunt.file.findup === 'function' | ||
)) { | ||
) | ||
) { | ||
throw new TypeError('The `grunt` argument did not match expectations'); | ||
@@ -40,6 +42,32 @@ } | ||
this.loadNpmTasks = function(name) { | ||
var filepath = grunt.file.findup('node_modules/' + name, { | ||
cwd: path.resolve('node_modules', name), | ||
nocase: true | ||
}); | ||
var requiredFile, folderIndex, filepath, | ||
modulePartialPath = 'node_modules/' + name; | ||
try { | ||
requiredFile = require.resolve(name); | ||
} | ||
catch (e) { | ||
requiredFile = null; | ||
} | ||
if (requiredFile && | ||
requiredFile.length > modulePartialPath.length && | ||
( | ||
(folderIndex = requiredFile.indexOf(modulePartialPath)) && | ||
folderIndex !== -1 && | ||
( | ||
folderIndex === (requiredFile.length - modulePartialPath.length) || | ||
requiredFile.charAt(folderIndex + modulePartialPath.length) === '/' | ||
) | ||
) | ||
) { | ||
filepath = requiredFile.slice(0, folderIndex + modulePartialPath.length); | ||
} | ||
else { | ||
// TODO: Verify the initial `require.resolve` approach should already cover this whole scenario. If so, remove the `findup` dependency. | ||
filepath = grunt.file.findup(modulePartialPath, { | ||
cwd: path.resolve('node_modules', name), | ||
nocase: true | ||
}); | ||
} | ||
// If we found a magically hidden version of this Node module while ignoring "package.json" files | ||
@@ -49,4 +77,4 @@ if (filepath) { | ||
} | ||
// Otherwise let Grunt do its thing and hope for the best | ||
else { | ||
// Let Grunt do its thing and hope for the best (e.g. that there is a "gruntcollection" at play) | ||
_grunt_loadNpmTasks.call(grunt, name); | ||
@@ -53,0 +81,0 @@ } |
{ | ||
"name": "grunt-loadnpmtasks", | ||
"description": "A Node module (not a Grunt task itself) to help in loading NPM-based tasks without requiring a \"package.json\" file next to every Gruntfile. To be used as an alternative to `grunt.loadNpmTasks`/`grunt.task.loadNpmTasks`.", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/JamesMGreene/grunt-loadNpmTasks", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -7,3 +7,3 @@ # grunt-loadNpmTasks [![Build Status](https://secure.travis-ci.org/JamesMGreene/grunt-loadNpmTasks.png?branch=master)](http://travis-ci.org/JamesMGreene/grunt-loadNpmTasks) | ||
## Getting Started | ||
Install the module with: `npm install grunt-loadNpmTasks` | ||
Install the module with: `npm install grunt-loadnpmtasks` | ||
@@ -13,3 +13,3 @@ Within your Gruntfile (or Node.js code, if you are using Grunt programmatically), you can then do: | ||
```js | ||
var loader = require('grunt-loadNpmTasks')(grunt); // Where `grunt` is an instance of Grunt | ||
var loader = require('grunt-loadnpmtasks')(grunt); // Where `grunt` is an instance of Grunt | ||
loader.loadNpmTasks('grunt-contrib-jshint'); | ||
@@ -21,20 +21,12 @@ ``` | ||
```js | ||
require('grunt-loadNpmTasks').extend(grunt); // Where `grunt` is an instance of Grunt | ||
require('grunt-loadnpmtasks').extend(grunt); // Where `grunt` is an instance of Grunt | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.task.loadNpmTasks('grunt-contrib-uglify'); | ||
``` | ||
## Documentation | ||
_(Coming soon)_ | ||
## Examples | ||
_(Coming soon)_ | ||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
## Release History | ||
_(Nothing yet)_ | ||
## License | ||
Copyright (c) 2013 James M. Greene | ||
Licensed under the MIT license. |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
9345
163
30
1