devfab 2.1.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 +23 -22
- package/dist/common/require.esm.js +1 -1
- package/dist/common/require.js +1 -1
- package/dist/index.esm.js +3 -3
- package/dist/index.js +3 -3
- package/dist/index.umd.js +3 -3
- package/lib/devfab.js +92 -274
- package/lib/devfab.min.js +3 -3
- package/lib/devfab.require.js +92 -276
- package/lib/devfab.require.min.js +1 -1
- package/package.json +1 -1
package/lib/devfab.require.js
CHANGED
|
@@ -2492,127 +2492,6 @@
|
|
|
2492
2492
|
}]);
|
|
2493
2493
|
}();
|
|
2494
2494
|
|
|
2495
|
-
/**
|
|
2496
|
-
* 全局污染检测:加载前后 diff window 的 key 集合。
|
|
2497
|
-
*
|
|
2498
|
-
* 为什么需要:二开脚本直接跑在宿主 window 上,A 客户的脚本改了一个全局变量,
|
|
2499
|
-
* B 客户就跟着崩,而且现场无法归因。真做 iframe / Proxy 沙箱成本极高,
|
|
2500
|
-
* 但「加载完能告诉你动了哪些全局」只需要几十行,能挡住大半这类事故。
|
|
2501
|
-
*
|
|
2502
|
-
* 边界(这是观测,不是隔离):
|
|
2503
|
-
* - 事后告警,不阻止副作用——脚本已经执行过了;
|
|
2504
|
-
* - 并发加载时窗口会重叠,归因以「最后完成的一批」结算,可能不准;
|
|
2505
|
-
* - 只比较可枚举自有属性的**引用**,`window.foo.bar = 1` 这类深层改动检测不到。
|
|
2506
|
-
*/
|
|
2507
|
-
|
|
2508
|
-
/** 默认盯防的 key:出现即说明宿主的关键设施被动过 */
|
|
2509
|
-
var DEFAULT_WATCH = ['$', 'jQuery', 'define', 'require', 'requirejs', 'devfab', '__devfab'];
|
|
2510
|
-
var GlobalGuard = /*#__PURE__*/function () {
|
|
2511
|
-
function GlobalGuard(options) {
|
|
2512
|
-
_classCallCheck(this, GlobalGuard);
|
|
2513
|
-
var o = options || {};
|
|
2514
|
-
this.maxPollution = o.maxPollution === undefined ? 3 : Number(o.maxPollution);
|
|
2515
|
-
this.watch = [].concat(o.watch || DEFAULT_WATCH);
|
|
2516
|
-
this.target = o.target || (typeof window !== 'undefined' ? window : null);
|
|
2517
|
-
this.enabled = o.enabled === undefined ? true : !!o.enabled;
|
|
2518
|
-
this._pending = 0;
|
|
2519
|
-
this._before = null;
|
|
2520
|
-
this.lastWarnings = [];
|
|
2521
|
-
}
|
|
2522
|
-
return _createClass(GlobalGuard, [{
|
|
2523
|
-
key: "_snapshot",
|
|
2524
|
-
value: function _snapshot() {
|
|
2525
|
-
var map = new Map();
|
|
2526
|
-
var target = this.target;
|
|
2527
|
-
if (!target) return map;
|
|
2528
|
-
Object.keys(target).forEach(function (key) {
|
|
2529
|
-
map.set(key, target[key]);
|
|
2530
|
-
});
|
|
2531
|
-
return map;
|
|
2532
|
-
}
|
|
2533
|
-
}, {
|
|
2534
|
-
key: "_diff",
|
|
2535
|
-
value: function _diff() {
|
|
2536
|
-
var _this = this;
|
|
2537
|
-
var before = this._before;
|
|
2538
|
-
var after = this._snapshot();
|
|
2539
|
-
var warnings = [];
|
|
2540
|
-
if (!before) return warnings;
|
|
2541
|
-
after.forEach(function (value, key) {
|
|
2542
|
-
var watched = _this.watch.indexOf(key) !== -1;
|
|
2543
|
-
if (!before.has(key)) {
|
|
2544
|
-
warnings.push({
|
|
2545
|
-
type: 'added',
|
|
2546
|
-
key: key,
|
|
2547
|
-
watched: watched
|
|
2548
|
-
});
|
|
2549
|
-
return;
|
|
2550
|
-
}
|
|
2551
|
-
if (before.get(key) !== value) {
|
|
2552
|
-
warnings.push({
|
|
2553
|
-
type: 'overwritten',
|
|
2554
|
-
key: key,
|
|
2555
|
-
watched: watched
|
|
2556
|
-
});
|
|
2557
|
-
}
|
|
2558
|
-
});
|
|
2559
|
-
// 命中盯防名单,或新增数量超过阈值,才认为「值得提醒」。
|
|
2560
|
-
// 1~2 个自有全局是正常写法,全报会把信号淹掉。
|
|
2561
|
-
var watchedCount = warnings.filter(function (item) {
|
|
2562
|
-
return item.watched;
|
|
2563
|
-
}).length;
|
|
2564
|
-
var addedCount = warnings.filter(function (item) {
|
|
2565
|
-
return item.type === 'added';
|
|
2566
|
-
}).length;
|
|
2567
|
-
if (!watchedCount && addedCount <= this.maxPollution) return [];
|
|
2568
|
-
return warnings;
|
|
2569
|
-
}
|
|
2570
|
-
|
|
2571
|
-
/**
|
|
2572
|
-
* 开始观测。返回的 `end()` 幂等,重复调用只有第一次有效,
|
|
2573
|
-
* 这样超时分支和 errback 分支可以都调,不会把计数搞负。
|
|
2574
|
-
*/
|
|
2575
|
-
}, {
|
|
2576
|
-
key: "begin",
|
|
2577
|
-
value: function begin() {
|
|
2578
|
-
var _this2 = this;
|
|
2579
|
-
if (!this.enabled || !this.target) {
|
|
2580
|
-
return {
|
|
2581
|
-
end: function end() {
|
|
2582
|
-
return [];
|
|
2583
|
-
}
|
|
2584
|
-
};
|
|
2585
|
-
}
|
|
2586
|
-
this._pending++;
|
|
2587
|
-
if (this._pending === 1) this._before = this._snapshot();
|
|
2588
|
-
var done = false;
|
|
2589
|
-
return {
|
|
2590
|
-
end: function end() {
|
|
2591
|
-
if (done) return [];
|
|
2592
|
-
done = true;
|
|
2593
|
-
_this2._pending--;
|
|
2594
|
-
// 还有并发批次没结束,交给最后结束的那一批结算
|
|
2595
|
-
if (_this2._pending > 0) return [];
|
|
2596
|
-
var warnings = _this2._diff();
|
|
2597
|
-
_this2._before = null;
|
|
2598
|
-
_this2.lastWarnings = warnings;
|
|
2599
|
-
return warnings;
|
|
2600
|
-
}
|
|
2601
|
-
};
|
|
2602
|
-
}
|
|
2603
|
-
}, {
|
|
2604
|
-
key: "configure",
|
|
2605
|
-
value: function configure(options) {
|
|
2606
|
-
var o = options || {};
|
|
2607
|
-
if (o.enabled !== undefined) this.enabled = !!o.enabled;
|
|
2608
|
-
if (o.maxPollution !== undefined) this.maxPollution = Number(o.maxPollution);
|
|
2609
|
-
if (o.watch !== undefined) this.watch = [].concat(o.watch || []);
|
|
2610
|
-
if (o.target !== undefined) this.target = o.target || null;
|
|
2611
|
-
return this;
|
|
2612
|
-
}
|
|
2613
|
-
}]);
|
|
2614
|
-
}();
|
|
2615
|
-
|
|
2616
2495
|
/** 加载超时:RequireJS 自己的 waitSeconds 默认 30s,这个定时器是更早的兜底 */
|
|
2617
2496
|
var CODE_TIMEOUT = 504;
|
|
2618
2497
|
|
|
@@ -2635,10 +2514,8 @@
|
|
|
2635
2514
|
var path = _path;
|
|
2636
2515
|
var files = _files;
|
|
2637
2516
|
var callback = _callback;
|
|
2638
|
-
// 单参形式:(files, callback) 或 (files)。判据是「第一个是数组、第二个不是数组」,
|
|
2639
|
-
// 放宽到非函数是因为 loadModules([url]) 这种不带回调的调用很常见。
|
|
2640
2517
|
if (Array.isArray(_path) && !Array.isArray(_files)) {
|
|
2641
|
-
path =
|
|
2518
|
+
path = undefined;
|
|
2642
2519
|
files = _path;
|
|
2643
2520
|
callback = typeof _files === 'function' ? _files : _callback;
|
|
2644
2521
|
}
|
|
@@ -2647,8 +2524,7 @@
|
|
|
2647
2524
|
var result = {
|
|
2648
2525
|
code: 0,
|
|
2649
2526
|
message: '',
|
|
2650
|
-
data: []
|
|
2651
|
-
warnings: []
|
|
2527
|
+
data: []
|
|
2652
2528
|
};
|
|
2653
2529
|
if (params.type === 'require' && typeof params.require !== 'function' || params.type === 'define' && typeof params.define !== 'function' //
|
|
2654
2530
|
) {
|
|
@@ -2688,64 +2564,44 @@
|
|
|
2688
2564
|
version: '',
|
|
2689
2565
|
timeout: 15000,
|
|
2690
2566
|
retry: 0,
|
|
2691
|
-
strict: false,
|
|
2692
2567
|
baseUrl: ''
|
|
2693
2568
|
};
|
|
2694
2569
|
var BaseFileRequire = /*#__PURE__*/function () {
|
|
2695
|
-
/**
|
|
2696
|
-
* args 只接受**参数与策略**,不接受加载器覆盖:
|
|
2697
|
-
* - 加载策略:`version` / `timeout` / `retry` / `strict` / `baseUrl` / `manifest`
|
|
2698
|
-
* / `origins` / `lockVersion` / `verifyHash` / `pollution` / `watch` / `maxPollution`
|
|
2699
|
-
* - 通道与时钟:`importer`(ESM 通道用的 import 函数)、`setTimeout` / `clearTimeout`
|
|
2700
|
-
*
|
|
2701
|
-
* 刻意**不再接受** `define` / `require` / `undef` / `requireConfig`:
|
|
2702
|
-
* 这四个是 AMD 加载器本体,AMD 通道只走内嵌的 RequireJS 2.3.2。以前允许覆盖的
|
|
2703
|
-
* 后果是「宿主传了自己的 require,但 undef 仍取内嵌的那份」,两套注册表混用,
|
|
2704
|
-
* 而且被覆盖时是静默的。要换通道请用 `loadModules()`,不要替换加载器。
|
|
2705
|
-
*
|
|
2706
|
-
* 其余配置一律走 `configure(options)` 在运行时改。
|
|
2707
|
-
*/
|
|
2708
2570
|
function BaseFileRequire(args) {
|
|
2709
|
-
var _this$__require;
|
|
2710
2571
|
_classCallCheck(this, BaseFileRequire);
|
|
2711
|
-
|
|
2712
|
-
// 只有显式传参才写全局。模块加载时会 new 一次单例,若无条件写 false,
|
|
2713
|
-
// 宿主在 import 之前设好的 `window.__devfab.debug` 会被抹掉。
|
|
2714
|
-
if (o.debug !== undefined) this.debug = !!o.debug;
|
|
2715
|
-
this.__rootPath = undefined;
|
|
2716
|
-
this.__define = __requirejs.define;
|
|
2717
|
-
this.__require = __requirejs.require;
|
|
2718
|
-
this.__undef = typeof ((_this$__require = this.__require) === null || _this$__require === void 0 ? void 0 : _this$__require.undef) === 'function' ? this.__require.undef : null;
|
|
2719
|
-
this.__requireConfig = this._pickRequireConfig(this.__require);
|
|
2720
|
-
this.__import = o.importer || null;
|
|
2721
|
-
this._setTimer = o.setTimeout || function (fn, ms) {
|
|
2722
|
-
return setTimeout(fn, ms);
|
|
2723
|
-
};
|
|
2724
|
-
this._clearTimer = o.clearTimeout || function (id) {
|
|
2725
|
-
return clearTimeout(id);
|
|
2726
|
-
};
|
|
2727
|
-
this.options = {
|
|
2728
|
-
version: o.version ? String(o.version) : DEFAULT_OPTIONS.version,
|
|
2729
|
-
timeout: o.timeout === undefined ? DEFAULT_OPTIONS.timeout : Math.max(0, toNumber(o.timeout, 0)),
|
|
2730
|
-
retry: o.retry === undefined ? DEFAULT_OPTIONS.retry : Math.max(0, toNumber(o.retry, 0)),
|
|
2731
|
-
strict: !!o.strict,
|
|
2732
|
-
baseUrl: o.baseUrl || DEFAULT_OPTIONS.baseUrl
|
|
2733
|
-
};
|
|
2734
|
-
this.policy = new LoadPolicy(o);
|
|
2735
|
-
this.guard = new GlobalGuard(this._guardOptions(o));
|
|
2736
|
-
if (this.options.version) this._applyUrlArgs();
|
|
2572
|
+
this.__init(args);
|
|
2737
2573
|
}
|
|
2738
|
-
|
|
2739
|
-
/**
|
|
2740
|
-
* 调试开关的**唯一来源**是 `window.__devfab.debug`。
|
|
2741
|
-
*
|
|
2742
|
-
* 为什么做成访问器:这个开关被三处读——加载器这里、`_utils/models/_extend.js` 的
|
|
2743
|
-
* 扩展脚本装配、`_utils/string.js` 的 isDebug。以前各读各的(实例字段 /
|
|
2744
|
-
* `window.__devfab.debug` / `window.devfab.debug`),宿主开了一个另两个不生效,
|
|
2745
|
-
* 排查时看起来像「日志不打印」。统一读写同一个位置后,`FileRequire.configure({debug:true})`、
|
|
2746
|
-
* `FileRequire.debug = true`、`window.__devfab.debug = true` 三句话效果完全一致。
|
|
2747
|
-
*/
|
|
2748
2574
|
return _createClass(BaseFileRequire, [{
|
|
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();
|
|
2603
|
+
}
|
|
2604
|
+
}, {
|
|
2749
2605
|
key: "debug",
|
|
2750
2606
|
get: function get() {
|
|
2751
2607
|
var ns = typeof window !== 'undefined' ? window.__devfab : null;
|
|
@@ -2766,48 +2622,26 @@
|
|
|
2766
2622
|
value: function _pickRequireConfig(loader) {
|
|
2767
2623
|
return loader && typeof loader.config === 'function' ? loader.config.bind(loader) : null;
|
|
2768
2624
|
}
|
|
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
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 || {};
|
|
2635
|
+
var _this$__data = this.__data,
|
|
2636
|
+
config = _this$__data.options,
|
|
2637
|
+
policy = _this$__data.policy;
|
|
2800
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,19 +2681,23 @@
|
|
|
2844
2681
|
}, {
|
|
2845
2682
|
key: "getVersion",
|
|
2846
2683
|
value: function getVersion() {
|
|
2847
|
-
return this.options.version;
|
|
2684
|
+
return this.__data.options.version;
|
|
2848
2685
|
}
|
|
2849
2686
|
|
|
2850
2687
|
/** 策略 + 兜底配置摘要,宿主启动时打一行日志排查效率最高 */
|
|
2851
2688
|
}, {
|
|
2852
2689
|
key: "describe",
|
|
2853
2690
|
value: function describe() {
|
|
2854
|
-
|
|
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, {
|
|
2855
2697
|
debug: this.debug,
|
|
2856
|
-
policy:
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
canNativeImport: typeof (this.__import || nativeImport) === 'function'
|
|
2698
|
+
policy: policy.describe(),
|
|
2699
|
+
canUndef: typeof undef === 'function',
|
|
2700
|
+
canNativeImport: typeof (importImpl || nativeImport) === 'function'
|
|
2860
2701
|
});
|
|
2861
2702
|
}
|
|
2862
2703
|
|
|
@@ -2865,8 +2706,7 @@
|
|
|
2865
2706
|
key: "_define",
|
|
2866
2707
|
value: function _define(_path, _files, _callback) {
|
|
2867
2708
|
var params = {
|
|
2868
|
-
|
|
2869
|
-
define: this.__define,
|
|
2709
|
+
define: this.__data.define,
|
|
2870
2710
|
type: 'define'
|
|
2871
2711
|
};
|
|
2872
2712
|
var _parseArgs = parseArgs(_path, _files, _callback, params),
|
|
@@ -2878,28 +2718,16 @@
|
|
|
2878
2718
|
callback === null || callback === void 0 || callback(result);
|
|
2879
2719
|
return;
|
|
2880
2720
|
}
|
|
2881
|
-
this.
|
|
2882
|
-
}
|
|
2883
|
-
}, {
|
|
2884
|
-
key: "_mergeWarnings",
|
|
2885
|
-
value: function _mergeWarnings(prev, next) {
|
|
2886
|
-
var list = (prev || []).slice();
|
|
2887
|
-
(next || []).forEach(function (item) {
|
|
2888
|
-
var exists = list.some(function (one) {
|
|
2889
|
-
return one.type === item.type && one.key === item.key;
|
|
2890
|
-
});
|
|
2891
|
-
if (!exists) list.push(item);
|
|
2892
|
-
});
|
|
2893
|
-
return list;
|
|
2721
|
+
this.__data.define(path, files, callback);
|
|
2894
2722
|
}
|
|
2895
2723
|
}, {
|
|
2896
2724
|
key: "_undefModules",
|
|
2897
2725
|
value: function _undefModules(moduleIds) {
|
|
2898
|
-
var
|
|
2899
|
-
if (typeof
|
|
2726
|
+
var undef = this.__data.undef;
|
|
2727
|
+
if (typeof undef !== 'function') return;
|
|
2900
2728
|
moduleIds.forEach(function (id) {
|
|
2901
2729
|
try {
|
|
2902
|
-
|
|
2730
|
+
undef(id);
|
|
2903
2731
|
} catch (err) {
|
|
2904
2732
|
// undef 只对曾经顶层 require 过的模块有效;抛错说明它还没进注册表,忽略即可
|
|
2905
2733
|
}
|
|
@@ -2907,18 +2735,22 @@
|
|
|
2907
2735
|
}
|
|
2908
2736
|
|
|
2909
2737
|
/**
|
|
2910
|
-
* 统一加载入口:策略校验 ->
|
|
2738
|
+
* 统一加载入口:策略校验 -> 计时 / 重试 -> 结算。
|
|
2911
2739
|
* 默认配置(version 空、retry 0、timeout 15s)下的行为与原来一致,
|
|
2912
|
-
*
|
|
2740
|
+
* 只是多了一个「更早失败」的兜底。
|
|
2913
2741
|
*/
|
|
2914
2742
|
}, {
|
|
2915
2743
|
key: "_load",
|
|
2916
2744
|
value: function _load(_path, _files, _callback) {
|
|
2917
|
-
var
|
|
2918
|
-
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;
|
|
2919
2752
|
var params = {
|
|
2920
|
-
|
|
2921
|
-
require: this.__require,
|
|
2753
|
+
require: require,
|
|
2922
2754
|
type: 'require'
|
|
2923
2755
|
};
|
|
2924
2756
|
var _parseArgs2 = parseArgs(_path, _files, _callback, params),
|
|
@@ -2932,7 +2764,7 @@
|
|
|
2932
2764
|
return;
|
|
2933
2765
|
}
|
|
2934
2766
|
var moduleIds = toModuleIds(path, files);
|
|
2935
|
-
var denied =
|
|
2767
|
+
var denied = policy.checkModules(moduleIds);
|
|
2936
2768
|
if (denied) {
|
|
2937
2769
|
result.code = denied.code;
|
|
2938
2770
|
result.message = denied.message;
|
|
@@ -2942,40 +2774,26 @@
|
|
|
2942
2774
|
var settled = false;
|
|
2943
2775
|
var attempt = 0;
|
|
2944
2776
|
var timer = null;
|
|
2945
|
-
var scoop = null;
|
|
2946
|
-
var closeScoop = function closeScoop() {
|
|
2947
|
-
if (!scoop) return;
|
|
2948
|
-
result.warnings = _this2._mergeWarnings(result.warnings, scoop.end());
|
|
2949
|
-
scoop = null;
|
|
2950
|
-
};
|
|
2951
2777
|
var finish = function finish() {
|
|
2952
2778
|
if (settled) return;
|
|
2953
2779
|
settled = true;
|
|
2954
2780
|
if (timer !== null) {
|
|
2955
|
-
|
|
2781
|
+
clearTimer(timer);
|
|
2956
2782
|
timer = null;
|
|
2957
2783
|
}
|
|
2958
|
-
closeScoop();
|
|
2959
|
-
if (config.strict && result.warnings.length) {
|
|
2960
|
-
result.code = 500;
|
|
2961
|
-
result.message = "Global pollution detection failed\uFF1A".concat(result.warnings.map(function (item) {
|
|
2962
|
-
return "".concat(item.type, ":").concat(item.key);
|
|
2963
|
-
}).join(', '));
|
|
2964
|
-
}
|
|
2965
2784
|
callback === null || callback === void 0 || callback(result);
|
|
2966
2785
|
};
|
|
2967
2786
|
var start = function start() {
|
|
2968
2787
|
attempt++;
|
|
2969
|
-
scoop = _this2.guard.begin();
|
|
2970
2788
|
if (config.timeout > 0) {
|
|
2971
|
-
timer =
|
|
2789
|
+
timer = setTimer(function () {
|
|
2972
2790
|
if (settled) return;
|
|
2973
2791
|
var err = new Error("load timeout after ".concat(config.timeout, "ms: ").concat(filesStr));
|
|
2974
2792
|
err.__devfabTimeout = true;
|
|
2975
2793
|
retryOrFail(err, "files load timeout after ".concat(config.timeout, "ms, the files: ").concat(filesStr));
|
|
2976
2794
|
}, config.timeout);
|
|
2977
2795
|
}
|
|
2978
|
-
|
|
2796
|
+
require(path, files, function () {
|
|
2979
2797
|
for (var _len = arguments.length, contents = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2980
2798
|
contents[_key] = arguments[_key];
|
|
2981
2799
|
}
|
|
@@ -2988,13 +2806,12 @@
|
|
|
2988
2806
|
var retryOrFail = function retryOrFail(err, message) {
|
|
2989
2807
|
if (settled) return;
|
|
2990
2808
|
if (timer !== null) {
|
|
2991
|
-
|
|
2809
|
+
clearTimer(timer);
|
|
2992
2810
|
timer = null;
|
|
2993
2811
|
}
|
|
2994
2812
|
if (attempt <= config.retry) {
|
|
2995
|
-
closeScoop();
|
|
2996
2813
|
// 不 undef 就会复用上一次的失败状态,重试形同虚设
|
|
2997
|
-
|
|
2814
|
+
_this._undefModules(moduleIds);
|
|
2998
2815
|
start();
|
|
2999
2816
|
return;
|
|
3000
2817
|
}
|
|
@@ -3027,7 +2844,8 @@
|
|
|
3027
2844
|
value: function resolveUrl(rel) {
|
|
3028
2845
|
var raw = String(rel == null ? '' : rel);
|
|
3029
2846
|
if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || /^\/\//.test(raw)) return raw;
|
|
3030
|
-
var
|
|
2847
|
+
var baseUrl = this.__data.options.baseUrl;
|
|
2848
|
+
var base = baseUrl || (typeof document !== 'undefined' && document.baseURI ? document.baseURI : '');
|
|
3031
2849
|
if (!base) return raw;
|
|
3032
2850
|
try {
|
|
3033
2851
|
return new URL(raw, base).href;
|
|
@@ -3038,9 +2856,11 @@
|
|
|
3038
2856
|
}, {
|
|
3039
2857
|
key: "_importOne",
|
|
3040
2858
|
value: function _importOne(moduleId) {
|
|
3041
|
-
var
|
|
2859
|
+
var _this$__data5 = this.__data,
|
|
2860
|
+
policy = _this$__data5.policy,
|
|
2861
|
+
importImpl = _this$__data5.importImpl;
|
|
3042
2862
|
var url = this.resolveUrl(moduleId);
|
|
3043
|
-
var originDenied =
|
|
2863
|
+
var originDenied = policy.checkOrigin(url);
|
|
3044
2864
|
if (originDenied) {
|
|
3045
2865
|
return Promise.resolve({
|
|
3046
2866
|
ok: false,
|
|
@@ -3048,10 +2868,10 @@
|
|
|
3048
2868
|
message: originDenied.message
|
|
3049
2869
|
});
|
|
3050
2870
|
}
|
|
3051
|
-
var entry =
|
|
2871
|
+
var entry = policy.entryOf(moduleId);
|
|
3052
2872
|
var expected = entry && entry.sha256;
|
|
3053
2873
|
var run = function run() {
|
|
3054
|
-
var importer =
|
|
2874
|
+
var importer = importImpl || nativeImport;
|
|
3055
2875
|
if (typeof importer !== 'function') {
|
|
3056
2876
|
return Promise.resolve({
|
|
3057
2877
|
ok: false,
|
|
@@ -3076,7 +2896,7 @@
|
|
|
3076
2896
|
});
|
|
3077
2897
|
};
|
|
3078
2898
|
if (!expected) return run();
|
|
3079
|
-
return
|
|
2899
|
+
return policy.verify(url, expected).then(function (verified) {
|
|
3080
2900
|
if (!verified.ok) {
|
|
3081
2901
|
return {
|
|
3082
2902
|
ok: false,
|
|
@@ -3098,9 +2918,9 @@
|
|
|
3098
2918
|
}, {
|
|
3099
2919
|
key: "loadModules",
|
|
3100
2920
|
value: function loadModules(_path, _files, _callback) {
|
|
3101
|
-
var
|
|
2921
|
+
var _this2 = this;
|
|
2922
|
+
var policy = this.__data.policy;
|
|
3102
2923
|
var params = {
|
|
3103
|
-
path: this.__rootPath,
|
|
3104
2924
|
type: 'module'
|
|
3105
2925
|
};
|
|
3106
2926
|
var _parseArgs3 = parseArgs(_path, _files, _callback, params),
|
|
@@ -3114,7 +2934,7 @@
|
|
|
3114
2934
|
callback === null || callback === void 0 || callback(r);
|
|
3115
2935
|
return r;
|
|
3116
2936
|
};
|
|
3117
|
-
var denied =
|
|
2937
|
+
var denied = policy.checkModules(moduleIds);
|
|
3118
2938
|
if (denied) {
|
|
3119
2939
|
result.code = denied.code;
|
|
3120
2940
|
result.message = denied.message;
|
|
@@ -3123,11 +2943,9 @@
|
|
|
3123
2943
|
if (!files.length) {
|
|
3124
2944
|
return Promise.resolve(settle(result));
|
|
3125
2945
|
}
|
|
3126
|
-
var scoop = this.guard.begin();
|
|
3127
2946
|
return Promise.all(moduleIds.map(function (id) {
|
|
3128
|
-
return
|
|
2947
|
+
return _this2._importOne(id);
|
|
3129
2948
|
})).then(function (list) {
|
|
3130
|
-
result.warnings = scoop.end();
|
|
3131
2949
|
var failed = list.filter(function (item) {
|
|
3132
2950
|
return !item.ok;
|
|
3133
2951
|
});
|
|
@@ -3226,9 +3044,7 @@
|
|
|
3226
3044
|
|
|
3227
3045
|
exports.CODE_POLICY = CODE_POLICY;
|
|
3228
3046
|
exports.CODE_TIMEOUT = CODE_TIMEOUT;
|
|
3229
|
-
exports.DEFAULT_WATCH = DEFAULT_WATCH;
|
|
3230
3047
|
exports.FileRequire = FileRequire;
|
|
3231
|
-
exports.GlobalGuard = GlobalGuard;
|
|
3232
3048
|
exports.LoadPolicy = LoadPolicy;
|
|
3233
3049
|
exports["default"] = FileRequire;
|
|
3234
3050
|
|