diff --git a/packages/shims-node.d.ts b/packages/shims-node.d.ts index 604c8462b9fa7c8b601ee2e5a1eeb070e9df38d2..26f460689c26bf05b26fb01b68e66415050a4f1d 100644 --- a/packages/shims-node.d.ts +++ b/packages/shims-node.d.ts @@ -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 diff --git a/packages/uni-cli-shared/src/preprocess/context.ts b/packages/uni-cli-shared/src/preprocess/context.ts index 05a4a6d3c1250f06e1ea5780d988ba65c9c56b9f..0b0ad8834a2803b336a4449c88b04c7052dc468f 100644 --- a/packages/uni-cli-shared/src/preprocess/context.ts +++ b/packages/uni-cli-shared/src/preprocess/context.ts @@ -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 diff --git a/packages/uni-cli-shared/src/resolve.ts b/packages/uni-cli-shared/src/resolve.ts index c1cdba4868860131d9a6f3297c6ecbc92262dc2c..4b0c46b0674846ab47e173ccbb942b468db248d9 100644 --- a/packages/uni-cli-shared/src/resolve.ts +++ b/packages/uni-cli-shared/src/resolve.ts @@ -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 diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index e0a2d434672f7538c0c9ed77fc6d0d949d4389c6..71c0f432e6567ee7336affe997e0c8bf5bccf23f 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -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; }); } diff --git a/packages/uni-h5/src/service/api/location/chooseLocation/LoctaionPicker.tsx b/packages/uni-h5/src/service/api/location/chooseLocation/LoctaionPicker.tsx index c1c117678eace1ebe126de96c03f529fdec7bfd6..6641c8bbdc29e04cd106350515c6be8902959795 100644 --- a/packages/uni-h5/src/service/api/location/chooseLocation/LoctaionPicker.tsx +++ b/packages/uni-h5/src/service/api/location/chooseLocation/LoctaionPicker.tsx @@ -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], diff --git a/packages/uni-h5/src/service/api/location/getLocation.ts b/packages/uni-h5/src/service/api/location/getLocation.ts index 894deb9d7fe360a1d8e8972c31aaaa22cd188e1c..ab16f441eac202e90c729e6889d2503b27c353d9 100644 --- a/packages/uni-h5/src/service/api/location/getLocation.ts +++ b/packages/uni-h5/src/service/api/location/getLocation.ts @@ -132,15 +132,15 @@ export const getLocation = 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 = defineAsyncApi( }) } }) - .then((coords: GeolocationCoordinates|any) => { + .then((coords: GeolocationCoordinates | any) => { resolve({ latitude: coords.latitude, longitude: coords.longitude, diff --git a/packages/uni-stacktracey/__tests__/uni-stacktracey.spec.ts b/packages/uni-stacktracey/__tests__/uni-stacktracey.spec.ts index 804bc599ffb77f6952720a3b594cf2c7e1e66750..df71f5ced23fa6c0e54c6f9c01fc2b3461c12315 100644 --- a/packages/uni-stacktracey/__tests__/uni-stacktracey.spec.ts +++ b/packages/uni-stacktracey/__tests__/uni-stacktracey.spec.ts @@ -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 = 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 = CoroutineScope(Dispatchers.Default).async { +^ +`) + }) + }) }) diff --git a/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js b/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js index f487f4c25b38486843ac2e6a0f940fd7c01b8326..40e05ed5cfd13b7f8d370a824183a4dad1771442 100644 --- a/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js +++ b/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js @@ -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; }) diff --git a/packages/uni-stacktracey/dist/uni-stacktracey.es.js b/packages/uni-stacktracey/dist/uni-stacktracey.es.js index 135fcadcb308b7048996d53146a9a59f95522c46..c829975efa222703abfc038417ccd031fca86d8e 100644 --- a/packages/uni-stacktracey/dist/uni-stacktracey.es.js +++ b/packages/uni-stacktracey/dist/uni-stacktracey.es.js @@ -1,4 +1,5 @@ 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; }) diff --git a/packages/uni-stacktracey/src/index.ts b/packages/uni-stacktracey/src/index.ts index 18cffd75cff45e6fc03d3feafdf2f5ee92d3ed4b..d7d950b2b147be87e998de9543e7ebdf83fbdd93 100644 --- a/packages/uni-stacktracey/src/index.ts +++ b/packages/uni-stacktracey/src/index.ts @@ -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 }) diff --git a/packages/uni-stacktracey/test/nativeplugins-sourceMap/uni_modules/test-uts-battery/app-android/index.kt.map b/packages/uni-stacktracey/test/nativeplugins-sourceMap/uni_modules/test-uts-battery/app-android/index.kt.map deleted file mode 100644 index 4aa193c0698b31afd92830a5c9de9396e5bce604..0000000000000000000000000000000000000000 --- a/packages/uni-stacktracey/test/nativeplugins-sourceMap/uni_modules/test-uts-battery/app-android/index.kt.map +++ /dev/null @@ -1 +0,0 @@ -{"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 diff --git a/packages/uni-stacktracey/test/nativeplugins-sourceMap/uni_modules/test-uts-static/app-android/index.kt.map b/packages/uni-stacktracey/test/nativeplugins-sourceMap/uni_modules/test-uts-static/app-android/index.kt.map deleted file mode 100644 index 93f9979b60d44a866f394d03ab2f492b33861aff..0000000000000000000000000000000000000000 --- a/packages/uni-stacktracey/test/nativeplugins-sourceMap/uni_modules/test-uts-static/app-android/index.kt.map +++ /dev/null @@ -1 +0,0 @@ -{"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 diff --git a/packages/uni-stacktracey/test/nativeplugins-sourceMap/uni_modules/test-uts/app-android/index.kt.map b/packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app-plus/uni_modules/test-uts/app-android/index.kt.map similarity index 100% rename from packages/uni-stacktracey/test/nativeplugins-sourceMap/uni_modules/test-uts/app-android/index.kt.map rename to packages/uni-stacktracey/test/uts/unpackage/dist/dev/.sourcemap/app-plus/uni_modules/test-uts/app-android/index.kt.map diff --git a/packages/vite-plugin-uni/src/cli/utils.ts b/packages/vite-plugin-uni/src/cli/utils.ts index 89c816d193fd14908a49f3ddf7fb07dc72b1946e..4a094f2b19fb1c7d51b19fba4c2c7b78c24976a1 100644 --- a/packages/vite-plugin-uni/src/cli/utils.ts +++ b/packages/vite-plugin-uni/src/cli/utils.ts @@ -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) {