@dcloudio/uni-cli-shared 2.0.2-alpha-3071220230331001 → 2.0.2-alpha-3071320230407001

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.
@@ -12,9 +12,15 @@ function parseUniExtApis(vite = true) {
12
12
  if (!fs_extra_1.default.existsSync(uniModulesDir)) {
13
13
  return {};
14
14
  }
15
+ let platform = process.env.UNI_PLATFORM;
16
+ if (platform === 'h5') {
17
+ platform = 'web';
18
+ }
19
+ else if (platform === 'app-plus') {
20
+ platform = 'app';
21
+ }
15
22
  const injects = {};
16
23
  fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
17
- var _a, _b;
18
24
  // 必须以 uni- 开头
19
25
  if (!uniModuleDir.startsWith('uni-')) {
20
26
  return;
@@ -24,13 +30,25 @@ function parseUniExtApis(vite = true) {
24
30
  return;
25
31
  }
26
32
  try {
27
- 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'];
33
+ const exports = JSON.parse(fs_extra_1.default.readFileSync(pkgPath, 'utf8'))
34
+ ?.uni_modules?.['uni-ext-api'];
28
35
  if (exports) {
29
- Object.assign(injects, parseInjects(vite, process.env.UNI_PLATFORM === 'h5' ? 'web' : process.env.UNI_PLATFORM, `@/uni_modules/${uniModuleDir}`, exports));
36
+ const curInjects = parseInjects(vite, platform, `@/uni_modules/${uniModuleDir}`, exports);
37
+ if (platform === 'app') {
38
+ Object.keys(curInjects).forEach((name) => {
39
+ const options = curInjects[name];
40
+ // js 平台禁用了
41
+ if (Array.isArray(options) && options.length === 3) {
42
+ if (options[2] && options[2].js === false) {
43
+ delete curInjects[name];
44
+ }
45
+ }
46
+ });
47
+ }
48
+ Object.assign(injects, curInjects);
30
49
  }
31
50
  }
32
- catch (e) {
33
- }
51
+ catch (e) { }
34
52
  });
35
53
  return injects;
36
54
  }
@@ -73,12 +91,12 @@ function parseInjects(vite = true, platform, source, exports = {}) {
73
91
  }
74
92
  const injects = {};
75
93
  for (const key in rootDefines) {
76
- Object.assign(injects, parseInject(vite, source, 'uni', rootDefines[key]));
94
+ Object.assign(injects, parseInject(vite, platform, source, 'uni', rootDefines[key]));
77
95
  }
78
96
  return injects;
79
97
  }
80
98
  exports.parseInjects = parseInjects;
81
- function parseInject(vite = true, source, globalObject, define) {
99
+ function parseInject(vite = true, platform, source, globalObject, define) {
82
100
  const injects = {};
83
101
  if (define === false) {
84
102
  }
@@ -95,7 +113,24 @@ function parseInject(vite = true, source, globalObject, define) {
95
113
  else {
96
114
  const keys = Object.keys(define);
97
115
  keys.forEach((d) => {
98
- injects[globalObject + '.' + d] = [source, define[d]];
116
+ if (typeof define[d] === 'string') {
117
+ injects[globalObject + '.' + d] = [source, define[d]];
118
+ }
119
+ else {
120
+ const defineOptions = define[d];
121
+ if (defineOptions[platform] !== false) {
122
+ if (platform === 'app') {
123
+ injects[globalObject + '.' + d] = [
124
+ source,
125
+ defineOptions.name || d,
126
+ defineOptions.app,
127
+ ];
128
+ }
129
+ else {
130
+ injects[globalObject + '.' + d] = [source, defineOptions.name || d];
131
+ }
132
+ }
133
+ }
99
134
  });
100
135
  }
101
136
  return injects;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.2-alpha-3071220230331001",
3
+ "version": "2.0.2-alpha-3071320230407001",
4
4
  "description": "uni-cli-shared",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -26,5 +26,5 @@
26
26
  "postcss-urlrewrite": "^0.2.2",
27
27
  "strip-json-comments": "^2.0.1"
28
28
  },
29
- "gitHead": "7cb55f4f4d9c6e3e310110bf5a8e8eb6782dc793"
29
+ "gitHead": "98c4a8752da20d280e61cb2497544f4096893a10"
30
30
  }