@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/kotlin.js ADDED
@@ -0,0 +1,324 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.checkAndroidVersionTips = exports.compile = exports.resolveAndroidDepFiles = exports.runKotlinDev = exports.runKotlinProd = exports.createKotlinResolveTypeReferenceName = void 0;
30
+ const os_1 = __importDefault(require("os"));
31
+ const fs_extra_1 = __importDefault(require("fs-extra"));
32
+ const path_1 = __importStar(require("path"));
33
+ const adm_zip_1 = __importDefault(require("adm-zip"));
34
+ const fast_glob_1 = require("fast-glob");
35
+ const shared_1 = require("@vue/shared");
36
+ const android_versions_1 = require("android-versions");
37
+ const shared_2 = require("./shared");
38
+ const utils_1 = require("./utils");
39
+ function createKotlinResolveTypeReferenceName(_namespace, _ast) {
40
+ return (name) => name;
41
+ }
42
+ exports.createKotlinResolveTypeReferenceName = createKotlinResolveTypeReferenceName;
43
+ function parseKotlinPackage(filename) {
44
+ const res = (0, utils_1.resolvePackage)(filename);
45
+ if (!res) {
46
+ return { package: '' };
47
+ }
48
+ return {
49
+ package: 'uts.sdk.' + (res.is_uni_modules ? 'modules.' : '') + res.name,
50
+ };
51
+ }
52
+ async function runKotlinProd(filename) {
53
+ // 文件有可能是 app-ios 里边的,因为编译到 android 时,为了保证不报错,可能会去读取 ios 下的 uts
54
+ if (filename.includes('app-ios')) {
55
+ return;
56
+ }
57
+ const inputDir = process.env.UNI_INPUT_DIR;
58
+ const outputDir = process.env.UNI_OUTPUT_DIR;
59
+ await compile(filename, { inputDir, outputDir, sourceMap: true });
60
+ (0, utils_1.genUTSPlatformResource)(filename, {
61
+ inputDir,
62
+ outputDir,
63
+ platform: 'app-android',
64
+ extname: '.kt',
65
+ });
66
+ }
67
+ exports.runKotlinProd = runKotlinProd;
68
+ async function runKotlinDev(filename) {
69
+ // 文件有可能是 app-ios 里边的,因为编译到 android 时,为了保证不报错,可能会去读取 ios 下的 uts
70
+ if (filename.includes('app-ios')) {
71
+ return;
72
+ }
73
+ const inputDir = process.env.UNI_INPUT_DIR;
74
+ const outputDir = process.env.UNI_OUTPUT_DIR;
75
+ const result = (await compile(filename, {
76
+ inputDir,
77
+ outputDir,
78
+ sourceMap: true,
79
+ }));
80
+ result.type = 'kotlin';
81
+ result.changed = [];
82
+ const kotlinFile = (0, utils_1.resolveUTSPlatformFile)(filename, {
83
+ inputDir,
84
+ outputDir,
85
+ platform: 'app-android',
86
+ extname: '.kt',
87
+ });
88
+ // 开发模式下,需要生成 dex
89
+ if (fs_extra_1.default.existsSync(kotlinFile)) {
90
+ const compilerServer = (0, utils_1.getCompilerServer)('uniapp-runextension');
91
+ if (!compilerServer) {
92
+ throw `项目使用了uts插件,正在安装 uts Android 运行扩展...`;
93
+ }
94
+ const { getDefaultJar, getKotlincHome, compile, checkDependencies, checkRResources, } = compilerServer;
95
+ let deps = [];
96
+ if (checkDependencies) {
97
+ deps = await checkDeps(filename, checkDependencies);
98
+ }
99
+ let resDeps = [];
100
+ if (checkRResources) {
101
+ resDeps = await checkRes(filename, checkRResources);
102
+ }
103
+ // time = Date.now()
104
+ const jarFile = resolveJarPath(kotlinFile);
105
+ const options = {
106
+ kotlinc: resolveKotlincArgs(kotlinFile, getKotlincHome(), getDefaultJar()
107
+ .concat(resolveLibs(filename))
108
+ .concat(deps)
109
+ .concat(resDeps)),
110
+ d8: resolveD8Args(jarFile),
111
+ sourceRoot: inputDir,
112
+ sourceMapPath: resolveSourceMapFile(outputDir, kotlinFile),
113
+ };
114
+ const res = await compile(options, inputDir);
115
+ // console.log('dex compile time: ' + (Date.now() - time) + 'ms')
116
+ if (res) {
117
+ try {
118
+ fs_extra_1.default.unlinkSync(jarFile);
119
+ // 短期内先不删除,方便排查问题
120
+ // fs.unlinkSync(kotlinFile)
121
+ }
122
+ catch (e) { }
123
+ const dexFile = resolveDexFile(jarFile);
124
+ if (fs_extra_1.default.existsSync(dexFile)) {
125
+ result.changed = [(0, shared_2.normalizePath)(path_1.default.relative(outputDir, dexFile))];
126
+ }
127
+ }
128
+ // else {
129
+ // throw `${normalizePath(
130
+ // path.relative(process.env.UNI_INPUT_DIR, filename)
131
+ // )} 编译失败`
132
+ // }
133
+ }
134
+ return result;
135
+ }
136
+ exports.runKotlinDev = runKotlinDev;
137
+ function checkDeps(filename, checkDependencies) {
138
+ const configJsonFile = resolveConfigJsonFile(filename);
139
+ if (configJsonFile && hasDeps(configJsonFile)) {
140
+ return checkDependencies(configJsonFile).then(({ code, msg, data }) => {
141
+ if (code !== 0) {
142
+ console.error(msg);
143
+ return [];
144
+ }
145
+ return data;
146
+ });
147
+ }
148
+ return Promise.resolve([]);
149
+ }
150
+ function hasDeps(configJsonFile) {
151
+ const deps = (0, shared_2.parseJson)(fs_extra_1.default.readFileSync(configJsonFile, 'utf8')).dependencies || [];
152
+ if ((0, shared_1.isArray)(deps) && deps.length) {
153
+ return true;
154
+ }
155
+ return false;
156
+ }
157
+ function checkRes(filename, checkRResources) {
158
+ const resDir = resolveResDir(filename);
159
+ if (resDir) {
160
+ return checkRResources(resDir).then(({ code, msg, data }) => {
161
+ if (code !== 0) {
162
+ console.error(msg);
163
+ return [];
164
+ }
165
+ return [data.jarPath];
166
+ });
167
+ }
168
+ return Promise.resolve([]);
169
+ }
170
+ function resolveResDir(filename) {
171
+ const resDir = path_1.default.resolve((0, utils_1.resolveAndroidDir)(filename), 'res');
172
+ if (fs_extra_1.default.existsSync(resDir)) {
173
+ return resDir;
174
+ }
175
+ }
176
+ function resolveAndroidResourceClass(filename) {
177
+ const resDir = resolveResDir(filename);
178
+ if (resDir && fs_extra_1.default.readdirSync(resDir).length) {
179
+ const pkg = resolveAndroidManifestPackage(filename);
180
+ if (pkg) {
181
+ return pkg + '.R';
182
+ }
183
+ }
184
+ }
185
+ const packageRe = /\s+package="(.*)"/;
186
+ function resolveAndroidManifestPackage(filename) {
187
+ const manifestXmlPath = path_1.default.resolve((0, utils_1.resolveAndroidDir)(filename), 'AndroidManifest.xml');
188
+ if (fs_extra_1.default.existsSync(manifestXmlPath)) {
189
+ const matches = fs_extra_1.default.readFileSync(manifestXmlPath, 'utf8').match(packageRe);
190
+ if (matches && matches[1]) {
191
+ return matches[1];
192
+ }
193
+ }
194
+ }
195
+ const deps = ['AndroidManifest.xml', 'config.json'];
196
+ function resolveAndroidDepFiles(filename) {
197
+ const dir = (0, utils_1.resolveAndroidDir)(filename);
198
+ return deps.map((dep) => path_1.default.resolve(dir, dep));
199
+ }
200
+ exports.resolveAndroidDepFiles = resolveAndroidDepFiles;
201
+ function resolveConfigJsonFile(filename) {
202
+ const configJsonFile = path_1.default.resolve((0, utils_1.resolveAndroidDir)(filename), 'config.json');
203
+ if (fs_extra_1.default.existsSync(configJsonFile)) {
204
+ return configJsonFile;
205
+ }
206
+ }
207
+ function resolveSourceMapFile(outputDir, kotlinFile) {
208
+ return (path_1.default.resolve((0, shared_2.resolveSourceMapPath)(), path_1.default.relative(outputDir, kotlinFile)) +
209
+ '.map');
210
+ }
211
+ const DEFAULT_IMPORTS = [
212
+ 'kotlinx.coroutines.async',
213
+ 'kotlinx.coroutines.CoroutineScope',
214
+ 'kotlinx.coroutines.Deferred',
215
+ 'kotlinx.coroutines.Dispatchers',
216
+ 'io.dcloud.uts.*',
217
+ ];
218
+ async function compile(filename, { inputDir, outputDir, sourceMap }) {
219
+ const { bundle, UtsTarget } = (0, utils_1.getUtsCompiler)();
220
+ // let time = Date.now()
221
+ const imports = [...DEFAULT_IMPORTS];
222
+ const rClass = resolveAndroidResourceClass(filename);
223
+ if (rClass) {
224
+ imports.push(rClass);
225
+ }
226
+ const result = await bundle(UtsTarget.KOTLIN, {
227
+ input: {
228
+ root: inputDir,
229
+ filename,
230
+ },
231
+ output: {
232
+ isPlugin: true,
233
+ outDir: outputDir,
234
+ package: parseKotlinPackage(filename).package,
235
+ sourceMap: sourceMap ? (0, utils_1.resolveUTSSourceMapPath)() : false,
236
+ extname: 'kt',
237
+ imports,
238
+ logFilename: true,
239
+ noColor: (0, shared_2.isInHBuilderX)(),
240
+ },
241
+ });
242
+ sourceMap &&
243
+ (0, utils_1.moveRootIndexSourceMap)(filename, {
244
+ inputDir,
245
+ outputDir,
246
+ platform: 'app-android',
247
+ extname: '.kt',
248
+ });
249
+ return result;
250
+ }
251
+ exports.compile = compile;
252
+ function resolveKotlincArgs(filename, kotlinc, jars) {
253
+ return [
254
+ filename,
255
+ '-cp',
256
+ resolveClassPath(jars),
257
+ '-d',
258
+ resolveJarPath(filename),
259
+ '-kotlin-home',
260
+ kotlinc,
261
+ ];
262
+ }
263
+ function resolveD8Args(filename) {
264
+ return [
265
+ filename,
266
+ '--no-desugaring',
267
+ '--min-api',
268
+ '19',
269
+ '--output',
270
+ resolveDexPath(filename),
271
+ ];
272
+ }
273
+ function resolveLibs(filename) {
274
+ const libsPath = path_1.default.resolve((0, utils_1.resolveAndroidDir)(filename), 'libs');
275
+ const libs = [];
276
+ if (fs_extra_1.default.existsSync(libsPath)) {
277
+ libs.push(...(0, fast_glob_1.sync)('*.jar', { cwd: libsPath, absolute: true }));
278
+ const zips = (0, fast_glob_1.sync)('*.aar', { cwd: libsPath });
279
+ zips.forEach((name) => {
280
+ const outputPath = resolveAndroidArchiveOutputPath(name);
281
+ if (!fs_extra_1.default.existsSync(outputPath)) {
282
+ // 解压
283
+ const zip = new adm_zip_1.default(path_1.default.resolve(libsPath, name));
284
+ zip.extractAllTo(outputPath, true);
285
+ }
286
+ libs.push(...(0, fast_glob_1.sync)('**/*.jar', {
287
+ cwd: outputPath,
288
+ absolute: true,
289
+ }));
290
+ });
291
+ }
292
+ return libs;
293
+ }
294
+ function resolveAndroidArchiveOutputPath(aar) {
295
+ return path_1.default.resolve(process.env.UNI_OUTPUT_DIR, '../.uts/aar', aar ? aar.replace('.aar', '') : '');
296
+ }
297
+ function resolveDexFile(jarFile) {
298
+ return (0, shared_2.normalizePath)(path_1.default.resolve(path_1.default.dirname(jarFile), 'classes.dex'));
299
+ }
300
+ function resolveDexPath(filename) {
301
+ return path_1.default.dirname(filename);
302
+ }
303
+ function resolveJarPath(filename) {
304
+ return filename.replace(path_1.default.extname(filename), '.jar');
305
+ }
306
+ function resolveClassPath(jars) {
307
+ return jars.join(os_1.default.platform() === 'win32' ? ';' : ':');
308
+ }
309
+ function checkAndroidVersionTips(pluginId, pluginDir, is_uni_modules) {
310
+ const configJsonFile = (0, path_1.join)(pluginDir, is_uni_modules ? 'utssdk' : '', 'app-android', 'config.json');
311
+ if (configJsonFile && fs_extra_1.default.existsSync(configJsonFile)) {
312
+ try {
313
+ const configJson = (0, shared_2.parseJson)(fs_extra_1.default.readFileSync(configJsonFile, 'utf8'));
314
+ if (configJson.minSdkVersion) {
315
+ const androidVersion = (0, android_versions_1.get)(configJson.minSdkVersion);
316
+ if (androidVersion) {
317
+ return `uts插件[${pluginId}]需在 Android ${androidVersion.semver} 版本及以上方可正常使用`;
318
+ }
319
+ }
320
+ }
321
+ catch (e) { }
322
+ }
323
+ }
324
+ exports.checkAndroidVersionTips = checkAndroidVersionTips;
@@ -0,0 +1,23 @@
1
+ import { BasicSourceMapConsumer, IndexedSourceMapConsumer } from 'source-map';
2
+ interface MessageSourceLocation {
3
+ type: 'exception' | 'error' | 'warning' | 'info' | 'logging' | 'output';
4
+ message: string;
5
+ file?: string;
6
+ line: number;
7
+ column: number;
8
+ code?: string;
9
+ }
10
+ interface GenerateCodeFrameOptions {
11
+ sourceRoot?: string;
12
+ replaceTabsWithSpace?: boolean;
13
+ }
14
+ export declare function generateCodeFrameSourceMapConsumer(consumer: BasicSourceMapConsumer | IndexedSourceMapConsumer, m: MessageSourceLocation, options?: GenerateCodeFrameOptions): Required<MessageSourceLocation> | undefined;
15
+ export declare function generateCodeFrameWithSourceMapPath(filename: string, messages: MessageSourceLocation[] | string, options?: GenerateCodeFrameOptions): Promise<Required<MessageSourceLocation>[]>;
16
+ interface GenerateCodeFrameWithStacktraceOptions {
17
+ name: string;
18
+ inputDir: string;
19
+ outputDir: string;
20
+ }
21
+ export declare function generateCodeFrameWithKotlinStacktrace(stacktrace: string, { name, inputDir, outputDir }: GenerateCodeFrameWithStacktraceOptions): Promise<unknown>;
22
+ export declare function generateCodeFrameWithSwiftStacktrace(stacktrace: string, { name, inputDir, outputDir }: GenerateCodeFrameWithStacktraceOptions): Promise<unknown>;
23
+ export {};
@@ -0,0 +1,117 @@
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.generateCodeFrameWithSwiftStacktrace = exports.generateCodeFrameWithKotlinStacktrace = exports.generateCodeFrameWithSourceMapPath = exports.generateCodeFrameSourceMapConsumer = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const source_map_1 = require("source-map");
10
+ const stacktrace_1 = require("../stacktrace");
11
+ function generateCodeFrameSourceMapConsumer(consumer, m, options = {}) {
12
+ if (m.file) {
13
+ const res = consumer.originalPositionFor({
14
+ line: m.line,
15
+ column: m.column,
16
+ });
17
+ if (res.source != null && res.line != null && res.column != null) {
18
+ let code = consumer.sourceContentFor(res.source, true);
19
+ if (code) {
20
+ code = (0, stacktrace_1.generateCodeFrame)(code, { line: res.line, column: res.column });
21
+ if (options.replaceTabsWithSpace) {
22
+ code = code.replace(/\t/g, ' ');
23
+ }
24
+ return {
25
+ type: m.type,
26
+ file: res.source,
27
+ line: res.line,
28
+ column: res.column,
29
+ message: m.message,
30
+ code,
31
+ };
32
+ }
33
+ }
34
+ }
35
+ }
36
+ exports.generateCodeFrameSourceMapConsumer = generateCodeFrameSourceMapConsumer;
37
+ function initConsumer(filename) {
38
+ if (fs_1.default.existsSync(filename)) {
39
+ return new source_map_1.SourceMapConsumer(fs_1.default.readFileSync(filename, 'utf8'));
40
+ }
41
+ return Promise.resolve(undefined);
42
+ }
43
+ function generateCodeFrameWithSourceMapPath(filename, messages, options = {}) {
44
+ if (typeof messages === 'string') {
45
+ try {
46
+ messages = JSON.parse(messages);
47
+ }
48
+ catch (e) { }
49
+ }
50
+ if (Array.isArray(messages) && messages.length) {
51
+ return new Promise((resolve) => {
52
+ initConsumer(filename).then((consumer) => {
53
+ resolve(messages
54
+ .map((m) => {
55
+ if (m.file && consumer) {
56
+ const message = generateCodeFrameSourceMapConsumer(consumer, m, options);
57
+ if (message) {
58
+ return message;
59
+ }
60
+ }
61
+ if (!m.file) {
62
+ m.file = '';
63
+ }
64
+ return m;
65
+ })
66
+ .filter(Boolean));
67
+ });
68
+ });
69
+ }
70
+ return Promise.resolve([]);
71
+ }
72
+ exports.generateCodeFrameWithSourceMapPath = generateCodeFrameWithSourceMapPath;
73
+ function resolveSourceMapPath(sourceMapFilename, name, outputDir) {
74
+ const is_uni_modules = path_1.default.basename(path_1.default.dirname(name)) === 'uni_modules';
75
+ return path_1.default.resolve(outputDir, '../.sourcemap/app', name, is_uni_modules ? 'utssdk' : '', sourceMapFilename);
76
+ }
77
+ function generateCodeFrameWithKotlinStacktrace(stacktrace, { name, inputDir, outputDir }) {
78
+ const sourceMapFilename = resolveSourceMapPath('app-android/index.kt.map', name, outputDir);
79
+ return generateCodeFrameWithStacktrace(stacktrace, /e:\s+(.*):\s+\(([0-9]+),\s+([0-9]+)\):\s+(.*)/g, {
80
+ sourceRoot: inputDir,
81
+ sourceMapFilename,
82
+ });
83
+ }
84
+ exports.generateCodeFrameWithKotlinStacktrace = generateCodeFrameWithKotlinStacktrace;
85
+ function generateCodeFrameWithSwiftStacktrace(stacktrace, { name, inputDir, outputDir }) {
86
+ const sourceMapFilename = resolveSourceMapPath('app-ios/index.swift.map', name, outputDir);
87
+ return generateCodeFrameWithStacktrace(stacktrace, /(.*):([0-9]+):([0-9]+):\s+error:\s+(.*)/g, {
88
+ sourceRoot: inputDir,
89
+ sourceMapFilename,
90
+ });
91
+ }
92
+ exports.generateCodeFrameWithSwiftStacktrace = generateCodeFrameWithSwiftStacktrace;
93
+ function generateCodeFrameWithStacktrace(stacktrace, regexp, { sourceRoot, sourceMapFilename, replaceTabsWithSpace, }) {
94
+ return new Promise((resolve) => {
95
+ initConsumer(sourceMapFilename).then((consumer) => {
96
+ if (!consumer) {
97
+ return resolve(stacktrace);
98
+ }
99
+ resolve(stacktrace.replace(regexp, (substring, file, line, column, message) => {
100
+ const m = generateCodeFrameSourceMapConsumer(consumer, {
101
+ type: 'error',
102
+ file,
103
+ message,
104
+ line: parseInt(line),
105
+ column: parseInt(column),
106
+ }, { sourceRoot, replaceTabsWithSpace });
107
+ if (!m) {
108
+ return substring;
109
+ }
110
+ return `error: ${message}
111
+ at ${m.file}:${m.line}:${m.column}
112
+ ${m.code}
113
+ `;
114
+ }));
115
+ });
116
+ });
117
+ }
@@ -0,0 +1,2 @@
1
+ export declare function storeDex(dexFile: string, pluginRelativeDir: string, outputDir: string): void;
2
+ export declare function restoreDex(pluginRelativeDir: string, outputDir: string, is_uni_modules: boolean): void;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.restoreDex = exports.storeDex = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const path_1 = require("path");
6
+ function dexName() {
7
+ return 'classes.dex';
8
+ }
9
+ function storeDex(dexFile, pluginRelativeDir, outputDir) {
10
+ (0, fs_extra_1.copySync)(dexFile, resolveDexCacheFilename(pluginRelativeDir, outputDir));
11
+ }
12
+ exports.storeDex = storeDex;
13
+ function restoreDex(pluginRelativeDir, outputDir, is_uni_modules) {
14
+ const cacheFile = resolveDexCacheFile(pluginRelativeDir, outputDir);
15
+ if (cacheFile) {
16
+ (0, fs_extra_1.copySync)(cacheFile, (0, path_1.join)(outputDir, pluginRelativeDir, is_uni_modules ? 'utssdk' : '', 'app-android', dexName()));
17
+ }
18
+ }
19
+ exports.restoreDex = restoreDex;
20
+ function resolveDexCacheFilename(pluginRelativeDir, outputDir) {
21
+ return (0, path_1.join)(outputDir, '../.uts/dex', pluginRelativeDir, dexName());
22
+ }
23
+ function resolveDexCacheFile(pluginRelativeDir, outputDir) {
24
+ const file = resolveDexCacheFilename(pluginRelativeDir, outputDir);
25
+ return ((0, fs_extra_1.existsSync)(file) && file) || '';
26
+ }
@@ -0,0 +1,8 @@
1
+ import { APP_PLATFORM, CheckOptions, CheckResult } from './utils';
2
+ export { genManifestFile } from './manifest';
3
+ export { restoreDex, storeDex } from './dex';
4
+ export { restoreSourceMap, storeSourceMap } from './sourceMap';
5
+ export declare function checkKotlinCompile(playground: typeof process.env.HX_USE_BASE_TYPE, options: CheckOptions): Promise<CheckResult>;
6
+ export declare function checkSwiftCompile(playground: typeof process.env.HX_USE_BASE_TYPE, options: CheckOptions): Promise<CheckResult>;
7
+ export declare function checkCompile(platform: APP_PLATFORM, playground: typeof process.env.HX_USE_BASE_TYPE, options: CheckOptions): Promise<CheckResult>;
8
+ export declare function initCheckOptionsEnv(): CheckOptions['env'];
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initCheckOptionsEnv = exports.checkCompile = exports.checkSwiftCompile = exports.checkKotlinCompile = exports.storeSourceMap = exports.restoreSourceMap = exports.storeDex = exports.restoreDex = exports.genManifestFile = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const path_1 = require("path");
6
+ const shared_1 = require("../shared");
7
+ const manifest_1 = require("./manifest");
8
+ const utils_1 = require("./utils");
9
+ var manifest_2 = require("./manifest");
10
+ Object.defineProperty(exports, "genManifestFile", { enumerable: true, get: function () { return manifest_2.genManifestFile; } });
11
+ var dex_1 = require("./dex");
12
+ Object.defineProperty(exports, "restoreDex", { enumerable: true, get: function () { return dex_1.restoreDex; } });
13
+ Object.defineProperty(exports, "storeDex", { enumerable: true, get: function () { return dex_1.storeDex; } });
14
+ var sourceMap_1 = require("./sourceMap");
15
+ Object.defineProperty(exports, "restoreSourceMap", { enumerable: true, get: function () { return sourceMap_1.restoreSourceMap; } });
16
+ Object.defineProperty(exports, "storeSourceMap", { enumerable: true, get: function () { return sourceMap_1.storeSourceMap; } });
17
+ const ANDROID_CUSTOM_RES = [
18
+ 'app-android/assets/',
19
+ 'app-android/libs/',
20
+ 'app-android/res/',
21
+ 'app-android/AndroidManifest.xml',
22
+ ];
23
+ const IOS_CUSTOM_RES = [
24
+ 'app-ios/Frameworks/',
25
+ 'app-ios/Resources/',
26
+ 'app-ios/Info.plist',
27
+ ];
28
+ function checkKotlinCompile(playground, options) {
29
+ return checkCompile('app-android', playground, options);
30
+ }
31
+ exports.checkKotlinCompile = checkKotlinCompile;
32
+ function checkSwiftCompile(playground, options) {
33
+ return checkCompile('app-ios', playground, options);
34
+ }
35
+ exports.checkSwiftCompile = checkSwiftCompile;
36
+ function checkCompile(platform, playground, options) {
37
+ const platformOptions = {
38
+ customRes: platform === 'app-android' ? ANDROID_CUSTOM_RES : IOS_CUSTOM_RES,
39
+ };
40
+ if (playground === 'standard') {
41
+ return checkWithPlayground(platform, 'standard', options, platformOptions);
42
+ }
43
+ return checkWithPlayground(platform, 'custom', options, platformOptions);
44
+ }
45
+ exports.checkCompile = checkCompile;
46
+ async function checkWithPlayground(platform, type, { id, env, cacheDir, pluginDir, pluginRelativeDir, is_uni_modules, }, { customRes }) {
47
+ // 第一步:获取所有文件列表
48
+ const files = await (0, manifest_1.resolvePluginFiles)(platform, pluginDir, is_uni_modules);
49
+ let tips = '';
50
+ // 标准基座检查是否包含原生资源/配置
51
+ if (type === 'standard') {
52
+ if ((0, manifest_1.hasCustomResources)(files, customRes)) {
53
+ tips = (0, utils_1.customResourceTips)(id);
54
+ }
55
+ else {
56
+ // 检查 config.json
57
+ if (platform === 'app-android') {
58
+ if (androidHasCustomConfigJson(pluginDir, is_uni_modules)) {
59
+ tips = (0, utils_1.customResourceTips)(id);
60
+ }
61
+ }
62
+ else if (platform === 'app-ios') {
63
+ if (iOSHasCustomConfigJson(pluginDir, is_uni_modules)) {
64
+ tips = (0, utils_1.customResourceTips)(id);
65
+ }
66
+ }
67
+ }
68
+ }
69
+ // 第二步:获取当前插件缓存文件信息
70
+ const manifest = (0, manifest_1.resolveManifestJson)(platform, pluginRelativeDir, cacheDir);
71
+ if (!manifest) {
72
+ return { expired: true, tips, files };
73
+ }
74
+ // 第四步:检查文件变更
75
+ const res = await (0, manifest_1.checkManifest)(manifest, { env, files, pluginDir });
76
+ // 自定义基座检查原生资源/配置是否发生变化
77
+ if (type === 'custom' && typeof res === 'string') {
78
+ if ((0, manifest_1.isCustomResources)(res, customRes)) {
79
+ tips = (0, utils_1.customResourceChangedTips)(id);
80
+ }
81
+ }
82
+ return {
83
+ expired: res !== true,
84
+ tips,
85
+ files,
86
+ };
87
+ }
88
+ function initCheckOptionsEnv() {
89
+ return {
90
+ compilerVersion: require('../../package.json').version,
91
+ };
92
+ }
93
+ exports.initCheckOptionsEnv = initCheckOptionsEnv;
94
+ function androidHasCustomConfigJson(pluginDir, is_uni_modules) {
95
+ return hasCustomConfigJson('app-android', 'minSdkVersion', pluginDir, is_uni_modules);
96
+ }
97
+ function iOSHasCustomConfigJson(pluginDir, is_uni_modules) {
98
+ return hasCustomConfigJson('app-ios', 'deploymentTarget', pluginDir, is_uni_modules);
99
+ }
100
+ function hasCustomConfigJson(platform, key, pluginDir, is_uni_modules) {
101
+ const configJsonFile = (0, path_1.join)(pluginDir, is_uni_modules ? 'utssdk' : '', platform, 'config.json');
102
+ if (configJsonFile && (0, fs_extra_1.existsSync)(configJsonFile)) {
103
+ try {
104
+ const configJson = (0, shared_1.parseJson)((0, fs_extra_1.readFileSync)(configJsonFile, 'utf8'));
105
+ const len = Object.keys(configJson).length;
106
+ if (len > 1) {
107
+ return true;
108
+ }
109
+ if (len === 1) {
110
+ if (!configJson.hasOwnProperty(key)) {
111
+ return true;
112
+ }
113
+ }
114
+ }
115
+ catch (e) { }
116
+ }
117
+ return false;
118
+ }
@@ -0,0 +1,44 @@
1
+ import { APP_PLATFORM } from './utils';
2
+ interface ManifestFile {
3
+ md5: string;
4
+ }
5
+ declare const VERSION = "1";
6
+ export interface Manifest {
7
+ version: typeof VERSION;
8
+ env: Record<string, unknown>;
9
+ files: {
10
+ [file: string]: ManifestFile;
11
+ };
12
+ }
13
+ /**
14
+ * 计算文件 md5(有缓存)
15
+ * @param file
16
+ * @returns
17
+ */
18
+ export declare function hash(file: string): Promise<string>;
19
+ interface GenManifestJsonOptions {
20
+ pluginDir: string;
21
+ env: Record<string, unknown>;
22
+ files?: string[];
23
+ is_uni_modules: boolean;
24
+ }
25
+ export interface GenManifestFileOptions {
26
+ cacheDir: string;
27
+ pluginRelativeDir: string;
28
+ is_uni_modules: boolean;
29
+ env: Record<string, unknown>;
30
+ pluginDir: string;
31
+ files?: string[];
32
+ }
33
+ export declare function genManifestFile(platform: APP_PLATFORM, { files, pluginDir, env, cacheDir, pluginRelativeDir, is_uni_modules, }: GenManifestFileOptions): Promise<boolean>;
34
+ export declare function genManifestJson(platform: APP_PLATFORM, { pluginDir, files, env, is_uni_modules }: GenManifestJsonOptions): Promise<Manifest>;
35
+ export declare function resolvePluginFiles(platform: APP_PLATFORM, pluginDir: string, is_uni_modules: boolean): Promise<string[]>;
36
+ export declare function checkManifest(manifest: Manifest, { env, files, pluginDir, }: {
37
+ pluginDir: string;
38
+ files: string[];
39
+ env: Record<string, unknown>;
40
+ }): Promise<string | boolean>;
41
+ export declare function hasCustomResources(files: string[], resources: string[]): true | undefined;
42
+ export declare function isCustomResources(file: string, resources: string[]): boolean;
43
+ export declare function resolveManifestJson(platform: APP_PLATFORM, pluginRelativeDir: string, cacheDir: string): Manifest | undefined;
44
+ export {};