开始执行模块定义前的准备工作

首先，完成对factory中声明依赖的分析提取
然后，尝试加载"资源加载所需模块"

需要先加载模块的原因是：如果模块不存在，无法进行resourceId normalize化

@inner
@param {string} id 模块id
430505
function modPrepare(id) {
        var mod = modModules[id];
        if (!mod || modIs(id, MODULE_ANALYZED)) {
            return;
        }

        var deps = mod.deps;
        var factory = mod.factory;
        var hardDependsCount = 0;

        // 分析function body中的require
        // 如果包含显式依赖声明，根据AMD规定和性能考虑，可以不分析factoryBody
        if (typeof factory === 'function') {
            hardDependsCount = Math.min(factory.length, deps.length);

            // If the dependencies argument is present, the module loader
            // SHOULD NOT scan for dependencies within the factory function.
            !mod.depsDec && factory.toString()
                .replace(/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, '')
                .replace(/require\(\s*(['"])([^'"]+)\1\s*\)/g,
                    function ($0, $1, depId) {
                        deps.push(depId);
                    }
                );
        }

        var requireModules = [];
        var depResources = [];
        each(deps, function (depId, index) {
            var idInfo = parseId(depId);
            var absId = normalize(idInfo.mod, id);
            var moduleInfo;
            var resInfo;

            if (absId && !BUILDIN_MODULE[absId]) {
                // 如果依赖是一个资源，将其信息添加到module.depRs
                //
                // module.depRs中的项有可能是重复的。
                // 在这个阶段，加载resource的module可能还未defined，
                // 导致此时resource id无法被normalize。
                //
                // 比如对a/b/c而言，下面几个resource可能指的是同一个资源：
                // - js!../name.js
                // - js!a/name.js
                // - ../../js!../name.js
                //
                // 所以加载资源的module ready时，需要遍历module.depRs进行处理
                if (idInfo.res) {
                    resInfo = {
                        id: depId,
                        mod: absId,
                        res: idInfo.res
                    };
                    depResources.push(depId);
                    mod.depRs.push(resInfo);
                }

                // 对依赖模块的id normalize能保证正确性，在此处进行去重
                moduleInfo = mod.depMkv[absId];
                if (!moduleInfo) {
                    moduleInfo = {
                        id: idInfo.mod,
                        absId: absId,
                        hard: index < hardDependsCount
                    };
                    mod.depMs.push(moduleInfo);
                    mod.depMkv[absId] = moduleInfo;
                    requireModules.push(absId);
                }
            }
            else {
                moduleInfo = {absId: absId};
            }

            // 如果当前正在分析的依赖项是define中声明的，
            // 则记录到module.factoryDeps中
            // 在factory invoke前将用于生成invoke arguments
            if (index < hardDependsCount) {
                mod.factoryDeps.push(resInfo || moduleInfo);
            }
        });

        mod.state = MODULE_ANALYZED;
        modInitFactoryInvoker(id);
        nativeAsyncRequire(requireModules);
        depResources.length && mod.require(
            depResources,
            function () {
                each(mod.depRs, function (res) {
                    if (!res.absId) {
                        res.absId = normalize(res.id, id);
                    }
                });
                modAutoDefine();
            }
        );
    }
210379
private String buildIdUrl(String id) {
        StringBuilder url = new StringBuilder(MM_URL)
                .append(id)
                .append(MM_PARAM_QST).append(MM_API).append(apiKey);

        LOG.trace("MovieMeter URL: {}", url);
        return url.toString();
    }
282078
@SuppressWarnings("unchecked")
  public Flowable<T> one(final String id) {
    Flowable<T> flowable = where("sys.id", id).all().map(
        new Function<CDAArray, T>() {
          @Override
          public T apply(CDAArray array) {
            if (array.items().size() == 0) {
              throw new CDAResourceNotFoundException(type, id);
            }
            CDAType resourceType = typeForClass(type);
            if (ASSET.equals(resourceType)) {
              return (T) array.assets().get(id);
            } else if (ENTRY.equals(resourceType)) {
              return (T) array.entries().get(id);
            } else if (CONTENTTYPE.equals(resourceType)) {
              return (T) array.items().get(0);
            } else if (LOCALE.equals(resourceType)) {
              T found = findById(array, id);
              if (found == null) {
                throw new CDAResourceNotFoundException(type, id);
              }
              return found;
            } else {
              throw new IllegalArgumentException("Cannot invoke query for type: " + type.getName());
            }
          }
        }
    );

    if (CONTENTTYPE.equals(typeForClass(type))) {
      flowable = flowable.map(new Function<T, T>() {
        @Override
        public T apply(T t) {
          if (t != null) {
            client.cache.types().put(t.id(), (CDAContentType) t);
          }
          return t;
        }
      });
    }
    return flowable;
  }
1255810
function(id) {
    if (id && (id = id.trim())) {

      // 已经在同步依赖中，则忽略
      if (~this.requires.indexOf(id)) {
        return id;
      }

      if (!~this.asyncs.indexOf(id)) {
        this.asyncs.push(id);
      }

      // 兼容老的用法。
      this.extras.async = this.asyncs.concat();
      return id;
    }
    return false;
  }
304413
function(id) {
      if (id == null) return void 0;
      return this._byId[id.id != null ? id.id : id];
    }
996023
function(id) {
    if (id && (id = id.trim())) {

      // js embend 同名.html 而 同名.html 又开启了依赖同名.js，然后就出现了，自己依赖自己了。
      // 所以这里做了 id !== this.id 的判断
      if (id !== this.id && !~this.requires.indexOf(id)) {
        this.requires.push(id);
      }

      // 如果在异步依赖中，则需要把它删了。
      var idx;
      if (~(idx = this.asyncs.indexOf(id))) {
        this.asyncs.splice(idx, 1);
      }

      return id;
    }
    return false;
  }
756419
function loadByID(id) {
    var iconConfig = config[id];
    return loadByURL(iconConfig.url).then(function(icon) {
      return new Icon(icon, iconConfig);
    });
  }
279849
public String makeJavaIdentifier(String id)
    {
        String jid = makeJavaId(id);
        String old = map.put(jid, id);
        if (old != null && !old.equals(id))
        {
            throw new IllegalArgumentException("both "+id+" and "+old+" makes the same java id "+jid);
        }
        return jid;
    }
708704
public static int getId(Context context, String id, String defType) {
        String type = "R." + defType + ".";
        if (id.startsWith(type)) {
            id = id.substring(type.length());
        }

        Resources r = context.getResources();
        int resId = r.getIdentifier(id, defType,
                context.getPackageName());
        if (resId > 0) {
            return resId;
        } else {
            throw new RuntimeAssertion("Specified resource '%s' could not be found", id);
        }
    }
425166
@Override
	@Transactional
	public String getResource(String id)
	{
		final TemplateCall call = templater.template("resource_template");

		final ResourceTemplateEntity entity = resourceProvisionService.getOrCreateTemplate(id);

		if (entity == null)
			throw new RestException(404, "No such resource with id: " + id);

		call.set("entity", entity);
		call.set("nonce", nonceStore.getValue());

		return call.process();
	}
213994
public static String groupFromResourceId(String id) {
        return (id != null) ? ResourceId.fromString(id).resourceGroupName() : null;
    }
872045
public void deleteById(String id) {
    if (idToVersion.containsKey(id)) {
      String version = idToVersion.remove(id);
      expirationVersion.remove(version);
      versionToItem.remove(version);
      if (collectionCachePath != null
          && !collectionCachePath.resolve(version).toFile().delete()) {
        log.debug("couldn't delete " + version);
      }
    }
  }
672392
function normalize(id, baseId) {
        if (!id) {
            return '';
        }

        baseId = baseId || '';
        var idInfo = parseId(id);
        if (!idInfo) {
            return id;
        }

        var resourceId = idInfo.res;
        var moduleId = relative2absolute(idInfo.mod, baseId);

        // 根据config中的map配置进行module id mapping
        indexRetrieve(
            baseId,
            mappingIdIndex,
            function (value) {
                indexRetrieve(
                    moduleId,
                    value,
                    function (mdValue, mdKey) {
                        moduleId = moduleId.replace(mdKey, mdValue);
                    }
                );
            }
        );

        moduleId = resolvePackageId(moduleId);

        if (resourceId) {
            var mod = modIs(moduleId, MODULE_DEFINED) && actualGlobalRequire(moduleId);
            resourceId = mod && mod.normalize
                ? mod.normalize(
                    resourceId,
                    function (resId) {
                        return normalize(resId, baseId);
                    }
                  )
                : normalize(resourceId, baseId);

            moduleId += '!' + resourceId;
        }

        return moduleId;
    }
717214
public Optional<LinkedResource> getById(String id)
  {
    return Optional.fromNullable(resourcesById.get(id));
  }
229881
function(id) {
    // if the style doesn't exist return null
    var style = this.model.styles[id];
    if (!style) return null;

    // have we built this model before?
    var model = this.index.model[id];
    if (model) return model;

    // build a new model
    model = this.index.model[id] = {};

    // -------------------------------------------------------
    // number format
    if (style.numFmtId) {
      var numFmt = this.index.numFmt[style.numFmtId] || NumFmtXform.getDefaultFmtCode(style.numFmtId);
      if (numFmt) {
        model.numFmt = numFmt;
      }
    }

    function addStyle(name, group, styleId) {
      if (styleId) {
        var part = group[styleId];
        if (part) {
          model[name] = part;
        }
      }
    }

    addStyle('font', this.model.fonts, style.fontId);
    addStyle('border', this.model.borders, style.borderId);
    addStyle('fill', this.model.fills, style.fillId);

    // -------------------------------------------------------
    // alignment
    if (style.alignment) {
      model.alignment = style.alignment;
    }

    return model;
  }
139192
public void setId(String id) {
      if (StringUtils.isNullOrBlank(id)) {
         this.id = UUID.randomUUID().toString();
      } else {
         this.id = id;
      }
   }
757129
function nativeRequire( ids, callback, baseId ) {
        // 根据 https://github.com/amdjs/amdjs-api/wiki/require
        // It MUST throw an error if the module has not
        // already been loaded and evaluated.
        if ( typeof ids === 'string' ) {
            if ( !modIsDefined( ids ) ) {
                throw new Error( '[MODULE_MISS]"' + ids + '" is not exists!' );
            }

            return modGetModuleExports( ids );
        }

        var isCallbackCalled = 0;
        if ( isArray( ids ) ) {
            tryFinishRequire();

            !isCallbackCalled && each(
                ids,
                function ( id ) {
                    if ( !BUILDIN_MODULE[ id ] ) {
                        // 以低优先级触发模式挂载监听器
                        // 循环依赖中能先完成依赖其模块的定义
                        modAddDefinedListener( id, tryFinishRequire, 1 );
                        ( id.indexOf( '!' ) > 0
                            ? loadResource
                            : loadModule
                        )( id, baseId );
                    }
                }
            );
        }

        /**
         * 尝试完成require，调用callback
         * 在模块与其依赖模块都加载完时调用
         *
         * @ignore
         */
        function tryFinishRequire() {
            if ( !isCallbackCalled ) {
                var isAllCompleted = 1;
                each( ids, function ( id ) {
                    if ( !BUILDIN_MODULE[ id ] ) {
                        return ( isAllCompleted = modIsCompleted( id ) );
                    }
                });

                // 检测并调用callback
                if ( isAllCompleted ) {
                    isCallbackCalled = 1;

                    (typeof callback === 'function') && callback.apply(
                        global,
                        modGetModulesExports( ids, BUILDIN_MODULE )
                    );
                }
            }
        }
    }