@dcloudio/uni-uts-v1 3.0.0-3061320221209001
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/dist/code.d.ts +9 -0
- package/dist/code.js +314 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +268 -0
- package/dist/kotlin.d.ts +13 -0
- package/dist/kotlin.js +324 -0
- package/dist/legacy/index.d.ts +23 -0
- package/dist/legacy/index.js +117 -0
- package/dist/manifest/dex.d.ts +2 -0
- package/dist/manifest/dex.js +26 -0
- package/dist/manifest/index.d.ts +8 -0
- package/dist/manifest/index.js +118 -0
- package/dist/manifest/manifest.d.ts +44 -0
- package/dist/manifest/manifest.js +176 -0
- package/dist/manifest/sourceMap.d.ts +17 -0
- package/dist/manifest/sourceMap.js +49 -0
- package/dist/manifest/utils.d.ts +18 -0
- package/dist/manifest/utils.js +15 -0
- package/dist/shared.d.ts +8 -0
- package/dist/shared.js +65 -0
- package/dist/sourceMap.d.ts +30 -0
- package/dist/sourceMap.js +146 -0
- package/dist/stacktrace.d.ts +11 -0
- package/dist/stacktrace.js +94 -0
- package/dist/swift.d.ts +13 -0
- package/dist/swift.js +183 -0
- package/dist/utils.d.ts +38 -0
- package/dist/utils.js +148 -0
- package/package.json +35 -0
package/dist/code.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface GenProxyCodeOptions {
|
|
2
|
+
is_uni_modules: boolean;
|
|
3
|
+
name: string;
|
|
4
|
+
namespace: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function genProxyCode(module: string, options: GenProxyCodeOptions): Promise<string>;
|
|
7
|
+
export declare function resolveRootIndex(module: string, options: GenProxyCodeOptions): string | false;
|
|
8
|
+
export declare function resolvePlatformIndex(platform: 'app-android' | 'app-ios', module: string, options: GenProxyCodeOptions): string | false;
|
|
9
|
+
export {};
|
package/dist/code.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict";
|
|
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.resolvePlatformIndex = exports.resolveRootIndex = exports.genProxyCode = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const shared_1 = require("./shared");
|
|
11
|
+
async function genProxyCode(module, options) {
|
|
12
|
+
const { name, is_uni_modules } = options;
|
|
13
|
+
return `
|
|
14
|
+
import { initUtsProxyClass, initUtsProxyFunction, initUtsPackageName, initUtsIndexClassName, initUtsClassName } from '@dcloudio/uni-app'
|
|
15
|
+
const name = '${name}'
|
|
16
|
+
const errMsg = \`${utils_1.ERR_MSG_PLACEHOLDER}\`
|
|
17
|
+
const is_uni_modules = ${is_uni_modules}
|
|
18
|
+
const pkg = initUtsPackageName(name, is_uni_modules)
|
|
19
|
+
const cls = initUtsIndexClassName(name, is_uni_modules)
|
|
20
|
+
${genModuleCode(await parseModuleDecls(module, options))}
|
|
21
|
+
`;
|
|
22
|
+
}
|
|
23
|
+
exports.genProxyCode = genProxyCode;
|
|
24
|
+
function resolveRootIndex(module, options) {
|
|
25
|
+
const filename = path_1.default.resolve(module, options.is_uni_modules ? 'utssdk' : '', 'index.uts');
|
|
26
|
+
return fs_1.default.existsSync(filename) && filename;
|
|
27
|
+
}
|
|
28
|
+
exports.resolveRootIndex = resolveRootIndex;
|
|
29
|
+
function resolvePlatformIndex(platform, module, options) {
|
|
30
|
+
const filename = path_1.default.resolve(module, options.is_uni_modules ? 'utssdk' : '', platform, 'index.uts');
|
|
31
|
+
return fs_1.default.existsSync(filename) && filename;
|
|
32
|
+
}
|
|
33
|
+
exports.resolvePlatformIndex = resolvePlatformIndex;
|
|
34
|
+
function genModuleCode(decls) {
|
|
35
|
+
const codes = [];
|
|
36
|
+
decls.forEach((decl) => {
|
|
37
|
+
if (decl.type === 'Class') {
|
|
38
|
+
if (decl.isDefault) {
|
|
39
|
+
codes.push(`export default initUtsProxyClass(Object.assign({ errMsg, package: pkg, class: initUtsClassName(name, '${decl.cls}', is_uni_modules) }, ${JSON.stringify(decl.options)} ))`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
codes.push(`export const ${decl.cls} = initUtsProxyClass(Object.assign({ errMsg, package: pkg, class: initUtsClassName(name, '${decl.cls}', is_uni_modules) }, ${JSON.stringify(decl.options)} ))`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (decl.type === 'FunctionDeclaration') {
|
|
46
|
+
if (decl.isDefault) {
|
|
47
|
+
codes.push(`export default initUtsProxyFunction(${decl.async}, { errMsg, main: true, package: pkg, class: cls, name: '${decl.method}', params: ${JSON.stringify(decl.params)}})`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
codes.push(`export const ${decl.method} = initUtsProxyFunction(${decl.async}, { errMsg, main: true, package: pkg, class: cls, name: '${decl.method}', params: ${JSON.stringify(decl.params)}})`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (decl.type === 'VariableDeclaration') {
|
|
54
|
+
codes.push(`export ${decl.kind} ${decl.declarations
|
|
55
|
+
.map((d) => `${d.id.value} = ${genInitCode(d.init)}`)
|
|
56
|
+
.join(', ')}`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return codes.join(`\n`);
|
|
60
|
+
}
|
|
61
|
+
async function parseModuleDecls(module, options) {
|
|
62
|
+
// 优先合并 ios + android,如果没有,查找根目录 index.uts
|
|
63
|
+
const iosDecls = await parseFile(resolvePlatformIndex('app-ios', module, options), options);
|
|
64
|
+
const androidDecls = await parseFile(resolvePlatformIndex('app-android', module, options), options);
|
|
65
|
+
// 优先使用 app-ios,因为 app-ios 平台函数类型需要正确的参数列表
|
|
66
|
+
const decls = mergeDecls(androidDecls, iosDecls);
|
|
67
|
+
// 如果没有平台特有,查找 root index.uts
|
|
68
|
+
if (!decls.length) {
|
|
69
|
+
return await parseFile(resolveRootIndex(module, options), options);
|
|
70
|
+
}
|
|
71
|
+
return decls;
|
|
72
|
+
}
|
|
73
|
+
function mergeDecls(from, to) {
|
|
74
|
+
from.forEach((item) => {
|
|
75
|
+
if (item.type === 'Class') {
|
|
76
|
+
if (!to.find((toItem) => toItem.type === 'Class' && toItem.cls === item.cls)) {
|
|
77
|
+
to.push(item);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (item.type === 'FunctionDeclaration') {
|
|
81
|
+
if (!to.find((toItem) => toItem.type === 'FunctionDeclaration' &&
|
|
82
|
+
toItem.method === item.method)) {
|
|
83
|
+
to.push(item);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (item.type === 'VariableDeclaration' &&
|
|
87
|
+
item.declarations.length === 1) {
|
|
88
|
+
if (!to.find((toItem) => {
|
|
89
|
+
if (toItem.type === 'VariableDeclaration' &&
|
|
90
|
+
toItem.declarations.length === 1) {
|
|
91
|
+
const toDecl = toItem.declarations[0].id;
|
|
92
|
+
const decl = item.declarations[0].id;
|
|
93
|
+
return (toDecl.type === 'Identifier' &&
|
|
94
|
+
decl.type === 'Identifier' &&
|
|
95
|
+
toDecl.value === decl.value);
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
})) {
|
|
99
|
+
to.push(item);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return to;
|
|
104
|
+
}
|
|
105
|
+
async function parseFile(filename, options) {
|
|
106
|
+
if (filename) {
|
|
107
|
+
return parseCode(fs_1.default.readFileSync(filename, 'utf8'), options.namespace);
|
|
108
|
+
}
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
async function parseCode(code, namespace) {
|
|
112
|
+
// 懒加载 uts 编译器
|
|
113
|
+
// eslint-disable-next-line no-restricted-globals
|
|
114
|
+
const { parse } = require('@dcloudio/uts');
|
|
115
|
+
const ast = await parse(code, { noColor: (0, shared_1.isInHBuilderX)() });
|
|
116
|
+
return parseAst(ast, (0, utils_1.createResolveTypeReferenceName)(namespace, ast));
|
|
117
|
+
}
|
|
118
|
+
function parseAst({ body }, resolveTypeReferenceName) {
|
|
119
|
+
const decls = [];
|
|
120
|
+
body.forEach((item) => {
|
|
121
|
+
if (item.type === 'ExportDeclaration') {
|
|
122
|
+
const decl = item.declaration;
|
|
123
|
+
switch (decl.type) {
|
|
124
|
+
case 'FunctionDeclaration':
|
|
125
|
+
decls.push(genFunctionDeclaration(decl, resolveTypeReferenceName, false));
|
|
126
|
+
break;
|
|
127
|
+
case 'ClassDeclaration':
|
|
128
|
+
decls.push(genClassDeclaration(decl, resolveTypeReferenceName, false));
|
|
129
|
+
break;
|
|
130
|
+
case 'VariableDeclaration':
|
|
131
|
+
const varDecl = genVariableDeclaration(decl);
|
|
132
|
+
if (varDecl) {
|
|
133
|
+
decls.push(varDecl);
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else if (item.type === 'ExportDefaultDeclaration') {
|
|
139
|
+
const decl = item.decl;
|
|
140
|
+
if (decl.type === 'ClassExpression') {
|
|
141
|
+
if (decl.identifier) {
|
|
142
|
+
// export default class test{}
|
|
143
|
+
decls.push(genClassDeclaration(decl, resolveTypeReferenceName, true));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else if (decl.type === 'FunctionExpression') {
|
|
147
|
+
if (decl.identifier) {
|
|
148
|
+
decls.push(genFunctionDeclaration(decl, resolveTypeReferenceName, true));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return decls;
|
|
154
|
+
}
|
|
155
|
+
function isReturnPromise(anno) {
|
|
156
|
+
if (!anno) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
const { typeAnnotation } = anno;
|
|
160
|
+
return (typeAnnotation.type === 'TsTypeReference' &&
|
|
161
|
+
typeAnnotation.typeName.type === 'Identifier' &&
|
|
162
|
+
typeAnnotation.typeName.value === 'Promise');
|
|
163
|
+
}
|
|
164
|
+
function genProxyFunction(method, async, params, isDefault = false) {
|
|
165
|
+
return { type: 'FunctionDeclaration', method, async, params, isDefault };
|
|
166
|
+
}
|
|
167
|
+
function genProxyClass(cls, options, isDefault = false) {
|
|
168
|
+
return { type: 'Class', cls, options, isDefault };
|
|
169
|
+
}
|
|
170
|
+
function resolveIdentifierDefaultValue(ident) {
|
|
171
|
+
if (ident.type === 'NullLiteral') {
|
|
172
|
+
return 'UTSNull';
|
|
173
|
+
}
|
|
174
|
+
else if (ident.type === 'StringLiteral' ||
|
|
175
|
+
ident.type === 'NumericLiteral' ||
|
|
176
|
+
ident.type === 'BooleanLiteral') {
|
|
177
|
+
return ident.value;
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
function resolveIdentifierType(ident, resolveTypeReferenceName) {
|
|
182
|
+
if (ident.typeAnnotation) {
|
|
183
|
+
const { typeAnnotation } = ident.typeAnnotation;
|
|
184
|
+
if (typeAnnotation.type === 'TsKeywordType') {
|
|
185
|
+
return typeAnnotation.kind;
|
|
186
|
+
}
|
|
187
|
+
else if (typeAnnotation.type === 'TsFunctionType') {
|
|
188
|
+
return 'UTSCallback';
|
|
189
|
+
}
|
|
190
|
+
else if (typeAnnotation.type === 'TsTypeReference' &&
|
|
191
|
+
typeAnnotation.typeName.type === 'Identifier') {
|
|
192
|
+
return resolveTypeReferenceName(typeAnnotation.typeName.value);
|
|
193
|
+
}
|
|
194
|
+
else if (typeAnnotation.type === 'TsUnionType') {
|
|
195
|
+
if (typeAnnotation.types.length === 2) {
|
|
196
|
+
const [type1, type2] = typeAnnotation.types;
|
|
197
|
+
if (type1.type === 'TsKeywordType' && type1.kind === 'null') {
|
|
198
|
+
if (type2.type === 'TsParenthesizedType' &&
|
|
199
|
+
type2.typeAnnotation.type === 'TsFunctionType') {
|
|
200
|
+
return 'UTSCallback';
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (type2.type === 'TsKeywordType' && type2.kind === 'null') {
|
|
204
|
+
if (type1.type === 'TsParenthesizedType' &&
|
|
205
|
+
type1.typeAnnotation.type === 'TsFunctionType') {
|
|
206
|
+
return 'UTSCallback';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return '';
|
|
213
|
+
}
|
|
214
|
+
function resolveFunctionParams(params, resolveTypeReferenceName) {
|
|
215
|
+
const result = [];
|
|
216
|
+
params.forEach(({ pat }) => {
|
|
217
|
+
if (pat.type === 'Identifier') {
|
|
218
|
+
result.push({
|
|
219
|
+
name: pat.value,
|
|
220
|
+
type: resolveIdentifierType(pat, resolveTypeReferenceName),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
else if (pat.type === 'AssignmentPattern') {
|
|
224
|
+
if (pat.left.type === 'Identifier') {
|
|
225
|
+
const param = {
|
|
226
|
+
name: pat.left.value,
|
|
227
|
+
type: resolveIdentifierType(pat.left, resolveTypeReferenceName),
|
|
228
|
+
};
|
|
229
|
+
const defaultValue = resolveIdentifierDefaultValue(pat.right);
|
|
230
|
+
if (defaultValue !== null) {
|
|
231
|
+
param.default = defaultValue;
|
|
232
|
+
}
|
|
233
|
+
result.push(param);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
result.push({ name: '', type: '' });
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
function genFunctionDeclaration(decl, resolveTypeReferenceName, isDefault = false) {
|
|
243
|
+
return genProxyFunction(decl.identifier.value, decl.async || isReturnPromise(decl.returnType), resolveFunctionParams(decl.params, resolveTypeReferenceName), isDefault);
|
|
244
|
+
}
|
|
245
|
+
function genClassDeclaration(decl, resolveTypeReferenceName, isDefault = false) {
|
|
246
|
+
const cls = decl.identifier.value;
|
|
247
|
+
const constructor = { params: [] };
|
|
248
|
+
const methods = {};
|
|
249
|
+
const staticMethods = {};
|
|
250
|
+
const props = [];
|
|
251
|
+
const staticProps = [];
|
|
252
|
+
decl.body.forEach((item) => {
|
|
253
|
+
if (item.type === 'Constructor') {
|
|
254
|
+
constructor.params = resolveFunctionParams(item.params, resolveTypeReferenceName);
|
|
255
|
+
}
|
|
256
|
+
else if (item.type === 'ClassMethod') {
|
|
257
|
+
if (item.key.type === 'Identifier') {
|
|
258
|
+
const name = item.key.value;
|
|
259
|
+
const value = {
|
|
260
|
+
async: item.function.async || isReturnPromise(item.function.returnType),
|
|
261
|
+
params: resolveFunctionParams(item.function.params, resolveTypeReferenceName),
|
|
262
|
+
};
|
|
263
|
+
if (item.isStatic) {
|
|
264
|
+
staticMethods[name] = value;
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
methods[name] = value;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
else if (item.type === 'ClassProperty') {
|
|
272
|
+
if (item.key.type === 'Identifier') {
|
|
273
|
+
if (item.isStatic) {
|
|
274
|
+
staticProps.push(item.key.value);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
props.push(item.key.value);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
return genProxyClass(cls, { constructor, methods, staticMethods, props, staticProps }, isDefault);
|
|
283
|
+
}
|
|
284
|
+
function genInitCode(expr) {
|
|
285
|
+
switch (expr.type) {
|
|
286
|
+
case 'BooleanLiteral':
|
|
287
|
+
return expr.value + '';
|
|
288
|
+
case 'NumericLiteral':
|
|
289
|
+
return expr.value + '';
|
|
290
|
+
case 'StringLiteral':
|
|
291
|
+
return expr.value;
|
|
292
|
+
}
|
|
293
|
+
return '';
|
|
294
|
+
}
|
|
295
|
+
function genVariableDeclaration(decl) {
|
|
296
|
+
// 目前仅支持 const 的 boolean,number,string
|
|
297
|
+
const lits = ['BooleanLiteral', 'NumericLiteral', 'StringLiteral'];
|
|
298
|
+
if (decl.kind === 'const' &&
|
|
299
|
+
!decl.declarations.find((d) => {
|
|
300
|
+
if (d.id.type !== 'Identifier') {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
if (!d.init) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
const type = d.init.type;
|
|
307
|
+
if (!lits.includes(type)) {
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
return false;
|
|
311
|
+
})) {
|
|
312
|
+
return decl;
|
|
313
|
+
}
|
|
314
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { generateCodeFrameWithKotlinStacktrace, generateCodeFrameWithSwiftStacktrace } from './legacy';
|
|
2
|
+
export declare const sourcemap: {
|
|
3
|
+
generateCodeFrameWithKotlinStacktrace: typeof generateCodeFrameWithKotlinStacktrace;
|
|
4
|
+
generateCodeFrameWithSwiftStacktrace: typeof generateCodeFrameWithSwiftStacktrace;
|
|
5
|
+
};
|
|
6
|
+
export * from './sourceMap';
|
|
7
|
+
export { compile as toKotlin } from './kotlin';
|
|
8
|
+
export { compile as toSwift } from './swift';
|
|
9
|
+
export declare function compile(pluginDir: string): Promise<{
|
|
10
|
+
code: string;
|
|
11
|
+
deps: string[];
|
|
12
|
+
} | undefined>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.compile = exports.toSwift = exports.toKotlin = exports.sourcemap = void 0;
|
|
18
|
+
const shared_1 = require("@vue/shared");
|
|
19
|
+
const path_1 = require("path");
|
|
20
|
+
const kotlin_1 = require("./kotlin");
|
|
21
|
+
const swift_1 = require("./swift");
|
|
22
|
+
const code_1 = require("./code");
|
|
23
|
+
const utils_1 = require("./utils");
|
|
24
|
+
const stacktrace_1 = require("./stacktrace");
|
|
25
|
+
const sourceMap_1 = require("./sourceMap");
|
|
26
|
+
const shared_2 = require("./shared");
|
|
27
|
+
const legacy_1 = require("./legacy");
|
|
28
|
+
const manifest_1 = require("./manifest");
|
|
29
|
+
const utils_2 = require("./manifest/utils");
|
|
30
|
+
exports.sourcemap = {
|
|
31
|
+
generateCodeFrameWithKotlinStacktrace: legacy_1.generateCodeFrameWithKotlinStacktrace,
|
|
32
|
+
generateCodeFrameWithSwiftStacktrace: legacy_1.generateCodeFrameWithSwiftStacktrace,
|
|
33
|
+
};
|
|
34
|
+
__exportStar(require("./sourceMap"), exports);
|
|
35
|
+
var kotlin_2 = require("./kotlin");
|
|
36
|
+
Object.defineProperty(exports, "toKotlin", { enumerable: true, get: function () { return kotlin_2.compile; } });
|
|
37
|
+
var swift_2 = require("./swift");
|
|
38
|
+
Object.defineProperty(exports, "toSwift", { enumerable: true, get: function () { return swift_2.compile; } });
|
|
39
|
+
function parseErrMsg(code, errMsg) {
|
|
40
|
+
return code.replace(utils_1.ERR_MSG_PLACEHOLDER, errMsg);
|
|
41
|
+
}
|
|
42
|
+
function compileErrMsg(id) {
|
|
43
|
+
return `uts插件[${id}]编译失败,无法使用`;
|
|
44
|
+
}
|
|
45
|
+
function warn(msg) {
|
|
46
|
+
console.warn(`提示:${msg}`);
|
|
47
|
+
}
|
|
48
|
+
async function compile(pluginDir) {
|
|
49
|
+
const pkg = (0, utils_1.resolvePackage)(pluginDir);
|
|
50
|
+
if (!pkg) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const cacheDir = process.env.HX_DEPENDENCIES_DIR;
|
|
54
|
+
const inputDir = process.env.UNI_INPUT_DIR;
|
|
55
|
+
const outputDir = process.env.UNI_OUTPUT_DIR;
|
|
56
|
+
const utsPlatform = process.env.UNI_UTS_PLATFORM;
|
|
57
|
+
const pluginRelativeDir = (0, path_1.relative)(inputDir, pluginDir);
|
|
58
|
+
const env = (0, manifest_1.initCheckOptionsEnv)();
|
|
59
|
+
const deps = [];
|
|
60
|
+
const code = await (0, code_1.genProxyCode)(pluginDir, pkg);
|
|
61
|
+
let errMsg = '';
|
|
62
|
+
if (process.env.NODE_ENV !== 'development') {
|
|
63
|
+
// 生产模式 支持同时生成 android 和 ios 的 uts 插件
|
|
64
|
+
if (utsPlatform === 'app-android' || utsPlatform === 'app') {
|
|
65
|
+
const filename = (0, code_1.resolvePlatformIndex)('app-android', pluginDir, pkg) ||
|
|
66
|
+
(0, code_1.resolveRootIndex)(pluginDir, pkg);
|
|
67
|
+
if (filename) {
|
|
68
|
+
await getCompiler('kotlin').runProd(filename);
|
|
69
|
+
if (cacheDir) {
|
|
70
|
+
(0, manifest_1.genManifestFile)('app-android', {
|
|
71
|
+
pluginDir,
|
|
72
|
+
env,
|
|
73
|
+
cacheDir,
|
|
74
|
+
pluginRelativeDir,
|
|
75
|
+
is_uni_modules: pkg.is_uni_modules,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (utsPlatform === 'app-ios' || utsPlatform === 'app') {
|
|
81
|
+
const filename = (0, code_1.resolvePlatformIndex)('app-ios', pluginDir, pkg) ||
|
|
82
|
+
(0, code_1.resolveRootIndex)(pluginDir, pkg);
|
|
83
|
+
if (filename) {
|
|
84
|
+
await getCompiler('swift').runProd(filename);
|
|
85
|
+
if (cacheDir) {
|
|
86
|
+
(0, manifest_1.genManifestFile)('app-ios', {
|
|
87
|
+
pluginDir,
|
|
88
|
+
env,
|
|
89
|
+
cacheDir,
|
|
90
|
+
pluginRelativeDir,
|
|
91
|
+
is_uni_modules: pkg.is_uni_modules,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const compilerType = utsPlatform === 'app-android' ? 'kotlin' : 'swift';
|
|
99
|
+
const versionTips = getCompiler(compilerType).checkVersionTips(pkg.id, pluginDir, pkg.is_uni_modules);
|
|
100
|
+
// iOS windows 平台,标准基座不编译
|
|
101
|
+
if (utsPlatform === 'app-ios') {
|
|
102
|
+
if (shared_2.isWindows) {
|
|
103
|
+
process.env.UNI_UTS_TIPS = `iOS手机在windows上真机运行时uts插件代码修改需提交云端打包自定义基座才能生效`;
|
|
104
|
+
return {
|
|
105
|
+
code: parseErrMsg(code, errMsg),
|
|
106
|
+
deps,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// ios 模拟器不支持
|
|
110
|
+
if (process.env.HX_RUN_DEVICE_TYPE === 'ios_simulator') {
|
|
111
|
+
process.env.UNI_UTS_TIPS = `iOS手机在模拟器运行暂不支持uts插件,如需调用uts插件请使用自定义基座`;
|
|
112
|
+
return {
|
|
113
|
+
code: parseErrMsg(code, compileErrMsg(pkg.id)),
|
|
114
|
+
deps,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (utsPlatform === 'app-android' || utsPlatform === 'app-ios') {
|
|
119
|
+
let tips = '';
|
|
120
|
+
// dev 模式
|
|
121
|
+
if (cacheDir) {
|
|
122
|
+
// 检查缓存
|
|
123
|
+
// let start = Date.now()
|
|
124
|
+
// console.log('uts插件[' + pkg.id + ']start', start)
|
|
125
|
+
const res = await (0, manifest_1.checkCompile)(utsPlatform, process.env.HX_USE_BASE_TYPE, {
|
|
126
|
+
id: pkg.id,
|
|
127
|
+
env,
|
|
128
|
+
cacheDir,
|
|
129
|
+
outputDir,
|
|
130
|
+
pluginDir,
|
|
131
|
+
pluginRelativeDir,
|
|
132
|
+
is_uni_modules: pkg.is_uni_modules,
|
|
133
|
+
});
|
|
134
|
+
if (res.tips) {
|
|
135
|
+
tips = res.tips;
|
|
136
|
+
}
|
|
137
|
+
// console.log('uts插件[' + pkg.id + ']end', Date.now())
|
|
138
|
+
// console.log('uts插件[' + pkg.id + ']缓存检查耗时:', Date.now() - start)
|
|
139
|
+
if (!res.expired) {
|
|
140
|
+
if (utsPlatform === 'app-android') {
|
|
141
|
+
(0, manifest_1.restoreDex)(pluginRelativeDir, outputDir, pkg.is_uni_modules);
|
|
142
|
+
}
|
|
143
|
+
// 还原 sourcemap
|
|
144
|
+
(0, manifest_1.restoreSourceMap)(utsPlatform, pluginRelativeDir, outputDir, cacheDir, pkg.is_uni_modules);
|
|
145
|
+
console.log((0, utils_2.cacheTips)(pkg.id));
|
|
146
|
+
if (res.tips) {
|
|
147
|
+
warn(res.tips);
|
|
148
|
+
}
|
|
149
|
+
if (versionTips) {
|
|
150
|
+
warn(versionTips);
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
code: parseErrMsg(code, errMsg),
|
|
154
|
+
// 所有文件加入依赖
|
|
155
|
+
deps: res.files.map((name) => (0, path_1.join)(pluginDir, name)),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const filename = (0, code_1.resolvePlatformIndex)(utsPlatform, pluginDir, pkg) ||
|
|
160
|
+
(0, code_1.resolveRootIndex)(pluginDir, pkg);
|
|
161
|
+
if (filename) {
|
|
162
|
+
deps.push(filename);
|
|
163
|
+
if (utsPlatform === 'app-android') {
|
|
164
|
+
deps.push(...(0, kotlin_1.resolveAndroidDepFiles)(filename));
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
deps.push(...(0, swift_1.resolveIOSDepFiles)(filename));
|
|
168
|
+
}
|
|
169
|
+
const res = await getCompiler(compilerType).runDev(filename);
|
|
170
|
+
if (res) {
|
|
171
|
+
if ((0, shared_1.isArray)(res.deps) && res.deps.length) {
|
|
172
|
+
// 添加其他文件的依赖
|
|
173
|
+
deps.push(...res.deps);
|
|
174
|
+
}
|
|
175
|
+
let isSuccess = false;
|
|
176
|
+
if (res.type === 'swift') {
|
|
177
|
+
if (res.code) {
|
|
178
|
+
errMsg = compileErrMsg(pkg.id);
|
|
179
|
+
console.error(`error: ` +
|
|
180
|
+
(await (0, stacktrace_1.parseUtsSwiftPluginStacktrace)({
|
|
181
|
+
stacktrace: res.msg,
|
|
182
|
+
sourceMapFile: (0, sourceMap_1.resolveUtsPluginSourceMapFile)('swift', filename, inputDir, outputDir),
|
|
183
|
+
sourceRoot: inputDir,
|
|
184
|
+
})));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
isSuccess = true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else if (res.type === 'kotlin') {
|
|
191
|
+
if (res.changed.length) {
|
|
192
|
+
isSuccess = true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (isSuccess) {
|
|
196
|
+
// 生成缓存文件
|
|
197
|
+
if (cacheDir) {
|
|
198
|
+
// 存储 sourcemap
|
|
199
|
+
(0, manifest_1.storeSourceMap)(utsPlatform, pluginRelativeDir, outputDir, cacheDir, pkg.is_uni_modules);
|
|
200
|
+
// 生成 manifest
|
|
201
|
+
(0, manifest_1.genManifestFile)(utsPlatform, {
|
|
202
|
+
pluginDir,
|
|
203
|
+
env,
|
|
204
|
+
cacheDir,
|
|
205
|
+
pluginRelativeDir,
|
|
206
|
+
is_uni_modules: pkg.is_uni_modules,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (tips) {
|
|
210
|
+
warn(tips);
|
|
211
|
+
}
|
|
212
|
+
if (versionTips) {
|
|
213
|
+
warn(versionTips);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const files = [];
|
|
217
|
+
if (process.env.UNI_APP_UTS_CHANGED_FILES) {
|
|
218
|
+
try {
|
|
219
|
+
files.push(...JSON.parse(process.env.UNI_APP_UTS_CHANGED_FILES));
|
|
220
|
+
}
|
|
221
|
+
catch (e) { }
|
|
222
|
+
}
|
|
223
|
+
if (res.changed && res.changed.length) {
|
|
224
|
+
files.push(...res.changed);
|
|
225
|
+
// 需要缓存 dex 文件
|
|
226
|
+
if (cacheDir && res.type === 'kotlin') {
|
|
227
|
+
res.changed.forEach((file) => {
|
|
228
|
+
if (file.endsWith('classes.dex')) {
|
|
229
|
+
(0, manifest_1.storeDex)((0, path_1.join)(outputDir, file), pluginRelativeDir, outputDir);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
if (res.type === 'kotlin') {
|
|
236
|
+
errMsg = compileErrMsg(pkg.id);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
process.env.UNI_APP_UTS_CHANGED_FILES = JSON.stringify([
|
|
240
|
+
...new Set(files),
|
|
241
|
+
]);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
errMsg = compileErrMsg(pkg.id);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
code: parseErrMsg(code, errMsg),
|
|
251
|
+
deps,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
exports.compile = compile;
|
|
255
|
+
function getCompiler(type) {
|
|
256
|
+
if (type === 'swift') {
|
|
257
|
+
return {
|
|
258
|
+
runProd: swift_1.runSwiftProd,
|
|
259
|
+
runDev: swift_1.runSwiftDev,
|
|
260
|
+
checkVersionTips: swift_1.checkIOSVersionTips,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
runProd: kotlin_1.runKotlinProd,
|
|
265
|
+
runDev: kotlin_1.runKotlinDev,
|
|
266
|
+
checkVersionTips: kotlin_1.checkAndroidVersionTips,
|
|
267
|
+
};
|
|
268
|
+
}
|
package/dist/kotlin.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { UtsResult } from '@dcloudio/uts';
|
|
2
|
+
import { ToKotlinOptions } from './utils';
|
|
3
|
+
import { Module } from '../types/types';
|
|
4
|
+
export declare function createKotlinResolveTypeReferenceName(_namespace: string, _ast: Module): (name: string) => string;
|
|
5
|
+
export declare function runKotlinProd(filename: string): Promise<void>;
|
|
6
|
+
export type RunKotlinDevResult = UtsResult & {
|
|
7
|
+
type: 'kotlin';
|
|
8
|
+
changed: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare function runKotlinDev(filename: string): Promise<RunKotlinDevResult | undefined>;
|
|
11
|
+
export declare function resolveAndroidDepFiles(filename: string): string[];
|
|
12
|
+
export declare function compile(filename: string, { inputDir, outputDir, sourceMap }: ToKotlinOptions): Promise<UtsResult>;
|
|
13
|
+
export declare function checkAndroidVersionTips(pluginId: string, pluginDir: string, is_uni_modules: boolean): string | undefined;
|