@dcloudio/uni-cli-shared 2.0.2-3090620231104001 → 2.0.2-3090920231225001
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/cache.js +17 -26
- package/lib/uts/resolver.js +2 -2
- package/lib/{uni_modules → uts}/uni_modules.js +11 -1
- package/lib/uts/utils.js +7 -2
- package/lib/uts/uts-loader.js +11 -2
- package/lib/uts/uts.js +110 -17
- package/package.json +2 -2
package/lib/cache.js
CHANGED
|
@@ -79,7 +79,9 @@ function updateComponentJson (name, jsonObj, usingComponents = true, type = 'Com
|
|
|
79
79
|
if (type === 'Component') {
|
|
80
80
|
jsonObj.component = true
|
|
81
81
|
if (process.env.UNI_PLATFORM === 'mp-alipay') {
|
|
82
|
-
|
|
82
|
+
const manifestConfig = process.UNI_MANIFEST
|
|
83
|
+
const alipayConfig = manifestConfig['mp-alipay'] || {}
|
|
84
|
+
jsonObj.styleIsolation = alipayConfig.styleIsolation || 'apply-shared'
|
|
83
85
|
}
|
|
84
86
|
} else if (type === 'Page') {
|
|
85
87
|
if (process.env.UNI_PLATFORM === 'mp-baidu') {
|
|
@@ -160,39 +162,28 @@ function updateUsingComponents (name, usingComponents, type) {
|
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
const oldJsonStr = getJsonFile(name)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
165
|
+
const jsonObj = oldJsonStr ? JSON.parse(oldJsonStr) : {
|
|
166
|
+
usingComponents
|
|
167
|
+
}
|
|
168
|
+
if (type === 'Component') {
|
|
169
|
+
jsonObj.component = true
|
|
170
|
+
if (process.env.UNI_PLATFORM === 'mp-alipay') {
|
|
171
|
+
const manifestConfig = process.UNI_MANIFEST
|
|
172
|
+
const alipayConfig = manifestConfig['mp-alipay'] || {}
|
|
173
|
+
jsonObj.styleIsolation = alipayConfig.styleIsolation || 'apply-shared'
|
|
174
|
+
}
|
|
175
|
+
} else if (type === 'Page') {
|
|
176
|
+
if (process.env.UNI_PLATFORM === 'mp-baidu') {
|
|
166
177
|
jsonObj.component = true
|
|
167
|
-
if (process.env.UNI_PLATFORM === 'mp-alipay') {
|
|
168
|
-
jsonObj.styleIsolation = 'apply-shared'
|
|
169
|
-
}
|
|
170
|
-
} else if (type === 'Page') {
|
|
171
|
-
if (process.env.UNI_PLATFORM === 'mp-baidu') {
|
|
172
|
-
jsonObj.component = true
|
|
173
|
-
}
|
|
174
178
|
}
|
|
175
|
-
|
|
179
|
+
}
|
|
180
|
+
if (oldJsonStr) { // update
|
|
176
181
|
jsonObj.usingComponents = usingComponents
|
|
177
182
|
const newJsonStr = JSON.stringify(jsonObj, null, 2)
|
|
178
183
|
if (newJsonStr !== oldJsonStr) {
|
|
179
184
|
updateJsonFile(name, newJsonStr)
|
|
180
185
|
}
|
|
181
186
|
} else { // add
|
|
182
|
-
const jsonObj = {
|
|
183
|
-
usingComponents
|
|
184
|
-
}
|
|
185
|
-
if (type === 'Component') {
|
|
186
|
-
jsonObj.component = true
|
|
187
|
-
if (process.env.UNI_PLATFORM === 'mp-alipay') {
|
|
188
|
-
jsonObj.styleIsolation = 'apply-shared'
|
|
189
|
-
}
|
|
190
|
-
} else if (type === 'Page') {
|
|
191
|
-
if (process.env.UNI_PLATFORM === 'mp-baidu') {
|
|
192
|
-
jsonObj.component = true
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
187
|
updateJsonFile(name, jsonObj)
|
|
197
188
|
}
|
|
198
189
|
}
|
package/lib/uts/resolver.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
const {
|
|
3
|
-
|
|
3
|
+
resolveUTSModule
|
|
4
4
|
} = require('./uts')
|
|
5
5
|
class UTSResolverPlugin {
|
|
6
6
|
apply (resolver) {
|
|
@@ -12,7 +12,7 @@ class UTSResolverPlugin {
|
|
|
12
12
|
utsModulePath = path.resolve(request.path, request.request)
|
|
13
13
|
}
|
|
14
14
|
if (utsModulePath) {
|
|
15
|
-
const utsModule =
|
|
15
|
+
const utsModule = resolveUTSModule(utsModulePath)
|
|
16
16
|
if (utsModule) {
|
|
17
17
|
if (process.env.UNI_PLATFORM === 'app-plus') {
|
|
18
18
|
request.request = utsModule + '/package.json?uts-proxy'
|
|
@@ -63,6 +63,9 @@ exports.parseUniExtApis = parseUniExtApis;
|
|
|
63
63
|
* @returns
|
|
64
64
|
*/
|
|
65
65
|
function parseInjects(vite = true, platform, language, source, uniModuleRootDir, exports = {}) {
|
|
66
|
+
if (platform === 'app-plus') {
|
|
67
|
+
platform = 'app';
|
|
68
|
+
}
|
|
66
69
|
let rootDefines = {};
|
|
67
70
|
Object.keys(exports).forEach((name) => {
|
|
68
71
|
if (name.startsWith('uni')) {
|
|
@@ -71,10 +74,17 @@ function parseInjects(vite = true, platform, language, source, uniModuleRootDir,
|
|
|
71
74
|
});
|
|
72
75
|
const injects = {};
|
|
73
76
|
if (Object.keys(rootDefines).length) {
|
|
74
|
-
|
|
77
|
+
let hasPlatformFile = uniModuleRootDir
|
|
75
78
|
? fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'index.uts')) ||
|
|
76
79
|
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', platform))
|
|
77
80
|
: true;
|
|
81
|
+
if (!hasPlatformFile) {
|
|
82
|
+
if (platform === 'app') {
|
|
83
|
+
hasPlatformFile =
|
|
84
|
+
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-android')) ||
|
|
85
|
+
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-ios'));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
78
88
|
for (const key in rootDefines) {
|
|
79
89
|
Object.assign(injects, parseInject(vite, platform, language, source, 'uni', rootDefines[key], hasPlatformFile));
|
|
80
90
|
}
|
package/lib/uts/utils.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const {
|
|
4
|
-
normalizePath
|
|
4
|
+
normalizePath,
|
|
5
|
+
camelize,
|
|
6
|
+
capitalize
|
|
5
7
|
} = require('../util')
|
|
6
8
|
|
|
7
9
|
function hasProjectYarn (cwd) {
|
|
@@ -34,5 +36,8 @@ Please run \`${command}\` and try again.`
|
|
|
34
36
|
module.exports = {
|
|
35
37
|
version: require('../../package.json').version,
|
|
36
38
|
normalizePath,
|
|
37
|
-
installDepTips
|
|
39
|
+
installDepTips,
|
|
40
|
+
camelize,
|
|
41
|
+
capitalize,
|
|
42
|
+
isArray: Array.isArray
|
|
38
43
|
}
|
package/lib/uts/uts-loader.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
const path = require('path')
|
|
2
2
|
const {
|
|
3
|
-
resolveUTSCompiler
|
|
3
|
+
resolveUTSCompiler,
|
|
4
|
+
parseUniExtApiNamespacesOnce
|
|
4
5
|
} = require('./uts')
|
|
5
6
|
module.exports = function (content) {
|
|
6
7
|
const callback = this.async()
|
|
7
|
-
resolveUTSCompiler().compile(path.dirname(this.resourcePath)
|
|
8
|
+
resolveUTSCompiler().compile(path.dirname(this.resourcePath), {
|
|
9
|
+
isX: false,
|
|
10
|
+
isPlugin: true,
|
|
11
|
+
extApis: parseUniExtApiNamespacesOnce(
|
|
12
|
+
process.env.UNI_UTS_PLATFORM,
|
|
13
|
+
process.env.UNI_UTS_TARGET_LANGUAGE
|
|
14
|
+
),
|
|
15
|
+
sourceMap: process.env.NODE_ENV === 'development'
|
|
16
|
+
}).then(result => {
|
|
8
17
|
if (result) {
|
|
9
18
|
result.deps.forEach((dep) => {
|
|
10
19
|
this.addDependency(dep)
|
package/lib/uts/uts.js
CHANGED
|
@@ -3,24 +3,37 @@ 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.initUTSComponents = exports.resolveUTSCompiler = exports.
|
|
6
|
+
exports.parseUniExtApiNamespacesJsOnce = exports.parseUniExtApiNamespacesOnce = exports.parseSwiftPackageWithPluginId = exports.parseKotlinPackageWithPluginId = exports.initUTSComponents = exports.parseUTSComponent = exports.isUTSComponent = exports.resolveUTSCompiler = exports.resolveUTSModule = exports.resolveUTSAppModule = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
10
10
|
const hbx_1 = require("./hbx");
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
|
+
const uni_modules_1 = require("./uni_modules");
|
|
13
|
+
// 重要,该文件编译后的 js 需要同步到 vue2 编译器 uni-cli-shared/lib/uts
|
|
14
|
+
function once(fn, ctx = null) {
|
|
15
|
+
let res;
|
|
16
|
+
return ((...args) => {
|
|
17
|
+
if (fn) {
|
|
18
|
+
res = fn.apply(ctx, args);
|
|
19
|
+
fn = null;
|
|
20
|
+
}
|
|
21
|
+
return res;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
12
24
|
/**
|
|
13
25
|
* 解析 app 平台的 uts 插件,任意平台(android|ios)存在即可
|
|
14
26
|
* @param id
|
|
15
27
|
* @param importer
|
|
16
28
|
* @returns
|
|
17
29
|
*/
|
|
18
|
-
function
|
|
30
|
+
function resolveUTSAppModule(id, importer, includeUTSSDK = true) {
|
|
19
31
|
id = path_1.default.resolve(importer, id);
|
|
20
|
-
if (id.includes('
|
|
32
|
+
if (id.includes('uni_modules') || (includeUTSSDK && id.includes('utssdk'))) {
|
|
21
33
|
const parts = (0, utils_1.normalizePath)(id).split('/');
|
|
22
34
|
const parentDir = parts[parts.length - 2];
|
|
23
|
-
if (parentDir === 'uni_modules' ||
|
|
35
|
+
if (parentDir === 'uni_modules' ||
|
|
36
|
+
(includeUTSSDK && parentDir === 'utssdk')) {
|
|
24
37
|
const basedir = parentDir === 'uni_modules' ? 'utssdk' : '';
|
|
25
38
|
if (fs_1.default.existsSync(path_1.default.resolve(id, basedir, 'index.uts'))) {
|
|
26
39
|
return id;
|
|
@@ -29,32 +42,33 @@ function resolveUtsAppModule(id, importer) {
|
|
|
29
42
|
return path_1.default.resolve(id, basedir, p);
|
|
30
43
|
};
|
|
31
44
|
const extname = ['.uts'];
|
|
32
|
-
if (
|
|
45
|
+
if (resolveUTSFile(resolvePlatformDir('app-android'), extname)) {
|
|
33
46
|
return id;
|
|
34
47
|
}
|
|
35
|
-
if (
|
|
48
|
+
if (resolveUTSFile(resolvePlatformDir('app-ios'), extname)) {
|
|
36
49
|
return id;
|
|
37
50
|
}
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
53
|
}
|
|
41
|
-
exports.
|
|
54
|
+
exports.resolveUTSAppModule = resolveUTSAppModule;
|
|
42
55
|
// 仅限 root/uni_modules/test-plugin | root/utssdk/test-plugin 格式
|
|
43
|
-
function
|
|
56
|
+
function resolveUTSModule(id, importer, includeUTSSDK = true) {
|
|
44
57
|
if (process.env.UNI_PLATFORM === 'app' ||
|
|
45
58
|
process.env.UNI_PLATFORM === 'app-plus') {
|
|
46
|
-
return
|
|
59
|
+
return resolveUTSAppModule(id, importer);
|
|
47
60
|
}
|
|
48
61
|
id = path_1.default.resolve(importer, id);
|
|
49
|
-
if (id.includes('
|
|
62
|
+
if (id.includes('uni_modules') || (includeUTSSDK && id.includes('utssdk'))) {
|
|
50
63
|
const parts = (0, utils_1.normalizePath)(id).split('/');
|
|
51
64
|
const parentDir = parts[parts.length - 2];
|
|
52
|
-
if (parentDir === 'uni_modules' ||
|
|
65
|
+
if (parentDir === 'uni_modules' ||
|
|
66
|
+
(includeUTSSDK && parentDir === 'utssdk')) {
|
|
53
67
|
const basedir = parentDir === 'uni_modules' ? 'utssdk' : '';
|
|
54
68
|
const resolvePlatformDir = (p) => {
|
|
55
69
|
return path_1.default.resolve(id, basedir, p);
|
|
56
70
|
};
|
|
57
|
-
let index =
|
|
71
|
+
let index = resolveUTSFile(resolvePlatformDir(process.env.UNI_UTS_PLATFORM));
|
|
58
72
|
if (index) {
|
|
59
73
|
return index;
|
|
60
74
|
}
|
|
@@ -65,8 +79,8 @@ function resolveUtsModule(id, importer) {
|
|
|
65
79
|
}
|
|
66
80
|
}
|
|
67
81
|
}
|
|
68
|
-
exports.
|
|
69
|
-
function
|
|
82
|
+
exports.resolveUTSModule = resolveUTSModule;
|
|
83
|
+
function resolveUTSFile(dir, extensions = ['.uts', '.ts', '.js']) {
|
|
70
84
|
for (let i = 0; i < extensions.length; i++) {
|
|
71
85
|
const indexFile = path_1.default.join(dir, 'index' + extensions[i]);
|
|
72
86
|
if (fs_1.default.existsSync(indexFile)) {
|
|
@@ -100,16 +114,38 @@ function resolveUTSCompiler() {
|
|
|
100
114
|
return require(compilerPath);
|
|
101
115
|
}
|
|
102
116
|
exports.resolveUTSCompiler = resolveUTSCompiler;
|
|
117
|
+
const utsComponents = new Map();
|
|
118
|
+
function isUTSComponent(name) {
|
|
119
|
+
return utsComponents.has(name);
|
|
120
|
+
}
|
|
121
|
+
exports.isUTSComponent = isUTSComponent;
|
|
122
|
+
function parseUTSComponent(name, type) {
|
|
123
|
+
const meta = utsComponents.get(name);
|
|
124
|
+
if (meta) {
|
|
125
|
+
const namespace = meta[type === 'swift' ? 'swiftModule' : 'kotlinPackage'] || '';
|
|
126
|
+
const className = (0, utils_1.capitalize)((0, utils_1.camelize)(name)) + 'Component';
|
|
127
|
+
return {
|
|
128
|
+
className,
|
|
129
|
+
namespace,
|
|
130
|
+
source: meta.source,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.parseUTSComponent = parseUTSComponent;
|
|
103
135
|
function initUTSComponents(inputDir, platform) {
|
|
136
|
+
utsComponents.clear();
|
|
104
137
|
const components = [];
|
|
105
138
|
if (platform !== 'app' && platform !== 'app-plus') {
|
|
106
139
|
return components;
|
|
107
140
|
}
|
|
108
|
-
const easycomsObj =
|
|
141
|
+
const easycomsObj = {};
|
|
109
142
|
const dirs = resolveUTSComponentDirs(inputDir);
|
|
110
143
|
dirs.forEach((dir) => {
|
|
111
144
|
const is_uni_modules_utssdk = dir.endsWith('utssdk');
|
|
112
145
|
const is_ussdk = !is_uni_modules_utssdk && path_1.default.dirname(dir).endsWith('utssdk');
|
|
146
|
+
const pluginId = is_uni_modules_utssdk
|
|
147
|
+
? path_1.default.basename(path_1.default.dirname(dir))
|
|
148
|
+
: path_1.default.basename(dir);
|
|
113
149
|
if (is_uni_modules_utssdk || is_ussdk) {
|
|
114
150
|
fast_glob_1.default
|
|
115
151
|
.sync('**/*.vue', {
|
|
@@ -125,15 +161,27 @@ function initUTSComponents(inputDir, platform) {
|
|
|
125
161
|
}
|
|
126
162
|
if (name) {
|
|
127
163
|
const importDir = (0, utils_1.normalizePath)(is_uni_modules_utssdk ? path_1.default.dirname(dir) : dir);
|
|
128
|
-
easycomsObj[`^${name}$`] =
|
|
164
|
+
easycomsObj[`^${name}$`] = {
|
|
165
|
+
source: `${importDir}?uts-proxy`,
|
|
166
|
+
kotlinPackage: parseKotlinPackageWithPluginId(pluginId, is_uni_modules_utssdk),
|
|
167
|
+
swiftModule: parseSwiftPackageWithPluginId(pluginId, is_uni_modules_utssdk),
|
|
168
|
+
};
|
|
129
169
|
}
|
|
130
170
|
});
|
|
131
171
|
}
|
|
132
172
|
});
|
|
133
173
|
Object.keys(easycomsObj).forEach((name) => {
|
|
174
|
+
const obj = easycomsObj[name];
|
|
175
|
+
const componentName = name.slice(1, -1);
|
|
134
176
|
components.push({
|
|
177
|
+
name: componentName,
|
|
135
178
|
pattern: new RegExp(name),
|
|
136
|
-
replacement:
|
|
179
|
+
replacement: obj.source,
|
|
180
|
+
});
|
|
181
|
+
utsComponents.set(componentName, {
|
|
182
|
+
source: obj.source,
|
|
183
|
+
kotlinPackage: obj.kotlinPackage,
|
|
184
|
+
swiftModule: obj.swiftModule,
|
|
137
185
|
});
|
|
138
186
|
});
|
|
139
187
|
return components;
|
|
@@ -162,3 +210,48 @@ function parseVueComponentName(file) {
|
|
|
162
210
|
return matches[1];
|
|
163
211
|
}
|
|
164
212
|
}
|
|
213
|
+
function prefix(id) {
|
|
214
|
+
if (process.env.UNI_UTS_MODULE_PREFIX &&
|
|
215
|
+
!id.startsWith(process.env.UNI_UTS_MODULE_PREFIX)) {
|
|
216
|
+
return process.env.UNI_UTS_MODULE_PREFIX + '-' + id;
|
|
217
|
+
}
|
|
218
|
+
return id;
|
|
219
|
+
}
|
|
220
|
+
function parseKotlinPackageWithPluginId(id, is_uni_modules) {
|
|
221
|
+
return 'uts.sdk.' + (is_uni_modules ? 'modules.' : '') + (0, utils_1.camelize)(prefix(id));
|
|
222
|
+
}
|
|
223
|
+
exports.parseKotlinPackageWithPluginId = parseKotlinPackageWithPluginId;
|
|
224
|
+
function parseSwiftPackageWithPluginId(id, is_uni_modules) {
|
|
225
|
+
return ('UTSSDK' +
|
|
226
|
+
(is_uni_modules ? 'Modules' : '') +
|
|
227
|
+
(0, utils_1.capitalize)((0, utils_1.camelize)(prefix(id))));
|
|
228
|
+
}
|
|
229
|
+
exports.parseSwiftPackageWithPluginId = parseSwiftPackageWithPluginId;
|
|
230
|
+
exports.parseUniExtApiNamespacesOnce = once((platform, language) => {
|
|
231
|
+
const extApis = (0, exports.parseUniExtApiNamespacesJsOnce)(platform, language);
|
|
232
|
+
const namespaces = {};
|
|
233
|
+
Object.keys(extApis).forEach((name) => {
|
|
234
|
+
const options = extApis[name];
|
|
235
|
+
let source = options[0];
|
|
236
|
+
const pluginId = path_1.default.basename(options[0]);
|
|
237
|
+
if (language === 'kotlin') {
|
|
238
|
+
source = parseKotlinPackageWithPluginId(pluginId, true);
|
|
239
|
+
}
|
|
240
|
+
else if (language === 'swift') {
|
|
241
|
+
source = parseSwiftPackageWithPluginId(pluginId, true);
|
|
242
|
+
}
|
|
243
|
+
namespaces[name] = [source, options[1]];
|
|
244
|
+
});
|
|
245
|
+
return namespaces;
|
|
246
|
+
});
|
|
247
|
+
exports.parseUniExtApiNamespacesJsOnce = once((platform, language) => {
|
|
248
|
+
const extApis = (0, uni_modules_1.parseUniExtApis)(true, platform, language);
|
|
249
|
+
const namespaces = {};
|
|
250
|
+
Object.keys(extApis).forEach((name) => {
|
|
251
|
+
const options = extApis[name];
|
|
252
|
+
if ((0, utils_1.isArray)(options) && options.length >= 2) {
|
|
253
|
+
namespaces[name.replace('uni.', '')] = [options[0], options[1]];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
return namespaces;
|
|
257
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "2.0.2-
|
|
3
|
+
"version": "2.0.2-3090920231225001",
|
|
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": "
|
|
29
|
+
"gitHead": "930c6d04bc26067ed5f7b8a1e782ad43760509fd"
|
|
30
30
|
}
|