wallet-core/thirdparty/systemjs/lib/cjs-helpers.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

hookConstructor(function(constructor) {
return function() {
var loader = this;
constructor.call(loader);
if (typeof window != 'undefined' && typeof document != 'undefined' && window.location)
var windowOrigin = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
function stripOrigin(path) {
if (path.substr(0, 8) == 'file:///')
return path.substr(7 + !!isWindows);
if (windowOrigin && path.substr(0, windowOrigin.length) == windowOrigin)
return path.substr(windowOrigin.length);
return path;
}
loader.set('@@cjs-helpers', loader.newModule({
requireResolve: function(request, parentId) {
return stripOrigin(loader.normalizeSync(request, parentId));
},
getPathVars: function(moduleId) {
// remove any plugin syntax
var pluginIndex = moduleId.lastIndexOf('!');
var filename;
if (pluginIndex != -1)
filename = moduleId.substr(0, pluginIndex);
else
filename = moduleId;
var dirname = filename.split('/');
dirname.pop();
dirname = dirname.join('/');
return {
filename: stripOrigin(filename),
dirname: stripOrigin(dirname)
};
}
}))
};
});