MCPcopy
hub / github.com/nbubna/store / makeModuleMap

Function makeModuleMap

libs/requirejs.js:415–485  ·  view source on GitHub ↗

* Creates a module mapping that includes plugin prefix, module * name, and path. If parentModuleMap is provided it will * also normalize the name via require.normalize() * * @param {String} name the module name * @param {String} [parentModuleMap] parent m

(name, parentModuleMap, isNormalized, applyMap)

Source from the content-addressed store, hash-verified

413 * @returns {Object}
414 */
415 function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
416 var url, pluginModule, suffix, nameParts,
417 prefix = null,
418 parentName = parentModuleMap ? parentModuleMap.name : null,
419 originalName = name,
420 isDefine = true,
421 normalizedName = '';
422
423 //If no name, then it means it is a require call, generate an
424 //internal name.
425 if (!name) {
426 isDefine = false;
427 name = '_@r' + (requireCounter += 1);
428 }
429
430 nameParts = splitPrefix(name);
431 prefix = nameParts[0];
432 name = nameParts[1];
433
434 if (prefix) {
435 prefix = normalize(prefix, parentName, applyMap);
436 pluginModule = getOwn(defined, prefix);
437 }
438
439 //Account for relative paths if there is a base name.
440 if (name) {
441 if (prefix) {
442 if (pluginModule && pluginModule.normalize) {
443 //Plugin is loaded, use its normalize method.
444 normalizedName = pluginModule.normalize(name, function (name) {
445 return normalize(name, parentName, applyMap);
446 });
447 } else {
448 normalizedName = normalize(name, parentName, applyMap);
449 }
450 } else {
451 //A regular module.
452 normalizedName = normalize(name, parentName, applyMap);
453
454 //Normalized name may be a plugin ID due to map config
455 //application in normalize. The map config values must
456 //already be normalized, so do not need to redo that part.
457 nameParts = splitPrefix(normalizedName);
458 prefix = nameParts[0];
459 normalizedName = nameParts[1];
460 isNormalized = true;
461
462 url = context.nameToUrl(normalizedName);
463 }
464 }
465
466 //If the id is a plugin id that cannot be determined if it needs
467 //normalization, stamp it with a unique ID so two matching relative
468 //ids that may conflict can be separate.
469 suffix = prefix && !pluginModule && !isNormalized ?
470 '_unnormalized' + (unnormalizedCounter += 1) :
471 '';
472

Callers 3

newContextFunction · 0.85
callGetModuleFunction · 0.85
localRequireFunction · 0.85

Calls 3

splitPrefixFunction · 0.85
normalizeFunction · 0.85
getOwnFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…