runtime_library/module.js
/**
   *  Eval the module_code to extract the module.exports.
   *  Note that within the eval context, require will be overwritten
   *  with a version that prepends the path of the current module_identifier
   *  (or its directory if module_identifier refers to a file) so that
   *  when require is called in submodules it will work as expected.
   *
   *  @param {String} module_identifier
   *  @param {String} module_code
   *
   *  @returns {type depends on module} exports The module.exports or exports set by running the module_code
   */
Eval the module_code to extract the module.exports.
Note that within the eval context, require will be overwritten
with a version that prepends the path of the current module_identifier
(or its directory if module_identifier refers to a file) so that
when require is called in submodules it will work as expected.



@returns {type depends on module} exports The module.exports or exports set by running the module_code
Eval the module_code to extract the module . exports . Note that within the eval context require will be overwritten with a version that prepends the path of the current module_identifier ( or its directory if module_identifier refers to a file ) so that when require is called in submodules it will work as expected . @returns { type depends on module } exports The module . exports or exports set by running the module_code
function loadJavascript(module_identifier, module_code) {
    var module = { exports: {} };
    var exports;
    try {
      var dir_for_submodules = splitPath(module_identifier).dir;
      var last_module_path = truncateToLastInstance(dir_for_submodules, CODIUS_MODULE_REGEX);
      var overwrite_require = '(function(){' +
        'var original_require = require; ' +
        'var full_id = ""; ' +
        'require = function(id){ ' +
          'if (id.search(' + CODIUS_MODULE_REGEX +') === 0) { ' +
            'full_id = "' + last_module_path + '" + "/codius_modules/" + ' + CODIUS_MODULE_REGEX + '.exec(id)[1] + id.replace(' + CODIUS_MODULE_REGEX + ', ""); ' +
          '} else { ' +
            'full_id = "' + dir_for_submodules + '" + id; ' +
          '}' +
          'return original_require(full_id);' +
        '}' +
      '})()';
      eval('(function(module, exports, require){' + overwrite_require + ';' + module_code + ';})(module, module.exports, require);');
    } catch(error) {
      throw new Error('Error requiring module: "' + module_identifier + '" ' + error);
    }
    exports = module.exports || module;
    return exports;
  }
function loadJavascript ( module_identifier , module_code ) { var module = { exports : { } } ; var exports ; try { var dir_for_submodules = splitPath ( module_identifier ) . dir ; var last_module_path = truncateToLastInstance ( dir_for_submodules , CODIUS_MODULE_REGEX ) ; var overwrite_require = '(function(){' + 'var original_require = require; ' + 'var full_id = ""; ' + 'require = function(id){ ' + 'if (id.search(' + CODIUS_MODULE_REGEX + ') === 0) { ' + 'full_id = "' + last_module_path + '" + "/codius_modules/" + ' + CODIUS_MODULE_REGEX + '.exec(id)[1] + id.replace(' + CODIUS_MODULE_REGEX + ', ""); ' + '} else { ' + 'full_id = "' + dir_for_submodules + '" + id; ' + '}' + 'return original_require(full_id);' + '}' + '})()' ; eval ( '(function(module, exports, require){' + overwrite_require + ';' + module_code + ';})(module, module.exports, require);' ) ; } catch ( error ) { throw new Error ( 'Error requiring module: "' + module_identifier + '" ' + error ) ; } exports = module . exports || module ; return exports ; }
Eval the module_code to extract the module.exports.
Eval the module_code to extract the module . exports .
// Overwrite the require that will be used by submodules // dir_for_submodules is the directory the current file is in // However, if a submodule requires a module we must look for it in // the manifest of that submodule, which is what we use the last_module_path for // (e.g. if `codius_modules/module/lib/index.js` requires `submodule`, we need to // look for it in `codius_modules/module/codius-manifest.json`, NOT in `codius_modules/module/lib/codius-manifest.json`) // eval the module code to extract the module.exports section