Skip to content

ESM: Enable static imports. (Part 3)

Evan Welsh requested to merge esm/static-imports into master

Depends on !453 (merged) > !456 (merged).

This PR enables static ESM imports alongside our existing module system.

Local Imports

// a.js
import b from './b.js'

log(b);
// b.js
log('b.js!');

export default 'a.js!';

gjs -m a.js will work as expected.

ESM Libraries

ESM libraries are loaded from resource:///org/gnome/gjs/modules/esm/ and have access to native module with import.meta.require('native')

gi

import gi from 'gi'

log(gi.require('Gtk', '3.0') === imports.gi.Gtk)

GI may have a more expansive API in the future, but for now it contains only the essentials.

system

import system from 'system'

log(system === imports.system)

Named exports will follow in a later PR.

Edited by Philip Chimento

Merge request reports