@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
|
@@ -0,0 +1,176 @@
|
|
|
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.resolveManifestJson = exports.isCustomResources = exports.hasCustomResources = exports.checkManifest = exports.resolvePluginFiles = exports.genManifestJson = exports.genManifestFile = exports.hash = void 0;
|
|
7
|
+
const fs_extra_1 = require("fs-extra");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const md5_file_1 = __importDefault(require("md5-file"));
|
|
10
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
11
|
+
const fileCaches = new Map();
|
|
12
|
+
const VERSION = '1';
|
|
13
|
+
/**
|
|
14
|
+
* 计算文件 md5(有缓存)
|
|
15
|
+
* @param file
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
async function hash(file) {
|
|
19
|
+
const cache = fileCaches.get(file);
|
|
20
|
+
const stat = (0, fs_extra_1.statSync)(file);
|
|
21
|
+
if (cache && cache.mtimeMs === stat.mtimeMs) {
|
|
22
|
+
return cache.md5;
|
|
23
|
+
}
|
|
24
|
+
return (0, md5_file_1.default)(file).then((value) => {
|
|
25
|
+
fileCaches.set(file, { mtimeMs: stat.mtimeMs, md5: value });
|
|
26
|
+
return value;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.hash = hash;
|
|
30
|
+
async function genManifestFile(platform, { files, pluginDir, env, cacheDir, pluginRelativeDir, is_uni_modules, }) {
|
|
31
|
+
(0, fs_extra_1.outputFileSync)(resolveManifestFilename(platform, pluginRelativeDir, cacheDir), JSON.stringify(await genManifestJson(platform, {
|
|
32
|
+
pluginDir,
|
|
33
|
+
files,
|
|
34
|
+
env,
|
|
35
|
+
is_uni_modules,
|
|
36
|
+
}), null, 2));
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
exports.genManifestFile = genManifestFile;
|
|
40
|
+
async function genManifestJson(platform, { pluginDir, files, env, is_uni_modules }) {
|
|
41
|
+
if (!files) {
|
|
42
|
+
files = await resolvePluginFiles(platform, pluginDir, is_uni_modules);
|
|
43
|
+
}
|
|
44
|
+
if (!files) {
|
|
45
|
+
files = [];
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
version: VERSION,
|
|
49
|
+
env,
|
|
50
|
+
files: await genManifestFiles(pluginDir, files),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.genManifestJson = genManifestJson;
|
|
54
|
+
async function genManifestFiles(dir, files) {
|
|
55
|
+
const manifestFiles = {};
|
|
56
|
+
// 优先 uts 文件
|
|
57
|
+
files = files.sort((a, b) => {
|
|
58
|
+
const aUts = a.endsWith('.uts');
|
|
59
|
+
const bUts = b.endsWith('.uts');
|
|
60
|
+
if (aUts && bUts) {
|
|
61
|
+
return a > b ? 1 : -1;
|
|
62
|
+
}
|
|
63
|
+
if (aUts) {
|
|
64
|
+
return -1;
|
|
65
|
+
}
|
|
66
|
+
return 1;
|
|
67
|
+
});
|
|
68
|
+
const md5Arr = await Promise.all(files.map((file) => hash((0, path_1.join)(dir, file))));
|
|
69
|
+
files.forEach((name, index) => {
|
|
70
|
+
manifestFiles[name] = {
|
|
71
|
+
md5: md5Arr[index],
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
return manifestFiles;
|
|
75
|
+
}
|
|
76
|
+
async function resolvePluginCommonFiles(pluginDir, is_uni_modules) {
|
|
77
|
+
const patterns = ['*'];
|
|
78
|
+
if (is_uni_modules) {
|
|
79
|
+
patterns.push('utssdk/*.uts');
|
|
80
|
+
patterns.push('utssdk/common/**/*');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
patterns.push('common/**/*');
|
|
84
|
+
}
|
|
85
|
+
return (0, fast_glob_1.default)(patterns, {
|
|
86
|
+
ignore: ['changelog.md', 'readme.md'],
|
|
87
|
+
cwd: pluginDir,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
async function resolvePluginFiles(platform, pluginDir, is_uni_modules) {
|
|
91
|
+
return Promise.all([
|
|
92
|
+
resolvePluginCommonFiles(pluginDir, is_uni_modules),
|
|
93
|
+
resolvePluginPlatformFiles(platform, pluginDir, is_uni_modules),
|
|
94
|
+
]).then((files) => files.flat());
|
|
95
|
+
}
|
|
96
|
+
exports.resolvePluginFiles = resolvePluginFiles;
|
|
97
|
+
async function resolvePluginPlatformFiles(platform, pluginDir, is_uni_modules) {
|
|
98
|
+
return (0, fast_glob_1.default)((is_uni_modules ? 'utssdk/' : '') + platform + '/**/*', {
|
|
99
|
+
cwd: pluginDir,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async function checkManifest(manifest, { env, files, pluginDir, }) {
|
|
103
|
+
if (manifest.version !== VERSION) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (isEnvExpired(manifest.env, env)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return checkFiles(manifest.files, files, pluginDir);
|
|
110
|
+
}
|
|
111
|
+
exports.checkManifest = checkManifest;
|
|
112
|
+
/**
|
|
113
|
+
* 判断 env 是否过期
|
|
114
|
+
* @param value
|
|
115
|
+
* @param other
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
function isEnvExpired(value, other) {
|
|
119
|
+
const valueKeys = Object.keys(value);
|
|
120
|
+
const otherKeys = Object.keys(other);
|
|
121
|
+
if (valueKeys.length !== otherKeys.length) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
if (valueKeys.find((name) => value[name] !== other[name])) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 判断文件列表是否过期
|
|
131
|
+
* @param files
|
|
132
|
+
* @param filenames
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
135
|
+
async function checkFiles(files, filenames, pluginDir) {
|
|
136
|
+
const oldFilenames = Object.keys(files);
|
|
137
|
+
// 第一步:优先判断文件列表长度
|
|
138
|
+
if (oldFilenames.length !== filenames.length) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
// 第二步:判断文件列表
|
|
142
|
+
if (oldFilenames.find((name) => !filenames.includes(name))) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
// 第三步:判断文件 md5
|
|
146
|
+
for (const name of oldFilenames) {
|
|
147
|
+
const md5 = await hash((0, path_1.join)(pluginDir, name));
|
|
148
|
+
if (files[name].md5 !== md5) {
|
|
149
|
+
return name;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
function hasCustomResources(files, resources) {
|
|
155
|
+
if (files.some((file) => isCustomResources(file, resources))) {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.hasCustomResources = hasCustomResources;
|
|
160
|
+
function isCustomResources(file, resources) {
|
|
161
|
+
return resources.some((res) => file.includes(res));
|
|
162
|
+
}
|
|
163
|
+
exports.isCustomResources = isCustomResources;
|
|
164
|
+
function resolveManifestFilename(platform, pluginRelativeDir, cacheDir) {
|
|
165
|
+
return (0, path_1.join)(cacheDir, platform, 'uts', pluginRelativeDir, 'manifest.json');
|
|
166
|
+
}
|
|
167
|
+
function resolveManifestJson(platform, pluginRelativeDir, cacheDir) {
|
|
168
|
+
const file = resolveManifestFilename(platform, pluginRelativeDir, cacheDir);
|
|
169
|
+
if ((0, fs_extra_1.existsSync)(file)) {
|
|
170
|
+
try {
|
|
171
|
+
return JSON.parse((0, fs_extra_1.readFileSync)(file, 'utf8'));
|
|
172
|
+
}
|
|
173
|
+
catch (e) { }
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.resolveManifestJson = resolveManifestJson;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { APP_PLATFORM } from './utils';
|
|
2
|
+
/**
|
|
3
|
+
* 缓存 sourcemap
|
|
4
|
+
* @param pluginRelativeDir
|
|
5
|
+
* @param outputDir
|
|
6
|
+
* @param cacheDir
|
|
7
|
+
*/
|
|
8
|
+
export declare function storeSourceMap(platform: APP_PLATFORM, pluginRelativeDir: string, outputDir: string, cacheDir: string, is_uni_modules: boolean): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 拷贝 sourcemap
|
|
11
|
+
* @param pluginRelativeDir
|
|
12
|
+
* @param outputDir
|
|
13
|
+
* @param cacheDir
|
|
14
|
+
*/
|
|
15
|
+
export declare function restoreSourceMap(platform: APP_PLATFORM, pluginRelativeDir: string, outputDir: string, cacheDir: string, is_uni_modules: boolean): void;
|
|
16
|
+
export declare function resolveSourceMapFilename(platform: APP_PLATFORM, pluginRelativeDir: string, outputDir: string, is_uni_modules: boolean): string;
|
|
17
|
+
export declare function resolveSourceMapCacheFilename(platform: APP_PLATFORM, cacheDir: string, pluginRelativeDir: string): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveSourceMapCacheFilename = exports.resolveSourceMapFilename = exports.restoreSourceMap = exports.storeSourceMap = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const shared_1 = require("../shared");
|
|
7
|
+
function getSourceMapFilename(platform) {
|
|
8
|
+
return `index${platform === 'app-android' ? '.kt' : '.swift'}.map`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 缓存 sourcemap
|
|
12
|
+
* @param pluginRelativeDir
|
|
13
|
+
* @param outputDir
|
|
14
|
+
* @param cacheDir
|
|
15
|
+
*/
|
|
16
|
+
function storeSourceMap(platform, pluginRelativeDir, outputDir, cacheDir, is_uni_modules) {
|
|
17
|
+
const sourceMapFilename = resolveSourceMapFilename(platform, pluginRelativeDir, outputDir, is_uni_modules);
|
|
18
|
+
if ((0, fs_extra_1.existsSync)(sourceMapFilename)) {
|
|
19
|
+
(0, fs_extra_1.copySync)(sourceMapFilename, resolveSourceMapCacheFilename(platform, cacheDir, pluginRelativeDir));
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
exports.storeSourceMap = storeSourceMap;
|
|
25
|
+
/**
|
|
26
|
+
* 拷贝 sourcemap
|
|
27
|
+
* @param pluginRelativeDir
|
|
28
|
+
* @param outputDir
|
|
29
|
+
* @param cacheDir
|
|
30
|
+
*/
|
|
31
|
+
function restoreSourceMap(platform, pluginRelativeDir, outputDir, cacheDir, is_uni_modules) {
|
|
32
|
+
const sourceMapCacheFile = resolveSourceMapCacheFile(platform, cacheDir, pluginRelativeDir);
|
|
33
|
+
if (sourceMapCacheFile) {
|
|
34
|
+
(0, fs_extra_1.copySync)(sourceMapCacheFile, resolveSourceMapFilename(platform, pluginRelativeDir, outputDir, is_uni_modules));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.restoreSourceMap = restoreSourceMap;
|
|
38
|
+
function resolveSourceMapFilename(platform, pluginRelativeDir, outputDir, is_uni_modules) {
|
|
39
|
+
return (0, path_1.join)((0, shared_1.resolveSourceMapPath)(outputDir, 'app'), pluginRelativeDir, is_uni_modules ? 'utssdk' : '', platform, getSourceMapFilename(platform));
|
|
40
|
+
}
|
|
41
|
+
exports.resolveSourceMapFilename = resolveSourceMapFilename;
|
|
42
|
+
function resolveSourceMapCacheFilename(platform, cacheDir, pluginRelativeDir) {
|
|
43
|
+
return (0, path_1.join)(cacheDir, platform, 'uts', pluginRelativeDir, getSourceMapFilename(platform));
|
|
44
|
+
}
|
|
45
|
+
exports.resolveSourceMapCacheFilename = resolveSourceMapCacheFilename;
|
|
46
|
+
function resolveSourceMapCacheFile(platform, cacheDir, pluginRelativeDir) {
|
|
47
|
+
const file = resolveSourceMapCacheFilename(platform, cacheDir, pluginRelativeDir);
|
|
48
|
+
return ((0, fs_extra_1.existsSync)(file) && file) || '';
|
|
49
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type APP_PLATFORM = 'app-android' | 'app-ios';
|
|
2
|
+
export interface CheckOptions {
|
|
3
|
+
id: string;
|
|
4
|
+
env: Record<string, unknown>;
|
|
5
|
+
pluginDir: string;
|
|
6
|
+
pluginRelativeDir: string;
|
|
7
|
+
cacheDir: string;
|
|
8
|
+
outputDir: string;
|
|
9
|
+
is_uni_modules: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface CheckResult {
|
|
12
|
+
expired: boolean;
|
|
13
|
+
tips?: string;
|
|
14
|
+
files: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare function customResourceTips(id: string): string;
|
|
17
|
+
export declare function customResourceChangedTips(id: string): string;
|
|
18
|
+
export declare function cacheTips(id: string): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cacheTips = exports.customResourceChangedTips = exports.customResourceTips = void 0;
|
|
4
|
+
function customResourceTips(id) {
|
|
5
|
+
return `uts插件[${id}]依赖的原生配置或三方SDK在运行至标准基座时不能生效,如需正常调用请使用自定义基座`;
|
|
6
|
+
}
|
|
7
|
+
exports.customResourceTips = customResourceTips;
|
|
8
|
+
function customResourceChangedTips(id) {
|
|
9
|
+
return `uts插件[${id}]依赖的原生配置或三方SDK发生变化,需要重新打包自定义基座`;
|
|
10
|
+
}
|
|
11
|
+
exports.customResourceChangedTips = customResourceChangedTips;
|
|
12
|
+
function cacheTips(id) {
|
|
13
|
+
return `uts插件[${id}]文件未发生变化,跳过编译`;
|
|
14
|
+
}
|
|
15
|
+
exports.cacheTips = cacheTips;
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function parseJson(jsonStr: string): any;
|
|
2
|
+
export declare function once<T extends (...args: any[]) => any>(fn: T, ctx?: unknown): T;
|
|
3
|
+
export declare const runByHBuilderX: () => boolean;
|
|
4
|
+
export declare const isInHBuilderX: () => boolean;
|
|
5
|
+
export declare function resolveSourceMapPath(outputDir?: string, platform?: UniApp.PLATFORM): string;
|
|
6
|
+
export declare const isWindows: boolean;
|
|
7
|
+
export declare function normalizePath(id: string): string;
|
|
8
|
+
export declare function installHBuilderXPlugin(plugin: string): void;
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
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.installHBuilderXPlugin = exports.normalizePath = exports.isWindows = exports.resolveSourceMapPath = exports.isInHBuilderX = exports.runByHBuilderX = exports.once = exports.parseJson = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const jsonc_parser_1 = require("jsonc-parser");
|
|
10
|
+
function parseJson(jsonStr) {
|
|
11
|
+
return (0, jsonc_parser_1.parse)(jsonStr);
|
|
12
|
+
}
|
|
13
|
+
exports.parseJson = parseJson;
|
|
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
|
+
}
|
|
24
|
+
exports.once = once;
|
|
25
|
+
exports.runByHBuilderX = once(() => {
|
|
26
|
+
return (!!process.env.UNI_HBUILDERX_PLUGINS &&
|
|
27
|
+
(!!process.env.RUN_BY_HBUILDERX || !!process.env.HX_Version));
|
|
28
|
+
});
|
|
29
|
+
exports.isInHBuilderX = once(() => {
|
|
30
|
+
try {
|
|
31
|
+
// eslint-disable-next-line no-restricted-globals
|
|
32
|
+
const { name } = require(path_1.default.resolve(process.cwd(), '../about/package.json'));
|
|
33
|
+
if (name === 'about') {
|
|
34
|
+
process.env.UNI_HBUILDERX_PLUGINS = path_1.default.resolve(process.cwd(), '..');
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
// console.error(e)
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
});
|
|
43
|
+
function resolveSourceMapPath(outputDir, platform) {
|
|
44
|
+
let dir = platform || process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM;
|
|
45
|
+
if (dir === 'app-plus') {
|
|
46
|
+
dir = 'app';
|
|
47
|
+
}
|
|
48
|
+
return path_1.default.resolve(outputDir || process.env.UNI_OUTPUT_DIR, '../.sourcemap/' + dir);
|
|
49
|
+
}
|
|
50
|
+
exports.resolveSourceMapPath = resolveSourceMapPath;
|
|
51
|
+
exports.isWindows = os_1.default.platform() === 'win32';
|
|
52
|
+
function normalizePath(id) {
|
|
53
|
+
return exports.isWindows ? id.replace(/\\/g, '/') : id;
|
|
54
|
+
}
|
|
55
|
+
exports.normalizePath = normalizePath;
|
|
56
|
+
function supportAutoInstallPlugin() {
|
|
57
|
+
return !!process.env.HX_Version;
|
|
58
|
+
}
|
|
59
|
+
function installHBuilderXPlugin(plugin) {
|
|
60
|
+
if (!supportAutoInstallPlugin()) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
return console.error(`%HXRunUniAPPPluginName%${plugin}%HXRunUniAPPPluginName%`);
|
|
64
|
+
}
|
|
65
|
+
exports.installHBuilderXPlugin = installHBuilderXPlugin;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { NullableMappedPosition, NullablePosition } from 'source-map';
|
|
2
|
+
export declare function resolveUtsPluginSourceMapFile(target: 'kotlin' | 'swift', filename: string, inputDir: string, outputDir: string): string;
|
|
3
|
+
interface PositionFor {
|
|
4
|
+
sourceMapFile: string;
|
|
5
|
+
filename: string;
|
|
6
|
+
line: number;
|
|
7
|
+
column: number;
|
|
8
|
+
withSourceContent?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 根据源码文件名、行号、列号,返回生成后文件、行号、列号(根据 uts 文件返回 kt|swift 文件)
|
|
12
|
+
* @param originalPosition
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function generatedPositionFor({ sourceMapFile, filename, line, column, outputDir, }: PositionFor & {
|
|
16
|
+
outputDir?: string;
|
|
17
|
+
}): Promise<NullablePosition & {
|
|
18
|
+
source: string | null;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* 根据生成后的文件名、行号、列号,返回源码文件、行号、列号(根据 kt|swift 文件返回 uts 文件)
|
|
22
|
+
* @param generatedPosition
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare function originalPositionFor(generatedPosition: Omit<PositionFor, 'filename'> & {
|
|
26
|
+
inputDir?: string;
|
|
27
|
+
}): Promise<NullableMappedPosition & {
|
|
28
|
+
sourceContent?: string;
|
|
29
|
+
}>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.originalPositionFor = exports.generatedPositionFor = exports.resolveUtsPluginSourceMapFile = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const source_map_1 = require("source-map");
|
|
7
|
+
const EXTNAME = {
|
|
8
|
+
kotlin: '.kt',
|
|
9
|
+
swift: '.swift',
|
|
10
|
+
};
|
|
11
|
+
const PLATFORM_DIR = {
|
|
12
|
+
kotlin: 'app-android',
|
|
13
|
+
swift: 'app-ios',
|
|
14
|
+
};
|
|
15
|
+
function resolveUtsPluginSourceMapFile(target, filename, inputDir, outputDir) {
|
|
16
|
+
inputDir = normalizePath(inputDir);
|
|
17
|
+
outputDir = normalizePath(outputDir);
|
|
18
|
+
filename = normalizePath(filename);
|
|
19
|
+
const pluginDir = resolvePluginDir(inputDir, outputDir, filename);
|
|
20
|
+
if (!pluginDir) {
|
|
21
|
+
throw `plugin dir not found`;
|
|
22
|
+
}
|
|
23
|
+
const is_uni_modules = (0, path_1.basename)((0, path_1.dirname)(pluginDir)) === 'uni_modules';
|
|
24
|
+
const sourceMapFile = (0, path_1.join)((0, path_1.join)(outputDir, '../.sourcemap/app'), (0, path_1.relative)(inputDir, pluginDir), is_uni_modules ? 'utssdk' : '', PLATFORM_DIR[target], `index${EXTNAME[target]}.map`);
|
|
25
|
+
if (!(0, fs_1.existsSync)(sourceMapFile)) {
|
|
26
|
+
throw `${sourceMapFile} not found`;
|
|
27
|
+
}
|
|
28
|
+
return sourceMapFile;
|
|
29
|
+
}
|
|
30
|
+
exports.resolveUtsPluginSourceMapFile = resolveUtsPluginSourceMapFile;
|
|
31
|
+
function resolvePluginDir(inputDir, outputDir, filename) {
|
|
32
|
+
// 目标文件是编译后 kt 或 swift
|
|
33
|
+
if (filename.startsWith(outputDir)) {
|
|
34
|
+
const relativePath = (0, path_1.relative)(outputDir, filename);
|
|
35
|
+
// uni_modules/test-uts
|
|
36
|
+
if (relativePath.startsWith('uni_modules')) {
|
|
37
|
+
return (0, path_1.join)(inputDir, (0, path_1.join)(relativePath, '../../..'));
|
|
38
|
+
}
|
|
39
|
+
// utssdk/test-uts
|
|
40
|
+
return (0, path_1.join)(inputDir, (0, path_1.join)(relativePath, '../..'));
|
|
41
|
+
}
|
|
42
|
+
else if (filename.startsWith(inputDir)) {
|
|
43
|
+
let parent = (0, path_1.dirname)(filename);
|
|
44
|
+
const utssdkDir = normalizePath((0, path_1.join)(inputDir, 'utssdk'));
|
|
45
|
+
const uniModulesDir = normalizePath((0, path_1.join)(inputDir, 'uni_modules'));
|
|
46
|
+
while (parent) {
|
|
47
|
+
const dir = (0, path_1.dirname)(parent);
|
|
48
|
+
if (parent === dir) {
|
|
49
|
+
// windows 上边会剩下一个盘符
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (dir === utssdkDir || dir === uniModulesDir) {
|
|
53
|
+
return parent;
|
|
54
|
+
}
|
|
55
|
+
parent = dir;
|
|
56
|
+
}
|
|
57
|
+
throw `${filename} is not a uts plugin file`;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw `${filename} is not in ${inputDir} or ${outputDir}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
var BIAS;
|
|
64
|
+
(function (BIAS) {
|
|
65
|
+
BIAS[BIAS["GREATEST_LOWER_BOUND"] = 1] = "GREATEST_LOWER_BOUND";
|
|
66
|
+
BIAS[BIAS["LEAST_UPPER_BOUND"] = 2] = "LEAST_UPPER_BOUND";
|
|
67
|
+
})(BIAS || (BIAS = {}));
|
|
68
|
+
const consumers = {};
|
|
69
|
+
/**
|
|
70
|
+
* 解析源码文件,目前 uts 的 sourcemap 存储的都是相对目录
|
|
71
|
+
* @param consumer
|
|
72
|
+
* @param filename
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
function resolveSource(consumer, filename) {
|
|
76
|
+
filename = normalizePath(filename);
|
|
77
|
+
return (consumer.sources.find((source) => filename.endsWith(source)) || filename);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 根据源码文件名、行号、列号,返回生成后文件、行号、列号(根据 uts 文件返回 kt|swift 文件)
|
|
81
|
+
* @param originalPosition
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
function generatedPositionFor({ sourceMapFile, filename, line, column, outputDir, }) {
|
|
85
|
+
return resolveSourceMapConsumer(sourceMapFile).then((consumer) => {
|
|
86
|
+
const res = consumer.generatedPositionFor({
|
|
87
|
+
source: resolveSource(consumer, filename),
|
|
88
|
+
line,
|
|
89
|
+
column,
|
|
90
|
+
bias: column === 0 ? BIAS.LEAST_UPPER_BOUND : BIAS.GREATEST_LOWER_BOUND,
|
|
91
|
+
});
|
|
92
|
+
let source = null;
|
|
93
|
+
if (outputDir) {
|
|
94
|
+
// 根据 sourceMapFile 和 outputDir,计算出生成后的文件路径
|
|
95
|
+
source = (0, path_1.join)(outputDir, (0, path_1.relative)((0, path_1.join)(outputDir, '../.sourcemap/app'), sourceMapFile)).replace('.map', '');
|
|
96
|
+
}
|
|
97
|
+
return Object.assign(res, { source });
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.generatedPositionFor = generatedPositionFor;
|
|
101
|
+
/**
|
|
102
|
+
* 根据生成后的文件名、行号、列号,返回源码文件、行号、列号(根据 kt|swift 文件返回 uts 文件)
|
|
103
|
+
* @param generatedPosition
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
function originalPositionFor(generatedPosition) {
|
|
107
|
+
return resolveSourceMapConsumer(generatedPosition.sourceMapFile).then((consumer) => {
|
|
108
|
+
const res = consumer.originalPositionFor({
|
|
109
|
+
line: generatedPosition.line,
|
|
110
|
+
column: generatedPosition.column,
|
|
111
|
+
bias: generatedPosition.column === 0
|
|
112
|
+
? BIAS.LEAST_UPPER_BOUND
|
|
113
|
+
: BIAS.GREATEST_LOWER_BOUND,
|
|
114
|
+
});
|
|
115
|
+
if (generatedPosition.withSourceContent &&
|
|
116
|
+
res.source &&
|
|
117
|
+
res.line &&
|
|
118
|
+
res.column) {
|
|
119
|
+
return Object.assign(res, {
|
|
120
|
+
sourceContent: consumer.sourceContentFor(res.source, true),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (res.source && generatedPosition.inputDir) {
|
|
124
|
+
res.source = (0, path_1.join)(generatedPosition.inputDir, res.source);
|
|
125
|
+
}
|
|
126
|
+
return res;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
exports.originalPositionFor = originalPositionFor;
|
|
130
|
+
async function resolveSourceMapConsumer(sourceMapFile) {
|
|
131
|
+
const stats = (0, fs_1.statSync)(sourceMapFile);
|
|
132
|
+
if (!stats.isFile()) {
|
|
133
|
+
throw `${sourceMapFile} is not a file`;
|
|
134
|
+
}
|
|
135
|
+
const cache = consumers[sourceMapFile];
|
|
136
|
+
if (!cache || cache.time !== stats.mtimeMs) {
|
|
137
|
+
consumers[sourceMapFile] = {
|
|
138
|
+
time: stats.mtimeMs,
|
|
139
|
+
consumer: await new source_map_1.SourceMapConsumer((0, fs_1.readFileSync)(sourceMapFile, 'utf8')),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return consumers[sourceMapFile].consumer;
|
|
143
|
+
}
|
|
144
|
+
function normalizePath(path) {
|
|
145
|
+
return path.replace(/\\/g, '/');
|
|
146
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface ParseUtsPluginStacktraceOptions {
|
|
2
|
+
stacktrace: string;
|
|
3
|
+
sourceRoot: string;
|
|
4
|
+
sourceMapFile: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function parseUtsSwiftPluginStacktrace({ stacktrace, sourceRoot, sourceMapFile, }: ParseUtsPluginStacktraceOptions): Promise<string>;
|
|
7
|
+
export declare function generateCodeFrame(source: string, start?: number | {
|
|
8
|
+
line: number;
|
|
9
|
+
column: number;
|
|
10
|
+
}, end?: number): string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateCodeFrame = exports.parseUtsSwiftPluginStacktrace = void 0;
|
|
4
|
+
const sourceMap_1 = require("./sourceMap");
|
|
5
|
+
const splitRE = /\r?\n/;
|
|
6
|
+
const uniModulesUtsRe = /\/unimodule(.*)\/src\/index.swift:([0-9]+):([0-9]+):\s+error:\s+(.*)/;
|
|
7
|
+
async function parseUtsSwiftPluginStacktrace({ stacktrace, sourceRoot, sourceMapFile, }) {
|
|
8
|
+
const res = [];
|
|
9
|
+
const lines = stacktrace.split(splitRE);
|
|
10
|
+
for (let i = 0; i < lines.length; i++) {
|
|
11
|
+
const line = lines[i];
|
|
12
|
+
const codes = await parseUtsStacktraceLine(line, uniModulesUtsRe, sourceMapFile, sourceRoot);
|
|
13
|
+
if (codes && codes.length) {
|
|
14
|
+
res.push(...codes);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
res.push(line);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return res.join('\n');
|
|
21
|
+
}
|
|
22
|
+
exports.parseUtsSwiftPluginStacktrace = parseUtsSwiftPluginStacktrace;
|
|
23
|
+
async function parseUtsStacktraceLine(lineStr, re, sourceMapFile, sourceRoot) {
|
|
24
|
+
const uniModulesMatches = lineStr.match(re);
|
|
25
|
+
if (!uniModulesMatches) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const lines = [];
|
|
29
|
+
const [, , line, column, message] = uniModulesMatches;
|
|
30
|
+
const originalPosition = await (0, sourceMap_1.originalPositionFor)({
|
|
31
|
+
sourceMapFile,
|
|
32
|
+
line: parseInt(line),
|
|
33
|
+
column: parseInt(column),
|
|
34
|
+
withSourceContent: true,
|
|
35
|
+
});
|
|
36
|
+
lines.push(`${message}`);
|
|
37
|
+
if (originalPosition.source && originalPosition.sourceContent) {
|
|
38
|
+
lines.push(`at ${originalPosition.source}:${originalPosition.line}:${originalPosition.column}`);
|
|
39
|
+
if (originalPosition.line !== null && originalPosition.column !== null) {
|
|
40
|
+
lines.push(generateCodeFrame(originalPosition.sourceContent, {
|
|
41
|
+
line: originalPosition.line,
|
|
42
|
+
column: originalPosition.column,
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return lines;
|
|
47
|
+
}
|
|
48
|
+
const range = 2;
|
|
49
|
+
function posToNumber(source, pos) {
|
|
50
|
+
if (typeof pos === 'number')
|
|
51
|
+
return pos;
|
|
52
|
+
const lines = source.split(splitRE);
|
|
53
|
+
const { line, column } = pos;
|
|
54
|
+
let start = 0;
|
|
55
|
+
for (let i = 0; i < line - 1; i++) {
|
|
56
|
+
start += lines[i].length + 1;
|
|
57
|
+
}
|
|
58
|
+
return start + column;
|
|
59
|
+
}
|
|
60
|
+
function generateCodeFrame(source, start = 0, end) {
|
|
61
|
+
start = posToNumber(source, start);
|
|
62
|
+
end = end || start;
|
|
63
|
+
const lines = source.split(splitRE);
|
|
64
|
+
let count = 0;
|
|
65
|
+
const res = [];
|
|
66
|
+
for (let i = 0; i < lines.length; i++) {
|
|
67
|
+
count += lines[i].length + 1;
|
|
68
|
+
if (count >= start) {
|
|
69
|
+
for (let j = i - range; j <= i + range || end > count; j++) {
|
|
70
|
+
if (j < 0 || j >= lines.length)
|
|
71
|
+
continue;
|
|
72
|
+
const line = j + 1;
|
|
73
|
+
res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
|
|
74
|
+
const lineLength = lines[j].length;
|
|
75
|
+
if (j === i) {
|
|
76
|
+
// push underline
|
|
77
|
+
const pad = start - (count - lineLength) + 1;
|
|
78
|
+
const length = Math.max(1, end > count ? lineLength - pad : end - start);
|
|
79
|
+
res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
|
|
80
|
+
}
|
|
81
|
+
else if (j > i) {
|
|
82
|
+
if (end > count) {
|
|
83
|
+
const length = Math.max(Math.min(end - count, lineLength), 1);
|
|
84
|
+
res.push(` | ` + '^'.repeat(length));
|
|
85
|
+
}
|
|
86
|
+
count += lineLength + 1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return res.join('\n');
|
|
93
|
+
}
|
|
94
|
+
exports.generateCodeFrame = generateCodeFrame;
|
package/dist/swift.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ToSwiftOptions } from './utils';
|
|
2
|
+
import { UtsResult } from '@dcloudio/uts';
|
|
3
|
+
export declare function runSwiftProd(filename: string): Promise<void>;
|
|
4
|
+
export type RunSwiftDevResult = UtsResult & {
|
|
5
|
+
type: 'swift';
|
|
6
|
+
code: number;
|
|
7
|
+
msg: string;
|
|
8
|
+
changed: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare function runSwiftDev(filename: string): Promise<RunSwiftDevResult | undefined>;
|
|
11
|
+
export declare function compile(filename: string, { inputDir, outputDir, sourceMap }: ToSwiftOptions): Promise<UtsResult>;
|
|
12
|
+
export declare function resolveIOSDepFiles(filename: string): string[];
|
|
13
|
+
export declare function checkIOSVersionTips(pluginId: string, pluginDir: string, is_uni_modules: boolean): string | undefined;
|