Quick update v0.2.0, you can now do the following too:
const {require} = imports.require;
const module = require('./file.js');
as long as you have the `gjs-require` path defined.
Basically you can use it stand-alone, as gjs argument, or as gjs module:
pick any of those.
I wish this was possible
if anyone is interested, without going full NodeJS behavior/core thingy,
I've just summarized in a 100% GJS way the `require` utility that works
with regular paths without going full rpm resolution.
https://github.com/WebReflection/gjs-require
It's literally 50 LOC and makes GJS imports a joy to
Thanks for your help. I accidentally sent a private reply to your earlier
message because I forgot to use Reply-To-All etc, but I think it's
redundant now, thanks to other messages in this list.
On Fri, 9 Nov 2018 at 17:43, Andrea Giammarchi via javascript-list <
javascript-list@gnome.org> wrote:
Thanks for that, that's the sort of thing I was looking for.
On Fri, 9 Nov 2018 at 17:37, Philip Chimento via javascript-list <
javascript-list@gnome.org> wrote:
> For completeness I should mention that there's of course a built-in way to
> have multiple source files. To import "foo.js", use "con
Very nice program path resolution! I still have to get filenames from
Error stack when inside the imported modules, but for the entry point
your programInvocationName suggestion is definitely preferable, really
clean and doesn't rely on external `realpath` like what I had by now.
Thank you.
O
I've replied directly to him but maybe it's interesting for others too.
This is the TL;DR version of how I bootstrap CommonJS equivalent of
`__dirname` and `__filename` at the entry point level.
#!/usr/bin/env gjs
const { GLib, Gio } = imports.gi;
const { File } = Gio;
const PROGRAM_EXE = File.ne
For completeness I should mention that there's of course a built-in way to
have multiple source files. To import "foo.js", use "const Foo =
imports.foo;", and to import "subdir/bar.js" use "const Bar =
imports.subdir.bar;"
To set the search path for modules, use "imports.searchPath" which is an
ar
See also https://github.com/makepost/gunit for a test runner, and
https://github.com/sammydre/ts-for-gjs for autocomplete and type
checking. I actually think it's good not to replicate core Node modules
because we have GLib and other introspected GNOME libs with
language-independent APIs.
On
Now that's interesting.
About the email on Glib vs Node core, I was rather suggesting cgjs as a way
to import files, nothing else really, but its modules that simulate NodeJS
**are** already based on Glib.
On Fri, Nov 9, 2018 at 5:36 PM Edgar Merino wrote:
> You can use webpack, which will give
You can use webpack, which will give you ES6 imports and UMD, take a look
at how it was done in this project (you can skip the babel configuration in
the gulpfile if not needed).
https://github.com/emerinohdz/power-alt-tab
Thanks.
El vie., 9 de nov. de 2018 8:22 a. m., Andrea Giammarchi via
java
if you are familiar with CommonJS, I suggest you to use cgjs
https://github.com/cgjs/cgjs#cgjs--
it's not really a 1:1 nodejs replica when it comes to core modules, but at
least it doesn't require you to learn a module system that only GJS uses
and that will inevitably fade away as soon as ES2015
11 matches
Mail list logo