Skip to content

Commit

Permalink
Allow global meta to provide opt-out of package extension adding
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Dec 4, 2015
1 parent c3b5be2 commit 41d08ad
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* // import 'package/index.js' loads in parallel package/lib/test.js,package/vendor/sizzle.js
* './index.js': ['./test'],
* './test.js': ['sizzle']
* }
* }
* }
* };
*
Expand All @@ -57,21 +57,21 @@
*
* In addition, the following modules properties will be allowed to be package
* -relative as well in the package module config:
*
*
* - loader
* - alias
*
*
* Package Configuration Loading
*
*
* Not all packages may already have their configuration present in the System config
* For these cases, a list of packageConfigPaths can be provided, which when matched against
* a request, will first request a ".json" file by the package name to derive the package
* configuration from. This allows dynamic loading of non-predetermined code, a key use
* case in SystemJS.
*
* Example:
*
*
* System.packageConfigPaths = ['packages/test/package.json', 'packages/*.json'];
*
* // will first request 'packages/new-package/package.json' for the package config
Expand All @@ -86,11 +86,11 @@
* The package name itself is taken to be the match up to and including the last wildcard
* or trailing slash.
* Package config paths are ordered - matching is done based on the first match found.
* Any existing package configurations for the package will deeply merge with the
* Any existing package configurations for the package will deeply merge with the
* package config, with the existing package configurations taking preference.
* To opt-out of the package configuration request for a package that matches
* packageConfigPaths, use the { configured: true } package config option.
*
*
*/
(function() {

Expand Down Expand Up @@ -121,7 +121,7 @@

function applyMap(map, name) {
var bestMatch, bestMatchLength = 0;

for (var p in map) {
if (name.substr(0, p.length) == p && (name.length == p.length || name[p.length] == '/')) {
var curMatchLength = p.split('/').length;
Expand All @@ -148,11 +148,11 @@
}

// given the package subpath, return the resultant combined path
// defaultExtension is only added if the path does not have
// defaultExtension is only added if the path does not have
// loader package meta or exact package meta
// We also re-incorporate package-level conditional syntax at this point
// allowing package map and package mains to point to conditionals
// when conditionals are present,
// when conditionals are present,
function toPackagePath(loader, pkgName, pkg, basePath, subPath, sync, isPlugin) {
// skip if its a plugin call already, or we have boolean / interpolation conditional syntax in subPath
var skipExtension = !!(isPlugin || subPath.indexOf('#?') != -1 || subPath.match(interpolationRegEx));
Expand All @@ -164,6 +164,13 @@
skipExtension = true;
});

// exact global meta or meta with any content after the last wildcard skips extension
if (!skipExtension && System.modules)
getMetaMatches(System.modules, pkgName, subPath, function(metaPattern, matchMeta, matchDepth) {
if (matchDepth == 0 || metaPattern.lastIndexOf('*') != metaPattern.length - 1)
skipExtension = true;
});

var normalized = pkgName + '/' + basePath + subPath + (skipExtension ? '' : getDefaultExtension(pkg, subPath));

return sync ? normalized : booleanConditional.call(loader, normalized, pkgName + '/').then(function(name) {
Expand Down Expand Up @@ -216,7 +223,7 @@
return toPackagePath(loader, pkgName, pkg, basePath, mapped.substr(2), sync, isPlugin);
// global package map
else
return (sync ? loader.normalizeSync : loader.normalize).call(loader, mapped);
return (sync ? loader.normalizeSync : loader.normalize).call(loader, mapped);
}

// apply non-environment map match
Expand Down Expand Up @@ -244,7 +251,7 @@

if (!negate && value || negate && !value)
return mapped[e] + subPath.substr(map.length);
}
}
})
.then(function(mapped) {
// no environment match
Expand All @@ -258,11 +265,11 @@
function createPackageNormalize(normalize, sync) {
return function(name, parentName, isPlugin) {
isPlugin = isPlugin === true;

// apply contextual package map first
if (parentName)
var parentPackage = getPackage.call(this, parentName) ||
this.defaultJSExtensions && parentName.substr(parentName.length - 3, 3) == '.js' &&
var parentPackage = getPackage.call(this, parentName) ||
this.defaultJSExtensions && parentName.substr(parentName.length - 3, 3) == '.js' &&
getPackage.call(this, parentName.substr(0, parentName.length - 3));

if (parentPackage) {
Expand Down Expand Up @@ -350,7 +357,7 @@
return pkgBundleLoads.promise;
}
})

// having loaded any bundles, attempt a package resolution now
.then(function() {
return packageResolution(normalized, pkgConfigMatch.pkgName);
Expand Down Expand Up @@ -380,7 +387,7 @@
for (var i = 0; i < loader.packageConfigPaths.length; i++) {
var p = loader.packageConfigPaths[i];
var pPkgLen = Math.max(p.lastIndexOf('*') + 1, p.lastIndexOf('/'));
var match = normalized.match(packageConfigPathsRegExps[p] ||
var match = normalized.match(packageConfigPathsRegExps[p] ||
(packageConfigPathsRegExps[p] = new RegExp('^(' + p.substr(0, pPkgLen).replace(/\*/g, '[^\\/]+') + ')(\/|$)')));
if (match && (!pkgPath || pkgPath == match[1])) {
pkgPath = match[1];
Expand Down Expand Up @@ -502,7 +509,7 @@
var pkg = loader.packages[pkgName];
var basePath = getBasePath(pkg);
var subPath = load.name.substr(pkgName.length + basePath.length + 1);

// format
if (pkg.format)
load.metadata.format = load.metadata.format || pkg.format;
Expand Down Expand Up @@ -542,4 +549,4 @@
};
});

})();
})();

0 comments on commit 41d08ad

Please sign in to comment.