Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throws error if no package.json exists #14

Open
jaridmargolin opened this issue Jan 12, 2017 · 2 comments
Open

throws error if no package.json exists #14

jaridmargolin opened this issue Jan 12, 2017 · 2 comments

Comments

@jaridmargolin
Copy link
Collaborator

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
Copy link
Owner

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
Copy link
Collaborator

doowb commented Jan 13, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants