[gjs/wip/package: 80/83] package: remove automagic imports
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/package: 80/83] package: remove automagic imports
- Date: Tue, 7 May 2013 22:02:06 +0000 (UTC)
commit c0907dcb8c252b42de30bcf4a8d565851e0f9650
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Tue May 7 23:44:28 2013 +0200
package: remove automagic imports
We want to use CommonJS style of imports, and automagic imports
are too risky when the namespace is crowded.
So make package.require() just a way to declare dependencies on
GI modules and their version.
modules/package.js | 83 +--------------------------------------------------
1 files changed, 2 insertions(+), 81 deletions(-)
---
diff --git a/modules/package.js b/modules/package.js
index bb64ac4..f1f7823 100644
--- a/modules/package.js
+++ b/modules/package.js
@@ -154,73 +154,6 @@ function start(params) {
return imports.main.main(ARGV);
}
-function _checkVersion(required, current) {
- if (required == '') {
- // No requirement
- return true;
- }
-
- // Major version must match, it's used for API
- // incompatible changes.
- // The rest just needs to be less or equal to
- // current. The code is generic, but gjs modules
- // should use only [major, minor]
- if (required[0] != current[0])
- return false;
-
- for (let i = 1; i < Math.min(current.length, required.length); i++) {
- if (required[i] > current[i])
- return false;
- if (required[i] < current[i])
- return true;
-
- // else they're equal, go on
- }
-
- return true;
-}
-
-function _isGjsModule(name, version) {
- // This is a subset of the JS modules we offer,
- // it includes only those that makes sense to use
- // standalone and in a general app.
- //
- // You will not find Gettext or Format here, use
- // the package functions instead. And Package, obviously,
- // because it's available as window.package.
- //
- // cairo is also a JS module, but the version checking
- // differs, see _isForeignModule()
- //
- // FIXME: Mainloop might be better as a GLib override?
- // FIXME: Signals should be an extension to Lang
- const RECOGNIZED_MODULE_NAMES = ['Lang',
- 'Mainloop',
- 'Signals',
- 'System',
- 'Params'];
- for (let i = 0; i < RECOGNIZED_MODULE_NAMES.length; i++) {
- let module = RECOGNIZED_MODULE_NAMES[i];
-
- if (module == name) {
- let actualModule = imports[module.toLowerCase()];
- let required = version.split('.');
-
- if (!_checkVersion(required, actualModule.$API_VERSION)) {
- printerr('Unsatisfied dependency: requested GJS module at version '
- + version + ', but only ' + (actualModule.$API_VERSION.join('.'))
- + ' is available');
- System.exit(1);
- } else {
- window[module] = actualModule;
- return true;
- }
- }
- }
-
- return false;
-}
-
/**
* require:
* @libs: the external dependencies to import
@@ -230,9 +163,6 @@ function _isGjsModule(name, version) {
* @libs must be an object whose keys are a typelib name,
* and values are the respective version. The empty string
* indicates any version.
- *
- * If dependencies are statisfied, require() will make
- * the module objects available as global names.
*/
function require(libs) {
_requires = libs;
@@ -240,21 +170,12 @@ function require(libs) {
for (let l in libs) {
let version = libs[l];
- if (_isGjsModule(l, version))
- continue;
-
if (version != '')
imports.gi.versions[l] = version;
try {
- if (name == 'cairo') {
- // Import the GI package to check the version,
- // but then load the JS one
- imports.gi.cairo;
- window.cairo = imports.cairo;
- } else {
- window[l] = imports.gi[l];
- }
+ // Import the package to check the version
+ imports.gi[l];
} catch(e) {
printerr('Unsatisfied dependency: ' + e.message);
System.exit(1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]