instead of loader opting out of defaultExtension, let meta handle this

This commit is contained in:
guybedford 2015-09-05 14:27:35 +02:00
parent 70624566c9
commit f8922eecb9

View File

@ -171,14 +171,15 @@
function toPackagePath(pkgName, pkg, basePath, subPath, isPlugin) {
var normalized = pkgName + '/' + basePath + subPath;
var hasLoadMeta = isPlugin;
var hasExtensionMeta = isPlugin;
if (pkg.meta)
getMetaMatches(pkg.meta, basePath, pkgName, normalized, function(matchMeta, matchDepth) {
if (matchMeta.loader || matchDepth == 0)
hasLoadMeta = true;
getMetaMatches(pkg.meta, basePath, pkgName, normalized, function(metaPattern, matchMeta, matchDepth) {
// exact meta or meta with any content after the last wildcard skips extension
if (matchDepth == 0 || metaPattern.lastIndexOf('*') != metaPattern.length - 1)
hasExtensionMeta = true;
});
return normalized + (hasLoadMeta ? '' : getDefaultExtension(pkg, subPath));
return normalized + (hasExtensionMeta ? '' : getDefaultExtension(pkg, subPath));
}
function getDefaultExtension(pkg, subPath) {
@ -380,14 +381,14 @@
if (basePath + module.substr(0, wildcardIndex) === normalized.substr(pkgName.length + 1, wildcardIndex + basePath.length)
&& module.substr(wildcardIndex + 1) === normalized.substr(normalized.length - module.length + wildcardIndex + 1)) {
matchFn(pkgMeta[dotRel + module], module.split('/').length);
matchFn(module, pkgMeta[dotRel + module], module.split('/').length);
}
}
// exact meta
var metaName = normalized.substr(pkgName.length + basePath.length + 1);
var exactMeta = pkgMeta[metaName] || pkgMeta['./' + metaName];
if (exactMeta && normalized.substr(pkgName.length + 1, basePath.length) == basePath)
matchFn(exactMeta, 0);
matchFn(exactMeta, exactMeta, 0);
}
hook('locate', function(locate) {
@ -408,7 +409,7 @@
var meta = {};
if (pkg.meta) {
var bestDepth = 0;
getMetaMatches(pkg.meta, basePath, pkgName, load.name, function(matchMeta, matchDepth) {
getMetaMatches(pkg.meta, basePath, pkgName, load.name, function(metaPattern, matchMeta, matchDepth) {
if (matchDepth > bestDepth)
bestDepth = matchDepth;
extendMeta(meta, matchMeta, matchDepth && bestDepth > matchDepth);