cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [3/8] js commit: CB-9505 Correct plugin modules loading within browserify flow. This closes #126
Date Fri, 28 Aug 2015 22:55:36 GMT
CB-9505 Correct plugin modules loading within browserify flow. This closes #126


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/0eec1df1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/0eec1df1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/0eec1df1

Branch: refs/heads/4.1.x
Commit: 0eec1df1d8d83ae9035a4191654ed90ab26deeeb
Parents: 5fdee87
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Tue Aug 18 13:36:53 2015 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Tue Aug 25 10:43:30 2015 +0300

----------------------------------------------------------------------
 src/common/init_b.js           | 11 ++++++-
 src/common/pluginloader.js     |  4 ---
 src/common/pluginloader_b.js   | 63 +++++++++++++++++++++++++++++++++++++
 tasks/lib/bundle-browserify.js |  6 ++--
 4 files changed, 76 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0eec1df1/src/common/init_b.js
----------------------------------------------------------------------
diff --git a/src/common/init_b.js b/src/common/init_b.js
index 6365bdb..8a805d1 100644
--- a/src/common/init_b.js
+++ b/src/common/init_b.js
@@ -23,9 +23,10 @@ var channel = require('cordova/channel');
 var cordova = require('cordova');
 var modulemapper = require('cordova/modulemapper');
 var platform = require('cordova/platform');
+var pluginloader = require('cordova/pluginloader');
 var utils = require('cordova/utils');
 
-var platformInitChannelsArray = [channel.onDOMContentLoaded, channel.onNativeReady];
+var platformInitChannelsArray = [channel.onDOMContentLoaded, channel.onNativeReady, channel.onPluginsReady];
 
 // setting exec
 cordova.exec = require('cordova/exec');
@@ -110,6 +111,14 @@ if (window._nativeReady) {
 // Call the platform-specific initialization.
 platform.bootstrap && platform.bootstrap();
 
+// Wrap in a setTimeout to support the use-case of having plugin JS appended to cordova.js.
+// The delay allows the attached modules to be defined before the plugin loader looks for
them.
+setTimeout(function() {
+    pluginloader.load(function() {
+        channel.onPluginsReady.fire();
+    });
+}, 0);
+
 /**
  * Create all cordova objects once native side is ready.
  */

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0eec1df1/src/common/pluginloader.js
----------------------------------------------------------------------
diff --git a/src/common/pluginloader.js b/src/common/pluginloader.js
index 7fd4d10..f2d34e0 100644
--- a/src/common/pluginloader.js
+++ b/src/common/pluginloader.js
@@ -19,10 +19,6 @@
  *
 */
 
-/*
-    NOTE: this file is NOT used when we use the browserify workflow
-*/
-
 var modulemapper = require('cordova/modulemapper');
 var urlutil = require('cordova/urlutil');
 

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0eec1df1/src/common/pluginloader_b.js
----------------------------------------------------------------------
diff --git a/src/common/pluginloader_b.js b/src/common/pluginloader_b.js
new file mode 100644
index 0000000..46e4446
--- /dev/null
+++ b/src/common/pluginloader_b.js
@@ -0,0 +1,63 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var modulemapper = require('cordova/modulemapper');
+
+// Handler for the cordova_plugins.js content.
+// See plugman's plugin_loader.js for the details of this object.
+function handlePluginsObject(moduleList) {
+    // if moduleList is not defined or empty, we've nothing to do
+    if (!moduleList || !moduleList.length) {
+        return;
+    }
+
+    // Loop through all the modules and then through their clobbers and merges.
+    for (var i = 0, module; module = moduleList[i]; i++) {
+        if (module.clobbers && module.clobbers.length) {
+            for (var j = 0; j < module.clobbers.length; j++) {
+                modulemapper.clobbers(module.id, module.clobbers[j]);
+            }
+        }
+
+        if (module.merges && module.merges.length) {
+            for (var k = 0; k < module.merges.length; k++) {
+                modulemapper.merges(module.id, module.merges[k]);
+            }
+        }
+
+        // Finally, if runs is truthy we want to simply require() the module.
+        if (module.runs) {
+            modulemapper.runs(module.id);
+        }
+    }
+}
+
+// Loads all plugins' js-modules. Plugin loading is syncronous in browserified bundle
+// but the method accepts callback to be compatible with non-browserify flow.
+// onDeviceReady is blocked on onPluginsReady. onPluginsReady is fired when there are
+// no plugins to load, or they are all done.
+exports.load = function(callback) {
+    var moduleList = require("cordova/plugin_list");
+    handlePluginsObject(moduleList);
+
+    callback();
+};
+

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/0eec1df1/tasks/lib/bundle-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/lib/bundle-browserify.js b/tasks/lib/bundle-browserify.js
index b10524d..3a1c3f9 100644
--- a/tasks/lib/bundle-browserify.js
+++ b/tasks/lib/bundle-browserify.js
@@ -38,9 +38,10 @@ module.exports = function bundle(platform, debug, commitId, platformVersion,
pla
     // Replace standart initialization script with browserify's one
     delete modules['cordova/init_b'];
     delete modules['cordova/modulemapper_b'];
-    delete modules['cordova/pluginloader'];
+    delete modules['cordova/pluginloader_b'];
     modules['cordova/init'] = path.resolve(root, 'src', 'common', 'init_b.js');
     modules['cordova/modulemapper'] = path.resolve(root, 'src', 'common', 'modulemapper_b.js');
+    modules['cordova/pluginloader'] = path.resolve(root, 'src', 'common', 'pluginloader_b.js');
 
     // test doesn't support custom paths
     if (platform === 'test') {
@@ -76,6 +77,5 @@ module.exports = function bundle(platform, debug, commitId, platformVersion,
pla
 
     return browserify({debug: !!debug, detectGlobals: false})
         .require(modules)
-        .exclude('cordova/plugin_list')
-        .exclude('cordova/pluginloader');
+        .exclude('cordova/plugin_list');
 };


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message