devfab 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +512 -290
- package/dist/common/models.esm.js +2 -2
- package/dist/common/models.js +2 -2
- package/dist/common/require.esm.js +5 -0
- package/dist/common/require.js +5 -0
- package/dist/common/utils.esm.js +3 -1
- package/dist/common/utils.js +3 -1
- package/dist/index.esm.js +6 -2
- package/dist/index.js +6 -2
- package/dist/index.umd.js +6 -2
- package/dist/react/index.js +1 -1
- package/dist/vue/vue3-adapter.esm.js +1 -1
- package/dist/vue/vue3-adapter.js +1 -1
- package/lib/devfab.js +4475 -2339
- package/lib/devfab.min.js +6 -2
- package/lib/devfab.require.js +3285 -0
- package/lib/devfab.require.min.js +5 -0
- package/package.json +83 -78
- package/dist/react/_virtual/_rollupPluginBabelHelpers.js +0 -3
- package/dist/react/adapter/common/dataSourceAdapter.js +0 -1
- package/dist/react/adapter/common/labelAdapter.js +0 -1
- package/dist/react/adapter/common/loadMetaAdapter.js +0 -1
- package/dist/react/adapter/common/refAdapter.js +0 -1
- package/dist/react/adapter/index.js +0 -1
- package/dist/react/adapter/model/dataSourceAdapter.js +0 -1
- package/dist/react/adapter/model/filterAdapter.js +0 -1
- package/dist/react/adapter/model/modelAdapter.js +0 -1
- package/dist/react/adapter/model/pageAdapter.js +0 -1
- package/lib/requirejs.js +0 -2473
package/lib/requirejs.js
DELETED
|
@@ -1,2473 +0,0 @@
|
|
|
1
|
-
// ======================================================
|
|
2
|
-
/** vim: et:ts=4:sw=4:sts=4
|
|
3
|
-
* @license RequireJS 2.3.2 Copyright jQuery Foundation and other contributors.
|
|
4
|
-
* Released under MIT license, https://github.com/requirejs/requirejs/blob/master/LICENSE
|
|
5
|
-
*/
|
|
6
|
-
// Not using strict: uneven strict support in browsers, #392, and causes
|
|
7
|
-
// problems with requirejs.exec()/transpiler plugins that may not be strict.
|
|
8
|
-
/* jslint regexp: true, nomen: true, sloppy: true */
|
|
9
|
-
/* global window, navigator, document, importScripts, setTimeout, opera */
|
|
10
|
-
var __requirejs, __require, __define
|
|
11
|
-
;(function (global, setTimeout) {
|
|
12
|
-
var requirejs, require, define
|
|
13
|
-
var req
|
|
14
|
-
var s
|
|
15
|
-
var head
|
|
16
|
-
var baseElement
|
|
17
|
-
var dataMain
|
|
18
|
-
var src
|
|
19
|
-
var body
|
|
20
|
-
var interactiveScript
|
|
21
|
-
var currentlyAddingScript
|
|
22
|
-
var mainScript
|
|
23
|
-
var subPath
|
|
24
|
-
var version = '2.3.2'
|
|
25
|
-
var commentRegExp = /\/\*[\s\S]*?\*\/|([^:"'=]|^)\/\/.*$/gm
|
|
26
|
-
var cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g
|
|
27
|
-
var jsSuffixRegExp = /\.js$/
|
|
28
|
-
var currDirRegExp = /^\.\//
|
|
29
|
-
var op = Object.prototype
|
|
30
|
-
var ostring = op.toString
|
|
31
|
-
var hasOwn = op.hasOwnProperty
|
|
32
|
-
var isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document)
|
|
33
|
-
var isWebWorker = !isBrowser && typeof importScripts !== 'undefined'
|
|
34
|
-
// PS3 indicates loaded and complete, but need to wait for complete
|
|
35
|
-
// specifically. Sequence is 'loading', 'loaded', execution,
|
|
36
|
-
// then 'complete'. The UA check is unfortunate, but not sure how
|
|
37
|
-
// to feature test w/o causing perf issues.
|
|
38
|
-
var readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ? /^complete$/ : /^(complete|loaded)$/
|
|
39
|
-
var defContextName = '_'
|
|
40
|
-
// Oh the tragedy, detecting opera. See the usage of isOpera for reason.
|
|
41
|
-
var isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]'
|
|
42
|
-
var contexts = {}
|
|
43
|
-
var cfg = {}
|
|
44
|
-
var globalDefQueue = []
|
|
45
|
-
var useInteractive = false
|
|
46
|
-
|
|
47
|
-
// Could match something like ')//comment', do not lose the prefix to comment.
|
|
48
|
-
function commentReplace(match, singlePrefix) {
|
|
49
|
-
return singlePrefix || ''
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function isFunction(it) {
|
|
53
|
-
return ostring.call(it) === '[object Function]'
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function isArray(it) {
|
|
57
|
-
return ostring.call(it) === '[object Array]'
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Helper function for iterating over an array. If the func returns
|
|
62
|
-
* a true value, it will break out of the loop.
|
|
63
|
-
*/
|
|
64
|
-
function each(ary, func) {
|
|
65
|
-
if (ary) {
|
|
66
|
-
var i
|
|
67
|
-
for (i = 0; i < ary.length; i += 1) {
|
|
68
|
-
// checkmark:disable-line
|
|
69
|
-
if (ary[i] && func(ary[i], i, ary)) {
|
|
70
|
-
break
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Helper function for iterating over an array backwards. If the func
|
|
78
|
-
* returns a true value, it will break out of the loop.
|
|
79
|
-
*/
|
|
80
|
-
function eachReverse(ary, func) {
|
|
81
|
-
if (ary) {
|
|
82
|
-
var i
|
|
83
|
-
for (i = ary.length - 1; i > -1; i -= 1) {
|
|
84
|
-
if (ary[i] && func(ary[i], i, ary)) {
|
|
85
|
-
break
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function hasProp(obj, prop) {
|
|
92
|
-
return hasOwn.call(obj, prop)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function getOwn(obj, prop) {
|
|
96
|
-
return hasProp(obj, prop) && obj[prop]
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Cycles over properties in an object and calls a function for each
|
|
101
|
-
* property value. If the function returns a truthy value, then the
|
|
102
|
-
* iteration is stopped.
|
|
103
|
-
*/
|
|
104
|
-
function eachProp(obj, func) {
|
|
105
|
-
var prop
|
|
106
|
-
for (prop in obj) {
|
|
107
|
-
if (hasProp(obj, prop)) {
|
|
108
|
-
if (func(obj[prop], prop)) {
|
|
109
|
-
break
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Simple function to mix in properties from source into target,
|
|
117
|
-
* but only if target does not already have a property of the same name.
|
|
118
|
-
*/
|
|
119
|
-
function mixin(target, source, force, deepStringMixin) {
|
|
120
|
-
if (source) {
|
|
121
|
-
eachProp(source, function (value, prop) {
|
|
122
|
-
if (force || !hasProp(target, prop)) {
|
|
123
|
-
if (deepStringMixin && typeof value === 'object' && value && !isArray(value) && !isFunction(value) && !(value instanceof RegExp)) {
|
|
124
|
-
if (!target[prop]) {
|
|
125
|
-
target[prop] = {}
|
|
126
|
-
}
|
|
127
|
-
mixin(target[prop], value, force, deepStringMixin)
|
|
128
|
-
} else {
|
|
129
|
-
target[prop] = value
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
return target
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Similar to Function.prototype.bind, but the 'this' object is specified
|
|
138
|
-
// first, since it is easier to read/figure out what 'this' will be.
|
|
139
|
-
function bind(obj, fn) {
|
|
140
|
-
return function () {
|
|
141
|
-
return fn.apply(obj, arguments)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function scripts() {
|
|
146
|
-
return document.getElementsByTagName('script')
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function defaultOnError(err) {
|
|
150
|
-
throw err
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Allow getting a global that is expressed in
|
|
154
|
-
// dot notation, like 'a.b.c'.
|
|
155
|
-
function getGlobal(value) {
|
|
156
|
-
if (!value) {
|
|
157
|
-
return value
|
|
158
|
-
}
|
|
159
|
-
var g = global
|
|
160
|
-
each(value.split('.'), function (part) {
|
|
161
|
-
g = g[part]
|
|
162
|
-
})
|
|
163
|
-
return g
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Constructs an error with a pointer to an URL with more information.
|
|
168
|
-
* @param {String} id the error ID that maps to an ID on a web page.
|
|
169
|
-
* @param {String} message human readable error.
|
|
170
|
-
* @param {Error} [err] the original error, if there is one.
|
|
171
|
-
*
|
|
172
|
-
* @returns {Error}
|
|
173
|
-
*/
|
|
174
|
-
function makeError(id, msg, err, requireModules) {
|
|
175
|
-
var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id)
|
|
176
|
-
e.requireType = id
|
|
177
|
-
e.requireModules = requireModules
|
|
178
|
-
if (err) {
|
|
179
|
-
e.originalError = err
|
|
180
|
-
}
|
|
181
|
-
return e
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (typeof define !== 'undefined') {
|
|
185
|
-
// If a define is already in play via another AMD loader,
|
|
186
|
-
// do not overwrite.
|
|
187
|
-
return
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (typeof requirejs !== 'undefined') {
|
|
191
|
-
if (isFunction(requirejs)) {
|
|
192
|
-
// Do not overwrite an existing requirejs instance.
|
|
193
|
-
return
|
|
194
|
-
}
|
|
195
|
-
cfg = requirejs
|
|
196
|
-
requirejs = undefined
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Allow for a require config object
|
|
200
|
-
if (typeof require !== 'undefined' && !isFunction(require)) {
|
|
201
|
-
// assume it is a config object.
|
|
202
|
-
cfg = require
|
|
203
|
-
require = undefined
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function newContext(contextName, contextOptions = {}) {
|
|
207
|
-
var inCheckLoaded
|
|
208
|
-
var Module
|
|
209
|
-
var context
|
|
210
|
-
var handlers
|
|
211
|
-
var checkLoadedTimeoutId
|
|
212
|
-
var config = {
|
|
213
|
-
// Defaults. Do not set a default for map
|
|
214
|
-
// config to speed up normalize(), which
|
|
215
|
-
// will run faster if there is no default.
|
|
216
|
-
waitSeconds: contextOptions.waitSeconds || 30,
|
|
217
|
-
baseUrl: './',
|
|
218
|
-
paths: {},
|
|
219
|
-
bundles: {},
|
|
220
|
-
pkgs: {},
|
|
221
|
-
shim: {},
|
|
222
|
-
config: {},
|
|
223
|
-
}
|
|
224
|
-
var registry = {}
|
|
225
|
-
// registry of just enabled modules, to speed
|
|
226
|
-
// cycle breaking code when lots of modules
|
|
227
|
-
// are registered, but not activated.
|
|
228
|
-
var enabledRegistry = {}
|
|
229
|
-
var undefEvents = {}
|
|
230
|
-
var defQueue = []
|
|
231
|
-
var defined = {}
|
|
232
|
-
var urlFetched = {}
|
|
233
|
-
var bundlesMap = {}
|
|
234
|
-
var requireCounter = 1
|
|
235
|
-
var unnormalizedCounter = 1
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Trims the . and .. from an array of path segments.
|
|
239
|
-
* It will keep a leading path segment if a .. will become
|
|
240
|
-
* the first path segment, to help with module name lookups,
|
|
241
|
-
* which act like paths, but can be remapped. But the end result,
|
|
242
|
-
* all paths that use this function should look normalized.
|
|
243
|
-
* NOTE: this method MODIFIES the input array.
|
|
244
|
-
* @param {Array} ary the array of path segments.
|
|
245
|
-
*/
|
|
246
|
-
function trimDots(ary) {
|
|
247
|
-
var i, part
|
|
248
|
-
for (i = 0; i < ary.length; i++) {
|
|
249
|
-
part = ary[i]
|
|
250
|
-
if (part === '.') {
|
|
251
|
-
ary.splice(i, 1)
|
|
252
|
-
i -= 1
|
|
253
|
-
} else if (part === '..') {
|
|
254
|
-
// If at the start, or previous value is still ..,
|
|
255
|
-
// keep them so that when converted to a path it may
|
|
256
|
-
// still work when converted to a path, even though
|
|
257
|
-
// as an ID it is less than ideal. In larger point
|
|
258
|
-
// releases, may be better to just kick out an error.
|
|
259
|
-
if (i === 0 || (i === 1 && ary[2] === '..') || ary[i - 1] === '..') {
|
|
260
|
-
continue
|
|
261
|
-
} else if (i > 0) {
|
|
262
|
-
ary.splice(i - 1, 2)
|
|
263
|
-
i -= 2
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Given a relative module name, like ./something, normalize it to
|
|
271
|
-
* a real name that can be mapped to a path.
|
|
272
|
-
* @param {String} name the relative name
|
|
273
|
-
* @param {String} baseName a real name that the name arg is relative
|
|
274
|
-
* to.
|
|
275
|
-
* @param {Boolean} applyMap apply the map config to the value. Should
|
|
276
|
-
* only be done if this normalization is for a dependency ID.
|
|
277
|
-
* @returns {String} normalized name
|
|
278
|
-
*/
|
|
279
|
-
function normalize(name, baseName, applyMap) {
|
|
280
|
-
var pkgMain
|
|
281
|
-
var mapValue
|
|
282
|
-
var nameParts
|
|
283
|
-
var i
|
|
284
|
-
var j
|
|
285
|
-
var nameSegment
|
|
286
|
-
var lastIndex
|
|
287
|
-
var foundMap
|
|
288
|
-
var foundI
|
|
289
|
-
var foundStarMap
|
|
290
|
-
var starI
|
|
291
|
-
var normalizedBaseParts
|
|
292
|
-
var baseParts = baseName && baseName.split('/')
|
|
293
|
-
var map = config.map
|
|
294
|
-
var starMap = map && map['*']
|
|
295
|
-
|
|
296
|
-
// Adjust any relative paths.
|
|
297
|
-
if (name) {
|
|
298
|
-
name = name.split('/')
|
|
299
|
-
lastIndex = name.length - 1
|
|
300
|
-
|
|
301
|
-
// If wanting node ID compatibility, strip .js from end
|
|
302
|
-
// of IDs. Have to do this here, and not in nameToUrl
|
|
303
|
-
// because node allows either .js or non .js to map
|
|
304
|
-
// to same file.
|
|
305
|
-
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
|
|
306
|
-
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '')
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Starts with a '.' so need the baseName
|
|
310
|
-
if (name[0].charAt(0) === '.' && baseParts) {
|
|
311
|
-
// Convert baseName to array, and lop off the last part,
|
|
312
|
-
// so that . matches that 'directory' and not name of the baseName's
|
|
313
|
-
// module. For instance, baseName of 'one/two/three', maps to
|
|
314
|
-
// 'one/two/three.js', but we want the directory, 'one/two' for
|
|
315
|
-
// this normalization.
|
|
316
|
-
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1)
|
|
317
|
-
name = normalizedBaseParts.concat(name)
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
trimDots(name)
|
|
321
|
-
name = name.join('/')
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// Apply map config if available.
|
|
325
|
-
if (applyMap && map && (baseParts || starMap)) {
|
|
326
|
-
nameParts = name.split('/')
|
|
327
|
-
|
|
328
|
-
for (i = nameParts.length; i > 0; i -= 1) {
|
|
329
|
-
nameSegment = nameParts.slice(0, i).join('/')
|
|
330
|
-
|
|
331
|
-
if (baseParts) {
|
|
332
|
-
// Find the longest baseName segment match in the config.
|
|
333
|
-
// So, do joins on the biggest to smallest lengths of baseParts.
|
|
334
|
-
let shouldBreakOuterLoop = false
|
|
335
|
-
for (j = baseParts.length; j > 0; j -= 1) {
|
|
336
|
-
mapValue = getOwn(map, baseParts.slice(0, j).join('/'))
|
|
337
|
-
|
|
338
|
-
// baseName segment has config, find if it has one for
|
|
339
|
-
// this name.
|
|
340
|
-
if (mapValue) {
|
|
341
|
-
mapValue = getOwn(mapValue, nameSegment)
|
|
342
|
-
if (mapValue) {
|
|
343
|
-
// Match, update name to the new value.
|
|
344
|
-
foundMap = mapValue
|
|
345
|
-
foundI = i
|
|
346
|
-
shouldBreakOuterLoop = true
|
|
347
|
-
break
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (shouldBreakOuterLoop) {
|
|
352
|
-
break
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// Check for a star map match, but just hold on to it,
|
|
357
|
-
// if there is a shorter segment match later in a matching
|
|
358
|
-
// config, then favor over this star map.
|
|
359
|
-
if (!foundStarMap && starMap && getOwn(starMap, nameSegment)) {
|
|
360
|
-
foundStarMap = getOwn(starMap, nameSegment)
|
|
361
|
-
starI = i
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (!foundMap && foundStarMap) {
|
|
366
|
-
foundMap = foundStarMap
|
|
367
|
-
foundI = starI
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
if (foundMap) {
|
|
371
|
-
nameParts.splice(0, foundI, foundMap)
|
|
372
|
-
name = nameParts.join('/')
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// If the name points to a package's name, use
|
|
377
|
-
// the package main instead.
|
|
378
|
-
pkgMain = getOwn(config.pkgs, name)
|
|
379
|
-
|
|
380
|
-
return pkgMain || name
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
function removeScript(name) {
|
|
384
|
-
if (isBrowser) {
|
|
385
|
-
each(scripts(), function (scriptNode) {
|
|
386
|
-
if (scriptNode.getAttribute('data-requiremodule') === name && scriptNode.getAttribute('data-requirecontext') === context.contextName) {
|
|
387
|
-
scriptNode.parentNode.removeChild(scriptNode)
|
|
388
|
-
return true
|
|
389
|
-
}
|
|
390
|
-
})
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
function hasPathFallback(id) {
|
|
395
|
-
var pathConfig = getOwn(config.paths, id)
|
|
396
|
-
if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
|
|
397
|
-
// Pop off the first array value, since it failed, and
|
|
398
|
-
// retry
|
|
399
|
-
pathConfig.shift()
|
|
400
|
-
context.require.undef(id)
|
|
401
|
-
|
|
402
|
-
// Custom require that does not do map translation, since
|
|
403
|
-
// ID is "absolute", already mapped/resolved.
|
|
404
|
-
context.makeRequire(null, {
|
|
405
|
-
skipMap: true,
|
|
406
|
-
})([id])
|
|
407
|
-
|
|
408
|
-
return true
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// Turns a plugin!resource to [plugin, resource]
|
|
413
|
-
// with the plugin being undefined if the name
|
|
414
|
-
// did not have a plugin prefix.
|
|
415
|
-
function splitPrefix(name) {
|
|
416
|
-
var prefix
|
|
417
|
-
var index = name ? name.indexOf('!') : -1
|
|
418
|
-
if (index > -1) {
|
|
419
|
-
prefix = name.substring(0, index)
|
|
420
|
-
name = name.substring(index + 1, name.length)
|
|
421
|
-
}
|
|
422
|
-
return [prefix, name]
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Creates a module mapping that includes plugin prefix, module
|
|
427
|
-
* name, and path. If parentModuleMap is provided it will
|
|
428
|
-
* also normalize the name via require.normalize()
|
|
429
|
-
*
|
|
430
|
-
* @param {String} name the module name
|
|
431
|
-
* @param {String} [parentModuleMap] parent module map
|
|
432
|
-
* for the module name, used to resolve relative names.
|
|
433
|
-
* @param {Boolean} isNormalized: is the ID already normalized.
|
|
434
|
-
* This is true if this call is done for a define() module ID.
|
|
435
|
-
* @param {Boolean} applyMap: apply the map config to the ID.
|
|
436
|
-
* Should only be true if this map is for a dependency.
|
|
437
|
-
*
|
|
438
|
-
* @returns {Object}
|
|
439
|
-
*/
|
|
440
|
-
function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
|
|
441
|
-
var url
|
|
442
|
-
var pluginModule
|
|
443
|
-
var suffix
|
|
444
|
-
var nameParts
|
|
445
|
-
var prefix = null
|
|
446
|
-
var parentName = parentModuleMap ? parentModuleMap.name : null
|
|
447
|
-
var originalName = name
|
|
448
|
-
var isDefine = true
|
|
449
|
-
var normalizedName = ''
|
|
450
|
-
|
|
451
|
-
// If no name, then it means it is a require call, generate an
|
|
452
|
-
// internal name.
|
|
453
|
-
if (!name) {
|
|
454
|
-
isDefine = false
|
|
455
|
-
name = '_@r' + (requireCounter += 1)
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
nameParts = splitPrefix(name)
|
|
459
|
-
prefix = nameParts[0]
|
|
460
|
-
name = nameParts[1]
|
|
461
|
-
|
|
462
|
-
if (prefix) {
|
|
463
|
-
prefix = normalize(prefix, parentName, applyMap)
|
|
464
|
-
pluginModule = getOwn(defined, prefix)
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
// Account for relative paths if there is a base name.
|
|
468
|
-
if (name) {
|
|
469
|
-
if (prefix) {
|
|
470
|
-
if (pluginModule && pluginModule.normalize) {
|
|
471
|
-
// Plugin is loaded, use its normalize method.
|
|
472
|
-
normalizedName = pluginModule.normalize(name, function (name) {
|
|
473
|
-
return normalize(name, parentName, applyMap)
|
|
474
|
-
})
|
|
475
|
-
} else {
|
|
476
|
-
// If nested plugin references, then do not try to
|
|
477
|
-
// normalize, as it will not normalize correctly. This
|
|
478
|
-
// places a restriction on resourceIds, and the longer
|
|
479
|
-
// term solution is not to normalize until plugins are
|
|
480
|
-
// loaded and all normalizations to allow for async
|
|
481
|
-
// loading of a loader plugin. But for now, fixes the
|
|
482
|
-
// common uses. Details in #1131
|
|
483
|
-
normalizedName = name.indexOf('!') === -1 ? normalize(name, parentName, applyMap) : name
|
|
484
|
-
}
|
|
485
|
-
} else {
|
|
486
|
-
// A regular module.
|
|
487
|
-
normalizedName = normalize(name, parentName, applyMap)
|
|
488
|
-
|
|
489
|
-
// Normalized name may be a plugin ID due to map config
|
|
490
|
-
// application in normalize. The map config values must
|
|
491
|
-
// already be normalized, so do not need to redo that part.
|
|
492
|
-
nameParts = splitPrefix(normalizedName)
|
|
493
|
-
prefix = nameParts[0]
|
|
494
|
-
normalizedName = nameParts[1]
|
|
495
|
-
isNormalized = true
|
|
496
|
-
|
|
497
|
-
url = context.nameToUrl(normalizedName)
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// If the id is a plugin id that cannot be determined if it needs
|
|
502
|
-
// normalization, stamp it with a unique ID so two matching relative
|
|
503
|
-
// ids that may conflict can be separate.
|
|
504
|
-
suffix = prefix && !pluginModule && !isNormalized ? '_unnormalized' + (unnormalizedCounter += 1) : ''
|
|
505
|
-
|
|
506
|
-
return {
|
|
507
|
-
prefix: prefix,
|
|
508
|
-
name: normalizedName,
|
|
509
|
-
parentMap: parentModuleMap,
|
|
510
|
-
unnormalized: !!suffix,
|
|
511
|
-
url: url,
|
|
512
|
-
originalName: originalName,
|
|
513
|
-
isDefine: isDefine,
|
|
514
|
-
id: (prefix ? prefix + '!' + normalizedName : normalizedName) + suffix,
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
function getModule(depMap) {
|
|
519
|
-
var id = depMap.id
|
|
520
|
-
var mod = getOwn(registry, id)
|
|
521
|
-
|
|
522
|
-
if (!mod) {
|
|
523
|
-
mod = registry[id] = new context.Module(depMap)
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
return mod
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
function on(depMap, name, fn) {
|
|
530
|
-
var id = depMap.id
|
|
531
|
-
var mod = getOwn(registry, id)
|
|
532
|
-
|
|
533
|
-
if (hasProp(defined, id) && (!mod || mod.defineEmitComplete)) {
|
|
534
|
-
if (name === 'defined') {
|
|
535
|
-
fn(defined[id])
|
|
536
|
-
}
|
|
537
|
-
} else {
|
|
538
|
-
mod = getModule(depMap)
|
|
539
|
-
if (mod.error && name === 'error') {
|
|
540
|
-
fn(mod.error)
|
|
541
|
-
} else {
|
|
542
|
-
mod.on(name, fn)
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
function onError(err, errback) {
|
|
548
|
-
var ids = err.requireModules
|
|
549
|
-
var notified = false
|
|
550
|
-
|
|
551
|
-
if (errback) {
|
|
552
|
-
errback(err)
|
|
553
|
-
} else {
|
|
554
|
-
each(ids, function (id) {
|
|
555
|
-
var mod = getOwn(registry, id)
|
|
556
|
-
if (mod) {
|
|
557
|
-
// Set error on module, so it skips timeout checks.
|
|
558
|
-
mod.error = err
|
|
559
|
-
if (mod.events.error) {
|
|
560
|
-
notified = true
|
|
561
|
-
mod.emit('error', err)
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
})
|
|
565
|
-
|
|
566
|
-
if (!notified) {
|
|
567
|
-
req.onError(err)
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Internal method to transfer globalQueue items to this context's
|
|
574
|
-
* defQueue.
|
|
575
|
-
*/
|
|
576
|
-
function takeGlobalQueue() {
|
|
577
|
-
// Push all the globalDefQueue items into the context's defQueue
|
|
578
|
-
if (globalDefQueue.length) {
|
|
579
|
-
each(globalDefQueue, function (queueItem) {
|
|
580
|
-
var id = queueItem[0]
|
|
581
|
-
if (typeof id === 'string') {
|
|
582
|
-
context.defQueueMap[id] = true
|
|
583
|
-
}
|
|
584
|
-
defQueue.push(queueItem)
|
|
585
|
-
})
|
|
586
|
-
globalDefQueue = []
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
handlers = {
|
|
591
|
-
require: function (mod) {
|
|
592
|
-
if (mod.require) {
|
|
593
|
-
return mod.require
|
|
594
|
-
} else {
|
|
595
|
-
return (mod.require = context.makeRequire(mod.map))
|
|
596
|
-
}
|
|
597
|
-
},
|
|
598
|
-
exports: function (mod) {
|
|
599
|
-
mod.usingExports = true
|
|
600
|
-
if (mod.map.isDefine) {
|
|
601
|
-
if (mod.exports) {
|
|
602
|
-
defined[mod.map.id] = mod.exports
|
|
603
|
-
} else {
|
|
604
|
-
mod.exports = defined[mod.map.id] = {}
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
},
|
|
608
|
-
module: function (mod) {
|
|
609
|
-
if (mod.module) {
|
|
610
|
-
return mod.module
|
|
611
|
-
} else {
|
|
612
|
-
return (mod.module = {
|
|
613
|
-
id: mod.map.id,
|
|
614
|
-
uri: mod.map.url,
|
|
615
|
-
config: function () {
|
|
616
|
-
return getOwn(config.config, mod.map.id) || {}
|
|
617
|
-
},
|
|
618
|
-
exports: mod.exports || (mod.exports = {}),
|
|
619
|
-
})
|
|
620
|
-
}
|
|
621
|
-
},
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
function cleanRegistry(id) {
|
|
625
|
-
// Clean up machinery used for waiting modules.
|
|
626
|
-
delete registry[id]
|
|
627
|
-
delete enabledRegistry[id]
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
function breakCycle(mod, traced, processed) {
|
|
631
|
-
var id = mod.map.id
|
|
632
|
-
|
|
633
|
-
if (mod.error) {
|
|
634
|
-
mod.emit('error', mod.error)
|
|
635
|
-
} else {
|
|
636
|
-
traced[id] = true
|
|
637
|
-
each(mod.depMaps, function (depMap, i) {
|
|
638
|
-
var depId = depMap.id
|
|
639
|
-
var dep = getOwn(registry, depId)
|
|
640
|
-
|
|
641
|
-
// Only force things that have not completed
|
|
642
|
-
// being defined, so still in the registry,
|
|
643
|
-
// and only if it has not been matched up
|
|
644
|
-
// in the module already.
|
|
645
|
-
if (dep && !mod.depMatched[i] && !processed[depId]) {
|
|
646
|
-
if (getOwn(traced, depId)) {
|
|
647
|
-
mod.defineDep(i, defined[depId])
|
|
648
|
-
mod.check() // pass false?
|
|
649
|
-
} else {
|
|
650
|
-
breakCycle(dep, traced, processed)
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
})
|
|
654
|
-
processed[id] = true
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
function checkLoaded() {
|
|
659
|
-
var err
|
|
660
|
-
var usingPathFallback
|
|
661
|
-
var waitInterval = config.waitSeconds * 1000
|
|
662
|
-
// It is possible to disable the wait interval by using waitSeconds of 0.
|
|
663
|
-
var expired = waitInterval && context.startTime + waitInterval < new Date().getTime()
|
|
664
|
-
var noLoads = []
|
|
665
|
-
var reqCalls = []
|
|
666
|
-
var stillLoading = false
|
|
667
|
-
var needCycleCheck = true
|
|
668
|
-
|
|
669
|
-
// Do not bother if this call was a result of a cycle break.
|
|
670
|
-
if (inCheckLoaded) {
|
|
671
|
-
return
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
inCheckLoaded = true
|
|
675
|
-
|
|
676
|
-
// Figure out the state of all the modules.
|
|
677
|
-
eachProp(enabledRegistry, function (mod) {
|
|
678
|
-
var map = mod.map
|
|
679
|
-
var modId = map.id
|
|
680
|
-
|
|
681
|
-
// Skip things that are not enabled or in error state.
|
|
682
|
-
if (!mod.enabled) {
|
|
683
|
-
return
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
if (!map.isDefine) {
|
|
687
|
-
reqCalls.push(mod)
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
if (!mod.error) {
|
|
691
|
-
// If the module should be executed, and it has not
|
|
692
|
-
// been inited and time is up, remember it.
|
|
693
|
-
if (!mod.inited && expired) {
|
|
694
|
-
if (hasPathFallback(modId)) {
|
|
695
|
-
usingPathFallback = true
|
|
696
|
-
stillLoading = true
|
|
697
|
-
} else {
|
|
698
|
-
noLoads.push(modId)
|
|
699
|
-
removeScript(modId)
|
|
700
|
-
}
|
|
701
|
-
} else if (!mod.inited && mod.fetched && map.isDefine) {
|
|
702
|
-
stillLoading = true
|
|
703
|
-
if (!map.prefix) {
|
|
704
|
-
// No reason to keep looking for unfinished
|
|
705
|
-
// loading. If the only stillLoading is a
|
|
706
|
-
// plugin resource though, keep going,
|
|
707
|
-
// because it may be that a plugin resource
|
|
708
|
-
// is waiting on a non-plugin cycle.
|
|
709
|
-
return (needCycleCheck = false)
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
})
|
|
714
|
-
|
|
715
|
-
if (expired && noLoads.length) {
|
|
716
|
-
// If wait time expired, throw error of unloaded modules.
|
|
717
|
-
err = makeError('timeout', 'Load timeout for modules: ' + noLoads, null, noLoads)
|
|
718
|
-
err.contextName = context.contextName
|
|
719
|
-
return onError(err)
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
// Not expired, check for a cycle.
|
|
723
|
-
if (needCycleCheck) {
|
|
724
|
-
each(reqCalls, function (mod) {
|
|
725
|
-
breakCycle(mod, {}, {})
|
|
726
|
-
})
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
// If still waiting on loads, and the waiting load is something
|
|
730
|
-
// other than a plugin resource, or there are still outstanding
|
|
731
|
-
// scripts, then just try back later.
|
|
732
|
-
if ((!expired || usingPathFallback) && stillLoading) {
|
|
733
|
-
// Something is still waiting to load. Wait for it, but only
|
|
734
|
-
// if a timeout is not already in effect.
|
|
735
|
-
if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
|
|
736
|
-
checkLoadedTimeoutId = setTimeout(function () {
|
|
737
|
-
checkLoadedTimeoutId = 0
|
|
738
|
-
checkLoaded()
|
|
739
|
-
}, 50)
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
inCheckLoaded = false
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
Module = function (map) {
|
|
747
|
-
this.events = getOwn(undefEvents, map.id) || {}
|
|
748
|
-
this.map = map
|
|
749
|
-
this.shim = getOwn(config.shim, map.id)
|
|
750
|
-
this.depExports = []
|
|
751
|
-
this.depMaps = []
|
|
752
|
-
this.depMatched = []
|
|
753
|
-
this.pluginMaps = {}
|
|
754
|
-
this.depCount = 0
|
|
755
|
-
|
|
756
|
-
/* this.exports this.factory
|
|
757
|
-
this.depMaps = [],
|
|
758
|
-
this.enabled, this.fetched
|
|
759
|
-
*/
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
Module.prototype = {
|
|
763
|
-
init: function (depMaps, factory, errback, options) {
|
|
764
|
-
options = options || {}
|
|
765
|
-
|
|
766
|
-
// Do not do more inits if already done. Can happen if there
|
|
767
|
-
// are multiple define calls for the same module. That is not
|
|
768
|
-
// a normal, common case, but it is also not unexpected.
|
|
769
|
-
if (this.inited) {
|
|
770
|
-
return
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
this.factory = factory
|
|
774
|
-
|
|
775
|
-
if (errback) {
|
|
776
|
-
// Register for errors on this module.
|
|
777
|
-
this.on('error', errback)
|
|
778
|
-
} else if (this.events.error) {
|
|
779
|
-
// If no errback already, but there are error listeners
|
|
780
|
-
// on this module, set up an errback to pass to the deps.
|
|
781
|
-
errback = bind(this, function (err) {
|
|
782
|
-
this.emit('error', err)
|
|
783
|
-
})
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
// Do a copy of the dependency array, so that
|
|
787
|
-
// source inputs are not modified. For example
|
|
788
|
-
// "shim" deps are passed in here directly, and
|
|
789
|
-
// doing a direct modification of the depMaps array
|
|
790
|
-
// would affect that config.
|
|
791
|
-
this.depMaps = depMaps && depMaps.slice(0)
|
|
792
|
-
|
|
793
|
-
this.errback = errback
|
|
794
|
-
|
|
795
|
-
// Indicate this module has be initialized
|
|
796
|
-
this.inited = true
|
|
797
|
-
|
|
798
|
-
this.ignore = options.ignore
|
|
799
|
-
|
|
800
|
-
// Could have option to init this module in enabled mode,
|
|
801
|
-
// or could have been previously marked as enabled. However,
|
|
802
|
-
// the dependencies are not known until init is called. So
|
|
803
|
-
// if enabled previously, now trigger dependencies as enabled.
|
|
804
|
-
if (options.enabled || this.enabled) {
|
|
805
|
-
// Enable this module and dependencies.
|
|
806
|
-
// Will call this.check()
|
|
807
|
-
this.enable()
|
|
808
|
-
} else {
|
|
809
|
-
this.check()
|
|
810
|
-
}
|
|
811
|
-
},
|
|
812
|
-
|
|
813
|
-
defineDep: function (i, depExports) {
|
|
814
|
-
// Because of cycles, defined callback for a given
|
|
815
|
-
// export can be called more than once.
|
|
816
|
-
if (!this.depMatched[i]) {
|
|
817
|
-
this.depMatched[i] = true
|
|
818
|
-
this.depCount -= 1
|
|
819
|
-
this.depExports[i] = depExports
|
|
820
|
-
}
|
|
821
|
-
},
|
|
822
|
-
|
|
823
|
-
fetch: function () {
|
|
824
|
-
if (this.fetched) {
|
|
825
|
-
return
|
|
826
|
-
}
|
|
827
|
-
this.fetched = true
|
|
828
|
-
|
|
829
|
-
context.startTime = new Date().getTime()
|
|
830
|
-
|
|
831
|
-
var map = this.map
|
|
832
|
-
|
|
833
|
-
// If the manager is for a plugin managed resource,
|
|
834
|
-
// ask the plugin to load it now.
|
|
835
|
-
if (this.shim) {
|
|
836
|
-
context.makeRequire(this.map, {
|
|
837
|
-
enableBuildCallback: true,
|
|
838
|
-
})(
|
|
839
|
-
this.shim.deps || [],
|
|
840
|
-
bind(this, function () {
|
|
841
|
-
return map.prefix ? this.callPlugin() : this.load()
|
|
842
|
-
})
|
|
843
|
-
)
|
|
844
|
-
} else {
|
|
845
|
-
// Regular dependency.
|
|
846
|
-
return map.prefix ? this.callPlugin() : this.load()
|
|
847
|
-
}
|
|
848
|
-
},
|
|
849
|
-
|
|
850
|
-
load: function () {
|
|
851
|
-
var url = this.map.url
|
|
852
|
-
|
|
853
|
-
// Regular dependency.
|
|
854
|
-
if (!urlFetched[url]) {
|
|
855
|
-
urlFetched[url] = true
|
|
856
|
-
context.load(this.map.id, url)
|
|
857
|
-
}
|
|
858
|
-
},
|
|
859
|
-
|
|
860
|
-
/**
|
|
861
|
-
* Checks if the module is ready to define itself, and if so,
|
|
862
|
-
* define it.
|
|
863
|
-
*/
|
|
864
|
-
check: function () {
|
|
865
|
-
if (!this.enabled || this.enabling) {
|
|
866
|
-
return
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
var err
|
|
870
|
-
var cjsModule
|
|
871
|
-
var id = this.map.id
|
|
872
|
-
var depExports = this.depExports
|
|
873
|
-
var exports = this.exports
|
|
874
|
-
var factory = this.factory
|
|
875
|
-
|
|
876
|
-
if (!this.inited) {
|
|
877
|
-
// Only fetch if not already in the defQueue.
|
|
878
|
-
if (!hasProp(context.defQueueMap, id)) {
|
|
879
|
-
this.fetch()
|
|
880
|
-
}
|
|
881
|
-
} else if (this.error) {
|
|
882
|
-
this.emit('error', this.error)
|
|
883
|
-
} else if (!this.defining) {
|
|
884
|
-
// The factory could trigger another require call
|
|
885
|
-
// that would result in checking this module to
|
|
886
|
-
// define itself again. If already in the process
|
|
887
|
-
// of doing that, skip this work.
|
|
888
|
-
this.defining = true
|
|
889
|
-
|
|
890
|
-
if (this.depCount < 1 && !this.defined) {
|
|
891
|
-
if (isFunction(factory)) {
|
|
892
|
-
// If there is an error listener, favor passing
|
|
893
|
-
// to that instead of throwing an error. However,
|
|
894
|
-
// only do it for define()'d modules. require
|
|
895
|
-
// errbacks should not be called for failures in
|
|
896
|
-
// their callbacks (#699). However if a global
|
|
897
|
-
// onError is set, use that.
|
|
898
|
-
if ((this.events.error && this.map.isDefine) || req.onError !== defaultOnError) {
|
|
899
|
-
try {
|
|
900
|
-
exports = context.execCb(id, factory, depExports, exports)
|
|
901
|
-
} catch (e) {
|
|
902
|
-
err = e
|
|
903
|
-
}
|
|
904
|
-
} else {
|
|
905
|
-
exports = context.execCb(id, factory, depExports, exports)
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
// Favor return value over exports. If node/cjs in play,
|
|
909
|
-
// then will not have a return value anyway. Favor
|
|
910
|
-
// module.exports assignment over exports object.
|
|
911
|
-
if (this.map.isDefine && exports === undefined) {
|
|
912
|
-
cjsModule = this.module
|
|
913
|
-
if (cjsModule) {
|
|
914
|
-
exports = cjsModule.exports
|
|
915
|
-
} else if (this.usingExports) {
|
|
916
|
-
// exports already set the defined value.
|
|
917
|
-
exports = this.exports
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
if (err) {
|
|
922
|
-
err.requireMap = this.map
|
|
923
|
-
err.requireModules = this.map.isDefine ? [this.map.id] : null
|
|
924
|
-
err.requireType = this.map.isDefine ? 'define' : 'require'
|
|
925
|
-
return onError((this.error = err))
|
|
926
|
-
}
|
|
927
|
-
} else {
|
|
928
|
-
// Just a literal value
|
|
929
|
-
exports = factory
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
this.exports = exports
|
|
933
|
-
|
|
934
|
-
if (this.map.isDefine && !this.ignore) {
|
|
935
|
-
defined[id] = exports
|
|
936
|
-
|
|
937
|
-
if (req.onResourceLoad) {
|
|
938
|
-
var resLoadMaps = []
|
|
939
|
-
each(this.depMaps, function (depMap) {
|
|
940
|
-
resLoadMaps.push(depMap.normalizedMap || depMap)
|
|
941
|
-
})
|
|
942
|
-
req.onResourceLoad(context, this.map, resLoadMaps)
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
// Clean up
|
|
947
|
-
cleanRegistry(id)
|
|
948
|
-
|
|
949
|
-
this.defined = true
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
// Finished the define stage. Allow calling check again
|
|
953
|
-
// to allow define notifications below in the case of a
|
|
954
|
-
// cycle.
|
|
955
|
-
this.defining = false
|
|
956
|
-
|
|
957
|
-
if (this.defined && !this.defineEmitted) {
|
|
958
|
-
this.defineEmitted = true
|
|
959
|
-
this.emit('defined', this.exports)
|
|
960
|
-
this.defineEmitComplete = true
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
},
|
|
964
|
-
|
|
965
|
-
callPlugin: function () {
|
|
966
|
-
var map = this.map
|
|
967
|
-
var id = map.id
|
|
968
|
-
// Map already normalized the prefix.
|
|
969
|
-
var pluginMap = makeModuleMap(map.prefix)
|
|
970
|
-
|
|
971
|
-
// Mark this as a dependency for this plugin, so it
|
|
972
|
-
// can be traced for cycles.
|
|
973
|
-
this.depMaps.push(pluginMap)
|
|
974
|
-
|
|
975
|
-
on(
|
|
976
|
-
pluginMap,
|
|
977
|
-
'defined',
|
|
978
|
-
bind(this, function (plugin) {
|
|
979
|
-
var load
|
|
980
|
-
var normalizedMap
|
|
981
|
-
var normalizedMod
|
|
982
|
-
var bundleId = getOwn(bundlesMap, this.map.id)
|
|
983
|
-
var name = this.map.name
|
|
984
|
-
var parentName = this.map.parentMap ? this.map.parentMap.name : null
|
|
985
|
-
var localRequire = context.makeRequire(map.parentMap, {
|
|
986
|
-
enableBuildCallback: true,
|
|
987
|
-
})
|
|
988
|
-
|
|
989
|
-
// If current map is not normalized, wait for that
|
|
990
|
-
// normalized name to load instead of continuing.
|
|
991
|
-
if (this.map.unnormalized) {
|
|
992
|
-
// Normalize the ID if the plugin allows it.
|
|
993
|
-
if (plugin.normalize) {
|
|
994
|
-
name =
|
|
995
|
-
plugin.normalize(name, function (name) {
|
|
996
|
-
return normalize(name, parentName, true)
|
|
997
|
-
}) || ''
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
// prefix and name should already be normalized, no need
|
|
1001
|
-
// for applying map config again either.
|
|
1002
|
-
normalizedMap = makeModuleMap(map.prefix + '!' + name, this.map.parentMap)
|
|
1003
|
-
on(
|
|
1004
|
-
normalizedMap,
|
|
1005
|
-
'defined',
|
|
1006
|
-
bind(this, function (value) {
|
|
1007
|
-
this.map.normalizedMap = normalizedMap
|
|
1008
|
-
this.init(
|
|
1009
|
-
[],
|
|
1010
|
-
function () {
|
|
1011
|
-
return value
|
|
1012
|
-
},
|
|
1013
|
-
null,
|
|
1014
|
-
{
|
|
1015
|
-
enabled: true,
|
|
1016
|
-
ignore: true,
|
|
1017
|
-
}
|
|
1018
|
-
)
|
|
1019
|
-
})
|
|
1020
|
-
)
|
|
1021
|
-
|
|
1022
|
-
normalizedMod = getOwn(registry, normalizedMap.id)
|
|
1023
|
-
if (normalizedMod) {
|
|
1024
|
-
// Mark this as a dependency for this plugin, so it
|
|
1025
|
-
// can be traced for cycles.
|
|
1026
|
-
this.depMaps.push(normalizedMap)
|
|
1027
|
-
|
|
1028
|
-
if (this.events.error) {
|
|
1029
|
-
normalizedMod.on(
|
|
1030
|
-
'error',
|
|
1031
|
-
bind(this, function (err) {
|
|
1032
|
-
this.emit('error', err)
|
|
1033
|
-
})
|
|
1034
|
-
)
|
|
1035
|
-
}
|
|
1036
|
-
normalizedMod.enable()
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
return
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
// If a paths config, then just load that file instead to
|
|
1043
|
-
// resolve the plugin, as it is built into that paths layer.
|
|
1044
|
-
if (bundleId) {
|
|
1045
|
-
this.map.url = context.nameToUrl(bundleId)
|
|
1046
|
-
this.load()
|
|
1047
|
-
return
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
load = bind(this, function (value) {
|
|
1051
|
-
this.init(
|
|
1052
|
-
[],
|
|
1053
|
-
function () {
|
|
1054
|
-
return value
|
|
1055
|
-
},
|
|
1056
|
-
null,
|
|
1057
|
-
{
|
|
1058
|
-
enabled: true,
|
|
1059
|
-
}
|
|
1060
|
-
)
|
|
1061
|
-
})
|
|
1062
|
-
|
|
1063
|
-
load.error = bind(this, function (err) {
|
|
1064
|
-
this.inited = true
|
|
1065
|
-
this.error = err
|
|
1066
|
-
err.requireModules = [id]
|
|
1067
|
-
|
|
1068
|
-
// Remove temp unnormalized modules for this module,
|
|
1069
|
-
// since they will never be resolved otherwise now.
|
|
1070
|
-
eachProp(registry, function (mod) {
|
|
1071
|
-
if (mod.map.id.indexOf(id + '_unnormalized') === 0) {
|
|
1072
|
-
cleanRegistry(mod.map.id)
|
|
1073
|
-
}
|
|
1074
|
-
})
|
|
1075
|
-
|
|
1076
|
-
onError(err)
|
|
1077
|
-
})
|
|
1078
|
-
|
|
1079
|
-
// Allow plugins to load other code without having to know the
|
|
1080
|
-
// context or how to 'complete' the load.
|
|
1081
|
-
load.fromText = bind(this, function (text, textAlt) {
|
|
1082
|
-
/* jslint evil: true */
|
|
1083
|
-
var moduleName = map.name
|
|
1084
|
-
var moduleMap = makeModuleMap(moduleName)
|
|
1085
|
-
var hasInteractive = useInteractive
|
|
1086
|
-
|
|
1087
|
-
// As of 2.1.0, support just passing the text, to reinforce
|
|
1088
|
-
// fromText only being called once per resource. Still
|
|
1089
|
-
// support old style of passing moduleName but discard
|
|
1090
|
-
// that moduleName in favor of the internal ref.
|
|
1091
|
-
if (textAlt) {
|
|
1092
|
-
text = textAlt
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
// Turn off interactive script matching for IE for any define
|
|
1096
|
-
// calls in the text, then turn it back on at the end.
|
|
1097
|
-
if (hasInteractive) {
|
|
1098
|
-
useInteractive = false
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
// Prime the system by creating a module instance for
|
|
1102
|
-
// it.
|
|
1103
|
-
getModule(moduleMap)
|
|
1104
|
-
|
|
1105
|
-
// Transfer any config to this other module.
|
|
1106
|
-
if (hasProp(config.config, id)) {
|
|
1107
|
-
config.config[moduleName] = config.config[id]
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
try {
|
|
1111
|
-
req.exec(text)
|
|
1112
|
-
} catch (e) {
|
|
1113
|
-
return onError(makeError('fromtexteval', 'fromText eval for ' + id + ' failed: ' + e, e, [id]))
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
if (hasInteractive) {
|
|
1117
|
-
useInteractive = true
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
// Mark this as a dependency for the plugin
|
|
1121
|
-
// resource
|
|
1122
|
-
this.depMaps.push(moduleMap)
|
|
1123
|
-
|
|
1124
|
-
// Support anonymous modules.
|
|
1125
|
-
context.completeLoad(moduleName)
|
|
1126
|
-
|
|
1127
|
-
// Bind the value of that module to the value for this
|
|
1128
|
-
// resource ID.
|
|
1129
|
-
localRequire([moduleName], load)
|
|
1130
|
-
})
|
|
1131
|
-
|
|
1132
|
-
// Use parentName here since the plugin's name is not reliable,
|
|
1133
|
-
// could be some weird string with no path that actually wants to
|
|
1134
|
-
// reference the parentName's path.
|
|
1135
|
-
plugin.load(map.name, localRequire, load, config)
|
|
1136
|
-
})
|
|
1137
|
-
)
|
|
1138
|
-
|
|
1139
|
-
context.enable(pluginMap, this)
|
|
1140
|
-
this.pluginMaps[pluginMap.id] = pluginMap
|
|
1141
|
-
},
|
|
1142
|
-
|
|
1143
|
-
enable: function () {
|
|
1144
|
-
enabledRegistry[this.map.id] = this
|
|
1145
|
-
this.enabled = true
|
|
1146
|
-
|
|
1147
|
-
// Set flag mentioning that the module is enabling,
|
|
1148
|
-
// so that immediate calls to the defined callbacks
|
|
1149
|
-
// for dependencies do not trigger inadvertent load
|
|
1150
|
-
// with the depCount still being zero.
|
|
1151
|
-
this.enabling = true
|
|
1152
|
-
|
|
1153
|
-
// Enable each dependency
|
|
1154
|
-
each(
|
|
1155
|
-
this.depMaps,
|
|
1156
|
-
bind(this, function (depMap, i) {
|
|
1157
|
-
var id, mod, handler
|
|
1158
|
-
|
|
1159
|
-
if (typeof depMap === 'string') {
|
|
1160
|
-
// Dependency needs to be converted to a depMap
|
|
1161
|
-
// and wired up to this module.
|
|
1162
|
-
depMap = makeModuleMap(depMap, this.map.isDefine ? this.map : this.map.parentMap, false, !this.skipMap)
|
|
1163
|
-
this.depMaps[i] = depMap
|
|
1164
|
-
|
|
1165
|
-
handler = getOwn(handlers, depMap.id)
|
|
1166
|
-
|
|
1167
|
-
if (handler) {
|
|
1168
|
-
this.depExports[i] = handler(this)
|
|
1169
|
-
return
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
this.depCount += 1
|
|
1173
|
-
|
|
1174
|
-
on(
|
|
1175
|
-
depMap,
|
|
1176
|
-
'defined',
|
|
1177
|
-
bind(this, function (depExports) {
|
|
1178
|
-
if (this.undefed) {
|
|
1179
|
-
return
|
|
1180
|
-
}
|
|
1181
|
-
this.defineDep(i, depExports)
|
|
1182
|
-
this.check()
|
|
1183
|
-
})
|
|
1184
|
-
)
|
|
1185
|
-
|
|
1186
|
-
if (this.errback) {
|
|
1187
|
-
on(depMap, 'error', bind(this, this.errback))
|
|
1188
|
-
} else if (this.events.error) {
|
|
1189
|
-
// No direct errback on this module, but something
|
|
1190
|
-
// else is listening for errors, so be sure to
|
|
1191
|
-
// propagate the error correctly.
|
|
1192
|
-
on(
|
|
1193
|
-
depMap,
|
|
1194
|
-
'error',
|
|
1195
|
-
bind(this, function (err) {
|
|
1196
|
-
this.emit('error', err)
|
|
1197
|
-
})
|
|
1198
|
-
)
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
id = depMap.id
|
|
1203
|
-
mod = registry[id]
|
|
1204
|
-
|
|
1205
|
-
// Skip special modules like 'require', 'exports', 'module'
|
|
1206
|
-
// Also, don't call enable if it is already enabled,
|
|
1207
|
-
// important in circular dependency cases.
|
|
1208
|
-
if (!hasProp(handlers, id) && mod && !mod.enabled) {
|
|
1209
|
-
context.enable(depMap, this)
|
|
1210
|
-
}
|
|
1211
|
-
})
|
|
1212
|
-
)
|
|
1213
|
-
|
|
1214
|
-
// Enable each plugin that is used in
|
|
1215
|
-
// a dependency
|
|
1216
|
-
eachProp(
|
|
1217
|
-
this.pluginMaps,
|
|
1218
|
-
bind(this, function (pluginMap) {
|
|
1219
|
-
var mod = getOwn(registry, pluginMap.id)
|
|
1220
|
-
if (mod && !mod.enabled) {
|
|
1221
|
-
context.enable(pluginMap, this)
|
|
1222
|
-
}
|
|
1223
|
-
})
|
|
1224
|
-
)
|
|
1225
|
-
|
|
1226
|
-
this.enabling = false
|
|
1227
|
-
|
|
1228
|
-
this.check()
|
|
1229
|
-
},
|
|
1230
|
-
|
|
1231
|
-
on: function (name, cb) {
|
|
1232
|
-
var cbs = this.events[name]
|
|
1233
|
-
if (!cbs) {
|
|
1234
|
-
cbs = this.events[name] = []
|
|
1235
|
-
}
|
|
1236
|
-
cbs.push(cb)
|
|
1237
|
-
},
|
|
1238
|
-
|
|
1239
|
-
emit: function (name, evt) {
|
|
1240
|
-
each(this.events[name], function (cb) {
|
|
1241
|
-
cb(evt)
|
|
1242
|
-
})
|
|
1243
|
-
if (name === 'error') {
|
|
1244
|
-
// Now that the error handler was triggered, remove
|
|
1245
|
-
// the listeners, since this broken Module instance
|
|
1246
|
-
// can stay around for a while in the registry.
|
|
1247
|
-
delete this.events[name]
|
|
1248
|
-
}
|
|
1249
|
-
},
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
function callGetModule(args) {
|
|
1253
|
-
// Skip modules already defined.
|
|
1254
|
-
if (!hasProp(defined, args[0])) {
|
|
1255
|
-
getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2])
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
function removeListener(node, func, name, ieName) {
|
|
1260
|
-
// Favor detachEvent because of IE9
|
|
1261
|
-
// issue, see attachEvent/addEventListener comment elsewhere
|
|
1262
|
-
// in this file.
|
|
1263
|
-
if (node.detachEvent && !isOpera) {
|
|
1264
|
-
// Probably IE. If not it will throw an error, which will be
|
|
1265
|
-
// useful to know.
|
|
1266
|
-
if (ieName) {
|
|
1267
|
-
node.detachEvent(ieName, func)
|
|
1268
|
-
}
|
|
1269
|
-
} else {
|
|
1270
|
-
node.removeEventListener(name, func, false)
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
/**
|
|
1275
|
-
* Given an event from a script node, get the requirejs info from it,
|
|
1276
|
-
* and then removes the event listeners on the node.
|
|
1277
|
-
* @param {Event} evt
|
|
1278
|
-
* @returns {Object}
|
|
1279
|
-
*/
|
|
1280
|
-
function getScriptData(evt) {
|
|
1281
|
-
// Using currentTarget instead of target for Firefox 2.0's sake. Not
|
|
1282
|
-
// all old browsers will be supported, but this one was easy enough
|
|
1283
|
-
// to support and still makes sense.
|
|
1284
|
-
var node = evt.currentTarget || evt.srcElement
|
|
1285
|
-
|
|
1286
|
-
// Remove the listeners once here.
|
|
1287
|
-
removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange')
|
|
1288
|
-
removeListener(node, context.onScriptError, 'error')
|
|
1289
|
-
|
|
1290
|
-
return {
|
|
1291
|
-
node: node,
|
|
1292
|
-
id: node && node.getAttribute('data-requiremodule'),
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
function intakeDefines() {
|
|
1297
|
-
var args
|
|
1298
|
-
|
|
1299
|
-
// Any defined modules in the global queue, intake them now.
|
|
1300
|
-
takeGlobalQueue()
|
|
1301
|
-
|
|
1302
|
-
// Make sure any remaining defQueue items get properly processed.
|
|
1303
|
-
while (defQueue.length) {
|
|
1304
|
-
args = defQueue.shift()
|
|
1305
|
-
if (args[0] === null) {
|
|
1306
|
-
return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]))
|
|
1307
|
-
} else {
|
|
1308
|
-
// args are id, deps, factory. Should be normalized by the
|
|
1309
|
-
// define() function.
|
|
1310
|
-
callGetModule(args)
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
context.defQueueMap = {}
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
context = {
|
|
1317
|
-
config: config,
|
|
1318
|
-
contextName: contextName,
|
|
1319
|
-
registry: registry,
|
|
1320
|
-
defined: defined,
|
|
1321
|
-
urlFetched: urlFetched,
|
|
1322
|
-
defQueue: defQueue,
|
|
1323
|
-
defQueueMap: {},
|
|
1324
|
-
Module: Module,
|
|
1325
|
-
makeModuleMap: makeModuleMap,
|
|
1326
|
-
nextTick: req.nextTick,
|
|
1327
|
-
onError: onError,
|
|
1328
|
-
|
|
1329
|
-
/**
|
|
1330
|
-
* Set a configuration for the context.
|
|
1331
|
-
* @param {Object} cfg config object to integrate.
|
|
1332
|
-
*/
|
|
1333
|
-
configure: function (cfg) {
|
|
1334
|
-
// Make sure the baseUrl ends in a slash.
|
|
1335
|
-
if (cfg.baseUrl) {
|
|
1336
|
-
if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== '/') {
|
|
1337
|
-
cfg.baseUrl += '/'
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
// Convert old style urlArgs string to a function.
|
|
1342
|
-
if (typeof cfg.urlArgs === 'string') {
|
|
1343
|
-
var urlArgs = cfg.urlArgs
|
|
1344
|
-
cfg.urlArgs = function (id, url) {
|
|
1345
|
-
return (url.indexOf('?') === -1 ? '?' : '&') + urlArgs
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
// Save off the paths since they require special processing,
|
|
1350
|
-
// they are additive.
|
|
1351
|
-
var shim = config.shim
|
|
1352
|
-
var objs = {
|
|
1353
|
-
paths: true,
|
|
1354
|
-
bundles: true,
|
|
1355
|
-
config: true,
|
|
1356
|
-
map: true,
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
eachProp(cfg, function (value, prop) {
|
|
1360
|
-
if (objs[prop]) {
|
|
1361
|
-
if (!config[prop]) {
|
|
1362
|
-
config[prop] = {}
|
|
1363
|
-
}
|
|
1364
|
-
mixin(config[prop], value, true, true)
|
|
1365
|
-
} else {
|
|
1366
|
-
config[prop] = value
|
|
1367
|
-
}
|
|
1368
|
-
})
|
|
1369
|
-
|
|
1370
|
-
// Reverse map the bundles
|
|
1371
|
-
if (cfg.bundles) {
|
|
1372
|
-
eachProp(cfg.bundles, function (value, prop) {
|
|
1373
|
-
each(value, function (v) {
|
|
1374
|
-
if (v !== prop) {
|
|
1375
|
-
bundlesMap[v] = prop
|
|
1376
|
-
}
|
|
1377
|
-
})
|
|
1378
|
-
})
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
// Merge shim
|
|
1382
|
-
if (cfg.shim) {
|
|
1383
|
-
eachProp(cfg.shim, function (value, id) {
|
|
1384
|
-
// Normalize the structure
|
|
1385
|
-
if (isArray(value)) {
|
|
1386
|
-
value = {
|
|
1387
|
-
deps: value,
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
if ((value.exports || value.init) && !value.exportsFn) {
|
|
1391
|
-
value.exportsFn = context.makeShimExports(value)
|
|
1392
|
-
}
|
|
1393
|
-
shim[id] = value
|
|
1394
|
-
})
|
|
1395
|
-
config.shim = shim
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
// Adjust packages if necessary.
|
|
1399
|
-
if (cfg.packages) {
|
|
1400
|
-
each(cfg.packages, function (pkgObj) {
|
|
1401
|
-
var location, name
|
|
1402
|
-
|
|
1403
|
-
pkgObj = typeof pkgObj === 'string' ? { name: pkgObj } : pkgObj
|
|
1404
|
-
|
|
1405
|
-
name = pkgObj.name
|
|
1406
|
-
location = pkgObj.location
|
|
1407
|
-
if (location) {
|
|
1408
|
-
config.paths[name] = pkgObj.location
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
// Save pointer to main module ID for pkg name.
|
|
1412
|
-
// Remove leading dot in main, so main paths are normalized,
|
|
1413
|
-
// and remove any trailing .js, since different package
|
|
1414
|
-
// envs have different conventions: some use a module name,
|
|
1415
|
-
// some use a file name.
|
|
1416
|
-
config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main').replace(currDirRegExp, '').replace(jsSuffixRegExp, '')
|
|
1417
|
-
})
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
// If there are any "waiting to execute" modules in the registry,
|
|
1421
|
-
// update the maps for them, since their info, like URLs to load,
|
|
1422
|
-
// may have changed.
|
|
1423
|
-
eachProp(registry, function (mod, id) {
|
|
1424
|
-
// If module already has init called, since it is too
|
|
1425
|
-
// late to modify them, and ignore unnormalized ones
|
|
1426
|
-
// since they are transient.
|
|
1427
|
-
if (!mod.inited && !mod.map.unnormalized) {
|
|
1428
|
-
mod.map = makeModuleMap(id, null, true)
|
|
1429
|
-
}
|
|
1430
|
-
})
|
|
1431
|
-
|
|
1432
|
-
// If a deps array or a config callback is specified, then call
|
|
1433
|
-
// require with those args. This is useful when require is defined as a
|
|
1434
|
-
// config object before require.js is loaded.
|
|
1435
|
-
if (cfg.deps || cfg.callback) {
|
|
1436
|
-
context.require(cfg.deps || [], cfg.callback)
|
|
1437
|
-
}
|
|
1438
|
-
},
|
|
1439
|
-
|
|
1440
|
-
makeShimExports: function (value) {
|
|
1441
|
-
function fn() {
|
|
1442
|
-
var ret
|
|
1443
|
-
if (value.init) {
|
|
1444
|
-
ret = value.init.apply(global, arguments)
|
|
1445
|
-
}
|
|
1446
|
-
return ret || (value.exports && getGlobal(value.exports))
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
return fn
|
|
1450
|
-
},
|
|
1451
|
-
|
|
1452
|
-
makeRequire: function (relMap, options) {
|
|
1453
|
-
options = options || {}
|
|
1454
|
-
|
|
1455
|
-
function localRequire(deps, callback, errback) {
|
|
1456
|
-
var id, map, requireMod
|
|
1457
|
-
|
|
1458
|
-
if (options.enableBuildCallback && callback && isFunction(callback)) {
|
|
1459
|
-
callback.__requireJsBuild = true
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1462
|
-
if (typeof deps === 'string') {
|
|
1463
|
-
if (isFunction(callback)) {
|
|
1464
|
-
// Invalid call
|
|
1465
|
-
return onError(makeError('requireargs', 'Invalid require call'), errback)
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
// If require|exports|module are requested, get the
|
|
1469
|
-
// value for them from the special handlers. Caveat:
|
|
1470
|
-
// this only works while module is being defined.
|
|
1471
|
-
if (relMap && hasProp(handlers, deps)) {
|
|
1472
|
-
return handlers[deps](registry[relMap.id])
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
// Synchronous access to one module. If require.get is
|
|
1476
|
-
// available (as in the Node adapter), prefer that.
|
|
1477
|
-
if (req.get) {
|
|
1478
|
-
return req.get(context, deps, relMap, localRequire)
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
// Normalize module name, if it contains . or ..
|
|
1482
|
-
map = makeModuleMap(deps, relMap, false, true)
|
|
1483
|
-
id = map.id
|
|
1484
|
-
|
|
1485
|
-
if (!hasProp(defined, id)) {
|
|
1486
|
-
return onError(makeError('notloaded', 'Module name "' + id + '" has not been loaded yet for context: ' + contextName + (relMap ? '' : '. Use require([])')))
|
|
1487
|
-
}
|
|
1488
|
-
return defined[id]
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
// Grab defines waiting in the global queue.
|
|
1492
|
-
intakeDefines()
|
|
1493
|
-
|
|
1494
|
-
// Mark all the dependencies as needing to be loaded.
|
|
1495
|
-
context.nextTick(function () {
|
|
1496
|
-
// Some defines could have been added since the
|
|
1497
|
-
// require call, collect them.
|
|
1498
|
-
intakeDefines()
|
|
1499
|
-
|
|
1500
|
-
requireMod = getModule(makeModuleMap(null, relMap))
|
|
1501
|
-
|
|
1502
|
-
// Store if map config should be applied to this require
|
|
1503
|
-
// call for dependencies.
|
|
1504
|
-
requireMod.skipMap = options.skipMap
|
|
1505
|
-
|
|
1506
|
-
requireMod.init(deps, callback, errback, {
|
|
1507
|
-
enabled: true,
|
|
1508
|
-
})
|
|
1509
|
-
|
|
1510
|
-
checkLoaded()
|
|
1511
|
-
})
|
|
1512
|
-
|
|
1513
|
-
return localRequire
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
mixin(localRequire, {
|
|
1517
|
-
isBrowser: isBrowser,
|
|
1518
|
-
|
|
1519
|
-
/**
|
|
1520
|
-
* Converts a module name + .extension into an URL path.
|
|
1521
|
-
* *Requires* the use of a module name. It does not support using
|
|
1522
|
-
* plain URLs like nameToUrl.
|
|
1523
|
-
*/
|
|
1524
|
-
toUrl: function (moduleNamePlusExt) {
|
|
1525
|
-
var ext
|
|
1526
|
-
var index = moduleNamePlusExt.lastIndexOf('.')
|
|
1527
|
-
var segment = moduleNamePlusExt.split('/')[0]
|
|
1528
|
-
var isRelative = segment === '.' || segment === '..'
|
|
1529
|
-
|
|
1530
|
-
// Have a file extension alias, and it is not the
|
|
1531
|
-
// dots from a relative path.
|
|
1532
|
-
if (index !== -1 && (!isRelative || index > 1)) {
|
|
1533
|
-
ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length)
|
|
1534
|
-
moduleNamePlusExt = moduleNamePlusExt.substring(0, index)
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
return context.nameToUrl(normalize(moduleNamePlusExt, relMap && relMap.id, true), ext, true)
|
|
1538
|
-
},
|
|
1539
|
-
|
|
1540
|
-
defined: function (id) {
|
|
1541
|
-
return hasProp(defined, makeModuleMap(id, relMap, false, true).id)
|
|
1542
|
-
},
|
|
1543
|
-
|
|
1544
|
-
specified: function (id) {
|
|
1545
|
-
id = makeModuleMap(id, relMap, false, true).id
|
|
1546
|
-
return hasProp(defined, id) || hasProp(registry, id)
|
|
1547
|
-
},
|
|
1548
|
-
})
|
|
1549
|
-
|
|
1550
|
-
// Only allow undef on top level require calls
|
|
1551
|
-
if (!relMap) {
|
|
1552
|
-
localRequire.undef = function (id) {
|
|
1553
|
-
// Bind any waiting define() calls to this context,
|
|
1554
|
-
// fix for #408
|
|
1555
|
-
takeGlobalQueue()
|
|
1556
|
-
|
|
1557
|
-
var map = makeModuleMap(id, relMap, true)
|
|
1558
|
-
var mod = getOwn(registry, id)
|
|
1559
|
-
|
|
1560
|
-
mod.undefed = true
|
|
1561
|
-
removeScript(id)
|
|
1562
|
-
|
|
1563
|
-
delete defined[id]
|
|
1564
|
-
delete urlFetched[map.url]
|
|
1565
|
-
delete undefEvents[id]
|
|
1566
|
-
|
|
1567
|
-
// Clean queued defines too. Go backwards
|
|
1568
|
-
// in array so that the splices do not
|
|
1569
|
-
// mess up the iteration.
|
|
1570
|
-
eachReverse(defQueue, function (args, i) {
|
|
1571
|
-
if (args[0] === id) {
|
|
1572
|
-
defQueue.splice(i, 1)
|
|
1573
|
-
}
|
|
1574
|
-
})
|
|
1575
|
-
delete context.defQueueMap[id]
|
|
1576
|
-
|
|
1577
|
-
if (mod) {
|
|
1578
|
-
// Hold on to listeners in case the
|
|
1579
|
-
// module will be attempted to be reloaded
|
|
1580
|
-
// using a different config.
|
|
1581
|
-
if (mod.events.defined) {
|
|
1582
|
-
undefEvents[id] = mod.events
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
cleanRegistry(id)
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
return localRequire
|
|
1591
|
-
},
|
|
1592
|
-
|
|
1593
|
-
/**
|
|
1594
|
-
* Called to enable a module if it is still in the registry
|
|
1595
|
-
* awaiting enablement. A second arg, parent, the parent module,
|
|
1596
|
-
* is passed in for context, when this method is overridden by
|
|
1597
|
-
* the optimizer. Not shown here to keep code compact.
|
|
1598
|
-
*/
|
|
1599
|
-
enable: function (depMap) {
|
|
1600
|
-
var mod = getOwn(registry, depMap.id)
|
|
1601
|
-
if (mod) {
|
|
1602
|
-
getModule(depMap).enable()
|
|
1603
|
-
}
|
|
1604
|
-
},
|
|
1605
|
-
|
|
1606
|
-
/**
|
|
1607
|
-
* Internal method used by environment adapters to complete a load event.
|
|
1608
|
-
* A load event could be a script load or just a load pass from a synchronous
|
|
1609
|
-
* load call.
|
|
1610
|
-
* @param {String} moduleName the name of the module to potentially complete.
|
|
1611
|
-
*/
|
|
1612
|
-
completeLoad: function (moduleName) {
|
|
1613
|
-
var found
|
|
1614
|
-
var args
|
|
1615
|
-
var mod
|
|
1616
|
-
var shim = getOwn(config.shim, moduleName) || {}
|
|
1617
|
-
var shExports = shim.exports
|
|
1618
|
-
|
|
1619
|
-
takeGlobalQueue()
|
|
1620
|
-
|
|
1621
|
-
while (defQueue.length) {
|
|
1622
|
-
args = defQueue.shift()
|
|
1623
|
-
if (args[0] === null) {
|
|
1624
|
-
args[0] = moduleName
|
|
1625
|
-
// If already found an anonymous module and bound it
|
|
1626
|
-
// to this name, then this is some other anon module
|
|
1627
|
-
// waiting for its completeLoad to fire.
|
|
1628
|
-
if (found) {
|
|
1629
|
-
break
|
|
1630
|
-
}
|
|
1631
|
-
found = true
|
|
1632
|
-
} else if (args[0] === moduleName) {
|
|
1633
|
-
// Found matching define call for this script!
|
|
1634
|
-
found = true
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
callGetModule(args)
|
|
1638
|
-
}
|
|
1639
|
-
context.defQueueMap = {}
|
|
1640
|
-
|
|
1641
|
-
// Do this after the cycle of callGetModule in case the result
|
|
1642
|
-
// of those calls/init calls changes the registry.
|
|
1643
|
-
mod = getOwn(registry, moduleName)
|
|
1644
|
-
|
|
1645
|
-
if (!found && !hasProp(defined, moduleName) && mod && !mod.inited) {
|
|
1646
|
-
if (config.enforceDefine && (!shExports || !getGlobal(shExports))) {
|
|
1647
|
-
if (hasPathFallback(moduleName)) {
|
|
1648
|
-
return
|
|
1649
|
-
} else {
|
|
1650
|
-
return onError(makeError('nodefine', 'No define call for ' + moduleName, null, [moduleName]))
|
|
1651
|
-
}
|
|
1652
|
-
} else {
|
|
1653
|
-
// A script that does not call define(), so just simulate
|
|
1654
|
-
// the call for it.
|
|
1655
|
-
callGetModule([moduleName, shim.deps || [], shim.exportsFn])
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
checkLoaded()
|
|
1660
|
-
},
|
|
1661
|
-
|
|
1662
|
-
/**
|
|
1663
|
-
* Converts a module name to a file path. Supports cases where
|
|
1664
|
-
* moduleName may actually be just an URL.
|
|
1665
|
-
* Note that it **does not** call normalize on the moduleName,
|
|
1666
|
-
* it is assumed to have already been normalized. This is an
|
|
1667
|
-
* internal API, not a public one. Use toUrl for the public API.
|
|
1668
|
-
*/
|
|
1669
|
-
nameToUrl: function (moduleName, ext, skipExt) {
|
|
1670
|
-
var paths
|
|
1671
|
-
var syms
|
|
1672
|
-
var i
|
|
1673
|
-
var parentModule
|
|
1674
|
-
var url
|
|
1675
|
-
var parentPath
|
|
1676
|
-
var bundleId
|
|
1677
|
-
var pkgMain = getOwn(config.pkgs, moduleName)
|
|
1678
|
-
|
|
1679
|
-
if (pkgMain) {
|
|
1680
|
-
moduleName = pkgMain
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
bundleId = getOwn(bundlesMap, moduleName)
|
|
1684
|
-
|
|
1685
|
-
if (bundleId) {
|
|
1686
|
-
return context.nameToUrl(bundleId, ext, skipExt)
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
// If a colon is in the URL, it indicates a protocol is used and it is just
|
|
1690
|
-
// an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
|
|
1691
|
-
// or ends with .js, then assume the user meant to use an url and not a module id.
|
|
1692
|
-
// The slash is important for protocol-less URLs as well as full paths.
|
|
1693
|
-
if (req.jsExtRegExp.test(moduleName)) {
|
|
1694
|
-
// Just a plain path, not module name lookup, so just return it.
|
|
1695
|
-
// Add extension if it is included. This is a bit wonky, only non-.js things pass
|
|
1696
|
-
// an extension, this method probably needs to be reworked.
|
|
1697
|
-
url = moduleName + (ext || '')
|
|
1698
|
-
} else {
|
|
1699
|
-
// A module that needs to be converted to a path.
|
|
1700
|
-
paths = config.paths
|
|
1701
|
-
|
|
1702
|
-
syms = moduleName.split('/')
|
|
1703
|
-
// For each module name segment, see if there is a path
|
|
1704
|
-
// registered for it. Start with most specific name
|
|
1705
|
-
// and work up from it.
|
|
1706
|
-
for (i = syms.length; i > 0; i -= 1) {
|
|
1707
|
-
parentModule = syms.slice(0, i).join('/')
|
|
1708
|
-
|
|
1709
|
-
parentPath = getOwn(paths, parentModule)
|
|
1710
|
-
if (parentPath) {
|
|
1711
|
-
// If an array, it means there are a few choices,
|
|
1712
|
-
// Choose the one that is desired
|
|
1713
|
-
if (isArray(parentPath)) {
|
|
1714
|
-
parentPath = parentPath[0]
|
|
1715
|
-
}
|
|
1716
|
-
syms.splice(0, i, parentPath)
|
|
1717
|
-
break
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
// Join the path parts together, then figure out if baseUrl is needed.
|
|
1722
|
-
url = syms.join('/')
|
|
1723
|
-
url += ext || (/^data:|^blob:|\?/.test(url) || skipExt ? '' : '.js')
|
|
1724
|
-
url = (url.charAt(0) === '/' || url.match(/^[\w+.-]+:/) ? '' : config.baseUrl) + url
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
return config.urlArgs && !/^blob:/.test(url) ? url + config.urlArgs(moduleName, url) : url
|
|
1728
|
-
},
|
|
1729
|
-
|
|
1730
|
-
// Delegates to req.load. Broken out as a separate function to
|
|
1731
|
-
// allow overriding in the optimizer.
|
|
1732
|
-
load: function (id, url) {
|
|
1733
|
-
req.load(context, id, url)
|
|
1734
|
-
},
|
|
1735
|
-
|
|
1736
|
-
/**
|
|
1737
|
-
* Executes a module callback function. Broken out as a separate function
|
|
1738
|
-
* solely to allow the build system to sequence the files in the built
|
|
1739
|
-
* layer in the right sequence.
|
|
1740
|
-
*
|
|
1741
|
-
* @private
|
|
1742
|
-
*/
|
|
1743
|
-
execCb: function (name, callback, args, exports) {
|
|
1744
|
-
return callback.apply(exports, args)
|
|
1745
|
-
},
|
|
1746
|
-
|
|
1747
|
-
/**
|
|
1748
|
-
* callback for script loads, used to check status of loading.
|
|
1749
|
-
*
|
|
1750
|
-
* @param {Event} evt the event from the browser for the script
|
|
1751
|
-
* that was loaded.
|
|
1752
|
-
*/
|
|
1753
|
-
onScriptLoad: function (evt) {
|
|
1754
|
-
// Using currentTarget instead of target for Firefox 2.0's sake. Not
|
|
1755
|
-
// all old browsers will be supported, but this one was easy enough
|
|
1756
|
-
// to support and still makes sense.
|
|
1757
|
-
if (evt.type === 'load' || readyRegExp.test((evt.currentTarget || evt.srcElement).readyState)) {
|
|
1758
|
-
// Reset interactive script so a script node is not held onto for
|
|
1759
|
-
// to long.
|
|
1760
|
-
interactiveScript = null
|
|
1761
|
-
|
|
1762
|
-
// Pull out the name of the module and the context.
|
|
1763
|
-
var data = getScriptData(evt)
|
|
1764
|
-
context.completeLoad(data.id)
|
|
1765
|
-
}
|
|
1766
|
-
},
|
|
1767
|
-
|
|
1768
|
-
/**
|
|
1769
|
-
* Callback for script errors.
|
|
1770
|
-
*/
|
|
1771
|
-
onScriptError: function (evt) {
|
|
1772
|
-
var data = getScriptData(evt)
|
|
1773
|
-
if (!hasPathFallback(data.id)) {
|
|
1774
|
-
var parents = []
|
|
1775
|
-
eachProp(registry, function (value, key) {
|
|
1776
|
-
if (key.indexOf('_@r') !== 0) {
|
|
1777
|
-
each(value.depMaps, function (depMap) {
|
|
1778
|
-
if (depMap.id === data.id) {
|
|
1779
|
-
parents.push(key)
|
|
1780
|
-
return true
|
|
1781
|
-
}
|
|
1782
|
-
})
|
|
1783
|
-
}
|
|
1784
|
-
})
|
|
1785
|
-
return onError(makeError('scripterror', 'Script error for "' + data.id + (parents.length ? '", needed by: ' + parents.join(', ') : '"'), evt, [data.id]))
|
|
1786
|
-
}
|
|
1787
|
-
},
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
|
-
context.require = context.makeRequire()
|
|
1791
|
-
return context
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
/**
|
|
1795
|
-
* Main entry point.
|
|
1796
|
-
*
|
|
1797
|
-
* If the only argument to require is a string, then the module that
|
|
1798
|
-
* is represented by that string is fetched for the appropriate context.
|
|
1799
|
-
*
|
|
1800
|
-
* If the first argument is an array, then it will be treated as an array
|
|
1801
|
-
* of dependency string names to fetch. An optional function callback can
|
|
1802
|
-
* be specified to execute when all of those dependencies are available.
|
|
1803
|
-
*
|
|
1804
|
-
* Make a local req variable to help Caja compliance (it assumes things
|
|
1805
|
-
* on a require that are not standardized), and to give a short
|
|
1806
|
-
* name for minification/local scope use.
|
|
1807
|
-
*/
|
|
1808
|
-
req = requirejs = function (deps, callback, errback, optional, contextOptions = {}) {
|
|
1809
|
-
// Find the right context, use default
|
|
1810
|
-
var context
|
|
1811
|
-
var config
|
|
1812
|
-
var contextName = defContextName
|
|
1813
|
-
|
|
1814
|
-
// Determine if have config object in the call.
|
|
1815
|
-
if (!isArray(deps) && typeof deps !== 'string') {
|
|
1816
|
-
// deps is a config object
|
|
1817
|
-
config = deps
|
|
1818
|
-
if (isArray(callback)) {
|
|
1819
|
-
// Adjust args if there are dependencies
|
|
1820
|
-
deps = callback
|
|
1821
|
-
callback = errback
|
|
1822
|
-
errback = optional
|
|
1823
|
-
} else {
|
|
1824
|
-
deps = []
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
|
|
1828
|
-
if (config && config.context) {
|
|
1829
|
-
contextName = config.context
|
|
1830
|
-
}
|
|
1831
|
-
|
|
1832
|
-
if (contextOptions.name) {
|
|
1833
|
-
contextName = contextOptions.name
|
|
1834
|
-
}
|
|
1835
|
-
|
|
1836
|
-
context = getOwn(contexts, contextName)
|
|
1837
|
-
if (!context) {
|
|
1838
|
-
context = contexts[contextName] = req.s.newContext(contextName, contextOptions)
|
|
1839
|
-
}
|
|
1840
|
-
|
|
1841
|
-
if (config) {
|
|
1842
|
-
context.configure(config)
|
|
1843
|
-
}
|
|
1844
|
-
|
|
1845
|
-
return context.require(deps, callback, errback)
|
|
1846
|
-
}
|
|
1847
|
-
|
|
1848
|
-
/**
|
|
1849
|
-
* Support require.config() to make it easier to cooperate with other
|
|
1850
|
-
* AMD loaders on globally agreed names.
|
|
1851
|
-
*/
|
|
1852
|
-
req.config = function (config) {
|
|
1853
|
-
return req(config)
|
|
1854
|
-
}
|
|
1855
|
-
|
|
1856
|
-
/**
|
|
1857
|
-
* Execute something after the current tick
|
|
1858
|
-
* of the event loop. Override for other envs
|
|
1859
|
-
* that have a better solution than setTimeout.
|
|
1860
|
-
* @param {Function} fn function to execute later.
|
|
1861
|
-
*/
|
|
1862
|
-
req.nextTick =
|
|
1863
|
-
typeof setTimeout !== 'undefined'
|
|
1864
|
-
? function (fn) {
|
|
1865
|
-
setTimeout(fn, 4)
|
|
1866
|
-
}
|
|
1867
|
-
: function (fn) {
|
|
1868
|
-
fn()
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
/**
|
|
1872
|
-
* Export require as a global, but only if it does not already exist.
|
|
1873
|
-
*/
|
|
1874
|
-
if (!require) {
|
|
1875
|
-
require = req
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
req.version = version
|
|
1879
|
-
|
|
1880
|
-
// Used to filter out dependencies that are already paths.
|
|
1881
|
-
req.jsExtRegExp = /^\/|:|\?|\.js$|\.css$/
|
|
1882
|
-
req.isBrowser = isBrowser
|
|
1883
|
-
s = req.s = {
|
|
1884
|
-
contexts: contexts,
|
|
1885
|
-
newContext: newContext,
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
|
-
// Create default context.
|
|
1889
|
-
req({})
|
|
1890
|
-
|
|
1891
|
-
// Exports some context-sensitive methods on global require.
|
|
1892
|
-
each(['toUrl', 'undef', 'defined', 'specified'], function (prop) {
|
|
1893
|
-
// Reference from contexts instead of early binding to default context,
|
|
1894
|
-
// so that during builds, the latest instance of the default context
|
|
1895
|
-
// with its config gets used.
|
|
1896
|
-
req[prop] = function () {
|
|
1897
|
-
var ctx = contexts[defContextName]
|
|
1898
|
-
return ctx.require[prop].apply(ctx, arguments)
|
|
1899
|
-
}
|
|
1900
|
-
})
|
|
1901
|
-
|
|
1902
|
-
if (isBrowser) {
|
|
1903
|
-
head = s.head = document.getElementsByTagName('head')[0]
|
|
1904
|
-
body = s.body = document.getElementsByTagName('body')[0]
|
|
1905
|
-
// If BASE tag is in play, using appendChild is a problem for IE6.
|
|
1906
|
-
// When that browser dies, this can be removed. Details in this jQuery bug:
|
|
1907
|
-
// http://dev.jquery.com/ticket/2709
|
|
1908
|
-
baseElement = document.getElementsByTagName('base')[0]
|
|
1909
|
-
if (baseElement) {
|
|
1910
|
-
head = s.head = baseElement.parentNode
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
|
|
1914
|
-
/**
|
|
1915
|
-
* Any errors that require explicitly generates will be passed to this
|
|
1916
|
-
* function. Intercept/override it if you want custom error handling.
|
|
1917
|
-
* @param {Error} err the error object.
|
|
1918
|
-
*/
|
|
1919
|
-
req.onError = defaultOnError
|
|
1920
|
-
|
|
1921
|
-
/**
|
|
1922
|
-
* Creates the node for the load command. Only used in browser envs.
|
|
1923
|
-
*/
|
|
1924
|
-
req.createNode = function (config, moduleName, url) {
|
|
1925
|
-
// get type css
|
|
1926
|
-
var type = ''
|
|
1927
|
-
try {
|
|
1928
|
-
const urls = url.split('?')
|
|
1929
|
-
if (urls[0].endsWith('.css')) type = 'css'
|
|
1930
|
-
} catch (error) {}
|
|
1931
|
-
|
|
1932
|
-
if (type === 'css') {
|
|
1933
|
-
// css
|
|
1934
|
-
var node = config.xhtml ? document.createElementNS('http://www.w3.org/1999/xhtml', 'html:link') : document.createElement('link')
|
|
1935
|
-
node.href = url
|
|
1936
|
-
node.rel = 'stylesheet'
|
|
1937
|
-
node.type = config.linkType || 'text/css'
|
|
1938
|
-
return node
|
|
1939
|
-
} else {
|
|
1940
|
-
var node = config.xhtml ? document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') : document.createElement('script')
|
|
1941
|
-
node.type = config.scriptType || 'text/javascript'
|
|
1942
|
-
node.charset = 'utf-8'
|
|
1943
|
-
node.async = false
|
|
1944
|
-
return node
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
/**
|
|
1949
|
-
* Does the request to load a module for the browser case.
|
|
1950
|
-
* Make this a separate function to allow other environments
|
|
1951
|
-
* to override it.
|
|
1952
|
-
*
|
|
1953
|
-
* @param {Object} context the require context to find state.
|
|
1954
|
-
* @param {String} moduleName the name of the module.
|
|
1955
|
-
* @param {Object} url the URL to the module.
|
|
1956
|
-
*/
|
|
1957
|
-
req.load = function (context, moduleName, url) {
|
|
1958
|
-
var config = (context && context.config) || {}
|
|
1959
|
-
var node
|
|
1960
|
-
if (isBrowser) {
|
|
1961
|
-
// In the browser so use a script tag
|
|
1962
|
-
node = req.createNode(config, moduleName, url)
|
|
1963
|
-
|
|
1964
|
-
node.setAttribute('data-requirecontext', context.contextName)
|
|
1965
|
-
node.setAttribute('data-requiremodule', moduleName)
|
|
1966
|
-
|
|
1967
|
-
// Set up load listener. Test attachEvent first because IE9 has
|
|
1968
|
-
// a subtle issue in its addEventListener and script onload firings
|
|
1969
|
-
// that do not match the behavior of all other browsers with
|
|
1970
|
-
// addEventListener support, which fire the onload event for a
|
|
1971
|
-
// script right after the script execution. See:
|
|
1972
|
-
// https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
|
|
1973
|
-
// UNFORTUNATELY Opera implements attachEvent but does not follow the script
|
|
1974
|
-
// script execution mode.
|
|
1975
|
-
if (
|
|
1976
|
-
node.attachEvent &&
|
|
1977
|
-
// Check if node.attachEvent is artificially added by custom script or
|
|
1978
|
-
// natively supported by browser
|
|
1979
|
-
// read https://github.com/requirejs/requirejs/issues/187
|
|
1980
|
-
// if we can NOT find [native code] then it must NOT natively supported.
|
|
1981
|
-
// in IE8, node.attachEvent does not have toString()
|
|
1982
|
-
// Note the test for "[native code" with no closing brace, see:
|
|
1983
|
-
// https://github.com/requirejs/requirejs/issues/273
|
|
1984
|
-
!(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) &&
|
|
1985
|
-
!isOpera
|
|
1986
|
-
) {
|
|
1987
|
-
// Probably IE. IE (at least 6-8) do not fire
|
|
1988
|
-
// script onload right after executing the script, so
|
|
1989
|
-
// we cannot tie the anonymous define call to a name.
|
|
1990
|
-
// However, IE reports the script as being in 'interactive'
|
|
1991
|
-
// readyState at the time of the define call.
|
|
1992
|
-
useInteractive = true
|
|
1993
|
-
|
|
1994
|
-
node.attachEvent('onreadystatechange', context.onScriptLoad)
|
|
1995
|
-
// It would be great to add an error handler here to catch
|
|
1996
|
-
// 404s in IE9+. However, onreadystatechange will fire before
|
|
1997
|
-
// the error handler, so that does not help. If addEventListener
|
|
1998
|
-
// is used, then IE will fire error before load, but we cannot
|
|
1999
|
-
// use that pathway given the connect.microsoft.com issue
|
|
2000
|
-
// mentioned above about not doing the 'script execute,
|
|
2001
|
-
// then fire the script load event listener before execute
|
|
2002
|
-
// next script' that other browsers do.
|
|
2003
|
-
// Best hope: IE10 fixes the issues,
|
|
2004
|
-
// and then destroys all installs of IE 6-9.
|
|
2005
|
-
// node.attachEvent('onerror', context.onScriptError);
|
|
2006
|
-
} else {
|
|
2007
|
-
node.addEventListener('load', context.onScriptLoad, false)
|
|
2008
|
-
node.addEventListener('error', context.onScriptError, false)
|
|
2009
|
-
}
|
|
2010
|
-
node.src = url
|
|
2011
|
-
|
|
2012
|
-
// Calling onNodeCreated after all properties on the node have been
|
|
2013
|
-
// set, but before it is placed in the DOM.
|
|
2014
|
-
if (config.onNodeCreated) {
|
|
2015
|
-
config.onNodeCreated(node, config, moduleName, url)
|
|
2016
|
-
}
|
|
2017
|
-
|
|
2018
|
-
// For some cache cases in IE 6-8, the script executes before the end
|
|
2019
|
-
// of the appendChild execution, so to tie an anonymous define
|
|
2020
|
-
// call to the module name (which is stored on the node), hold on
|
|
2021
|
-
// to a reference to this node, but clear after the DOM insertion.
|
|
2022
|
-
currentlyAddingScript = node
|
|
2023
|
-
if (baseElement) {
|
|
2024
|
-
head.insertBefore(node, baseElement)
|
|
2025
|
-
} else {
|
|
2026
|
-
// 微前端-阿里qiankun没有document.currentScript,webpack5生成异步chunk的访问地址404问题
|
|
2027
|
-
if (body) {
|
|
2028
|
-
body.appendChild(node)
|
|
2029
|
-
} else {
|
|
2030
|
-
head.appendChild(node)
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
currentlyAddingScript = null
|
|
2034
|
-
|
|
2035
|
-
return node
|
|
2036
|
-
} else if (isWebWorker) {
|
|
2037
|
-
try {
|
|
2038
|
-
// In a web worker, use importScripts. This is not a very
|
|
2039
|
-
// efficient use of importScripts, importScripts will block until
|
|
2040
|
-
// its script is downloaded and evaluated. However, if web workers
|
|
2041
|
-
// are in play, the expectation is that a build has been done so
|
|
2042
|
-
// that only one script needs to be loaded anyway. This may need
|
|
2043
|
-
// to be reevaluated if other use cases become common.
|
|
2044
|
-
|
|
2045
|
-
// Post a task to the event loop to work around a bug in WebKit
|
|
2046
|
-
// where the worker gets garbage-collected after calling
|
|
2047
|
-
// importScripts(): https://webkit.org/b/153317
|
|
2048
|
-
setTimeout(function () {}, 0)
|
|
2049
|
-
importScripts(url)
|
|
2050
|
-
|
|
2051
|
-
// Account for anonymous modules
|
|
2052
|
-
context.completeLoad(moduleName)
|
|
2053
|
-
} catch (e) {
|
|
2054
|
-
context.onError(makeError('importscripts', 'importScripts failed for ' + moduleName + ' at ' + url, e, [moduleName]))
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
function getInteractiveScript() {
|
|
2060
|
-
if (interactiveScript && interactiveScript.readyState === 'interactive') {
|
|
2061
|
-
return interactiveScript
|
|
2062
|
-
}
|
|
2063
|
-
|
|
2064
|
-
eachReverse(scripts(), function (script) {
|
|
2065
|
-
if (script.readyState === 'interactive') {
|
|
2066
|
-
return (interactiveScript = script)
|
|
2067
|
-
}
|
|
2068
|
-
})
|
|
2069
|
-
return interactiveScript
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
|
-
// Look for a data-main script attribute, which could also adjust the baseUrl.
|
|
2073
|
-
if (isBrowser && !cfg.skipDataMain) {
|
|
2074
|
-
// Figure out baseUrl. Get it from the script tag with require.js in it.
|
|
2075
|
-
eachReverse(scripts(), function (script) {
|
|
2076
|
-
// Set the 'head' where we can append children by
|
|
2077
|
-
// using the script's parent.
|
|
2078
|
-
if (!head) {
|
|
2079
|
-
head = script.parentNode
|
|
2080
|
-
}
|
|
2081
|
-
|
|
2082
|
-
// Look for a data-main attribute to set main script for the page
|
|
2083
|
-
// to load. If it is there, the path to data main becomes the
|
|
2084
|
-
// baseUrl, if it is not already set.
|
|
2085
|
-
dataMain = script.getAttribute('data-main')
|
|
2086
|
-
if (dataMain) {
|
|
2087
|
-
// Preserve dataMain in case it is a path (i.e. contains '?')
|
|
2088
|
-
mainScript = dataMain
|
|
2089
|
-
|
|
2090
|
-
// Set final baseUrl if there is not already an explicit one,
|
|
2091
|
-
// but only do so if the data-main value is not a loader plugin
|
|
2092
|
-
// module ID.
|
|
2093
|
-
if (!cfg.baseUrl && mainScript.indexOf('!') === -1) {
|
|
2094
|
-
// Pull off the directory of data-main for use as the
|
|
2095
|
-
// baseUrl.
|
|
2096
|
-
src = mainScript.split('/')
|
|
2097
|
-
mainScript = src.pop()
|
|
2098
|
-
subPath = src.length ? src.join('/') + '/' : './'
|
|
2099
|
-
|
|
2100
|
-
cfg.baseUrl = subPath
|
|
2101
|
-
}
|
|
2102
|
-
|
|
2103
|
-
// Strip off any trailing .js since mainScript is now
|
|
2104
|
-
// like a module name.
|
|
2105
|
-
mainScript = mainScript.replace(jsSuffixRegExp, '')
|
|
2106
|
-
|
|
2107
|
-
// If mainScript is still a path, fall back to dataMain
|
|
2108
|
-
if (req.jsExtRegExp.test(mainScript)) {
|
|
2109
|
-
mainScript = dataMain
|
|
2110
|
-
}
|
|
2111
|
-
|
|
2112
|
-
// Put the data-main script in the files to load.
|
|
2113
|
-
cfg.deps = cfg.deps ? cfg.deps.concat(mainScript) : [mainScript]
|
|
2114
|
-
|
|
2115
|
-
return true
|
|
2116
|
-
}
|
|
2117
|
-
})
|
|
2118
|
-
}
|
|
2119
|
-
|
|
2120
|
-
/**
|
|
2121
|
-
* The function that handles definitions of modules. Differs from
|
|
2122
|
-
* require() in that a string for the module should be the first argument,
|
|
2123
|
-
* and the function to execute after dependencies are loaded should
|
|
2124
|
-
* return a value to define the module corresponding to the first argument's
|
|
2125
|
-
* name.
|
|
2126
|
-
*/
|
|
2127
|
-
define = function (name, deps, callback) {
|
|
2128
|
-
var node, context
|
|
2129
|
-
|
|
2130
|
-
// Allow for anonymous modules
|
|
2131
|
-
if (typeof name !== 'string') {
|
|
2132
|
-
// Adjust args appropriately
|
|
2133
|
-
callback = deps
|
|
2134
|
-
deps = name
|
|
2135
|
-
name = null
|
|
2136
|
-
}
|
|
2137
|
-
|
|
2138
|
-
// This module may not have dependencies
|
|
2139
|
-
if (!isArray(deps)) {
|
|
2140
|
-
callback = deps
|
|
2141
|
-
deps = null
|
|
2142
|
-
}
|
|
2143
|
-
|
|
2144
|
-
// If no name, and callback is a function, then figure out if it a
|
|
2145
|
-
// CommonJS thing with dependencies.
|
|
2146
|
-
if (!deps && isFunction(callback)) {
|
|
2147
|
-
deps = []
|
|
2148
|
-
// Remove comments from the callback string,
|
|
2149
|
-
// look for require calls, and pull them into the dependencies,
|
|
2150
|
-
// but only if there are function args.
|
|
2151
|
-
if (callback.length) {
|
|
2152
|
-
callback
|
|
2153
|
-
.toString()
|
|
2154
|
-
.replace(commentRegExp, commentReplace)
|
|
2155
|
-
.replace(cjsRequireRegExp, (match, dep) => {
|
|
2156
|
-
deps.push(dep)
|
|
2157
|
-
})
|
|
2158
|
-
|
|
2159
|
-
// May be a CommonJS thing even without require calls, but still
|
|
2160
|
-
// could use exports, and module. Avoid doing exports and module
|
|
2161
|
-
// work though if it just needs require.
|
|
2162
|
-
// REQUIRES the function to expect the CommonJS variables in the
|
|
2163
|
-
// order listed below.
|
|
2164
|
-
deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps)
|
|
2165
|
-
}
|
|
2166
|
-
}
|
|
2167
|
-
|
|
2168
|
-
// If in IE 6-8 and hit an anonymous define() call, do the interactive
|
|
2169
|
-
// work.
|
|
2170
|
-
if (useInteractive) {
|
|
2171
|
-
node = currentlyAddingScript || getInteractiveScript()
|
|
2172
|
-
if (node) {
|
|
2173
|
-
if (!name) {
|
|
2174
|
-
name = node.getAttribute('data-requiremodule')
|
|
2175
|
-
}
|
|
2176
|
-
context = contexts[node.getAttribute('data-requirecontext')]
|
|
2177
|
-
}
|
|
2178
|
-
}
|
|
2179
|
-
|
|
2180
|
-
// Always save off evaluating the def call until the script onload handler.
|
|
2181
|
-
// This allows multiple modules to be in a file without prematurely
|
|
2182
|
-
// tracing dependencies, and allows for anonymous module support,
|
|
2183
|
-
// where the module name is not known until the script onload event
|
|
2184
|
-
// occurs. If no context, use the global queue, and get it processed
|
|
2185
|
-
// in the onscript load callback.
|
|
2186
|
-
if (context) {
|
|
2187
|
-
context.defQueue.push([name, deps, callback])
|
|
2188
|
-
context.defQueueMap[name] = true
|
|
2189
|
-
} else {
|
|
2190
|
-
globalDefQueue.push([name, deps, callback])
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2194
|
-
define.amd = {
|
|
2195
|
-
jQuery: true,
|
|
2196
|
-
}
|
|
2197
|
-
|
|
2198
|
-
/**
|
|
2199
|
-
* Executes the text. Normally just uses eval, but can be modified
|
|
2200
|
-
* to use a better, environment-specific call. Only used for transpiling
|
|
2201
|
-
* loader plugins, not for plain JS modules.
|
|
2202
|
-
* @param {String} text the text to execute/evaluate.
|
|
2203
|
-
*/
|
|
2204
|
-
req.exec = function (text) {
|
|
2205
|
-
/* jslint evil: true */
|
|
2206
|
-
// eslint-disable-next-line no-eval
|
|
2207
|
-
return eval(text)
|
|
2208
|
-
}
|
|
2209
|
-
__requirejs = __require = require
|
|
2210
|
-
__define = define
|
|
2211
|
-
// Set up with config info.
|
|
2212
|
-
req(cfg)
|
|
2213
|
-
})(this, typeof setTimeout === 'undefined' ? undefined : setTimeout)
|
|
2214
|
-
|
|
2215
|
-
/* ----------------------------------------------------------------------------
|
|
2216
|
-
* 以下为本地适配层,不属于 RequireJS 原始文件内容。
|
|
2217
|
-
* -------------------------------------------------------------------------- */
|
|
2218
|
-
;(function (global) {
|
|
2219
|
-
var varName = '__devfab'
|
|
2220
|
-
window[varName] = window[varName] || {}
|
|
2221
|
-
if (global[varName].__requirejsAdapterApplied) {
|
|
2222
|
-
return
|
|
2223
|
-
}
|
|
2224
|
-
global[varName].__requirejsAdapterApplied = true
|
|
2225
|
-
|
|
2226
|
-
var rawRequire = __require
|
|
2227
|
-
var rawDefine = __define
|
|
2228
|
-
|
|
2229
|
-
const loadModule = function (domain, deps, callback, errback) {
|
|
2230
|
-
if (typeof domain === 'function') {
|
|
2231
|
-
domain()
|
|
2232
|
-
return
|
|
2233
|
-
}
|
|
2234
|
-
if (Array.isArray(domain) && Array.isArray(deps)) {
|
|
2235
|
-
domain = domain.join('/')
|
|
2236
|
-
} else if (Array.isArray(domain)) {
|
|
2237
|
-
errback = arguments[2]
|
|
2238
|
-
callback = arguments[1]
|
|
2239
|
-
deps = arguments[0]
|
|
2240
|
-
domain = null
|
|
2241
|
-
}
|
|
2242
|
-
if (!Array.isArray(deps)) {
|
|
2243
|
-
deps?.()
|
|
2244
|
-
return
|
|
2245
|
-
}
|
|
2246
|
-
var args = []
|
|
2247
|
-
// if (!domain) domain = cb.loader?.domainKey || domain
|
|
2248
|
-
// var req = (domain && cb.extend.Scripts && cb.extend.Scripts[domain]) || (cb && cb.businessContext)
|
|
2249
|
-
// if (!req) {
|
|
2250
|
-
// if (domain) {
|
|
2251
|
-
// cb.console.warn(Error.E01005, 'cb.utils.loadModule:Business context not initialized!', domain)
|
|
2252
|
-
// callback.apply(this, args)
|
|
2253
|
-
// return
|
|
2254
|
-
// }
|
|
2255
|
-
// throw new Error('cb.utils.loadModule:Business context not initialized!')
|
|
2256
|
-
// }
|
|
2257
|
-
try {
|
|
2258
|
-
for (const item of deps) {
|
|
2259
|
-
const res = req('./' + item)
|
|
2260
|
-
args.push(res)
|
|
2261
|
-
}
|
|
2262
|
-
} catch (error) {
|
|
2263
|
-
console.warn(`[requirejs][loadModule]: module requires error, deps is `, deps, error)
|
|
2264
|
-
if (errback) errback(error)
|
|
2265
|
-
return
|
|
2266
|
-
}
|
|
2267
|
-
callback.apply(this, args)
|
|
2268
|
-
}
|
|
2269
|
-
|
|
2270
|
-
const require = function (domain, deps, callback, errback) {
|
|
2271
|
-
if (!domain) {
|
|
2272
|
-
console.debug('[require]: %c [requirejs] [require()] loadModule, Parameter[domain] is %o', 'color:fuchsia', domain)
|
|
2273
|
-
loadModule(domain, deps, callback, errback)
|
|
2274
|
-
return
|
|
2275
|
-
}
|
|
2276
|
-
if (Array.isArray(domain) && Array.isArray(deps)) {
|
|
2277
|
-
domain = domain.join('/')
|
|
2278
|
-
}
|
|
2279
|
-
var newdeps = []
|
|
2280
|
-
if (Array.isArray(deps)) {
|
|
2281
|
-
deps.forEach(function (item) {
|
|
2282
|
-
newdeps.push(`${domain}${item.substr(0, 1) === '/' ? '' : '/'}${item}`)
|
|
2283
|
-
})
|
|
2284
|
-
}
|
|
2285
|
-
console.debug('[requirejs]: %c requireInner, Parameter[newdeps] is %o', 'color:fuchsia', newdeps)
|
|
2286
|
-
rawRequire(newdeps, callback, errback)
|
|
2287
|
-
}
|
|
2288
|
-
|
|
2289
|
-
const define = function (domain, deps, callback) {
|
|
2290
|
-
if (!domain) {
|
|
2291
|
-
loadModule(domain, deps, callback)
|
|
2292
|
-
return
|
|
2293
|
-
}
|
|
2294
|
-
if (Array.isArray(domain) && Array.isArray(deps)) {
|
|
2295
|
-
domain = domain.join('/')
|
|
2296
|
-
}
|
|
2297
|
-
var newdeps = []
|
|
2298
|
-
if (Array.isArray(deps)) {
|
|
2299
|
-
deps.forEach(function (item) {
|
|
2300
|
-
newdeps.push(`${domain}${item.substr(0, 1) === '/' ? '' : '/'}${item}`)
|
|
2301
|
-
})
|
|
2302
|
-
}
|
|
2303
|
-
rawDefine(newdeps, callback)
|
|
2304
|
-
}
|
|
2305
|
-
|
|
2306
|
-
// 应用根目录,绝对地址、以 / 结尾。require 与 define 都要用,只算一次
|
|
2307
|
-
// var baseUrl = resolveBaseUrl()
|
|
2308
|
-
|
|
2309
|
-
// // http://host/a/b/extendjs/requirejs.js -> http://host/a/b/extendjs/
|
|
2310
|
-
// // baseUrl 指向「扩展脚本根目录」(extendjs/),扩展脚本按 <baseUrl><domain>/<file>
|
|
2311
|
-
// // 解析,也就是全都收在 extendjs/ 下:
|
|
2312
|
-
// // 无业务域 -> extendjs/test_VM.Extend.js
|
|
2313
|
-
// // 有业务域 -> extendjs/<domain>/test_VM.Extend.js
|
|
2314
|
-
// // 必须用绝对地址:history 模式下深链接刷新(/wfm/xxx)时 './' 会被解析成 /wfm/,
|
|
2315
|
-
// // 扩展脚本会 404
|
|
2316
|
-
// function resolveBaseUrl() {
|
|
2317
|
-
// var scripts = document.getElementsByTagName('script')
|
|
2318
|
-
// for (var i = scripts.length - 1; i >= 0; i--) {
|
|
2319
|
-
// var src = scripts[i].src || ''
|
|
2320
|
-
// var matched = /^(.*\/extendjs\/)requirejs(\.min)?\.js([?#]|$)/.exec(src)
|
|
2321
|
-
// if (matched) {
|
|
2322
|
-
// return matched[1]
|
|
2323
|
-
// }
|
|
2324
|
-
// }
|
|
2325
|
-
// return './'
|
|
2326
|
-
// }
|
|
2327
|
-
|
|
2328
|
-
// // domain + 文件名 -> 模块 id 列表,绝对路径/带协议的直接透传
|
|
2329
|
-
// function toIdList(domain, files) {
|
|
2330
|
-
// var prefix = domain ? String(domain).replace(/\/+$/, '') : ''
|
|
2331
|
-
// var list = Array.isArray(files) ? files : files ? [files] : []
|
|
2332
|
-
// return list.map(function (file) {
|
|
2333
|
-
// if (/^(\/|[a-zA-Z][\w+.-]*:)/.test(file)) {
|
|
2334
|
-
// return file
|
|
2335
|
-
// }
|
|
2336
|
-
// return prefix ? prefix + '/' + file : file
|
|
2337
|
-
// })
|
|
2338
|
-
// }
|
|
2339
|
-
|
|
2340
|
-
// // 正在执行的脚本地址。RequireJS 是 createNode + appendChild 注入 script,
|
|
2341
|
-
// // 脚本执行期间 document.currentScript 就指向它自己。
|
|
2342
|
-
// // 拿不到时返回空串,由调用方退化为匿名 define —— 不要用 scripts[length-1]
|
|
2343
|
-
// // 去猜,那个多半是 requirejs.js 自己,猜出来的 id 是错的。
|
|
2344
|
-
// function currentScriptSrc() {
|
|
2345
|
-
// var node = document.currentScript
|
|
2346
|
-
// return (node && node.src) || ''
|
|
2347
|
-
// }
|
|
2348
|
-
|
|
2349
|
-
// // 脚本地址 -> 相对 baseUrl 的模块 id
|
|
2350
|
-
// // http://host/a/extendjs/test_VM.Extend.js?t=1 -> 'extendjs/test_VM.Extend.js'
|
|
2351
|
-
// function toModuleId(src) {
|
|
2352
|
-
// if (!src) {
|
|
2353
|
-
// return ''
|
|
2354
|
-
// }
|
|
2355
|
-
// // 去掉 query 与 hash(dev 模式下 require 会带 ?t= 时间戳)
|
|
2356
|
-
// // 截掉「协议 + 域名」只留 pathname,方便和 baseUrl 做前缀比较
|
|
2357
|
-
// function pathnameOf(url) {
|
|
2358
|
-
// url = String(url).replace(/[?#].*$/, '')
|
|
2359
|
-
// var mark = url.indexOf('://')
|
|
2360
|
-
// return mark > -1 ? url.slice(url.indexOf('/', mark + 3)) : url
|
|
2361
|
-
// }
|
|
2362
|
-
// var path = pathnameOf(src)
|
|
2363
|
-
// var basePath = pathnameOf(baseUrl)
|
|
2364
|
-
// if (basePath && path.indexOf(basePath) === 0) {
|
|
2365
|
-
// path = path.slice(basePath.length)
|
|
2366
|
-
// }
|
|
2367
|
-
// return path.replace(/^\/+/, '')
|
|
2368
|
-
// }
|
|
2369
|
-
|
|
2370
|
-
// // 常见误写识别:define(['<domain>'], factory) —— 把 domain 写进了依赖数组。
|
|
2371
|
-
// // 这是合法的 AMD 匿名 define + 依赖,RequireJS 会去请求 <baseUrl><domain>.js,
|
|
2372
|
-
// // 拿不到就报 'Script error for "<domain>"',表现非常像「扩展脚本没加载到」。
|
|
2373
|
-
// // 只在「依赖名恰好等于脚本自身所在目录名」时才提示,避免误报。
|
|
2374
|
-
// function warnIfDomainAsDep(id) {
|
|
2375
|
-
// if (!Array.isArray(id) || !id.length) {
|
|
2376
|
-
// return
|
|
2377
|
-
// }
|
|
2378
|
-
// var file = toModuleId(currentScriptSrc())
|
|
2379
|
-
// var cut = file.indexOf('/')
|
|
2380
|
-
// var dir = cut > -1 ? file.slice(0, cut) : ''
|
|
2381
|
-
// if (!dir) {
|
|
2382
|
-
// return
|
|
2383
|
-
// }
|
|
2384
|
-
// for (var i = 0; i < id.length; i++) {
|
|
2385
|
-
// if (typeof id[i] === 'string' && id[i] === dir) {
|
|
2386
|
-
// console.warn(
|
|
2387
|
-
// '[devfab.define] 依赖 [' +
|
|
2388
|
-
// id[i] +
|
|
2389
|
-
// '] 与脚本所在目录同名,多半是想写 domain:第一个参数要传字符串,' +
|
|
2390
|
-
// "即 define('" +
|
|
2391
|
-
// id[i] +
|
|
2392
|
-
// "', [...], factory);或直接用匿名 define([], factory)。" +
|
|
2393
|
-
// '当前写法会让 RequireJS 去加载 ' +
|
|
2394
|
-
// dir +
|
|
2395
|
-
// '.js 并报 Script error。'
|
|
2396
|
-
// )
|
|
2397
|
-
// return
|
|
2398
|
-
// }
|
|
2399
|
-
// }
|
|
2400
|
-
// }
|
|
2401
|
-
|
|
2402
|
-
// // define 适配,两种写法都支持:
|
|
2403
|
-
// // define(domain, [deps], factory) 模块 id = '<domain>/<脚本相对路径>'
|
|
2404
|
-
// // define(domain, file, [deps], factory) 模块 id = '<domain>/<file>'
|
|
2405
|
-
// // 只有「非字符串 id」(匿名 define)和「以 .js 结尾的 id」(RequireJS 原生具名写法,
|
|
2406
|
-
// // 兼容方案 B 那版 'extendjs/xxx.Extend.js')原样透传;其余字符串一律当 domain,
|
|
2407
|
-
// // 这样 'hr/wfm' 这种多级 domain 也能用。
|
|
2408
|
-
// function domainDefine(id, deps, factory) {
|
|
2409
|
-
// if (typeof id !== 'string' || /\.js([?#]|$)/.test(id)) {
|
|
2410
|
-
// warnIfDomainAsDep(id)
|
|
2411
|
-
// return rawDefine.apply(this, arguments)
|
|
2412
|
-
// }
|
|
2413
|
-
// var domain = id.replace(/\/+$/, '')
|
|
2414
|
-
|
|
2415
|
-
// // define(domain, file, [deps], factory)
|
|
2416
|
-
// if (typeof deps === 'string') {
|
|
2417
|
-
// var explicit = deps
|
|
2418
|
-
// // 允许 file 已经带了 domain 前缀,避免拼成 'x/x/y.js'
|
|
2419
|
-
// if (explicit.indexOf(domain + '/') !== 0) {
|
|
2420
|
-
// explicit = domain + '/' + explicit
|
|
2421
|
-
// }
|
|
2422
|
-
// return rawDefine(explicit, factory, arguments[3])
|
|
2423
|
-
// }
|
|
2424
|
-
|
|
2425
|
-
// // toModuleId 返回的是「相对 baseUrl 的完整路径」,本身就已经包含了 domain 这一段
|
|
2426
|
-
// // (脚本放在 <baseUrl><domain>/ 下),所以这里直接用,不能再拼一次 domain
|
|
2427
|
-
// var file = toModuleId(currentScriptSrc())
|
|
2428
|
-
// if (file) {
|
|
2429
|
-
// if (file.indexOf(domain) !== 0) {
|
|
2430
|
-
// console.warn('[devfab.define] domain "' + id + '" 与脚本实际地址 "' + file + '" 对不上,请把扩展脚本放到 ' + domain + '/ 目录下')
|
|
2431
|
-
// }
|
|
2432
|
-
// return rawDefine(file, deps, factory)
|
|
2433
|
-
// }
|
|
2434
|
-
|
|
2435
|
-
// // 拿不到脚本地址(内联脚本等):退化为匿名 define,
|
|
2436
|
-
// // 由 RequireJS 按加载它的 script 上的 data-requiremodule 命名
|
|
2437
|
-
// console.warn('[devfab.define] 无法从脚本地址推断模块路径,已退化为匿名 define:' + id)
|
|
2438
|
-
// return typeof deps === 'function' || deps === undefined || deps === null ? rawDefine(deps) : rawDefine(deps, factory)
|
|
2439
|
-
// }
|
|
2440
|
-
// // 有些库靠 define.amd 判断是否 AMD 环境,包装后要保留
|
|
2441
|
-
// domainDefine.amd = rawDefine.amd
|
|
2442
|
-
|
|
2443
|
-
// function domainRequire(domain, deps, success, fail) {
|
|
2444
|
-
// // 非生产环境(window.__EXTEND_DEV__ 由 index.html 注入):每次加载都带上时间戳,
|
|
2445
|
-
// // 保证改了扩展脚本后刷新页面拿到的一定是新文件,而不是浏览器缓存里的旧版本
|
|
2446
|
-
// if (global.__EXTEND_DEV__) {
|
|
2447
|
-
// rawRequire.config({ urlArgs: 't=' + Date.now() })
|
|
2448
|
-
// }
|
|
2449
|
-
// // 原生签名:require(deps, callback, errback)
|
|
2450
|
-
// if (typeof domain !== 'string') {
|
|
2451
|
-
// return rawRequire(domain, deps, success)
|
|
2452
|
-
// }
|
|
2453
|
-
// // 老签名:require(domain, files, success, fail)
|
|
2454
|
-
// return rawRequire(toIdList(domain, deps), success, fail)
|
|
2455
|
-
// }
|
|
2456
|
-
|
|
2457
|
-
// rawRequire.config({
|
|
2458
|
-
// baseUrl: baseUrl,
|
|
2459
|
-
// nodeIdCompat: true,
|
|
2460
|
-
// })
|
|
2461
|
-
|
|
2462
|
-
// config / toUrl / defined / specified / undef 这些挂在原生 require 上,要跟着搬走
|
|
2463
|
-
// Object.keys(rawRequire).forEach(function (key) {
|
|
2464
|
-
// domainRequire[key] = rawRequire[key]
|
|
2465
|
-
// })
|
|
2466
|
-
// domainRequire.toIdList = toIdList
|
|
2467
|
-
// domainDefine.toModuleId = toModuleId
|
|
2468
|
-
|
|
2469
|
-
global[varName].requireInner = rawRequire
|
|
2470
|
-
global[varName].defineInner = rawDefine
|
|
2471
|
-
global[varName].require = require
|
|
2472
|
-
global[varName].define = define
|
|
2473
|
-
})(typeof window === 'undefined' ? this : window)
|