fix map configuration double slashing bug

This commit is contained in:
guybedford 2017-03-09 15:17:54 +02:00
parent c9cccd18d4
commit 720aa9e4e5
2 changed files with 38 additions and 3 deletions

View File

@ -149,12 +149,17 @@ export function setConfig (cfg, isEnvConfig) {
var v = cfg.map[p];
if (typeof v === 'string') {
config.map[p] = coreResolve.call(loader, config, v, undefined, false, false);
var mapped = coreResolve.call(loader, config, v, undefined, false, false);
if (mapped[mapped.length -1] === '/' && p[p.length - 1] !== ':' && p[p.length - 1] !== '/')
mapped = mapped.substr(0, mapped.length - 1);
config.map[p] = mapped;
}
// object map
else {
var pkgName = coreResolve.call(loader, config, p, undefined, true, true);
var pkgName = coreResolve.call(loader, config, p[p.length - 1] !== '/' ? p + '/' : p, undefined, true, true);
pkgName = pkgName.substr(0, pkgName.length - 1);
var pkg = config.packages[pkgName];
if (!pkg) {
pkg = config.packages[pkgName] = createPackage();
@ -191,7 +196,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, true);
var pkgName = coreResolve.call(loader, config, p[p.length - 1] !== '/' ? p + '/' : p, undefined, true, true);
pkgName = pkgName.substr(0, pkgName.length - 1);
setPkgConfig(config.packages[pkgName] = config.packages[pkgName] || createPackage(), cfg.packages[p], pkgName, false, config);

View File

@ -316,6 +316,23 @@ suite('SystemJS Standard Tests', function() {
});
});
test('Relative map and package config', function () {
System.config({
map: {
helloworld: './'
},
packages: {
helloworld: {
main: './helloworld.js'
}
}
});
return System.normalize('helloworld').then(function (normalized) {
ok(normalized.substr(normalized.length - 18, 18) === 'test/helloworld.js');
});
});
test('Package with json loader', function () {
System.config({
paths: {
@ -419,6 +436,17 @@ suite('SystemJS Standard Tests', function() {
});
test('Loading an AMD bundle', function () {
System.config({
map: {
helloworld: './'
},
packages: {
helloworld: {
main: './helloworld.js',
defaultExtension: false
}
}
});
System.config({
bundles: {
'tests/amd-bundle.js': ['bundle-*']
@ -591,6 +619,8 @@ suite('SystemJS Standard Tests', function() {
test('CommonJS require.resolve', function () {
return System.import('tests/cjs-resolve.js').then(function (m) {
console.log(':' + m);
console.log(m.substr(m.length - 12, 12));
ok(m.substr(m.length - 12, 12) == 'test/tests/a');
});
})