Skip to content

Commit

Permalink
Relocate absolute paths in SystemJS config file
Browse files Browse the repository at this point in the history
Absolute paths are not affected by changing baseURL, so they must all
be rewritten to be under /base. Closes issue #53
  • Loading branch information
bespokebob committed Oct 21, 2015
1 parent 1e0a147 commit dd1848b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ var initSystemjs = function(config) {
var cfgPath = basePath + kSystemjsConfig.configFile;
var kConfig = readConfigFile(cfgPath);

// Absolute paths for modules should be moved to /base, where Karma serves them
['map', 'paths'].forEach(function(cfgKey) {
if (typeof kConfig[cfgKey] === 'object') {
Object.keys(kConfig[cfgKey]).forEach(function(module) {
if (kConfig[cfgKey][module][0] === '/') {
kConfig[cfgKey][module] = '/base' + kConfig[cfgKey][module];
}
});
}
});

_.merge(kConfig, kSystemjsConfig.config);

kSystemjsConfig.config = kConfig;
Expand Down
7 changes: 7 additions & 0 deletions test/framework.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ describe('initSystemJs', function() {
expect(config.systemjs.config.baseURL).toEqual('abc');
});

it('Relocates absolute paths in config', function() {
config.systemjs.configFile = 'test/systemWithAbsolutePath.conf.js';
initSystemJs(config);
expect(config.systemjs.config.map['jquery']).toEqual('/base/thirdparty/jquery.js');
expect(config.systemjs.config.map['module-a']).toEqual('to-actual-src.js');
});

it('Attaches importPatterns to client.systemjs', function() {
config.files = [{pattern: '/app/**/*.js', included: true}];
initSystemJs(config);
Expand Down
7 changes: 7 additions & 0 deletions test/systemWithAbsolutePath.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
System.config({
baseURL: '/app',
map: {
'module-a': 'to-actual-src.js',
'jquery': '/thirdparty/jquery.js',
}
});

0 comments on commit dd1848b

Please sign in to comment.