diff options
Diffstat (limited to 'thirdparty/systemjs/lib/cjs-helpers.js')
-rw-r--r-- | thirdparty/systemjs/lib/cjs-helpers.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/thirdparty/systemjs/lib/cjs-helpers.js b/thirdparty/systemjs/lib/cjs-helpers.js new file mode 100644 index 000000000..0ae08d612 --- /dev/null +++ b/thirdparty/systemjs/lib/cjs-helpers.js @@ -0,0 +1,43 @@ +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) + }; + } + })) + }; +});
\ No newline at end of file |