@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 CHANGED
@@ -112,6 +112,5 @@ module.exports = {
112
112
  getPlatformGlobal,
113
113
  getPlatformStat,
114
114
  getPlatformPush,
115
- getPlatformUniCloud,
116
- uniModulesLoader: normalizePath(require.resolve('./uni_modules-loader'))
115
+ getPlatformUniCloud
117
116
  }
@@ -1,65 +1,36 @@
1
- 'use strict'
1
+ "use strict";
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { default: mod }
4
- }
5
- Object.defineProperty(exports, '__esModule', { value: true })
6
- exports.parseDefines = exports.parseExports = exports.genUniModulesExports = 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 genUniModulesExports () {
11
- const uniModulesDir = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules')
12
- if (!fs_extra_1.default.existsSync(uniModulesDir)) {
13
- return ''
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
- const platformDefines = exports[platform]
45
- // 该平台不支持
46
- if (platformDefines === false) {
47
- return [[], []]
48
- }
49
- return parseDefines(source, (0, merge_1.recursive)(true, rootDefines, platformDefines))
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.parseExports = parseExports
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 parseDefine (source, globalObject, define) {
85
- const importCodes = []
86
- const assignCodes = []
87
- if (typeof define === 'string') {
88
- importCodes.push(`import ${define} from '${source}'`)
89
- assignCodes.push(`${globalObject}.${define} = ${define}`)
90
- } else if (Array.isArray(define)) {
91
- importCodes.push(`import { ${define.join(', ')} } from '${source}'`)
92
- define.forEach((d) => {
93
- assignCodes.push(`${globalObject}.${d} = ${d}`)
94
- })
95
- } else {
96
- const keys = Object.keys(define)
97
- const specifiers = []
98
- keys.forEach((d) => {
99
- if (d !== define[d]) {
100
- specifiers.push(`${define[d]} as ${d}`)
101
- } else {
102
- specifiers.push(d)
103
- }
104
- assignCodes.push(`${globalObject}.${d} = ${d}`)
105
- })
106
- importCodes.push(`import { ${specifiers.join(', ')} } from '${source}'`)
107
- }
108
- return [importCodes, assignCodes]
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-36720221014001",
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": "d30323ee8aad81efa6ad05e25053f36257f4f261"
28
+ "gitHead": "7d7030aaaffab530253dc4cf02f87a13023c0d1f"
29
29
  }
@@ -1,8 +0,0 @@
1
- const {
2
- genUniModulesExports
3
- } = require('./uni_modules/uni_modules')
4
-
5
- module.exports = function () {
6
- this.cacheable && this.cacheable()
7
- return genUniModulesExports()
8
- }