@dcloudio/uni-cli-shared 2.0.1-alpha-36720221014001 → 2.0.1-alpha-36720221017001
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/index.js +1 -2
- package/lib/uni_modules/uni_modules.js +74 -84
- package/package.json +2 -2
- package/lib/uni_modules-loader.js +0 -8
package/lib/index.js
CHANGED
|
@@ -1,65 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
Object.defineProperty(exports,
|
|
6
|
-
exports.
|
|
7
|
-
const path_1 = __importDefault(require(
|
|
8
|
-
const fs_extra_1 = __importDefault(require(
|
|
9
|
-
const merge_1 = require(
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
const importCodes = []
|
|
16
|
-
const assignCodes = []
|
|
17
|
-
fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
|
|
18
|
-
var _a, _b
|
|
19
|
-
const pkgPath = path_1.default.resolve(uniModulesDir, uniModuleDir, 'package.json')
|
|
20
|
-
if (!fs_extra_1.default.existsSync(pkgPath)) {
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
const exports = (_b = (_a = JSON.parse(fs_extra_1.default.readFileSync(pkgPath, 'utf8'))) === null || _a === void 0 ? void 0 : _a.uni_modules) === null || _b === void 0 ? void 0 : _b.exports
|
|
24
|
-
if (exports) {
|
|
25
|
-
const [exportsImportCodes, exportsAssignCodes] = parseExports(process.env.UNI_PLATFORM === 'h5' ? 'web' : process.env.UNI_PLATFORM, `@/uni_modules/${uniModuleDir}`, exports)
|
|
26
|
-
importCodes.push(...exportsImportCodes)
|
|
27
|
-
assignCodes.push(...exportsAssignCodes)
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
if (!importCodes.length) {
|
|
31
|
-
return ''
|
|
32
|
-
}
|
|
33
|
-
return `${importCodes.join('\n')}
|
|
34
|
-
${assignCodes.join('\n')}`
|
|
35
|
-
}
|
|
36
|
-
exports.genUniModulesExports = genUniModulesExports
|
|
37
|
-
function parseExports (platform, source, exports = {}) {
|
|
38
|
-
const rootDefines = {}
|
|
39
|
-
Object.keys(exports).forEach((name) => {
|
|
40
|
-
if (name.startsWith('uni')) {
|
|
41
|
-
rootDefines[name] = exports[name]
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseInject = exports.parseInjects = exports.parseUniExtApis = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const merge_1 = require("merge");
|
|
10
|
+
function parseUniExtApis() {
|
|
11
|
+
const uniModulesDir = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules');
|
|
12
|
+
if (!fs_extra_1.default.existsSync(uniModulesDir)) {
|
|
13
|
+
return {};
|
|
42
14
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
15
|
+
const injects = {};
|
|
16
|
+
fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
// 必须以 uni- 开头
|
|
19
|
+
if (!uniModuleDir.startsWith('uni-')) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const pkgPath = path_1.default.resolve(uniModulesDir, uniModuleDir, 'package.json');
|
|
23
|
+
if (!fs_extra_1.default.existsSync(pkgPath)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const exports = (_b = (_a = JSON.parse(fs_extra_1.default.readFileSync(pkgPath, 'utf8'))) === null || _a === void 0 ? void 0 : _a.uni_modules) === null || _b === void 0 ? void 0 : _b['uni-ext-api'];
|
|
27
|
+
if (exports) {
|
|
28
|
+
Object.assign(injects, parseInjects(process.env.UNI_PLATFORM === 'h5' ? 'web' : process.env.UNI_PLATFORM, `@/uni_modules/${uniModuleDir}`, exports));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return injects;
|
|
50
32
|
}
|
|
51
|
-
exports.
|
|
52
|
-
function parseDefines (source, defines = {}) {
|
|
53
|
-
const importCodes = []
|
|
54
|
-
const assignCodes = []
|
|
55
|
-
Object.keys(defines).forEach((name) => {
|
|
56
|
-
const [defineImportCodes, defineAssignCodes] = parseDefine(source, name, defines[name])
|
|
57
|
-
importCodes.push(...defineImportCodes)
|
|
58
|
-
assignCodes.push(...defineAssignCodes)
|
|
59
|
-
})
|
|
60
|
-
return [importCodes, assignCodes]
|
|
61
|
-
}
|
|
62
|
-
exports.parseDefines = parseDefines
|
|
33
|
+
exports.parseUniExtApis = parseUniExtApis;
|
|
63
34
|
/**
|
|
64
35
|
* uni:'getBatteryInfo'
|
|
65
36
|
* import getBatteryInfo from '..'
|
|
@@ -81,29 +52,48 @@ exports.parseDefines = parseDefines
|
|
|
81
52
|
* @param define
|
|
82
53
|
* @returns
|
|
83
54
|
*/
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
55
|
+
function parseInjects(platform, source, exports = {}) {
|
|
56
|
+
let rootDefines = {};
|
|
57
|
+
Object.keys(exports).forEach((name) => {
|
|
58
|
+
if (name.startsWith('uni')) {
|
|
59
|
+
rootDefines[name] = exports[name];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const platformDefines = exports[platform];
|
|
63
|
+
// 该平台不支持
|
|
64
|
+
if (platformDefines === false) {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
if (platformDefines) {
|
|
68
|
+
rootDefines = (0, merge_1.recursive)(true, rootDefines, platformDefines);
|
|
69
|
+
}
|
|
70
|
+
const injects = {};
|
|
71
|
+
for (const key in rootDefines) {
|
|
72
|
+
Object.assign(injects, parseInject(source, 'uni', rootDefines[key]));
|
|
73
|
+
}
|
|
74
|
+
return injects;
|
|
75
|
+
}
|
|
76
|
+
exports.parseInjects = parseInjects;
|
|
77
|
+
function parseInject(source, globalObject, define) {
|
|
78
|
+
const injects = {};
|
|
79
|
+
if (define === false) {
|
|
80
|
+
}
|
|
81
|
+
else if (typeof define === 'string') {
|
|
82
|
+
// {'uni.getBatteryInfo' : '@dcloudio/uni-getbatteryinfo'}
|
|
83
|
+
injects[globalObject + '.' + define] = source;
|
|
84
|
+
}
|
|
85
|
+
else if (Array.isArray(define)) {
|
|
86
|
+
// {'uni.getBatteryInfo' : ['@dcloudio/uni-getbatteryinfo','getBatteryInfo]}
|
|
87
|
+
define.forEach((d) => {
|
|
88
|
+
injects[globalObject + '.' + d] = [source, d];
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const keys = Object.keys(define);
|
|
93
|
+
keys.forEach((d) => {
|
|
94
|
+
injects[globalObject + '.' + d] = [source, define[d]];
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return injects;
|
|
109
98
|
}
|
|
99
|
+
exports.parseInject = parseInject;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "2.0.1-alpha-
|
|
3
|
+
"version": "2.0.1-alpha-36720221017001",
|
|
4
4
|
"description": "uni-cli-shared",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"postcss-urlrewrite": "^0.2.2",
|
|
26
26
|
"strip-json-comments": "^2.0.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "7d7030aaaffab530253dc4cf02f87a13023c0d1f"
|
|
29
29
|
}
|