Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1F7EF200CB7 for ; Fri, 16 Jun 2017 02:19:57 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1E0CB160BED; Fri, 16 Jun 2017 00:19:57 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3D2CD160BDF for ; Fri, 16 Jun 2017 02:19:56 +0200 (CEST) Received: (qmail 81464 invoked by uid 500); 16 Jun 2017 00:19:55 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 81455 invoked by uid 99); 16 Jun 2017 00:19:55 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Jun 2017 00:19:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 56715DFAF5; Fri, 16 Jun 2017 00:19:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: steven@apache.org To: commits@cordova.apache.org Date: Fri, 16 Jun 2017 00:19:55 -0000 Message-Id: <62e1af370e154cdb8e1011a767653881@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/16] cordova-lib git commit: Revert lazy loading of modules. archived-at: Fri, 16 Jun 2017 00:19:57 -0000 Repository: cordova-lib Updated Branches: refs/heads/master e69b9e4ef -> 843f7cc34 Revert lazy loading of modules. Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/74c113df Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/74c113df Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/74c113df Branch: refs/heads/master Commit: 74c113df6e46060edef3385a99fe5a383321ccea Parents: e69b9e4 Author: filmaj Authored: Wed Jun 7 14:43:29 2017 -0500 Committer: filmaj Committed: Mon Jun 12 15:24:36 2017 -0500 ---------------------------------------------------------------------- cordova-lib.js | 32 ++++++++------------------------ src/cordova/cordova.js | 1 - src/cordova/util.js | 21 +++++++-------------- src/plugman/install.js | 4 ++-- src/plugman/plugman.js | 19 +++++-------------- 5 files changed, 22 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/74c113df/cordova-lib.js ---------------------------------------------------------------------- diff --git a/cordova-lib.js b/cordova-lib.js index 1252412..7a51ed7 100644 --- a/cordova-lib.js +++ b/cordova-lib.js @@ -17,21 +17,7 @@ under the License. */ -// For now expose plugman and cordova just as they were in the old repos - - -function addProperty(obj, property, modulePath) { - // Add properties as getter to delay load the modules on first invocation - Object.defineProperty(obj, property, { - configurable: true, - get: function () { - var module = require(modulePath); - // We do not need the getter any more - obj[property] = module; - return module; - } - }); -} +var common = require('cordova-common'); exports = module.exports = { set binname(name) { @@ -40,13 +26,11 @@ exports = module.exports = { get binname() { return this.cordova.binname; }, - get events() { return require('cordova-common').events }, - get configparser() { return require('cordova-common').ConfigParser }, - get PluginInfo() { return require('cordova-common').PluginInfo }, - get CordovaError() { return require('cordova-common').CordovaError } - + events: common.events, + configparser: common.ConfigParser, + PluginInfo: common.PluginInfo, + CordovaError: common.CordovaError, + plugman: require('./src/plugman/plugman'), + cordova: require('./src/cordova/cordova'), + cordova_platforms: require('./src/platforms/platforms') }; - -addProperty(module.exports, 'plugman', './src/plugman/plugman'); -addProperty(module.exports, 'cordova', './src/cordova/cordova'); -addProperty(module.exports, 'cordova_platforms', './src/platforms/platforms'); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/74c113df/src/cordova/cordova.js ---------------------------------------------------------------------- diff --git a/src/cordova/cordova.js b/src/cordova/cordova.js index 99c8078..f17cf69 100644 --- a/src/cordova/cordova.js +++ b/src/cordova/cordova.js @@ -55,7 +55,6 @@ exports.findProjectRoot = function(opt_startDir) { var addModuleProperty = cordova_util.addModuleProperty; addModuleProperty(module, 'prepare', './prepare', true); addModuleProperty(module, 'build', './build', true); -addModuleProperty(module, 'help', './help'); addModuleProperty(module, 'config', './config'); addModuleProperty(module, 'create', './create', true); addModuleProperty(module, 'emulate', './emulate', true); http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/74c113df/src/cordova/util.js ---------------------------------------------------------------------- diff --git a/src/cordova/util.js b/src/cordova/util.js index 987cb4e..8b62470 100644 --- a/src/cordova/util.js +++ b/src/cordova/util.js @@ -62,11 +62,11 @@ exports.cdProjectRoot = cdProjectRoot; exports.deleteSvnFolders = deleteSvnFolders; exports.listPlatforms = listPlatforms; exports.findPlugins = findPlugins; +exports.addModuleProperty = addModuleProperty; exports.appDir = appDir; exports.projectWww = projectWww; exports.projectConfig = projectConfig; exports.preProcessOptions = preProcessOptions; -exports.addModuleProperty = addModuleProperty; exports.getOrigWorkingDirectory = getOrigWorkingDirectory; exports._resetOrigCwd = _resetOrigCwd; exports.fixRelativePath = fixRelativePath; @@ -378,32 +378,25 @@ function isSymbolicLink(dir) { // opt_wrap is a boolean: True means that a callback-based wrapper for the promise-based function // should be created. function addModuleProperty(module, symbol, modulePath, opt_wrap, opt_obj) { - var val = null; + var modewl = require(modulePath); if (opt_wrap) { module.exports[symbol] = function() { - val = val || module.require(modulePath); if (arguments.length && typeof arguments[arguments.length - 1] === 'function') { // If args exist and the last one is a function, it's the callback. var args = Array.prototype.slice.call(arguments); var cb = args.pop(); - val.apply(module.exports, args).done(function(result) { cb(undefined, result); }, cb); + modewl.apply(module.exports, args).done(function(result) { cb(undefined, result); }, cb); } else { - val.apply(module.exports, arguments).done(null, function(err) { throw err; }); + modewl.apply(module.exports, arguments).done(null, function(err) { throw err; }); } }; } else { - Object.defineProperty(opt_obj || module.exports, symbol, { - get : function() { val = val || module.require(modulePath); return val; }, - set : function(v) { val = v; } - }); + (opt_obj || module.exports)[symbol] = modewl; } // Add the module.raw.foo as well. - if(module.exports.raw) { - Object.defineProperty(module.exports.raw, symbol, { - get : function() { val = val || module.require(modulePath); return val; }, - set : function(v) { val = v; } - }); + if (module.exports.raw) { + module.exports.raw[symbol] = modewl; } } http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/74c113df/src/plugman/install.js ---------------------------------------------------------------------- diff --git a/src/plugman/install.js b/src/plugman/install.js index 69b9aa3..fbc40aa 100644 --- a/src/plugman/install.js +++ b/src/plugman/install.js @@ -33,7 +33,6 @@ var path = require('path'), underscore = require('underscore'), shell = require('shelljs'), events = require('cordova-common').events, - plugman = require('./plugman'), HooksRunner = require('../hooks/HooksRunner'), isWindows = (os.platform().substr(0,3) === 'win'), pluginSpec = require('../cordova/plugin_spec_parser'), @@ -98,7 +97,8 @@ function possiblyFetch(id, plugins_dir, options) { var opts = underscore.extend({}, options, { client: 'plugman' }); - return plugman.raw.fetch(id, plugins_dir, opts); + // TODO: without runtime require below, we have a circular dependency. + return require('./plugman').raw.fetch(id, plugins_dir, opts); } function checkEngines(engines) { http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/74c113df/src/plugman/plugman.js ---------------------------------------------------------------------- diff --git a/src/plugman/plugman.js b/src/plugman/plugman.js index 3a97824..63102a4 100644 --- a/src/plugman/plugman.js +++ b/src/plugman/plugman.js @@ -23,35 +23,26 @@ var events = require('cordova-common').events; var Q = require('q'); function addProperty(o, symbol, modulePath, doWrap) { - var val = null; + var modewl = require(modulePath); if (doWrap) { o[symbol] = function() { - val = val || require(modulePath); if (arguments.length && typeof arguments[arguments.length - 1] === 'function') { // If args exist and the last one is a function, it's the callback. var args = Array.prototype.slice.call(arguments); var cb = args.pop(); - val.apply(o, args).done(function(result) {cb(undefined, result);}, cb); + modewl.apply(o, args).done(function(result) {cb(undefined, result);}, cb); } else { - val.apply(o, arguments).done(null, function(err){ throw err; }); + modewl.apply(o, arguments).done(null, function(err){ throw err; }); } }; } else { // The top-level plugman.foo - Object.defineProperty(o, symbol, { - configurable: true, - get : function() { val = val || require(modulePath); return val; }, - set : function(v) { val = v; } - }); + o[symbol] = modewl; } // The plugman.raw.foo - Object.defineProperty(o.raw, symbol, { - configurable: true, - get : function() { val = val || require(modulePath); return val; }, - set : function(v) { val = v; } - }); + o.raw[symbol] = modewl; } var plugman = { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org