@alicloud/alfa-core 1.5.6-alpha.0 → 1.5.6-alpha.1

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.
@@ -1,6 +1,9 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ var _window$ALIYUN_CONSOL;
2
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- var whiteList = ['alicdn.com', 'idptcloud01cdn.com'];
4
+ // 支持的主权云 CDN Host
5
+ // @ts-ignore
6
+ var whiteList = ['idptcloud01cdn.com', ((_window$ALIYUN_CONSOL = window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.MAIN_RESOURCE_CDN) || 'alicdn.com'];
4
7
  var win = window;
5
8
 
6
9
  // 兼容非公有云环境
@@ -11,7 +14,11 @@ var getCurrentCdnHost = function getCurrentCdnHost() {
11
14
  if (win.__alfa_cdn_host__) {
12
15
  return win.__alfa_cdn_host__;
13
16
  }
14
- var scriptUrl = ((_document$currentScri = document.currentScript) === null || _document$currentScri === void 0 ? void 0 : _document$currentScri.src) || import.meta.url;
17
+ var scriptUrl = (_document$currentScri = document.currentScript) === null || _document$currentScri === void 0 ? void 0 : _document$currentScri.src;
18
+ if (!scriptUrl) {
19
+ var _Error$stack, _Error$stack$toString;
20
+ scriptUrl = (_Error$stack = new Error('').stack) === null || _Error$stack === void 0 ? void 0 : (_Error$stack$toString = _Error$stack.toString().match(/(https?:\/\/[^\s]+)/)) === null || _Error$stack$toString === void 0 ? void 0 : _Error$stack$toString[1];
21
+ }
15
22
 
16
23
  // document.currentScript 可能为 null
17
24
  var _URL = new URL(scriptUrl),
@@ -28,6 +35,9 @@ var getCurrentCdnHost = function getCurrentCdnHost() {
28
35
  };
29
36
  var currentCdnHost = getCurrentCdnHost();
30
37
 
38
+ // 如果 host 被 o2 插件替换,则可以被用来判断是否需要替换 cdnHost
39
+ var gCdnHost = '//g.alicdn.com/';
40
+
31
41
  // 根据不同环境替换 cdn 的域名
32
42
  export default function requestInterceptor(_x) {
33
43
  return _requestInterceptor.apply(this, arguments);
@@ -37,7 +47,7 @@ function _requestInterceptor() {
37
47
  return _regeneratorRuntime.wrap(function _callee$(_context) {
38
48
  while (1) switch (_context.prev = _context.next) {
39
49
  case 0:
40
- if (currentCdnHost && currentCdnHost !== 'alicdn.com' && whiteList.includes(currentCdnHost)) {
50
+ if (currentCdnHost && currentCdnHost !== 'alicdn.com' && (whiteList.includes(currentCdnHost) || gCdnHost.includes(currentCdnHost))) {
41
51
  // if cdn is not alicdn, replace it
42
52
  if (config.url) {
43
53
  config.url = config.url.replace(new RegExp('.alicdn.com'), ".".concat(currentCdnHost)).replace('cws2.', 'cws.') // 非公有云下无 cws2
@@ -7,7 +7,10 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = requestInterceptor;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
- var whiteList = ['alicdn.com', 'idptcloud01cdn.com'];
10
+ var _window$ALIYUN_CONSOL;
11
+ // 支持的主权云 CDN Host
12
+ // @ts-ignore
13
+ var whiteList = ['idptcloud01cdn.com', ((_window$ALIYUN_CONSOL = window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.MAIN_RESOURCE_CDN) || 'alicdn.com'];
11
14
  var win = window;
12
15
 
13
16
  // 兼容非公有云环境
@@ -18,7 +21,11 @@ var getCurrentCdnHost = function getCurrentCdnHost() {
18
21
  if (win.__alfa_cdn_host__) {
19
22
  return win.__alfa_cdn_host__;
20
23
  }
21
- var scriptUrl = ((_document$currentScri = document.currentScript) === null || _document$currentScri === void 0 ? void 0 : _document$currentScri.src) || import.meta.url;
24
+ var scriptUrl = (_document$currentScri = document.currentScript) === null || _document$currentScri === void 0 ? void 0 : _document$currentScri.src;
25
+ if (!scriptUrl) {
26
+ var _Error$stack, _Error$stack$toString;
27
+ scriptUrl = (_Error$stack = new Error('').stack) === null || _Error$stack === void 0 ? void 0 : (_Error$stack$toString = _Error$stack.toString().match(/(https?:\/\/[^\s]+)/)) === null || _Error$stack$toString === void 0 ? void 0 : _Error$stack$toString[1];
28
+ }
22
29
 
23
30
  // document.currentScript 可能为 null
24
31
  var _URL = new URL(scriptUrl),
@@ -35,6 +42,9 @@ var getCurrentCdnHost = function getCurrentCdnHost() {
35
42
  };
36
43
  var currentCdnHost = getCurrentCdnHost();
37
44
 
45
+ // 如果 host 被 o2 插件替换,则可以被用来判断是否需要替换 cdnHost
46
+ var gCdnHost = '//g.alicdn.com/';
47
+
38
48
  // 根据不同环境替换 cdn 的域名
39
49
  function requestInterceptor(_x) {
40
50
  return _requestInterceptor.apply(this, arguments);
@@ -44,7 +54,7 @@ function _requestInterceptor() {
44
54
  return _regenerator.default.wrap(function _callee$(_context) {
45
55
  while (1) switch (_context.prev = _context.next) {
46
56
  case 0:
47
- if (currentCdnHost && currentCdnHost !== 'alicdn.com' && whiteList.includes(currentCdnHost)) {
57
+ if (currentCdnHost && currentCdnHost !== 'alicdn.com' && (whiteList.includes(currentCdnHost) || gCdnHost.includes(currentCdnHost))) {
48
58
  // if cdn is not alicdn, replace it
49
59
  if (config.url) {
50
60
  config.url = config.url.replace(new RegExp('.alicdn.com'), ".".concat(currentCdnHost)).replace('cws2.', 'cws.') // 非公有云下无 cws2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/alfa-core",
3
- "version": "1.5.6-alpha.0",
3
+ "version": "1.5.6-alpha.1",
4
4
  "description": "MicroFront End SDK for alicloud",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",