You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2015/10/31 01:08:37 UTC
[2/3] cordova-lib git commit: CB-9834 Introduce compat map for hook
requires
CB-9834 Introduce compat map for hook requires
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/38809af4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/38809af4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/38809af4
Branch: refs/heads/5.4.x
Commit: 38809af4f5ac6982b0b16c1a1ce89741197ea160
Parents: 40ecced
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Tue Oct 27 15:20:10 2015 +0300
Committer: Steve Gill <st...@gmail.com>
Committed: Fri Oct 30 16:43:21 2015 -0700
----------------------------------------------------------------------
cordova-lib/src/hooks/Context.js | 35 ++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/38809af4/cordova-lib/src/hooks/Context.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/hooks/Context.js b/cordova-lib/src/hooks/Context.js
index a0b6cfd..ed7f8a7 100644
--- a/cordova-lib/src/hooks/Context.js
+++ b/cordova-lib/src/hooks/Context.js
@@ -17,6 +17,9 @@
under the License.
*/
+var path = require('path');
+var events = require('cordova-common').events;
+
/**
* Creates hook script context
* @constructor
@@ -39,13 +42,39 @@ function Context(hook, opts) {
this.cordova = require('../cordova/cordova');
}
+// As per CB-9834 we need to maintain backward compatibility and provide a compat layer
+// for plugins that still require modules, factored to cordova-common.
+var compatMap = {
+ '../configparser/ConfigParser': function () {
+ return require('cordova-common').ConfigParser;
+ },
+ '../util/xml-helpers': function () {
+ return require('cordova-common').xmlHelpers;
+ }
+};
/**
* Returns a required module
- * @param {String} path Module path
+ * @param {String} modulePath Module path
* @returns {Object} */
-Context.prototype.requireCordovaModule = function (path) {
- return require(path);
+Context.prototype.requireCordovaModule = function (modulePath) {
+ // There is a very common mistake, when hook requires some cordova functionality
+ // using 'cordova-lib/...' path.
+ // This path will be resolved only when running cordova from 'normal' installation
+ // (without symlinked modules). If cordova-lib linked to cordova-cli this path is
+ // never resolved, so hook fails with 'Error: Cannot find module 'cordova-lib''
+ var resolvedPath = path.resolve(__dirname, modulePath.replace(/^cordova-lib/, '../../../cordova-lib'));
+ var relativePath = path.relative(__dirname, resolvedPath).replace(/\\/g, '/');
+ events.emit('verbose', 'Resolving module name for ' + modulePath + ' => ' + relativePath);
+
+ var compatRequire = compatMap[relativePath];
+ if (compatRequire) {
+ events.emit('warn', 'The module "' + path.basename(relativePath) + '" has been factored ' +
+ 'into "cordova-common". Consider update your plugin hooks.');
+ return compatRequire();
+ }
+
+ return require(relativePath);
};
module.exports = Context;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org