devfab 2.0.0 → 2.2.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 +118 -50
- package/dist/common/models.esm.js +2 -2
- package/dist/common/models.js +2 -2
- package/dist/common/require.esm.js +2 -2
- package/dist/common/require.js +2 -2
- package/dist/common/utils.esm.js +2 -2
- package/dist/common/utils.js +2 -2
- package/dist/index.esm.js +3 -3
- package/dist/index.js +3 -3
- package/dist/index.umd.js +3 -3
- package/lib/devfab.js +197 -374
- package/lib/devfab.min.js +3 -3
- package/lib/devfab.require.js +141 -373
- package/lib/devfab.require.min.js +2 -2
- package/package.json +1 -1
package/lib/devfab.require.js
CHANGED
|
@@ -25,14 +25,6 @@
|
|
|
25
25
|
writable: !1
|
|
26
26
|
}), e;
|
|
27
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
28
|
function _getPrototypeOf(t) {
|
|
37
29
|
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
38
30
|
return t.__proto__ || Object.getPrototypeOf(t);
|
|
@@ -58,27 +50,6 @@
|
|
|
58
50
|
return !!t;
|
|
59
51
|
})();
|
|
60
52
|
}
|
|
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
53
|
function _possibleConstructorReturn(t, e) {
|
|
83
54
|
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
|
84
55
|
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
@@ -113,8 +84,6 @@
|
|
|
113
84
|
}, _typeof(o);
|
|
114
85
|
}
|
|
115
86
|
|
|
116
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
117
|
-
|
|
118
87
|
// ======================================================
|
|
119
88
|
/** vim: et:ts=4:sw=4:sts=4
|
|
120
89
|
* @license RequireJS 2.3.2 Copyright jQuery Foundation and other contributors.
|
|
@@ -124,8 +93,7 @@
|
|
|
124
93
|
// problems with requirejs.exec()/transpiler plugins that may not be strict.
|
|
125
94
|
/* jslint regexp: true, nomen: true, sloppy: true */
|
|
126
95
|
/* global window, navigator, document, importScripts, setTimeout, opera */
|
|
127
|
-
var
|
|
128
|
-
window.__devfab_requirejs = __devfab_requirejs;
|
|
96
|
+
var __requirejs = {};
|
|
129
97
|
(function (global, setTimeout) {
|
|
130
98
|
var requirejs, require, define;
|
|
131
99
|
var req;
|
|
@@ -2130,22 +2098,22 @@
|
|
|
2130
2098
|
// eslint-disable-next-line no-eval
|
|
2131
2099
|
return eval(text);
|
|
2132
2100
|
};
|
|
2133
|
-
|
|
2134
|
-
|
|
2101
|
+
__requirejs.require = require;
|
|
2102
|
+
__requirejs.define = define;
|
|
2135
2103
|
// Set up with config info.
|
|
2136
2104
|
req(cfg);
|
|
2137
|
-
})(
|
|
2105
|
+
})(typeof window !== 'undefined' ? window : globalThis, typeof setTimeout === 'undefined' ? undefined : setTimeout)
|
|
2138
2106
|
|
|
2139
2107
|
/* ----------------------------------------------------------------------------
|
|
2140
2108
|
* 以下为本地适配层,不属于 RequireJS 原始文件内容。
|
|
2141
2109
|
* -------------------------------------------------------------------------- */;
|
|
2142
2110
|
(function (global) {
|
|
2143
|
-
if (
|
|
2111
|
+
if (__requirejs.__requirejsAdapterApplied) {
|
|
2144
2112
|
return;
|
|
2145
2113
|
}
|
|
2146
|
-
|
|
2147
|
-
var rawRequire =
|
|
2148
|
-
var rawDefine =
|
|
2114
|
+
__requirejs.__requirejsAdapterApplied = true;
|
|
2115
|
+
var rawRequire = __requirejs.require;
|
|
2116
|
+
var rawDefine = __requirejs.define;
|
|
2149
2117
|
var require = function require(_domain, _deps, _callback, _errback) {
|
|
2150
2118
|
var domain = _domain;
|
|
2151
2119
|
var deps = _deps;
|
|
@@ -2207,10 +2175,15 @@
|
|
|
2207
2175
|
require[prop] = rawRequire[prop];
|
|
2208
2176
|
}
|
|
2209
2177
|
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2178
|
+
|
|
2179
|
+
// 标记本身是为了让人能**验证**适配层究竟有没有生效(测试与现场排查都用它),
|
|
2180
|
+
// 不然「域前缀到底拼没拼」只能靠猜。
|
|
2181
|
+
require.__devfabAdapterApplied = true;
|
|
2182
|
+
define.__devfabAdapterApplied = true;
|
|
2183
|
+
__requirejs._require = rawRequire;
|
|
2184
|
+
__requirejs._define = rawDefine;
|
|
2185
|
+
__requirejs.require = require;
|
|
2186
|
+
__requirejs.define = define;
|
|
2214
2187
|
})();
|
|
2215
2188
|
|
|
2216
2189
|
/**
|
|
@@ -2519,127 +2492,6 @@
|
|
|
2519
2492
|
}]);
|
|
2520
2493
|
}();
|
|
2521
2494
|
|
|
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
2495
|
/** 加载超时:RequireJS 自己的 waitSeconds 默认 30s,这个定时器是更早的兜底 */
|
|
2644
2496
|
var CODE_TIMEOUT = 504;
|
|
2645
2497
|
|
|
@@ -2662,10 +2514,8 @@
|
|
|
2662
2514
|
var path = _path;
|
|
2663
2515
|
var files = _files;
|
|
2664
2516
|
var callback = _callback;
|
|
2665
|
-
// 单参形式:(files, callback) 或 (files)。判据是「第一个是数组、第二个不是数组」,
|
|
2666
|
-
// 放宽到非函数是因为 loadModules([url]) 这种不带回调的调用很常见。
|
|
2667
2517
|
if (Array.isArray(_path) && !Array.isArray(_files)) {
|
|
2668
|
-
path =
|
|
2518
|
+
path = undefined;
|
|
2669
2519
|
files = _path;
|
|
2670
2520
|
callback = typeof _files === 'function' ? _files : _callback;
|
|
2671
2521
|
}
|
|
@@ -2674,8 +2524,7 @@
|
|
|
2674
2524
|
var result = {
|
|
2675
2525
|
code: 0,
|
|
2676
2526
|
message: '',
|
|
2677
|
-
data: []
|
|
2678
|
-
warnings: []
|
|
2527
|
+
data: []
|
|
2679
2528
|
};
|
|
2680
2529
|
if (params.type === 'require' && typeof params.require !== 'function' || params.type === 'define' && typeof params.define !== 'function' //
|
|
2681
2530
|
) {
|
|
@@ -2715,99 +2564,84 @@
|
|
|
2715
2564
|
version: '',
|
|
2716
2565
|
timeout: 15000,
|
|
2717
2566
|
retry: 0,
|
|
2718
|
-
strict: false,
|
|
2719
2567
|
baseUrl: ''
|
|
2720
2568
|
};
|
|
2721
2569
|
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
2570
|
function BaseFileRequire(args) {
|
|
2730
|
-
var _o$__debug, _window$__devfab_requ, _window$__devfab_requ2, _this$__require;
|
|
2731
2571
|
_classCallCheck(this, BaseFileRequire);
|
|
2732
|
-
|
|
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();
|
|
2572
|
+
this.__init(args);
|
|
2756
2573
|
}
|
|
2757
|
-
|
|
2758
|
-
/**
|
|
2759
|
-
* urlArgs 只能配在真正在用的那个 require 上。
|
|
2760
|
-
* 传了自定义加载器(stub / 多 context)就取它的 config,否则取内嵌 RequireJS 的。
|
|
2761
|
-
*/
|
|
2762
2574
|
return _createClass(BaseFileRequire, [{
|
|
2763
|
-
key: "
|
|
2764
|
-
value: function
|
|
2765
|
-
var
|
|
2766
|
-
|
|
2767
|
-
|
|
2575
|
+
key: "__init",
|
|
2576
|
+
value: function __init(args) {
|
|
2577
|
+
var o = args || {};
|
|
2578
|
+
if (o.debug !== undefined) this.debug = !!o.debug;
|
|
2579
|
+
var require = __requirejs.require;
|
|
2580
|
+
this.__data = {
|
|
2581
|
+
/* --- 加载器句柄与通道:AMD 通道只走内嵌 RequireJS --- */
|
|
2582
|
+
define: __requirejs.define,
|
|
2583
|
+
require: require,
|
|
2584
|
+
undef: typeof (require === null || require === void 0 ? void 0 : require.undef) === 'function' ? require.undef : null,
|
|
2585
|
+
requireConfig: this._pickRequireConfig(require),
|
|
2586
|
+
importImpl: o.importer || null,
|
|
2587
|
+
setTimer: o.setTimeout || function (fn, ms) {
|
|
2588
|
+
return setTimeout(fn, ms);
|
|
2589
|
+
},
|
|
2590
|
+
clearTimer: o.clearTimeout || function (id) {
|
|
2591
|
+
return clearTimeout(id);
|
|
2592
|
+
},
|
|
2593
|
+
/* --- 配置与策略 --- */
|
|
2594
|
+
options: {
|
|
2595
|
+
version: o.version ? String(o.version) : DEFAULT_OPTIONS.version,
|
|
2596
|
+
timeout: o.timeout === undefined ? DEFAULT_OPTIONS.timeout : Math.max(0, toNumber(o.timeout, 0)),
|
|
2597
|
+
retry: o.retry === undefined ? DEFAULT_OPTIONS.retry : Math.max(0, toNumber(o.retry, 0)),
|
|
2598
|
+
baseUrl: o.baseUrl || DEFAULT_OPTIONS.baseUrl
|
|
2599
|
+
},
|
|
2600
|
+
policy: new LoadPolicy(o)
|
|
2601
|
+
};
|
|
2602
|
+
if (this.__data.options.version) this._applyUrlArgs();
|
|
2768
2603
|
}
|
|
2769
2604
|
}, {
|
|
2770
|
-
key: "
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
}
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2605
|
+
key: "debug",
|
|
2606
|
+
get: function get() {
|
|
2607
|
+
var ns = typeof window !== 'undefined' ? window.__devfab : null;
|
|
2608
|
+
return !!(ns && ns.debug);
|
|
2609
|
+
},
|
|
2610
|
+
set: function set(value) {
|
|
2611
|
+
if (typeof window === 'undefined') return;
|
|
2612
|
+
window.__devfab = window.__devfab || {};
|
|
2613
|
+
window.__devfab.debug = !!value;
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
/**
|
|
2617
|
+
* urlArgs 只能配在真正在用的那个 require 上。AMD 通道固定用内嵌 RequireJS,
|
|
2618
|
+
* 所以这里只从传入的加载器上取 config,不再回落到任何全局。
|
|
2619
|
+
*/
|
|
2620
|
+
}, {
|
|
2621
|
+
key: "_pickRequireConfig",
|
|
2622
|
+
value: function _pickRequireConfig(loader) {
|
|
2623
|
+
return loader && typeof loader.config === 'function' ? loader.config.bind(loader) : null;
|
|
2789
2624
|
}
|
|
2790
2625
|
|
|
2791
2626
|
/* ------------------------------ 配置 ------------------------------ */
|
|
2792
2627
|
|
|
2793
2628
|
/** 运行时增量配置(宿主切版本、换清单、改重试次数都走这里)
|
|
2794
|
-
*
|
|
2629
|
+
* 加载策略:版本、超时、重试、清单、白名单
|
|
2795
2630
|
*/
|
|
2796
2631
|
}, {
|
|
2797
2632
|
key: "configure",
|
|
2798
2633
|
value: function configure(options) {
|
|
2799
2634
|
var o = options || {};
|
|
2800
|
-
|
|
2635
|
+
var _this$__data = this.__data,
|
|
2636
|
+
config = _this$__data.options,
|
|
2637
|
+
policy = _this$__data.policy;
|
|
2638
|
+
if (o.debug !== undefined) this.debug = !!o.debug;
|
|
2801
2639
|
if (o.version !== undefined) this.setVersion(o.version);
|
|
2802
|
-
if (o.timeout !== undefined)
|
|
2803
|
-
if (o.retry !== undefined)
|
|
2804
|
-
if (o.
|
|
2805
|
-
if (o.baseUrl !== undefined) this.options.baseUrl = o.baseUrl || '';
|
|
2640
|
+
if (o.timeout !== undefined) config.timeout = Math.max(0, toNumber(o.timeout, config.timeout));
|
|
2641
|
+
if (o.retry !== undefined) config.retry = Math.max(0, toNumber(o.retry, config.retry));
|
|
2642
|
+
if (o.baseUrl !== undefined) config.baseUrl = o.baseUrl || '';
|
|
2806
2643
|
if (o.manifest !== undefined || o.origins !== undefined || o.lockVersion !== undefined || o.verifyHash !== undefined || o.fetch !== undefined) {
|
|
2807
|
-
|
|
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);
|
|
2644
|
+
policy.configure(o);
|
|
2811
2645
|
}
|
|
2812
2646
|
return this;
|
|
2813
2647
|
}
|
|
@@ -2822,19 +2656,22 @@
|
|
|
2822
2656
|
}, {
|
|
2823
2657
|
key: "setVersion",
|
|
2824
2658
|
value: function setVersion(version) {
|
|
2825
|
-
this.options.version = version ? String(version) : '';
|
|
2659
|
+
this.__data.options.version = version ? String(version) : '';
|
|
2826
2660
|
this._applyUrlArgs();
|
|
2827
2661
|
return this;
|
|
2828
2662
|
}
|
|
2829
2663
|
}, {
|
|
2830
2664
|
key: "_applyUrlArgs",
|
|
2831
2665
|
value: function _applyUrlArgs() {
|
|
2832
|
-
|
|
2666
|
+
var _this$__data2 = this.__data,
|
|
2667
|
+
requireConfig = _this$__data2.requireConfig,
|
|
2668
|
+
options = _this$__data2.options;
|
|
2669
|
+
if (typeof requireConfig !== 'function') {
|
|
2833
2670
|
return false;
|
|
2834
2671
|
}
|
|
2835
2672
|
try {
|
|
2836
|
-
|
|
2837
|
-
urlArgs:
|
|
2673
|
+
requireConfig({
|
|
2674
|
+
urlArgs: options.version ? "v=".concat(encodeURIComponent(options.version)) : ''
|
|
2838
2675
|
});
|
|
2839
2676
|
return true;
|
|
2840
2677
|
} catch (err) {
|
|
@@ -2844,54 +2681,23 @@
|
|
|
2844
2681
|
}, {
|
|
2845
2682
|
key: "getVersion",
|
|
2846
2683
|
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
|
-
};
|
|
2684
|
+
return this.__data.options.version;
|
|
2883
2685
|
}
|
|
2884
2686
|
|
|
2885
2687
|
/** 策略 + 兜底配置摘要,宿主启动时打一行日志排查效率最高 */
|
|
2886
2688
|
}, {
|
|
2887
2689
|
key: "describe",
|
|
2888
2690
|
value: function describe() {
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
policy
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2691
|
+
var _this$__data3 = this.__data,
|
|
2692
|
+
options = _this$__data3.options,
|
|
2693
|
+
policy = _this$__data3.policy,
|
|
2694
|
+
undef = _this$__data3.undef,
|
|
2695
|
+
importImpl = _this$__data3.importImpl;
|
|
2696
|
+
return Object.assign({}, options, {
|
|
2697
|
+
debug: this.debug,
|
|
2698
|
+
policy: policy.describe(),
|
|
2699
|
+
canUndef: typeof undef === 'function',
|
|
2700
|
+
canNativeImport: typeof (importImpl || nativeImport) === 'function'
|
|
2895
2701
|
});
|
|
2896
2702
|
}
|
|
2897
2703
|
|
|
@@ -2900,8 +2706,7 @@
|
|
|
2900
2706
|
key: "_define",
|
|
2901
2707
|
value: function _define(_path, _files, _callback) {
|
|
2902
2708
|
var params = {
|
|
2903
|
-
|
|
2904
|
-
define: this.__define,
|
|
2709
|
+
define: this.__data.define,
|
|
2905
2710
|
type: 'define'
|
|
2906
2711
|
};
|
|
2907
2712
|
var _parseArgs = parseArgs(_path, _files, _callback, params),
|
|
@@ -2913,28 +2718,16 @@
|
|
|
2913
2718
|
callback === null || callback === void 0 || callback(result);
|
|
2914
2719
|
return;
|
|
2915
2720
|
}
|
|
2916
|
-
this.
|
|
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;
|
|
2721
|
+
this.__data.define(path, files, callback);
|
|
2929
2722
|
}
|
|
2930
2723
|
}, {
|
|
2931
2724
|
key: "_undefModules",
|
|
2932
2725
|
value: function _undefModules(moduleIds) {
|
|
2933
|
-
var
|
|
2934
|
-
if (typeof
|
|
2726
|
+
var undef = this.__data.undef;
|
|
2727
|
+
if (typeof undef !== 'function') return;
|
|
2935
2728
|
moduleIds.forEach(function (id) {
|
|
2936
2729
|
try {
|
|
2937
|
-
|
|
2730
|
+
undef(id);
|
|
2938
2731
|
} catch (err) {
|
|
2939
2732
|
// undef 只对曾经顶层 require 过的模块有效;抛错说明它还没进注册表,忽略即可
|
|
2940
2733
|
}
|
|
@@ -2942,18 +2735,22 @@
|
|
|
2942
2735
|
}
|
|
2943
2736
|
|
|
2944
2737
|
/**
|
|
2945
|
-
* 统一加载入口:策略校验 ->
|
|
2738
|
+
* 统一加载入口:策略校验 -> 计时 / 重试 -> 结算。
|
|
2946
2739
|
* 默认配置(version 空、retry 0、timeout 15s)下的行为与原来一致,
|
|
2947
|
-
*
|
|
2740
|
+
* 只是多了一个「更早失败」的兜底。
|
|
2948
2741
|
*/
|
|
2949
2742
|
}, {
|
|
2950
2743
|
key: "_load",
|
|
2951
2744
|
value: function _load(_path, _files, _callback) {
|
|
2952
|
-
var
|
|
2953
|
-
var
|
|
2745
|
+
var _this = this;
|
|
2746
|
+
var _this$__data4 = this.__data,
|
|
2747
|
+
config = _this$__data4.options,
|
|
2748
|
+
policy = _this$__data4.policy,
|
|
2749
|
+
require = _this$__data4.require,
|
|
2750
|
+
setTimer = _this$__data4.setTimer,
|
|
2751
|
+
clearTimer = _this$__data4.clearTimer;
|
|
2954
2752
|
var params = {
|
|
2955
|
-
|
|
2956
|
-
require: this.__require,
|
|
2753
|
+
require: require,
|
|
2957
2754
|
type: 'require'
|
|
2958
2755
|
};
|
|
2959
2756
|
var _parseArgs2 = parseArgs(_path, _files, _callback, params),
|
|
@@ -2967,7 +2764,7 @@
|
|
|
2967
2764
|
return;
|
|
2968
2765
|
}
|
|
2969
2766
|
var moduleIds = toModuleIds(path, files);
|
|
2970
|
-
var denied =
|
|
2767
|
+
var denied = policy.checkModules(moduleIds);
|
|
2971
2768
|
if (denied) {
|
|
2972
2769
|
result.code = denied.code;
|
|
2973
2770
|
result.message = denied.message;
|
|
@@ -2977,40 +2774,26 @@
|
|
|
2977
2774
|
var settled = false;
|
|
2978
2775
|
var attempt = 0;
|
|
2979
2776
|
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
2777
|
var finish = function finish() {
|
|
2987
2778
|
if (settled) return;
|
|
2988
2779
|
settled = true;
|
|
2989
2780
|
if (timer !== null) {
|
|
2990
|
-
|
|
2781
|
+
clearTimer(timer);
|
|
2991
2782
|
timer = null;
|
|
2992
2783
|
}
|
|
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
2784
|
callback === null || callback === void 0 || callback(result);
|
|
3001
2785
|
};
|
|
3002
2786
|
var start = function start() {
|
|
3003
2787
|
attempt++;
|
|
3004
|
-
scoop = _this2.guard.begin();
|
|
3005
2788
|
if (config.timeout > 0) {
|
|
3006
|
-
timer =
|
|
2789
|
+
timer = setTimer(function () {
|
|
3007
2790
|
if (settled) return;
|
|
3008
2791
|
var err = new Error("load timeout after ".concat(config.timeout, "ms: ").concat(filesStr));
|
|
3009
2792
|
err.__devfabTimeout = true;
|
|
3010
2793
|
retryOrFail(err, "files load timeout after ".concat(config.timeout, "ms, the files: ").concat(filesStr));
|
|
3011
2794
|
}, config.timeout);
|
|
3012
2795
|
}
|
|
3013
|
-
|
|
2796
|
+
require(path, files, function () {
|
|
3014
2797
|
for (var _len = arguments.length, contents = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3015
2798
|
contents[_key] = arguments[_key];
|
|
3016
2799
|
}
|
|
@@ -3023,13 +2806,12 @@
|
|
|
3023
2806
|
var retryOrFail = function retryOrFail(err, message) {
|
|
3024
2807
|
if (settled) return;
|
|
3025
2808
|
if (timer !== null) {
|
|
3026
|
-
|
|
2809
|
+
clearTimer(timer);
|
|
3027
2810
|
timer = null;
|
|
3028
2811
|
}
|
|
3029
2812
|
if (attempt <= config.retry) {
|
|
3030
|
-
closeScoop();
|
|
3031
2813
|
// 不 undef 就会复用上一次的失败状态,重试形同虚设
|
|
3032
|
-
|
|
2814
|
+
_this._undefModules(moduleIds);
|
|
3033
2815
|
start();
|
|
3034
2816
|
return;
|
|
3035
2817
|
}
|
|
@@ -3062,7 +2844,8 @@
|
|
|
3062
2844
|
value: function resolveUrl(rel) {
|
|
3063
2845
|
var raw = String(rel == null ? '' : rel);
|
|
3064
2846
|
if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || /^\/\//.test(raw)) return raw;
|
|
3065
|
-
var
|
|
2847
|
+
var baseUrl = this.__data.options.baseUrl;
|
|
2848
|
+
var base = baseUrl || (typeof document !== 'undefined' && document.baseURI ? document.baseURI : '');
|
|
3066
2849
|
if (!base) return raw;
|
|
3067
2850
|
try {
|
|
3068
2851
|
return new URL(raw, base).href;
|
|
@@ -3073,9 +2856,11 @@
|
|
|
3073
2856
|
}, {
|
|
3074
2857
|
key: "_importOne",
|
|
3075
2858
|
value: function _importOne(moduleId) {
|
|
3076
|
-
var
|
|
2859
|
+
var _this$__data5 = this.__data,
|
|
2860
|
+
policy = _this$__data5.policy,
|
|
2861
|
+
importImpl = _this$__data5.importImpl;
|
|
3077
2862
|
var url = this.resolveUrl(moduleId);
|
|
3078
|
-
var originDenied =
|
|
2863
|
+
var originDenied = policy.checkOrigin(url);
|
|
3079
2864
|
if (originDenied) {
|
|
3080
2865
|
return Promise.resolve({
|
|
3081
2866
|
ok: false,
|
|
@@ -3083,10 +2868,10 @@
|
|
|
3083
2868
|
message: originDenied.message
|
|
3084
2869
|
});
|
|
3085
2870
|
}
|
|
3086
|
-
var entry =
|
|
2871
|
+
var entry = policy.entryOf(moduleId);
|
|
3087
2872
|
var expected = entry && entry.sha256;
|
|
3088
2873
|
var run = function run() {
|
|
3089
|
-
var importer =
|
|
2874
|
+
var importer = importImpl || nativeImport;
|
|
3090
2875
|
if (typeof importer !== 'function') {
|
|
3091
2876
|
return Promise.resolve({
|
|
3092
2877
|
ok: false,
|
|
@@ -3111,7 +2896,7 @@
|
|
|
3111
2896
|
});
|
|
3112
2897
|
};
|
|
3113
2898
|
if (!expected) return run();
|
|
3114
|
-
return
|
|
2899
|
+
return policy.verify(url, expected).then(function (verified) {
|
|
3115
2900
|
if (!verified.ok) {
|
|
3116
2901
|
return {
|
|
3117
2902
|
ok: false,
|
|
@@ -3133,9 +2918,9 @@
|
|
|
3133
2918
|
}, {
|
|
3134
2919
|
key: "loadModules",
|
|
3135
2920
|
value: function loadModules(_path, _files, _callback) {
|
|
3136
|
-
var
|
|
2921
|
+
var _this2 = this;
|
|
2922
|
+
var policy = this.__data.policy;
|
|
3137
2923
|
var params = {
|
|
3138
|
-
path: this.__rootPath,
|
|
3139
2924
|
type: 'module'
|
|
3140
2925
|
};
|
|
3141
2926
|
var _parseArgs3 = parseArgs(_path, _files, _callback, params),
|
|
@@ -3149,7 +2934,7 @@
|
|
|
3149
2934
|
callback === null || callback === void 0 || callback(r);
|
|
3150
2935
|
return r;
|
|
3151
2936
|
};
|
|
3152
|
-
var denied =
|
|
2937
|
+
var denied = policy.checkModules(moduleIds);
|
|
3153
2938
|
if (denied) {
|
|
3154
2939
|
result.code = denied.code;
|
|
3155
2940
|
result.message = denied.message;
|
|
@@ -3158,11 +2943,9 @@
|
|
|
3158
2943
|
if (!files.length) {
|
|
3159
2944
|
return Promise.resolve(settle(result));
|
|
3160
2945
|
}
|
|
3161
|
-
var scoop = this.guard.begin();
|
|
3162
2946
|
return Promise.all(moduleIds.map(function (id) {
|
|
3163
|
-
return
|
|
2947
|
+
return _this2._importOne(id);
|
|
3164
2948
|
})).then(function (list) {
|
|
3165
|
-
result.warnings = scoop.end();
|
|
3166
2949
|
var failed = list.filter(function (item) {
|
|
3167
2950
|
return !item.ok;
|
|
3168
2951
|
});
|
|
@@ -3195,15 +2978,10 @@
|
|
|
3195
2978
|
}
|
|
3196
2979
|
_inherits(FileRequireClass, _BaseFileRequire);
|
|
3197
2980
|
return _createClass(FileRequireClass, [{
|
|
3198
|
-
key: "
|
|
3199
|
-
value: function
|
|
2981
|
+
key: "provide",
|
|
2982
|
+
value: function provide(path, files, callback) {
|
|
3200
2983
|
this._define(path, files, callback);
|
|
3201
2984
|
}
|
|
3202
|
-
}, {
|
|
3203
|
-
key: "defineScript",
|
|
3204
|
-
value: function defineScript(o) {
|
|
3205
|
-
this.provideScript(o);
|
|
3206
|
-
}
|
|
3207
2985
|
}, {
|
|
3208
2986
|
key: "provideScript",
|
|
3209
2987
|
value: function provideScript(o) {
|
|
@@ -3213,11 +2991,11 @@
|
|
|
3213
2991
|
return o;
|
|
3214
2992
|
};
|
|
3215
2993
|
}
|
|
3216
|
-
this.
|
|
2994
|
+
this.provide([], callback);
|
|
3217
2995
|
}
|
|
3218
2996
|
}, {
|
|
3219
|
-
key: "
|
|
3220
|
-
value: function
|
|
2997
|
+
key: "inject",
|
|
2998
|
+
value: function inject(path, files, callback) {
|
|
3221
2999
|
this._load(path, files, callback);
|
|
3222
3000
|
}
|
|
3223
3001
|
}, {
|
|
@@ -3245,38 +3023,28 @@
|
|
|
3245
3023
|
if (typeof error === 'function') {
|
|
3246
3024
|
error(result);
|
|
3247
3025
|
} else {
|
|
3248
|
-
self.
|
|
3026
|
+
self.debug && console.error('[devfab][FileRequire][injectScript] error: ', result);
|
|
3249
3027
|
}
|
|
3250
3028
|
}
|
|
3251
3029
|
}
|
|
3252
|
-
this.
|
|
3253
|
-
}
|
|
3254
|
-
}, {
|
|
3255
|
-
key: "requireScript",
|
|
3256
|
-
value: function requireScript(_path, _files, _callback) {
|
|
3257
|
-
this.injectScript(_path, _files, _callback);
|
|
3030
|
+
this.inject(path, files, onCallback);
|
|
3258
3031
|
}
|
|
3259
3032
|
}]);
|
|
3260
3033
|
}(BaseFileRequire);
|
|
3034
|
+
/**
|
|
3035
|
+
* 全局唯一的加载器实例。
|
|
3036
|
+
*
|
|
3037
|
+
* 加载策略(清单 / 白名单 / 版本锁)、全局污染观测、超时重试
|
|
3038
|
+
* 都是**部署级**约定,一个页面只应该有一套。
|
|
3039
|
+
*/
|
|
3261
3040
|
var FileRequire = new FileRequireClass();
|
|
3262
|
-
FileRequire.create = function (args) {
|
|
3263
|
-
return new FileRequireClass(_objectSpread2(_objectSpread2({}, this._snapshotConfig()), args));
|
|
3264
|
-
};
|
|
3265
3041
|
|
|
3266
3042
|
window.__devfab = Object.assign({}, window.__devfab);
|
|
3267
3043
|
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
3044
|
|
|
3275
3045
|
exports.CODE_POLICY = CODE_POLICY;
|
|
3276
3046
|
exports.CODE_TIMEOUT = CODE_TIMEOUT;
|
|
3277
|
-
exports.DEFAULT_WATCH = DEFAULT_WATCH;
|
|
3278
3047
|
exports.FileRequire = FileRequire;
|
|
3279
|
-
exports.GlobalGuard = GlobalGuard;
|
|
3280
3048
|
exports.LoadPolicy = LoadPolicy;
|
|
3281
3049
|
exports["default"] = FileRequire;
|
|
3282
3050
|
|