So the new importModule only works when importing code files that are set up with the module.export stuff? That’s a great step for reusing some functions in several scripts. Will there be a way to import arbitrary code files like external libraries?
Yes, it uses module.exports but please note that it is not compatible with require() from Node. Can you give an example of what kind of external libraries you want to import?
(I now chose a random implementation on the internet which I import using this new importModule function, but I’d rather not have that source in Scriptable at all)
I’m not completely sure what you mean what you say you’d rather not store it “in Scriptable at all”. You’d always need to store the module somewhere on the disk. If you don’t like the module cluttering your list of scripts, and I totally understand that, you can create a directory in Scriptables documents directory, i.e. /iCloud/Scriptable, and load the script from there.
For example, I have the folder /iCloud/Scriptable/lib and I store all my reusable code in there. So if I have a module with filename md5.js in there, I can load it with loadModule("lib/md5").
I’ve just tried and it seems that moment.js is compatible with Scriptables importModule(path). Don’t generally expect modules that weren’t designed for Scriptable to be compatible with importModule. It is mostly meant for reusing your own code.
To get moment.js working, you need to store this file somewhere on your disk and then load it like you normally would, e.g. let moment = loadModule("lib/moment").
lib is included by default. I haven’t tested this but if you want it excluded, you may be able to add it to your .gitignore. I’m not sure if file synchronisation respects .gitignore.
That’s Kodex. It’s an excellent minimalistic code editor. I’ll also take the chance to recommend Textastic which packs a bunch more features but also an extra level of complexity.