Best way for extensions to include external JS files



I want to bundle log4javascript with my gnome-shell extension. I
obviously don't want to copy & paste it into my extension.js, so I'm
wondering what the best way to bundle it with my extension is.

In my current development version, I'm just including it in
extensions/myextension/lib/ and adding that directory to $GJS_PATH.
That way, each of the (seven) files that use it can do so by:

    const log4javascript = imports.log4javascript;

But as far as I know control over $GJS_PATH is not available to normal
extensions, so this wouldn't work well for a released extension.

I could drop it directly into my extension directory, but then I think
each file that uses log4javascript would have to do something like:

    const log4javascript =
imports.ui.extensionSystem.extensions['shellshape gfxmonk net'].log4javascript;

Which is annoyingly verbose, and ties every file to my extension
namespace - even the ones that should be able to be generic and
portable, like log4javascript_gjs_appender.js

Is there a way to require a relative js file? Or perhaps to
programmatically insert the current path into gjs' load path? That way
my extension.js could add <path_to_here>/lib/ to the load path before
importing any other files.

So, any thoughts on how it can / should be done?

Cheers,
 - Tim.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]