cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [2/2] js commit: CB-9436 Removes `require-tr` bundle transformation
Date Wed, 05 Aug 2015 23:08:46 GMT
CB-9436 Removes `require-tr` bundle transformation


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

Branch: refs/heads/master
Commit: d02896617847ce83b4d768cb3ad8ac348189d8b4
Parents: 2c29e18
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Fri Jul 31 17:29:26 2015 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Fri Jul 31 17:30:19 2015 +0300

----------------------------------------------------------------------
 package.json                     |   4 +-
 src/common/init_b.js             |   2 +
 src/common/modulemapper_b.js     | 111 +++++++++++++++++
 src/cordova_b.js                 |  14 +--
 tasks/compile-browserify.js      |   2 +-
 tasks/lib/bundle-browserify.js   |  86 +++++++------
 tasks/lib/packager-browserify.js |  32 +----
 tasks/lib/require-tr.js          | 228 ----------------------------------
 8 files changed, 170 insertions(+), 309 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d0289661/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 7139292..083c31d 100644
--- a/package.json
+++ b/package.json
@@ -73,9 +73,7 @@
     "through2": "^2.0.0"
   },
   "dependencies": {
-    "browserify": "10.1.3",
-    "through": "2.3.4",
-    "uglify-js": "^2.4.15"
+    "browserify": "10.1.3"
   },
   "cordova-platforms" : {
     "cordova-android"       : "../cordova-android",

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d0289661/src/common/init_b.js
----------------------------------------------------------------------
diff --git a/src/common/init_b.js b/src/common/init_b.js
index e796695..6365bdb 100644
--- a/src/common/init_b.js
+++ b/src/common/init_b.js
@@ -21,6 +21,7 @@
 
 var channel = require('cordova/channel');
 var cordova = require('cordova');
+var modulemapper = require('cordova/modulemapper');
 var platform = require('cordova/platform');
 var utils = require('cordova/utils');
 
@@ -113,6 +114,7 @@ platform.bootstrap && platform.bootstrap();
  * Create all cordova objects once native side is ready.
  */
 channel.join(function() {
+    modulemapper.mapModules(window);
 
     platform.initialize && platform.initialize();
 

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d0289661/src/common/modulemapper_b.js
----------------------------------------------------------------------
diff --git a/src/common/modulemapper_b.js b/src/common/modulemapper_b.js
new file mode 100644
index 0000000..98d82d3
--- /dev/null
+++ b/src/common/modulemapper_b.js
@@ -0,0 +1,111 @@
+/*
+ * 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 builder = require('cordova/builder'),
+    symbolList = [],
+    deprecationMap;
+
+exports.reset = function() {
+    symbolList = [];
+    deprecationMap = {};
+};
+
+function addEntry(strategy, moduleName, symbolPath, opt_deprecationMessage) {
+    symbolList.push(strategy, moduleName, symbolPath);
+    if (opt_deprecationMessage) {
+        deprecationMap[symbolPath] = opt_deprecationMessage;
+    }
+}
+
+// Note: Android 2.3 does have Function.bind().
+exports.clobbers = function(moduleName, symbolPath, opt_deprecationMessage) {
+    addEntry('c', moduleName, symbolPath, opt_deprecationMessage);
+};
+
+exports.merges = function(moduleName, symbolPath, opt_deprecationMessage) {
+    addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
+};
+
+exports.defaults = function(moduleName, symbolPath, opt_deprecationMessage) {
+    addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
+};
+
+exports.runs = function(moduleName) {
+    addEntry('r', moduleName, null);
+};
+
+function prepareNamespace(symbolPath, context) {
+    if (!symbolPath) {
+        return context;
+    }
+    var parts = symbolPath.split('.');
+    var cur = context;
+    for (var i = 0, part; part = parts[i]; ++i) {
+        cur = cur[part] = cur[part] || {};
+    }
+    return cur;
+}
+
+exports.mapModules = function(context) {
+    var origSymbols = {};
+    context.CDV_origSymbols = origSymbols;
+    for (var i = 0, len = symbolList.length; i < len; i += 3) {
+        var strategy = symbolList[i];
+        var moduleName = symbolList[i + 1];
+        var module = require(moduleName);
+        // <runs/>
+        if (strategy == 'r') {
+            continue;
+        }
+        var symbolPath = symbolList[i + 2];
+        var lastDot = symbolPath.lastIndexOf('.');
+        var namespace = symbolPath.substr(0, lastDot);
+        var lastName = symbolPath.substr(lastDot + 1);
+
+        var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol:
' + symbolPath + '. ' + deprecationMsg : null;
+        var parentObj = prepareNamespace(namespace, context);
+        var target = parentObj[lastName];
+
+        if (strategy == 'm' && target) {
+            builder.recursiveMerge(target, module);
+        } else if ((strategy == 'd' && !target) || (strategy != 'd')) {
+            if (!(symbolPath in origSymbols)) {
+                origSymbols[symbolPath] = target;
+            }
+            builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
+        }
+    }
+};
+
+exports.getOriginalSymbol = function(context, symbolPath) {
+    var origSymbols = context.CDV_origSymbols;
+    if (origSymbols && (symbolPath in origSymbols)) {
+        return origSymbols[symbolPath];
+    }
+    var parts = symbolPath.split('.');
+    var obj = context;
+    for (var i = 0; i < parts.length; ++i) {
+        obj = obj && obj[parts[i]];
+    }
+    return obj;
+};
+
+exports.reset();
+

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d0289661/src/cordova_b.js
----------------------------------------------------------------------
diff --git a/src/cordova_b.js b/src/cordova_b.js
index 1aecd32..359fb4a 100644
--- a/src/cordova_b.js
+++ b/src/cordova_b.js
@@ -98,19 +98,7 @@ function createEvent(type, data) {
 var cordova = {
     platformVersion:PLATFORM_VERSION_BUILD_LABEL,
     version:PLATFORM_VERSION_BUILD_LABEL,
-    require: function(module) {
-        console.log(module);
-        if(symbolList) {
-          for(var i = 0 ; i < symbolList.length ; i++) {
-            if(module === symbolList[i].symbol) {
-              return require(symbolList[i].path);
-            }
-          }
-        } else {
-          console.log("else");
-          return require(module);
-        }
-    },
+    require: require,
     platformId:platform.id,
     /**
      * Methods to add/remove your own addEventListener hijacking on document + window.

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d0289661/tasks/compile-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/compile-browserify.js b/tasks/compile-browserify.js
index 034acdc..cfafff2 100644
--- a/tasks/compile-browserify.js
+++ b/tasks/compile-browserify.js
@@ -55,6 +55,6 @@ module.exports = function(grunt) {
                 platformVersion = 'N/A';
             }
         }
-        generate(platformName, useWindowsLineEndings, platformVersion, done);
+        generate(platformName, useWindowsLineEndings, platformVersion, platformPath, done);
     });
 }

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d0289661/tasks/lib/bundle-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/lib/bundle-browserify.js b/tasks/lib/bundle-browserify.js
index 50478f6..b10524d 100644
--- a/tasks/lib/bundle-browserify.js
+++ b/tasks/lib/bundle-browserify.js
@@ -9,7 +9,7 @@
  *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to 
+ * Unless required by applicable law or agreed to
  * software distributed under the License is distr
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
  * KIND, either express or implied.  See the Licen
@@ -19,53 +19,63 @@
 var fs           = require('fs');
 var path         = require('path');
 var browserify   = require('browserify');
-var require_tr   = require('./require-tr');
 var root         = path.join(__dirname, '..', '..');
 var pkgJson      = require('../../package.json');
 var collectFiles = require('./collect-files');
 var copyProps    = require('./copy-props');
 
-module.exports = function bundle(platform, debug, commitId, platformVersion) {
-    require_tr.platform = platform;
-    // FIXME: need to find a way to void ignore missing
-    var b = browserify({debug: debug});
-    // XXX plugin_list is not present at this stage 
-    b.ignore(path.join(root, 'src', 'common', 'plugin_list'));
+module.exports = function bundle(platform, debug, commitId, platformVersion, platformPath)
{
+    platformPath = fs.existsSync(platformPath) && fs.existsSync(path.join(platformPath,
'cordova-js-src')) ?
+        path.join(platformPath, 'cordova-js-src') :
+        path.resolve(root, 'src', 'legacy-exec', platform);
 
-    b.transform(require_tr.transform, {'platform': platform});
+    var platformDirname = platform === 'amazon-fireos' ? 'android' : platform;
 
-    var cordovajssrc = path.join(process.cwd(), 'platforms', platform, 'platform_www', 'cordova-js-src');
-    //checks to see if browserify is run in a cli project and
-    //if the platform has a cordova-js-src to build cordova.js with
-    if(fs.existsSync(cordovajssrc)){ 
-        b.add(path.join(cordovajssrc, 'exec.js'));
-        b.add(path.join(cordovajssrc, 'platform.js'));
-    } else {
-        b.add(path.join(root, 'src', 'legacy-exec', platform, 'exec.js'));
-        b.add(path.join(root, 'src', 'legacy-exec', platform, 'platform.js'));
-    }
+    var modules = {'cordova': path.resolve(root, 'src', 'cordova_b.js')};
+    copyProps(modules, collectFiles(path.resolve(root, 'src', 'common'), 'cordova'));
+    copyProps(modules, collectFiles(platformPath, 'cordova'));
 
-    if (platform === 'test') {
-        // Add tests to bundle
-        // TODO: Also need to include android/ios tests
-        fs.readdirSync('test').forEach(function (item) {
-            var itemPath = path.resolve('test', item);
-            if (fs.statSync(itemPath).isFile()) b.add(itemPath);
-        });
+    // Replace standart initialization script with browserify's one
+    delete modules['cordova/init_b'];
+    delete modules['cordova/modulemapper_b'];
+    delete modules['cordova/pluginloader'];
+    modules['cordova/init'] = path.resolve(root, 'src', 'common', 'init_b.js');
+    modules['cordova/modulemapper'] = path.resolve(root, 'src', 'common', 'modulemapper_b.js');
 
-        // Add rest of modules from cordova-js-src/legacy-exec directory
-        // TODO: this probably should be done for all platforms?
-        fs.readdirSync(path.join(root, 'src', 'legacy-exec', platform, platform)).forEach(function
(item) {
-            var itemPath = path.resolve(root, 'src', 'legacy-exec', platform, platform, item);
-            if (fs.statSync(itemPath).isFile()) b.add(itemPath);
-        });
+    // test doesn't support custom paths
+    if (platform === 'test') {
+        var testFilesPath;
+        var androidPath = path.resolve(pkgJson['cordova-platforms']['cordova-android']);
+        var iosPath = path.resolve(pkgJson['cordova-platforms']['cordova-ios']);
+        // Add android platform-specific modules that have tests to the test bundle.
+        if(fs.existsSync(androidPath)) {
+            testFilesPath = path.resolve(androidPath, 'cordova-js-src', 'android');
+            modules['cordova/android/exec'] = path.resolve(androidPath, 'cordova-js-src',
'exec.js');
+        } else {
+            testFilesPath = path.resolve('src', 'legacy-exec', 'android', 'android');
+            modules['cordova/android/exec'] = path.resolve(root, 'src', 'legacy-exec', 'android',
'exec.js');
+        }
+        copyProps(modules, collectFiles(testFilesPath, 'cordova/android'));
 
-        // Ignore fake modules from tests, otherwise browserify fails to generate bundle
-        ['your mom', 'dino', 'a', 'ModuleA', 'ModuleB', 'ModuleC']
-        .forEach(b.ignore.bind(b));
+        //Add iOS platform-specific modules that have tests for the test bundle.
+        if(fs.existsSync(iosPath)) {
+            modules['cordova/ios/exec'] = path.join(iosPath, 'cordova-js-src', 'exec.js');
+        } else {
+            modules['cordova/ios/exec'] = path.resolve(root, 'src', 'legacy-exec', 'ios',
'exec.js');
+        }
+        copyProps(modules, collectFiles(testFilesPath, 'cordova/ios'));
     }
 
-    b.add(path.join(root, 'src', 'scripts', 'bootstrap.js'));
+    modules = Object.keys(modules)
+    .map(function (moduleId) {
+        return {
+            file: modules[moduleId],
+            expose: moduleId
+        };
+    });
 
-    return b;
-}
+    return browserify({debug: !!debug, detectGlobals: false})
+        .require(modules)
+        .exclude('cordova/plugin_list')
+        .exclude('cordova/pluginloader');
+};

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d0289661/tasks/lib/packager-browserify.js
----------------------------------------------------------------------
diff --git a/tasks/lib/packager-browserify.js b/tasks/lib/packager-browserify.js
index 5bdb39a..12863b6 100644
--- a/tasks/lib/packager-browserify.js
+++ b/tasks/lib/packager-browserify.js
@@ -9,7 +9,7 @@
  *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to 
+ * Unless required by applicable law or agreed to
  * software distributed under the License is distr
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
  * KIND, either express or implied.  See the Licen
@@ -19,26 +19,18 @@
 var fs                 = require('fs');
 var path               = require('path');
 var util               = require('util');
-var through            = require('through2');
 var requireTr          = require('./require-tr');
 var bundle             = require('./bundle-browserify');
 var computeCommitId    = require('./compute-commit-id');
 var writeLicenseHeader = require('./write-license-header');
 
-module.exports = function generate(platform, useWindowsLineEndings, platformVersion, done)
{
+module.exports = function generate(platform, useWindowsLineEndings, platformVersion, platformPath,
done) {
     computeCommitId(function(commitId) {
         var outReleaseFile, outReleaseFileStream,
             outDebugFile, outDebugFileStream,
             releaseBundle, debugBundle;
         var time = new Date().valueOf();
 
-        var libraryRelease = bundle(platform, false, commitId, platformVersion);
-       // if we are using windows line endings, we will also add the BOM
-       // if(useWindowsLineEndings) {
-       //     libraryRelease = "\ufeff" + libraryRelease.split(/\r?\n/).join("\r\n");
-       // }
-       // var libraryDebug   = bundle(platform, true, commitId);
-
         if (!fs.existsSync('pkg')) {
             fs.mkdirSync('pkg');
         }
@@ -46,25 +38,13 @@ module.exports = function generate(platform, useWindowsLineEndings, platformVers
         outReleaseFile = path.join('pkg', 'cordova.' + platform + '.js');
         outReleaseFileStream = fs.createWriteStream(outReleaseFile);
 
-        var symbolList = null;
-        var addSymbolList = through.obj(function(row, enc, next) {
-            if(symbolList === null) {
-                symbolList = requireTr.getModules(platform);
-                this.push(util.format('var symbolList = %s;\n%s\n', JSON.stringify(symbolList,
null, 4), row));
-            } else {
-                this.push(row);
-            }
-            next();
-        });
-
-        libraryRelease.pipeline.get('wrap').push(addSymbolList);
-
         // write license header
         writeLicenseHeader(outReleaseFileStream, platform, commitId, platformVersion);
 
-        releaseBundle = libraryRelease.bundle();
-
-        releaseBundle.pipe(outReleaseFileStream);
+        bundle(platform, false, commitId, platformVersion, platformPath)
+          .add(path.resolve(__dirname, '..', '..', 'src/scripts/bootstrap.js'))
+          .bundle()
+          .pipe(outReleaseFileStream);
 
         outReleaseFileStream.on('finish', function() {
           var newtime = new Date().valueOf() - time;

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d0289661/tasks/lib/require-tr.js
----------------------------------------------------------------------
diff --git a/tasks/lib/require-tr.js b/tasks/lib/require-tr.js
deleted file mode 100644
index a15f3ad..0000000
--- a/tasks/lib/require-tr.js
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-/*
- * This probably should live in plugman/cli world
- * Transoforms old require calls to new node-style require calls
- * the whole thing is fucking bullshit and needs to disappear ASAP
- */
-
-var fs = require('fs');
-var path = require('path');
-var util = require('util');
-var through = require('through');
-var UglifyJS = require('uglify-js');
-var os = require('os');
-var root = fs.realpathSync(path.join(__dirname, '..', '..'));
-
-var requireTr = {
-
-  init: function(platform) {
-    this.platform = platform;
-    this.modules[platform] = [];
-  },
-
-  transform: function(file, platObj) {
-    this.platform = platObj.platform;
-    var data = '';
-
-    function write(buf) {
-      data += buf;
-    }
-
-    function end() {
-      var platform = platObj.platform;
-      // SOME BS pre-transforms
-      if(data.match(/clobbers\("cordova\/plugin\/android\/app/)) {
-        // Checking for '\' from the windows path
-        root = root.replace(/\\/g, '/');
-
-        // new way that uses files from cordova-js-src
-        if (file.match(/android\/platform_www\/cordova-js-src\/platform.js$/) || file.match(/android\\platform_www\\cordova-js-src\\platform.js$/))
{
-            var androidPath = path.dirname(file).replace(/\\/g, '/');
-
-            data = data.replace(/modulemapper\.clobbers.*\n/,
-                                util.format('navigator.app = require("%s/plugin/android/app.js");',
androidPath));
-        } else if (file.match(/amazon-fireos\/platform_www\/cordova-js-src\/platform.js$/)
|| file.match(/amazon-fireos\\platform_www\\cordova-js-src\\platform.js$/)) {
-            var amazonfirePath = path.dirname(file).replace(/\\/g, '/');
-
-            data = data.replace(/modulemapper\.clobbers.*\n/,
-                                util.format('navigator.app = require("%s/plugin/android/app.js");',
amazonfirePath));
-        }
-
-
-        // the old way, keep as a fallback
-        if(file.match(/android\/platform.js$/) || file.match(/android\\platform.js$/)) {
-          data = data.replace(/modulemapper\.clobbers.*\n/,
-                              util.format('navigator.app = require("%s/src/legacy-exec/android/plugin/android/app");',
root));
-        } else if (file.match(/amazon-fireos\/platform.js$/) || file.match(/amazon-fireos\\platform.js$/))
{
-          data = data.replace(/modulemapper\.clobbers.*\n/,
-                              util.format('navigator.app = require("%s/src/legacy-exec/amazon-fireos/plugin/android/app");',
root));
-        }
-      }
-
-      if(data.match(/clobbers\("cordova\/exec\/proxy/)) {
-        // Checking for '\' from the windows path
-        root = root.replace(/\\/g, '/');
-
-        data = data.replace(/modulemapper\.clobbers.*\n/,
-                            util.format('cordova.commandProxy = require("%s/src/common/exec/proxy");',
root));
-      }
-
-      if(file.match(/FileReader.js$/)) {
-        data = data.replace(/getOriginalSymbol\(this/,
-                            'getOriginalSymbol(window');
-      }
-     
-      this.queue(_updateRequires(data, platform));
-      this.queue(null);
-    }
-   
-    return through(write, end);
-  },
-  hasModule: function(module, platform) {
-    if(this.modules[platform] === undefined) {
-      this.modules[platform] = [];
-    }
-    var platformModules = this.modules[platform];
-
-    for(var i = 0, j = platformModules.length ; i < j ; i++) {
-      if(platformModules[i].symbol === module) {
-        return true;
-      }
-    }
-    return false;
-  },
-  getModules: function(platform) {
-    return this.modules[platform] || [];
-  },
-  addModule: function(module, platform) {
-    if(!module || !module.symbol || !module.path) {
-      throw new Error("Can't add module without a symbol and a path");
-    }
-    this.modules[platform].push(module);
-  },
-  modules:{},
-  platform: null
-}
-
-/*
- * visits AST and modifies all the require('cordova/*') and require('org.apache.cordova.*')
- */
-function _updateRequires(code, platform) {
-  var ast = UglifyJS.parse(code);
-  var before = new UglifyJS.TreeTransformer(function(node, descend) {
-
-    // check all function calls
-    if(node instanceof UglifyJS.AST_Call) {
-      // check if function call is a require('module') call
-      if(node.expression.name === "require" && node.args.length === 1) {
-
-        // Uglify is not able to recognize Windows style paths using '\' instead of '/'
-        // So replacing all of the '/' back to Windows '\'
-        if (node.args[0].value !== undefined && node.args[0].value.indexOf(root)
!== -1 && process.platform === 'win32') {
-            node.args[0].value = node.args[0].value.replace(/\//g, '\\');
-        }
-
-        var module = node.args[0].value;
-
-        // make sure require only has one argument and that it starts with cordova (old style
require.js)
-        if(module !== undefined &&
-           module.indexOf("cordova") === 0 && module.indexOf("cordova-") !== 0) {
-
-          var scriptPath;
-          var cordovajssrc = path.join(process.cwd(), "platforms", platform, "platform_www",
"cordova-js-src");
-          // Amazon uses "android" directory
-          var platformName = platform === "amazon-fireos" ? "android" : platform;
-          var platformModuleRe = new RegExp('cordova\/(' + platformName + ')\/(.+)');
-
-          // require('cordova') -> cordova.js
-          if(module === "cordova") {
-            scriptPath = node.args[0].value = path.join(root, "src", "cordova_b");
-          // require('cordova/init') -> common/init
-          }  else if(module.match(/cordova\/init/)) {
-            scriptPath = node.args[0].value = module.replace(/cordova\/init/,
-                                    path.join(root, "src", "common", "init_b"));
-          // handle platform's special special requires
-          } else if(module.match(platformModuleRe)) {
-                if(fs.existsSync(cordovajssrc)) {
-                    //cordova cli project with cordova-js-src in platform
-                    scriptPath = node.args[0].value = module.replace(platformModuleRe,
-                        path.join(cordovajssrc, platformName, "$2"));
-                } else {
-                    //non cli or no cordova-js-src directory
-                    scriptPath = node.args[0].value = module.replace(platformModuleRe,
-                        path.join(root, "src", "legacy-exec", "$1", platformName, "$2"));
-                }
-          // require('cordova/exec') and require('cordova/platform') -> platform's exec/platform
-          } else if(module.match(/cordova\/(platform|exec)$/)) {
-                if(fs.existsSync(cordovajssrc)) {
-                    //cordova cli project with cordova-js-src in platform
-                    scriptPath = node.args[0].value = module.replace(/cordova\/(platform|exec)/,
path.join(cordovajssrc, "$1"));
-                } else {
-                    //non cli or no cordova-js-src directory
-                    scriptPath = node.args[0].value = module.replace(/cordova\/(platform|exec)/,
path.join(root, "src", "legacy-exec", platform, "$1"));
-                }
-            
-          // require('cordova/anything') should be under common/
-          } else if(module.match(/cordova\/(.+)/)) {
-            scriptPath = node.args[0].value = module.replace(/cordova\/(.+)/,
-                                    path.join(root, "src", "common", "$1"));
-          }
-          if(requireTr.hasModule(module, platform) === false) {
-            requireTr.addModule({symbol: module, path: scriptPath}, platform);
-          }
-        }
-        else if(module !== undefined && (module.indexOf("/") !== 0)){
-          var modules = requireTr.getModules(platform);
-
-
-          if(module.indexOf("../") === 0){
-            module = module.replace('../', '');
-          }
-          if(module.indexOf("./") === 0 ) {
-            module = module.replace('./', '');
-          }
-
-          for(var i = 0, j = modules.length ; i < j ; i++) {
-            var regx = new RegExp ("\\."+ module + "$");
-            if(module === modules[i].symbol || modules[i].symbol.search(regx) != -1) {
-                node.args[0].value = modules[i].path;
-                break;
-            }
-          }
-        }
-        descend(node, this);
-        return node;
-      }
-    }
-  });
-
-  ast.transform(before, null);
-
-  var stream = UglifyJS.OutputStream({beautify:true});
-
-  ast.print(stream);
-
-  return stream.toString();
-}
-
-module.exports = requireTr; 


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


Mime
View raw message