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

wip(uts): compiler

上级 48358b7c
......@@ -8,7 +8,8 @@ packages/uni-mp-compiler/dist
packages/uni-nvue-styler/dist
packages/vite-plugin-uni/dist
packages/uts/dist
packages/uni-uts-vite/dist
packages/uni-uts/dist
.DS_Store
node_modules
......
......@@ -6,7 +6,7 @@
"output": {
"format": "cjs"
},
"external": ["@dcloudio/uni-app-vite", "@dcloudio/uni-uts-vite"]
"external": ["@dcloudio/uni-app-vite"]
},
{
"input": {
......
'use strict';
var appVite = require('@dcloudio/uni-app-vite');
var utsVite = require('@dcloudio/uni-uts-vite');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var appVite__default = /*#__PURE__*/_interopDefaultLegacy(appVite);
var utsVite__default = /*#__PURE__*/_interopDefaultLegacy(utsVite);
var index = [appVite__default["default"], utsVite__default["default"]];
var index = [appVite__default["default"]];
module.exports = index;
......@@ -12160,7 +12160,7 @@ const StartLocationUpdateOptions = {
type(value, params) {
value = (value || '').toLowerCase();
if (coordTypes.indexOf(value) === -1) {
params.type = coordTypes[0];
params.type = coordTypes[1];
}
else {
params.type = value;
......@@ -16173,42 +16173,39 @@ const openLocation = defineAsyncApi(API_OPEN_LOCATION, (data, { resolve, reject
return resolve();
}, OpenLocationProtocol, OpenLocationOptions);
let started = false;
let watchId = 0;
/**
* 开始更新定位
*/
const startLocationUpdate = defineAsyncApi(API_START_LOCATION_UPDATE, (_, { resolve, reject }) => {
if (plus.geolocation && watchId === 0) {
watchId = plus.geolocation.watchPosition((res) => {
UniServiceJSBridge.invokeOnCallback(API_ON_LOCATION_CHANGE, res.coords);
resolve();
}, (error) => {
reject(error.message);
}, {
coordsType: _ === null || _ === void 0 ? void 0 : _.type,
});
}
else {
UniServiceJSBridge.invokeOnCallback(API_ON_LOCATION_CHANGE_ERROR, 'onLocationChange:fail');
}
resolve();
const startLocationUpdate = defineAsyncApi(API_START_LOCATION_UPDATE, (options, { resolve, reject }) => {
watchId =
watchId ||
plus.geolocation.watchPosition((res) => {
started = true;
UniServiceJSBridge.invokeOnCallback(API_ON_LOCATION_CHANGE, res.coords);
}, (error) => {
if (!started) {
reject(error.message);
started = true;
}
UniServiceJSBridge.invokeOnCallback(API_ON_LOCATION_CHANGE_ERROR, {
errMsg: `onLocationChange:fail ${error.message}`,
});
}, {
coordsType: options === null || options === void 0 ? void 0 : options.type,
});
setTimeout(resolve, 100);
}, StartLocationUpdateProtocol, StartLocationUpdateOptions);
const onLocationChange = defineOnApi(API_ON_LOCATION_CHANGE, () => { });
const stopLocationUpdate = defineAsyncApi(API_STOP_LOCATION_UPDATE, (_, { resolve, reject }) => {
const stopLocationUpdate = defineAsyncApi(API_STOP_LOCATION_UPDATE, (_, { resolve }) => {
if (watchId) {
plus.geolocation.clearWatch(watchId);
started = false;
watchId = 0;
resolve();
}
else {
reject('stopLocationUpdate:fail');
}
resolve();
});
const offLocationChange = defineOffApi(API_OFF_LOCATION_CHANGE, () => {
stopLocationUpdate();
});
const onLocationChange = defineOnApi(API_ON_LOCATION_CHANGE, () => { });
const offLocationChange = defineOffApi(API_OFF_LOCATION_CHANGE, () => { });
const onLocationChangeError = defineOnApi(API_ON_LOCATION_CHANGE_ERROR, () => { });
const offLocationChangeError = defineOnApi(API_OFF_LOCATION_CHANGE_ERROR, () => { });
const offLocationChangeError = defineOffApi(API_OFF_LOCATION_CHANGE_ERROR, () => { });
const showModal = defineAsyncApi(API_SHOW_MODAL, ({ title = '', content = '', showCancel = true, cancelText, cancelColor, confirmText, confirmColor, editable = false, placeholderText = '', } = {}, { resolve }) => {
const buttons = showCancel ? [cancelText, confirmText] : [confirmText];
......@@ -19431,8 +19428,8 @@ var uni$1 = {
chooseLocation: chooseLocation,
openLocation: openLocation,
startLocationUpdate: startLocationUpdate,
onLocationChange: onLocationChange,
stopLocationUpdate: stopLocationUpdate,
onLocationChange: onLocationChange,
offLocationChange: offLocationChange,
onLocationChangeError: onLocationChangeError,
offLocationChangeError: offLocationChangeError,
......
......@@ -42,7 +42,6 @@
},
"dependencies": {
"@dcloudio/uni-app-vite": "3.0.0-alpha-3060720221018002",
"@dcloudio/uni-app-vue": "3.0.0-alpha-3060720221018002",
"@dcloudio/uni-uts-vite": "3.0.0-alpha-3060720221018002"
"@dcloudio/uni-app-vue": "3.0.0-alpha-3060720221018002"
}
}
import appVite from '@dcloudio/uni-app-vite'
import utsVite from '@dcloudio/uni-uts-vite'
export default [appVite, utsVite]
export default [appVite]
import { initVuePlugins } from './vue'
import { initNVuePlugins } from './nvue'
import { uniAppPlugin } from './plugin'
import { uniUtsV1Plugin } from './plugins/uts'
export default () => {
return [
uniAppPlugin({
renderer: process.env.UNI_RENDERER,
appService: process.env.UNI_RENDERER_NATIVE === 'appService',
}),
uniUtsV1Plugin(),
...(process.env.UNI_COMPILER === 'nvue'
? initNVuePlugins()
: initVuePlugins()),
......
import type { Plugin } from 'vite'
import path from 'path'
import { parseVueRequest, resolveUtsAppModule } from '@dcloudio/uni-cli-shared'
import { getCompiler, genProxyCode } from '../utils/compiler'
import { resolvePackage } from '../utils/compiler/utils'
import { resolvePlatformIndex, resolveRootIndex } from '../utils/compiler/code'
import {
parseVueRequest,
resolveUtsAppModule,
resolveUTSCompiler,
} from '@dcloudio/uni-cli-shared'
const UTSProxyRE = /\?uts-proxy$/
......@@ -41,6 +41,14 @@ export function uniUtsV1Plugin(): Plugin {
}
const { filename: module } = parseVueRequest(id.replace('\0', ''))
const {
getCompiler,
genProxyCode,
resolvePackage,
resolvePlatformIndex,
resolveRootIndex,
} = resolveUTSCompiler().v1
const pkg = resolvePackage(module)
if (!pkg) {
return
......
......@@ -64,6 +64,7 @@
},
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
"devDependencies": {
"@dcloudio/uni-uts": "3.0.0-alpha-3060720221018002",
"@types/babel__core": "^7.1.19",
"@types/debug": "^4.1.7",
"@types/estree": "^0.0.51",
......
......@@ -19,7 +19,7 @@ export const isInHBuilderX = once(() => {
})
export const runByHBuilderX = once(() => {
return !!process.env.UNI_HBUILDERX_PLUGINS
return !!process.env.UNI_HBUILDERX_PLUGINS && !!process.env.RUN_BY_HBUILDERX
})
/**
......
......@@ -4,6 +4,7 @@ import path from 'path'
import debug from 'debug'
import resolve from 'resolve'
import { once } from '@dcloudio/uni-shared'
import * as UTSCompiler from '@dcloudio/uni-uts'
import { normalizePath } from './utils'
import { isInHBuilderX } from './hbx/env'
......@@ -198,3 +199,15 @@ function resolveUtsFile(
}
}
}
export function resolveUTSCompiler(): typeof UTSCompiler {
if (isInHBuilderX()) {
return require(path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'uniapp-uts'
))
}
return require(require.resolve('@dcloudio/uni-uts', {
paths: [process.env.UNI_CLI_CONTEXT],
}))
}
......@@ -5744,7 +5744,7 @@ const StartLocationUpdateOptions = {
type(value, params) {
value = (value || "").toLowerCase();
if (coordTypes.indexOf(value) === -1) {
params.type = coordTypes[0];
params.type = coordTypes[1];
} else {
params.type = value;
}
......@@ -16593,13 +16593,16 @@ function translateGeo(type, coords, skip) {
},
(res) => {
if ("detail" in res && "points" in res.detail && res.detail.points.length) {
const location2 = res.detail.points[0];
resolve(
extend({}, coords, {
longitude: location2.lng,
latitude: location2.lat
})
);
const { lng, lat } = res.detail.points[0];
resolve({
longitude: lng,
latitude: lat,
altitude: coords.altitude,
accuracy: coords.accuracy,
altitudeAccuracy: coords.altitudeAccuracy,
heading: coords.heading,
speed: coords.speed
});
} else {
resolve(coords);
}
......@@ -16617,12 +16620,15 @@ function translateGeo(type, coords, skip) {
(_, res) => {
if (res.info === "ok" && res.locations.length) {
const { lat, lng } = res.locations[0];
resolve(
extend({}, coords, {
longitude: lng,
latitude: lat
})
);
resolve({
longitude: lng,
latitude: lat,
altitude: coords.altitude,
accuracy: coords.accuracy,
altitudeAccuracy: coords.altitudeAccuracy,
heading: coords.heading,
speed: coords.speed
});
} else {
resolve(coords);
}
......@@ -20290,54 +20296,65 @@ const chooseLocation = /* @__PURE__ */ defineAsyncApi(
},
ChooseLocationProtocol
);
let started = false;
let watchId = 0;
const startLocationUpdate = /* @__PURE__ */ defineAsyncApi(
API_START_LOCATION_UPDATE,
(_, { resolve, reject }) => {
if (navigator.geolocation && watchId === 0) {
watchId = navigator.geolocation.watchPosition(
(res) => {
translateGeo(_ == null ? void 0 : _.type, res.coords).then((coords) => {
UniServiceJSBridge.invokeOnCallback(
API_ON_LOCATION_CHANGE,
coords
);
resolve();
}).catch((error) => {
reject(error.message);
});
},
(error) => {
(options, { resolve, reject }) => {
if (!navigator.geolocation) {
reject();
return;
}
watchId = watchId || navigator.geolocation.watchPosition(
(res) => {
started = true;
translateGeo(options == null ? void 0 : options.type, res.coords).then((coords) => {
UniServiceJSBridge.invokeOnCallback(
API_ON_LOCATION_CHANGE,
coords
);
resolve();
}).catch((error) => {
UniServiceJSBridge.invokeOnCallback(
API_ON_LOCATION_CHANGE_ERROR,
{ errMsg: `onLocationChange:fail ${error.message}` }
);
});
},
(error) => {
if (!started) {
reject(error.message);
started = true;
}
);
}
resolve();
UniServiceJSBridge.invokeOnCallback(API_ON_LOCATION_CHANGE_ERROR, {
errMsg: `onLocationChange:fail ${error.message}`
});
}
);
setTimeout(resolve, 100);
},
StartLocationUpdateProtocol,
StartLocationUpdateOptions
);
const onLocationChange = /* @__PURE__ */ defineOnApi(
API_ON_LOCATION_CHANGE,
() => {
}
);
const stopLocationUpdate = /* @__PURE__ */ defineAsyncApi(
API_STOP_LOCATION_UPDATE,
(_, { resolve, reject }) => {
(_, { resolve }) => {
if (watchId) {
navigator.geolocation.clearWatch(watchId);
started = false;
watchId = 0;
resolve();
} else {
reject("stopLocationUpdate:fail");
}
resolve();
}
);
const onLocationChange = /* @__PURE__ */ defineOnApi(
API_ON_LOCATION_CHANGE,
() => {
}
);
const offLocationChange = /* @__PURE__ */ defineOffApi(
API_OFF_LOCATION_CHANGE,
() => {
stopLocationUpdate();
}
);
const onLocationChangeError = /* @__PURE__ */ defineOnApi(
......@@ -20345,7 +20362,7 @@ const onLocationChangeError = /* @__PURE__ */ defineOnApi(
() => {
}
);
const offLocationChangeError = /* @__PURE__ */ defineOnApi(
const offLocationChangeError = /* @__PURE__ */ defineOffApi(
API_OFF_LOCATION_CHANGE_ERROR,
() => {
}
......@@ -22377,8 +22394,8 @@ const api = /* @__PURE__ */ Object.defineProperty({
openLocation,
chooseLocation,
startLocationUpdate,
onLocationChange,
stopLocationUpdate,
onLocationChange,
offLocationChange,
onLocationChangeError,
offLocationChangeError,
......
declare const _default: import("vite").Plugin[];
export default _default;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const v1_1 = require("./plugins/v1");
exports.default = [(0, v1_1.uniUtsV1Plugin)()];
import { uniUtsV1Plugin } from './plugins/v1'
export default [uniUtsV1Plugin()]
{
"name": "@dcloudio/uni-uts-vite",
"name": "@dcloudio/uni-uts",
"version": "3.0.0-alpha-3060720221018002",
"description": "uni-uts-vite",
"description": "uni-uts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
......@@ -10,24 +10,17 @@
"repository": {
"type": "git",
"url": "git+https://github.com/dcloudio/uni-app.git",
"directory": "packages/uni-uts-vite"
"directory": "packages/uni-uts"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "Apache-2.0",
"uni-app": {
"name": "uts",
"title": "uts",
"apply": [
"app"
],
"main": "dist/index.js"
},
"dependencies": {
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3060720221018002",
"@dcloudio/uni-shared": "3.0.0-alpha-3060720221018002",
"@dcloudio/uts": "3.0.0-alpha-3060720221018002",
"@vue/shared": "3.2.41",
"adm-zip": "^0.5.9",
"execa": "^5.1.1",
"fast-glob": "^3.2.11",
......
export * as v1 from './v1'
......@@ -14,7 +14,7 @@ import {
Param,
TsTypeAnnotation,
VariableDeclaration,
} from '../../../types/types'
} from '../../types/types'
import { createResolveTypeReferenceName } from './utils'
interface GenProxyCodeOptions {
......
import { runKotlinProd, runKotlinDev } from './kotlin'
import { runSwiftProd, runSwiftDev } from './swift'
export { genProxyCode } from './code'
export { genProxyCode, resolvePlatformIndex, resolveRootIndex } from './code'
export { resolvePackage } from './utils'
export function getCompiler(type: 'kotlin' | 'swift') {
if (type === 'swift') {
return {
......
......@@ -9,6 +9,7 @@ import {
isInHBuilderX,
normalizePath,
resolveSourceMapPath,
runByHBuilderX,
} from '@dcloudio/uni-cli-shared'
import {
genUTSPlatformResource,
......@@ -19,7 +20,7 @@ import {
resolveUTSPlatformFile,
resolveUTSSourceMapPath,
} from './utils'
import { Module } from '../../../types/types'
import { Module } from '../../types/types'
export function createKotlinResolveTypeReferenceName(
_namespace: string,
......@@ -111,7 +112,7 @@ function resolveSourceMapFile(outputDir: string, kotlinFile: string) {
async function compile(filename: string) {
if (!process.env.UNI_HBUILDERX_PLUGINS) {
return
return console.error('process.env.UNI_HBUILDERX_PLUGINS is not found')
}
const { bundle, UtsTarget } = getUtsCompiler()
const inputDir = process.env.UNI_INPUT_DIR
......@@ -238,7 +239,11 @@ const getCompilerServer = ():
// eslint-disable-next-line no-restricted-globals
return require(compilerServerPath)
} else {
installHBuilderXPlugin('uniapp-runextension')
if (runByHBuilderX()) {
installHBuilderXPlugin('uniapp-runextension')
} else {
console.error(compilerServerPath + ' is not found')
}
}
return false
......
......@@ -40,7 +40,7 @@ export async function runSwiftDev(_filename: string) {}
async function compile(filename: string) {
if (!process.env.UNI_HBUILDERX_PLUGINS) {
return
return console.error('process.env.UNI_HBUILDERX_PLUGINS is not found')
}
const { bundle, UtsTarget } = getUtsCompiler()
const inputDir = process.env.UNI_INPUT_DIR
......
......@@ -3,7 +3,7 @@ import fs from 'fs-extra'
import type { parse, bundle, UtsTarget } from '@dcloudio/uts'
import { normalizePath, resolveSourceMapPath } from '@dcloudio/uni-cli-shared'
import { camelize, capitalize } from '@vue/shared'
import { Module, ModuleItem } from '../../../types/types'
import { Module, ModuleItem } from '../../types/types'
export function resolveUTSSourceMapPath(_filename: string) {
return resolveSourceMapPath()
......
......@@ -192,7 +192,6 @@ importers:
'@dcloudio/uni-h5': 3.0.0-alpha-3060720221018002
'@dcloudio/uni-i18n': 3.0.0-alpha-3060720221018002
'@dcloudio/uni-shared': 3.0.0-alpha-3060720221018002
'@dcloudio/uni-uts-vite': 3.0.0-alpha-3060720221018002
'@types/pako': 1.0.2
'@vue/compiler-sfc': 3.2.41
autoprefixer: ^10.4.12
......@@ -202,7 +201,6 @@ importers:
dependencies:
'@dcloudio/uni-app-vite': link:../uni-app-vite
'@dcloudio/uni-app-vue': link:../uni-app-vue
'@dcloudio/uni-uts-vite': link:../uni-uts-vite
devDependencies:
'@dcloudio/uni-cli-shared': link:../uni-cli-shared
'@dcloudio/uni-components': link:../uni-components
......@@ -306,6 +304,7 @@ importers:
'@babel/types': ^7.17.0
'@dcloudio/uni-i18n': 3.0.0-alpha-3060720221018002
'@dcloudio/uni-shared': 3.0.0-alpha-3060720221018002
'@dcloudio/uni-uts': 3.0.0-alpha-3060720221018002
'@intlify/core-base': 9.1.9
'@intlify/shared': 9.1.9
'@intlify/vue-devtools': 9.1.9
......@@ -395,6 +394,7 @@ importers:
tapable: 2.2.1
xregexp: 3.1.0
devDependencies:
'@dcloudio/uni-uts': link:../uni-uts
'@types/babel__core': 7.1.19
'@types/debug': 4.1.7
'@types/estree': 0.0.51
......@@ -799,13 +799,14 @@ importers:
devDependencies:
'@types/debug': 4.1.7
packages/uni-uts-vite:
packages/uni-uts:
specifiers:
'@dcloudio/uni-cli-shared': 3.0.0-alpha-3060720221018002
'@dcloudio/uni-shared': 3.0.0-alpha-3060720221018002
'@dcloudio/uts': 3.0.0-alpha-3060720221018002
'@types/adm-zip': ^0.5.0
'@types/fs-extra': ^9.0.13
'@vue/shared': 3.2.41
adm-zip: ^0.5.9
execa: ^5.1.1
fast-glob: ^3.2.11
......@@ -814,6 +815,7 @@ importers:
'@dcloudio/uni-cli-shared': link:../uni-cli-shared
'@dcloudio/uni-shared': link:../uni-shared
'@dcloudio/uts': link:../uts
'@vue/shared': 3.2.41
adm-zip: 0.5.9
execa: 5.1.1
fast-glob: 3.2.12
......@@ -5347,7 +5349,7 @@ packages:
resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==}
/graceful-fs/4.2.9:
resolution: {integrity: sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==, registry: https://registry.yarnpkg.com/}
resolution: {integrity: sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==, registry: https://registry.yarnpkg.com/, tarball: https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz}
dev: true
/has-flag/3.0.0:
......
......@@ -32,8 +32,8 @@ const priority = {
'uni-cloud': 10,
'uni-automator': 10,
uts: 10,
'uni-uts-vite': 9,
'uni-stacktracey': 9,
'uni-uts': 9,
'uni-stacktracey': 8,
'size-check': 0,
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册