mirror of
https://github.com/systemjs/systemjs.git
synced 2026-01-25 14:57:38 +00:00
plugin normalize hook support (#542)
This commit is contained in:
parent
2079aa7ae5
commit
35dcda2d4c
@ -37,15 +37,24 @@
|
||||
return argumentName + '!' + pluginName;
|
||||
}
|
||||
else {
|
||||
return Promise.all([
|
||||
loader.normalize(argumentName, parentName),
|
||||
loader.normalize(pluginName, parentName)
|
||||
])
|
||||
.then(function(normalized) {
|
||||
argumentName = normalized[0];
|
||||
if (defaultExtension && argumentName.substr(argumentName.length - 3, 3) == '.js')
|
||||
argumentName = argumentName.substr(0, argumentName.length - 3);
|
||||
return argumentName + '!' + normalized[1];
|
||||
return loader.normalize(pluginName, parentName)
|
||||
.then(function(_pluginName) {
|
||||
pluginName = _pluginName;
|
||||
var pluginLoader = loader.pluginLoader || loader;
|
||||
return pluginLoader['import'](pluginName)
|
||||
})
|
||||
.then(function(pluginModule) {
|
||||
if (pluginModule.normalize)
|
||||
return pluginModule.normalize(argumentName, parentName);
|
||||
return loader.normalize(argumentName, parentName)
|
||||
.then(function(normalized) {
|
||||
if (defaultExtension && argumentName.substr(argumentName.length - 3, 3) == '.js')
|
||||
return argumentName.substr(0, argumentName.length - 3);
|
||||
return normalized;
|
||||
});
|
||||
})
|
||||
.then(function(argumentName) {
|
||||
return argumentName + '!' + pluginName;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -420,6 +420,13 @@ asyncTest('Advanced compiler plugin', function() {
|
||||
}, err);
|
||||
});
|
||||
|
||||
asyncTest('Plugin normalize hook', function() {
|
||||
System['import']('normalize-test!tests/normalize-plugin.js').then(function(m) {
|
||||
ok(m.name == 'normalize-test');
|
||||
start();
|
||||
}, err);
|
||||
});
|
||||
|
||||
asyncTest('Plugin as a dependency', function() {
|
||||
System.map['css'] = 'tests/css.js';
|
||||
System['import']('tests/cjs-loading-plugin.js').then(function(m) {
|
||||
|
||||
6
test/tests/normalize-plugin.js
Normal file
6
test/tests/normalize-plugin.js
Normal file
@ -0,0 +1,6 @@
|
||||
exports.normalize = function(name, parentName) {
|
||||
return name;
|
||||
};
|
||||
exports.fetch = function(load) {
|
||||
return 'exports.name = "' + load.name.split('!')[0] + '";';
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user