load-plugins icon indicating copy to clipboard operation
load-plugins copied to clipboard

throws error if no package.json exists

Open jaridmargolin opened this issue 9 years ago • 2 comments

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?

jaridmargolin avatar Jan 12 '17 15:01 jaridmargolin

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?

jonschlinkert avatar Jan 13 '17 03:01 jonschlinkert

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

doowb avatar Jan 13 '17 05:01 doowb