@dcloudio/uni-cli-shared 2.0.2-alpha-3080420230602001 → 2.0.2-alpha-3080520230615001

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.
@@ -3,29 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseInject = exports.parseInjects = exports.parseUniExtApis = void 0;
6
+ exports.parseInjects = exports.parseUniExtApis = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const merge_1 = require("merge");
10
- function parseUniExtApis(vite = true) {
9
+ function parseUniExtApis(vite = true, platform, language = 'javascript') {
11
10
  const uniModulesDir = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules');
12
11
  if (!fs_extra_1.default.existsSync(uniModulesDir)) {
13
12
  return {};
14
13
  }
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
- }
22
14
  const injects = {};
23
15
  fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
24
16
  // 必须以 uni- 开头
25
17
  if (!uniModuleDir.startsWith('uni-')) {
26
18
  return;
27
19
  }
28
- const pkgPath = path_1.default.resolve(uniModulesDir, uniModuleDir, 'package.json');
20
+ const uniModuleRootDir = path_1.default.resolve(uniModulesDir, uniModuleDir);
21
+ const pkgPath = path_1.default.resolve(uniModuleRootDir, 'package.json');
29
22
  if (!fs_extra_1.default.existsSync(pkgPath)) {
30
23
  return;
31
24
  }
@@ -33,18 +26,7 @@ function parseUniExtApis(vite = true) {
33
26
  const exports = JSON.parse(fs_extra_1.default.readFileSync(pkgPath, 'utf8'))
34
27
  ?.uni_modules?.['uni-ext-api'];
35
28
  if (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
- }
29
+ const curInjects = parseInjects(vite, platform, language, `@/uni_modules/${uniModuleDir}`, uniModuleRootDir, exports);
48
30
  Object.assign(injects, curInjects);
49
31
  }
50
32
  }
@@ -74,41 +56,43 @@ exports.parseUniExtApis = parseUniExtApis;
74
56
  * @param define
75
57
  * @returns
76
58
  */
77
- function parseInjects(vite = true, platform, source, exports = {}) {
59
+ function parseInjects(vite = true, platform, language, source, uniModuleRootDir, exports = {}) {
78
60
  let rootDefines = {};
79
61
  Object.keys(exports).forEach((name) => {
80
62
  if (name.startsWith('uni')) {
81
63
  rootDefines[name] = exports[name];
82
64
  }
83
65
  });
84
- const platformDefines = exports[platform];
85
- // 该平台不支持
86
- if (platformDefines === false) {
87
- return {};
88
- }
89
- if (platformDefines) {
90
- rootDefines = (0, merge_1.recursive)(true, rootDefines, platformDefines);
91
- }
92
66
  const injects = {};
93
- for (const key in rootDefines) {
94
- Object.assign(injects, parseInject(vite, platform, source, 'uni', rootDefines[key]));
67
+ if (Object.keys(rootDefines).length) {
68
+ const hasPlatformFile = uniModuleRootDir
69
+ ? fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'index.uts')) ||
70
+ fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', platform))
71
+ : true;
72
+ for (const key in rootDefines) {
73
+ Object.assign(injects, parseInject(vite, platform, language, source, 'uni', rootDefines[key], hasPlatformFile));
74
+ }
95
75
  }
96
76
  return injects;
97
77
  }
98
78
  exports.parseInjects = parseInjects;
99
- function parseInject(vite = true, platform, source, globalObject, define) {
79
+ function parseInject(vite = true, platform, language, source, globalObject, define, hasPlatformFile) {
100
80
  const injects = {};
101
81
  if (define === false) {
102
82
  }
103
83
  else if (typeof define === 'string') {
104
84
  // {'uni.getBatteryInfo' : '@dcloudio/uni-getbatteryinfo'}
105
- injects[globalObject + '.' + define] = vite ? source : [source, 'default'];
85
+ if (hasPlatformFile) {
86
+ injects[globalObject + '.' + define] = vite ? source : [source, 'default'];
87
+ }
106
88
  }
107
89
  else if (Array.isArray(define)) {
108
90
  // {'uni.getBatteryInfo' : ['@dcloudio/uni-getbatteryinfo','getBatteryInfo]}
109
- define.forEach((d) => {
110
- injects[globalObject + '.' + d] = [source, d];
111
- });
91
+ if (hasPlatformFile) {
92
+ define.forEach((d) => {
93
+ injects[globalObject + '.' + d] = [source, d];
94
+ });
95
+ }
112
96
  }
113
97
  else {
114
98
  const keys = Object.keys(define);
@@ -118,21 +102,56 @@ function parseInject(vite = true, platform, source, globalObject, define) {
118
102
  }
119
103
  else {
120
104
  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 {
105
+ const p = platform === 'app-android' || platform === 'app-ios'
106
+ ? 'app'
107
+ : platform;
108
+ if (!(p in defineOptions)) {
109
+ if (hasPlatformFile) {
130
110
  injects[globalObject + '.' + d] = [source, defineOptions.name || d];
131
111
  }
132
112
  }
113
+ else {
114
+ if (defineOptions[p] !== false) {
115
+ if (p === 'app') {
116
+ const appOptions = defineOptions.app;
117
+ if (isPlainObject(appOptions)) {
118
+ if (language === 'javascript') {
119
+ if (appOptions.js === false) {
120
+ return;
121
+ }
122
+ }
123
+ else if (language === 'kotlin') {
124
+ if (appOptions.kotlin === false) {
125
+ return;
126
+ }
127
+ }
128
+ else if (language === 'swift') {
129
+ if (appOptions.swift === false) {
130
+ return;
131
+ }
132
+ }
133
+ }
134
+ injects[globalObject + '.' + d] = [
135
+ source,
136
+ defineOptions.name || d,
137
+ defineOptions.app,
138
+ ];
139
+ }
140
+ else {
141
+ injects[globalObject + '.' + d] = [
142
+ source,
143
+ defineOptions.name || d,
144
+ ];
145
+ }
146
+ }
147
+ }
133
148
  }
134
149
  });
135
150
  }
136
151
  return injects;
137
152
  }
138
- exports.parseInject = parseInject;
153
+ const objectToString = Object.prototype.toString;
154
+ const toTypeString = (value) => objectToString.call(value);
155
+ function isPlainObject(val) {
156
+ return toTypeString(val) === '[object Object]';
157
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.2-alpha-3080420230602001",
3
+ "version": "2.0.2-alpha-3080520230615001",
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": "a666ad999f9275f8614f6f0974c2b14c23f85098"
29
+ "gitHead": "c9d18e44da2ea83e0ca9ed05048bfbad49f0de29"
30
30
  }