@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/swift.js ADDED
@@ -0,0 +1,183 @@
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.checkIOSVersionTips = exports.resolveIOSDepFiles = exports.compile = exports.runSwiftDev = exports.runSwiftProd = void 0;
30
+ const fs_extra_1 = __importDefault(require("fs-extra"));
31
+ const path_1 = __importStar(require("path"));
32
+ const shared_1 = require("@vue/shared");
33
+ const utils_1 = require("./utils");
34
+ const shared_2 = require("./shared");
35
+ function parseSwiftPackage(filename) {
36
+ const res = (0, utils_1.resolvePackage)(filename);
37
+ if (!res) {
38
+ return {
39
+ namespace: '',
40
+ };
41
+ }
42
+ const namespace = 'UTSSDK' + (res.is_uni_modules ? 'Modules' : '') + (0, shared_1.capitalize)(res.name);
43
+ return {
44
+ namespace,
45
+ };
46
+ }
47
+ async function runSwiftProd(filename) {
48
+ // 文件有可能是 app-android 里边的,因为编译到 ios 时,为了保证不报错,可能会去读取 android 下的 uts
49
+ if (filename.includes('app-android')) {
50
+ return;
51
+ }
52
+ const inputDir = process.env.UNI_INPUT_DIR;
53
+ const outputDir = process.env.UNI_OUTPUT_DIR;
54
+ await compile(filename, { inputDir, outputDir, sourceMap: true });
55
+ (0, utils_1.genUTSPlatformResource)(filename, {
56
+ inputDir,
57
+ outputDir,
58
+ platform: 'app-ios',
59
+ extname: '.swift',
60
+ });
61
+ }
62
+ exports.runSwiftProd = runSwiftProd;
63
+ let isEnvReady = true;
64
+ async function runSwiftDev(filename) {
65
+ var _a;
66
+ // 文件有可能是 app-android 里边的,因为编译到 ios 时,为了保证不报错,可能会去读取 android 下的 uts
67
+ if (filename.includes('app-android')) {
68
+ return;
69
+ }
70
+ if (!isEnvReady) {
71
+ console.error(`已跳过uts插件[${(_a = (0, utils_1.resolvePackage)(filename)) === null || _a === void 0 ? void 0 : _a.id}]的编译`);
72
+ return;
73
+ }
74
+ const compilerServer = (0, utils_1.getCompilerServer)('uts-development-ios');
75
+ if (!compilerServer) {
76
+ throw `项目使用了uts插件,正在安装 uts iOS 运行扩展...`;
77
+ }
78
+ if (compilerServer.checkEnv) {
79
+ const { code, msg } = compilerServer.checkEnv();
80
+ if (code) {
81
+ isEnvReady = false;
82
+ console.error(msg);
83
+ return;
84
+ }
85
+ }
86
+ const inputDir = process.env.UNI_INPUT_DIR;
87
+ const outputDir = process.env.UNI_OUTPUT_DIR;
88
+ const result = (await compile(filename, {
89
+ inputDir,
90
+ outputDir,
91
+ sourceMap: true,
92
+ }));
93
+ result.type = 'swift';
94
+ const swiftFile = (0, utils_1.resolveUTSPlatformFile)(filename, {
95
+ inputDir,
96
+ outputDir,
97
+ platform: 'app-ios',
98
+ extname: '.swift',
99
+ });
100
+ result.changed = [];
101
+ // 开发模式下,需要生成 framework
102
+ if (fs_extra_1.default.existsSync(swiftFile)) {
103
+ let projectPath = inputDir;
104
+ const isCli = isCliProject(projectPath);
105
+ if (isCli) {
106
+ projectPath = path_1.default.resolve(projectPath, '..');
107
+ }
108
+ const { id, is_uni_modules } = (0, utils_1.resolvePackage)(filename);
109
+ const { code, msg } = await compilerServer.compile({
110
+ projectPath,
111
+ isCli,
112
+ type: 1,
113
+ pluginName: id,
114
+ utsPath: resolveCompilerUtsPath(inputDir, is_uni_modules),
115
+ swiftPath: resolveCompilerSwiftPath(outputDir, is_uni_modules),
116
+ });
117
+ result.code = code;
118
+ result.msg = msg;
119
+ result.changed = [swiftFile];
120
+ }
121
+ return result;
122
+ }
123
+ exports.runSwiftDev = runSwiftDev;
124
+ function resolveCompilerUtsPath(projectPath, is_uni_modules) {
125
+ return path_1.default.resolve(projectPath, is_uni_modules ? 'uni_modules' : 'utssdk');
126
+ }
127
+ function resolveCompilerSwiftPath(outputDir, is_uni_modules) {
128
+ return path_1.default.resolve(outputDir, is_uni_modules ? 'uni_modules' : 'utssdk');
129
+ }
130
+ function isCliProject(projectPath) {
131
+ if (projectPath.endsWith('src')) {
132
+ return true;
133
+ }
134
+ return false;
135
+ }
136
+ async function compile(filename, { inputDir, outputDir, sourceMap }) {
137
+ const { bundle, UtsTarget } = (0, utils_1.getUtsCompiler)();
138
+ // let time = Date.now()
139
+ const result = await bundle(UtsTarget.SWIFT, {
140
+ input: {
141
+ root: inputDir,
142
+ filename,
143
+ },
144
+ output: {
145
+ isPlugin: true,
146
+ outDir: outputDir,
147
+ package: parseSwiftPackage(filename).namespace,
148
+ sourceMap: sourceMap ? (0, utils_1.resolveUTSSourceMapPath)() : false,
149
+ extname: 'swift',
150
+ imports: ['DCloudUTSFoundation'],
151
+ logFilename: true,
152
+ noColor: (0, shared_2.isInHBuilderX)(),
153
+ },
154
+ });
155
+ sourceMap &&
156
+ (0, utils_1.moveRootIndexSourceMap)(filename, {
157
+ inputDir,
158
+ outputDir,
159
+ platform: 'app-ios',
160
+ extname: '.swift',
161
+ });
162
+ return result;
163
+ }
164
+ exports.compile = compile;
165
+ const deps = ['Info.plist', 'config.json'];
166
+ function resolveIOSDepFiles(filename) {
167
+ const dir = (0, utils_1.resolveIOSDir)(filename);
168
+ return deps.map((dep) => path_1.default.resolve(dir, dep));
169
+ }
170
+ exports.resolveIOSDepFiles = resolveIOSDepFiles;
171
+ function checkIOSVersionTips(pluginId, pluginDir, is_uni_modules) {
172
+ const configJsonFile = (0, path_1.join)(pluginDir, is_uni_modules ? 'utssdk' : '', 'app-ios', 'config.json');
173
+ if (configJsonFile && fs_extra_1.default.existsSync(configJsonFile)) {
174
+ try {
175
+ const configJson = (0, shared_2.parseJson)(fs_extra_1.default.readFileSync(configJsonFile, 'utf8'));
176
+ if (configJson.deploymentTarget) {
177
+ return `uts插件[${pluginId}]需在 iOS ${configJson.deploymentTarget} 版本及以上方可正常使用`;
178
+ }
179
+ }
180
+ catch (e) { }
181
+ }
182
+ }
183
+ exports.checkIOSVersionTips = checkIOSVersionTips;
@@ -0,0 +1,38 @@
1
+ import type { parse, bundle, UtsTarget } from '@dcloudio/uts';
2
+ import { Module } from '../types/types';
3
+ interface ToOptions {
4
+ inputDir: string;
5
+ outputDir: string;
6
+ sourceMap: boolean;
7
+ }
8
+ export type ToKotlinOptions = ToOptions;
9
+ export type ToSwiftOptions = ToOptions;
10
+ export declare const ERR_MSG_PLACEHOLDER = "___ERR_MSG___";
11
+ export declare function resolveUTSSourceMapPath(): string;
12
+ export declare function getUtsCompiler(): {
13
+ parse: typeof parse;
14
+ bundle: typeof bundle;
15
+ UtsTarget: typeof UtsTarget;
16
+ };
17
+ export declare function resolvePackage(filename: string): {
18
+ id: string;
19
+ name: string;
20
+ namespace: string;
21
+ is_uni_modules: boolean;
22
+ } | undefined;
23
+ export interface UTSPlatformResourceOptions {
24
+ inputDir: string;
25
+ outputDir: string;
26
+ platform: typeof process.env.UNI_UTS_PLATFORM;
27
+ extname: '.kt' | '.swift';
28
+ }
29
+ export declare function genUTSPlatformResource(filename: string, options: UTSPlatformResourceOptions): void;
30
+ export declare function moveRootIndexSourceMap(filename: string, { inputDir, platform, extname }: UTSPlatformResourceOptions): void;
31
+ export declare function isRootIndex(filename: string, platform: typeof process.env.UNI_UTS_PLATFORM): boolean;
32
+ export declare function resolveAndroidDir(filename: string): string;
33
+ export declare function resolveIOSDir(filename: string): string;
34
+ export declare function resolveUTSPlatformFile(filename: string, { inputDir, outputDir, platform, extname }: UTSPlatformResourceOptions): string;
35
+ export declare function createResolveTypeReferenceName(namespace: string, ast: Module): (name: string) => string;
36
+ export type CompilerServer = {};
37
+ export declare function getCompilerServer<T extends CompilerServer>(pluginName: 'uts-development-ios' | 'uniapp-runextension'): T | undefined;
38
+ export {};
package/dist/utils.js ADDED
@@ -0,0 +1,148 @@
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.getCompilerServer = exports.createResolveTypeReferenceName = exports.resolveUTSPlatformFile = exports.resolveIOSDir = exports.resolveAndroidDir = exports.isRootIndex = exports.moveRootIndexSourceMap = exports.genUTSPlatformResource = exports.resolvePackage = exports.getUtsCompiler = exports.resolveUTSSourceMapPath = exports.ERR_MSG_PLACEHOLDER = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const shared_1 = require("@vue/shared");
10
+ const shared_2 = require("./shared");
11
+ exports.ERR_MSG_PLACEHOLDER = `___ERR_MSG___`;
12
+ function resolveUTSSourceMapPath() {
13
+ return (0, shared_2.resolveSourceMapPath)();
14
+ }
15
+ exports.resolveUTSSourceMapPath = resolveUTSSourceMapPath;
16
+ function getUtsCompiler() {
17
+ // eslint-disable-next-line no-restricted-globals
18
+ return require('@dcloudio/uts');
19
+ }
20
+ exports.getUtsCompiler = getUtsCompiler;
21
+ function resolvePackage(filename) {
22
+ const parts = (0, shared_2.normalizePath)(filename).split('/');
23
+ const isUniModules = parts.includes('uni_modules');
24
+ const index = isUniModules
25
+ ? parts.findIndex((part) => part === 'uni_modules')
26
+ : parts.findIndex((part) => part === 'utssdk');
27
+ if (index > -1) {
28
+ const id = parts[index + 1];
29
+ const name = (0, shared_1.camelize)(id);
30
+ return {
31
+ id,
32
+ name,
33
+ namespace: 'UTSSDK' + (isUniModules ? 'Modules' : '') + (0, shared_1.capitalize)(name),
34
+ is_uni_modules: isUniModules,
35
+ };
36
+ }
37
+ }
38
+ exports.resolvePackage = resolvePackage;
39
+ function genUTSPlatformResource(filename, options) {
40
+ const platformFile = resolveUTSPlatformFile(filename, options);
41
+ const { platform } = options;
42
+ const utsInputDir = resolveUTSPlatformDir(filename, platform);
43
+ const utsOutputDir = resolveUTSPlatformDir(platformFile, platform);
44
+ // 拷贝所有非uts文件及目录
45
+ if (fs_extra_1.default.existsSync(utsInputDir)) {
46
+ fs_extra_1.default.copySync(utsInputDir, utsOutputDir, {
47
+ filter(src) {
48
+ return path_1.default.extname(src) !== '.uts';
49
+ },
50
+ });
51
+ }
52
+ // 生产模式下,需要将生成的平台文件转移到 src 下
53
+ const srcDir = path_1.default.resolve(utsOutputDir, 'src');
54
+ if (!fs_extra_1.default.existsSync(srcDir)) {
55
+ fs_extra_1.default.mkdirSync(srcDir);
56
+ }
57
+ if (fs_extra_1.default.existsSync(platformFile)) {
58
+ fs_extra_1.default.moveSync(platformFile, path_1.default.resolve(utsOutputDir, 'src/index' + options.extname), {
59
+ overwrite: true,
60
+ });
61
+ }
62
+ }
63
+ exports.genUTSPlatformResource = genUTSPlatformResource;
64
+ function moveRootIndexSourceMap(filename, { inputDir, platform, extname }) {
65
+ if (isRootIndex(filename, platform)) {
66
+ const sourceMapFilename = path_1.default
67
+ .resolve(resolveUTSSourceMapPath(), path_1.default.relative(inputDir, filename))
68
+ .replace(path_1.default.extname(filename), extname + '.map');
69
+ if (fs_extra_1.default.existsSync(sourceMapFilename)) {
70
+ const newSourceMapFilename = path_1.default.resolve(path_1.default.dirname(sourceMapFilename), platform, path_1.default.basename(sourceMapFilename));
71
+ fs_extra_1.default.moveSync(sourceMapFilename, newSourceMapFilename, {
72
+ overwrite: true,
73
+ });
74
+ }
75
+ }
76
+ }
77
+ exports.moveRootIndexSourceMap = moveRootIndexSourceMap;
78
+ function isRootIndex(filename, platform) {
79
+ return path_1.default.basename(path_1.default.dirname(filename)) !== platform;
80
+ }
81
+ exports.isRootIndex = isRootIndex;
82
+ function resolveAndroidDir(filename) {
83
+ return resolveUTSPlatformDir(filename, 'app-android');
84
+ }
85
+ exports.resolveAndroidDir = resolveAndroidDir;
86
+ function resolveIOSDir(filename) {
87
+ return resolveUTSPlatformDir(filename, 'app-ios');
88
+ }
89
+ exports.resolveIOSDir = resolveIOSDir;
90
+ function resolveUTSPlatformDir(filename, platform) {
91
+ const maybePlatformDir = path_1.default.dirname(filename);
92
+ if (isRootIndex(filename, platform)) {
93
+ return path_1.default.join(maybePlatformDir, platform);
94
+ }
95
+ return maybePlatformDir;
96
+ }
97
+ function resolveUTSPlatformFile(filename, { inputDir, outputDir, platform, extname }) {
98
+ let platformFile = path_1.default
99
+ .resolve(outputDir, path_1.default.relative(inputDir, filename))
100
+ .replace(path_1.default.extname(filename), extname);
101
+ // 如果是根目录的 index.uts 编译出来的 index.kt,则移动到平台目录下
102
+ if (isRootIndex(filename, platform)) {
103
+ if (fs_extra_1.default.existsSync(platformFile)) {
104
+ const newPlatformFile = path_1.default.resolve(path_1.default.dirname(platformFile), platform + '/index' + extname);
105
+ fs_extra_1.default.moveSync(platformFile, newPlatformFile, {
106
+ overwrite: true,
107
+ });
108
+ platformFile = newPlatformFile;
109
+ }
110
+ }
111
+ return platformFile;
112
+ }
113
+ exports.resolveUTSPlatformFile = resolveUTSPlatformFile;
114
+ function resolveTypeAliasDeclNames(items) {
115
+ const names = [];
116
+ items.forEach((item) => {
117
+ if (item.type === 'TsTypeAliasDeclaration') {
118
+ names.push(item.id.value);
119
+ }
120
+ });
121
+ return names;
122
+ }
123
+ function createResolveTypeReferenceName(namespace, ast) {
124
+ const names = resolveTypeAliasDeclNames(ast.body);
125
+ return (name) => {
126
+ if (names.includes(name)) {
127
+ return namespace + (0, shared_1.capitalize)(name);
128
+ }
129
+ return name;
130
+ };
131
+ }
132
+ exports.createResolveTypeReferenceName = createResolveTypeReferenceName;
133
+ function getCompilerServer(pluginName) {
134
+ const compilerServerPath = path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, `${pluginName}/out/${pluginName === 'uniapp-runextension' ? 'main.js' : 'external.js'}`);
135
+ if (fs_extra_1.default.existsSync(compilerServerPath)) {
136
+ // eslint-disable-next-line no-restricted-globals
137
+ return require(compilerServerPath);
138
+ }
139
+ else {
140
+ if ((0, shared_2.runByHBuilderX)()) {
141
+ (0, shared_2.installHBuilderXPlugin)(pluginName);
142
+ }
143
+ else {
144
+ console.error(compilerServerPath + ' is not found');
145
+ }
146
+ }
147
+ }
148
+ exports.getCompilerServer = getCompilerServer;
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@dcloudio/uni-uts-v1",
3
+ "version": "3.0.0-3061320221209001",
4
+ "description": "uni-uts-v1",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/dcloudio/uni-app.git",
13
+ "directory": "packages/uni-uts-v1"
14
+ },
15
+ "scripts": {
16
+ "test": "echo \"Error: no test specified\" && exit 1"
17
+ },
18
+ "license": "Apache-2.0",
19
+ "dependencies": {
20
+ "@dcloudio/uts": "3.0.0-3061320221209001",
21
+ "@vue/shared": "3.2.45",
22
+ "android-versions": "^1.8.1",
23
+ "adm-zip": "^0.5.9",
24
+ "fast-glob": "^3.2.11",
25
+ "fs-extra": "^10.0.0",
26
+ "jsonc-parser": "^3.0.0",
27
+ "md5-file": "^5.0.0",
28
+ "source-map": "^0.7.4"
29
+ },
30
+ "devDependencies": {
31
+ "@types/adm-zip": "^0.5.0",
32
+ "@types/android-versions": "^1.8.0",
33
+ "@types/fs-extra": "^9.0.13"
34
+ }
35
+ }