babel-plugin-hylid-bridge 4.0.25 → 4.0.26-alpha.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/lib/generateCompatibilities.js +36 -31
- package/lib/index.js +5 -11
- package/package.json +2 -2
|
@@ -6,55 +6,60 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = _default;
|
|
8
8
|
exports.filterWhichCanIUseJsapi = filterWhichCanIUseJsapi;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
10
|
var _path = _interopRequireDefault(require("path"));
|
|
10
11
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
11
12
|
var _getLibraryDir = _interopRequireDefault(require("./getLibraryDir"));
|
|
12
|
-
var _helper = require("./helper");
|
|
13
13
|
// 筛选 hylid-bridge 兼容度信息
|
|
14
14
|
function _default(targets, libraryDir) {
|
|
15
15
|
var lib = libraryDir || (0, _getLibraryDir.default)();
|
|
16
|
-
targets = targets.map(function (item) {
|
|
17
|
-
return item.toLowerCase();
|
|
18
|
-
});
|
|
19
16
|
// 获取 lib 下的 bridge.js 文件
|
|
20
17
|
var bridgeFile = _path.default.join(lib, 'lib', 'whichCanIUse', 'compatibilities.json');
|
|
21
18
|
var compatibilities = JSON.parse(_fsExtra.default.readFileSync(bridgeFile, 'utf-8'));
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return true;
|
|
19
|
+
var envMaps = compatibilities.envMaps;
|
|
20
|
+
var envs = [];
|
|
21
|
+
var targetsList = targets.map(function (target) {
|
|
22
|
+
var res = {
|
|
23
|
+
platform: '',
|
|
24
|
+
clientName: ''
|
|
25
|
+
};
|
|
26
|
+
['Mp', 'MpWeb', 'Web'].some(function (prefix) {
|
|
27
|
+
if (target.startsWith(prefix)) {
|
|
28
|
+
res.platform = prefix.toUpperCase();
|
|
29
|
+
res.clientName = target.replace(prefix, '').toUpperCase();
|
|
30
|
+
}
|
|
35
31
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
return res;
|
|
33
|
+
});
|
|
34
|
+
envMaps.forEach(function (env, index) {
|
|
35
|
+
var _env$split = env.split('_'),
|
|
36
|
+
_env$split2 = (0, _slicedToArray2.default)(_env$split, 3),
|
|
37
|
+
clientName = _env$split2[0],
|
|
38
|
+
_ = _env$split2[1],
|
|
39
|
+
platform = _env$split2[2];
|
|
40
|
+
if (targetsList.some(function (item) {
|
|
41
|
+
return item.platform === platform && item.clientName === clientName;
|
|
42
|
+
})) {
|
|
43
|
+
envs.push(index);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
compatibilities.data.forEach(function (item) {
|
|
47
|
+
item.compatibilities = item.compatibilities.filter(function (i) {
|
|
48
|
+
return envs.includes(i.env);
|
|
44
49
|
});
|
|
45
|
-
}
|
|
50
|
+
});
|
|
51
|
+
compatibilities.data = compatibilities.data.filter(function (item) {
|
|
52
|
+
return item.compatibilities.length > 0;
|
|
53
|
+
});
|
|
46
54
|
_fsExtra.default.writeFileSync(bridgeFile, JSON.stringify(compatibilities));
|
|
47
55
|
}
|
|
48
56
|
// 从 api 维度筛除数据
|
|
49
57
|
function filterWhichCanIUseJsapi(apiList) {
|
|
50
58
|
var lib = (0, _getLibraryDir.default)();
|
|
51
|
-
// 获取 lib 下的 bridge.js 文件
|
|
52
59
|
var bridgeFile = _path.default.join(lib, 'lib', 'whichCanIUse', 'compatibilities.json');
|
|
53
60
|
var compatibilities = JSON.parse(_fsExtra.default.readFileSync(bridgeFile, 'utf-8'));
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
delete compatibilities[api];
|
|
57
|
-
}
|
|
61
|
+
compatibilities.data = compatibilities.data.filter(function (item) {
|
|
62
|
+
return apiList.includes(item.apiName);
|
|
58
63
|
});
|
|
59
64
|
_fsExtra.default.writeFileSync(bridgeFile, JSON.stringify(compatibilities));
|
|
60
65
|
}
|
package/lib/index.js
CHANGED
|
@@ -90,17 +90,11 @@ var _default = exports.default = function _default(core, opts) {
|
|
|
90
90
|
if (!state.whichCanIUseJsapiList) {
|
|
91
91
|
state.whichCanIUseJsapiList = [];
|
|
92
92
|
}
|
|
93
|
-
if (path.node.arguments[0].type === '
|
|
94
|
-
path.node.arguments[0].
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} else {
|
|
99
|
-
// apiName 为非字符串类型,警告开发者
|
|
100
|
-
(0, _utils.warn)('WhichCanIUse warning: apiName must be a string literal and not a variable');
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
});
|
|
93
|
+
if (path.node.arguments[0].type === 'StringLiteral') {
|
|
94
|
+
state.whichCanIUseJsapiList.push(path.node.arguments[0].value);
|
|
95
|
+
} else {
|
|
96
|
+
// apiName 为非字符串类型,警告开发者
|
|
97
|
+
(0, _utils.warn)('WhichCanIUse warning: apiName must be a string literal and not a variable');
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
if (path.node.callee.type !== 'MemberExpression' || !transformMy) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-hylid-bridge",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.26-alpha.0",
|
|
4
4
|
"description": "babel-plugin-hylid-bridge",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/babel-plugin-tester": "^9.0.7",
|
|
24
24
|
"babel-plugin-tester": "^10.1.0",
|
|
25
|
-
"hylid-bridge": "^4.0.
|
|
25
|
+
"hylid-bridge": "^4.0.26-alpha.0"
|
|
26
26
|
},
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"registry": "https://registry.npmjs.org/"
|