| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- "use strict";
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- var desc = Object.getOwnPropertyDescriptor(m, k);
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
- desc = { enumerable: true, get: function() { return m[k]; } };
- }
- Object.defineProperty(o, k2, desc);
- }) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- }));
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.compile = exports.toSwift = exports.toKotlin = exports.compileApp = exports.sourcemap = void 0;
- const shared_1 = require("@vue/shared");
- const path_1 = require("path");
- const kotlin_1 = require("./kotlin");
- const swift_1 = require("./swift");
- const code_1 = require("./code");
- const utils_1 = require("./utils");
- const stacktrace_1 = require("./stacktrace");
- const sourceMap_1 = require("./sourceMap");
- const shared_2 = require("./shared");
- const legacy_1 = require("./legacy");
- const manifest_1 = require("./manifest");
- const utils_2 = require("./manifest/utils");
- const encrypt_1 = require("./encrypt");
- exports.sourcemap = {
- generateCodeFrameWithKotlinStacktrace: legacy_1.generateCodeFrameWithKotlinStacktrace,
- generateCodeFrameWithSwiftStacktrace: legacy_1.generateCodeFrameWithSwiftStacktrace,
- };
- var index_1 = require("./uvue/index");
- Object.defineProperty(exports, "compileApp", { enumerable: true, get: function () { return index_1.compileApp; } });
- __exportStar(require("./sourceMap"), exports);
- var kotlin_2 = require("./kotlin");
- Object.defineProperty(exports, "toKotlin", { enumerable: true, get: function () { return kotlin_2.compile; } });
- var swift_2 = require("./swift");
- Object.defineProperty(exports, "toSwift", { enumerable: true, get: function () { return swift_2.compile; } });
- function parseErrMsg(code, errMsg) {
- return code.replace(utils_1.ERR_MSG_PLACEHOLDER, errMsg);
- }
- function compileErrMsg(id) {
- return `uts插件[${id}]编译失败,无法使用`;
- }
- function warn(msg) {
- console.warn(`提示:${msg}`);
- }
- function createResult(dir, errMsg, code, deps, meta) {
- return {
- dir,
- code: parseErrMsg(code, errMsg),
- deps,
- encrypt: false,
- meta,
- };
- }
- async function compile(pluginDir, { isX, isPlugin, extApis } = { isX: false, isPlugin: true }) {
- const pkg = (0, utils_1.resolvePackage)(pluginDir);
- if (!pkg) {
- return;
- }
- // 加密插件
- if ((0, encrypt_1.isEncrypt)(pluginDir)) {
- return (0, encrypt_1.compileEncrypt)(pluginDir);
- }
- const cacheDir = process.env.HX_DEPENDENCIES_DIR || '';
- const inputDir = process.env.UNI_INPUT_DIR;
- const outputDir = process.env.UNI_OUTPUT_DIR;
- const utsPlatform = process.env.UNI_UTS_PLATFORM;
- const pluginRelativeDir = (0, path_1.relative)(inputDir, pluginDir);
- const outputPluginDir = (0, shared_2.normalizePath)((0, path_1.join)(outputDir, pluginRelativeDir));
- const androidComponents = (0, utils_1.resolveAndroidComponents)(pluginDir, pkg.is_uni_modules);
- const iosComponents = (0, utils_1.resolveIOSComponents)(pluginDir, pkg.is_uni_modules);
- const env = (0, manifest_1.initCheckOptionsEnv)();
- const deps = [];
- const meta = {
- exports: {},
- types: {},
- };
- const code = await (0, code_1.genProxyCode)(pluginDir, (0, shared_1.extend)({
- androidComponents,
- iosComponents,
- format: process.env.UNI_UTS_JS_CODE_FORMAT === 'cjs'
- ? "cjs" /* FORMATS.CJS */
- : "es" /* FORMATS.ES */,
- pluginRelativeDir,
- moduleName: require((0, path_1.join)(pluginDir, 'package.json')).displayName || pkg.id,
- moduleType: process.env.UNI_UTS_MODULE_TYPE || '',
- meta,
- inputDir,
- }, pkg));
- let errMsg = '';
- if (process.env.NODE_ENV !== 'development') {
- // 生产模式 支持同时生成 android 和 ios 的 uts 插件
- if (utsPlatform === 'app-android' || utsPlatform === 'app') {
- let filename = (0, code_1.resolvePlatformIndex)('app-android', pluginDir, pkg) ||
- (0, code_1.resolveRootIndex)(pluginDir, pkg);
- if (!filename && Object.keys(androidComponents).length) {
- filename = (0, code_1.resolvePlatformIndexFilename)('app-android', pluginDir, pkg);
- }
- if (filename) {
- await getCompiler('kotlin').runProd(filename, androidComponents, {
- isX,
- isPlugin,
- extApis,
- });
- if (cacheDir) {
- // 存储 sourcemap
- (0, manifest_1.storeSourceMap)('app-android', pluginRelativeDir, outputDir, cacheDir, pkg.is_uni_modules);
- (0, manifest_1.genManifestFile)('app-android', {
- pluginDir,
- env,
- cacheDir,
- pluginRelativeDir,
- is_uni_modules: pkg.is_uni_modules,
- });
- }
- }
- }
- if (utsPlatform === 'app-ios' || utsPlatform === 'app') {
- let filename = (0, code_1.resolvePlatformIndex)('app-ios', pluginDir, pkg) ||
- (0, code_1.resolveRootIndex)(pluginDir, pkg);
- if (!filename && Object.keys(androidComponents).length) {
- filename = (0, code_1.resolvePlatformIndexFilename)('app-ios', pluginDir, pkg);
- }
- if (filename) {
- await getCompiler('swift').runProd(filename, iosComponents, {
- isX,
- isPlugin,
- extApis,
- });
- if (cacheDir) {
- (0, manifest_1.storeSourceMap)('app-ios', pluginRelativeDir, outputDir, cacheDir, pkg.is_uni_modules);
- (0, manifest_1.genManifestFile)('app-ios', {
- pluginDir,
- env,
- cacheDir,
- pluginRelativeDir,
- is_uni_modules: pkg.is_uni_modules,
- });
- }
- }
- }
- }
- else {
- const compilerType = utsPlatform === 'app-android' ? 'kotlin' : 'swift';
- const versionTips = getCompiler(compilerType).checkVersionTips(pkg.id, pluginDir, pkg.is_uni_modules);
- // iOS windows 平台,标准基座不编译
- if (utsPlatform === 'app-ios') {
- if (shared_2.isWindows) {
- process.env.UNI_UTS_ERRORS = `iOS手机在windows上使用标准基座真机运行无法使用uts插件,如需使用uts插件请提交云端打包自定义基座`;
- return createResult(outputPluginDir, errMsg, code, deps, meta);
- }
- }
- if (utsPlatform === 'app-android' || utsPlatform === 'app-ios') {
- const components = utsPlatform === 'app-android' ? androidComponents : iosComponents;
- let tips = '';
- // dev 模式
- if (cacheDir) {
- // 检查缓存
- // let start = Date.now()
- // console.log('uts插件[' + pkg.id + ']start', start)
- const res = await (0, manifest_1.checkCompile)(utsPlatform, process.env.HX_USE_BASE_TYPE, {
- id: pkg.id,
- env,
- cacheDir,
- outputDir,
- pluginDir,
- pluginRelativeDir,
- is_uni_modules: pkg.is_uni_modules,
- });
- if (res.tips) {
- tips = res.tips;
- }
- // console.log('uts插件[' + pkg.id + ']end', Date.now())
- // console.log('uts插件[' + pkg.id + ']缓存检查耗时:', Date.now() - start)
- if (!res.expired) {
- if (utsPlatform === 'app-android') {
- (0, manifest_1.restoreDex)(pluginRelativeDir, cacheDir, outputDir, pkg.is_uni_modules);
- }
- // 还原 sourcemap
- (0, manifest_1.restoreSourceMap)(utsPlatform, pluginRelativeDir, outputDir, cacheDir, pkg.is_uni_modules);
- // 处理 config.json
- (0, utils_1.genConfigJson)(utsPlatform, components, pluginRelativeDir, pkg.is_uni_modules, inputDir, outputDir);
- console.log((0, utils_2.cacheTips)(pkg.id));
- if (res.tips) {
- warn(res.tips);
- }
- if (versionTips) {
- warn(versionTips);
- }
- // 所有文件加入依赖
- return createResult(outputPluginDir, errMsg, code, res.files.map((name) => (0, path_1.join)(pluginDir, name)), meta);
- }
- }
- let filename = (0, code_1.resolvePlatformIndex)(utsPlatform, pluginDir, pkg) ||
- (0, code_1.resolveRootIndex)(pluginDir, pkg);
- if (!filename && Object.keys(androidComponents).length) {
- filename = (0, code_1.resolvePlatformIndexFilename)(utsPlatform, pluginDir, pkg);
- }
- if (filename) {
- deps.push(filename);
- if (utsPlatform === 'app-android') {
- deps.push(...(0, kotlin_1.resolveAndroidDepFiles)(filename));
- }
- else {
- deps.push(...(0, swift_1.resolveIOSDepFiles)(filename));
- }
- // 处理 config.json
- (0, utils_1.genConfigJson)(utsPlatform, components, pluginRelativeDir, pkg.is_uni_modules, inputDir, outputDir);
- const res = await getCompiler(compilerType).runDev(filename, {
- components,
- isX,
- isPlugin,
- cacheDir,
- pluginRelativeDir,
- is_uni_modules: pkg.is_uni_modules,
- extApis,
- });
- if (res) {
- if ((0, shared_1.isArray)(res.deps) && res.deps.length) {
- // 添加其他文件的依赖
- deps.push(...res.deps);
- }
- let isSuccess = false;
- if (res.type === 'swift') {
- if (res.code) {
- errMsg = compileErrMsg(pkg.id);
- console.error(`error: ` +
- (await (0, stacktrace_1.parseUTSSwiftPluginStacktrace)({
- stacktrace: res.msg,
- sourceMapFile: (0, sourceMap_1.resolveUTSPluginSourceMapFile)('swift', filename, inputDir, outputDir),
- sourceRoot: inputDir,
- })));
- }
- else {
- isSuccess = true;
- }
- }
- else if (res.type === 'kotlin') {
- if (res.changed.length) {
- isSuccess = true;
- }
- }
- if (isSuccess) {
- // 生成缓存文件
- if (cacheDir) {
- // 存储 sourcemap
- (0, manifest_1.storeSourceMap)(utsPlatform, pluginRelativeDir, outputDir, cacheDir, pkg.is_uni_modules);
- // 生成 manifest
- (0, manifest_1.genManifestFile)(utsPlatform, {
- pluginDir,
- env,
- cacheDir,
- pluginRelativeDir,
- is_uni_modules: pkg.is_uni_modules,
- });
- }
- if (tips) {
- warn(tips);
- }
- if (versionTips) {
- warn(versionTips);
- }
- }
- const files = [];
- if (process.env.UNI_APP_UTS_CHANGED_FILES) {
- try {
- files.push(...JSON.parse(process.env.UNI_APP_UTS_CHANGED_FILES));
- }
- catch (e) { }
- }
- if (res.changed && res.changed.length) {
- files.push(...res.changed);
- }
- else {
- if (res.type === 'kotlin') {
- errMsg = compileErrMsg(pkg.id);
- }
- }
- process.env.UNI_APP_UTS_CHANGED_FILES = JSON.stringify([
- ...new Set(files),
- ]);
- }
- else {
- errMsg = compileErrMsg(pkg.id);
- }
- }
- }
- }
- return createResult(outputPluginDir, errMsg, code, deps, meta);
- }
- exports.compile = compile;
- function getCompiler(type) {
- if (type === 'swift') {
- return {
- runProd: swift_1.runSwiftProd,
- runDev: swift_1.runSwiftDev,
- checkVersionTips: swift_1.checkIOSVersionTips,
- };
- }
- return {
- runProd: kotlin_1.runKotlinProd,
- runDev: kotlin_1.runKotlinDev,
- checkVersionTips: kotlin_1.checkAndroidVersionTips,
- };
- }
|