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

wip(uts): Uts -> UTS

上级 7ea00805
{"version":3,"sources":["uni_modules/test-uniplugin/static/logo.png","uni_modules/test-uniplugin/utssdk/app-android/index.uts","uni_modules/test-uniplugin/utssdk/app-android/interface.uts"],"sourcesContent":["import { UTSAndroid } from 'io.dcloud.uts'\nexport default UTSAndroid.getResourcePath('uni_modules/test-uniplugin/static/logo.png')\n ","import Log from 'android.util.Log'\nimport FrameLayout from 'android.widget.FrameLayout'\nimport View from 'android.view.View'\nimport { login } from 'login'\nimport { IUser } from './interface'\nimport logo from '../../static/logo.png'\n\nconst test = arrayOf(1, 2, 3)\n\ntype GetBatteryInfoOptions = {\n success?: (res: UTSJSONObject) => void\n fail?: (res: UTSJSONObject) => void\n complete?: (res: UTSJSONObject) => void\n}\nexport class User implements IUser {\n async login(name: string, pwd: string) {\n setTimeout(() => {\n console.log('timeout')\n }, 1000)\n login(name, pwd)\n for (let i = 0; i < 10; i++) {\n console.log(i)\n }\n Log.info(logo)\n\n console.log('def android')\n\n\n\n\n\n\n\n\n console.log('ndef ios')\n\n\n console.log('def android || def ios')\n\n\n\n\n const a = -3\n console.log(~a)\n new XToast<XToast<unknown>>(getUniActivity())\n .setContentView(R.layout.toast_hint)\n .setDuration(1000)\n .setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_finish)\n .setText(android.R.id.message, '点我消失')\n .show()\n }\n register(name: string, callback: () => void) {\n Log.info(logo as FrameLayout)\n }\n test(view: View) {\n console.log(new TestClass())\n }\n}\nfunction login(name: string, callback: () => void) { }\n\n@Suppress(\"DEPRECATION\")\nexport function register(name: string, callback: () => void) { }\nexport function offMemoryWarning(\n callback: null | ((level: number) => void) = null\n) { }\nclass TestClass {\n\n}\n","export interface IUser {\n register(name: string): void\n}\n"],"names":[],"mappings":";;;;;;AAAA;ACAA,OAAgB,gBAAkB,CAAA;AAClC,OAAwB,0BAA4B,CAAA;AACpD,OAAiB,iBAAmB,CAAA;AACpC;UCHiB;QACf,SAAS,MAAM,MAAM,GAAG,IAAI;;cFAf,WAAW,eAAe,CAAC;ACM1C,IAAM,OAAO,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAEC,WAAxB;IACH,SAAA,SAAQ,oBAA8B;IACtC,SAAA,MAAK,oBAA8B;IACnC,SAAA,UAAS,oBAA8B;AACzC;AACO,WAAM,OAAgB;IAC3B,iBAAM,MAAM,MAAM,MAAM,EAAE,KAAK,MAAM,8CAAE;QACrC,WAAW,KAAM;YACf,QAAQ,GAAG,CAAC;QACd;UAAG,IAAI;QACP,MAAM,MAAM;YACZ;YAAK,IAAI,IAAI,CAAC;YAAd,MAAgB,IAAI,EAAE;gBACpB,QAAQ,GAAG,CAAC;gBADU;;QAExB;QACA,IAAI,IAAI;QAER,QAAQ,GAAG,CAAC;QASZ,QAAQ,GAAG,CAAC;QAGZ,QAAQ,GAAG,CAAC;QAMZ,QAAQ,GAAG,CAAC,CADF,EAAE,KACE;QACV,OAAO,OAAO,CAAO,GAAG,kBACzB,cAAc,CAAC,EAAE,MAAM,CAAC,UAAU,EAClC,WAAW,CAAC,IAAI,EAChB,gBAAgB,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,oBAAoB,EACjE,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,QAC9B,IAAI;IACT;IACA,aAAA,SAAS,MAAM,MAAM,EAAE,qBAAoB,EAAE;QAC3C,IAAI,IAAI,YAAS;IACnB;IACA,SAAA,KAAK,MAAM,IAAI,EAAE;QACf,QAAQ,GAAG,CAAC,AAAI;IAClB;AACF;AACA,IAAS,MAAM,MAAM,MAAM,EAAE,gBAAgB,IAAI,EAAE,CAAE;AAErD,CAAC,SAAS;AAAc,IACR,SAAS,MAAM,MAAM,EAAE,qBAAoB,EAAE,CAAE;AACxD,IAAS,iBACd,2BAA6C,IAAI,EACjD,CAAE;AACJ,WAAM;AAEN"} {"version":3,"sources":["uni_modules/test-uniplugin/static/logo.png","uni_modules/test-uniplugin/utssdk/app-android/index.uts","uni_modules/test-uniplugin/utssdk/app-android/utils.uts","uni_modules/test-uniplugin/utssdk/app-android/login.uts","uni_modules/test-uniplugin/utssdk/app-android/interface.uts"],"sourcesContent":["import { UTSAndroid } from 'io.dcloud.uts'\nexport default UTSAndroid.getResourcePath('uni_modules/test-uniplugin/static/logo.png')\n ","import Log from 'android.util.Log'\nimport FrameLayout from 'android.widget.FrameLayout'\nimport View from 'android.view.View'\nimport { login } from 'login'\nimport { IUser } from './interface'\nimport logo from '../../static/logo.png'\n\nconst test = arrayOf(1, 2, 3)\n\ntype GetBatteryInfoOptions = {\n success?: (res: UTSJSONObject) => void\n fail?: (res: UTSJSONObject) => void\n complete?: (res: UTSJSONObject) => void\n}\nexport class User implements IUser {\n async login(name: string, pwd: string) {\n setTimeout(() => {\n console.log('timeout')\n }, 1000)\n login(name, pwd)\n for (let i = 0; i < 10; i++) {\n console.log(i)\n }\n Log.info(logo)\n\n console.log('def android')\n\n\n\n\n\n\n\n\n console.log('ndef ios')\n\n\n console.log('def android || def ios')\n\n\n\n\n const a = -3\n console.log(~a)\n new XToast<XToast<unknown>>(getUniActivity())\n .setContentView(R.layout.toast_hint)\n .setDuration(1000)\n .setImageDrawable(android.R.id.icon, R.mipmap.ic_dialog_tip_finish)\n .setText(android.R.id.message, '点我消失')\n .show()\n }\n register(name: string, callback: () => void) {\n Log.info(logo as FrameLayout)\n }\n test(view: View) {\n console.log(new TestClass())\n }\n}\nfunction login(name: string, callback: () => void) { }\n\n@Suppress(\"DEPRECATION\")\nexport function register(name: string, callback: () => void) { }\nexport function offMemoryWarning(\n callback: null | ((level: number) => void) = null\n) { }\nclass TestClass {\n\n}\n","export function test(){\n console.log('test')\n}\n","import { test } from \"./utils.uts\"\nexport function login(name: string, pwd: string) {\n console.log('login')\n test()\n return { name, pwd }\n}\n","export interface IUser {\n register(name: string): void\n}\n"],"names":[],"mappings":";;;;;;AAAA;ACAA,OAAgB,gBAAkB,CAAA;AAClC,OAAwB,0BAA4B,CAAA;AACpD,OAAiB,iBAAmB,CAAA;ACF7B,IAAS,OAAM;IAClB,QAAQ,GAAG,CAAC;AAChB;ACDO,IAAS,MAAM,MAAM,MAAM,EAAE,KAAK,MAAM,iBAAE;IAC/C,QAAQ,GAAG,CAAC;IACZ;IACA,OAAO;QAAE,IAAA,OAAA;QAAM,IAAA,MAAA;KAAK;AACtB;UCLiB;QACf,SAAS,MAAM,MAAM,GAAG,IAAI;;cJAf,WAAW,eAAe,CAAC;ACM1C,IAAM,QAAO,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AAEC,WAAxB;IACH,SAAA,SAAQ,oBAA8B;IACtC,SAAA,MAAK,oBAA8B;IACnC,SAAA,UAAS,oBAA8B;AACzC;AACO,WAAM,OAAgB;IAC3B,iBAAM,MAAM,MAAM,MAAM,EAAE,KAAK,MAAM,8CAAE;QACrC,WAAW,KAAM;YACf,QAAQ,GAAG,CAAC;QACd;UAAG,IAAI;QACP,MAAM,MAAM;YACZ;YAAK,IAAI,IAAI,CAAC;YAAd,MAAgB,IAAI,EAAE;gBACpB,QAAQ,GAAG,CAAC;gBADU;;QAExB;QACA,IAAI,IAAI;QAER,QAAQ,GAAG,CAAC;QASZ,QAAQ,GAAG,CAAC;QAGZ,QAAQ,GAAG,CAAC;QAMZ,QAAQ,GAAG,CAAC,CADF,EAAE,KACE;QACV,OAAO,OAAO,CAAO,GAAG,kBACzB,cAAc,CAAC,EAAE,MAAM,CAAC,UAAU,EAClC,WAAW,CAAC,IAAI,EAChB,gBAAgB,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,oBAAoB,EACjE,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,QAC9B,IAAI;IACT;IACA,aAAA,SAAS,MAAM,MAAM,EAAE,qBAAoB,EAAE;QAC3C,IAAI,IAAI,YAAS;IACnB;IACA,SAAA,KAAK,MAAM,IAAI,EAAE;QACf,QAAQ,GAAG,CAAC,AAAI;IAClB;AACF;AACA,UAAe,MAAM,MAAM,EAAE,gBAAgB,IAAI,EAAE,CAAE;AAErD,CAAC,SAAS;AAAc,IACR,SAAS,MAAM,MAAM,EAAE,qBAAoB,EAAE,CAAE;AACxD,IAAS,iBACd,2BAA6C,IAAI,EACjD,CAAE;AACJ,WAAM;AAEN"}
\ No newline at end of file \ No newline at end of file
...@@ -8,12 +8,22 @@ import io.dcloud.uts.UTSAndroid; ...@@ -8,12 +8,22 @@ import io.dcloud.uts.UTSAndroid;
import android.util.Log; import android.util.Log;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.view.View; import android.view.View;
import login.login; fun test() {
console.log("test", " at uni_modules/test-uniplugin/utssdk/app-android/utils.uts:2");
}
fun login(name: String, pwd: String): UTSJSONObject {
console.log("login", " at uni_modules/test-uniplugin/utssdk/app-android/login.uts:3");
test();
return object : UTSJSONObject() {
var name = name
var pwd = pwd
};
}
interface IUser { interface IUser {
fun register(name: String): Unit; fun register(name: String): Unit;
} }
val default = UTSAndroid.getResourcePath("uni_modules/test-uniplugin/static/logo.png"); val default = UTSAndroid.getResourcePath("uni_modules/test-uniplugin/static/logo.png");
val test = arrayOf(1, 2, 3); val test1 = arrayOf(1, 2, 3);
open class GetBatteryInfoOptions : UTSJSONObject() { open class GetBatteryInfoOptions : UTSJSONObject() {
open var success: UTSCallback? = null; open var success: UTSCallback? = null;
open var fail: UTSCallback? = null; open var fail: UTSCallback? = null;
......
...@@ -14585,9 +14585,10 @@ const compressVideo = defineAsyncApi(API_COMPRESS_VIDEO, (options, { resolve, re ...@@ -14585,9 +14585,10 @@ const compressVideo = defineAsyncApi(API_COMPRESS_VIDEO, (options, { resolve, re
const filename = `${TEMP_PATH}/compressed/${Date.now()}_${getFileName(options.src)}`; const filename = `${TEMP_PATH}/compressed/${Date.now()}_${getFileName(options.src)}`;
plus.zip.compressVideo(extend({}, options, { plus.zip.compressVideo(extend({}, options, {
filename, filename,
}), () => { }), (videoInfo) => {
resolve({ resolve({
tempFilePath: filename, tempFilePath: filename,
size: videoInfo.size,
}); });
}, reject); }, reject);
}, CompressVideoProtocol, CompressVideoOptions); }, CompressVideoProtocol, CompressVideoOptions);
......
import { initVuePlugins } from './vue' import { initVuePlugins } from './vue'
import { initNVuePlugins } from './nvue' import { initNVuePlugins } from './nvue'
import { uniAppPlugin } from './plugin' import { uniAppPlugin } from './plugin'
import { uniUtsV1Plugin } from './plugins/uts' import { uniUTSV1Plugin } from './plugins/uts'
export default () => { export default () => {
return [ return [
uniAppPlugin({ uniAppPlugin({
renderer: process.env.UNI_RENDERER, renderer: process.env.UNI_RENDERER,
appService: process.env.UNI_RENDERER_NATIVE === 'appService', appService: process.env.UNI_RENDERER_NATIVE === 'appService',
}), }),
uniUtsV1Plugin(), uniUTSV1Plugin(),
...(process.env.UNI_COMPILER === 'nvue' ...(process.env.UNI_COMPILER === 'nvue'
? initNVuePlugins() ? initNVuePlugins()
: initVuePlugins()), : initVuePlugins()),
......
...@@ -2,7 +2,7 @@ import type { Plugin } from 'vite' ...@@ -2,7 +2,7 @@ import type { Plugin } from 'vite'
import path from 'path' import path from 'path'
import { import {
parseVueRequest, parseVueRequest,
resolveUtsAppModule, resolveUTSAppModule,
resolveUTSCompiler, resolveUTSCompiler,
} from '@dcloudio/uni-cli-shared' } from '@dcloudio/uni-cli-shared'
import { once } from '@dcloudio/uni-shared' import { once } from '@dcloudio/uni-shared'
...@@ -21,7 +21,7 @@ const utsModuleCaches = new Map< ...@@ -21,7 +21,7 @@ const utsModuleCaches = new Map<
meta?: any meta?: any
}> }>
>() >()
export function uniUtsV1Plugin(): Plugin { export function uniUTSV1Plugin(): Plugin {
process.env.UNI_UTS_USING_ROLLUP = 'true' process.env.UNI_UTS_USING_ROLLUP = 'true'
return { return {
name: 'uni:uts', name: 'uni:uts',
...@@ -31,7 +31,7 @@ export function uniUtsV1Plugin(): Plugin { ...@@ -31,7 +31,7 @@ export function uniUtsV1Plugin(): Plugin {
if (isUTSProxy(id)) { if (isUTSProxy(id)) {
return id return id
} }
const module = resolveUtsAppModule( const module = resolveUTSAppModule(
id, id,
importer ? path.dirname(importer) : process.env.UNI_INPUT_DIR importer ? path.dirname(importer) : process.env.UNI_INPUT_DIR
) )
......
...@@ -14,7 +14,7 @@ import type { EasycomMatcher } from './easycom' ...@@ -14,7 +14,7 @@ import type { EasycomMatcher } from './easycom'
* @param importer * @param importer
* @returns * @returns
*/ */
export function resolveUtsAppModule(id: string, importer: string) { export function resolveUTSAppModule(id: string, importer: string) {
id = path.resolve(importer, id) id = path.resolve(importer, id)
if (id.includes('utssdk') || id.includes('uni_modules')) { if (id.includes('utssdk') || id.includes('uni_modules')) {
const parts = normalizePath(id).split('/') const parts = normalizePath(id).split('/')
...@@ -28,10 +28,10 @@ export function resolveUtsAppModule(id: string, importer: string) { ...@@ -28,10 +28,10 @@ export function resolveUtsAppModule(id: string, importer: string) {
return path.resolve(id, basedir, p) return path.resolve(id, basedir, p)
} }
const extname = ['.uts'] const extname = ['.uts']
if (resolveUtsFile(resolvePlatformDir('app-android'), extname)) { if (resolveUTSFile(resolvePlatformDir('app-android'), extname)) {
return id return id
} }
if (resolveUtsFile(resolvePlatformDir('app-ios'), extname)) { if (resolveUTSFile(resolvePlatformDir('app-ios'), extname)) {
return id return id
} }
} }
...@@ -39,12 +39,12 @@ export function resolveUtsAppModule(id: string, importer: string) { ...@@ -39,12 +39,12 @@ export function resolveUtsAppModule(id: string, importer: string) {
} }
// 仅限 root/uni_modules/test-plugin | root/utssdk/test-plugin 格式 // 仅限 root/uni_modules/test-plugin | root/utssdk/test-plugin 格式
export function resolveUtsModule(id: string, importer: string) { export function resolveUTSModule(id: string, importer: string) {
if ( if (
process.env.UNI_PLATFORM === 'app' || process.env.UNI_PLATFORM === 'app' ||
process.env.UNI_PLATFORM === 'app-plus' process.env.UNI_PLATFORM === 'app-plus'
) { ) {
return resolveUtsAppModule(id, importer) return resolveUTSAppModule(id, importer)
} }
id = path.resolve(importer, id) id = path.resolve(importer, id)
if (id.includes('utssdk') || id.includes('uni_modules')) { if (id.includes('utssdk') || id.includes('uni_modules')) {
...@@ -56,7 +56,7 @@ export function resolveUtsModule(id: string, importer: string) { ...@@ -56,7 +56,7 @@ export function resolveUtsModule(id: string, importer: string) {
return path.resolve(id, basedir, p) return path.resolve(id, basedir, p)
} }
let index = resolveUtsFile( let index = resolveUTSFile(
resolvePlatformDir(process.env.UNI_UTS_PLATFORM) resolvePlatformDir(process.env.UNI_UTS_PLATFORM)
) )
if (index) { if (index) {
...@@ -70,7 +70,7 @@ export function resolveUtsModule(id: string, importer: string) { ...@@ -70,7 +70,7 @@ export function resolveUtsModule(id: string, importer: string) {
} }
} }
function resolveUtsFile( function resolveUTSFile(
dir: string, dir: string,
extensions: string[] = ['.uts', '.ts', '.js'] extensions: string[] = ['.uts', '.ts', '.js']
) { ) {
......
...@@ -14,7 +14,7 @@ import { ...@@ -14,7 +14,7 @@ import {
updateMiniProgramComponentsByScriptFilename, updateMiniProgramComponentsByScriptFilename,
updateMiniProgramComponentsByTemplateFilename, updateMiniProgramComponentsByTemplateFilename,
withSourcemap, withSourcemap,
resolveUtsModule, resolveUTSModule,
} from '@dcloudio/uni-cli-shared' } from '@dcloudio/uni-cli-shared'
import { virtualComponentPath, virtualPagePath } from './entry' import { virtualComponentPath, virtualPagePath } from './entry'
import { CustomPluginOptions, ResolvedId } from 'rollup' import { CustomPluginOptions, ResolvedId } from 'rollup'
...@@ -60,7 +60,7 @@ export function uniUsingComponentsPlugin( ...@@ -60,7 +60,7 @@ export function uniUsingComponentsPlugin(
skipSelf?: boolean skipSelf?: boolean
} }
): Promise<ResolvedId | null> => { ): Promise<ResolvedId | null> => {
const id = resolveUtsModule( const id = resolveUTSModule(
source, source,
importer || process.env.UNI_INPUT_DIR importer || process.env.UNI_INPUT_DIR
) )
......
...@@ -11,8 +11,8 @@ const utsErrorMsg = `Error: ...@@ -11,8 +11,8 @@ const utsErrorMsg = `Error:
${path.resolve( ${path.resolve(
utsProjectDir, utsProjectDir,
'unpackage/dist/dev/app-plus/uni_modules/test-uts/app-android/index.kt' 'unpackage/dist/dev/app-plus/uni_modules/test-uts/app-android/index.kt'
)}:59:67: error: unresolved reference: UtsJSONObject )}:59:67: error: unresolved reference: UTSJSONObject
open suspend fun testClassAsync(opts: AsyncOptions): Deferred<UtsJSONObject> = CoroutineScope(Dispatchers.Default).async { open suspend fun testClassAsync(opts: AsyncOptions): Deferred<UTSJSONObject> = CoroutineScope(Dispatchers.Default).async {
^ ^
` `
...@@ -59,8 +59,8 @@ at node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime. ...@@ -59,8 +59,8 @@ at node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.
}).then((res: string) => { }).then((res: string) => {
expect(res).toEqual(`Error: expect(res).toEqual(`Error:
at uni_modules/test-uts/app-android/index.uts:82:52 at uni_modules/test-uts/app-android/index.uts:82:52
error: unresolved reference: UtsJSONObject error: unresolved reference: UTSJSONObject
open suspend fun testClassAsync(opts: AsyncOptions): Deferred<UtsJSONObject> = CoroutineScope(Dispatchers.Default).async { open suspend fun testClassAsync(opts: AsyncOptions): Deferred<UTSJSONObject> = CoroutineScope(Dispatchers.Default).async {
^ ^
`) `)
}) })
......
...@@ -17,7 +17,7 @@ describe('code-frame-uts', () => { ...@@ -17,7 +17,7 @@ describe('code-frame-uts', () => {
}) })
).toMatchSnapshot() ).toMatchSnapshot()
expect( expect(
await generateCodeFrameWithKotlinStacktrace(androidUtssdkError, { await generateCodeFrameWithKotlinStacktrace(androidUTSsdkError, {
name: 'utssdk/test2', name: 'utssdk/test2',
inputDir: '/Users/fxy/DCloud/test-uts', inputDir: '/Users/fxy/DCloud/test-uts',
outputDir: path.resolve(utsProjectDir, 'unpackage/dist/dev/app-plus'), outputDir: path.resolve(utsProjectDir, 'unpackage/dist/dev/app-plus'),
...@@ -39,7 +39,7 @@ const androidUniModulesError = `e: uni_modules/test-uts1/utssdk/app-android/inde ...@@ -39,7 +39,7 @@ const androidUniModulesError = `e: uni_modules/test-uts1/utssdk/app-android/inde
FAILURE: Build failed with an exception.` FAILURE: Build failed with an exception.`
const androidUtssdkError = `e: utssdk/test2/app-android/index.kt: (8, 12): The integer literal does not conform to the expected type String const androidUTSsdkError = `e: utssdk/test2/app-android/index.kt: (8, 12): The integer literal does not conform to the expected type String
FAILURE: Build failed with an exception.` FAILURE: Build failed with an exception.`
......
...@@ -417,7 +417,7 @@ export function uniStracktraceyPreset( ...@@ -417,7 +417,7 @@ export function uniStracktraceyPreset(
} }
} }
interface UtsStracktraceyPreset { interface UTSStracktraceyPreset {
/** /**
* 源码根目录 * 源码根目录
*/ */
...@@ -432,7 +432,7 @@ interface UtsStracktraceyPreset { ...@@ -432,7 +432,7 @@ interface UtsStracktraceyPreset {
sourceMapRoot: string sourceMapRoot: string
} }
export function utsStracktraceyPreset( export function utsStracktraceyPreset(
opts: UtsStracktraceyPreset opts: UTSStracktraceyPreset
): StacktraceyPreset { ): StacktraceyPreset {
const { inputRoot, outputRoot, sourceMapRoot } = opts const { inputRoot, outputRoot, sourceMapRoot } = opts
......
...@@ -11,7 +11,7 @@ const is_uni_modules = false ...@@ -11,7 +11,7 @@ const is_uni_modules = false
const pkg = initUTSPackageName(name, is_uni_modules) const pkg = initUTSPackageName(name, is_uni_modules)
const cls = initUTSIndexClassName(name, is_uni_modules) const cls = initUTSIndexClassName(name, is_uni_modules)
export const TestUtsComponent = {} export const TestUTSComponent = {}
export const onMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarning', params: [{"name":"callback","type":"UTSCallback"}]}) export const onMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarning', params: [{"name":"callback","type":"UTSCallback"}]})
export const offMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarning', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}]}) export const offMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarning', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}]})
...@@ -33,7 +33,7 @@ const cls = initUTSIndexClassName(name, is_uni_modules) ...@@ -33,7 +33,7 @@ const cls = initUTSIndexClassName(name, is_uni_modules)
const exports = { __esModule: true } const exports = { __esModule: true }
exports.TestUtsComponent = {} exports.TestUTSComponent = {}
exports.onMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarning', params: [{"name":"callback","type":"UTSCallback"}]}) exports.onMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'onMemoryWarning', params: [{"name":"callback","type":"UTSCallback"}]})
exports.offMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarning', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}]}) exports.offMemoryWarning = initUTSProxyFunction(false, { moduleName, moduleType, errMsg, main: true, package: pkg, class: cls, name: 'offMemoryWarning', params: [{"name":"callback","type":"UTSCallback","default":"UTSNull"}]})
......
...@@ -14,9 +14,9 @@ describe('code', () => { ...@@ -14,9 +14,9 @@ describe('code', () => {
id: 'test-uts', id: 'test-uts',
is_uni_modules: false, is_uni_modules: false,
name: 'test-uts', name: 'test-uts',
namespace: 'uts.sdk.testUts', namespace: 'uts.sdk.testUTS',
extname: '.uts', extname: '.uts',
androidComponents: { TestUts: '' }, androidComponents: { TestUTS: '' },
}) })
).replace(ERR_MSG_PLACEHOLDER, '') ).replace(ERR_MSG_PLACEHOLDER, '')
).toMatchSnapshot() ).toMatchSnapshot()
...@@ -28,11 +28,11 @@ describe('code', () => { ...@@ -28,11 +28,11 @@ describe('code', () => {
id: 'test-uts', id: 'test-uts',
is_uni_modules: false, is_uni_modules: false,
name: 'test-uts', name: 'test-uts',
namespace: 'uts.sdk.testUts', namespace: 'uts.sdk.testUTS',
extname: '.uts', extname: '.uts',
format: FORMATS.CJS, format: FORMATS.CJS,
pluginRelativeDir: 'utssdk/test-uts', pluginRelativeDir: 'utssdk/test-uts',
androidComponents: { TestUts: '' }, androidComponents: { TestUTS: '' },
}) })
).replace(ERR_MSG_PLACEHOLDER, '') ).replace(ERR_MSG_PLACEHOLDER, '')
).toMatchSnapshot() ).toMatchSnapshot()
......
import { resolve } from 'path' import { resolve } from 'path'
import { import {
resolveUtsPluginSourceMapFile, resolveUTSPluginSourceMapFile,
generatedPositionFor, generatedPositionFor,
originalPositionFor, originalPositionFor,
} from '../src' } from '../src'
...@@ -15,8 +15,8 @@ const utssdkPluginDir = 'utssdk/test-uts' ...@@ -15,8 +15,8 @@ const utssdkPluginDir = 'utssdk/test-uts'
const uniModulesPluginDir = 'uni_modules/test-uniplugin' const uniModulesPluginDir = 'uni_modules/test-uniplugin'
describe('uts:sourceMap', () => { describe('uts:sourceMap', () => {
test('resolveUtsPluginSourceMapFile with uni_modules uts=>kotlin', () => { test('resolveUTSPluginSourceMapFile with uni_modules uts=>kotlin', () => {
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'kotlin', 'kotlin',
resolve(inputDir, uniModulesPluginDir, 'utssdk/app-android/index.uts'), resolve(inputDir, uniModulesPluginDir, 'utssdk/app-android/index.uts'),
inputDir, inputDir,
...@@ -24,7 +24,7 @@ describe('uts:sourceMap', () => { ...@@ -24,7 +24,7 @@ describe('uts:sourceMap', () => {
) )
expect(sourceMapFile).toBeDefined() expect(sourceMapFile).toBeDefined()
expect( expect(
resolveUtsPluginSourceMapFile( resolveUTSPluginSourceMapFile(
'kotlin', 'kotlin',
resolve(inputDir, uniModulesPluginDir, 'utssdk/index.uts'), resolve(inputDir, uniModulesPluginDir, 'utssdk/index.uts'),
inputDir, inputDir,
...@@ -32,7 +32,7 @@ describe('uts:sourceMap', () => { ...@@ -32,7 +32,7 @@ describe('uts:sourceMap', () => {
) )
).toBe(sourceMapFile) ).toBe(sourceMapFile)
expect( expect(
resolveUtsPluginSourceMapFile( resolveUTSPluginSourceMapFile(
'kotlin', 'kotlin',
resolve( resolve(
inputDir, inputDir,
...@@ -45,8 +45,8 @@ describe('uts:sourceMap', () => { ...@@ -45,8 +45,8 @@ describe('uts:sourceMap', () => {
).toBe(sourceMapFile) ).toBe(sourceMapFile)
}) })
test('resolveUtsPluginSourceMapFile with uni_modules uts=>swift', () => { test('resolveUTSPluginSourceMapFile with uni_modules uts=>swift', () => {
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'swift', 'swift',
resolve(inputDir, uniModulesPluginDir, 'utssdk/app-ios/index.uts'), resolve(inputDir, uniModulesPluginDir, 'utssdk/app-ios/index.uts'),
inputDir, inputDir,
...@@ -55,8 +55,8 @@ describe('uts:sourceMap', () => { ...@@ -55,8 +55,8 @@ describe('uts:sourceMap', () => {
expect(sourceMapFile).toBeDefined() expect(sourceMapFile).toBeDefined()
}) })
test('resolveUtsPluginSourceMapFile with utssdk uts=>kotlin', () => { test('resolveUTSPluginSourceMapFile with utssdk uts=>kotlin', () => {
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'kotlin', 'kotlin',
resolve(inputDir, utssdkPluginDir, 'app-android/index.uts'), resolve(inputDir, utssdkPluginDir, 'app-android/index.uts'),
inputDir, inputDir,
...@@ -64,8 +64,8 @@ describe('uts:sourceMap', () => { ...@@ -64,8 +64,8 @@ describe('uts:sourceMap', () => {
) )
expect(sourceMapFile).toBeDefined() expect(sourceMapFile).toBeDefined()
}) })
test('resolveUtsPluginSourceMapFile with utssdk uts=>swift', () => { test('resolveUTSPluginSourceMapFile with utssdk uts=>swift', () => {
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'swift', 'swift',
resolve(inputDir, utssdkPluginDir, 'app-ios/index.uts'), resolve(inputDir, utssdkPluginDir, 'app-ios/index.uts'),
inputDir, inputDir,
...@@ -74,8 +74,8 @@ describe('uts:sourceMap', () => { ...@@ -74,8 +74,8 @@ describe('uts:sourceMap', () => {
expect(sourceMapFile).toBeDefined() expect(sourceMapFile).toBeDefined()
}) })
test('resolveUtsPluginSourceMapFile with uni_modules kt', () => { test('resolveUTSPluginSourceMapFile with uni_modules kt', () => {
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'kotlin', 'kotlin',
resolve(outputDir, uniModulesPluginDir, 'utssdk/app-android/index.kt'), resolve(outputDir, uniModulesPluginDir, 'utssdk/app-android/index.kt'),
inputDir, inputDir,
...@@ -83,15 +83,15 @@ describe('uts:sourceMap', () => { ...@@ -83,15 +83,15 @@ describe('uts:sourceMap', () => {
) )
expect(sourceMapFile).toBeDefined() expect(sourceMapFile).toBeDefined()
}) })
test('resolveUtsPluginSourceMapFile with uni_modules swift', () => { test('resolveUTSPluginSourceMapFile with uni_modules swift', () => {
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'swift', 'swift',
resolve(outputDir, uniModulesPluginDir, 'utssdk/app-ios/index.swift'), resolve(outputDir, uniModulesPluginDir, 'utssdk/app-ios/index.swift'),
inputDir, inputDir,
outputDir outputDir
) )
expect(sourceMapFile).toBeDefined() expect(sourceMapFile).toBeDefined()
const sourceMapFile2 = resolveUtsPluginSourceMapFile( const sourceMapFile2 = resolveUTSPluginSourceMapFile(
'swift', 'swift',
resolve(outputDir, uniModulesPluginDir, 'utssdk/app-ios/src/index.swift'), resolve(outputDir, uniModulesPluginDir, 'utssdk/app-ios/src/index.swift'),
inputDir, inputDir,
...@@ -99,8 +99,8 @@ describe('uts:sourceMap', () => { ...@@ -99,8 +99,8 @@ describe('uts:sourceMap', () => {
) )
expect(sourceMapFile2).toBeDefined() expect(sourceMapFile2).toBeDefined()
}) })
test('resolveUtsPluginSourceMapFile with utssdk kt', () => { test('resolveUTSPluginSourceMapFile with utssdk kt', () => {
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'kotlin', 'kotlin',
resolve(outputDir, utssdkPluginDir, 'app-android/index.kt'), resolve(outputDir, utssdkPluginDir, 'app-android/index.kt'),
inputDir, inputDir,
...@@ -108,8 +108,8 @@ describe('uts:sourceMap', () => { ...@@ -108,8 +108,8 @@ describe('uts:sourceMap', () => {
) )
expect(sourceMapFile).toBeDefined() expect(sourceMapFile).toBeDefined()
}) })
test('resolveUtsPluginSourceMapFile with utssdk swift', () => { test('resolveUTSPluginSourceMapFile with utssdk swift', () => {
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'swift', 'swift',
resolve(outputDir, utssdkPluginDir, 'app-ios/index.swift'), resolve(outputDir, utssdkPluginDir, 'app-ios/index.swift'),
inputDir, inputDir,
...@@ -123,7 +123,7 @@ describe('uts:sourceMap', () => { ...@@ -123,7 +123,7 @@ describe('uts:sourceMap', () => {
uniModulesPluginDir, uniModulesPluginDir,
'utssdk/app-android/login.uts' 'utssdk/app-android/login.uts'
) )
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'kotlin', 'kotlin',
filename, filename,
inputDir, inputDir,
...@@ -153,7 +153,7 @@ describe('uts:sourceMap', () => { ...@@ -153,7 +153,7 @@ describe('uts:sourceMap', () => {
uniModulesPluginDir, uniModulesPluginDir,
'utssdk/app-android/index.kt' 'utssdk/app-android/index.kt'
) )
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'kotlin', 'kotlin',
filename, filename,
inputDir, inputDir,
...@@ -175,7 +175,7 @@ describe('uts:sourceMap', () => { ...@@ -175,7 +175,7 @@ describe('uts:sourceMap', () => {
uniModulesPluginDir, uniModulesPluginDir,
'utssdk/app-ios/src/index.kt' 'utssdk/app-ios/src/index.kt'
) )
const sourceMapFile = resolveUtsPluginSourceMapFile( const sourceMapFile = resolveUTSPluginSourceMapFile(
'swift', 'swift',
filename, filename,
inputDir, inputDir,
......
import path from 'path' import path from 'path'
import { parseUtsSwiftPluginStacktrace } from '../src/stacktrace' import { parseUTSSwiftPluginStacktrace } from '../src/stacktrace'
const stacktrace = `/uts-development-ios/dependences/buildFramework/template/xcode_ust_template/unimoduleTestUts1/src/index.swift:3:12: error: cannot convert return expression of type 'Int' to return type 'String' const stacktrace = `/uts-development-ios/dependences/buildFramework/template/xcode_ust_template/unimoduleTestUTS1/src/index.swift:3:12: error: cannot convert return expression of type 'Int' to return type 'String'
/uts-development-ios/dependences/buildFramework/template/xcode_ust_template/unimoduleTestUts1/src/index.swift:6:12: error: cannot convert return expression of type 'Int' to return type 'String' /uts-development-ios/dependences/buildFramework/template/xcode_ust_template/unimoduleTestUTS1/src/index.swift:6:12: error: cannot convert return expression of type 'Int' to return type 'String'
` `
describe('uts:stacktrace', () => { describe('uts:stacktrace', () => {
test('parseUtsSwiftPluginStacktrace', async () => { test('parseUTSSwiftPluginStacktrace', async () => {
const codes = await parseUtsSwiftPluginStacktrace({ const codes = await parseUTSSwiftPluginStacktrace({
stacktrace, stacktrace,
sourceMapFile: path.resolve( sourceMapFile: path.resolve(
__dirname, __dirname,
......
...@@ -28,8 +28,8 @@ import { ...@@ -28,8 +28,8 @@ import {
resolveIOSComponents, resolveIOSComponents,
resolvePackage, resolvePackage,
} from './utils' } from './utils'
import { parseUtsSwiftPluginStacktrace } from './stacktrace' import { parseUTSSwiftPluginStacktrace } from './stacktrace'
import { resolveUtsPluginSourceMapFile } from './sourceMap' import { resolveUTSPluginSourceMapFile } from './sourceMap'
import { isWindows } from './shared' import { isWindows } from './shared'
import { import {
generateCodeFrameWithKotlinStacktrace, generateCodeFrameWithKotlinStacktrace,
...@@ -311,9 +311,9 @@ export async function compile( ...@@ -311,9 +311,9 @@ export async function compile(
errMsg = compileErrMsg(pkg.id) errMsg = compileErrMsg(pkg.id)
console.error( console.error(
`error: ` + `error: ` +
(await parseUtsSwiftPluginStacktrace({ (await parseUTSSwiftPluginStacktrace({
stacktrace: res.msg, stacktrace: res.msg,
sourceMapFile: resolveUtsPluginSourceMapFile( sourceMapFile: resolveUTSPluginSourceMapFile(
'swift', 'swift',
filename, filename,
inputDir, inputDir,
......
...@@ -4,13 +4,13 @@ import path, { join } from 'path' ...@@ -4,13 +4,13 @@ import path, { join } from 'path'
import AdmZip from 'adm-zip' import AdmZip from 'adm-zip'
import { sync } from 'fast-glob' import { sync } from 'fast-glob'
import { isArray } from '@vue/shared' import { isArray } from '@vue/shared'
import type { UtsResult } from '@dcloudio/uts' import type { UTSResult } from '@dcloudio/uts'
import { get } from 'android-versions' import { get } from 'android-versions'
import { normalizePath, parseJson, resolveSourceMapPath } from './shared' import { normalizePath, parseJson, resolveSourceMapPath } from './shared'
import { import {
CompilerServer, CompilerServer,
genUTSPlatformResource, genUTSPlatformResource,
getUtsCompiler, getUTSCompiler,
getCompilerServer, getCompilerServer,
moveRootIndexSourceMap, moveRootIndexSourceMap,
resolveAndroidDir, resolveAndroidDir,
...@@ -88,7 +88,7 @@ export async function runKotlinProd( ...@@ -88,7 +88,7 @@ export async function runKotlinProd(
}) })
} }
export type RunKotlinDevResult = UtsResult & { export type RunKotlinDevResult = UTSResult & {
type: 'kotlin' type: 'kotlin'
changed: string[] changed: string[]
} }
...@@ -300,7 +300,7 @@ export async function compile( ...@@ -300,7 +300,7 @@ export async function compile(
filename: string, filename: string,
{ inputDir, outputDir, sourceMap, components }: ToKotlinOptions { inputDir, outputDir, sourceMap, components }: ToKotlinOptions
) { ) {
const { bundle, UtsTarget } = getUtsCompiler() const { bundle, UTSTarget } = getUTSCompiler()
// let time = Date.now() // let time = Date.now()
const imports = [...DEFAULT_IMPORTS] const imports = [...DEFAULT_IMPORTS]
const rClass = resolveAndroidResourceClass(filename) const rClass = resolveAndroidResourceClass(filename)
...@@ -330,7 +330,7 @@ export async function compile( ...@@ -330,7 +330,7 @@ export async function compile(
} }
} }
const result = await bundle(UtsTarget.KOTLIN, { const result = await bundle(UTSTarget.KOTLIN, {
input, input,
output: { output: {
isPlugin: true, isPlugin: true,
......
...@@ -18,7 +18,7 @@ const PLATFORM_DIR = { ...@@ -18,7 +18,7 @@ const PLATFORM_DIR = {
swift: 'app-ios', swift: 'app-ios',
} }
export function resolveUtsPluginSourceMapFile( export function resolveUTSPluginSourceMapFile(
target: 'kotlin' | 'swift', target: 'kotlin' | 'swift',
filename: string, filename: string,
inputDir: string, inputDir: string,
...@@ -44,6 +44,8 @@ export function resolveUtsPluginSourceMapFile( ...@@ -44,6 +44,8 @@ export function resolveUtsPluginSourceMapFile(
} }
return sourceMapFile return sourceMapFile
} }
// 兼容旧版本
export const resolveUtsPluginSourceMapFile = resolveUTSPluginSourceMapFile
function resolvePluginDir( function resolvePluginDir(
inputDir: string, inputDir: string,
......
import { originalPositionFor } from './sourceMap' import { originalPositionFor } from './sourceMap'
const splitRE = /\r?\n/ const splitRE = /\r?\n/
const uniModulesSwiftUtsRe = const uniModulesSwiftUTSRe =
/(.*)index.swift:([0-9]+):([0-9]+):\s+error:\s+(.*)/ /(.*)index.swift:([0-9]+):([0-9]+):\s+error:\s+(.*)/
interface ParseUtsPluginStacktraceOptions { interface ParseUTSPluginStacktraceOptions {
stacktrace: string stacktrace: string
sourceRoot: string sourceRoot: string
sourceMapFile: string sourceMapFile: string
} }
export async function parseUtsSwiftPluginStacktrace({ export async function parseUTSSwiftPluginStacktrace({
stacktrace, stacktrace,
sourceRoot, sourceRoot,
sourceMapFile, sourceMapFile,
}: ParseUtsPluginStacktraceOptions) { }: ParseUTSPluginStacktraceOptions) {
const res: string[] = [] const res: string[] = []
const lines = stacktrace.split(splitRE) const lines = stacktrace.split(splitRE)
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
const line = lines[i] const line = lines[i]
const codes = await parseUtsStacktraceLine( const codes = await parseUTSStacktraceLine(
line, line,
uniModulesSwiftUtsRe, uniModulesSwiftUTSRe,
sourceMapFile, sourceMapFile,
sourceRoot sourceRoot
) )
...@@ -34,7 +34,7 @@ export async function parseUtsSwiftPluginStacktrace({ ...@@ -34,7 +34,7 @@ export async function parseUtsSwiftPluginStacktrace({
return res.join('\n') return res.join('\n')
} }
async function parseUtsStacktraceLine( async function parseUTSStacktraceLine(
lineStr: string, lineStr: string,
re: RegExp, re: RegExp,
sourceMapFile: string, sourceMapFile: string,
......
...@@ -4,7 +4,7 @@ import { ...@@ -4,7 +4,7 @@ import {
genComponentsCode, genComponentsCode,
genUTSPlatformResource, genUTSPlatformResource,
getCompilerServer, getCompilerServer,
getUtsCompiler, getUTSCompiler,
isColorSupported, isColorSupported,
moveRootIndexSourceMap, moveRootIndexSourceMap,
parseSwiftPackageWithPluginId, parseSwiftPackageWithPluginId,
...@@ -15,7 +15,7 @@ import { ...@@ -15,7 +15,7 @@ import {
ToSwiftOptions, ToSwiftOptions,
} from './utils' } from './utils'
import { parseJson } from './shared' import { parseJson } from './shared'
import { UtsResult } from '@dcloudio/uts' import { UTSResult } from '@dcloudio/uts'
function parseSwiftPackage(filename: string) { function parseSwiftPackage(filename: string) {
const res = resolvePackage(filename) const res = resolvePackage(filename)
...@@ -61,7 +61,7 @@ export async function runSwiftProd( ...@@ -61,7 +61,7 @@ export async function runSwiftProd(
}) })
} }
export type RunSwiftDevResult = UtsResult & { export type RunSwiftDevResult = UTSResult & {
type: 'swift' type: 'swift'
code: number code: number
msg: string msg: string
...@@ -132,7 +132,7 @@ export async function runSwiftDev( ...@@ -132,7 +132,7 @@ export async function runSwiftDev(
isCli, isCli,
type: is_uni_modules ? 1 : 2, type: is_uni_modules ? 1 : 2,
pluginName: id, pluginName: id,
utsPath: resolveCompilerUtsPath(inputDir, is_uni_modules), utsPath: resolveCompilerUTSPath(inputDir, is_uni_modules),
swiftPath: resolveCompilerSwiftPath(outputDir, is_uni_modules), swiftPath: resolveCompilerSwiftPath(outputDir, is_uni_modules),
}) })
result.code = code result.code = code
...@@ -142,7 +142,7 @@ export async function runSwiftDev( ...@@ -142,7 +142,7 @@ export async function runSwiftDev(
return result return result
} }
function resolveCompilerUtsPath(projectPath: string, is_uni_modules: boolean) { function resolveCompilerUTSPath(projectPath: string, is_uni_modules: boolean) {
return path.resolve(projectPath, is_uni_modules ? 'uni_modules' : 'utssdk') return path.resolve(projectPath, is_uni_modules ? 'uni_modules' : 'utssdk')
} }
...@@ -161,7 +161,7 @@ export async function compile( ...@@ -161,7 +161,7 @@ export async function compile(
filename: string, filename: string,
{ inputDir, outputDir, sourceMap, components }: ToSwiftOptions { inputDir, outputDir, sourceMap, components }: ToSwiftOptions
) { ) {
const { bundle, UtsTarget } = getUtsCompiler() const { bundle, UTSTarget } = getUTSCompiler()
// let time = Date.now() // let time = Date.now()
const componentsCode = genComponentsCode(filename, components) const componentsCode = genComponentsCode(filename, components)
const { namespace, id: pluginId } = parseSwiftPackage(filename) const { namespace, id: pluginId } = parseSwiftPackage(filename)
...@@ -185,7 +185,7 @@ export async function compile( ...@@ -185,7 +185,7 @@ export async function compile(
return return
} }
} }
const result = await bundle(UtsTarget.SWIFT, { const result = await bundle(UTSTarget.SWIFT, {
input, input,
output: { output: {
isPlugin: true, isPlugin: true,
......
import path, { basename, resolve } from 'path' import path, { basename, resolve } from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import type { parse, bundle, UtsTarget } from '@dcloudio/uts' import type { parse, bundle, UTSTarget } from '@dcloudio/uts'
import { camelize, capitalize, extend } from '@vue/shared' import { camelize, capitalize, extend } from '@vue/shared'
import glob from 'fast-glob' import glob from 'fast-glob'
import { Module, ModuleItem } from '../types/types' import { Module, ModuleItem } from '../types/types'
...@@ -28,10 +28,10 @@ export function resolveUTSSourceMapPath() { ...@@ -28,10 +28,10 @@ export function resolveUTSSourceMapPath() {
return resolveSourceMapPath() return resolveSourceMapPath()
} }
export function getUtsCompiler(): { export function getUTSCompiler(): {
parse: typeof parse parse: typeof parse
bundle: typeof bundle bundle: typeof bundle
UtsTarget: typeof UtsTarget UTSTarget: typeof UTSTarget
} { } {
// eslint-disable-next-line no-restricted-globals // eslint-disable-next-line no-restricted-globals
return require('@dcloudio/uts') return require('@dcloudio/uts')
......
import { resolve } from 'path' import { resolve } from 'path'
import type { import type {
UtsBundleOptions, UTSBundleOptions,
UtsOptions, UTSOptions,
UtsParseOptions, UTSParseOptions,
UtsResult, UTSResult,
} from './types' } from './types'
import { normalizePath } from './utils' import { normalizePath } from './utils'
...@@ -12,7 +12,7 @@ const bindings = !!bindingsOverride ...@@ -12,7 +12,7 @@ const bindings = !!bindingsOverride
? require(resolve(bindingsOverride)) ? require(resolve(bindingsOverride))
: require('./binding').default : require('./binding').default
function resolveOptions(options: UtsOptions) { function resolveOptions(options: UTSOptions) {
const { input, output } = options const { input, output } = options
if (!input?.root) { if (!input?.root) {
return return
...@@ -46,14 +46,14 @@ function resolveOptions(options: UtsOptions) { ...@@ -46,14 +46,14 @@ function resolveOptions(options: UtsOptions) {
return options return options
} }
export function parse(source: string, options: UtsParseOptions = {}) { export function parse(source: string, options: UTSParseOptions = {}) {
options.noColor = !!options.noColor options.noColor = !!options.noColor
return bindings return bindings
.parse(source, toBuffer(options)) .parse(source, toBuffer(options))
.then((res: string) => JSON.parse(res)) .then((res: string) => JSON.parse(res))
} }
export function toKotlin(options: UtsOptions): Promise<UtsResult> { export function toKotlin(options: UTSOptions): Promise<UTSResult> {
const kotlinOptions = resolveOptions(options) const kotlinOptions = resolveOptions(options)
if (!kotlinOptions) { if (!kotlinOptions) {
return Promise.resolve({}) return Promise.resolve({})
...@@ -63,7 +63,7 @@ export function toKotlin(options: UtsOptions): Promise<UtsResult> { ...@@ -63,7 +63,7 @@ export function toKotlin(options: UtsOptions): Promise<UtsResult> {
.then((res: string) => JSON.parse(res)) .then((res: string) => JSON.parse(res))
} }
export function bundleKotlin(options: UtsBundleOptions): Promise<UtsResult> { export function bundleKotlin(options: UTSBundleOptions): Promise<UTSResult> {
const bundleOptions = resolveOptions(options) const bundleOptions = resolveOptions(options)
if (!bundleOptions) { if (!bundleOptions) {
return Promise.resolve({}) return Promise.resolve({})
...@@ -73,7 +73,7 @@ export function bundleKotlin(options: UtsBundleOptions): Promise<UtsResult> { ...@@ -73,7 +73,7 @@ export function bundleKotlin(options: UtsBundleOptions): Promise<UtsResult> {
.then((res: string) => JSON.parse(res)) .then((res: string) => JSON.parse(res))
} }
export function toSwift(options: UtsOptions): Promise<UtsResult> { export function toSwift(options: UTSOptions): Promise<UTSResult> {
const swiftOptions = resolveOptions(options) const swiftOptions = resolveOptions(options)
if (!swiftOptions) { if (!swiftOptions) {
return Promise.resolve({}) return Promise.resolve({})
...@@ -83,7 +83,7 @@ export function toSwift(options: UtsOptions): Promise<UtsResult> { ...@@ -83,7 +83,7 @@ export function toSwift(options: UtsOptions): Promise<UtsResult> {
.then((res: string) => JSON.parse(res)) .then((res: string) => JSON.parse(res))
} }
export function bundleSwift(options: UtsBundleOptions): Promise<UtsResult> { export function bundleSwift(options: UTSBundleOptions): Promise<UTSResult> {
const bundleOptions = resolveOptions(options) const bundleOptions = resolveOptions(options)
if (!bundleOptions) { if (!bundleOptions) {
return Promise.resolve({}) return Promise.resolve({})
......
import { bundleKotlin, bundleSwift } from './api' import { bundleKotlin, bundleSwift } from './api'
import { UtsBundleOptions, UtsResult, UtsTarget } from './types' import { UTSBundleOptions, UTSResult, UTSTarget } from './types'
export { UtsTarget, UtsResult } from './types' export { UTSTarget, UTSResult } from './types'
export type UtsMode = 'dev' | 'build' export type UTSMode = 'dev' | 'build'
export const UtsTargetExtNames = { export const UTSTargetExtNames = {
[UtsTarget.KOTLIN]: 'kt', [UTSTarget.KOTLIN]: 'kt',
[UtsTarget.SWIFT]: 'swift', [UTSTarget.SWIFT]: 'swift',
} as const } as const
export interface ToOptions { export interface ToOptions {
/** /**
...@@ -52,12 +52,12 @@ export interface ToOptions { ...@@ -52,12 +52,12 @@ export interface ToOptions {
export { parse, bundleKotlin, bundleSwift } from './api' export { parse, bundleKotlin, bundleSwift } from './api'
export function bundle( export function bundle(
target: UtsTarget, target: UTSTarget,
opts: UtsBundleOptions opts: UTSBundleOptions
): Promise<UtsResult> { ): Promise<UTSResult> {
if (target === UtsTarget.KOTLIN) { if (target === UTSTarget.KOTLIN) {
return bundleKotlin(opts) return bundleKotlin(opts)
} else if (target === UtsTarget.SWIFT) { } else if (target === UTSTarget.SWIFT) {
return bundleSwift(opts) return bundleSwift(opts)
} }
return Promise.resolve({}) return Promise.resolve({})
......
export enum UtsTarget { export enum UTSTarget {
KOTLIN = 'kotlin', KOTLIN = 'kotlin',
SWIFT = 'swift', SWIFT = 'swift',
} }
export interface UtsParserConfig { export interface UTSParserConfig {
/** /**
* Defaults to `false` * Defaults to `false`
*/ */
allowImportWithoutSpecifiers?: boolean allowImportWithoutSpecifiers?: boolean
} }
export type UtsParseOptions = UtsParserConfig & { export type UTSParseOptions = UTSParserConfig & {
filename?: string filename?: string
comments?: boolean comments?: boolean
noColor?: boolean noColor?: boolean
} }
export type UtsInputOptions = UtsParseOptions & { export type UTSInputOptions = UTSParseOptions & {
root: string root: string
pluginId: string pluginId: string
filename: string filename: string
...@@ -24,7 +24,7 @@ export type UtsInputOptions = UtsParseOptions & { ...@@ -24,7 +24,7 @@ export type UtsInputOptions = UtsParseOptions & {
paths: Record<string, string> paths: Record<string, string>
} }
export type UtsOutputOptions = { export type UTSOutputOptions = {
outDir: string outDir: string
package: string package: string
imports?: string[] imports?: string[]
...@@ -35,16 +35,16 @@ export type UtsOutputOptions = { ...@@ -35,16 +35,16 @@ export type UtsOutputOptions = {
noColor?: boolean noColor?: boolean
isPlugin?: boolean isPlugin?: boolean
} }
export interface UtsOptions { export interface UTSOptions {
input: UtsInputOptions input: UTSInputOptions
output: UtsOutputOptions output: UTSOutputOptions
} }
export interface UtsResult { export interface UTSResult {
filename?: string filename?: string
deps?: string[] deps?: string[]
time?: number time?: number
error?: Error error?: Error
} }
export interface UtsBundleOptions extends UtsOptions {} export interface UTSBundleOptions extends UTSOptions {}
...@@ -88,7 +88,7 @@ export function initEnv( ...@@ -88,7 +88,7 @@ export function initEnv(
: process.cwd() : process.cwd()
// TODO 待优化 // TODO 待优化
initUtsPlatform(options) initUTSPlatform(options)
if ( if (
options.platform === 'quickapp-webview-huawei' || options.platform === 'quickapp-webview-huawei' ||
...@@ -170,7 +170,7 @@ export function initEnv( ...@@ -170,7 +170,7 @@ export function initEnv(
console.log(M['compiling']) console.log(M['compiling'])
} }
function initUtsPlatform(options: CliOptions) { function initUTSPlatform(options: CliOptions) {
if (options.platform === 'app-android') { if (options.platform === 'app-android') {
process.env.UNI_UTS_PLATFORM = 'app-android' process.env.UNI_UTS_PLATFORM = 'app-android'
options.platform = 'app' options.platform = 'app'
......
...@@ -5,13 +5,13 @@ import { ...@@ -5,13 +5,13 @@ import {
extensions, extensions,
normalizePath, normalizePath,
requireResolve, requireResolve,
resolveUtsModule, resolveUTSModule,
resolveUtsAppModule, resolveUTSAppModule,
} from '@dcloudio/uni-cli-shared' } from '@dcloudio/uni-cli-shared'
import { VitePluginUniResolvedOptions } from '..' import { VitePluginUniResolvedOptions } from '..'
function resolveUtsModuleProxyFile(id: string, importer: string) { function resolveUTSModuleProxyFile(id: string, importer: string) {
const file = resolveUtsAppModule(id, importer) const file = resolveUTSAppModule(id, importer)
if (file) { if (file) {
return file + '?uts-proxy' return file + '?uts-proxy'
} }
...@@ -23,8 +23,8 @@ export const customResolver: ResolverFunction = (updatedId, importer) => { ...@@ -23,8 +23,8 @@ export const customResolver: ResolverFunction = (updatedId, importer) => {
: process.env.UNI_INPUT_DIR : process.env.UNI_INPUT_DIR
const utsModuleFile = const utsModuleFile =
process.env.UNI_PLATFORM === 'app' process.env.UNI_PLATFORM === 'app'
? resolveUtsModuleProxyFile(updatedId, utsImporter) ? resolveUTSModuleProxyFile(updatedId, utsImporter)
: resolveUtsModule(updatedId, utsImporter) : resolveUTSModule(updatedId, utsImporter)
if (utsModuleFile) { if (utsModuleFile) {
return isWindows ? normalizePath(utsModuleFile) : utsModuleFile return isWindows ? normalizePath(utsModuleFile) : utsModuleFile
} }
......
import path from 'path' import path from 'path'
import debug from 'debug' import debug from 'debug'
import { Plugin } from 'vite' import { Plugin } from 'vite'
import { resolveBuiltIn, resolveUtsModule } from '@dcloudio/uni-cli-shared' import { resolveBuiltIn, resolveUTSModule } from '@dcloudio/uni-cli-shared'
import { VitePluginUniResolvedOptions } from '../..' import { VitePluginUniResolvedOptions } from '../..'
...@@ -40,7 +40,7 @@ export function uniResolveIdPlugin( ...@@ -40,7 +40,7 @@ export function uniResolveIdPlugin(
)) ))
} }
if (process.env.UNI_PLATFORM !== 'app') { if (process.env.UNI_PLATFORM !== 'app') {
return resolveUtsModule( return resolveUTSModule(
id, id,
importer ? path.dirname(importer) : process.env.UNI_INPUT_DIR importer ? path.dirname(importer) : process.env.UNI_INPUT_DIR
) )
......
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const { parse, bundle, UtsTarget } = require('../packages/uts/dist') const { parse, bundle, UTSTarget } = require('../packages/uts/dist')
const projectDir = path.resolve(__dirname, '../packages/playground/uts') const projectDir = path.resolve(__dirname, '../packages/playground/uts')
const outDir = path.resolve(projectDir, 'unpackage/dist/dev/app-plus') const outDir = path.resolve(projectDir, 'unpackage/dist/dev/app-plus')
...@@ -21,7 +21,7 @@ parse( ...@@ -21,7 +21,7 @@ parse(
}) })
async function testKotlin() { async function testKotlin() {
const start = Date.now() const start = Date.now()
await bundle(UtsTarget.KOTLIN, { await bundle(UTSTarget.KOTLIN, {
input: { input: {
root: projectDir, root: projectDir,
filename: path.resolve( filename: path.resolve(
...@@ -60,7 +60,7 @@ async function testKotlin() { ...@@ -60,7 +60,7 @@ async function testKotlin() {
) )
) )
}) })
await bundle(UtsTarget.KOTLIN, { await bundle(UTSTarget.KOTLIN, {
input: { input: {
root: projectDir, root: projectDir,
filename: path.resolve( filename: path.resolve(
...@@ -89,7 +89,7 @@ async function testKotlin() { ...@@ -89,7 +89,7 @@ async function testKotlin() {
async function testKotlinComponent() { async function testKotlinComponent() {
const start = Date.now() const start = Date.now()
await bundle(UtsTarget.KOTLIN, { await bundle(UTSTarget.KOTLIN, {
input: { input: {
root: projectDir, root: projectDir,
pluginId: 'animation-view', pluginId: 'animation-view',
...@@ -131,7 +131,7 @@ async function testKotlinComponent() { ...@@ -131,7 +131,7 @@ async function testKotlinComponent() {
async function testSwift() { async function testSwift() {
const start = Date.now() const start = Date.now()
await bundle(UtsTarget.SWIFT, { await bundle(UTSTarget.SWIFT, {
input: { input: {
root: projectDir, root: projectDir,
filename: path.resolve( filename: path.resolve(
...@@ -161,7 +161,7 @@ async function testSwift() { ...@@ -161,7 +161,7 @@ async function testSwift() {
) )
) )
}) })
await bundle(UtsTarget.SWIFT, { await bundle(UTSTarget.SWIFT, {
input: { input: {
root: projectDir, root: projectDir,
filename: path.resolve( filename: path.resolve(
...@@ -183,7 +183,7 @@ async function testSwift() { ...@@ -183,7 +183,7 @@ async function testSwift() {
async function testSwiftComponent() { async function testSwiftComponent() {
const start = Date.now() const start = Date.now()
await bundle(UtsTarget.SWIFT, { await bundle(UTSTarget.SWIFT, {
input: { input: {
root: projectDir, root: projectDir,
filename: path.resolve( filename: path.resolve(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册