espruino / EspruinoTools

JavaScript library of tools for Espruino - used for the Web IDE, CLI, etc.
Apache License 2.0
150 stars 89 forks source link

Improve localModules plugin #171

Closed mariusGundersen closed 11 months ago

mariusGundersen commented 11 months ago

This improves the localModules plugin by making the cwd and modules folder name settable through config. It also fixes modules loading so that it will look in parent folders as well. This makes it possible to load a module from another module, since it will find the current module folder it is in.

gfwilliams commented 11 months ago

This looks good however I'm a bit concerned about making MODULES_CWD a config entry... When you first add a config item, if it doesn't exist the value is set to defaultValue - so I'm thinking if we were to save our config, then we might end up in a position where you run the espruino tools from one directory, then CWD gets saved, and then the next time you try to run it from a new directory it's searching in the old one?

I think that's probably only an issue right now for the NW/electron based Web IDE (which we don't really support now anyway) but it might bite us in future.

Maybe make MODULES_CWD default value as "" and then add:

var cwd = Espruino.Config.MODULES_CWD;
if (cwd=="") cwd = process.cwd();

So then we can't get into that state?

mariusGundersen commented 11 months ago

That's a good point, I've fixed that

gfwilliams commented 11 months ago

Looks great - thanks!