fix pathing regression

This commit is contained in:
guybedford 2017-01-31 08:38:08 +02:00
parent ee90da148f
commit d1bdd5d150
3 changed files with 38 additions and 14 deletions

View File

@ -147,12 +147,12 @@ export function setConfig (cfg, isEnvConfig) {
var v = cfg.map[p];
if (typeof v === 'string') {
config.map[p] = coreResolve.call(loader, config, v, undefined, false);
config.map[p] = coreResolve.call(loader, config, v, undefined, false, false);
}
// object map
else {
var pkgName = coreResolve.call(loader, config, p, undefined, true);
var pkgName = coreResolve.call(loader, config, p, undefined, true, true);
var pkg = config.packages[pkgName];
if (!pkg) {
pkg = config.packages[pkgName] = createPackage();
@ -169,7 +169,7 @@ export function setConfig (cfg, isEnvConfig) {
for (var i = 0; i < cfg.packageConfigPaths.length; i++) {
var path = cfg.packageConfigPaths[i];
var packageLength = Math.max(path.lastIndexOf('*') + 1, path.lastIndexOf('/'));
var normalized = coreResolve.call(loader, config, path.substr(0, packageLength), undefined, false);
var normalized = coreResolve.call(loader, config, path.substr(0, packageLength), undefined, false, false);
packageConfigPaths[i] = normalized + path.substr(packageLength);
}
config.packageConfigPaths = packageConfigPaths;
@ -189,8 +189,7 @@ export function setConfig (cfg, isEnvConfig) {
if (p.match(/^([^\/]+:)?\/\/$/))
throw new TypeError('"' + p + '" is not a valid package name.');
var pkgName = coreResolve.call(loader, config, p[p.length -1] !== '/' ? p + '/' : p, undefined, true);
pkgName = pkgName.substr(0, pkgName.length - 1);
var pkgName = coreResolve.call(loader, config, p, undefined, true, true);
setPkgConfig(config.packages[pkgName] = config.packages[pkgName] || createPackage(), cfg.packages[p], pkgName, false, config);
}
@ -208,7 +207,7 @@ export function setConfig (cfg, isEnvConfig) {
extend(config.meta[p] = config.meta[p] || {}, cfg.meta[p]);
}
else {
var resolved = coreResolve.call(loader, config, p, undefined, true);
var resolved = coreResolve.call(loader, config, p, undefined, true, true);
extend(config.meta[resolved] = config.meta[resolved] || {}, cfg.meta[p]);
}
}

View File

@ -152,10 +152,10 @@ export function decanonicalize (config, key) {
// plugin
if (parsed) {
var pluginKey = decanonicalize.call(this, config, parsed.plugin);
return combinePluginParts(config.pluginFirst, coreResolve.call(this, config, parsed.argument, undefined, false), pluginKey);
return combinePluginParts(config.pluginFirst, coreResolve.call(this, config, parsed.argument, undefined, false, false), pluginKey);
}
return coreResolve.call(this, config, key, undefined, false);
return coreResolve.call(this, config, key, undefined, false, false);
}
export function normalizeSync (key, parentKey) {
@ -178,7 +178,7 @@ export function normalizeSync (key, parentKey) {
return packageResolveSync.call(this, config, key, parentMetadata.pluginArgument || parentKey, metadata, parentMetadata, !!metadata.pluginKey);
}
export function coreResolve (config, key, parentKey, doMap) {
export function coreResolve (config, key, parentKey, doMap, packageName) {
var relativeResolved = resolveIfNotPlain(key, parentKey || baseURI);
// standard URL resolution
@ -204,7 +204,11 @@ export function coreResolve (config, key, parentKey, doMap) {
if (key.substr(0, 6) === '@node/')
return key;
return applyPaths(config.baseURL, config.paths, key);
var trailingSlash = packageName && key[key.length - 1] !== '/';
var resolved = applyPaths(config.baseURL, config.paths, trailingSlash ? key + '/' : key);
if (trailingSlash)
return resolved.substr(0, resolved.length - 1);
return resolved;
}
function packageResolveSync (config, key, parentKey, metadata, parentMetadata, skipExtensions) {
@ -220,7 +224,10 @@ function packageResolveSync (config, key, parentKey, metadata, parentMetadata, s
}
}
var normalized = coreResolve.call(this, config, key, parentKey, true);
var trailingSlash = key[key.length - 1] === '/';
var normalized = coreResolve.call(this, config, trailingSlash ? key : key + '/', parentKey, true, true);
if (!trailingSlash)
normalized = normalized.substr(0, normalized.length - 1);
var pkgConfigMatch = getPackageConfigMatch(config, normalized);
metadata.packageKey = pkgConfigMatch && pkgConfigMatch.packageKey || getMapMatch(config.packages, normalized);
@ -261,7 +268,7 @@ function packageResolve (config, key, parentKey, metadata, parentMetadata, skipE
return mapped;
// apply map, core, paths, contextual package map
var normalized = coreResolve.call(loader, config, key, parentKey, true);
var normalized = coreResolve.call(loader, config, key, parentKey, true, true);
var pkgConfigMatch = getPackageConfigMatch(config, normalized);
metadata.packageKey = pkgConfigMatch && pkgConfigMatch.packageKey || getMapMatch(config.packages, normalized);

View File

@ -234,7 +234,7 @@ suite('SystemJS Standard Tests', function() {
}
});
var base = System.resolveSync('');
var base = System.resolveSync('./');
return Promise.all([
System.resolve('a'),
@ -250,7 +250,7 @@ suite('SystemJS Standard Tests', function() {
ok(a[1] === base + 'c/b');
ok(a[2] === base + 'b/b');
ok(a[3] === base + 'd/c');
ok(a[4] === base + 'b');
ok(a[4] === base + 'd');
ok(a[5] === 'http://jquery.com/jquery.js');
ok(a[6] === 'http://jquery.com/jquery.js/c');
ok(a[7] === 'https://another.com/x');
@ -1123,6 +1123,24 @@ suite('SystemJS Standard Tests', function() {
})
});
test('Package configuration main normalization', function () {
SystemJS.config({
paths: {
"npm:": "jspm_packages/npm/",
"app/": "src/"
},
packages: {
"app": {
"format": "system",
"main": "index.js"
}
}
});
console.log(System.normalizeSync('app'));
ok(System.normalizeSync('app') === System.baseURL + 'src/index.js');
});
test('esModule meta option', function () {
System.config({
meta: {