Skip to content
Permalink
Browse files
feat: Replace addProperty with ES6 getters (#96)
* Replace addProperty with ES6 getters in main module

This allows static code analysis tools to better understand the module
dependencies. For example, you can use VS Code's code navigation feature
to jump to the module definition.

There's a slight difference in implementation, as the getters installed
by addProperty would only call `require` on first invocation and then
replace themselves with the actual module. But since require does
caching itself, I don't see how that would make a big difference in
terms of runtime.

* Replace addProperty with ES6 getters in ConfigFile

* Remove private module util/addProperty
  • Loading branch information
raphinesse authored and erisu committed Nov 7, 2019
1 parent d53d266 commit 40cb6ceef90f4d04727094c429748044f1dc0b38
Showing 3 changed files with 33 additions and 68 deletions.
@@ -17,31 +17,28 @@
under the License.
*/

var addProperty = require('./src/util/addProperty');

module.exports = { };

addProperty(module, 'events', './src/events');
addProperty(module, 'superspawn', './src/superspawn');

addProperty(module, 'ActionStack', './src/ActionStack');
addProperty(module, 'CordovaError', './src/CordovaError/CordovaError');
addProperty(module, 'CordovaLogger', './src/CordovaLogger');
addProperty(module, 'CordovaCheck', './src/CordovaCheck');
addProperty(module, 'CordovaExternalToolErrorContext', './src/CordovaError/CordovaExternalToolErrorContext');
addProperty(module, 'PlatformJson', './src/PlatformJson');
addProperty(module, 'ConfigParser', './src/ConfigParser/ConfigParser');
addProperty(module, 'FileUpdater', './src/FileUpdater');

addProperty(module, 'PluginInfo', './src/PluginInfo/PluginInfo');
addProperty(module, 'PluginInfoProvider', './src/PluginInfo/PluginInfoProvider');

addProperty(module, 'PluginManager', './src/PluginManager');

addProperty(module, 'ConfigChanges', './src/ConfigChanges/ConfigChanges');
addProperty(module, 'ConfigKeeper', './src/ConfigChanges/ConfigKeeper');
addProperty(module, 'ConfigFile', './src/ConfigChanges/ConfigFile');
addProperty(module, 'mungeUtil', './src/ConfigChanges/munge-util');

addProperty(module, 'xmlHelpers', './src/util/xml-helpers');

module.exports = {
get events () { return require('./src/events'); },
get superspawn () { return require('./src/superspawn'); },

get ActionStack () { return require('./src/ActionStack'); },
get CordovaError () { return require('./src/CordovaError/CordovaError'); },
get CordovaLogger () { return require('./src/CordovaLogger'); },
get CordovaCheck () { return require('./src/CordovaCheck'); },
get CordovaExternalToolErrorContext () { return require('./src/CordovaError/CordovaExternalToolErrorContext'); },
get PlatformJson () { return require('./src/PlatformJson'); },
get ConfigParser () { return require('./src/ConfigParser/ConfigParser'); },
get FileUpdater () { return require('./src/FileUpdater'); },

get PluginInfo () { return require('./src/PluginInfo/PluginInfo'); },
get PluginInfoProvider () { return require('./src/PluginInfo/PluginInfoProvider'); },

get PluginManager () { return require('./src/PluginManager'); },

get ConfigChanges () { return require('./src/ConfigChanges/ConfigChanges'); },
get ConfigKeeper () { return require('./src/ConfigChanges/ConfigKeeper'); },
get ConfigFile () { return require('./src/ConfigChanges/ConfigFile'); },
get mungeUtil () { return require('./src/ConfigChanges/munge-util'); },

get xmlHelpers () { return require('./src/util/xml-helpers'); }
};
@@ -17,17 +17,16 @@
var fs = require('fs-extra');
var path = require('path');

var modules = {};
var addProperty = require('../util/addProperty');

// Use delay loading to ensure plist and other node modules to not get loaded
// on Android, Windows platforms
addProperty(module, 'bplist', 'bplist-parser', modules);
addProperty(module, 'et', 'elementtree', modules);
addProperty(module, 'glob', 'glob', modules);
addProperty(module, 'plist', 'plist', modules);
addProperty(module, 'plist_helpers', '../util/plist-helpers', modules);
addProperty(module, 'xml_helpers', '../util/xml-helpers', modules);
const modules = {
get bplist () { return require('bplist-parser'); },
get et () { return require('elementtree'); },
get glob () { return require('glob'); },
get plist () { return require('plist'); },
get plist_helpers () { return require('../util/plist-helpers'); },
get xml_helpers () { return require('../util/xml-helpers'); }
};

/******************************************************************************
* ConfigFile class

This file was deleted.

0 comments on commit 40cb6ce

Please sign in to comment.