packages/jsio.js
function loadModule (baseLoader, fromDir, fromFile, item, opts) {
      var modulePath = item.from;
      var possibilities = util.resolveModulePath(modulePath, fromDir);
      for (var i = 0, p; p = possibilities[i]; ++i) {
        var path = possibilities[i].path;
        if (!opts.reload && (path in jsio.__modules)) {
          return possibilities[i];
        }

        if (path in failedFetch) { possibilities.splice(i--, 1); }
      }

      if (!possibilities.length) {
        if (opts.suppressErrors) { return false; }
        var e = new Error('Could not import `' + item.from + '`'
            + "\tImport Stack:\n"
            + "\t\t" + processStack().join("\n\t\t"));
        e.jsioLogged = true;
        e.code = MODULE_NOT_FOUND;
        throw e;
      }

      var moduleDef = findModule(possibilities);
      if (!moduleDef) {
        if (opts.suppressErrors) { return false; }
        var paths = [];
        for (var i = 0, p; p = possibilities[i]; ++i) { paths.push(p.path); }
        var e = new Error("Could not import `" + modulePath + "`\n"
          + "\tlooked in:\n"
            + "\t\t" + paths.join('\n\t\t') + "\n"
            + "\tImport Stack:\n"
            + "\t\t" + processStack().join("\n\t\t"));
        e.code = MODULE_NOT_FOUND;
        throw e;
      }

      // a (potentially) nicer way to refer to a module -- how it was referenced in code when it was first imported
      moduleDef.friendlyPath = modulePath;

      // cache the base module's path in the path cache so we don't have to
      // try out all paths the next time we see the same base module.
      if (moduleDef.baseMod && !(moduleDef.baseMod in jsioPath.cache)) {
        jsioPath.cache[moduleDef.baseMod] = moduleDef.basePath;
      }

      // don't apply the standard preprocessors to base.js.  If we're reloading
      // the source code, always apply them.  We also don't want to run them
      // if they've been run once -- moduleDef.pre is set to true already
      // if we're reading the code from the source cache.
      if (modulePath != 'base' && (opts.reload || !opts.dontPreprocess && !moduleDef.pre)) {
        moduleDef.pre = true;

        applyPreprocessors(fromDir, moduleDef, ["import", "inlineSlice"], opts);
      }

      // any additional preprocessors?
      if (opts.preprocessors) {
        applyPreprocessors(fromDir, moduleDef, opts.preprocessors, opts);
      }

      return moduleDef;
    }
function loadModule (baseLoader, fromDir, fromFile, item, opts) {
      var modulePath = item.from;
      var possibilities = util.resolveModulePath(modulePath, fromDir);
      for (var i = 0, p; p = possibilities[i]; ++i) {
        var path = possibilities[i].path;
        if (!opts.reload && (path in jsio.__modules)) {
          return possibilities[i];
        }

        if (path in failedFetch) { possibilities.splice(i--, 1); }
      }

      if (!possibilities.length) {
        if (opts.suppressErrors) { return false; }
        var e = new Error('Could not import `' + item.from + '`'
            + "\tImport Stack:\n"
            + "\t\t" + processStack().join("\n\t\t"));
        e.jsioLogged = true;
        e.code = MODULE_NOT_FOUND;
        throw e;
      }

      var moduleDef = findModule(possibilities);
      if (!moduleDef) {
        if (opts.suppressErrors) { return false; }
        var paths = [];
        for (var i = 0, p; p = possibilities[i]; ++i) { paths.push(p.path); }
        var e = new Error("Could not import `" + modulePath + "`\n"
          + "\tlooked in:\n"
            + "\t\t" + paths.join('\n\t\t') + "\n"
            + "\tImport Stack:\n"
            + "\t\t" + processStack().join("\n\t\t"));
        e.code = MODULE_NOT_FOUND;
        throw e;
      }

      // a (potentially) nicer way to refer to a module -- how it was referenced in code when it was first imported
      moduleDef.friendlyPath = modulePath;

      // cache the base module's path in the path cache so we don't have to
      // try out all paths the next time we see the same base module.
      if (moduleDef.baseMod && !(moduleDef.baseMod in jsioPath.cache)) {
        jsioPath.cache[moduleDef.baseMod] = moduleDef.basePath;
      }

      // don't apply the standard preprocessors to base.js.  If we're reloading
      // the source code, always apply them.  We also don't want to run them
      // if they've been run once -- moduleDef.pre is set to true already
      // if we're reading the code from the source cache.
      if (modulePath != 'base' && (opts.reload || !opts.dontPreprocess && !moduleDef.pre)) {
        moduleDef.pre = true;

        applyPreprocessors(fromDir, moduleDef, ["import", "inlineSlice"], opts);
      }

      // any additional preprocessors?
      if (opts.preprocessors) {
        applyPreprocessors(fromDir, moduleDef, opts.preprocessors, opts);
      }

      return moduleDef;
    }
function loadModule ( baseLoader , fromDir , fromFile , item , opts ) { var modulePath = item . from ; var possibilities = util . resolveModulePath ( modulePath , fromDir ) ; for ( var i = 0 , p ; p = possibilities [ i ] ; ++ i ) { var path = possibilities [ i ] . path ; if ( ! opts . reload && ( path in jsio . __modules ) ) { return possibilities [ i ] ; } if ( path in failedFetch ) { possibilities . splice ( i -- , 1 ) ; } } if ( ! possibilities . length ) { if ( opts . suppressErrors ) { return false ; } var e = new Error ( 'Could not import `' + item . from + '`' + "\tImport Stack:\n" + "\t\t" + processStack ( ) . join ( "\n\t\t" ) ) ; e . jsioLogged = true ; e . code = MODULE_NOT_FOUND ; throw e ; } var moduleDef = findModule ( possibilities ) ; if ( ! moduleDef ) { if ( opts . suppressErrors ) { return false ; } var paths = [ ] ; for ( var i = 0 , p ; p = possibilities [ i ] ; ++ i ) { paths . push ( p . path ) ; } var e = new Error ( "Could not import `" + modulePath + "`\n" + "\tlooked in:\n" + "\t\t" + paths . join ( '\n\t\t' ) + "\n" + "\tImport Stack:\n" + "\t\t" + processStack ( ) . join ( "\n\t\t" ) ) ; e . code = MODULE_NOT_FOUND ; throw e ; } // a (potentially) nicer way to refer to a module -- how it was referenced in code when it was first imported moduleDef . friendlyPath = modulePath ; // cache the base module's path in the path cache so we don't have to // try out all paths the next time we see the same base module. if ( moduleDef . baseMod && ! ( moduleDef . baseMod in jsioPath . cache ) ) { jsioPath . cache [ moduleDef . baseMod ] = moduleDef . basePath ; } // don't apply the standard preprocessors to base.js.  If we're reloading // the source code, always apply them.  We also don't want to run them // if they've been run once -- moduleDef.pre is set to true already // if we're reading the code from the source cache. if ( modulePath != 'base' && ( opts . reload || ! opts . dontPreprocess && ! moduleDef . pre ) ) { moduleDef . pre = true ; applyPreprocessors ( fromDir , moduleDef , [ "import" , "inlineSlice" ] , opts ) ; } // any additional preprocessors? if ( opts . preprocessors ) { applyPreprocessors ( fromDir , moduleDef , opts . preprocessors , opts ) ; } return moduleDef ; }
load a module from a file
load a module from a file