babel-plugin-hylid-bridge 4.0.27-alpha.0 → 4.0.28-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.
- package/lib/generateCompatibilities.js +31 -36
- package/lib/index.js +11 -5
- package/package.json +2 -2
|
@@ -6,60 +6,55 @@ 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"));
|
|
10
9
|
var _path = _interopRequireDefault(require("path"));
|
|
11
10
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
12
11
|
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
|
+
});
|
|
16
19
|
// 获取 lib 下的 bridge.js 文件
|
|
17
20
|
var bridgeFile = _path.default.join(lib, 'lib', 'whichCanIUse', 'compatibilities.json');
|
|
18
21
|
var compatibilities = JSON.parse(_fsExtra.default.readFileSync(bridgeFile, 'utf-8'));
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
// 获取 hylid-bridge 版本
|
|
23
|
+
var packageJsonFile = _path.default.join(lib, 'package.json');
|
|
24
|
+
var _JSON$parse = JSON.parse(_fsExtra.default.readFileSync(packageJsonFile, 'utf-8')),
|
|
25
|
+
version = _JSON$parse.version;
|
|
26
|
+
for (var api in compatibilities) {
|
|
27
|
+
compatibilities[api] = compatibilities[api].filter(function (item) {
|
|
28
|
+
// 标记删除的数据不要
|
|
29
|
+
if (item.deleteAt) return false;
|
|
30
|
+
// 比当前 hylid-bridge 版本低的不要
|
|
31
|
+
if (item.hylidBridgeVersion && (0, _helper.compareVersion)(version, item.hylidBridgeVersion) < 0) return false;
|
|
32
|
+
// babel 配置中没有的平台和客户端不要
|
|
33
|
+
if (!targets.includes((item.platformType + item.clientName).toLowerCase())) return false;
|
|
34
|
+
return true;
|
|
31
35
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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);
|
|
36
|
+
compatibilities[api] = compatibilities[api].map(function (item) {
|
|
37
|
+
return {
|
|
38
|
+
clientName: item.clientName,
|
|
39
|
+
platformType: item.platformType,
|
|
40
|
+
clientVersion: item.clientVersion,
|
|
41
|
+
osType: item.osType,
|
|
42
|
+
supported: item.supported
|
|
43
|
+
};
|
|
49
44
|
});
|
|
50
|
-
}
|
|
51
|
-
compatibilities.data = compatibilities.data.filter(function (item) {
|
|
52
|
-
return item.compatibilities.length > 0;
|
|
53
|
-
});
|
|
45
|
+
}
|
|
54
46
|
_fsExtra.default.writeFileSync(bridgeFile, JSON.stringify(compatibilities));
|
|
55
47
|
}
|
|
56
48
|
// 从 api 维度筛除数据
|
|
57
49
|
function filterWhichCanIUseJsapi(apiList) {
|
|
58
50
|
var lib = (0, _getLibraryDir.default)();
|
|
51
|
+
// 获取 lib 下的 bridge.js 文件
|
|
59
52
|
var bridgeFile = _path.default.join(lib, 'lib', 'whichCanIUse', 'compatibilities.json');
|
|
60
53
|
var compatibilities = JSON.parse(_fsExtra.default.readFileSync(bridgeFile, 'utf-8'));
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
Object.keys(compatibilities).forEach(function (api) {
|
|
55
|
+
if (!apiList.includes(api)) {
|
|
56
|
+
delete compatibilities[api];
|
|
57
|
+
}
|
|
63
58
|
});
|
|
64
59
|
_fsExtra.default.writeFileSync(bridgeFile, JSON.stringify(compatibilities));
|
|
65
60
|
}
|
package/lib/index.js
CHANGED
|
@@ -90,11 +90,17 @@ 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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
if (path.node.arguments[0].type === 'ObjectExpression') {
|
|
94
|
+
path.node.arguments[0].properties.forEach(function (property) {
|
|
95
|
+
if (property.type === 'ObjectProperty' && property.key.type === 'Identifier' && property.key.name === 'apiName') {
|
|
96
|
+
if (property.value.type === 'StringLiteral') {
|
|
97
|
+
state.whichCanIUseJsapiList.push(property.value.value);
|
|
98
|
+
} else {
|
|
99
|
+
// apiName 为非字符串类型,警告开发者
|
|
100
|
+
(0, _utils.warn)('WhichCanIUse warning: apiName must be a string literal and not a variable');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
98
104
|
}
|
|
99
105
|
}
|
|
100
106
|
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.28-alpha.1",
|
|
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.28-alpha.1"
|
|
26
26
|
},
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"registry": "https://registry.npmjs.org/"
|