boolean conditional type enforce, isPlugin provided unnecessarily, meta and package config to permit global map

This commit is contained in:
guybedford 2016-02-14 16:02:25 +02:00
parent dd64b11faf
commit 08f798f67f
3 changed files with 19 additions and 9 deletions

View File

@ -71,6 +71,9 @@
else if (typeof m == 'object' && m + '' == 'Module')
m = m['default'];
if (bool && typeof m != 'boolean')
throw new TypeError('Condition ' + serializeCondition(conditionObj) + ' did not resolve to a boolean.');
return conditionObj.negate ? !m : m;
});
}

View File

@ -99,14 +99,20 @@ var nodeCoreModules = ['assert', 'buffer', 'child_process', 'cluster', 'console'
defines the `decanonicalize` function and normalizes everything into
a URL.
*/
function applyMap(name) {
// first run map config
if (name[0] != '.' && name[0] != '/' && !name.match(absURLRegEx)) {
var mapMatch = getMapMatch(this.map, name);
if (mapMatch)
return this.map[mapMatch] + name.substr(mapMatch.length);
}
return name;
}
hook('normalize', function(normalize) {
return function(name, parentName) {
// first run map config
if (name[0] != '.' && name[0] != '/' && !name.match(absURLRegEx)) {
var mapMatch = getMapMatch(this.map, name);
if (mapMatch)
name = this.map[mapMatch] + name.substr(mapMatch.length);
}
name = applyMap.call(this, name);
// dynamically load node-core modules when requiring `@node/fs` for example
if (name.substr(0, 6) == '@node/' && nodeCoreModules.indexOf(name.substr(6)) != -1) {
@ -397,7 +403,7 @@ SystemJSLoader.prototype.config = function(cfg) {
throw new TypeError('"' + p + '" is not a valid package name.');
var defaultJSExtension = loader.defaultJSExtensions && p.substr(p.length - 3, 3) != '.js';
var prop = loader.decanonicalize(p);
var prop = loader.decanonicalize(applyMap(p));
if (defaultJSExtension && prop.substr(prop.length - 3, 3) == '.js')
prop = prop.substr(0, prop.length - 3);
@ -440,7 +446,8 @@ SystemJSLoader.prototype.config = function(cfg) {
loader[c][p] = v[p];
}
else if (c == 'meta') {
loader[c][loader.decanonicalize(p)] = v[p];
// meta can go through global map
loader[c][loader.decanonicalize(applyMap(p))] = v[p];
}
else if (c == 'depCache') {
var defaultJSExtension = loader.defaultJSExtensions && p.substr(p.length - 3, 3) != '.js';

View File

@ -102,7 +102,7 @@
return Promise.all([
loader.normalize(parsed.argument, parentName, true),
loader.normalize(parsed.plugin, parentName, true)
loader.normalize(parsed.plugin, parentName)
])
.then(function(normalized) {
return combinePluginParts(loader, normalized[0], normalized[1], checkDefaultExtension(loader, parsed.argument));