Re: gjs / seed status



On Tue, May 26, 2015 at 6:53 AM, Satyajit Sahoo <satyajit happy gmail com> wrote:
[...]
But that's not the main issue. The main issue comes when you try to use modules.  The module search paths are always relative to the path of the root file, and not the file which is importing the module. For example, say I've this structure,

-- app.js
--lib/
  --module1.js
  --module2.js

And say, you try to do this in app.js,

// app.js

imports.searchPath.unshift(".");

const Module1 = imports.lib.module1

Then the following in module1.js

// module1.js

imports.searchPath.unshift(".");

const Module2 = imports.module2

But this won't work, even if both module1.js and module2.js are in the same directory. I'll have to do,

imports.searchPath.unshift(".");

const Module1 = imports.lib.module1

This is very frustrating, especially when you are trying to build a set of libraries to use.

Unfortunately JS libraries are explicitly not supported, according to what has been said earlier on this mailing list. [1]

Actually I believe the search path is relative to the current directory, not the location of the module file. So I think probably your best bet if you want to use your helper library in an app is to do this:

- Bundle the helper library with the app and install it into $(pkgdatadir)
- Add a launch script for the app that calls "gjs -I @pkgdatadir@ $@"
- In your Makefile.am replace @pkgdatadir@ with the value of $(pkgdatadir) (see [2] for an example)

Not a very good story, but there it is.

[1] https://mail.gnome.org/archives/_javascript_-list/2013-August/msg00001.html
[2] https://github.com/ptomato/jasmine-gjs/blob/master/Makefile.am#L8

--
Philip


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