devfab 1.5.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/lib/devfab.js +4188 -1073
- 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 +10 -5
- 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 -2286
|
@@ -0,0 +1,3285 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.devfab = global.devfab || {}, global.devfab.require = {})));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function _assertThisInitialized(e) {
|
|
8
|
+
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
function _callSuper(t, o, e) {
|
|
12
|
+
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
13
|
+
}
|
|
14
|
+
function _classCallCheck(a, n) {
|
|
15
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
16
|
+
}
|
|
17
|
+
function _defineProperties(e, r) {
|
|
18
|
+
for (var t = 0; t < r.length; t++) {
|
|
19
|
+
var o = r[t];
|
|
20
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _createClass(e, r, t) {
|
|
24
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
25
|
+
writable: !1
|
|
26
|
+
}), e;
|
|
27
|
+
}
|
|
28
|
+
function _defineProperty(e, r, t) {
|
|
29
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
30
|
+
value: t,
|
|
31
|
+
enumerable: !0,
|
|
32
|
+
configurable: !0,
|
|
33
|
+
writable: !0
|
|
34
|
+
}) : e[r] = t, e;
|
|
35
|
+
}
|
|
36
|
+
function _getPrototypeOf(t) {
|
|
37
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
38
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
39
|
+
}, _getPrototypeOf(t);
|
|
40
|
+
}
|
|
41
|
+
function _inherits(t, e) {
|
|
42
|
+
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
43
|
+
t.prototype = Object.create(e && e.prototype, {
|
|
44
|
+
constructor: {
|
|
45
|
+
value: t,
|
|
46
|
+
writable: !0,
|
|
47
|
+
configurable: !0
|
|
48
|
+
}
|
|
49
|
+
}), Object.defineProperty(t, "prototype", {
|
|
50
|
+
writable: !1
|
|
51
|
+
}), e && _setPrototypeOf(t, e);
|
|
52
|
+
}
|
|
53
|
+
function _isNativeReflectConstruct() {
|
|
54
|
+
try {
|
|
55
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
56
|
+
} catch (t) {}
|
|
57
|
+
return (_isNativeReflectConstruct = function () {
|
|
58
|
+
return !!t;
|
|
59
|
+
})();
|
|
60
|
+
}
|
|
61
|
+
function ownKeys(e, r) {
|
|
62
|
+
var t = Object.keys(e);
|
|
63
|
+
if (Object.getOwnPropertySymbols) {
|
|
64
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
65
|
+
r && (o = o.filter(function (r) {
|
|
66
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
67
|
+
})), t.push.apply(t, o);
|
|
68
|
+
}
|
|
69
|
+
return t;
|
|
70
|
+
}
|
|
71
|
+
function _objectSpread2(e) {
|
|
72
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
73
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
74
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
75
|
+
_defineProperty(e, r, t[r]);
|
|
76
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
77
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return e;
|
|
81
|
+
}
|
|
82
|
+
function _possibleConstructorReturn(t, e) {
|
|
83
|
+
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
|
84
|
+
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
85
|
+
return _assertThisInitialized(t);
|
|
86
|
+
}
|
|
87
|
+
function _setPrototypeOf(t, e) {
|
|
88
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
89
|
+
return t.__proto__ = e, t;
|
|
90
|
+
}, _setPrototypeOf(t, e);
|
|
91
|
+
}
|
|
92
|
+
function _toPrimitive(t, r) {
|
|
93
|
+
if ("object" != typeof t || !t) return t;
|
|
94
|
+
var e = t[Symbol.toPrimitive];
|
|
95
|
+
if (void 0 !== e) {
|
|
96
|
+
var i = e.call(t, r || "default");
|
|
97
|
+
if ("object" != typeof i) return i;
|
|
98
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
99
|
+
}
|
|
100
|
+
return ("string" === r ? String : Number)(t);
|
|
101
|
+
}
|
|
102
|
+
function _toPropertyKey(t) {
|
|
103
|
+
var i = _toPrimitive(t, "string");
|
|
104
|
+
return "symbol" == typeof i ? i : i + "";
|
|
105
|
+
}
|
|
106
|
+
function _typeof(o) {
|
|
107
|
+
"@babel/helpers - typeof";
|
|
108
|
+
|
|
109
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
110
|
+
return typeof o;
|
|
111
|
+
} : function (o) {
|
|
112
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
113
|
+
}, _typeof(o);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
117
|
+
|
|
118
|
+
// ======================================================
|
|
119
|
+
/** vim: et:ts=4:sw=4:sts=4
|
|
120
|
+
* @license RequireJS 2.3.2 Copyright jQuery Foundation and other contributors.
|
|
121
|
+
* Released under MIT license, https://github.com/requirejs/requirejs/blob/master/LICENSE
|
|
122
|
+
*/
|
|
123
|
+
// Not using strict: uneven strict support in browsers, #392, and causes
|
|
124
|
+
// problems with requirejs.exec()/transpiler plugins that may not be strict.
|
|
125
|
+
/* jslint regexp: true, nomen: true, sloppy: true */
|
|
126
|
+
/* global window, navigator, document, importScripts, setTimeout, opera */
|
|
127
|
+
var __devfab_requirejs = {};
|
|
128
|
+
window.__devfab_requirejs = __devfab_requirejs;
|
|
129
|
+
(function (global, setTimeout) {
|
|
130
|
+
var requirejs, require, define;
|
|
131
|
+
var req;
|
|
132
|
+
var s;
|
|
133
|
+
var head;
|
|
134
|
+
var baseElement;
|
|
135
|
+
var dataMain;
|
|
136
|
+
var src;
|
|
137
|
+
var body;
|
|
138
|
+
var interactiveScript;
|
|
139
|
+
var currentlyAddingScript;
|
|
140
|
+
var mainScript;
|
|
141
|
+
var subPath;
|
|
142
|
+
var version = '2.3.2';
|
|
143
|
+
var commentRegExp = /\/\*[\s\S]*?\*\/|([^:"'=]|^)\/\/.*$/gm;
|
|
144
|
+
var cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g;
|
|
145
|
+
var jsSuffixRegExp = /\.js$/;
|
|
146
|
+
var currDirRegExp = /^\.\//;
|
|
147
|
+
var op = Object.prototype;
|
|
148
|
+
var ostring = op.toString;
|
|
149
|
+
var hasOwn = op.hasOwnProperty;
|
|
150
|
+
var isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
|
|
151
|
+
var isWebWorker = !isBrowser && typeof importScripts !== 'undefined';
|
|
152
|
+
// PS3 indicates loaded and complete, but need to wait for complete
|
|
153
|
+
// specifically. Sequence is 'loading', 'loaded', execution,
|
|
154
|
+
// then 'complete'. The UA check is unfortunate, but not sure how
|
|
155
|
+
// to feature test w/o causing perf issues.
|
|
156
|
+
var readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ? /^complete$/ : /^(complete|loaded)$/;
|
|
157
|
+
var defContextName = '_';
|
|
158
|
+
// Oh the tragedy, detecting opera. See the usage of isOpera for reason.
|
|
159
|
+
var isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]';
|
|
160
|
+
var contexts = {};
|
|
161
|
+
var cfg = {};
|
|
162
|
+
var globalDefQueue = [];
|
|
163
|
+
var useInteractive = false;
|
|
164
|
+
|
|
165
|
+
// Could match something like ')//comment', do not lose the prefix to comment.
|
|
166
|
+
function commentReplace(match, singlePrefix) {
|
|
167
|
+
return singlePrefix || '';
|
|
168
|
+
}
|
|
169
|
+
function isFunction(it) {
|
|
170
|
+
return ostring.call(it) === '[object Function]';
|
|
171
|
+
}
|
|
172
|
+
function isArray(it) {
|
|
173
|
+
return ostring.call(it) === '[object Array]';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Helper function for iterating over an array. If the func returns
|
|
178
|
+
* a true value, it will break out of the loop.
|
|
179
|
+
*/
|
|
180
|
+
function each(ary, func) {
|
|
181
|
+
if (ary) {
|
|
182
|
+
var i;
|
|
183
|
+
for (i = 0; i < ary.length; i += 1) {
|
|
184
|
+
// checkmark:disable-line
|
|
185
|
+
if (ary[i] && func(ary[i], i, ary)) {
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Helper function for iterating over an array backwards. If the func
|
|
194
|
+
* returns a true value, it will break out of the loop.
|
|
195
|
+
*/
|
|
196
|
+
function eachReverse(ary, func) {
|
|
197
|
+
if (ary) {
|
|
198
|
+
var i;
|
|
199
|
+
for (i = ary.length - 1; i > -1; i -= 1) {
|
|
200
|
+
if (ary[i] && func(ary[i], i, ary)) {
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function hasProp(obj, prop) {
|
|
207
|
+
return hasOwn.call(obj, prop);
|
|
208
|
+
}
|
|
209
|
+
function getOwn(obj, prop) {
|
|
210
|
+
return hasProp(obj, prop) && obj[prop];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Cycles over properties in an object and calls a function for each
|
|
215
|
+
* property value. If the function returns a truthy value, then the
|
|
216
|
+
* iteration is stopped.
|
|
217
|
+
*/
|
|
218
|
+
function eachProp(obj, func) {
|
|
219
|
+
var prop;
|
|
220
|
+
for (prop in obj) {
|
|
221
|
+
if (hasProp(obj, prop)) {
|
|
222
|
+
if (func(obj[prop], prop)) {
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Simple function to mix in properties from source into target,
|
|
231
|
+
* but only if target does not already have a property of the same name.
|
|
232
|
+
*/
|
|
233
|
+
function mixin(target, source, force, deepStringMixin) {
|
|
234
|
+
if (source) {
|
|
235
|
+
eachProp(source, function (value, prop) {
|
|
236
|
+
if (force || !hasProp(target, prop)) {
|
|
237
|
+
if (deepStringMixin && _typeof(value) === 'object' && value && !isArray(value) && !isFunction(value) && !(value instanceof RegExp)) {
|
|
238
|
+
if (!target[prop]) {
|
|
239
|
+
target[prop] = {};
|
|
240
|
+
}
|
|
241
|
+
mixin(target[prop], value, force, deepStringMixin);
|
|
242
|
+
} else {
|
|
243
|
+
target[prop] = value;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return target;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Similar to Function.prototype.bind, but the 'this' object is specified
|
|
252
|
+
// first, since it is easier to read/figure out what 'this' will be.
|
|
253
|
+
function bind(obj, fn) {
|
|
254
|
+
return function () {
|
|
255
|
+
return fn.apply(obj, arguments);
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function scripts() {
|
|
259
|
+
return document.getElementsByTagName('script');
|
|
260
|
+
}
|
|
261
|
+
function defaultOnError(err) {
|
|
262
|
+
throw err;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Allow getting a global that is expressed in
|
|
266
|
+
// dot notation, like 'a.b.c'.
|
|
267
|
+
function getGlobal(value) {
|
|
268
|
+
if (!value) {
|
|
269
|
+
return value;
|
|
270
|
+
}
|
|
271
|
+
var g = global;
|
|
272
|
+
each(value.split('.'), function (part) {
|
|
273
|
+
g = g[part];
|
|
274
|
+
});
|
|
275
|
+
return g;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Constructs an error with a pointer to an URL with more information.
|
|
280
|
+
* @param {String} id the error ID that maps to an ID on a web page.
|
|
281
|
+
* @param {String} message human readable error.
|
|
282
|
+
* @param {Error} [err] the original error, if there is one.
|
|
283
|
+
*
|
|
284
|
+
* @returns {Error}
|
|
285
|
+
*/
|
|
286
|
+
function makeError(id, msg, err, requireModules) {
|
|
287
|
+
var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
|
|
288
|
+
e.requireType = id;
|
|
289
|
+
e.requireModules = requireModules;
|
|
290
|
+
if (err) {
|
|
291
|
+
e.originalError = err;
|
|
292
|
+
}
|
|
293
|
+
return e;
|
|
294
|
+
}
|
|
295
|
+
if (typeof define !== 'undefined') {
|
|
296
|
+
// If a define is already in play via another AMD loader,
|
|
297
|
+
// do not overwrite.
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (typeof requirejs !== 'undefined') {
|
|
301
|
+
if (isFunction(requirejs)) {
|
|
302
|
+
// Do not overwrite an existing requirejs instance.
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
cfg = requirejs;
|
|
306
|
+
requirejs = undefined;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Allow for a require config object
|
|
310
|
+
if (typeof require !== 'undefined' && !isFunction(require)) {
|
|
311
|
+
// assume it is a config object.
|
|
312
|
+
cfg = require;
|
|
313
|
+
require = undefined;
|
|
314
|
+
}
|
|
315
|
+
function newContext(contextName) {
|
|
316
|
+
var contextOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
317
|
+
var inCheckLoaded;
|
|
318
|
+
var Module;
|
|
319
|
+
var context;
|
|
320
|
+
var handlers;
|
|
321
|
+
var checkLoadedTimeoutId;
|
|
322
|
+
var _config = {
|
|
323
|
+
// Defaults. Do not set a default for map
|
|
324
|
+
// config to speed up normalize(), which
|
|
325
|
+
// will run faster if there is no default.
|
|
326
|
+
waitSeconds: contextOptions.waitSeconds || 30,
|
|
327
|
+
baseUrl: './',
|
|
328
|
+
paths: {},
|
|
329
|
+
bundles: {},
|
|
330
|
+
pkgs: {},
|
|
331
|
+
shim: {},
|
|
332
|
+
config: {}
|
|
333
|
+
};
|
|
334
|
+
var registry = {};
|
|
335
|
+
// registry of just enabled modules, to speed
|
|
336
|
+
// cycle breaking code when lots of modules
|
|
337
|
+
// are registered, but not activated.
|
|
338
|
+
var enabledRegistry = {};
|
|
339
|
+
var undefEvents = {};
|
|
340
|
+
var defQueue = [];
|
|
341
|
+
var _defined = {};
|
|
342
|
+
var urlFetched = {};
|
|
343
|
+
var bundlesMap = {};
|
|
344
|
+
var requireCounter = 1;
|
|
345
|
+
var unnormalizedCounter = 1;
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Trims the . and .. from an array of path segments.
|
|
349
|
+
* It will keep a leading path segment if a .. will become
|
|
350
|
+
* the first path segment, to help with module name lookups,
|
|
351
|
+
* which act like paths, but can be remapped. But the end result,
|
|
352
|
+
* all paths that use this function should look normalized.
|
|
353
|
+
* NOTE: this method MODIFIES the input array.
|
|
354
|
+
* @param {Array} ary the array of path segments.
|
|
355
|
+
*/
|
|
356
|
+
function trimDots(ary) {
|
|
357
|
+
var i, part;
|
|
358
|
+
for (i = 0; i < ary.length; i++) {
|
|
359
|
+
part = ary[i];
|
|
360
|
+
if (part === '.') {
|
|
361
|
+
ary.splice(i, 1);
|
|
362
|
+
i -= 1;
|
|
363
|
+
} else if (part === '..') {
|
|
364
|
+
// If at the start, or previous value is still ..,
|
|
365
|
+
// keep them so that when converted to a path it may
|
|
366
|
+
// still work when converted to a path, even though
|
|
367
|
+
// as an ID it is less than ideal. In larger point
|
|
368
|
+
// releases, may be better to just kick out an error.
|
|
369
|
+
if (i === 0 || i === 1 && ary[2] === '..' || ary[i - 1] === '..') {
|
|
370
|
+
continue;
|
|
371
|
+
} else if (i > 0) {
|
|
372
|
+
ary.splice(i - 1, 2);
|
|
373
|
+
i -= 2;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Given a relative module name, like ./something, normalize it to
|
|
381
|
+
* a real name that can be mapped to a path.
|
|
382
|
+
* @param {String} name the relative name
|
|
383
|
+
* @param {String} baseName a real name that the name arg is relative
|
|
384
|
+
* to.
|
|
385
|
+
* @param {Boolean} applyMap apply the map config to the value. Should
|
|
386
|
+
* only be done if this normalization is for a dependency ID.
|
|
387
|
+
* @returns {String} normalized name
|
|
388
|
+
*/
|
|
389
|
+
function normalize(name, baseName, applyMap) {
|
|
390
|
+
var pkgMain;
|
|
391
|
+
var mapValue;
|
|
392
|
+
var nameParts;
|
|
393
|
+
var i;
|
|
394
|
+
var j;
|
|
395
|
+
var nameSegment;
|
|
396
|
+
var lastIndex;
|
|
397
|
+
var foundMap;
|
|
398
|
+
var foundI;
|
|
399
|
+
var foundStarMap;
|
|
400
|
+
var starI;
|
|
401
|
+
var normalizedBaseParts;
|
|
402
|
+
var baseParts = baseName && baseName.split('/');
|
|
403
|
+
var map = _config.map;
|
|
404
|
+
var starMap = map && map['*'];
|
|
405
|
+
|
|
406
|
+
// Adjust any relative paths.
|
|
407
|
+
if (name) {
|
|
408
|
+
name = name.split('/');
|
|
409
|
+
lastIndex = name.length - 1;
|
|
410
|
+
|
|
411
|
+
// If wanting node ID compatibility, strip .js from end
|
|
412
|
+
// of IDs. Have to do this here, and not in nameToUrl
|
|
413
|
+
// because node allows either .js or non .js to map
|
|
414
|
+
// to same file.
|
|
415
|
+
if (_config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
|
|
416
|
+
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// Starts with a '.' so need the baseName
|
|
420
|
+
if (name[0].charAt(0) === '.' && baseParts) {
|
|
421
|
+
// Convert baseName to array, and lop off the last part,
|
|
422
|
+
// so that . matches that 'directory' and not name of the baseName's
|
|
423
|
+
// module. For instance, baseName of 'one/two/three', maps to
|
|
424
|
+
// 'one/two/three.js', but we want the directory, 'one/two' for
|
|
425
|
+
// this normalization.
|
|
426
|
+
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
|
|
427
|
+
name = normalizedBaseParts.concat(name);
|
|
428
|
+
}
|
|
429
|
+
trimDots(name);
|
|
430
|
+
name = name.join('/');
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Apply map config if available.
|
|
434
|
+
if (applyMap && map && (baseParts || starMap)) {
|
|
435
|
+
nameParts = name.split('/');
|
|
436
|
+
for (i = nameParts.length; i > 0; i -= 1) {
|
|
437
|
+
nameSegment = nameParts.slice(0, i).join('/');
|
|
438
|
+
if (baseParts) {
|
|
439
|
+
// Find the longest baseName segment match in the config.
|
|
440
|
+
// So, do joins on the biggest to smallest lengths of baseParts.
|
|
441
|
+
var shouldBreakOuterLoop = false;
|
|
442
|
+
for (j = baseParts.length; j > 0; j -= 1) {
|
|
443
|
+
mapValue = getOwn(map, baseParts.slice(0, j).join('/'));
|
|
444
|
+
|
|
445
|
+
// baseName segment has config, find if it has one for
|
|
446
|
+
// this name.
|
|
447
|
+
if (mapValue) {
|
|
448
|
+
mapValue = getOwn(mapValue, nameSegment);
|
|
449
|
+
if (mapValue) {
|
|
450
|
+
// Match, update name to the new value.
|
|
451
|
+
foundMap = mapValue;
|
|
452
|
+
foundI = i;
|
|
453
|
+
shouldBreakOuterLoop = true;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (shouldBreakOuterLoop) {
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Check for a star map match, but just hold on to it,
|
|
464
|
+
// if there is a shorter segment match later in a matching
|
|
465
|
+
// config, then favor over this star map.
|
|
466
|
+
if (!foundStarMap && starMap && getOwn(starMap, nameSegment)) {
|
|
467
|
+
foundStarMap = getOwn(starMap, nameSegment);
|
|
468
|
+
starI = i;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (!foundMap && foundStarMap) {
|
|
472
|
+
foundMap = foundStarMap;
|
|
473
|
+
foundI = starI;
|
|
474
|
+
}
|
|
475
|
+
if (foundMap) {
|
|
476
|
+
nameParts.splice(0, foundI, foundMap);
|
|
477
|
+
name = nameParts.join('/');
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// If the name points to a package's name, use
|
|
482
|
+
// the package main instead.
|
|
483
|
+
pkgMain = getOwn(_config.pkgs, name);
|
|
484
|
+
return pkgMain || name;
|
|
485
|
+
}
|
|
486
|
+
function removeScript(name) {
|
|
487
|
+
if (isBrowser) {
|
|
488
|
+
each(scripts(), function (scriptNode) {
|
|
489
|
+
if (scriptNode.getAttribute('data-requiremodule') === name && scriptNode.getAttribute('data-requirecontext') === context.contextName) {
|
|
490
|
+
scriptNode.parentNode.removeChild(scriptNode);
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function hasPathFallback(id) {
|
|
497
|
+
var pathConfig = getOwn(_config.paths, id);
|
|
498
|
+
if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
|
|
499
|
+
// Pop off the first array value, since it failed, and
|
|
500
|
+
// retry
|
|
501
|
+
pathConfig.shift();
|
|
502
|
+
context.require.undef(id);
|
|
503
|
+
|
|
504
|
+
// Custom require that does not do map translation, since
|
|
505
|
+
// ID is "absolute", already mapped/resolved.
|
|
506
|
+
context.makeRequire(null, {
|
|
507
|
+
skipMap: true
|
|
508
|
+
})([id]);
|
|
509
|
+
return true;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Turns a plugin!resource to [plugin, resource]
|
|
514
|
+
// with the plugin being undefined if the name
|
|
515
|
+
// did not have a plugin prefix.
|
|
516
|
+
function splitPrefix(name) {
|
|
517
|
+
var prefix;
|
|
518
|
+
var index = name ? name.indexOf('!') : -1;
|
|
519
|
+
if (index > -1) {
|
|
520
|
+
prefix = name.substring(0, index);
|
|
521
|
+
name = name.substring(index + 1, name.length);
|
|
522
|
+
}
|
|
523
|
+
return [prefix, name];
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Creates a module mapping that includes plugin prefix, module
|
|
528
|
+
* name, and path. If parentModuleMap is provided it will
|
|
529
|
+
* also normalize the name via require.normalize()
|
|
530
|
+
*
|
|
531
|
+
* @param {String} name the module name
|
|
532
|
+
* @param {String} [parentModuleMap] parent module map
|
|
533
|
+
* for the module name, used to resolve relative names.
|
|
534
|
+
* @param {Boolean} isNormalized: is the ID already normalized.
|
|
535
|
+
* This is true if this call is done for a define() module ID.
|
|
536
|
+
* @param {Boolean} applyMap: apply the map config to the ID.
|
|
537
|
+
* Should only be true if this map is for a dependency.
|
|
538
|
+
*
|
|
539
|
+
* @returns {Object}
|
|
540
|
+
*/
|
|
541
|
+
function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
|
|
542
|
+
var url;
|
|
543
|
+
var pluginModule;
|
|
544
|
+
var suffix;
|
|
545
|
+
var nameParts;
|
|
546
|
+
var prefix = null;
|
|
547
|
+
var parentName = parentModuleMap ? parentModuleMap.name : null;
|
|
548
|
+
var originalName = name;
|
|
549
|
+
var isDefine = true;
|
|
550
|
+
var normalizedName = '';
|
|
551
|
+
|
|
552
|
+
// If no name, then it means it is a require call, generate an
|
|
553
|
+
// internal name.
|
|
554
|
+
if (!name) {
|
|
555
|
+
isDefine = false;
|
|
556
|
+
name = '_@r' + (requireCounter += 1);
|
|
557
|
+
}
|
|
558
|
+
nameParts = splitPrefix(name);
|
|
559
|
+
prefix = nameParts[0];
|
|
560
|
+
name = nameParts[1];
|
|
561
|
+
if (prefix) {
|
|
562
|
+
prefix = normalize(prefix, parentName, applyMap);
|
|
563
|
+
pluginModule = getOwn(_defined, prefix);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// Account for relative paths if there is a base name.
|
|
567
|
+
if (name) {
|
|
568
|
+
if (prefix) {
|
|
569
|
+
if (pluginModule && pluginModule.normalize) {
|
|
570
|
+
// Plugin is loaded, use its normalize method.
|
|
571
|
+
normalizedName = pluginModule.normalize(name, function (name) {
|
|
572
|
+
return normalize(name, parentName, applyMap);
|
|
573
|
+
});
|
|
574
|
+
} else {
|
|
575
|
+
// If nested plugin references, then do not try to
|
|
576
|
+
// normalize, as it will not normalize correctly. This
|
|
577
|
+
// places a restriction on resourceIds, and the longer
|
|
578
|
+
// term solution is not to normalize until plugins are
|
|
579
|
+
// loaded and all normalizations to allow for async
|
|
580
|
+
// loading of a loader plugin. But for now, fixes the
|
|
581
|
+
// common uses. Details in #1131
|
|
582
|
+
normalizedName = name.indexOf('!') === -1 ? normalize(name, parentName, applyMap) : name;
|
|
583
|
+
}
|
|
584
|
+
} else {
|
|
585
|
+
// A regular module.
|
|
586
|
+
normalizedName = normalize(name, parentName, applyMap);
|
|
587
|
+
|
|
588
|
+
// Normalized name may be a plugin ID due to map config
|
|
589
|
+
// application in normalize. The map config values must
|
|
590
|
+
// already be normalized, so do not need to redo that part.
|
|
591
|
+
nameParts = splitPrefix(normalizedName);
|
|
592
|
+
prefix = nameParts[0];
|
|
593
|
+
normalizedName = nameParts[1];
|
|
594
|
+
isNormalized = true;
|
|
595
|
+
url = context.nameToUrl(normalizedName);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// If the id is a plugin id that cannot be determined if it needs
|
|
600
|
+
// normalization, stamp it with a unique ID so two matching relative
|
|
601
|
+
// ids that may conflict can be separate.
|
|
602
|
+
suffix = prefix && !pluginModule && !isNormalized ? '_unnormalized' + (unnormalizedCounter += 1) : '';
|
|
603
|
+
return {
|
|
604
|
+
prefix: prefix,
|
|
605
|
+
name: normalizedName,
|
|
606
|
+
parentMap: parentModuleMap,
|
|
607
|
+
unnormalized: !!suffix,
|
|
608
|
+
url: url,
|
|
609
|
+
originalName: originalName,
|
|
610
|
+
isDefine: isDefine,
|
|
611
|
+
id: (prefix ? prefix + '!' + normalizedName : normalizedName) + suffix
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
function getModule(depMap) {
|
|
615
|
+
var id = depMap.id;
|
|
616
|
+
var mod = getOwn(registry, id);
|
|
617
|
+
if (!mod) {
|
|
618
|
+
mod = registry[id] = new context.Module(depMap);
|
|
619
|
+
}
|
|
620
|
+
return mod;
|
|
621
|
+
}
|
|
622
|
+
function on(depMap, name, fn) {
|
|
623
|
+
var id = depMap.id;
|
|
624
|
+
var mod = getOwn(registry, id);
|
|
625
|
+
if (hasProp(_defined, id) && (!mod || mod.defineEmitComplete)) {
|
|
626
|
+
if (name === 'defined') {
|
|
627
|
+
fn(_defined[id]);
|
|
628
|
+
}
|
|
629
|
+
} else {
|
|
630
|
+
mod = getModule(depMap);
|
|
631
|
+
if (mod.error && name === 'error') {
|
|
632
|
+
fn(mod.error);
|
|
633
|
+
} else {
|
|
634
|
+
mod.on(name, fn);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function onError(err, errback) {
|
|
639
|
+
var ids = err.requireModules;
|
|
640
|
+
var notified = false;
|
|
641
|
+
if (errback) {
|
|
642
|
+
errback(err);
|
|
643
|
+
} else {
|
|
644
|
+
each(ids, function (id) {
|
|
645
|
+
var mod = getOwn(registry, id);
|
|
646
|
+
if (mod) {
|
|
647
|
+
// Set error on module, so it skips timeout checks.
|
|
648
|
+
mod.error = err;
|
|
649
|
+
if (mod.events.error) {
|
|
650
|
+
notified = true;
|
|
651
|
+
mod.emit('error', err);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
if (!notified) {
|
|
656
|
+
req.onError(err);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Internal method to transfer globalQueue items to this context's
|
|
663
|
+
* defQueue.
|
|
664
|
+
*/
|
|
665
|
+
function takeGlobalQueue() {
|
|
666
|
+
// Push all the globalDefQueue items into the context's defQueue
|
|
667
|
+
if (globalDefQueue.length) {
|
|
668
|
+
each(globalDefQueue, function (queueItem) {
|
|
669
|
+
var id = queueItem[0];
|
|
670
|
+
if (typeof id === 'string') {
|
|
671
|
+
context.defQueueMap[id] = true;
|
|
672
|
+
}
|
|
673
|
+
defQueue.push(queueItem);
|
|
674
|
+
});
|
|
675
|
+
globalDefQueue = [];
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
handlers = {
|
|
679
|
+
require: function require(mod) {
|
|
680
|
+
if (mod.require) {
|
|
681
|
+
return mod.require;
|
|
682
|
+
} else {
|
|
683
|
+
return mod.require = context.makeRequire(mod.map);
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
exports: function exports(mod) {
|
|
687
|
+
mod.usingExports = true;
|
|
688
|
+
if (mod.map.isDefine) {
|
|
689
|
+
if (mod.exports) {
|
|
690
|
+
_defined[mod.map.id] = mod.exports;
|
|
691
|
+
} else {
|
|
692
|
+
mod.exports = _defined[mod.map.id] = {};
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
module: function module(mod) {
|
|
697
|
+
if (mod.module) {
|
|
698
|
+
return mod.module;
|
|
699
|
+
} else {
|
|
700
|
+
return mod.module = {
|
|
701
|
+
id: mod.map.id,
|
|
702
|
+
uri: mod.map.url,
|
|
703
|
+
config: function config() {
|
|
704
|
+
return getOwn(_config.config, mod.map.id) || {};
|
|
705
|
+
},
|
|
706
|
+
exports: mod.exports || (mod.exports = {})
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
function cleanRegistry(id) {
|
|
712
|
+
// Clean up machinery used for waiting modules.
|
|
713
|
+
delete registry[id];
|
|
714
|
+
delete enabledRegistry[id];
|
|
715
|
+
}
|
|
716
|
+
function breakCycle(mod, traced, processed) {
|
|
717
|
+
var id = mod.map.id;
|
|
718
|
+
if (mod.error) {
|
|
719
|
+
mod.emit('error', mod.error);
|
|
720
|
+
} else {
|
|
721
|
+
traced[id] = true;
|
|
722
|
+
each(mod.depMaps, function (depMap, i) {
|
|
723
|
+
var depId = depMap.id;
|
|
724
|
+
var dep = getOwn(registry, depId);
|
|
725
|
+
|
|
726
|
+
// Only force things that have not completed
|
|
727
|
+
// being defined, so still in the registry,
|
|
728
|
+
// and only if it has not been matched up
|
|
729
|
+
// in the module already.
|
|
730
|
+
if (dep && !mod.depMatched[i] && !processed[depId]) {
|
|
731
|
+
if (getOwn(traced, depId)) {
|
|
732
|
+
mod.defineDep(i, _defined[depId]);
|
|
733
|
+
mod.check(); // pass false?
|
|
734
|
+
} else {
|
|
735
|
+
breakCycle(dep, traced, processed);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
processed[id] = true;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function checkLoaded() {
|
|
743
|
+
var err;
|
|
744
|
+
var usingPathFallback;
|
|
745
|
+
var waitInterval = _config.waitSeconds * 1000;
|
|
746
|
+
// It is possible to disable the wait interval by using waitSeconds of 0.
|
|
747
|
+
var expired = waitInterval && context.startTime + waitInterval < new Date().getTime();
|
|
748
|
+
var noLoads = [];
|
|
749
|
+
var reqCalls = [];
|
|
750
|
+
var stillLoading = false;
|
|
751
|
+
var needCycleCheck = true;
|
|
752
|
+
|
|
753
|
+
// Do not bother if this call was a result of a cycle break.
|
|
754
|
+
if (inCheckLoaded) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
inCheckLoaded = true;
|
|
758
|
+
|
|
759
|
+
// Figure out the state of all the modules.
|
|
760
|
+
eachProp(enabledRegistry, function (mod) {
|
|
761
|
+
var map = mod.map;
|
|
762
|
+
var modId = map.id;
|
|
763
|
+
|
|
764
|
+
// Skip things that are not enabled or in error state.
|
|
765
|
+
if (!mod.enabled) {
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
if (!map.isDefine) {
|
|
769
|
+
reqCalls.push(mod);
|
|
770
|
+
}
|
|
771
|
+
if (!mod.error) {
|
|
772
|
+
// If the module should be executed, and it has not
|
|
773
|
+
// been inited and time is up, remember it.
|
|
774
|
+
if (!mod.inited && expired) {
|
|
775
|
+
if (hasPathFallback(modId)) {
|
|
776
|
+
usingPathFallback = true;
|
|
777
|
+
stillLoading = true;
|
|
778
|
+
} else {
|
|
779
|
+
noLoads.push(modId);
|
|
780
|
+
removeScript(modId);
|
|
781
|
+
}
|
|
782
|
+
} else if (!mod.inited && mod.fetched && map.isDefine) {
|
|
783
|
+
stillLoading = true;
|
|
784
|
+
if (!map.prefix) {
|
|
785
|
+
// No reason to keep looking for unfinished
|
|
786
|
+
// loading. If the only stillLoading is a
|
|
787
|
+
// plugin resource though, keep going,
|
|
788
|
+
// because it may be that a plugin resource
|
|
789
|
+
// is waiting on a non-plugin cycle.
|
|
790
|
+
return needCycleCheck = false;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
if (expired && noLoads.length) {
|
|
796
|
+
// If wait time expired, throw error of unloaded modules.
|
|
797
|
+
err = makeError('timeout', 'Load timeout for modules: ' + noLoads, null, noLoads);
|
|
798
|
+
err.contextName = context.contextName;
|
|
799
|
+
return onError(err);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// Not expired, check for a cycle.
|
|
803
|
+
if (needCycleCheck) {
|
|
804
|
+
each(reqCalls, function (mod) {
|
|
805
|
+
breakCycle(mod, {}, {});
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// If still waiting on loads, and the waiting load is something
|
|
810
|
+
// other than a plugin resource, or there are still outstanding
|
|
811
|
+
// scripts, then just try back later.
|
|
812
|
+
if ((!expired || usingPathFallback) && stillLoading) {
|
|
813
|
+
// Something is still waiting to load. Wait for it, but only
|
|
814
|
+
// if a timeout is not already in effect.
|
|
815
|
+
if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
|
|
816
|
+
checkLoadedTimeoutId = setTimeout(function () {
|
|
817
|
+
checkLoadedTimeoutId = 0;
|
|
818
|
+
checkLoaded();
|
|
819
|
+
}, 50);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
inCheckLoaded = false;
|
|
823
|
+
}
|
|
824
|
+
Module = function Module(map) {
|
|
825
|
+
this.events = getOwn(undefEvents, map.id) || {};
|
|
826
|
+
this.map = map;
|
|
827
|
+
this.shim = getOwn(_config.shim, map.id);
|
|
828
|
+
this.depExports = [];
|
|
829
|
+
this.depMaps = [];
|
|
830
|
+
this.depMatched = [];
|
|
831
|
+
this.pluginMaps = {};
|
|
832
|
+
this.depCount = 0;
|
|
833
|
+
|
|
834
|
+
/* this.exports this.factory
|
|
835
|
+
this.depMaps = [],
|
|
836
|
+
this.enabled, this.fetched
|
|
837
|
+
*/
|
|
838
|
+
};
|
|
839
|
+
Module.prototype = {
|
|
840
|
+
init: function init(depMaps, factory, errback, options) {
|
|
841
|
+
options = options || {};
|
|
842
|
+
|
|
843
|
+
// Do not do more inits if already done. Can happen if there
|
|
844
|
+
// are multiple define calls for the same module. That is not
|
|
845
|
+
// a normal, common case, but it is also not unexpected.
|
|
846
|
+
if (this.inited) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
this.factory = factory;
|
|
850
|
+
if (errback) {
|
|
851
|
+
// Register for errors on this module.
|
|
852
|
+
this.on('error', errback);
|
|
853
|
+
} else if (this.events.error) {
|
|
854
|
+
// If no errback already, but there are error listeners
|
|
855
|
+
// on this module, set up an errback to pass to the deps.
|
|
856
|
+
errback = bind(this, function (err) {
|
|
857
|
+
this.emit('error', err);
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// Do a copy of the dependency array, so that
|
|
862
|
+
// source inputs are not modified. For example
|
|
863
|
+
// "shim" deps are passed in here directly, and
|
|
864
|
+
// doing a direct modification of the depMaps array
|
|
865
|
+
// would affect that config.
|
|
866
|
+
this.depMaps = depMaps && depMaps.slice(0);
|
|
867
|
+
this.errback = errback;
|
|
868
|
+
|
|
869
|
+
// Indicate this module has be initialized
|
|
870
|
+
this.inited = true;
|
|
871
|
+
this.ignore = options.ignore;
|
|
872
|
+
|
|
873
|
+
// Could have option to init this module in enabled mode,
|
|
874
|
+
// or could have been previously marked as enabled. However,
|
|
875
|
+
// the dependencies are not known until init is called. So
|
|
876
|
+
// if enabled previously, now trigger dependencies as enabled.
|
|
877
|
+
if (options.enabled || this.enabled) {
|
|
878
|
+
// Enable this module and dependencies.
|
|
879
|
+
// Will call this.check()
|
|
880
|
+
this.enable();
|
|
881
|
+
} else {
|
|
882
|
+
this.check();
|
|
883
|
+
}
|
|
884
|
+
},
|
|
885
|
+
defineDep: function defineDep(i, depExports) {
|
|
886
|
+
// Because of cycles, defined callback for a given
|
|
887
|
+
// export can be called more than once.
|
|
888
|
+
if (!this.depMatched[i]) {
|
|
889
|
+
this.depMatched[i] = true;
|
|
890
|
+
this.depCount -= 1;
|
|
891
|
+
this.depExports[i] = depExports;
|
|
892
|
+
}
|
|
893
|
+
},
|
|
894
|
+
fetch: function fetch() {
|
|
895
|
+
if (this.fetched) {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
this.fetched = true;
|
|
899
|
+
context.startTime = new Date().getTime();
|
|
900
|
+
var map = this.map;
|
|
901
|
+
|
|
902
|
+
// If the manager is for a plugin managed resource,
|
|
903
|
+
// ask the plugin to load it now.
|
|
904
|
+
if (this.shim) {
|
|
905
|
+
context.makeRequire(this.map, {
|
|
906
|
+
enableBuildCallback: true
|
|
907
|
+
})(this.shim.deps || [], bind(this, function () {
|
|
908
|
+
return map.prefix ? this.callPlugin() : this.load();
|
|
909
|
+
}));
|
|
910
|
+
} else {
|
|
911
|
+
// Regular dependency.
|
|
912
|
+
return map.prefix ? this.callPlugin() : this.load();
|
|
913
|
+
}
|
|
914
|
+
},
|
|
915
|
+
load: function load() {
|
|
916
|
+
var url = this.map.url;
|
|
917
|
+
|
|
918
|
+
// Regular dependency.
|
|
919
|
+
if (!urlFetched[url]) {
|
|
920
|
+
urlFetched[url] = true;
|
|
921
|
+
context.load(this.map.id, url);
|
|
922
|
+
}
|
|
923
|
+
},
|
|
924
|
+
/**
|
|
925
|
+
* Checks if the module is ready to define itself, and if so,
|
|
926
|
+
* define it.
|
|
927
|
+
*/
|
|
928
|
+
check: function check() {
|
|
929
|
+
if (!this.enabled || this.enabling) {
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
var err;
|
|
933
|
+
var cjsModule;
|
|
934
|
+
var id = this.map.id;
|
|
935
|
+
var depExports = this.depExports;
|
|
936
|
+
var exports = this.exports;
|
|
937
|
+
var factory = this.factory;
|
|
938
|
+
if (!this.inited) {
|
|
939
|
+
// Only fetch if not already in the defQueue.
|
|
940
|
+
if (!hasProp(context.defQueueMap, id)) {
|
|
941
|
+
this.fetch();
|
|
942
|
+
}
|
|
943
|
+
} else if (this.error) {
|
|
944
|
+
this.emit('error', this.error);
|
|
945
|
+
} else if (!this.defining) {
|
|
946
|
+
// The factory could trigger another require call
|
|
947
|
+
// that would result in checking this module to
|
|
948
|
+
// define itself again. If already in the process
|
|
949
|
+
// of doing that, skip this work.
|
|
950
|
+
this.defining = true;
|
|
951
|
+
if (this.depCount < 1 && !this.defined) {
|
|
952
|
+
if (isFunction(factory)) {
|
|
953
|
+
// If there is an error listener, favor passing
|
|
954
|
+
// to that instead of throwing an error. However,
|
|
955
|
+
// only do it for define()'d modules. require
|
|
956
|
+
// errbacks should not be called for failures in
|
|
957
|
+
// their callbacks (#699). However if a global
|
|
958
|
+
// onError is set, use that.
|
|
959
|
+
if (this.events.error && this.map.isDefine || req.onError !== defaultOnError) {
|
|
960
|
+
try {
|
|
961
|
+
exports = context.execCb(id, factory, depExports, exports);
|
|
962
|
+
} catch (e) {
|
|
963
|
+
err = e;
|
|
964
|
+
}
|
|
965
|
+
} else {
|
|
966
|
+
exports = context.execCb(id, factory, depExports, exports);
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
// Favor return value over exports. If node/cjs in play,
|
|
970
|
+
// then will not have a return value anyway. Favor
|
|
971
|
+
// module.exports assignment over exports object.
|
|
972
|
+
if (this.map.isDefine && exports === undefined) {
|
|
973
|
+
cjsModule = this.module;
|
|
974
|
+
if (cjsModule) {
|
|
975
|
+
exports = cjsModule.exports;
|
|
976
|
+
} else if (this.usingExports) {
|
|
977
|
+
// exports already set the defined value.
|
|
978
|
+
exports = this.exports;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
if (err) {
|
|
982
|
+
err.requireMap = this.map;
|
|
983
|
+
err.requireModules = this.map.isDefine ? [this.map.id] : null;
|
|
984
|
+
err.requireType = this.map.isDefine ? 'define' : 'require';
|
|
985
|
+
return onError(this.error = err);
|
|
986
|
+
}
|
|
987
|
+
} else {
|
|
988
|
+
// Just a literal value
|
|
989
|
+
exports = factory;
|
|
990
|
+
}
|
|
991
|
+
this.exports = exports;
|
|
992
|
+
if (this.map.isDefine && !this.ignore) {
|
|
993
|
+
_defined[id] = exports;
|
|
994
|
+
if (req.onResourceLoad) {
|
|
995
|
+
var resLoadMaps = [];
|
|
996
|
+
each(this.depMaps, function (depMap) {
|
|
997
|
+
resLoadMaps.push(depMap.normalizedMap || depMap);
|
|
998
|
+
});
|
|
999
|
+
req.onResourceLoad(context, this.map, resLoadMaps);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// Clean up
|
|
1004
|
+
cleanRegistry(id);
|
|
1005
|
+
this.defined = true;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// Finished the define stage. Allow calling check again
|
|
1009
|
+
// to allow define notifications below in the case of a
|
|
1010
|
+
// cycle.
|
|
1011
|
+
this.defining = false;
|
|
1012
|
+
if (this.defined && !this.defineEmitted) {
|
|
1013
|
+
this.defineEmitted = true;
|
|
1014
|
+
this.emit('defined', this.exports);
|
|
1015
|
+
this.defineEmitComplete = true;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
},
|
|
1019
|
+
callPlugin: function callPlugin() {
|
|
1020
|
+
var map = this.map;
|
|
1021
|
+
var id = map.id;
|
|
1022
|
+
// Map already normalized the prefix.
|
|
1023
|
+
var pluginMap = makeModuleMap(map.prefix);
|
|
1024
|
+
|
|
1025
|
+
// Mark this as a dependency for this plugin, so it
|
|
1026
|
+
// can be traced for cycles.
|
|
1027
|
+
this.depMaps.push(pluginMap);
|
|
1028
|
+
on(pluginMap, 'defined', bind(this, function (plugin) {
|
|
1029
|
+
var load;
|
|
1030
|
+
var normalizedMap;
|
|
1031
|
+
var normalizedMod;
|
|
1032
|
+
var bundleId = getOwn(bundlesMap, this.map.id);
|
|
1033
|
+
var name = this.map.name;
|
|
1034
|
+
var parentName = this.map.parentMap ? this.map.parentMap.name : null;
|
|
1035
|
+
var localRequire = context.makeRequire(map.parentMap, {
|
|
1036
|
+
enableBuildCallback: true
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
// If current map is not normalized, wait for that
|
|
1040
|
+
// normalized name to load instead of continuing.
|
|
1041
|
+
if (this.map.unnormalized) {
|
|
1042
|
+
// Normalize the ID if the plugin allows it.
|
|
1043
|
+
if (plugin.normalize) {
|
|
1044
|
+
name = plugin.normalize(name, function (name) {
|
|
1045
|
+
return normalize(name, parentName, true);
|
|
1046
|
+
}) || '';
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// prefix and name should already be normalized, no need
|
|
1050
|
+
// for applying map config again either.
|
|
1051
|
+
normalizedMap = makeModuleMap(map.prefix + '!' + name, this.map.parentMap);
|
|
1052
|
+
on(normalizedMap, 'defined', bind(this, function (value) {
|
|
1053
|
+
this.map.normalizedMap = normalizedMap;
|
|
1054
|
+
this.init([], function () {
|
|
1055
|
+
return value;
|
|
1056
|
+
}, null, {
|
|
1057
|
+
enabled: true,
|
|
1058
|
+
ignore: true
|
|
1059
|
+
});
|
|
1060
|
+
}));
|
|
1061
|
+
normalizedMod = getOwn(registry, normalizedMap.id);
|
|
1062
|
+
if (normalizedMod) {
|
|
1063
|
+
// Mark this as a dependency for this plugin, so it
|
|
1064
|
+
// can be traced for cycles.
|
|
1065
|
+
this.depMaps.push(normalizedMap);
|
|
1066
|
+
if (this.events.error) {
|
|
1067
|
+
normalizedMod.on('error', bind(this, function (err) {
|
|
1068
|
+
this.emit('error', err);
|
|
1069
|
+
}));
|
|
1070
|
+
}
|
|
1071
|
+
normalizedMod.enable();
|
|
1072
|
+
}
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
// If a paths config, then just load that file instead to
|
|
1077
|
+
// resolve the plugin, as it is built into that paths layer.
|
|
1078
|
+
if (bundleId) {
|
|
1079
|
+
this.map.url = context.nameToUrl(bundleId);
|
|
1080
|
+
this.load();
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
load = bind(this, function (value) {
|
|
1084
|
+
this.init([], function () {
|
|
1085
|
+
return value;
|
|
1086
|
+
}, null, {
|
|
1087
|
+
enabled: true
|
|
1088
|
+
});
|
|
1089
|
+
});
|
|
1090
|
+
load.error = bind(this, function (err) {
|
|
1091
|
+
this.inited = true;
|
|
1092
|
+
this.error = err;
|
|
1093
|
+
err.requireModules = [id];
|
|
1094
|
+
|
|
1095
|
+
// Remove temp unnormalized modules for this module,
|
|
1096
|
+
// since they will never be resolved otherwise now.
|
|
1097
|
+
eachProp(registry, function (mod) {
|
|
1098
|
+
if (mod.map.id.indexOf(id + '_unnormalized') === 0) {
|
|
1099
|
+
cleanRegistry(mod.map.id);
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
onError(err);
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
// Allow plugins to load other code without having to know the
|
|
1106
|
+
// context or how to 'complete' the load.
|
|
1107
|
+
load.fromText = bind(this, function (text, textAlt) {
|
|
1108
|
+
/* jslint evil: true */
|
|
1109
|
+
var moduleName = map.name;
|
|
1110
|
+
var moduleMap = makeModuleMap(moduleName);
|
|
1111
|
+
var hasInteractive = useInteractive;
|
|
1112
|
+
|
|
1113
|
+
// As of 2.1.0, support just passing the text, to reinforce
|
|
1114
|
+
// fromText only being called once per resource. Still
|
|
1115
|
+
// support old style of passing moduleName but discard
|
|
1116
|
+
// that moduleName in favor of the internal ref.
|
|
1117
|
+
if (textAlt) {
|
|
1118
|
+
text = textAlt;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// Turn off interactive script matching for IE for any define
|
|
1122
|
+
// calls in the text, then turn it back on at the end.
|
|
1123
|
+
if (hasInteractive) {
|
|
1124
|
+
useInteractive = false;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// Prime the system by creating a module instance for
|
|
1128
|
+
// it.
|
|
1129
|
+
getModule(moduleMap);
|
|
1130
|
+
|
|
1131
|
+
// Transfer any config to this other module.
|
|
1132
|
+
if (hasProp(_config.config, id)) {
|
|
1133
|
+
_config.config[moduleName] = _config.config[id];
|
|
1134
|
+
}
|
|
1135
|
+
try {
|
|
1136
|
+
req.exec(text);
|
|
1137
|
+
} catch (e) {
|
|
1138
|
+
return onError(makeError('fromtexteval', 'fromText eval for ' + id + ' failed: ' + e, e, [id]));
|
|
1139
|
+
}
|
|
1140
|
+
if (hasInteractive) {
|
|
1141
|
+
useInteractive = true;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// Mark this as a dependency for the plugin
|
|
1145
|
+
// resource
|
|
1146
|
+
this.depMaps.push(moduleMap);
|
|
1147
|
+
|
|
1148
|
+
// Support anonymous modules.
|
|
1149
|
+
context.completeLoad(moduleName);
|
|
1150
|
+
|
|
1151
|
+
// Bind the value of that module to the value for this
|
|
1152
|
+
// resource ID.
|
|
1153
|
+
localRequire([moduleName], load);
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
// Use parentName here since the plugin's name is not reliable,
|
|
1157
|
+
// could be some weird string with no path that actually wants to
|
|
1158
|
+
// reference the parentName's path.
|
|
1159
|
+
plugin.load(map.name, localRequire, load, _config);
|
|
1160
|
+
}));
|
|
1161
|
+
context.enable(pluginMap, this);
|
|
1162
|
+
this.pluginMaps[pluginMap.id] = pluginMap;
|
|
1163
|
+
},
|
|
1164
|
+
enable: function enable() {
|
|
1165
|
+
enabledRegistry[this.map.id] = this;
|
|
1166
|
+
this.enabled = true;
|
|
1167
|
+
|
|
1168
|
+
// Set flag mentioning that the module is enabling,
|
|
1169
|
+
// so that immediate calls to the defined callbacks
|
|
1170
|
+
// for dependencies do not trigger inadvertent load
|
|
1171
|
+
// with the depCount still being zero.
|
|
1172
|
+
this.enabling = true;
|
|
1173
|
+
|
|
1174
|
+
// Enable each dependency
|
|
1175
|
+
each(this.depMaps, bind(this, function (depMap, i) {
|
|
1176
|
+
var id, mod, handler;
|
|
1177
|
+
if (typeof depMap === 'string') {
|
|
1178
|
+
// Dependency needs to be converted to a depMap
|
|
1179
|
+
// and wired up to this module.
|
|
1180
|
+
depMap = makeModuleMap(depMap, this.map.isDefine ? this.map : this.map.parentMap, false, !this.skipMap);
|
|
1181
|
+
this.depMaps[i] = depMap;
|
|
1182
|
+
handler = getOwn(handlers, depMap.id);
|
|
1183
|
+
if (handler) {
|
|
1184
|
+
this.depExports[i] = handler(this);
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
this.depCount += 1;
|
|
1188
|
+
on(depMap, 'defined', bind(this, function (depExports) {
|
|
1189
|
+
if (this.undefed) {
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
this.defineDep(i, depExports);
|
|
1193
|
+
this.check();
|
|
1194
|
+
}));
|
|
1195
|
+
if (this.errback) {
|
|
1196
|
+
on(depMap, 'error', bind(this, this.errback));
|
|
1197
|
+
} else if (this.events.error) {
|
|
1198
|
+
// No direct errback on this module, but something
|
|
1199
|
+
// else is listening for errors, so be sure to
|
|
1200
|
+
// propagate the error correctly.
|
|
1201
|
+
on(depMap, 'error', bind(this, function (err) {
|
|
1202
|
+
this.emit('error', err);
|
|
1203
|
+
}));
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
id = depMap.id;
|
|
1207
|
+
mod = registry[id];
|
|
1208
|
+
|
|
1209
|
+
// Skip special modules like 'require', 'exports', 'module'
|
|
1210
|
+
// Also, don't call enable if it is already enabled,
|
|
1211
|
+
// important in circular dependency cases.
|
|
1212
|
+
if (!hasProp(handlers, id) && mod && !mod.enabled) {
|
|
1213
|
+
context.enable(depMap, this);
|
|
1214
|
+
}
|
|
1215
|
+
}));
|
|
1216
|
+
|
|
1217
|
+
// Enable each plugin that is used in
|
|
1218
|
+
// a dependency
|
|
1219
|
+
eachProp(this.pluginMaps, bind(this, function (pluginMap) {
|
|
1220
|
+
var mod = getOwn(registry, pluginMap.id);
|
|
1221
|
+
if (mod && !mod.enabled) {
|
|
1222
|
+
context.enable(pluginMap, this);
|
|
1223
|
+
}
|
|
1224
|
+
}));
|
|
1225
|
+
this.enabling = false;
|
|
1226
|
+
this.check();
|
|
1227
|
+
},
|
|
1228
|
+
on: function on(name, cb) {
|
|
1229
|
+
var cbs = this.events[name];
|
|
1230
|
+
if (!cbs) {
|
|
1231
|
+
cbs = this.events[name] = [];
|
|
1232
|
+
}
|
|
1233
|
+
cbs.push(cb);
|
|
1234
|
+
},
|
|
1235
|
+
emit: function emit(name, evt) {
|
|
1236
|
+
each(this.events[name], function (cb) {
|
|
1237
|
+
cb(evt);
|
|
1238
|
+
});
|
|
1239
|
+
if (name === 'error') {
|
|
1240
|
+
// Now that the error handler was triggered, remove
|
|
1241
|
+
// the listeners, since this broken Module instance
|
|
1242
|
+
// can stay around for a while in the registry.
|
|
1243
|
+
delete this.events[name];
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
function callGetModule(args) {
|
|
1248
|
+
// Skip modules already defined.
|
|
1249
|
+
if (!hasProp(_defined, args[0])) {
|
|
1250
|
+
getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2]);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
function removeListener(node, func, name, ieName) {
|
|
1254
|
+
// Favor detachEvent because of IE9
|
|
1255
|
+
// issue, see attachEvent/addEventListener comment elsewhere
|
|
1256
|
+
// in this file.
|
|
1257
|
+
if (node.detachEvent && !isOpera) {
|
|
1258
|
+
// Probably IE. If not it will throw an error, which will be
|
|
1259
|
+
// useful to know.
|
|
1260
|
+
if (ieName) {
|
|
1261
|
+
node.detachEvent(ieName, func);
|
|
1262
|
+
}
|
|
1263
|
+
} else {
|
|
1264
|
+
node.removeEventListener(name, func, false);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* Given an event from a script node, get the requirejs info from it,
|
|
1270
|
+
* and then removes the event listeners on the node.
|
|
1271
|
+
* @param {Event} evt
|
|
1272
|
+
* @returns {Object}
|
|
1273
|
+
*/
|
|
1274
|
+
function getScriptData(evt) {
|
|
1275
|
+
// Using currentTarget instead of target for Firefox 2.0's sake. Not
|
|
1276
|
+
// all old browsers will be supported, but this one was easy enough
|
|
1277
|
+
// to support and still makes sense.
|
|
1278
|
+
var node = evt.currentTarget || evt.srcElement;
|
|
1279
|
+
|
|
1280
|
+
// Remove the listeners once here.
|
|
1281
|
+
removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange');
|
|
1282
|
+
removeListener(node, context.onScriptError, 'error');
|
|
1283
|
+
return {
|
|
1284
|
+
node: node,
|
|
1285
|
+
id: node && node.getAttribute('data-requiremodule')
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
function intakeDefines() {
|
|
1289
|
+
var args;
|
|
1290
|
+
|
|
1291
|
+
// Any defined modules in the global queue, intake them now.
|
|
1292
|
+
takeGlobalQueue();
|
|
1293
|
+
|
|
1294
|
+
// Make sure any remaining defQueue items get properly processed.
|
|
1295
|
+
while (defQueue.length) {
|
|
1296
|
+
args = defQueue.shift();
|
|
1297
|
+
if (args[0] === null) {
|
|
1298
|
+
return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
|
|
1299
|
+
} else {
|
|
1300
|
+
// args are id, deps, factory. Should be normalized by the
|
|
1301
|
+
// define() function.
|
|
1302
|
+
callGetModule(args);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
context.defQueueMap = {};
|
|
1306
|
+
}
|
|
1307
|
+
context = {
|
|
1308
|
+
config: _config,
|
|
1309
|
+
contextName: contextName,
|
|
1310
|
+
registry: registry,
|
|
1311
|
+
defined: _defined,
|
|
1312
|
+
urlFetched: urlFetched,
|
|
1313
|
+
defQueue: defQueue,
|
|
1314
|
+
defQueueMap: {},
|
|
1315
|
+
Module: Module,
|
|
1316
|
+
makeModuleMap: makeModuleMap,
|
|
1317
|
+
nextTick: req.nextTick,
|
|
1318
|
+
onError: onError,
|
|
1319
|
+
/**
|
|
1320
|
+
* Set a configuration for the context.
|
|
1321
|
+
* @param {Object} cfg config object to integrate.
|
|
1322
|
+
*/
|
|
1323
|
+
configure: function configure(cfg) {
|
|
1324
|
+
// Make sure the baseUrl ends in a slash.
|
|
1325
|
+
if (cfg.baseUrl) {
|
|
1326
|
+
if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== '/') {
|
|
1327
|
+
cfg.baseUrl += '/';
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// Convert old style urlArgs string to a function.
|
|
1332
|
+
if (typeof cfg.urlArgs === 'string') {
|
|
1333
|
+
var urlArgs = cfg.urlArgs;
|
|
1334
|
+
cfg.urlArgs = function (id, url) {
|
|
1335
|
+
return (url.indexOf('?') === -1 ? '?' : '&') + urlArgs;
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
// Save off the paths since they require special processing,
|
|
1340
|
+
// they are additive.
|
|
1341
|
+
var shim = _config.shim;
|
|
1342
|
+
var objs = {
|
|
1343
|
+
paths: true,
|
|
1344
|
+
bundles: true,
|
|
1345
|
+
config: true,
|
|
1346
|
+
map: true
|
|
1347
|
+
};
|
|
1348
|
+
eachProp(cfg, function (value, prop) {
|
|
1349
|
+
if (objs[prop]) {
|
|
1350
|
+
if (!_config[prop]) {
|
|
1351
|
+
_config[prop] = {};
|
|
1352
|
+
}
|
|
1353
|
+
mixin(_config[prop], value, true, true);
|
|
1354
|
+
} else {
|
|
1355
|
+
_config[prop] = value;
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
|
|
1359
|
+
// Reverse map the bundles
|
|
1360
|
+
if (cfg.bundles) {
|
|
1361
|
+
eachProp(cfg.bundles, function (value, prop) {
|
|
1362
|
+
each(value, function (v) {
|
|
1363
|
+
if (v !== prop) {
|
|
1364
|
+
bundlesMap[v] = prop;
|
|
1365
|
+
}
|
|
1366
|
+
});
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// Merge shim
|
|
1371
|
+
if (cfg.shim) {
|
|
1372
|
+
eachProp(cfg.shim, function (value, id) {
|
|
1373
|
+
// Normalize the structure
|
|
1374
|
+
if (isArray(value)) {
|
|
1375
|
+
value = {
|
|
1376
|
+
deps: value
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
if ((value.exports || value.init) && !value.exportsFn) {
|
|
1380
|
+
value.exportsFn = context.makeShimExports(value);
|
|
1381
|
+
}
|
|
1382
|
+
shim[id] = value;
|
|
1383
|
+
});
|
|
1384
|
+
_config.shim = shim;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
// Adjust packages if necessary.
|
|
1388
|
+
if (cfg.packages) {
|
|
1389
|
+
each(cfg.packages, function (pkgObj) {
|
|
1390
|
+
var location, name;
|
|
1391
|
+
pkgObj = typeof pkgObj === 'string' ? {
|
|
1392
|
+
name: pkgObj
|
|
1393
|
+
} : pkgObj;
|
|
1394
|
+
name = pkgObj.name;
|
|
1395
|
+
location = pkgObj.location;
|
|
1396
|
+
if (location) {
|
|
1397
|
+
_config.paths[name] = pkgObj.location;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
// Save pointer to main module ID for pkg name.
|
|
1401
|
+
// Remove leading dot in main, so main paths are normalized,
|
|
1402
|
+
// and remove any trailing .js, since different package
|
|
1403
|
+
// envs have different conventions: some use a module name,
|
|
1404
|
+
// some use a file name.
|
|
1405
|
+
_config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main').replace(currDirRegExp, '').replace(jsSuffixRegExp, '');
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
// If there are any "waiting to execute" modules in the registry,
|
|
1410
|
+
// update the maps for them, since their info, like URLs to load,
|
|
1411
|
+
// may have changed.
|
|
1412
|
+
eachProp(registry, function (mod, id) {
|
|
1413
|
+
// If module already has init called, since it is too
|
|
1414
|
+
// late to modify them, and ignore unnormalized ones
|
|
1415
|
+
// since they are transient.
|
|
1416
|
+
if (!mod.inited && !mod.map.unnormalized) {
|
|
1417
|
+
mod.map = makeModuleMap(id, null, true);
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
|
|
1421
|
+
// If a deps array or a config callback is specified, then call
|
|
1422
|
+
// require with those args. This is useful when require is defined as a
|
|
1423
|
+
// config object before require.js is loaded.
|
|
1424
|
+
if (cfg.deps || cfg.callback) {
|
|
1425
|
+
context.require(cfg.deps || [], cfg.callback);
|
|
1426
|
+
}
|
|
1427
|
+
},
|
|
1428
|
+
makeShimExports: function makeShimExports(value) {
|
|
1429
|
+
function fn() {
|
|
1430
|
+
var ret;
|
|
1431
|
+
if (value.init) {
|
|
1432
|
+
ret = value.init.apply(global, arguments);
|
|
1433
|
+
}
|
|
1434
|
+
return ret || value.exports && getGlobal(value.exports);
|
|
1435
|
+
}
|
|
1436
|
+
return fn;
|
|
1437
|
+
},
|
|
1438
|
+
makeRequire: function makeRequire(relMap, options) {
|
|
1439
|
+
options = options || {};
|
|
1440
|
+
function localRequire(deps, callback, errback) {
|
|
1441
|
+
var id, map, requireMod;
|
|
1442
|
+
if (options.enableBuildCallback && callback && isFunction(callback)) {
|
|
1443
|
+
callback.__requireJsBuild = true;
|
|
1444
|
+
}
|
|
1445
|
+
if (typeof deps === 'string') {
|
|
1446
|
+
if (isFunction(callback)) {
|
|
1447
|
+
// Invalid call
|
|
1448
|
+
return onError(makeError('requireargs', 'Invalid require call'), errback);
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// If require|exports|module are requested, get the
|
|
1452
|
+
// value for them from the special handlers. Caveat:
|
|
1453
|
+
// this only works while module is being defined.
|
|
1454
|
+
if (relMap && hasProp(handlers, deps)) {
|
|
1455
|
+
return handlers[deps](registry[relMap.id]);
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
// Synchronous access to one module. If require.get is
|
|
1459
|
+
// available (as in the Node adapter), prefer that.
|
|
1460
|
+
if (req.get) {
|
|
1461
|
+
return req.get(context, deps, relMap, localRequire);
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// Normalize module name, if it contains . or ..
|
|
1465
|
+
map = makeModuleMap(deps, relMap, false, true);
|
|
1466
|
+
id = map.id;
|
|
1467
|
+
if (!hasProp(_defined, id)) {
|
|
1468
|
+
return onError(makeError('notloaded', 'Module name "' + id + '" has not been loaded yet for context: ' + contextName + (relMap ? '' : '. Use require([])')));
|
|
1469
|
+
}
|
|
1470
|
+
return _defined[id];
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
// Grab defines waiting in the global queue.
|
|
1474
|
+
intakeDefines();
|
|
1475
|
+
|
|
1476
|
+
// Mark all the dependencies as needing to be loaded.
|
|
1477
|
+
context.nextTick(function () {
|
|
1478
|
+
// Some defines could have been added since the
|
|
1479
|
+
// require call, collect them.
|
|
1480
|
+
intakeDefines();
|
|
1481
|
+
requireMod = getModule(makeModuleMap(null, relMap));
|
|
1482
|
+
|
|
1483
|
+
// Store if map config should be applied to this require
|
|
1484
|
+
// call for dependencies.
|
|
1485
|
+
requireMod.skipMap = options.skipMap;
|
|
1486
|
+
requireMod.init(deps, callback, errback, {
|
|
1487
|
+
enabled: true
|
|
1488
|
+
});
|
|
1489
|
+
checkLoaded();
|
|
1490
|
+
});
|
|
1491
|
+
return localRequire;
|
|
1492
|
+
}
|
|
1493
|
+
mixin(localRequire, {
|
|
1494
|
+
isBrowser: isBrowser,
|
|
1495
|
+
/**
|
|
1496
|
+
* Converts a module name + .extension into an URL path.
|
|
1497
|
+
* *Requires* the use of a module name. It does not support using
|
|
1498
|
+
* plain URLs like nameToUrl.
|
|
1499
|
+
*/
|
|
1500
|
+
toUrl: function toUrl(moduleNamePlusExt) {
|
|
1501
|
+
var ext;
|
|
1502
|
+
var index = moduleNamePlusExt.lastIndexOf('.');
|
|
1503
|
+
var segment = moduleNamePlusExt.split('/')[0];
|
|
1504
|
+
var isRelative = segment === '.' || segment === '..';
|
|
1505
|
+
|
|
1506
|
+
// Have a file extension alias, and it is not the
|
|
1507
|
+
// dots from a relative path.
|
|
1508
|
+
if (index !== -1 && (!isRelative || index > 1)) {
|
|
1509
|
+
ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
|
|
1510
|
+
moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
|
|
1511
|
+
}
|
|
1512
|
+
return context.nameToUrl(normalize(moduleNamePlusExt, relMap && relMap.id, true), ext, true);
|
|
1513
|
+
},
|
|
1514
|
+
defined: function defined(id) {
|
|
1515
|
+
return hasProp(_defined, makeModuleMap(id, relMap, false, true).id);
|
|
1516
|
+
},
|
|
1517
|
+
specified: function specified(id) {
|
|
1518
|
+
id = makeModuleMap(id, relMap, false, true).id;
|
|
1519
|
+
return hasProp(_defined, id) || hasProp(registry, id);
|
|
1520
|
+
}
|
|
1521
|
+
});
|
|
1522
|
+
|
|
1523
|
+
// Only allow undef on top level require calls
|
|
1524
|
+
if (!relMap) {
|
|
1525
|
+
localRequire.undef = function (id) {
|
|
1526
|
+
// Bind any waiting define() calls to this context,
|
|
1527
|
+
// fix for #408
|
|
1528
|
+
takeGlobalQueue();
|
|
1529
|
+
var map = makeModuleMap(id, relMap, true);
|
|
1530
|
+
var mod = getOwn(registry, id);
|
|
1531
|
+
mod.undefed = true;
|
|
1532
|
+
removeScript(id);
|
|
1533
|
+
delete _defined[id];
|
|
1534
|
+
delete urlFetched[map.url];
|
|
1535
|
+
delete undefEvents[id];
|
|
1536
|
+
|
|
1537
|
+
// Clean queued defines too. Go backwards
|
|
1538
|
+
// in array so that the splices do not
|
|
1539
|
+
// mess up the iteration.
|
|
1540
|
+
eachReverse(defQueue, function (args, i) {
|
|
1541
|
+
if (args[0] === id) {
|
|
1542
|
+
defQueue.splice(i, 1);
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1545
|
+
delete context.defQueueMap[id];
|
|
1546
|
+
if (mod) {
|
|
1547
|
+
// Hold on to listeners in case the
|
|
1548
|
+
// module will be attempted to be reloaded
|
|
1549
|
+
// using a different config.
|
|
1550
|
+
if (mod.events.defined) {
|
|
1551
|
+
undefEvents[id] = mod.events;
|
|
1552
|
+
}
|
|
1553
|
+
cleanRegistry(id);
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
return localRequire;
|
|
1558
|
+
},
|
|
1559
|
+
/**
|
|
1560
|
+
* Called to enable a module if it is still in the registry
|
|
1561
|
+
* awaiting enablement. A second arg, parent, the parent module,
|
|
1562
|
+
* is passed in for context, when this method is overridden by
|
|
1563
|
+
* the optimizer. Not shown here to keep code compact.
|
|
1564
|
+
*/
|
|
1565
|
+
enable: function enable(depMap) {
|
|
1566
|
+
var mod = getOwn(registry, depMap.id);
|
|
1567
|
+
if (mod) {
|
|
1568
|
+
getModule(depMap).enable();
|
|
1569
|
+
}
|
|
1570
|
+
},
|
|
1571
|
+
/**
|
|
1572
|
+
* Internal method used by environment adapters to complete a load event.
|
|
1573
|
+
* A load event could be a script load or just a load pass from a synchronous
|
|
1574
|
+
* load call.
|
|
1575
|
+
* @param {String} moduleName the name of the module to potentially complete.
|
|
1576
|
+
*/
|
|
1577
|
+
completeLoad: function completeLoad(moduleName) {
|
|
1578
|
+
var found;
|
|
1579
|
+
var args;
|
|
1580
|
+
var mod;
|
|
1581
|
+
var shim = getOwn(_config.shim, moduleName) || {};
|
|
1582
|
+
var shExports = shim.exports;
|
|
1583
|
+
takeGlobalQueue();
|
|
1584
|
+
while (defQueue.length) {
|
|
1585
|
+
args = defQueue.shift();
|
|
1586
|
+
if (args[0] === null) {
|
|
1587
|
+
args[0] = moduleName;
|
|
1588
|
+
// If already found an anonymous module and bound it
|
|
1589
|
+
// to this name, then this is some other anon module
|
|
1590
|
+
// waiting for its completeLoad to fire.
|
|
1591
|
+
if (found) {
|
|
1592
|
+
break;
|
|
1593
|
+
}
|
|
1594
|
+
found = true;
|
|
1595
|
+
} else if (args[0] === moduleName) {
|
|
1596
|
+
// Found matching define call for this script!
|
|
1597
|
+
found = true;
|
|
1598
|
+
}
|
|
1599
|
+
callGetModule(args);
|
|
1600
|
+
}
|
|
1601
|
+
context.defQueueMap = {};
|
|
1602
|
+
|
|
1603
|
+
// Do this after the cycle of callGetModule in case the result
|
|
1604
|
+
// of those calls/init calls changes the registry.
|
|
1605
|
+
mod = getOwn(registry, moduleName);
|
|
1606
|
+
if (!found && !hasProp(_defined, moduleName) && mod && !mod.inited) {
|
|
1607
|
+
if (_config.enforceDefine && (!shExports || !getGlobal(shExports))) {
|
|
1608
|
+
if (hasPathFallback(moduleName)) {
|
|
1609
|
+
return;
|
|
1610
|
+
} else {
|
|
1611
|
+
return onError(makeError('nodefine', 'No define call for ' + moduleName, null, [moduleName]));
|
|
1612
|
+
}
|
|
1613
|
+
} else {
|
|
1614
|
+
// A script that does not call define(), so just simulate
|
|
1615
|
+
// the call for it.
|
|
1616
|
+
callGetModule([moduleName, shim.deps || [], shim.exportsFn]);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
checkLoaded();
|
|
1620
|
+
},
|
|
1621
|
+
/**
|
|
1622
|
+
* Converts a module name to a file path. Supports cases where
|
|
1623
|
+
* moduleName may actually be just an URL.
|
|
1624
|
+
* Note that it **does not** call normalize on the moduleName,
|
|
1625
|
+
* it is assumed to have already been normalized. This is an
|
|
1626
|
+
* internal API, not a public one. Use toUrl for the public API.
|
|
1627
|
+
*/
|
|
1628
|
+
nameToUrl: function nameToUrl(moduleName, ext, skipExt) {
|
|
1629
|
+
var paths;
|
|
1630
|
+
var syms;
|
|
1631
|
+
var i;
|
|
1632
|
+
var parentModule;
|
|
1633
|
+
var url;
|
|
1634
|
+
var parentPath;
|
|
1635
|
+
var bundleId;
|
|
1636
|
+
var pkgMain = getOwn(_config.pkgs, moduleName);
|
|
1637
|
+
if (pkgMain) {
|
|
1638
|
+
moduleName = pkgMain;
|
|
1639
|
+
}
|
|
1640
|
+
bundleId = getOwn(bundlesMap, moduleName);
|
|
1641
|
+
if (bundleId) {
|
|
1642
|
+
return context.nameToUrl(bundleId, ext, skipExt);
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
// If a colon is in the URL, it indicates a protocol is used and it is just
|
|
1646
|
+
// an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
|
|
1647
|
+
// or ends with .js, then assume the user meant to use an url and not a module id.
|
|
1648
|
+
// The slash is important for protocol-less URLs as well as full paths.
|
|
1649
|
+
if (req.jsExtRegExp.test(moduleName)) {
|
|
1650
|
+
// Just a plain path, not module name lookup, so just return it.
|
|
1651
|
+
// Add extension if it is included. This is a bit wonky, only non-.js things pass
|
|
1652
|
+
// an extension, this method probably needs to be reworked.
|
|
1653
|
+
url = moduleName + (ext || '');
|
|
1654
|
+
} else {
|
|
1655
|
+
// A module that needs to be converted to a path.
|
|
1656
|
+
paths = _config.paths;
|
|
1657
|
+
syms = moduleName.split('/');
|
|
1658
|
+
// For each module name segment, see if there is a path
|
|
1659
|
+
// registered for it. Start with most specific name
|
|
1660
|
+
// and work up from it.
|
|
1661
|
+
for (i = syms.length; i > 0; i -= 1) {
|
|
1662
|
+
parentModule = syms.slice(0, i).join('/');
|
|
1663
|
+
parentPath = getOwn(paths, parentModule);
|
|
1664
|
+
if (parentPath) {
|
|
1665
|
+
// If an array, it means there are a few choices,
|
|
1666
|
+
// Choose the one that is desired
|
|
1667
|
+
if (isArray(parentPath)) {
|
|
1668
|
+
parentPath = parentPath[0];
|
|
1669
|
+
}
|
|
1670
|
+
syms.splice(0, i, parentPath);
|
|
1671
|
+
break;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
// Join the path parts together, then figure out if baseUrl is needed.
|
|
1676
|
+
url = syms.join('/');
|
|
1677
|
+
url += ext || (/^data:|^blob:|\?/.test(url) || skipExt ? '' : '.js');
|
|
1678
|
+
url = (url.charAt(0) === '/' || url.match(/^[\w+.-]+:/) ? '' : _config.baseUrl) + url;
|
|
1679
|
+
}
|
|
1680
|
+
return _config.urlArgs && !/^blob:/.test(url) ? url + _config.urlArgs(moduleName, url) : url;
|
|
1681
|
+
},
|
|
1682
|
+
// Delegates to req.load. Broken out as a separate function to
|
|
1683
|
+
// allow overriding in the optimizer.
|
|
1684
|
+
load: function load(id, url) {
|
|
1685
|
+
req.load(context, id, url);
|
|
1686
|
+
},
|
|
1687
|
+
/**
|
|
1688
|
+
* Executes a module callback function. Broken out as a separate function
|
|
1689
|
+
* solely to allow the build system to sequence the files in the built
|
|
1690
|
+
* layer in the right sequence.
|
|
1691
|
+
*
|
|
1692
|
+
* @private
|
|
1693
|
+
*/
|
|
1694
|
+
execCb: function execCb(name, callback, args, exports) {
|
|
1695
|
+
return callback.apply(exports, args);
|
|
1696
|
+
},
|
|
1697
|
+
/**
|
|
1698
|
+
* callback for script loads, used to check status of loading.
|
|
1699
|
+
*
|
|
1700
|
+
* @param {Event} evt the event from the browser for the script
|
|
1701
|
+
* that was loaded.
|
|
1702
|
+
*/
|
|
1703
|
+
onScriptLoad: function onScriptLoad(evt) {
|
|
1704
|
+
// Using currentTarget instead of target for Firefox 2.0's sake. Not
|
|
1705
|
+
// all old browsers will be supported, but this one was easy enough
|
|
1706
|
+
// to support and still makes sense.
|
|
1707
|
+
if (evt.type === 'load' || readyRegExp.test((evt.currentTarget || evt.srcElement).readyState)) {
|
|
1708
|
+
// Reset interactive script so a script node is not held onto for
|
|
1709
|
+
// to long.
|
|
1710
|
+
interactiveScript = null;
|
|
1711
|
+
|
|
1712
|
+
// Pull out the name of the module and the context.
|
|
1713
|
+
var data = getScriptData(evt);
|
|
1714
|
+
context.completeLoad(data.id);
|
|
1715
|
+
}
|
|
1716
|
+
},
|
|
1717
|
+
/**
|
|
1718
|
+
* Callback for script errors.
|
|
1719
|
+
*/
|
|
1720
|
+
onScriptError: function onScriptError(evt) {
|
|
1721
|
+
var data = getScriptData(evt);
|
|
1722
|
+
if (!hasPathFallback(data.id)) {
|
|
1723
|
+
var parents = [];
|
|
1724
|
+
eachProp(registry, function (value, key) {
|
|
1725
|
+
if (key.indexOf('_@r') !== 0) {
|
|
1726
|
+
each(value.depMaps, function (depMap) {
|
|
1727
|
+
if (depMap.id === data.id) {
|
|
1728
|
+
parents.push(key);
|
|
1729
|
+
return true;
|
|
1730
|
+
}
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
});
|
|
1734
|
+
return onError(makeError('scripterror', 'Script error for "' + data.id + (parents.length ? '", needed by: ' + parents.join(', ') : '"'), evt, [data.id]));
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
context.require = context.makeRequire();
|
|
1739
|
+
return context;
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
/**
|
|
1743
|
+
* Main entry point.
|
|
1744
|
+
*
|
|
1745
|
+
* If the only argument to require is a string, then the module that
|
|
1746
|
+
* is represented by that string is fetched for the appropriate context.
|
|
1747
|
+
*
|
|
1748
|
+
* If the first argument is an array, then it will be treated as an array
|
|
1749
|
+
* of dependency string names to fetch. An optional function callback can
|
|
1750
|
+
* be specified to execute when all of those dependencies are available.
|
|
1751
|
+
*
|
|
1752
|
+
* Make a local req variable to help Caja compliance (it assumes things
|
|
1753
|
+
* on a require that are not standardized), and to give a short
|
|
1754
|
+
* name for minification/local scope use.
|
|
1755
|
+
*/
|
|
1756
|
+
req = requirejs = function requirejs(deps, callback, errback, optional) {
|
|
1757
|
+
var contextOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1758
|
+
// Find the right context, use default
|
|
1759
|
+
var context;
|
|
1760
|
+
var config;
|
|
1761
|
+
var contextName = defContextName;
|
|
1762
|
+
|
|
1763
|
+
// Determine if have config object in the call.
|
|
1764
|
+
if (!isArray(deps) && typeof deps !== 'string') {
|
|
1765
|
+
// deps is a config object
|
|
1766
|
+
config = deps;
|
|
1767
|
+
if (isArray(callback)) {
|
|
1768
|
+
// Adjust args if there are dependencies
|
|
1769
|
+
deps = callback;
|
|
1770
|
+
callback = errback;
|
|
1771
|
+
errback = optional;
|
|
1772
|
+
} else {
|
|
1773
|
+
deps = [];
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
if (config && config.context) {
|
|
1777
|
+
contextName = config.context;
|
|
1778
|
+
}
|
|
1779
|
+
if (contextOptions.name) {
|
|
1780
|
+
contextName = contextOptions.name;
|
|
1781
|
+
}
|
|
1782
|
+
context = getOwn(contexts, contextName);
|
|
1783
|
+
if (!context) {
|
|
1784
|
+
context = contexts[contextName] = req.s.newContext(contextName, contextOptions);
|
|
1785
|
+
}
|
|
1786
|
+
if (config) {
|
|
1787
|
+
context.configure(config);
|
|
1788
|
+
}
|
|
1789
|
+
return context.require(deps, callback, errback);
|
|
1790
|
+
};
|
|
1791
|
+
|
|
1792
|
+
/**
|
|
1793
|
+
* Support require.config() to make it easier to cooperate with other
|
|
1794
|
+
* AMD loaders on globally agreed names.
|
|
1795
|
+
*/
|
|
1796
|
+
req.config = function (config) {
|
|
1797
|
+
return req(config);
|
|
1798
|
+
};
|
|
1799
|
+
|
|
1800
|
+
/**
|
|
1801
|
+
* Execute something after the current tick
|
|
1802
|
+
* of the event loop. Override for other envs
|
|
1803
|
+
* that have a better solution than setTimeout.
|
|
1804
|
+
* @param {Function} fn function to execute later.
|
|
1805
|
+
*/
|
|
1806
|
+
req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) {
|
|
1807
|
+
setTimeout(fn, 4);
|
|
1808
|
+
} : function (fn) {
|
|
1809
|
+
fn();
|
|
1810
|
+
};
|
|
1811
|
+
|
|
1812
|
+
/**
|
|
1813
|
+
* Export require as a global, but only if it does not already exist.
|
|
1814
|
+
*/
|
|
1815
|
+
if (!require) {
|
|
1816
|
+
require = req;
|
|
1817
|
+
}
|
|
1818
|
+
req.version = version;
|
|
1819
|
+
|
|
1820
|
+
// Used to filter out dependencies that are already paths.
|
|
1821
|
+
req.jsExtRegExp = /^\/|:|\?|\.js$|\.css$/;
|
|
1822
|
+
req.isBrowser = isBrowser;
|
|
1823
|
+
s = req.s = {
|
|
1824
|
+
contexts: contexts,
|
|
1825
|
+
newContext: newContext
|
|
1826
|
+
};
|
|
1827
|
+
|
|
1828
|
+
// Create default context.
|
|
1829
|
+
req({});
|
|
1830
|
+
|
|
1831
|
+
// Exports some context-sensitive methods on global require.
|
|
1832
|
+
each(['toUrl', 'undef', 'defined', 'specified'], function (prop) {
|
|
1833
|
+
// Reference from contexts instead of early binding to default context,
|
|
1834
|
+
// so that during builds, the latest instance of the default context
|
|
1835
|
+
// with its config gets used.
|
|
1836
|
+
req[prop] = function () {
|
|
1837
|
+
var ctx = contexts[defContextName];
|
|
1838
|
+
return ctx.require[prop].apply(ctx, arguments);
|
|
1839
|
+
};
|
|
1840
|
+
});
|
|
1841
|
+
if (isBrowser) {
|
|
1842
|
+
head = s.head = document.getElementsByTagName('head')[0];
|
|
1843
|
+
body = s.body = document.getElementsByTagName('body')[0];
|
|
1844
|
+
// If BASE tag is in play, using appendChild is a problem for IE6.
|
|
1845
|
+
// When that browser dies, this can be removed. Details in this jQuery bug:
|
|
1846
|
+
// http://dev.jquery.com/ticket/2709
|
|
1847
|
+
baseElement = document.getElementsByTagName('base')[0];
|
|
1848
|
+
if (baseElement) {
|
|
1849
|
+
head = s.head = baseElement.parentNode;
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
/**
|
|
1854
|
+
* Any errors that require explicitly generates will be passed to this
|
|
1855
|
+
* function. Intercept/override it if you want custom error handling.
|
|
1856
|
+
* @param {Error} err the error object.
|
|
1857
|
+
*/
|
|
1858
|
+
req.onError = defaultOnError;
|
|
1859
|
+
|
|
1860
|
+
/**
|
|
1861
|
+
* Creates the node for the load command. Only used in browser envs.
|
|
1862
|
+
*/
|
|
1863
|
+
req.createNode = function (config, moduleName, url) {
|
|
1864
|
+
// get type css
|
|
1865
|
+
var type = '';
|
|
1866
|
+
try {
|
|
1867
|
+
var urls = url.split('?');
|
|
1868
|
+
if (urls[0].endsWith('.css')) type = 'css';
|
|
1869
|
+
} catch (error) {}
|
|
1870
|
+
if (type === 'css') {
|
|
1871
|
+
// css
|
|
1872
|
+
var node = config.xhtml ? document.createElementNS('http://www.w3.org/1999/xhtml', 'html:link') : document.createElement('link');
|
|
1873
|
+
node.href = url;
|
|
1874
|
+
node.rel = 'stylesheet';
|
|
1875
|
+
node.type = config.linkType || 'text/css';
|
|
1876
|
+
return node;
|
|
1877
|
+
} else {
|
|
1878
|
+
var node = config.xhtml ? document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') : document.createElement('script');
|
|
1879
|
+
node.type = config.scriptType || 'text/javascript';
|
|
1880
|
+
node.charset = 'utf-8';
|
|
1881
|
+
node.async = false;
|
|
1882
|
+
return node;
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
|
|
1886
|
+
/**
|
|
1887
|
+
* Does the request to load a module for the browser case.
|
|
1888
|
+
* Make this a separate function to allow other environments
|
|
1889
|
+
* to override it.
|
|
1890
|
+
*
|
|
1891
|
+
* @param {Object} context the require context to find state.
|
|
1892
|
+
* @param {String} moduleName the name of the module.
|
|
1893
|
+
* @param {Object} url the URL to the module.
|
|
1894
|
+
*/
|
|
1895
|
+
req.load = function (context, moduleName, url) {
|
|
1896
|
+
var config = context && context.config || {};
|
|
1897
|
+
var node;
|
|
1898
|
+
if (isBrowser) {
|
|
1899
|
+
// In the browser so use a script tag
|
|
1900
|
+
node = req.createNode(config, moduleName, url);
|
|
1901
|
+
node.setAttribute('data-requirecontext', context.contextName);
|
|
1902
|
+
node.setAttribute('data-requiremodule', moduleName);
|
|
1903
|
+
|
|
1904
|
+
// Set up load listener. Test attachEvent first because IE9 has
|
|
1905
|
+
// a subtle issue in its addEventListener and script onload firings
|
|
1906
|
+
// that do not match the behavior of all other browsers with
|
|
1907
|
+
// addEventListener support, which fire the onload event for a
|
|
1908
|
+
// script right after the script execution. See:
|
|
1909
|
+
// https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
|
|
1910
|
+
// UNFORTUNATELY Opera implements attachEvent but does not follow the script
|
|
1911
|
+
// script execution mode.
|
|
1912
|
+
if (node.attachEvent &&
|
|
1913
|
+
// Check if node.attachEvent is artificially added by custom script or
|
|
1914
|
+
// natively supported by browser
|
|
1915
|
+
// read https://github.com/requirejs/requirejs/issues/187
|
|
1916
|
+
// if we can NOT find [native code] then it must NOT natively supported.
|
|
1917
|
+
// in IE8, node.attachEvent does not have toString()
|
|
1918
|
+
// Note the test for "[native code" with no closing brace, see:
|
|
1919
|
+
// https://github.com/requirejs/requirejs/issues/273
|
|
1920
|
+
!(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) && !isOpera) {
|
|
1921
|
+
// Probably IE. IE (at least 6-8) do not fire
|
|
1922
|
+
// script onload right after executing the script, so
|
|
1923
|
+
// we cannot tie the anonymous define call to a name.
|
|
1924
|
+
// However, IE reports the script as being in 'interactive'
|
|
1925
|
+
// readyState at the time of the define call.
|
|
1926
|
+
useInteractive = true;
|
|
1927
|
+
node.attachEvent('onreadystatechange', context.onScriptLoad);
|
|
1928
|
+
// It would be great to add an error handler here to catch
|
|
1929
|
+
// 404s in IE9+. However, onreadystatechange will fire before
|
|
1930
|
+
// the error handler, so that does not help. If addEventListener
|
|
1931
|
+
// is used, then IE will fire error before load, but we cannot
|
|
1932
|
+
// use that pathway given the connect.microsoft.com issue
|
|
1933
|
+
// mentioned above about not doing the 'script execute,
|
|
1934
|
+
// then fire the script load event listener before execute
|
|
1935
|
+
// next script' that other browsers do.
|
|
1936
|
+
// Best hope: IE10 fixes the issues,
|
|
1937
|
+
// and then destroys all installs of IE 6-9.
|
|
1938
|
+
// node.attachEvent('onerror', context.onScriptError);
|
|
1939
|
+
} else {
|
|
1940
|
+
node.addEventListener('load', context.onScriptLoad, false);
|
|
1941
|
+
node.addEventListener('error', context.onScriptError, false);
|
|
1942
|
+
}
|
|
1943
|
+
node.src = url;
|
|
1944
|
+
|
|
1945
|
+
// Calling onNodeCreated after all properties on the node have been
|
|
1946
|
+
// set, but before it is placed in the DOM.
|
|
1947
|
+
if (config.onNodeCreated) {
|
|
1948
|
+
config.onNodeCreated(node, config, moduleName, url);
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
// For some cache cases in IE 6-8, the script executes before the end
|
|
1952
|
+
// of the appendChild execution, so to tie an anonymous define
|
|
1953
|
+
// call to the module name (which is stored on the node), hold on
|
|
1954
|
+
// to a reference to this node, but clear after the DOM insertion.
|
|
1955
|
+
currentlyAddingScript = node;
|
|
1956
|
+
if (baseElement) {
|
|
1957
|
+
head.insertBefore(node, baseElement);
|
|
1958
|
+
} else {
|
|
1959
|
+
// 微前端-阿里qiankun没有document.currentScript,webpack5生成异步chunk的访问地址404问题
|
|
1960
|
+
if (body) {
|
|
1961
|
+
body.appendChild(node);
|
|
1962
|
+
} else {
|
|
1963
|
+
head.appendChild(node);
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
currentlyAddingScript = null;
|
|
1967
|
+
return node;
|
|
1968
|
+
} else if (isWebWorker) {
|
|
1969
|
+
try {
|
|
1970
|
+
// In a web worker, use importScripts. This is not a very
|
|
1971
|
+
// efficient use of importScripts, importScripts will block until
|
|
1972
|
+
// its script is downloaded and evaluated. However, if web workers
|
|
1973
|
+
// are in play, the expectation is that a build has been done so
|
|
1974
|
+
// that only one script needs to be loaded anyway. This may need
|
|
1975
|
+
// to be reevaluated if other use cases become common.
|
|
1976
|
+
|
|
1977
|
+
// Post a task to the event loop to work around a bug in WebKit
|
|
1978
|
+
// where the worker gets garbage-collected after calling
|
|
1979
|
+
// importScripts(): https://webkit.org/b/153317
|
|
1980
|
+
setTimeout(function () {}, 0);
|
|
1981
|
+
importScripts(url);
|
|
1982
|
+
|
|
1983
|
+
// Account for anonymous modules
|
|
1984
|
+
context.completeLoad(moduleName);
|
|
1985
|
+
} catch (e) {
|
|
1986
|
+
context.onError(makeError('importscripts', 'importScripts failed for ' + moduleName + ' at ' + url, e, [moduleName]));
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
};
|
|
1990
|
+
function getInteractiveScript() {
|
|
1991
|
+
if (interactiveScript && interactiveScript.readyState === 'interactive') {
|
|
1992
|
+
return interactiveScript;
|
|
1993
|
+
}
|
|
1994
|
+
eachReverse(scripts(), function (script) {
|
|
1995
|
+
if (script.readyState === 'interactive') {
|
|
1996
|
+
return interactiveScript = script;
|
|
1997
|
+
}
|
|
1998
|
+
});
|
|
1999
|
+
return interactiveScript;
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
// Look for a data-main script attribute, which could also adjust the baseUrl.
|
|
2003
|
+
if (isBrowser && !cfg.skipDataMain) {
|
|
2004
|
+
// Figure out baseUrl. Get it from the script tag with require.js in it.
|
|
2005
|
+
eachReverse(scripts(), function (script) {
|
|
2006
|
+
// Set the 'head' where we can append children by
|
|
2007
|
+
// using the script's parent.
|
|
2008
|
+
if (!head) {
|
|
2009
|
+
head = script.parentNode;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
// Look for a data-main attribute to set main script for the page
|
|
2013
|
+
// to load. If it is there, the path to data main becomes the
|
|
2014
|
+
// baseUrl, if it is not already set.
|
|
2015
|
+
dataMain = script.getAttribute('data-main');
|
|
2016
|
+
if (dataMain) {
|
|
2017
|
+
// Preserve dataMain in case it is a path (i.e. contains '?')
|
|
2018
|
+
mainScript = dataMain;
|
|
2019
|
+
|
|
2020
|
+
// Set final baseUrl if there is not already an explicit one,
|
|
2021
|
+
// but only do so if the data-main value is not a loader plugin
|
|
2022
|
+
// module ID.
|
|
2023
|
+
if (!cfg.baseUrl && mainScript.indexOf('!') === -1) {
|
|
2024
|
+
// Pull off the directory of data-main for use as the
|
|
2025
|
+
// baseUrl.
|
|
2026
|
+
src = mainScript.split('/');
|
|
2027
|
+
mainScript = src.pop();
|
|
2028
|
+
subPath = src.length ? src.join('/') + '/' : './';
|
|
2029
|
+
cfg.baseUrl = subPath;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
// Strip off any trailing .js since mainScript is now
|
|
2033
|
+
// like a module name.
|
|
2034
|
+
mainScript = mainScript.replace(jsSuffixRegExp, '');
|
|
2035
|
+
|
|
2036
|
+
// If mainScript is still a path, fall back to dataMain
|
|
2037
|
+
if (req.jsExtRegExp.test(mainScript)) {
|
|
2038
|
+
mainScript = dataMain;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
// Put the data-main script in the files to load.
|
|
2042
|
+
cfg.deps = cfg.deps ? cfg.deps.concat(mainScript) : [mainScript];
|
|
2043
|
+
return true;
|
|
2044
|
+
}
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
/**
|
|
2049
|
+
* The function that handles definitions of modules. Differs from
|
|
2050
|
+
* require() in that a string for the module should be the first argument,
|
|
2051
|
+
* and the function to execute after dependencies are loaded should
|
|
2052
|
+
* return a value to define the module corresponding to the first argument's
|
|
2053
|
+
* name.
|
|
2054
|
+
*/
|
|
2055
|
+
define = function define(name, deps, callback) {
|
|
2056
|
+
var node, context;
|
|
2057
|
+
|
|
2058
|
+
// Allow for anonymous modules
|
|
2059
|
+
if (typeof name !== 'string') {
|
|
2060
|
+
// Adjust args appropriately
|
|
2061
|
+
callback = deps;
|
|
2062
|
+
deps = name;
|
|
2063
|
+
name = null;
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
// This module may not have dependencies
|
|
2067
|
+
if (!isArray(deps)) {
|
|
2068
|
+
callback = deps;
|
|
2069
|
+
deps = null;
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
// If no name, and callback is a function, then figure out if it a
|
|
2073
|
+
// CommonJS thing with dependencies.
|
|
2074
|
+
if (!deps && isFunction(callback)) {
|
|
2075
|
+
deps = [];
|
|
2076
|
+
// Remove comments from the callback string,
|
|
2077
|
+
// look for require calls, and pull them into the dependencies,
|
|
2078
|
+
// but only if there are function args.
|
|
2079
|
+
if (callback.length) {
|
|
2080
|
+
callback.toString().replace(commentRegExp, commentReplace).replace(cjsRequireRegExp, function (match, dep) {
|
|
2081
|
+
deps.push(dep);
|
|
2082
|
+
});
|
|
2083
|
+
|
|
2084
|
+
// May be a CommonJS thing even without require calls, but still
|
|
2085
|
+
// could use exports, and module. Avoid doing exports and module
|
|
2086
|
+
// work though if it just needs require.
|
|
2087
|
+
// REQUIRES the function to expect the CommonJS variables in the
|
|
2088
|
+
// order listed below.
|
|
2089
|
+
deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
// If in IE 6-8 and hit an anonymous define() call, do the interactive
|
|
2094
|
+
// work.
|
|
2095
|
+
if (useInteractive) {
|
|
2096
|
+
node = currentlyAddingScript || getInteractiveScript();
|
|
2097
|
+
if (node) {
|
|
2098
|
+
if (!name) {
|
|
2099
|
+
name = node.getAttribute('data-requiremodule');
|
|
2100
|
+
}
|
|
2101
|
+
context = contexts[node.getAttribute('data-requirecontext')];
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
// Always save off evaluating the def call until the script onload handler.
|
|
2106
|
+
// This allows multiple modules to be in a file without prematurely
|
|
2107
|
+
// tracing dependencies, and allows for anonymous module support,
|
|
2108
|
+
// where the module name is not known until the script onload event
|
|
2109
|
+
// occurs. If no context, use the global queue, and get it processed
|
|
2110
|
+
// in the onscript load callback.
|
|
2111
|
+
if (context) {
|
|
2112
|
+
context.defQueue.push([name, deps, callback]);
|
|
2113
|
+
context.defQueueMap[name] = true;
|
|
2114
|
+
} else {
|
|
2115
|
+
globalDefQueue.push([name, deps, callback]);
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
define.amd = {
|
|
2119
|
+
jQuery: true
|
|
2120
|
+
};
|
|
2121
|
+
|
|
2122
|
+
/**
|
|
2123
|
+
* Executes the text. Normally just uses eval, but can be modified
|
|
2124
|
+
* to use a better, environment-specific call. Only used for transpiling
|
|
2125
|
+
* loader plugins, not for plain JS modules.
|
|
2126
|
+
* @param {String} text the text to execute/evaluate.
|
|
2127
|
+
*/
|
|
2128
|
+
req.exec = function (text) {
|
|
2129
|
+
/* jslint evil: true */
|
|
2130
|
+
// eslint-disable-next-line no-eval
|
|
2131
|
+
return eval(text);
|
|
2132
|
+
};
|
|
2133
|
+
__devfab_requirejs.require = require;
|
|
2134
|
+
__devfab_requirejs.define = define;
|
|
2135
|
+
// Set up with config info.
|
|
2136
|
+
req(cfg);
|
|
2137
|
+
})(commonjsGlobal, typeof setTimeout === 'undefined' ? undefined : setTimeout)
|
|
2138
|
+
|
|
2139
|
+
/* ----------------------------------------------------------------------------
|
|
2140
|
+
* 以下为本地适配层,不属于 RequireJS 原始文件内容。
|
|
2141
|
+
* -------------------------------------------------------------------------- */;
|
|
2142
|
+
(function (global) {
|
|
2143
|
+
if (__devfab_requirejs.__requirejsAdapterApplied) {
|
|
2144
|
+
return;
|
|
2145
|
+
}
|
|
2146
|
+
__devfab_requirejs.__requirejsAdapterApplied = true;
|
|
2147
|
+
var rawRequire = __devfab_requirejs.require;
|
|
2148
|
+
var rawDefine = __devfab_requirejs.define;
|
|
2149
|
+
var require = function require(_domain, _deps, _callback, _errback) {
|
|
2150
|
+
var domain = _domain;
|
|
2151
|
+
var deps = _deps;
|
|
2152
|
+
var callback = _callback;
|
|
2153
|
+
var errback = _errback;
|
|
2154
|
+
if (Array.isArray(_domain) && typeof _deps === 'function') {
|
|
2155
|
+
deps = _domain;
|
|
2156
|
+
callback = _deps;
|
|
2157
|
+
errback = _callback;
|
|
2158
|
+
rawRequire(deps, callback, errback);
|
|
2159
|
+
return;
|
|
2160
|
+
}
|
|
2161
|
+
if (!_domain && Array.isArray(deps)) {
|
|
2162
|
+
domain = [];
|
|
2163
|
+
}
|
|
2164
|
+
if (Array.isArray(domain) && Array.isArray(deps)) {
|
|
2165
|
+
domain = domain.join('/');
|
|
2166
|
+
}
|
|
2167
|
+
var newdeps = domain ? [] : deps;
|
|
2168
|
+
if (typeof domain === 'string' && domain && Array.isArray(deps)) {
|
|
2169
|
+
deps.forEach(function (item) {
|
|
2170
|
+
newdeps.push("".concat(domain).concat(item.substr(0, 1) === '/' ? '' : '/').concat(item));
|
|
2171
|
+
});
|
|
2172
|
+
}
|
|
2173
|
+
console.debug('[devfab][requirejs]: %c requireInner, Parameter[newdeps] is %o', 'color:fuchsia', newdeps);
|
|
2174
|
+
rawRequire(newdeps, callback, errback);
|
|
2175
|
+
};
|
|
2176
|
+
var define = function define(_domain, _deps, _callback) {
|
|
2177
|
+
var domain = _domain;
|
|
2178
|
+
var deps = _deps;
|
|
2179
|
+
var callback = _callback;
|
|
2180
|
+
if (Array.isArray(_domain) && typeof _deps === 'function') {
|
|
2181
|
+
deps = _domain;
|
|
2182
|
+
callback = _deps;
|
|
2183
|
+
rawDefine(deps, callback);
|
|
2184
|
+
return;
|
|
2185
|
+
}
|
|
2186
|
+
if (!_domain && Array.isArray(deps)) {
|
|
2187
|
+
domain = [];
|
|
2188
|
+
}
|
|
2189
|
+
if (Array.isArray(domain) && Array.isArray(deps)) {
|
|
2190
|
+
domain = domain.join('/');
|
|
2191
|
+
}
|
|
2192
|
+
var newdeps = domain ? [] : deps;
|
|
2193
|
+
if (typeof domain === 'string' && domain && Array.isArray(deps)) {
|
|
2194
|
+
deps.forEach(function (item) {
|
|
2195
|
+
newdeps.push("".concat(domain).concat(item.substr(0, 1) === '/' ? '' : '/').concat(item));
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2198
|
+
rawDefine(newdeps, callback);
|
|
2199
|
+
};
|
|
2200
|
+
|
|
2201
|
+
// RequireJS 把 config / undef / defined / specified / onError / toUrl 等 API
|
|
2202
|
+
// 挂在 require 函数本身。包装后若不转发,这些能力会整片消失:
|
|
2203
|
+
// urlArgs 配不上(版本号进不了 URL)、失败模块 undef 不掉(重试必然复用失败状态)、
|
|
2204
|
+
// 已加载状态查不到。这里按自有属性逐个复制,包装函数已有的键不覆盖。
|
|
2205
|
+
for (var prop in rawRequire) {
|
|
2206
|
+
if (Object.prototype.hasOwnProperty.call(rawRequire, prop) && typeof require[prop] === 'undefined') {
|
|
2207
|
+
require[prop] = rawRequire[prop];
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
__devfab_requirejs._require = rawRequire;
|
|
2211
|
+
__devfab_requirejs._define = rawDefine;
|
|
2212
|
+
__devfab_requirejs.require = require;
|
|
2213
|
+
__devfab_requirejs.define = define;
|
|
2214
|
+
})();
|
|
2215
|
+
|
|
2216
|
+
/**
|
|
2217
|
+
* 加载策略层:清单登记(manifest)+ 域名白名单 + 版本锁 + 完整性校验。
|
|
2218
|
+
*
|
|
2219
|
+
* 定位:让「运行时加载远端脚本」从**风险**变成**可审计的特性**。
|
|
2220
|
+
* 这一层不做代码隔离(那是沙箱的事),只回答一个问题:这段代码该不该被执行。
|
|
2221
|
+
*
|
|
2222
|
+
* 边界(如实告知宿主,别指望它做它做不到的事):
|
|
2223
|
+
* - sha256 校验依赖 `fetch` + `crypto.subtle`。AMD 通道拿不到脚本文本(RequireJS
|
|
2224
|
+
* 自己插 <script>),所以 AMD 侧只做「登记制 + 域名白名单 + 版本锁」;
|
|
2225
|
+
* 完整性校验用在 ESM 通道(loadModules)与构建期(scripts/manifest.js)。
|
|
2226
|
+
* - `crypto.subtle` 只在安全上下文(https / localhost)可用,非安全上下文会跳过,
|
|
2227
|
+
* 跳过这件事会体现在返回值的 `skipped` 里,不静默通过。
|
|
2228
|
+
*
|
|
2229
|
+
* ============================================================================
|
|
2230
|
+
* manifest.json 的格式与生成
|
|
2231
|
+
* ============================================================================
|
|
2232
|
+
*
|
|
2233
|
+
* 由 `node scripts/manifest.js <扫描目录>` 在**构建期**产出,随静态资源一起发布。
|
|
2234
|
+
* 不要在运行时生成:让运行时自己扫目录算摘要,等于自己给自己发许可 —— 文件被改后
|
|
2235
|
+
* 重算一遍,清单就跟着变了,登记制当场失效。清单的效力来自「它在文件被修改之前
|
|
2236
|
+
* 就固定下来」。
|
|
2237
|
+
*
|
|
2238
|
+
* 格式只有四个顶层字段,多写不读:
|
|
2239
|
+
*
|
|
2240
|
+
* {
|
|
2241
|
+
* "name": "frontend-extends",
|
|
2242
|
+
* "version": "1.2.0",
|
|
2243
|
+
* "generatedAt": "2026-10-20T10:44:48.413Z",
|
|
2244
|
+
* "modules": {
|
|
2245
|
+
* "extendjs/frontend/frontend_view_list_FE.Extend.js": {
|
|
2246
|
+
* "sha256": "<64 位十六进制摘要>",
|
|
2247
|
+
* "size": 733
|
|
2248
|
+
* }
|
|
2249
|
+
* }
|
|
2250
|
+
* }
|
|
2251
|
+
*
|
|
2252
|
+
* 字段消费方:
|
|
2253
|
+
* - name -> describe(),只用于日志展示
|
|
2254
|
+
* - version -> checkVersion(),版本锁的比对基准,生成时请显式指定
|
|
2255
|
+
* - generatedAt -> 无人使用;仅供人工追溯。`--check` **故意不比对**它,
|
|
2256
|
+
* 否则每次生成都不同,CI 永远红。
|
|
2257
|
+
* - modules -> _moduleIndex(),登记制与完整性校验的数据源
|
|
2258
|
+
*
|
|
2259
|
+
* modules 支持两种形态(_moduleIndex 都能吃):
|
|
2260
|
+
* - 对象:{ "<模块 id>": { sha256, size } } <- scripts/manifest.js 的产出
|
|
2261
|
+
* - 数组:[{ path: "<模块 id>", sha256, size }] <- 手写或其他工具产出
|
|
2262
|
+
* 条目里的摘要字段名**必须是 sha256**。换成 hash / digest 之类的名字不会报错,
|
|
2263
|
+
* entryOf() 取不到值时走「无期望值」分支,完整性校验会被静默跳过。
|
|
2264
|
+
*
|
|
2265
|
+
* -------------------------- key 必须与模块 id 同形 --------------------------
|
|
2266
|
+
*
|
|
2267
|
+
* key 是相对扫描目录的路径,斜杠分隔,不带前导 `./` 或 `/`:
|
|
2268
|
+
*
|
|
2269
|
+
* 扫描 example/vue3/static -> key = extendjs/frontend/xxx_FE.Extend.js
|
|
2270
|
+
* 运行时 require(['extendjs', 'frontend'], ['xxx_FE.Extend.js'])
|
|
2271
|
+
* -> 模块 id = extendjs/frontend/xxx_FE.Extend.js 一致
|
|
2272
|
+
*
|
|
2273
|
+
* 这就是 toModuleIds()(运行时)与 manifest.js 的 toKey()(构建期)必须同构的原因。
|
|
2274
|
+
* 扫错层级时 key 会丢掉域前缀,现象是「明明登记了却全部 403」,此时用 --base 补:
|
|
2275
|
+
*
|
|
2276
|
+
* node scripts/manifest.js example/vue3/static/extendjs --base extendjs
|
|
2277
|
+
*
|
|
2278
|
+
* ----------------------------- 生成命令与参数 -----------------------------
|
|
2279
|
+
*
|
|
2280
|
+
* node scripts/manifest.js <扫描目录> [选项]
|
|
2281
|
+
*
|
|
2282
|
+
* --name <包名> 默认取目录名
|
|
2283
|
+
* --version <版本> 默认 1.0.0;**请始终显式传**,它是版本锁的基准
|
|
2284
|
+
* --base <前缀> 给 key 加路径前缀,默认空
|
|
2285
|
+
* --out <文件> 默认 <扫描目录>/manifest.json(放这里宿主才能访问到)
|
|
2286
|
+
* --check 只校验不写盘,与目录不一致时退出码 1,给 CI 用
|
|
2287
|
+
*
|
|
2288
|
+
* 扫描是递归的,且只收 `.js` / `.mjs`;已有的 manifest.json 会被跳过,不会自我递归。
|
|
2289
|
+
* 除生成外还支持一致性校验,能报出三类差异(清单缺少 / 文件已不存在 / 内容已变更):
|
|
2290
|
+
*
|
|
2291
|
+
* node scripts/manifest.js static --name frontend-extends --version 1.2.0 --check
|
|
2292
|
+
*
|
|
2293
|
+
* 接进宿主时注意时序:`configure({ manifest })` 之前发起的加载会按「无 manifest」
|
|
2294
|
+
* 放行,所以清单要在启动早期就绪(构建期 import,或启动时 await fetch)。
|
|
2295
|
+
*/
|
|
2296
|
+
|
|
2297
|
+
/** 策略拒绝:未登记、来源不在白名单、版本锁不匹配、完整性校验失败 */
|
|
2298
|
+
var CODE_POLICY = 403;
|
|
2299
|
+
|
|
2300
|
+
/**
|
|
2301
|
+
* 路径归一化。manifest 的 key 与运行时拼出来的模块 id 必须用同一种写法,
|
|
2302
|
+
* 否则「明明登记了却查不到」这类问题极难排查。
|
|
2303
|
+
*/
|
|
2304
|
+
function normalizePath(p) {
|
|
2305
|
+
return String(p == null ? '' : p).replace(/\\/g, '/').replace(/^\.\//, '').replace(/^\/+/, '');
|
|
2306
|
+
}
|
|
2307
|
+
function isAbsoluteUrl(url) {
|
|
2308
|
+
return /^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(url) || /^(?:blob|data):/i.test(url);
|
|
2309
|
+
}
|
|
2310
|
+
function toHex(buffer) {
|
|
2311
|
+
var bytes = new Uint8Array(buffer);
|
|
2312
|
+
var out = '';
|
|
2313
|
+
for (var i = 0; i < bytes.length; i++) {
|
|
2314
|
+
out += bytes[i].toString(16).padStart(2, '0');
|
|
2315
|
+
}
|
|
2316
|
+
return out;
|
|
2317
|
+
}
|
|
2318
|
+
var LoadPolicy = /*#__PURE__*/function () {
|
|
2319
|
+
function LoadPolicy(options) {
|
|
2320
|
+
_classCallCheck(this, LoadPolicy);
|
|
2321
|
+
this.manifest = null;
|
|
2322
|
+
this.origins = null;
|
|
2323
|
+
this.lockVersion = null;
|
|
2324
|
+
this.verifyHash = true;
|
|
2325
|
+
this.fetch = null;
|
|
2326
|
+
this._index = null;
|
|
2327
|
+
this.configure(options);
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
/** 增量配置:只覆盖传进来的字段,未传的保持原值 */
|
|
2331
|
+
return _createClass(LoadPolicy, [{
|
|
2332
|
+
key: "configure",
|
|
2333
|
+
value: function configure(options) {
|
|
2334
|
+
var o = options || {};
|
|
2335
|
+
if (o.manifest !== undefined) this.manifest = o.manifest || null;
|
|
2336
|
+
if (o.origins !== undefined) {
|
|
2337
|
+
this.origins = o.origins ? [].concat(o.origins).map(function (item) {
|
|
2338
|
+
return String(item).trim().replace(/\/+$/, '');
|
|
2339
|
+
}) : null;
|
|
2340
|
+
}
|
|
2341
|
+
if (o.lockVersion !== undefined) this.lockVersion = o.lockVersion || null;
|
|
2342
|
+
if (o.verifyHash !== undefined) this.verifyHash = !!o.verifyHash;
|
|
2343
|
+
if (o.fetch !== undefined) {
|
|
2344
|
+
this.fetch = o.fetch || null;
|
|
2345
|
+
} else if (!this.fetch && typeof fetch === 'function') {
|
|
2346
|
+
this.fetch = function () {
|
|
2347
|
+
return fetch.apply(void 0, arguments);
|
|
2348
|
+
};
|
|
2349
|
+
}
|
|
2350
|
+
this._index = null;
|
|
2351
|
+
return this;
|
|
2352
|
+
}
|
|
2353
|
+
}, {
|
|
2354
|
+
key: "enabled",
|
|
2355
|
+
get: function get() {
|
|
2356
|
+
return !!this.manifest;
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
/* ------------------------------ 清单 ------------------------------ */
|
|
2360
|
+
}, {
|
|
2361
|
+
key: "_moduleIndex",
|
|
2362
|
+
value: function _moduleIndex() {
|
|
2363
|
+
if (this._index) return this._index;
|
|
2364
|
+
var index = {};
|
|
2365
|
+
var modules = this.manifest && this.manifest.modules;
|
|
2366
|
+
if (Array.isArray(modules)) {
|
|
2367
|
+
modules.forEach(function (item) {
|
|
2368
|
+
if (item && item.path) index[normalizePath(item.path)] = item;
|
|
2369
|
+
});
|
|
2370
|
+
} else if (modules && _typeof(modules) === 'object') {
|
|
2371
|
+
Object.keys(modules).forEach(function (key) {
|
|
2372
|
+
index[normalizePath(key)] = modules[key] || {};
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2375
|
+
this._index = index;
|
|
2376
|
+
return index;
|
|
2377
|
+
}
|
|
2378
|
+
}, {
|
|
2379
|
+
key: "entryOf",
|
|
2380
|
+
value: function entryOf(moduleId) {
|
|
2381
|
+
if (!this.manifest) return null;
|
|
2382
|
+
return this._moduleIndex()[normalizePath(moduleId)] || null;
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
/** 版本锁:宿主钉死某个清单版本,防止「悄悄换了文件」 */
|
|
2386
|
+
}, {
|
|
2387
|
+
key: "checkVersion",
|
|
2388
|
+
value: function checkVersion() {
|
|
2389
|
+
if (!this.lockVersion || !this.manifest) return null;
|
|
2390
|
+
var actual = String(this.manifest.version || '');
|
|
2391
|
+
if (actual === String(this.lockVersion)) return null;
|
|
2392
|
+
return {
|
|
2393
|
+
code: CODE_POLICY,
|
|
2394
|
+
message: "\u6E05\u5355\u7248\u672C ".concat(actual || '(未声明)', " \u4E0E\u9501\u5B9A\u7248\u672C ").concat(this.lockVersion, " \u4E0D\u4E00\u81F4\uFF0C\u62D2\u7EDD\u52A0\u8F7D")
|
|
2395
|
+
};
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
/**
|
|
2399
|
+
* 批量校验一组模块 id。
|
|
2400
|
+
* - 未配置 manifest:登记制不启用,直接放行(保持对存量宿主的零影响);
|
|
2401
|
+
* - 配置了 manifest:不在清单里的一律拒,这是「只能跑经过打包的产物」的落点。
|
|
2402
|
+
*/
|
|
2403
|
+
}, {
|
|
2404
|
+
key: "checkModules",
|
|
2405
|
+
value: function checkModules(moduleIds) {
|
|
2406
|
+
var versionDenied = this.checkVersion();
|
|
2407
|
+
if (versionDenied) return versionDenied;
|
|
2408
|
+
if (!this.manifest) return null;
|
|
2409
|
+
for (var i = 0; i < moduleIds.length; i++) {
|
|
2410
|
+
var id = normalizePath(moduleIds[i]);
|
|
2411
|
+
if (!this._moduleIndex()[id]) {
|
|
2412
|
+
return {
|
|
2413
|
+
code: CODE_POLICY,
|
|
2414
|
+
message: "Module ".concat(id, " not registered in the list, loading denied.")
|
|
2415
|
+
};
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
return null;
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
/* ---------------------------- 白名单 ---------------------------- */
|
|
2422
|
+
}, {
|
|
2423
|
+
key: "checkOrigin",
|
|
2424
|
+
value: function checkOrigin(url) {
|
|
2425
|
+
if (!this.origins) return null;
|
|
2426
|
+
// 相对路径必然同源,不参与白名单判断
|
|
2427
|
+
if (!isAbsoluteUrl(url)) return null;
|
|
2428
|
+
var origin;
|
|
2429
|
+
try {
|
|
2430
|
+
origin = new URL(url).origin;
|
|
2431
|
+
} catch (err) {
|
|
2432
|
+
return {
|
|
2433
|
+
code: CODE_POLICY,
|
|
2434
|
+
message: "\u65E0\u6CD5\u89E3\u6790\u7684\u5730\u5740\uFF1A".concat(url)
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2437
|
+
if (this.origins.indexOf(origin) === -1) {
|
|
2438
|
+
return {
|
|
2439
|
+
code: CODE_POLICY,
|
|
2440
|
+
message: "\u6765\u6E90 ".concat(origin, " \u4E0D\u5728\u767D\u540D\u5355\u5185\uFF08\u5141\u8BB8\uFF1A").concat(this.origins.join(', '), "\uFF09")
|
|
2441
|
+
};
|
|
2442
|
+
}
|
|
2443
|
+
return null;
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
/* ---------------------------- 完整性 ---------------------------- */
|
|
2447
|
+
|
|
2448
|
+
/**
|
|
2449
|
+
* 预检 sha256:fetch 取文本算摘要,通过后调用方再真正加载。
|
|
2450
|
+
* 代价是多一次请求(浏览器缓存通常能命中),换来「文件被替换」能当场发现。
|
|
2451
|
+
*/
|
|
2452
|
+
}, {
|
|
2453
|
+
key: "verify",
|
|
2454
|
+
value: function verify(url, expected) {
|
|
2455
|
+
var _this = this;
|
|
2456
|
+
if (!this.verifyHash) return Promise.resolve({
|
|
2457
|
+
ok: true,
|
|
2458
|
+
skipped: 'disabled'
|
|
2459
|
+
});
|
|
2460
|
+
if (!expected) return Promise.resolve({
|
|
2461
|
+
ok: true
|
|
2462
|
+
});
|
|
2463
|
+
var subtle = typeof globalThis !== 'undefined' && globalThis.crypto && globalThis.crypto.subtle;
|
|
2464
|
+
if (!subtle) return Promise.resolve({
|
|
2465
|
+
ok: true,
|
|
2466
|
+
skipped: 'crypto.subtle unavailable(需要 https / localhost)'
|
|
2467
|
+
});
|
|
2468
|
+
if (!this.fetch) return Promise.resolve({
|
|
2469
|
+
ok: true,
|
|
2470
|
+
skipped: 'fetch unavailable'
|
|
2471
|
+
});
|
|
2472
|
+
return Promise.resolve().then(function () {
|
|
2473
|
+
return _this.fetch(url);
|
|
2474
|
+
}).then(function (res) {
|
|
2475
|
+
if (!res || !res.ok) {
|
|
2476
|
+
return {
|
|
2477
|
+
ok: false,
|
|
2478
|
+
message: "\u5B8C\u6574\u6027\u9884\u68C0\u8BF7\u6C42\u5931\u8D25\uFF1AHTTP ".concat(res && res.status || 'unknown')
|
|
2479
|
+
};
|
|
2480
|
+
}
|
|
2481
|
+
return res.arrayBuffer().then(function (buffer) {
|
|
2482
|
+
return subtle.digest('SHA-256', buffer);
|
|
2483
|
+
});
|
|
2484
|
+
}).then(function (digest) {
|
|
2485
|
+
if (!digest || digest.ok === false) return digest;
|
|
2486
|
+
var actual = toHex(digest);
|
|
2487
|
+
var want = String(expected).toLowerCase();
|
|
2488
|
+
if (actual !== want) {
|
|
2489
|
+
return {
|
|
2490
|
+
ok: false,
|
|
2491
|
+
message: "sha256 \u4E0D\u5339\u914D\uFF1A\u671F\u671B ".concat(want, "\uFF0C\u5B9E\u9645 ").concat(actual)
|
|
2492
|
+
};
|
|
2493
|
+
}
|
|
2494
|
+
return {
|
|
2495
|
+
ok: true
|
|
2496
|
+
};
|
|
2497
|
+
})["catch"](function (err) {
|
|
2498
|
+
return {
|
|
2499
|
+
ok: false,
|
|
2500
|
+
message: "\u5B8C\u6574\u6027\u9884\u68C0\u5F02\u5E38\uFF1A".concat(err && err.message || err),
|
|
2501
|
+
error: err
|
|
2502
|
+
};
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
/** 策略摘要:宿主启动时打一行日志,比事后翻代码有用 */
|
|
2507
|
+
}, {
|
|
2508
|
+
key: "describe",
|
|
2509
|
+
value: function describe() {
|
|
2510
|
+
return {
|
|
2511
|
+
manifest: this.enabled ? this.manifest.name || '(unnamed)' : null,
|
|
2512
|
+
version: this.manifest && this.manifest.version || null,
|
|
2513
|
+
lockVersion: this.lockVersion,
|
|
2514
|
+
modules: this.enabled ? Object.keys(this._moduleIndex()).length : 0,
|
|
2515
|
+
origins: this.origins ? this.origins.slice() : null,
|
|
2516
|
+
verifyHash: this.verifyHash
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
}]);
|
|
2520
|
+
}();
|
|
2521
|
+
|
|
2522
|
+
/**
|
|
2523
|
+
* 全局污染检测:加载前后 diff window 的 key 集合。
|
|
2524
|
+
*
|
|
2525
|
+
* 为什么需要:二开脚本直接跑在宿主 window 上,A 客户的脚本改了一个全局变量,
|
|
2526
|
+
* B 客户就跟着崩,而且现场无法归因。真做 iframe / Proxy 沙箱成本极高,
|
|
2527
|
+
* 但「加载完能告诉你动了哪些全局」只需要几十行,能挡住大半这类事故。
|
|
2528
|
+
*
|
|
2529
|
+
* 边界(这是观测,不是隔离):
|
|
2530
|
+
* - 事后告警,不阻止副作用——脚本已经执行过了;
|
|
2531
|
+
* - 并发加载时窗口会重叠,归因以「最后完成的一批」结算,可能不准;
|
|
2532
|
+
* - 只比较可枚举自有属性的**引用**,`window.foo.bar = 1` 这类深层改动检测不到。
|
|
2533
|
+
*/
|
|
2534
|
+
|
|
2535
|
+
/** 默认盯防的 key:出现即说明宿主的关键设施被动过 */
|
|
2536
|
+
var DEFAULT_WATCH = ['$', 'jQuery', 'define', 'require', 'requirejs', 'devfab', '__devfab', '__devfab_requirejs'];
|
|
2537
|
+
var GlobalGuard = /*#__PURE__*/function () {
|
|
2538
|
+
function GlobalGuard(options) {
|
|
2539
|
+
_classCallCheck(this, GlobalGuard);
|
|
2540
|
+
var o = options || {};
|
|
2541
|
+
this.maxPollution = o.maxPollution === undefined ? 3 : Number(o.maxPollution);
|
|
2542
|
+
this.watch = [].concat(o.watch || DEFAULT_WATCH);
|
|
2543
|
+
this.target = o.target || (typeof window !== 'undefined' ? window : null);
|
|
2544
|
+
this.enabled = o.enabled === undefined ? true : !!o.enabled;
|
|
2545
|
+
this._pending = 0;
|
|
2546
|
+
this._before = null;
|
|
2547
|
+
this.lastWarnings = [];
|
|
2548
|
+
}
|
|
2549
|
+
return _createClass(GlobalGuard, [{
|
|
2550
|
+
key: "_snapshot",
|
|
2551
|
+
value: function _snapshot() {
|
|
2552
|
+
var map = new Map();
|
|
2553
|
+
var target = this.target;
|
|
2554
|
+
if (!target) return map;
|
|
2555
|
+
Object.keys(target).forEach(function (key) {
|
|
2556
|
+
map.set(key, target[key]);
|
|
2557
|
+
});
|
|
2558
|
+
return map;
|
|
2559
|
+
}
|
|
2560
|
+
}, {
|
|
2561
|
+
key: "_diff",
|
|
2562
|
+
value: function _diff() {
|
|
2563
|
+
var _this = this;
|
|
2564
|
+
var before = this._before;
|
|
2565
|
+
var after = this._snapshot();
|
|
2566
|
+
var warnings = [];
|
|
2567
|
+
if (!before) return warnings;
|
|
2568
|
+
after.forEach(function (value, key) {
|
|
2569
|
+
var watched = _this.watch.indexOf(key) !== -1;
|
|
2570
|
+
if (!before.has(key)) {
|
|
2571
|
+
warnings.push({
|
|
2572
|
+
type: 'added',
|
|
2573
|
+
key: key,
|
|
2574
|
+
watched: watched
|
|
2575
|
+
});
|
|
2576
|
+
return;
|
|
2577
|
+
}
|
|
2578
|
+
if (before.get(key) !== value) {
|
|
2579
|
+
warnings.push({
|
|
2580
|
+
type: 'overwritten',
|
|
2581
|
+
key: key,
|
|
2582
|
+
watched: watched
|
|
2583
|
+
});
|
|
2584
|
+
}
|
|
2585
|
+
});
|
|
2586
|
+
// 命中盯防名单,或新增数量超过阈值,才认为「值得提醒」。
|
|
2587
|
+
// 1~2 个自有全局是正常写法,全报会把信号淹掉。
|
|
2588
|
+
var watchedCount = warnings.filter(function (item) {
|
|
2589
|
+
return item.watched;
|
|
2590
|
+
}).length;
|
|
2591
|
+
var addedCount = warnings.filter(function (item) {
|
|
2592
|
+
return item.type === 'added';
|
|
2593
|
+
}).length;
|
|
2594
|
+
if (!watchedCount && addedCount <= this.maxPollution) return [];
|
|
2595
|
+
return warnings;
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2598
|
+
/**
|
|
2599
|
+
* 开始观测。返回的 `end()` 幂等,重复调用只有第一次有效,
|
|
2600
|
+
* 这样超时分支和 errback 分支可以都调,不会把计数搞负。
|
|
2601
|
+
*/
|
|
2602
|
+
}, {
|
|
2603
|
+
key: "begin",
|
|
2604
|
+
value: function begin() {
|
|
2605
|
+
var _this2 = this;
|
|
2606
|
+
if (!this.enabled || !this.target) {
|
|
2607
|
+
return {
|
|
2608
|
+
end: function end() {
|
|
2609
|
+
return [];
|
|
2610
|
+
}
|
|
2611
|
+
};
|
|
2612
|
+
}
|
|
2613
|
+
this._pending++;
|
|
2614
|
+
if (this._pending === 1) this._before = this._snapshot();
|
|
2615
|
+
var done = false;
|
|
2616
|
+
return {
|
|
2617
|
+
end: function end() {
|
|
2618
|
+
if (done) return [];
|
|
2619
|
+
done = true;
|
|
2620
|
+
_this2._pending--;
|
|
2621
|
+
// 还有并发批次没结束,交给最后结束的那一批结算
|
|
2622
|
+
if (_this2._pending > 0) return [];
|
|
2623
|
+
var warnings = _this2._diff();
|
|
2624
|
+
_this2._before = null;
|
|
2625
|
+
_this2.lastWarnings = warnings;
|
|
2626
|
+
return warnings;
|
|
2627
|
+
}
|
|
2628
|
+
};
|
|
2629
|
+
}
|
|
2630
|
+
}, {
|
|
2631
|
+
key: "configure",
|
|
2632
|
+
value: function configure(options) {
|
|
2633
|
+
var o = options || {};
|
|
2634
|
+
if (o.enabled !== undefined) this.enabled = !!o.enabled;
|
|
2635
|
+
if (o.maxPollution !== undefined) this.maxPollution = Number(o.maxPollution);
|
|
2636
|
+
if (o.watch !== undefined) this.watch = [].concat(o.watch || []);
|
|
2637
|
+
if (o.target !== undefined) this.target = o.target || null;
|
|
2638
|
+
return this;
|
|
2639
|
+
}
|
|
2640
|
+
}]);
|
|
2641
|
+
}();
|
|
2642
|
+
|
|
2643
|
+
/** 加载超时:RequireJS 自己的 waitSeconds 默认 30s,这个定时器是更早的兜底 */
|
|
2644
|
+
var CODE_TIMEOUT = 504;
|
|
2645
|
+
|
|
2646
|
+
/**
|
|
2647
|
+
* 原生动态 import。
|
|
2648
|
+
*
|
|
2649
|
+
* 不能用字面量 `import(url)` —— rollup 在 cjs / umd 输出里会把它改写成
|
|
2650
|
+
* `require(url)`,产物直接失效。用 Function 构造可以绕开静态分析,
|
|
2651
|
+
* 代价是要求 CSP 允许 unsafe-eval(和无 unsafe-eval 就跑不起来的内嵌
|
|
2652
|
+
* RequireJS 是同一个前提,不额外增加约束)。
|
|
2653
|
+
*/
|
|
2654
|
+
var nativeImport = null;
|
|
2655
|
+
try {
|
|
2656
|
+
// eslint-disable-next-line no-new-func
|
|
2657
|
+
nativeImport = new Function('s', 'return import(s)');
|
|
2658
|
+
} catch (err) {
|
|
2659
|
+
nativeImport = null;
|
|
2660
|
+
}
|
|
2661
|
+
function parseArgs(_path, _files, _callback, params) {
|
|
2662
|
+
var path = _path;
|
|
2663
|
+
var files = _files;
|
|
2664
|
+
var callback = _callback;
|
|
2665
|
+
// 单参形式:(files, callback) 或 (files)。判据是「第一个是数组、第二个不是数组」,
|
|
2666
|
+
// 放宽到非函数是因为 loadModules([url]) 这种不带回调的调用很常见。
|
|
2667
|
+
if (Array.isArray(_path) && !Array.isArray(_files)) {
|
|
2668
|
+
path = params === null || params === void 0 ? void 0 : params.path;
|
|
2669
|
+
files = _path;
|
|
2670
|
+
callback = typeof _files === 'function' ? _files : _callback;
|
|
2671
|
+
}
|
|
2672
|
+
files = Array.isArray(files) ? files : [];
|
|
2673
|
+
var filesStr = files.join(',');
|
|
2674
|
+
var result = {
|
|
2675
|
+
code: 0,
|
|
2676
|
+
message: '',
|
|
2677
|
+
data: [],
|
|
2678
|
+
warnings: []
|
|
2679
|
+
};
|
|
2680
|
+
if (params.type === 'require' && typeof params.require !== 'function' || params.type === 'define' && typeof params.define !== 'function' //
|
|
2681
|
+
) {
|
|
2682
|
+
result.code = 404;
|
|
2683
|
+
result.message = "requirejs is undefined, the fiels: ".concat(filesStr);
|
|
2684
|
+
}
|
|
2685
|
+
return {
|
|
2686
|
+
path: path,
|
|
2687
|
+
files: files,
|
|
2688
|
+
callback: callback,
|
|
2689
|
+
filesStr: filesStr,
|
|
2690
|
+
result: result
|
|
2691
|
+
};
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
/**
|
|
2695
|
+
* 把「域前缀 + 文件列表」拼成模块 id,必须与 requirejs.js 适配层的拼法保持一致,
|
|
2696
|
+
* 否则策略层的清单查找会全部落空(而且看起来像「清单没打包进去」)。
|
|
2697
|
+
*/
|
|
2698
|
+
function toModuleIds(path, files) {
|
|
2699
|
+
var domain = '';
|
|
2700
|
+
if (Array.isArray(path)) {
|
|
2701
|
+
domain = path.filter(Boolean).join('/');
|
|
2702
|
+
} else if (typeof path === 'string') {
|
|
2703
|
+
domain = path.replace(/\/+$/, '');
|
|
2704
|
+
}
|
|
2705
|
+
return files.map(function (file) {
|
|
2706
|
+
var name = String(file).replace(/^\/+/, '');
|
|
2707
|
+
return domain ? "".concat(domain, "/").concat(name) : name;
|
|
2708
|
+
});
|
|
2709
|
+
}
|
|
2710
|
+
function toNumber(value, fallback) {
|
|
2711
|
+
var num = Number(value);
|
|
2712
|
+
return Number.isFinite(num) ? num : fallback;
|
|
2713
|
+
}
|
|
2714
|
+
var DEFAULT_OPTIONS = {
|
|
2715
|
+
version: '',
|
|
2716
|
+
timeout: 15000,
|
|
2717
|
+
retry: 0,
|
|
2718
|
+
strict: false,
|
|
2719
|
+
baseUrl: ''
|
|
2720
|
+
};
|
|
2721
|
+
var BaseFileRequire = /*#__PURE__*/function () {
|
|
2722
|
+
/**
|
|
2723
|
+
* args 同时承担两件事,分区明确:
|
|
2724
|
+
* - 底层加载器覆盖:`define` / `require` / `undef` / `requireConfig` / `importer`
|
|
2725
|
+
* - 加载策略:`version` / `timeout` / `retry` / `strict` / `baseUrl` / `manifest`
|
|
2726
|
+
* / `origins` / `lockVersion` / `verifyHash` / `pollution` / `watch` / `maxPollution`
|
|
2727
|
+
* 其余一律走 `configure(options)` 在运行时改。
|
|
2728
|
+
*/
|
|
2729
|
+
function BaseFileRequire(args) {
|
|
2730
|
+
var _o$__debug, _window$__devfab_requ, _window$__devfab_requ2, _this$__require;
|
|
2731
|
+
_classCallCheck(this, BaseFileRequire);
|
|
2732
|
+
var o = args || {};
|
|
2733
|
+
this.__debug = (_o$__debug = o.__debug) !== null && _o$__debug !== void 0 ? _o$__debug : false;
|
|
2734
|
+
this.__rootPath = undefined;
|
|
2735
|
+
this.__define = o.define || ((_window$__devfab_requ = window.__devfab_requirejs) === null || _window$__devfab_requ === void 0 ? void 0 : _window$__devfab_requ.define);
|
|
2736
|
+
this.__require = o.require || ((_window$__devfab_requ2 = window.__devfab_requirejs) === null || _window$__devfab_requ2 === void 0 ? void 0 : _window$__devfab_requ2.require);
|
|
2737
|
+
this.__undef = o.undef || (typeof ((_this$__require = this.__require) === null || _this$__require === void 0 ? void 0 : _this$__require.undef) === 'function' ? this.__require.undef : null);
|
|
2738
|
+
this.__requireConfig = o.requireConfig || this._pickRequireConfig(this.__require);
|
|
2739
|
+
this.__import = o.importer || null;
|
|
2740
|
+
this._setTimer = o.setTimeout || function (fn, ms) {
|
|
2741
|
+
return setTimeout(fn, ms);
|
|
2742
|
+
};
|
|
2743
|
+
this._clearTimer = o.clearTimeout || function (id) {
|
|
2744
|
+
return clearTimeout(id);
|
|
2745
|
+
};
|
|
2746
|
+
this.options = {
|
|
2747
|
+
version: o.version ? String(o.version) : DEFAULT_OPTIONS.version,
|
|
2748
|
+
timeout: o.timeout === undefined ? DEFAULT_OPTIONS.timeout : Math.max(0, toNumber(o.timeout, 0)),
|
|
2749
|
+
retry: o.retry === undefined ? DEFAULT_OPTIONS.retry : Math.max(0, toNumber(o.retry, 0)),
|
|
2750
|
+
strict: !!o.strict,
|
|
2751
|
+
baseUrl: o.baseUrl || DEFAULT_OPTIONS.baseUrl
|
|
2752
|
+
};
|
|
2753
|
+
this.policy = new LoadPolicy(o);
|
|
2754
|
+
this.guard = new GlobalGuard(this._guardOptions(o));
|
|
2755
|
+
if (this.options.version) this._applyUrlArgs();
|
|
2756
|
+
}
|
|
2757
|
+
|
|
2758
|
+
/**
|
|
2759
|
+
* urlArgs 只能配在真正在用的那个 require 上。
|
|
2760
|
+
* 传了自定义加载器(stub / 多 context)就取它的 config,否则取内嵌 RequireJS 的。
|
|
2761
|
+
*/
|
|
2762
|
+
return _createClass(BaseFileRequire, [{
|
|
2763
|
+
key: "_pickRequireConfig",
|
|
2764
|
+
value: function _pickRequireConfig(loader) {
|
|
2765
|
+
var _window$__devfab_requ3;
|
|
2766
|
+
var req = loader && typeof loader.config === 'function' ? loader : (_window$__devfab_requ3 = window.__devfab_requirejs) === null || _window$__devfab_requ3 === void 0 ? void 0 : _window$__devfab_requ3.require;
|
|
2767
|
+
return req && typeof req.config === 'function' ? req.config.bind(req) : null;
|
|
2768
|
+
}
|
|
2769
|
+
}, {
|
|
2770
|
+
key: "_guardOptions",
|
|
2771
|
+
value: function _guardOptions(o) {
|
|
2772
|
+
if (o.pollution === false) {
|
|
2773
|
+
return {
|
|
2774
|
+
enabled: false,
|
|
2775
|
+
target: o.target
|
|
2776
|
+
};
|
|
2777
|
+
}
|
|
2778
|
+
if (o.pollution && _typeof(o.pollution) === 'object') {
|
|
2779
|
+
return Object.assign({
|
|
2780
|
+
target: o.target
|
|
2781
|
+
}, o.pollution);
|
|
2782
|
+
}
|
|
2783
|
+
return {
|
|
2784
|
+
target: o.target,
|
|
2785
|
+
watch: o.watch,
|
|
2786
|
+
maxPollution: o.maxPollution,
|
|
2787
|
+
enabled: o.pollution === undefined ? true : !!o.pollution
|
|
2788
|
+
};
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2791
|
+
/* ------------------------------ 配置 ------------------------------ */
|
|
2792
|
+
|
|
2793
|
+
/** 运行时增量配置(宿主切版本、换清单、改重试次数都走这里)
|
|
2794
|
+
* 加载策略:版本、超时、重试、清单、白名单、全局污染检测
|
|
2795
|
+
*/
|
|
2796
|
+
}, {
|
|
2797
|
+
key: "configure",
|
|
2798
|
+
value: function configure(options) {
|
|
2799
|
+
var o = options || {};
|
|
2800
|
+
if (o.debug !== undefined) this.__debug = !!o.debug;
|
|
2801
|
+
if (o.version !== undefined) this.setVersion(o.version);
|
|
2802
|
+
if (o.timeout !== undefined) this.options.timeout = Math.max(0, toNumber(o.timeout, this.options.timeout));
|
|
2803
|
+
if (o.retry !== undefined) this.options.retry = Math.max(0, toNumber(o.retry, this.options.retry));
|
|
2804
|
+
if (o.strict !== undefined) this.options.strict = !!o.strict;
|
|
2805
|
+
if (o.baseUrl !== undefined) this.options.baseUrl = o.baseUrl || '';
|
|
2806
|
+
if (o.manifest !== undefined || o.origins !== undefined || o.lockVersion !== undefined || o.verifyHash !== undefined || o.fetch !== undefined) {
|
|
2807
|
+
this.policy.configure(o);
|
|
2808
|
+
}
|
|
2809
|
+
if (o.pollution !== undefined) this.guard.configure(this._guardOptions(o));else if (o.watch !== undefined || o.maxPollution !== undefined || o.target !== undefined) {
|
|
2810
|
+
this.guard.configure(o);
|
|
2811
|
+
}
|
|
2812
|
+
return this;
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2815
|
+
/**
|
|
2816
|
+
* 设置二开包版本,拼成 `?v=` 交给 RequireJS 的 urlArgs。
|
|
2817
|
+
*
|
|
2818
|
+
* 注意这是 RequireJS **context 级**配置,一个页面内以最后一次设置为准 ——
|
|
2819
|
+
* 这与实际情况相符:整个二开包本来就应该同一个版本,分模块各自版本只会让缓存失效
|
|
2820
|
+
* 变成玄学。多实例需要不同版本时请分 iframe。
|
|
2821
|
+
*/
|
|
2822
|
+
}, {
|
|
2823
|
+
key: "setVersion",
|
|
2824
|
+
value: function setVersion(version) {
|
|
2825
|
+
this.options.version = version ? String(version) : '';
|
|
2826
|
+
this._applyUrlArgs();
|
|
2827
|
+
return this;
|
|
2828
|
+
}
|
|
2829
|
+
}, {
|
|
2830
|
+
key: "_applyUrlArgs",
|
|
2831
|
+
value: function _applyUrlArgs() {
|
|
2832
|
+
if (typeof this.__requireConfig !== 'function') {
|
|
2833
|
+
return false;
|
|
2834
|
+
}
|
|
2835
|
+
try {
|
|
2836
|
+
this.__requireConfig({
|
|
2837
|
+
urlArgs: this.options.version ? "v=".concat(encodeURIComponent(this.options.version)) : ''
|
|
2838
|
+
});
|
|
2839
|
+
return true;
|
|
2840
|
+
} catch (err) {
|
|
2841
|
+
return false;
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
}, {
|
|
2845
|
+
key: "getVersion",
|
|
2846
|
+
value: function getVersion() {
|
|
2847
|
+
return this.options.version;
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2850
|
+
/**
|
|
2851
|
+
* 导出本实例的配置快照,供 `create()` 派生新实例时继承。
|
|
2852
|
+
*
|
|
2853
|
+
* 为什么需要:`create()` 原先是彻底干净的实例,于是宿主在单例上
|
|
2854
|
+
* `configure({ manifest, lockVersion })` 之后,`_utils/models/_extend.js` 里那句
|
|
2855
|
+
* `FileRequire.create({ require }).require(...)` 完全不受约束 —— 扩展脚本主链路上
|
|
2856
|
+
* 登记制与版本锁等于没开。派生时继承配置,这个缺口才闭合。
|
|
2857
|
+
*
|
|
2858
|
+
* 刻意**不包含加载器**(`define` / `require` / `undef` / `requireConfig` / `importer`):
|
|
2859
|
+
* 构造函数会按当前 `window.__devfab_requirejs` 重新取,派生实例拿到的是「此刻真正
|
|
2860
|
+
* 在用的那个加载器」,而不是父实例构造时捕获的旧引用。要指定加载器请显式传,
|
|
2861
|
+
* `create({ require })` 会覆盖。
|
|
2862
|
+
*/
|
|
2863
|
+
}, {
|
|
2864
|
+
key: "_snapshotConfig",
|
|
2865
|
+
value: function _snapshotConfig() {
|
|
2866
|
+
return {
|
|
2867
|
+
__debug: this.__debug,
|
|
2868
|
+
version: this.options.version,
|
|
2869
|
+
timeout: this.options.timeout,
|
|
2870
|
+
retry: this.options.retry,
|
|
2871
|
+
strict: this.options.strict,
|
|
2872
|
+
baseUrl: this.options.baseUrl,
|
|
2873
|
+
manifest: this.policy.manifest,
|
|
2874
|
+
origins: this.policy.origins,
|
|
2875
|
+
lockVersion: this.policy.lockVersion,
|
|
2876
|
+
verifyHash: this.policy.verifyHash,
|
|
2877
|
+
fetch: this.policy.fetch,
|
|
2878
|
+
pollution: this.guard.enabled,
|
|
2879
|
+
watch: this.guard.watch,
|
|
2880
|
+
maxPollution: this.guard.maxPollution,
|
|
2881
|
+
target: this.guard.target
|
|
2882
|
+
};
|
|
2883
|
+
}
|
|
2884
|
+
|
|
2885
|
+
/** 策略 + 兜底配置摘要,宿主启动时打一行日志排查效率最高 */
|
|
2886
|
+
}, {
|
|
2887
|
+
key: "describe",
|
|
2888
|
+
value: function describe() {
|
|
2889
|
+
return Object.assign({}, this.options, {
|
|
2890
|
+
debug: this.__debug,
|
|
2891
|
+
policy: this.policy.describe(),
|
|
2892
|
+
pollutionGuard: this.guard.enabled,
|
|
2893
|
+
canUndef: typeof this.__undef === 'function',
|
|
2894
|
+
canNativeImport: typeof (this.__import || nativeImport) === 'function'
|
|
2895
|
+
});
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
/* --------------------------- AMD 通道 --------------------------- */
|
|
2899
|
+
}, {
|
|
2900
|
+
key: "_define",
|
|
2901
|
+
value: function _define(_path, _files, _callback) {
|
|
2902
|
+
var params = {
|
|
2903
|
+
path: this.__rootPath,
|
|
2904
|
+
define: this.__define,
|
|
2905
|
+
type: 'define'
|
|
2906
|
+
};
|
|
2907
|
+
var _parseArgs = parseArgs(_path, _files, _callback, params),
|
|
2908
|
+
path = _parseArgs.path,
|
|
2909
|
+
files = _parseArgs.files,
|
|
2910
|
+
callback = _parseArgs.callback,
|
|
2911
|
+
result = _parseArgs.result;
|
|
2912
|
+
if (result.code === 404) {
|
|
2913
|
+
callback === null || callback === void 0 || callback(result);
|
|
2914
|
+
return;
|
|
2915
|
+
}
|
|
2916
|
+
this.__define(path, files, callback);
|
|
2917
|
+
}
|
|
2918
|
+
}, {
|
|
2919
|
+
key: "_mergeWarnings",
|
|
2920
|
+
value: function _mergeWarnings(prev, next) {
|
|
2921
|
+
var list = (prev || []).slice();
|
|
2922
|
+
(next || []).forEach(function (item) {
|
|
2923
|
+
var exists = list.some(function (one) {
|
|
2924
|
+
return one.type === item.type && one.key === item.key;
|
|
2925
|
+
});
|
|
2926
|
+
if (!exists) list.push(item);
|
|
2927
|
+
});
|
|
2928
|
+
return list;
|
|
2929
|
+
}
|
|
2930
|
+
}, {
|
|
2931
|
+
key: "_undefModules",
|
|
2932
|
+
value: function _undefModules(moduleIds) {
|
|
2933
|
+
var _this = this;
|
|
2934
|
+
if (typeof this.__undef !== 'function') return;
|
|
2935
|
+
moduleIds.forEach(function (id) {
|
|
2936
|
+
try {
|
|
2937
|
+
_this.__undef(id);
|
|
2938
|
+
} catch (err) {
|
|
2939
|
+
// undef 只对曾经顶层 require 过的模块有效;抛错说明它还没进注册表,忽略即可
|
|
2940
|
+
}
|
|
2941
|
+
});
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2944
|
+
/**
|
|
2945
|
+
* 统一加载入口:策略校验 -> 观测 -> 计时 / 重试 -> 结算。
|
|
2946
|
+
* 默认配置(version 空、retry 0、timeout 15s)下的行为与原来一致,
|
|
2947
|
+
* 只是多了一个「更早失败」的兜底和 warnings 字段。
|
|
2948
|
+
*/
|
|
2949
|
+
}, {
|
|
2950
|
+
key: "_load",
|
|
2951
|
+
value: function _load(_path, _files, _callback) {
|
|
2952
|
+
var _this2 = this;
|
|
2953
|
+
var config = this.options;
|
|
2954
|
+
var params = {
|
|
2955
|
+
path: this.__rootPath,
|
|
2956
|
+
require: this.__require,
|
|
2957
|
+
type: 'require'
|
|
2958
|
+
};
|
|
2959
|
+
var _parseArgs2 = parseArgs(_path, _files, _callback, params),
|
|
2960
|
+
path = _parseArgs2.path,
|
|
2961
|
+
files = _parseArgs2.files,
|
|
2962
|
+
callback = _parseArgs2.callback,
|
|
2963
|
+
result = _parseArgs2.result,
|
|
2964
|
+
filesStr = _parseArgs2.filesStr;
|
|
2965
|
+
if (result.code === 404) {
|
|
2966
|
+
callback === null || callback === void 0 || callback(result);
|
|
2967
|
+
return;
|
|
2968
|
+
}
|
|
2969
|
+
var moduleIds = toModuleIds(path, files);
|
|
2970
|
+
var denied = this.policy.checkModules(moduleIds);
|
|
2971
|
+
if (denied) {
|
|
2972
|
+
result.code = denied.code;
|
|
2973
|
+
result.message = denied.message;
|
|
2974
|
+
callback === null || callback === void 0 || callback(result);
|
|
2975
|
+
return;
|
|
2976
|
+
}
|
|
2977
|
+
var settled = false;
|
|
2978
|
+
var attempt = 0;
|
|
2979
|
+
var timer = null;
|
|
2980
|
+
var scoop = null;
|
|
2981
|
+
var closeScoop = function closeScoop() {
|
|
2982
|
+
if (!scoop) return;
|
|
2983
|
+
result.warnings = _this2._mergeWarnings(result.warnings, scoop.end());
|
|
2984
|
+
scoop = null;
|
|
2985
|
+
};
|
|
2986
|
+
var finish = function finish() {
|
|
2987
|
+
if (settled) return;
|
|
2988
|
+
settled = true;
|
|
2989
|
+
if (timer !== null) {
|
|
2990
|
+
_this2._clearTimer(timer);
|
|
2991
|
+
timer = null;
|
|
2992
|
+
}
|
|
2993
|
+
closeScoop();
|
|
2994
|
+
if (config.strict && result.warnings.length) {
|
|
2995
|
+
result.code = 500;
|
|
2996
|
+
result.message = "Global pollution detection failed\uFF1A".concat(result.warnings.map(function (item) {
|
|
2997
|
+
return "".concat(item.type, ":").concat(item.key);
|
|
2998
|
+
}).join(', '));
|
|
2999
|
+
}
|
|
3000
|
+
callback === null || callback === void 0 || callback(result);
|
|
3001
|
+
};
|
|
3002
|
+
var start = function start() {
|
|
3003
|
+
attempt++;
|
|
3004
|
+
scoop = _this2.guard.begin();
|
|
3005
|
+
if (config.timeout > 0) {
|
|
3006
|
+
timer = _this2._setTimer(function () {
|
|
3007
|
+
if (settled) return;
|
|
3008
|
+
var err = new Error("load timeout after ".concat(config.timeout, "ms: ").concat(filesStr));
|
|
3009
|
+
err.__devfabTimeout = true;
|
|
3010
|
+
retryOrFail(err, "files load timeout after ".concat(config.timeout, "ms, the files: ").concat(filesStr));
|
|
3011
|
+
}, config.timeout);
|
|
3012
|
+
}
|
|
3013
|
+
_this2.__require(path, files, function () {
|
|
3014
|
+
for (var _len = arguments.length, contents = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3015
|
+
contents[_key] = arguments[_key];
|
|
3016
|
+
}
|
|
3017
|
+
result.data = contents;
|
|
3018
|
+
finish();
|
|
3019
|
+
}, function (err) {
|
|
3020
|
+
retryOrFail(err);
|
|
3021
|
+
});
|
|
3022
|
+
};
|
|
3023
|
+
var retryOrFail = function retryOrFail(err, message) {
|
|
3024
|
+
if (settled) return;
|
|
3025
|
+
if (timer !== null) {
|
|
3026
|
+
_this2._clearTimer(timer);
|
|
3027
|
+
timer = null;
|
|
3028
|
+
}
|
|
3029
|
+
if (attempt <= config.retry) {
|
|
3030
|
+
closeScoop();
|
|
3031
|
+
// 不 undef 就会复用上一次的失败状态,重试形同虚设
|
|
3032
|
+
_this2._undefModules(moduleIds);
|
|
3033
|
+
start();
|
|
3034
|
+
return;
|
|
3035
|
+
}
|
|
3036
|
+
result.code = err && err.__devfabTimeout ? CODE_TIMEOUT : 500;
|
|
3037
|
+
result.message = message || "files load error, the files: ".concat(filesStr);
|
|
3038
|
+
result.error = err;
|
|
3039
|
+
finish();
|
|
3040
|
+
};
|
|
3041
|
+
start();
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
/**
|
|
3045
|
+
* 带兜底的加载:与 `require` 完全等价,保留这个名字是为了让宿主代码读得懂
|
|
3046
|
+
* 「这一处是走完整策略的」。
|
|
3047
|
+
*/
|
|
3048
|
+
}, {
|
|
3049
|
+
key: "load",
|
|
3050
|
+
value: function load(path, files, callback) {
|
|
3051
|
+
this._load(path, files, callback);
|
|
3052
|
+
}
|
|
3053
|
+
|
|
3054
|
+
/* --------------------------- ESM 通道 --------------------------- */
|
|
3055
|
+
|
|
3056
|
+
/**
|
|
3057
|
+
* 把模块 id 解析成可 import 的地址。相对路径以 `baseUrl`(缺省为
|
|
3058
|
+
* `document.baseURI`)为基准,这样宿主不用自己拼绝对地址。
|
|
3059
|
+
*/
|
|
3060
|
+
}, {
|
|
3061
|
+
key: "resolveUrl",
|
|
3062
|
+
value: function resolveUrl(rel) {
|
|
3063
|
+
var raw = String(rel == null ? '' : rel);
|
|
3064
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || /^\/\//.test(raw)) return raw;
|
|
3065
|
+
var base = this.options.baseUrl || (typeof document !== 'undefined' && document.baseURI ? document.baseURI : '');
|
|
3066
|
+
if (!base) return raw;
|
|
3067
|
+
try {
|
|
3068
|
+
return new URL(raw, base).href;
|
|
3069
|
+
} catch (err) {
|
|
3070
|
+
return raw;
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
}, {
|
|
3074
|
+
key: "_importOne",
|
|
3075
|
+
value: function _importOne(moduleId) {
|
|
3076
|
+
var _this3 = this;
|
|
3077
|
+
var url = this.resolveUrl(moduleId);
|
|
3078
|
+
var originDenied = this.policy.checkOrigin(url);
|
|
3079
|
+
if (originDenied) {
|
|
3080
|
+
return Promise.resolve({
|
|
3081
|
+
ok: false,
|
|
3082
|
+
code: originDenied.code,
|
|
3083
|
+
message: originDenied.message
|
|
3084
|
+
});
|
|
3085
|
+
}
|
|
3086
|
+
var entry = this.policy.entryOf(moduleId);
|
|
3087
|
+
var expected = entry && entry.sha256;
|
|
3088
|
+
var run = function run() {
|
|
3089
|
+
var importer = _this3.__import || nativeImport;
|
|
3090
|
+
if (typeof importer !== 'function') {
|
|
3091
|
+
return Promise.resolve({
|
|
3092
|
+
ok: false,
|
|
3093
|
+
code: 500,
|
|
3094
|
+
message: 'native import() is unavailable(CSP 是否禁用了 unsafe-eval?)'
|
|
3095
|
+
});
|
|
3096
|
+
}
|
|
3097
|
+
return Promise.resolve().then(function () {
|
|
3098
|
+
return importer(url);
|
|
3099
|
+
}).then(function (module) {
|
|
3100
|
+
return {
|
|
3101
|
+
ok: true,
|
|
3102
|
+
module: module
|
|
3103
|
+
};
|
|
3104
|
+
}, function (err) {
|
|
3105
|
+
return {
|
|
3106
|
+
ok: false,
|
|
3107
|
+
code: 500,
|
|
3108
|
+
message: "module load error: ".concat(url),
|
|
3109
|
+
error: err
|
|
3110
|
+
};
|
|
3111
|
+
});
|
|
3112
|
+
};
|
|
3113
|
+
if (!expected) return run();
|
|
3114
|
+
return this.policy.verify(url, expected).then(function (verified) {
|
|
3115
|
+
if (!verified.ok) {
|
|
3116
|
+
return {
|
|
3117
|
+
ok: false,
|
|
3118
|
+
code: CODE_POLICY,
|
|
3119
|
+
message: "".concat(verified.message, "\uFF08").concat(url, "\uFF09")
|
|
3120
|
+
};
|
|
3121
|
+
}
|
|
3122
|
+
return run();
|
|
3123
|
+
});
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
/**
|
|
3127
|
+
* ESM 通道:用原生 `import()` 加载,与 AMD 通道并存而不是替代它。
|
|
3128
|
+
*
|
|
3129
|
+
* 用途:新宿主(Vite / ESM)不必为了加载二开产物把 AMD 拖进来;
|
|
3130
|
+
* 相对地,这条通道不做 AMD 匿名 define 那套匹配,模块必须是标准 ESM。
|
|
3131
|
+
* 返回 Promise,同时兼容 callback 写法。
|
|
3132
|
+
*/
|
|
3133
|
+
}, {
|
|
3134
|
+
key: "loadModules",
|
|
3135
|
+
value: function loadModules(_path, _files, _callback) {
|
|
3136
|
+
var _this4 = this;
|
|
3137
|
+
var params = {
|
|
3138
|
+
path: this.__rootPath,
|
|
3139
|
+
type: 'module'
|
|
3140
|
+
};
|
|
3141
|
+
var _parseArgs3 = parseArgs(_path, _files, _callback, params),
|
|
3142
|
+
path = _parseArgs3.path,
|
|
3143
|
+
files = _parseArgs3.files,
|
|
3144
|
+
callback = _parseArgs3.callback,
|
|
3145
|
+
result = _parseArgs3.result,
|
|
3146
|
+
filesStr = _parseArgs3.filesStr;
|
|
3147
|
+
var moduleIds = toModuleIds(path, files);
|
|
3148
|
+
var settle = function settle(r) {
|
|
3149
|
+
callback === null || callback === void 0 || callback(r);
|
|
3150
|
+
return r;
|
|
3151
|
+
};
|
|
3152
|
+
var denied = this.policy.checkModules(moduleIds);
|
|
3153
|
+
if (denied) {
|
|
3154
|
+
result.code = denied.code;
|
|
3155
|
+
result.message = denied.message;
|
|
3156
|
+
return Promise.resolve(settle(result));
|
|
3157
|
+
}
|
|
3158
|
+
if (!files.length) {
|
|
3159
|
+
return Promise.resolve(settle(result));
|
|
3160
|
+
}
|
|
3161
|
+
var scoop = this.guard.begin();
|
|
3162
|
+
return Promise.all(moduleIds.map(function (id) {
|
|
3163
|
+
return _this4._importOne(id);
|
|
3164
|
+
})).then(function (list) {
|
|
3165
|
+
result.warnings = scoop.end();
|
|
3166
|
+
var failed = list.filter(function (item) {
|
|
3167
|
+
return !item.ok;
|
|
3168
|
+
});
|
|
3169
|
+
if (failed.length) {
|
|
3170
|
+
// 部分成功也不给半份 data:宿主拿半份当完整用比直接失败更糟
|
|
3171
|
+
result.code = failed[0].code || 500;
|
|
3172
|
+
result.message = "".concat(failed.map(function (item) {
|
|
3173
|
+
return item.message;
|
|
3174
|
+
}).join('; '), "\uFF08the files: ").concat(filesStr, "\uFF09");
|
|
3175
|
+
result.error = failed[0].error;
|
|
3176
|
+
} else {
|
|
3177
|
+
result.data = list.map(function (item) {
|
|
3178
|
+
return item.module;
|
|
3179
|
+
});
|
|
3180
|
+
}
|
|
3181
|
+
return settle(result);
|
|
3182
|
+
});
|
|
3183
|
+
}
|
|
3184
|
+
}, {
|
|
3185
|
+
key: "loadModule",
|
|
3186
|
+
value: function loadModule(url, callback) {
|
|
3187
|
+
return this.loadModules([url], callback);
|
|
3188
|
+
}
|
|
3189
|
+
}]);
|
|
3190
|
+
}();
|
|
3191
|
+
var FileRequireClass = /*#__PURE__*/function (_BaseFileRequire) {
|
|
3192
|
+
function FileRequireClass() {
|
|
3193
|
+
_classCallCheck(this, FileRequireClass);
|
|
3194
|
+
return _callSuper(this, FileRequireClass, arguments);
|
|
3195
|
+
}
|
|
3196
|
+
_inherits(FileRequireClass, _BaseFileRequire);
|
|
3197
|
+
return _createClass(FileRequireClass, [{
|
|
3198
|
+
key: "define",
|
|
3199
|
+
value: function define(path, files, callback) {
|
|
3200
|
+
this._define(path, files, callback);
|
|
3201
|
+
}
|
|
3202
|
+
}, {
|
|
3203
|
+
key: "defineScript",
|
|
3204
|
+
value: function defineScript(o) {
|
|
3205
|
+
this.provideScript(o);
|
|
3206
|
+
}
|
|
3207
|
+
}, {
|
|
3208
|
+
key: "provideScript",
|
|
3209
|
+
value: function provideScript(o) {
|
|
3210
|
+
var callback = o;
|
|
3211
|
+
if (typeof o !== 'function') {
|
|
3212
|
+
callback = function callback() {
|
|
3213
|
+
return o;
|
|
3214
|
+
};
|
|
3215
|
+
}
|
|
3216
|
+
this.define([], callback);
|
|
3217
|
+
}
|
|
3218
|
+
}, {
|
|
3219
|
+
key: "require",
|
|
3220
|
+
value: function require(path, files, callback) {
|
|
3221
|
+
this._load(path, files, callback);
|
|
3222
|
+
}
|
|
3223
|
+
}, {
|
|
3224
|
+
key: "injectScript",
|
|
3225
|
+
value: function injectScript(_path, _files, _callback, _error) {
|
|
3226
|
+
var self = this;
|
|
3227
|
+
var path = _path;
|
|
3228
|
+
var files = _files;
|
|
3229
|
+
var callback = _callback;
|
|
3230
|
+
var error = _error;
|
|
3231
|
+
if (Array.isArray(_path) && typeof _files === 'function') {
|
|
3232
|
+
path = undefined;
|
|
3233
|
+
files = _path;
|
|
3234
|
+
callback = _files;
|
|
3235
|
+
error = _callback;
|
|
3236
|
+
}
|
|
3237
|
+
function onCallback(result) {
|
|
3238
|
+
if (result.code == 0 && Array.isArray(result.data)) {
|
|
3239
|
+
for (var i = 0, len = result.data.length; i < len; i++) {
|
|
3240
|
+
var _callback2;
|
|
3241
|
+
var content = result.data[i];
|
|
3242
|
+
(_callback2 = callback) === null || _callback2 === void 0 || _callback2(content, i);
|
|
3243
|
+
}
|
|
3244
|
+
} else {
|
|
3245
|
+
if (typeof error === 'function') {
|
|
3246
|
+
error(result);
|
|
3247
|
+
} else {
|
|
3248
|
+
self.__debug && console.error('[devfab][FileRequire][injectScript] error: ', result);
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
this._load(path, files, onCallback);
|
|
3253
|
+
}
|
|
3254
|
+
}, {
|
|
3255
|
+
key: "requireScript",
|
|
3256
|
+
value: function requireScript(_path, _files, _callback) {
|
|
3257
|
+
this.injectScript(_path, _files, _callback);
|
|
3258
|
+
}
|
|
3259
|
+
}]);
|
|
3260
|
+
}(BaseFileRequire);
|
|
3261
|
+
var FileRequire = new FileRequireClass();
|
|
3262
|
+
FileRequire.create = function (args) {
|
|
3263
|
+
return new FileRequireClass(_objectSpread2(_objectSpread2({}, this._snapshotConfig()), args));
|
|
3264
|
+
};
|
|
3265
|
+
|
|
3266
|
+
window.__devfab = Object.assign({}, window.__devfab);
|
|
3267
|
+
window.__devfab.FileRequire = FileRequire;
|
|
3268
|
+
window.__devfab.filePolicy = {
|
|
3269
|
+
LoadPolicy: LoadPolicy,
|
|
3270
|
+
GlobalGuard: GlobalGuard,
|
|
3271
|
+
CODE_POLICY: CODE_POLICY,
|
|
3272
|
+
CODE_TIMEOUT: CODE_TIMEOUT
|
|
3273
|
+
};
|
|
3274
|
+
|
|
3275
|
+
exports.CODE_POLICY = CODE_POLICY;
|
|
3276
|
+
exports.CODE_TIMEOUT = CODE_TIMEOUT;
|
|
3277
|
+
exports.DEFAULT_WATCH = DEFAULT_WATCH;
|
|
3278
|
+
exports.FileRequire = FileRequire;
|
|
3279
|
+
exports.GlobalGuard = GlobalGuard;
|
|
3280
|
+
exports.LoadPolicy = LoadPolicy;
|
|
3281
|
+
exports["default"] = FileRequire;
|
|
3282
|
+
|
|
3283
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3284
|
+
|
|
3285
|
+
}));
|