throws error if no package.json exists
TypeError: Cannot read property 'dependencies' of null
I think rather than throwing an error, the library could either:
- Fail silently -- return an empty object?
- Try to resolve by reading contents of
node_modulesdirectory.
Thoughts?
Hmm, perhaps we should make this an option, so that it's configurable based on usage? I can see both of your proposed solutions being useful depending on use case, but also still being able to throw an error when necessary is useful in some cases.
@TrySound or @doowb, any opinion on this?
I think we should do #1 since if the package.json is found but there are no modules listed, then it'll return an empty array. I think it should be the same if no package.json is found. This would be implemented in resolve-dep. You can achieve the same effect by passing {config: {}} as options when calling load-plugins.
var plugin = require('load-plugins')('gulp-*', {config: {}});
For #2, you should be able to add ./node_modules to the beginning of your pattern to search through all the folders in node_modules.
// load any `ansi-` modules
var ansi = require('load-plugins')('./node_modules/ansi-*');