jonschlinkert / load-plugins

Thin wrapper around resolve-dep for loading plugins from node_modules or local directories. Like load-gulp-plugins, match dep, etc, but works for gulp, grunt, assemble, verb or anything other task runner or build system that uses plugins.
https://github.com/jonschlinkert
MIT License
22 stars 1 forks source link

throws error if no package.json exists #14

Open jaridmargolin opened 7 years ago

jaridmargolin commented 7 years ago
TypeError: Cannot read property 'dependencies' of null

I think rather than throwing an error, the library could either:

  1. Fail silently -- return an empty object?
  2. Try to resolve by reading contents of node_modules directory.

Thoughts?

jonschlinkert commented 7 years ago

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?

doowb commented 7 years ago

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-*');