Skip to content

esm/gi: Improve check for version conflicts

Florian Müllner requested to merge fmuellner/gjs:better-version-check into master

The following pattern currently fails:

let Soup;
try {
    Soup = gi.require('Soup', '3.0');
} catch (e) {
    Soup = gi.require('Soup', '2.4');
}

That is because require() checks the version argument against recorded versions from previous calls (regardless of whether the namespace was loaded successfully or not).

Address this by adding a new version property to namespaces that reflects the actually loaded version.

The update the gi.require() check to make use of it.

This doesn't only fix the above use case, but is also more reliable in that it works when the version argument is omitted:

const Gtk4 = gi.require('Gtk');
const Gtk3 = gi.require('Gtk', '3.0');

now throws an exception, while before both Gtk4 and Gtk3 were resolved to the Gtk namespace (version 4.0).

Edited by Philip Chimento

Merge request reports