This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
220 lines (188 loc) · 8.33 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
(function (global) {
var realRequire, realDefine,
nodeRequire = require,
parentModule = typeof module !== 'undefined' && module.parent,
slice = Array.prototype.slice,
internBase = 'node_modules/intern',
polyfillUrl = '/node_modules/systemjs/dist/system-polyfills.js',
systemJSUrl = '/node_modules/systemjs/dist/system.src.js',
requireQueue = [],
defineQueue = [],
configQueue = [
[{
pluginFirst: true,
baseURL: nodeRequire ? '' : '/',
meta: {
'intern/*': { scriptLoad: true },
'dojo/*': { scriptLoad: true }
},
packages: {
'intern': { format: 'amd', defaultExtension: 'js' },
'dojo': { format: 'amd', defaultExtension: 'js' },
'fbjs': {
main: 'index.js',
defaultExtension: 'js',
},
'react': {
main: 'react.js',
defaultExtension: 'js',
map: {
'object-assign': 'node_modules/object-assign/index.js',
}
}
},
map: {
'dojo': 'node_modules/dojo',
'intern': internBase,
'intern/chai': internBase + '/browser_modules/chai/chai.js',
// These are required for transpiling
'react': 'node_modules/react',
'fbjs': 'node_modules/fbjs',
'systemjs-babel-build': 'node_modules/systemjs-plugin-babel/systemjs-babel-browser.js',
'plugin-babel': 'node_modules/systemjs-plugin-babel/plugin-babel.js'
}
}]
];
function setHooks() {
var normalize = SystemJS.normalize,
hasMap = {
'host-browser': !nodeRequire,
'host-node': !!nodeRequire
};
function has(str) {
return hasMap[str];
}
has.add = function (str, val) {
hasMap[str] = val;
};
// dojo/has is both a function-returning module and a loader-plugin.
// SystemJS doesn't support this, so we need to hack the behavior in.
SystemJS.set('@intern-systemjs-loader:has', System.newModule({ __useDefault: true, default: has, }));
SystemJS.set('@intern-systemjs-loader:undefined', System.newModule({ __useDefault: true }));
SystemJS.set('@intern-systemjs-loader:node', System.newModule({
fetch: function () { return ''; },
instantiate: function (load) {
// Offer a helpful message if someone tries to use this in the browser
if (!parentModule || !parentModule.require) {
throw new ReferenceError('Node require not found (is this a browser?)');
}
return parentModule.require(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 normalizeForIntern (name, parentName, parentAddress) {
var current, split, target,
// Matcher for `dojo/has!foo?bar:baz`, where bar or baz could also be a ternary condition
matcher = /[^?]+(?=\?([^:]+)(?::(.+))?)/,
hook = name.indexOf('dojo/has') === 0
|| name.indexOf('./has') === 0 && parentName.split('/').slice(-2)[0] === 'dojo';
// SystemJS erroneously thinks dojo/request/node is required by dojo/request in the browser even though it's
// hidden by an if statement so the module can support both node and the browser.
// Just point to our export undefined module for now.
if (name.indexOf('./request/node') > -1 && parentName.indexOf('dojo/') > -1) {
return '@intern-systemjs-loader:undefined';
}
if (hook) {
// If a direct request the module, return the one we set earlier
if (name.slice(-4) === '/has') {
return '@intern-systemjs-loader:has';
}
// Loop over the conditions to figure out which module to load (if any)
target = name.slice(name.indexOf('!') + 1);
while (current = matcher.exec(target)) {
target = has(current[0]) ? current[1] : current[2];
}
// Handle relative modules
if (/^\.{1,2}\//.test(target)) {
target = parentName.split('/').slice(0, -1).concat([target])
.join('/').replace(/[^/]+\/\.\.\//, '').replace(/\.\//, '');
}
// Run the result through this normalizer again if required
return target ? normalizeForIntern.call(this, target) : '@intern-systemjs-loader:undefined';
}
// intern/main is the same, it defines some properties but also provides access to the tdd,
// bdd, qunit and object interfaces. We can ignore the module and normalize the
// interfaces to their proper locations.
if (name.indexOf('intern!') === 0) {
return normalize.call(this, internBase + '/lib/interfaces/' + name.split('!')[1] + '.js');
}
// dojo/node!x can be normalized to @node/x
if (/^(?:intern\/)?dojo\/node!/.test(name)) {
return '@intern-systemjs-loader:node!' + name.split('!')[1];
}
return normalize.call(this, name, parentName, parentAddress);
};
}
function loadSystemJS() {
loadScript(systemJSUrl, swapLoader);
}
function loadScript(src, cb) {
var script = document.createElement('script');
script.src = src;
script.onload = cb;
document.body.appendChild(script);
}
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.
global.define = function () {
if (realDefine) {
realDefine.apply(null, arguments);
}
else {
defineQueue.push(slice.call(arguments));
}
};
global.require = function () {
if (realRequire) {
realRequire.apply(null, arguments);
}
else {
requireQueue.push(slice.call(arguments));
}
};
require.config = function () {
configQueue.push(slice.call(arguments));
};
if (nodeRequire) {
// Pre-cache punycode so that global define doesn't break it
// see https://github.com/bestiejs/punycode.js/issues/47
nodeRequire('punycode');
// Require the loader and set global
global.SystemJS = global.System = nodeRequire('systemjs');
// Fix decanonicalize so it doesn't add file:// to intern/ paths
var decanonicalize = System.decanonicalize;
System.decanonicalize = function (name, id) {
var done = decanonicalize.call(this, name, id);
if (/^intern\//.test(name)) {
done = done.replace(/^file:\/\//, '');
}
return done;
};
swapLoader();
}
// Load when.js first if Promise is unavailable
else if (typeof Promise === 'undefined') {
loadScript(polyfillUrl, loadSystemJS);
}
else {
loadSystemJS();
}
})(typeof global !== 'undefined' ? global : window);