siddharthkp / auto-install

Install dependencies as you code ⚡️
MIT License
1.2k stars 71 forks source link

A couple cases which uninstall needed repos #79

Open zeg-io opened 7 years ago

zeg-io commented 7 years ago

When you use express-generator to create boilerplate auto-install deletes some of the modules: debug and hbs Unfortunately hbs isn't required anywhere else, I guess the view engine makes assumptions as to the module's existence, so not sure what can be done about that.

It appears the reason that bin/www doesn't get picked up is because it doesn't end in .js

bin/www

let debug = require('debug')('template-emailer:server')

app.js

app.set('view engine', 'hbs')
siddharthkp commented 7 years ago

Ouch! Any ideas on how to fix it?

zeg-io commented 7 years ago

Well, the solutions that I came up with all involve exceptions to the rule, so I don't like them but I don't know that there's a way around it right now.

Option 1:

Have the code also check for bin/www as an exception to the .js only. Have the code interpret app.set('view engine', 'xxxxxx') as a require again, I don't like writing exceptions into my code usually so it feels icky

Option 2:

Same as above, but you have it only do that if express is also loaded, so that the exception code is only triggered if it needs to. This is more work and prevents the code from being executed otherwise. However, I'm not sure that that actually buys anyone anything other than additional work

Normally I wouldn't advocate exceptions...except that express is so prevalent, and this tool requires developers to jump through unnecessary hoops to get their code back to a working state.

Personally my feeling is one of the two options is taken given how prevalent express is and how that fact limits your audience if you don't.

siddharthkp commented 7 years ago

What if I try to pass every file through the js parser, if it can't make sense of it, I just skip it.

Would slow down the first parse quite a bit, but while watching for changes it would be fast enough

zeg-io commented 7 years ago

That seems a reasonable approach for the first case anyway. That, or maybe reduce that approach and pass in files without extensions and .JS files to keep a more narrow focus