From f8922eecb9a3dc6aa766eb2e7967b2cd8db0def6 Mon Sep 17 00:00:00 2001 From: guybedford Date: Sat, 5 Sep 2015 14:27:35 +0200 Subject: [PATCH] instead of loader opting out of defaultExtension, let meta handle this --- lib/package.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/package.js b/lib/package.js index 403b2093..18536694 100644 --- a/lib/package.js +++ b/lib/package.js @@ -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);