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/07/22 02:02:03 UTC
cordova-lib git commit: CB-9036 fixed browserify cordova requires
Repository: cordova-lib
Updated Branches:
refs/heads/master 0b0dee5e4 -> 02ae8a20c
CB-9036 fixed browserify cordova 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/02ae8a20
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/02ae8a20
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/02ae8a20
Branch: refs/heads/master
Commit: 02ae8a20c1868283fe9086b7e32f41f8b153cdbb
Parents: 0b0dee5
Author: Steve Gill <st...@gmail.com>
Authored: Tue Jul 21 16:49:55 2015 -0700
Committer: Steve Gill <st...@gmail.com>
Committed: Tue Jul 21 17:02:00 2015 -0700
----------------------------------------------------------------------
cordova-lib/src/plugman/prepare-browserify.js | 15 ++++++----
.../src/plugman/util/prepare-namespace.js | 29 +++++++++++---------
2 files changed, 25 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/02ae8a20/cordova-lib/src/plugman/prepare-browserify.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/prepare-browserify.js b/cordova-lib/src/plugman/prepare-browserify.js
index 10256c0..df3ec1e 100644
--- a/cordova-lib/src/plugman/prepare-browserify.js
+++ b/cordova-lib/src/plugman/prepare-browserify.js
@@ -214,16 +214,16 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir, www_
// Handles clobbers and merges
// Writes needed requires to cordovaRequires Array
// which gets written to cordova_requires.js which
- // gets added to the browserify build
+ // gets added to the browserify bundle.
var namespace;
module.clobbers.forEach(function(child) {
- namespace = prepareNamespace(child.target, 'c');
- if(cordovaRequires.indexOf(namespace) !== -1) {
+ namespace = prepareNamespace(child.target, true, scriptPath);
+ if(cordovaRequires.indexOf(namespace) === -1) {
cordovaRequires.push(namespace);
}
});
module.merges.forEach(function(child) {
- namespace = prepareNamespace(child.target, 'm');
+ namespace = prepareNamespace(child.target, false, scriptPath);
if(cordovaRequires.indexOf(namespace) === -1) {
cordovaRequires.push(namespace);
}
@@ -239,17 +239,20 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir, www_
events.emit('verbose', 'Writing out cordova_plugins.js...');
fs.writeFileSync(path.join(wwwDir, 'cordova_plugins.js'), cordova_plugins, 'utf8');
+ //Write out cordova_requires.js.
if(cordovaRequires.length > 0) {
var cordovaRequiresString = cordovaRequires.join('\n');
events.emit('verbose', 'Writing out cordova_requires.js...');
fs.writeFileSync(path.join(wwwDir, 'cordova_requires.js'), cordovaRequiresString, 'utf8');
- //add it to browserify
+ //add it to the browserify bundle
libraryRelease.add(path.join(wwwDir, 'cordova_requires.js'));
}
-
+
+ //run transforms on plugin files
libraryRelease.transform(requireTr.transform);
scripts.forEach(function(script) {
+ //add every plugin javascript file to browserify bundle
libraryRelease.add(script);
});
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/02ae8a20/cordova-lib/src/plugman/util/prepare-namespace.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/util/prepare-namespace.js b/cordova-lib/src/plugman/util/prepare-namespace.js
index fb3918d..27dfeeb 100644
--- a/cordova-lib/src/plugman/util/prepare-namespace.js
+++ b/cordova-lib/src/plugman/util/prepare-namespace.js
@@ -20,12 +20,17 @@
var util = require('util');
-// FIXME this is extremely guettho
+/**
+ * Used to handle plugin merges and clobbers
+ * @param {string} target - target namespace to clobber or merge with
+ * @param {boolean} doClobber - Determines if clobbers or merges. Clobbers if true.
+ * @param {string} scriptPath - Path to the javascript file
+ */
module.exports = prepare_namespace;
-function prepare_namespace(target, method) {
+
+function prepare_namespace(target, doClobber, scriptPath) {
var old = target;
target = target.replace(/^window(\.)?/, '');
-
var lastDot = target.lastIndexOf('.');
var lastName = target.substr(lastDot + 1);
var props = target.split('.');
@@ -37,24 +42,22 @@ function prepare_namespace(target, method) {
code += util.format('window.%s = window.%s || {};\n', sub, sub);
}
}
-
props.unshift('window');
var object = props.slice(0, props.length - 1).join('.');
- // code = '\n';
- if(method === 'c') {
+ if(doClobber === true) {
return util.format(
- "%s\nrequire('cordova/builder').assignOrWrapInDeprecateGetter(%s, '%s', module.exports);",
+ "%s\n;require('cordova/builder').assignOrWrapInDeprecateGetter(%s, '%s', require('%s'));",
code,
object,
- lastName
+ lastName,
+ scriptPath
);
- } else if(method === 'm' && old !== '') {
+ } else if(old !== '') {
return util.format(
- "%s\n;require('cordova/builder').recursiveMerge(%s, module.exports);",
+ "%s\n;require('cordova/builder').recursiveMerge(%s, require('%s'));",
code,
- old
+ old,
+ scriptPath
);
- } else {
- return '// no clobber or merges';
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org