core/modules.js
function loadModules(code, callback){
    var loadedModuleData = [];
    var requires = getModulesRequired(code);
    if (requires.length == 0) {
      // no modules needed - just return
      callback(code);
    } else {
      Espruino.Core.Status.setStatus("Loading modules");
      // Kick off the module loading (each returns a promise)
      var promises = requires.map(function (moduleName) {
        return loadModule(requires, moduleName, loadedModuleData);
      });
      // When all promises are complete
      Promise.all(promises).then(function(){
        callback(loadedModuleData.join("\n") + "\n" + code);
      });
    }
  }
function loadModules(code, callback){
    var loadedModuleData = [];
    var requires = getModulesRequired(code);
    if (requires.length == 0) {
      // no modules needed - just return
      callback(code);
    } else {
      Espruino.Core.Status.setStatus("Loading modules");
      // Kick off the module loading (each returns a promise)
      var promises = requires.map(function (moduleName) {
        return loadModule(requires, moduleName, loadedModuleData);
      });
      // When all promises are complete
      Promise.all(promises).then(function(){
        callback(loadedModuleData.join("\n") + "\n" + code);
      });
    }
  }
function loadModules ( code , callback ) { var loadedModuleData = [ ] ; var requires = getModulesRequired ( code ) ; if ( requires . length == 0 ) { // no modules needed - just return callback ( code ) ; } else { Espruino . Core . Status . setStatus ( "Loading modules" ) ; // Kick off the module loading (each returns a promise) var promises = requires . map ( function ( moduleName ) { return loadModule ( requires , moduleName , loadedModuleData ) ; } ) ; // When all promises are complete Promise . all ( promises ) . then ( function ( ) { callback ( loadedModuleData . join ( "\n" ) + "\n" + code ) ; } ) ; } }
Finds instances of 'require' and then ensures that
those modules are loaded into the module cache beforehand
(by inserting the relevant 'addCached' commands into 'code'
Finds instances of require and then ensures that those modules are loaded into the module cache beforehand ( by inserting the relevant addCached commands into code