src/deep-core/lib/Generic/require1k.js
function resolveModuleOrGetExports(baseOrModule, relative, resolved) {
    // This should really be after the relative check, but because we are
    // `throw`ing, it messes up the optimizations. If we are being called
    // as resolveModule then the string `base` won't have the `e` property,
    // so we're fine.
    if (baseOrModule.e) {
      throw baseOrModule.e;
    }

    // If 2 arguments are given, then we are resolving modules...
    if (relative) {
      baseElement.href = baseOrModule;
      // If the relative url doesn't begin with a "." or a "/", then it's
      // in node_modules
      relativeElement.href = (relative[0] != "." && relative[0] != "/") ? "./node_modules/" + relative : relative;

      resolved = relativeElement.href.substr(-3).toLowerCase() == ".js" ?
        relativeElement.href :
        relativeElement.href + ".js";

      baseElement.href = "";
      return (MODULES[resolved] = MODULES[resolved] || {l: resolved});
    }

    // ...otherwise we are getting the exports

    // Is this module a redirect to another one?
    if (baseOrModule.n) {
      return resolveModuleOrGetExports(baseOrModule.n);
    }

    if (!baseOrModule[tmp]) {
      (baseOrModule.f || globalEval("(function(require,"+tmp+",module){" + baseOrModule.t + "\n})//# sourceURL=" + baseOrModule.l))(
        function require (id) {
          return resolveModuleOrGetExports(resolveModuleOrGetExports(baseOrModule.l, id));
        }, // require
        baseOrModule[tmp] = {}, // exports
        baseOrModule // module
      );
    }

    return baseOrModule[tmp];
  }
function resolveModuleOrGetExports(baseOrModule, relative, resolved) {
    // This should really be after the relative check, but because we are
    // `throw`ing, it messes up the optimizations. If we are being called
    // as resolveModule then the string `base` won't have the `e` property,
    // so we're fine.
    if (baseOrModule.e) {
      throw baseOrModule.e;
    }

    // If 2 arguments are given, then we are resolving modules...
    if (relative) {
      baseElement.href = baseOrModule;
      // If the relative url doesn't begin with a "." or a "/", then it's
      // in node_modules
      relativeElement.href = (relative[0] != "." && relative[0] != "/") ? "./node_modules/" + relative : relative;

      resolved = relativeElement.href.substr(-3).toLowerCase() == ".js" ?
        relativeElement.href :
        relativeElement.href + ".js";

      baseElement.href = "";
      return (MODULES[resolved] = MODULES[resolved] || {l: resolved});
    }

    // ...otherwise we are getting the exports

    // Is this module a redirect to another one?
    if (baseOrModule.n) {
      return resolveModuleOrGetExports(baseOrModule.n);
    }

    if (!baseOrModule[tmp]) {
      (baseOrModule.f || globalEval("(function(require,"+tmp+",module){" + baseOrModule.t + "\n})//# sourceURL=" + baseOrModule.l))(
        function require (id) {
          return resolveModuleOrGetExports(resolveModuleOrGetExports(baseOrModule.l, id));
        }, // require
        baseOrModule[tmp] = {}, // exports
        baseOrModule // module
      );
    }

    return baseOrModule[tmp];
  }
function resolveModuleOrGetExports ( baseOrModule , relative , resolved ) { // This should really be after the relative check, but because we are // `throw`ing, it messes up the optimizations. If we are being called // as resolveModule then the string `base` won't have the `e` property, // so we're fine. if ( baseOrModule . e ) { throw baseOrModule . e ; } // If 2 arguments are given, then we are resolving modules... if ( relative ) { baseElement . href = baseOrModule ; // If the relative url doesn't begin with a "." or a "/", then it's // in node_modules relativeElement . href = ( relative [ 0 ] != "." && relative [ 0 ] != "/" ) ? "./node_modules/" + relative : relative ; resolved = relativeElement . href . substr ( - 3 ) . toLowerCase ( ) == ".js" ? relativeElement . href : relativeElement . href + ".js" ; baseElement . href = "" ; return ( MODULES [ resolved ] = MODULES [ resolved ] || { l : resolved } ) ; } // ...otherwise we are getting the exports // Is this module a redirect to another one? if ( baseOrModule . n ) { return resolveModuleOrGetExports ( baseOrModule . n ) ; } if ( ! baseOrModule [ tmp ] ) { ( baseOrModule . f || globalEval ( "(function(require," + tmp + ",module){" + baseOrModule . t + "\n})//# sourceURL=" + baseOrModule . l ) ) ( function require ( id ) { return resolveModuleOrGetExports ( resolveModuleOrGetExports ( baseOrModule . l , id ) ) ; } , // require baseOrModule [ tmp ] = { } , // exports baseOrModule // module ) ; } return baseOrModule [ tmp ] ; }
Save bytes by combining two functions - resolveModule which resolves a given relative path against the given base, and returns an existing or new module object - getExports which returns the existing exports or runs the factory to create the exports for a module
Save bytes by combining two functions - resolveModule which resolves a given relative path against the given base and returns an existing or new module object - getExports which returns the existing exports or runs the factory to create the exports for a module