提交 f7b09e6a 编写于 作者: fxy060608's avatar fxy060608

wip(uts): sourcemap

上级 aa44f17a
......@@ -7,7 +7,8 @@ declare namespace NodeJS {
UNI_NODE_ENV: 'production' | 'development' | 'test'
UNI_PLATFORM: UniApp.PLATFORM
UNI_SUB_PLATFORM: 'quickapp-webview-huawei' | 'quickapp-webview-union'
UNI_APP_PLATFORM: 'app-android' | 'app-ios'
UNI_APP_PLATFORM: 'android' | 'ios'
UNI_UTS_PLATFORM: 'app-android' | 'app-ios'
UNI_INPUT_DIR: string
UNI_OUTPUT_DIR: string
......
......@@ -63,9 +63,9 @@ export function initPreContext(
nvueContext.APP_NVUE = true
nvueContext.APP_PLUS_NVUE = true
if (process.env.UNI_APP_PLATFORM === 'app-android') {
if (process.env.UNI_APP_PLATFORM === 'android') {
defaultContext.APP_ANDROID = true
} else if (process.env.UNI_APP_PLATFORM === 'app-ios') {
} else if (process.env.UNI_APP_PLATFORM === 'ios') {
defaultContext.APP_IOS = true
} else {
defaultContext.APP_ANDROID = true
......
......@@ -21,16 +21,11 @@ function resolveWithSymlinks(id: string, basedir: string): string {
preserveSymlinks: true,
pathFilter(pkg, filepath, relativePath) {
if (pkg.uni_modules && (pkg.uni_modules as any).type === 'uts') {
const file = process.env.UNI_UTS_PLATFORM + '/index.uts'
if (
process.env.UNI_APP_PLATFORM === 'app-android' ||
process.env.UNI_APP_PLATFORM === 'app-ios'
fs.existsSync(path.join(filepath.replace(relativePath, ''), file))
) {
const file = process.env.UNI_APP_PLATFORM + '/index.uts'
if (
fs.existsSync(path.join(filepath.replace(relativePath, ''), file))
) {
return file
}
return file
}
}
return relativePath
......
......@@ -18446,44 +18446,49 @@ const getLocation = /* @__PURE__ */ defineAsyncApi(API_GET_LOCATION, ({ type, al
reject2(new Error("network error"));
}
});
} else if (mapInfo.type === MapType.AMAP) {
window.AMap.plugin("AMap.Geolocation", function() {
var geolocation = new window.AMap.Geolocation({});
geolocation.getCurrentPosition(function(status, res) {
if (status === "complete") {
resolve2({
latitude: res.position.lat,
longitude: res.position.lng,
accuracy: res.accuracy
});
} else {
reject2(new Error(res.message || JSON.stringify(res)));
}
});
});
} else {
reject2(error);
}
});
}).then((coords, skip) => {
if (type && type.toUpperCase() === "WGS84" || mapInfo.type !== MapType.QQ || skip) {
const wgs84Map = [MapType.GOOGLE];
if (type && type.toUpperCase() === "WGS84" || wgs84Map.includes(mapInfo.type) || skip) {
return coords;
}
return new Promise((resolve2) => {
getJSONP(`https://apis.map.qq.com/jsapi?qt=translate&type=1&points=${coords.longitude},${coords.latitude}&key=${mapInfo.key}&output=jsonp&pf=jsapi&ref=jsapi`, {
callback: "cb"
}, (res) => {
if ("detail" in res && "points" in res.detail && res.detail.points.length) {
const location2 = res.detail.points[0];
resolve2(extend({}, coords, {
longitude: location2.lng,
latitude: location2.lat
}));
} else {
resolve2(coords);
}
}, () => resolve2(coords));
});
if (mapInfo.type === MapType.QQ) {
return new Promise((resolve2) => {
getJSONP(`https://apis.map.qq.com/jsapi?qt=translate&type=1&points=${coords.longitude},${coords.latitude}&key=${mapInfo.key}&output=jsonp&pf=jsapi&ref=jsapi`, {
callback: "cb"
}, (res) => {
if ("detail" in res && "points" in res.detail && res.detail.points.length) {
const location2 = res.detail.points[0];
resolve2(extend({}, coords, {
longitude: location2.lng,
latitude: location2.lat
}));
} else {
resolve2(coords);
}
}, () => resolve2(coords));
});
}
if (mapInfo.type === MapType.AMAP) {
return new Promise((resolve2) => {
loadMaps([], () => {
window.AMap.convertFrom([coords.longitude, coords.latitude], "gps", (_, res) => {
if (res.info === "ok" && res.locations.length) {
const { lat, lng } = res.locations[0];
resolve2(extend({}, coords, {
longitude: lng,
latitude: lat
}));
} else {
resolve2(coords);
}
});
});
});
}
}).then((coords) => {
resolve({
latitude: coords.latitude,
......@@ -18792,33 +18797,22 @@ function useList(state2) {
});
} else if (mapInfo.type === MapType.AMAP) {
window.AMap.plugin("AMap.PlaceSearch", function() {
var autoOptions = {
const placeSearch = new window.AMap.PlaceSearch({
city: "\u5168\u56FD",
pageSize: 10,
pageIndex: listState.pageIndex
};
var placeSearch = new window.AMap.PlaceSearch(autoOptions);
if (state2.searching) {
placeSearch.searchNearBy(state2.keyword, [state2.longitude, state2.latitude], 5e4, function(status, result) {
if (status === "error") {
console.error(result);
} else if (status === "no_data") {
listState.hasNextPage = false;
} else {
pushData(result.poiList.pois);
}
});
} else {
placeSearch.searchNearBy("", [state2.longitude, state2.latitude], 5e3, function(status, result) {
if (status === "error") {
console.error(result);
} else if (status === "no_data") {
listState.hasNextPage = false;
} else {
pushData(result.poiList.pois);
}
});
}
});
const keyword = state2.searching ? state2.keyword : "";
const radius = state2.searching ? 5e4 : 5e3;
placeSearch.searchNearBy(keyword, [state2.longitude, state2.latitude], radius, function(status, result) {
if (status === "error") {
console.error(result);
} else if (status === "no_data") {
listState.hasNextPage = false;
} else {
pushData(result.poiList.pois);
}
});
listState.loading = false;
});
}
......
......@@ -193,8 +193,8 @@ function useList(state: State) {
pageSize: 10,
pageIndex: listState.pageIndex,
})
const keyword = state.searching?state.keyword:''
const radius = state.searching?50000:5000
const keyword = state.searching ? state.keyword : ''
const radius = state.searching ? 50000 : 5000
placeSearch.searchNearBy(
keyword,
[state.longitude, state.latitude],
......
......@@ -132,15 +132,15 @@ export const getLocation = <API_TYPE_GET_LOCATION>defineAsyncApi(
[coords.longitude, coords.latitude],
'gps',
(_: string, res: any) => {
if(res.info === 'ok' && res.locations.length){
const {lat,lng} = res.locations[0]
if (res.info === 'ok' && res.locations.length) {
const { lat, lng } = res.locations[0]
resolve(
extend({}, coords, {
longitude: lng,
latitude: lat,
})
)
}else{
} else {
resolve(coords)
}
}
......@@ -149,7 +149,7 @@ export const getLocation = <API_TYPE_GET_LOCATION>defineAsyncApi(
})
}
})
.then((coords: GeolocationCoordinates|any) => {
.then((coords: GeolocationCoordinates | any) => {
resolve({
latitude: coords.latitude,
longitude: coords.longitude,
......
......@@ -5,20 +5,16 @@ const {
utsStracktraceyPreset,
} = require('../dist/uni-stacktracey.cjs.js')
const utsErrorMsg = `e: DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.kt: (9, 5): Unresolved reference: logxxxxxxx
const utsProjectDir = path.resolve(__dirname, '../test/uts')
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':nativeplugins:DCloud-UTSPlugin:compileReleaseKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s`
const utsErrorMsg = `Error:
${path.resolve(
utsProjectDir,
'unpackage/dist/dev/app-plus/uni_modules/test-uts/app-android/index.kt'
)}:59:67: error: unresolved reference: UtsJSONObject
open suspend fun testClassAsync(opts: AsyncOptions): Deferred<UtsJSONObject> = CoroutineScope(Dispatchers.Default).async {
^
`
const uniErrorMsg = `Error: Sentry Error
at a.throwError(/static/js/pages-index-index.3ab0d0e5.js:1:567)
......@@ -50,31 +46,23 @@ at node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.
})
})
// test('utsStracktraceyPreset local', () => {
// stacktracey(utsErrorMsg, {
// preset: utsStracktraceyPreset({
// base: path.resolve(
// __dirname,
// '../test/nativeplugins-sourceMap/DCloud-UTSPlugin/'
// ),
// sourceRoot: 'DCloud-UTSPlugin/android/src/',
// }),
// }).then((res: string) => {
// expect(res)
// .toEqual(`e: C:/Users/xianyang/Documents/HBuilderProjects/test-uni2/nativeplugins/DCloud-UTSPlugin/android/src/io/dcloud/uniplugin/TestModule.uts: (7, 0): Unresolved reference: logxxxxxxx
// FAILURE: Build failed with an exception.
// * What went wrong:
// Execution failed for task ':nativeplugins:DCloud-UTSPlugin:compileReleaseKotlin'.
// > Compilation error. See log for more details
// * Try:
// Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
// * Get more help at https://help.gradle.org
// BUILD FAILED in 2s`)
// })
// })
test('utsStracktraceyPreset local', () => {
stacktracey(utsErrorMsg, {
preset: utsStracktraceyPreset({
inputRoot: '/Users/fxy/Projects/Demo/my-vue3-project-uts/src',
outputRoot: path.resolve(utsProjectDir, 'unpackage/dist/dev/app-plus'),
sourceMapRoot: path.resolve(
utsProjectDir,
'unpackage/dist/dev/.sourcemap/app-plus'
),
}),
}).then((res: string) => {
expect(res).toEqual(`Error:
at uni_modules/test-uts/app-android/index.uts:82:52
error: unresolved reference: UtsJSONObject
open suspend fun testClassAsync(opts: AsyncOptions): Deferred<UtsJSONObject> = CoroutineScope(Dispatchers.Default).async {
^
`)
})
})
})
......@@ -3,12 +3,12 @@
Object.defineProperty(exports, '__esModule', { value: true });
var require$$0$2 = require('fs');
var require$$1$2 = require('path');
var path = require('path');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
/* ------------------------------------------------------------------------ */
const O = Object, isBrowser =
......@@ -1663,7 +1663,7 @@ var readWasm$1 = createCommonjsModule(function (module) {
{
// Node version of reading a wasm file into an array buffer.
const fs = require$$0__default["default"];
const path = require$$1__default["default"];
const path = path__default["default"];
module.exports = function readWasm() {
return new Promise((resolve, reject) => {
......@@ -3851,15 +3851,11 @@ function uniStracktraceyPreset(opts) {
};
}
function utsStracktraceyPreset(opts) {
const { base, sourceRoot } = opts;
const { inputRoot, outputRoot, sourceMapRoot } = opts;
let errStack = [];
return {
parseSourceMapUrl(file, fileName, fileRelative) {
// 组合 sourceMapUrl
if (sourceRoot) {
return `${file.replace(sourceRoot, base + '/')}.map`;
}
return `${base}/${file}.map`;
return path__default["default"].resolve(sourceMapRoot, path__default["default"].relative(outputRoot, file) + '.map');
},
getSourceMapContent(file, fileName, fileRelative) {
// 根据 base,filename 组合 sourceMapUrl
......@@ -3870,30 +3866,26 @@ function utsStracktraceyPreset(opts) {
const entries = lines
.map((line, index) => {
line = line.trim();
let callee, fileLineColumn = [], planA, planB;
if ((planA = line.match(/e: (.+\.kt)(.+\))*:\s*(.+)*/))) {
const matches = line.match(/\s*(.+\.kt):([0-9]+):([0-9]+):\s+(.*)/);
if (matches) {
errStack.push('%StacktraceyItem%');
callee = 'e: ';
fileLineColumn = (planA[2].match(/.*:.*\((\d+).+?(\d+)\)/) || []).slice(1);
}
else {
errStack.push(line);
return undefined;
return;
}
const fileName = planA[1]
? (planB = planA[1].match(/(.*)*\/(.+)/) || [])[2] || ''
: '';
const fileName = matches[1].replace(/^.*(\\|\/|\:)/, '');
return {
beforeParse: line,
callee: callee || '',
callee: '',
index: false,
native: false,
file: nixSlashes(planA[1] || ''),
line: parseInt(fileLineColumn[0] || '', 10) || undefined,
column: parseInt(fileLineColumn[1] || '', 10) || undefined,
file: nixSlashes(matches[1]),
line: parseInt(matches[2]),
column: parseInt(matches[3]),
fileName,
fileShort: planB ? planB[1] : '',
errMsg: planA[3] || '',
fileShort: line,
errMsg: matches[4] || '',
calleeShort: '',
fileRelative: '',
thirdParty: false,
......@@ -3910,8 +3902,10 @@ function utsStracktraceyPreset(opts) {
.map((item) => {
if (item === '%StacktraceyItem%') {
const _stack = stack.items.shift();
if (_stack)
return `${_stack.callee}${_stack.file}: (${_stack.line}, ${_stack.column}): ${_stack.errMsg}`;
if (_stack) {
return `at ${nixSlashes(path__default["default"].relative(inputRoot, _stack.file))}:${_stack.line}:${_stack.column}
${_stack.errMsg}`;
}
}
return item;
})
......
import require$$0$2 from 'fs';
import path from 'path';
/* ------------------------------------------------------------------------ */
const O = Object, isBrowser =
......@@ -3844,15 +3845,11 @@ function uniStracktraceyPreset(opts) {
};
}
function utsStracktraceyPreset(opts) {
const { base, sourceRoot } = opts;
const { inputRoot, outputRoot, sourceMapRoot } = opts;
let errStack = [];
return {
parseSourceMapUrl(file, fileName, fileRelative) {
// 组合 sourceMapUrl
if (sourceRoot) {
return `${file.replace(sourceRoot, base + '/')}.map`;
}
return `${base}/${file}.map`;
return path.resolve(sourceMapRoot, path.relative(outputRoot, file) + '.map');
},
getSourceMapContent(file, fileName, fileRelative) {
// 根据 base,filename 组合 sourceMapUrl
......@@ -3863,30 +3860,26 @@ function utsStracktraceyPreset(opts) {
const entries = lines
.map((line, index) => {
line = line.trim();
let callee, fileLineColumn = [], planA, planB;
if ((planA = line.match(/e: (.+\.kt)(.+\))*:\s*(.+)*/))) {
const matches = line.match(/\s*(.+\.kt):([0-9]+):([0-9]+):\s+(.*)/);
if (matches) {
errStack.push('%StacktraceyItem%');
callee = 'e: ';
fileLineColumn = (planA[2].match(/.*:.*\((\d+).+?(\d+)\)/) || []).slice(1);
}
else {
errStack.push(line);
return undefined;
return;
}
const fileName = planA[1]
? (planB = planA[1].match(/(.*)*\/(.+)/) || [])[2] || ''
: '';
const fileName = matches[1].replace(/^.*(\\|\/|\:)/, '');
return {
beforeParse: line,
callee: callee || '',
callee: '',
index: false,
native: false,
file: nixSlashes(planA[1] || ''),
line: parseInt(fileLineColumn[0] || '', 10) || undefined,
column: parseInt(fileLineColumn[1] || '', 10) || undefined,
file: nixSlashes(matches[1]),
line: parseInt(matches[2]),
column: parseInt(matches[3]),
fileName,
fileShort: planB ? planB[1] : '',
errMsg: planA[3] || '',
fileShort: line,
errMsg: matches[4] || '',
calleeShort: '',
fileRelative: '',
thirdParty: false,
......@@ -3903,8 +3896,10 @@ function utsStracktraceyPreset(opts) {
.map((item) => {
if (item === '%StacktraceyItem%') {
const _stack = stack.items.shift();
if (_stack)
return `${_stack.callee}${_stack.file}: (${_stack.line}, ${_stack.column}): ${_stack.errMsg}`;
if (_stack) {
return `at ${nixSlashes(path.relative(inputRoot, _stack.file))}:${_stack.line}:${_stack.column}
${_stack.errMsg}`;
}
}
return item;
})
......
......@@ -6,6 +6,7 @@ import {
IndexedSourceMapConsumer,
Position,
} from '../lib/source-map/source-map'
import path from 'path'
// @ts-ignore
if (__PLATFORM_WEB__) {
......@@ -396,28 +397,31 @@ export function uniStracktraceyPreset(
interface UtsStracktraceyPreset {
/**
* source 根目录(如:/wgtRoot/__UNI__E070870/nativeplugins/DCloud-UTSPlugin/android/src/)
* 源码根目录
*/
sourceRoot: string
inputRoot: string
/**
* 编译后根目录
*/
outputRoot: string
/**
* sourceMap 根目录
*/
base: string
sourceMapRoot: string
}
export function utsStracktraceyPreset(
opts: UtsStracktraceyPreset
): StacktraceyPreset {
const { base, sourceRoot } = opts
const { inputRoot, outputRoot, sourceMapRoot } = opts
let errStack: string[] = []
return {
parseSourceMapUrl(file, fileName, fileRelative) {
// 组合 sourceMapUrl
if (sourceRoot) {
return `${file.replace(sourceRoot, base + '/')}.map`
}
return `${base}/${file}.map`
return path.resolve(
sourceMapRoot,
path.relative(outputRoot, file) + '.map'
)
},
getSourceMapContent(file, fileName, fileRelative) {
// 根据 base,filename 组合 sourceMapUrl
......@@ -434,37 +438,29 @@ export function utsStracktraceyPreset(
.map((line, index) => {
line = line.trim()
let callee,
fileLineColumn = [],
planA,
planB
if ((planA = line.match(/e: (.+\.kt)(.+\))*:\s*(.+)*/))) {
const matches = line.match(
/\s*(.+\.kt):([0-9]+):([0-9]+):\s+(.*)/
) as string[]
if (matches) {
errStack.push('%StacktraceyItem%')
callee = 'e: '
fileLineColumn = (
planA[2].match(/.*:.*\((\d+).+?(\d+)\)/) || []
).slice(1)
} else {
errStack.push(line)
return undefined
return
}
const fileName: string = planA[1]
? (planB = planA[1].match(/(.*)*\/(.+)/) || [])[2] || ''
: ''
const fileName: string = matches[1].replace(/^.*(\\|\/|\:)/, '')
return {
beforeParse: line,
callee: callee || '',
callee: '',
index: false,
native: false,
file: nixSlashes(planA[1] || ''),
line: parseInt(fileLineColumn[0] || '', 10) || undefined,
column: parseInt(fileLineColumn[1] || '', 10) || undefined,
file: nixSlashes(matches[1]),
line: parseInt(matches[2]),
column: parseInt(matches[3]),
fileName,
fileShort: planB ? planB[1] : '',
errMsg: planA[3] || '',
fileShort: line,
errMsg: matches[4] || '',
calleeShort: '',
fileRelative: '',
thirdParty: false,
......@@ -482,8 +478,12 @@ export function utsStracktraceyPreset(
.map((item) => {
if (item === '%StacktraceyItem%') {
const _stack = stack.items.shift()
if (_stack)
return `${_stack.callee}${_stack.file}: (${_stack.line}, ${_stack.column}): ${_stack.errMsg}`
if (_stack) {
return `at ${nixSlashes(path.relative(inputRoot, _stack.file))}:${
_stack.line
}:${_stack.column}
${_stack.errMsg}`
}
}
return item
})
......
{"version":3,"sources":["/Users/fxy/Projects/Demo/my-vue3-project-uts/src/uni_modules/test-uts-battery/app-android/index.uts"],"sourcesContent":["import Context from \"android.content.Context\";\nimport BatteryManager from \"android.os.BatteryManager\";\nimport { getAppContext } from \"io.dcloud.uts.android\";\n\nexport default function getBatteryCapacity(): number {\n const context = getAppContext();\n if (context != null) {\n const manager = context.getSystemService(\n Context.BATTERY_SERVICE\n ) as BatteryManager;\n const currentLevel: number = manager.getIntProperty(\n BatteryManager.BATTERY_PROPERTY_CAPACITY\n );\n return currentLevel;\n }\n return 0;\n}"],"names":[],"mappings":";;;;;;AAAA,OAAoB,uBAAyB,CAAC;AAC9C,OAA2B,yBAA2B,CAAC;AACvD;AAEe,IAAS,kBAAkB,IAAI,MAAM,CAAC;IACnD,IAAM,OAAO,GAAG,aAAa,EAAE,AAAC;IAChC,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,IAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CACtC,OAAO,CAAC,eAAe,CACxB,IAAI,cAAc,AAAC;QACpB,IAAM,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CACjD,cAAc,CAAC,yBAAyB,CACzC,AAAC;QACF,OAAO,YAAY,CAAC;IACtB;IACA,OAAO,CAAC,CAAC;AACX"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/Projects/Demo/my-vue3-project-uts/src/uni_modules/test-uts-static/static/logo.png","/Users/fxy/Projects/Demo/my-vue3-project-uts/src/uni_modules/test-uts-static/app-android/index.uts"],"sourcesContent":["import { getResourcePath } from 'io.dcloud.uts.android'\nexport default getResourcePath('uni_modules/test-uts-static/static/logo.png')\n ","import logo from \"../static/logo.png\";\nexport function getLogoPath(): string {\n return logo;\n}\n"],"names":[],"mappings":";;;;;;AAAA;gBACe,eAAe,CAAC,6CAA6C,CAAC;ACAtE,IAAS,WAAW,IAAI,MAAM,CAAC;IACpC,iBAAY;AACd"}
\ No newline at end of file
......@@ -87,17 +87,8 @@ export function initEnv(
: process.cwd()
// TODO 待优化
if (options.platform === 'app-android' || options.platform === 'app-ios') {
process.env.UNI_APP_PLATFORM = options.platform
options.platform = 'app'
}
if (options.platform === 'app-plus') {
options.platform = 'app'
}
if (options.platform === 'app' && !process.env.UNI_APP_PLATFORM) {
// 目前仅支持 app-android,先强制使用 app-android
process.env.UNI_APP_PLATFORM = 'app-android'
}
initUtsPlatform(options)
if (
options.platform === 'quickapp-webview-huawei' ||
options.platform === 'quickapp-webview-union'
......@@ -176,6 +167,28 @@ export function initEnv(
console.log(M['compiling'])
}
function initUtsPlatform(options: CliOptions) {
if (options.platform === 'app-android') {
process.env.UNI_APP_PLATFORM = 'android'
process.env.UNI_UTS_PLATFORM = 'app-android'
options.platform = 'app'
} else if (options.platform === 'app-ios') {
process.env.UNI_APP_PLATFORM = 'ios'
process.env.UNI_UTS_PLATFORM = 'app-ios'
options.platform = 'app'
} else {
if (process.env.UNI_APP_PLATFORM === 'android') {
process.env.UNI_UTS_PLATFORM = 'app-android'
}
if (process.env.UNI_APP_PLATFORM === 'ios') {
process.env.UNI_UTS_PLATFORM = 'app-ios'
}
if (options.platform === 'app-plus') {
options.platform = 'app'
}
}
}
function initAutomator({ autoHost, autoPort }: CliOptions) {
// 发行分包,插件也不需要自动化测试
if (!autoPort || process.env.UNI_SUBPACKAGE || process.env.UNI_MP_PLUGIN) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册