intern-systemjs-loader
Advanced tools
Comparing version 0.0.4 to 0.1.0
82
main.js
@@ -1,8 +0,9 @@ | ||
(function () { | ||
(function (global) { | ||
var realRequire, realDefine, | ||
nodeRequire = require, | ||
slice = Array.prototype.slice, | ||
internBase = '/node_modules/intern', | ||
thisBase = '/node_modules/intern-systemjs-loader', | ||
polyfillUrl = '/node_modules/systemjs/dist/system-polyfills.js', | ||
systemJSUrl = '/node_modules/systemjs/dist/system.src.js', | ||
internBase = 'node_modules/intern', | ||
thisBase = 'node_modules/intern-systemjs-loader', | ||
polyfillUrl = 'node_modules/systemjs/dist/system-polyfills.js', | ||
systemJSUrl = 'node_modules/systemjs/dist/system.src.js', | ||
requireQueue = [], | ||
@@ -13,3 +14,3 @@ defineQueue = [], | ||
pluginFirst: true, | ||
baseURL: '/', | ||
baseURL: nodeRequire ? '' : '/', | ||
meta: { | ||
@@ -34,4 +35,4 @@ 'intern/*': { scriptLoad: true }, | ||
hasMap = { | ||
'host-browser': true, | ||
'host-node': false | ||
'host-browser': !nodeRequire, | ||
'host-node': !!nodeRequire | ||
}; | ||
@@ -51,6 +52,10 @@ | ||
SystemJS.set('@intern-systemjs-loader:undefined', System.newModule({ __useDefault: true })); | ||
SystemJS.set('@intern-systemjs-loader:node', System.newModule({ | ||
fetch: function () { return ''; }, | ||
instantiate: function (load) { return nodeRequire(load.address); } | ||
})); | ||
// Normalize "dojo/has" to either our hasPlugin or hasModule GUIDs depending on whether it's | ||
// required as a loader plugin or a module. | ||
SystemJS.normalize = function (name, parentName, parentAddress) { | ||
SystemJS.normalize = function normalizeForIntern (name, parentName, parentAddress) { | ||
var current, split, target, | ||
@@ -87,3 +92,4 @@ // Matcher for `dojo/has!foo?bar:baz`, where bar or baz could also be a ternary condition | ||
return target ? normalize.call(this, target) : '@intern-systemjs-loader:undefined'; | ||
// Run the result through this normalizer again if required | ||
return target ? normalizeForIntern.call(this, target) : '@intern-systemjs-loader:undefined'; | ||
} | ||
@@ -98,2 +104,7 @@ | ||
// dojo/node!x can be normalized to @node/x | ||
if (name.indexOf('dojo/node!') === 0) { | ||
return '@intern-systemjs-loader:node!' + name.split('!')[1]; | ||
} | ||
return normalize.call(this, name, parentName, parentAddress); | ||
@@ -105,20 +116,3 @@ }; | ||
function loadSystemJS() { | ||
loadScript(systemJSUrl, function () { | ||
window.require = realRequire = System.amdRequire; | ||
window.define = realDefine = System.amdDefine; | ||
require.config = System.config.bind(System); | ||
setHooks(); | ||
// Flush any queues that were populated before SystemJS finished loading | ||
while (configQueue.length) { | ||
System.config.apply(System, configQueue.shift()); | ||
} | ||
while (defineQueue.length) { | ||
realDefine.apply(null, defineQueue.shift()); | ||
} | ||
while (requireQueue.length) { | ||
realRequire.apply(null, requireQueue.shift()); | ||
} | ||
}); | ||
loadScript(systemJSUrl, swapLoader); | ||
} | ||
@@ -135,5 +129,25 @@ | ||
function swapLoader() { | ||
global.require = realRequire = System.amdRequire; | ||
global.define = realDefine = System.amdDefine; | ||
realRequire.config = System.config.bind(System); | ||
realRequire.nodeRequire = nodeRequire; | ||
setHooks(); | ||
// Flush any queues that were populated before SystemJS finished loading | ||
while (configQueue.length) { | ||
System.config.apply(System, configQueue.shift()); | ||
} | ||
while (defineQueue.length) { | ||
realDefine.apply(null, defineQueue.shift()); | ||
} | ||
while (requireQueue.length) { | ||
realRequire.apply(null, requireQueue.shift()); | ||
} | ||
} | ||
// Provide the initial define, require and config functions. These just push the arguments to | ||
// arrays so they can be recalled when SystemJS has finished loading. | ||
window.define = function () { | ||
global.define = function () { | ||
if (realDefine) { | ||
@@ -147,3 +161,3 @@ realDefine.apply(null, arguments); | ||
window.require = function () { | ||
global.require = function () { | ||
if (realRequire) { | ||
@@ -161,4 +175,8 @@ realRequire.apply(null, arguments); | ||
if (nodeRequire) { | ||
global.SystemJS = global.System = nodeRequire('systemjs'); | ||
swapLoader(); | ||
} | ||
// Load when.js first if Promise is unavailable | ||
if (typeof Promise === 'undefined') { | ||
else if (typeof Promise === 'undefined') { | ||
loadScript(polyfillUrl, loadSystemJS); | ||
@@ -169,2 +187,2 @@ } | ||
} | ||
})(); | ||
})(typeof global !== 'undefined' ? global : window); |
{ | ||
"name": "intern-systemjs-loader", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "A wrapper for using SystemJS as Intern's loader", | ||
@@ -8,3 +8,4 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "phantomjs --remote-debugger-port=9001 --webdriver=4444 & ./node_modules/.bin/intern-runner config=tests/local.intern", | ||
"testClient": "./node_modules/.bin/intern-client config=tests/local.intern" | ||
}, | ||
@@ -22,3 +23,7 @@ "keywords": [ | ||
"systemjs": "^0.19.27" | ||
}, | ||
"devDependencies": { | ||
"intern": "^3.2.0", | ||
"systemjs-plugin-babel": "0.0.10" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
43637
12
644
2
2
2
1