Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
0be34a20
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
0be34a20
编写于
11月 23, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): compiler
上级
3c82233b
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
285 addition
and
29 deletion
+285
-29
packages/uni-uts-v1/__tests__/examples/uts/unpackage/cache/app-android/uts/uni_modules/test-uts/manifest.json
.../cache/app-android/uts/uni_modules/test-uts/manifest.json
+3
-0
packages/uni-uts-v1/__tests__/examples/uts/unpackage/cache/app-ios/uts/uni_modules/test-uts/manifest.json
...kage/cache/app-ios/uts/uni_modules/test-uts/manifest.json
+3
-0
packages/uni-uts-v1/__tests__/manifest.spec.ts
packages/uni-uts-v1/__tests__/manifest.spec.ts
+121
-7
packages/uni-uts-v1/__tests__/sourceMap.spec.ts
packages/uni-uts-v1/__tests__/sourceMap.spec.ts
+0
-8
packages/uni-uts-v1/src/index.ts
packages/uni-uts-v1/src/index.ts
+34
-6
packages/uni-uts-v1/src/kotlin.ts
packages/uni-uts-v1/src/kotlin.ts
+1
-1
packages/uni-uts-v1/src/manifest/index.ts
packages/uni-uts-v1/src/manifest/index.ts
+2
-0
packages/uni-uts-v1/src/manifest/manifest.ts
packages/uni-uts-v1/src/manifest/manifest.ts
+9
-1
packages/uni-uts-v1/src/manifest/sourceMap.ts
packages/uni-uts-v1/src/manifest/sourceMap.ts
+109
-0
packages/uni-uts-v1/src/swift.ts
packages/uni-uts-v1/src/swift.ts
+1
-1
packages/uni-uts-v1/src/utils.ts
packages/uni-uts-v1/src/utils.ts
+2
-5
未找到文件。
packages/uni-uts-v1/__tests__/examples/uts/unpackage/cache/app-android/uts/uni_modules/test-uts/manifest.json
浏览文件 @
0be34a20
...
...
@@ -10,6 +10,9 @@
"utssdk/common/utils.uts"
:
{
"md5"
:
"d41d8cd98f00b204e9800998ecf8427e"
},
"utssdk/index.uts"
:
{
"md5"
:
"d41d8cd98f00b204e9800998ecf8427e"
},
"package.json"
:
{
"md5"
:
"9595031a0d4158abb72060cdf3a200c1"
},
...
...
packages/uni-uts-v1/__tests__/examples/uts/unpackage/cache/app-ios/uts/uni_modules/test-uts/manifest.json
浏览文件 @
0be34a20
...
...
@@ -10,6 +10,9 @@
"utssdk/common/utils.uts"
:
{
"md5"
:
"d41d8cd98f00b204e9800998ecf8427e"
},
"utssdk/index.uts"
:
{
"md5"
:
"d41d8cd98f00b204e9800998ecf8427e"
},
"package.json"
:
{
"md5"
:
"9595031a0d4158abb72060cdf3a200c1"
},
...
...
packages/uni-uts-v1/__tests__/manifest.spec.ts
浏览文件 @
0be34a20
import
{
resolve
}
from
'
path
'
import
path
,
{
resolve
}
from
'
path
'
import
{
checkManifest
,
genManifestFile
,
resolveManifestJson
,
resolvePluginFiles
,
}
from
'
../src/manifest/manifest
'
import
{
checkKotlinCompile
,
checkSwiftCompile
}
from
'
../src/manifest/index
'
import
{
resolveSourceMapCacheFilename
,
resolveSourceMapFilename
,
}
from
'
../src/manifest/sourceMap
'
const
pluginModuleDir
=
resolve
(
__dirname
,
'
examples/uts/uni_modules/test-uts
'
)
const
pluginDir
=
resolve
(
__dirname
,
'
examples/uts/utssdk/test-uts
'
)
...
...
@@ -45,6 +50,7 @@ describe('manifest', () => {
await
resolvePluginFiles
(
'
app-android
'
,
pluginModuleDir
,
true
)
).
toEqual
([
'
package.json
'
,
'
utssdk/index.uts
'
,
'
utssdk/common/utils.uts
'
,
'
utssdk/app-android/index.uts
'
,
'
utssdk/app-android/assets/test.json
'
,
...
...
@@ -59,16 +65,17 @@ describe('manifest', () => {
])
expect
(
await
resolvePluginFiles
(
'
app-ios
'
,
pluginModuleDir
,
true
)).
toEqual
([
'
package.json
'
,
'
utssdk/index.uts
'
,
'
utssdk/common/utils.uts
'
,
'
utssdk/app-ios/index.uts
'
,
'
utssdk/app-ios/assets/test.json
'
,
])
})
test
(
'
check manifest
'
,
async
()
=>
{
// await genManifestFile('app-android',
pluginModuleOptions)
// await genManifestFile('app-ios',
pluginModuleOptions)
// await genManifestFile('app-android',
pluginOptions)
// await genManifestFile('app-ios',
pluginOptions)
await
genManifestFile
(
'
app-android
'
,
pluginModuleOptions
)
await
genManifestFile
(
'
app-ios
'
,
pluginModuleOptions
)
await
genManifestFile
(
'
app-android
'
,
pluginOptions
)
await
genManifestFile
(
'
app-ios
'
,
pluginOptions
)
const
manifest
=
resolveManifestJson
(
'
app-android
'
,
pluginModuleOptions
.
pluginRelativeDir
,
...
...
@@ -102,7 +109,7 @@ describe('manifest', () => {
test
(
'
gen android manifest
'
,
async
()
=>
{
const
res
=
await
checkKotlinCompile
(
'
standard
'
,
pluginModuleOptions
)
expect
(
res
.
expired
).
toBe
(
false
)
expect
(
res
.
files
.
length
).
toBe
(
4
)
expect
(
res
.
files
.
length
).
toBe
(
5
)
expect
(
res
.
tips
).
toBeTruthy
()
const
res1
=
await
checkKotlinCompile
(
'
standard
'
,
pluginOptions
)
...
...
@@ -113,11 +120,118 @@ describe('manifest', () => {
test
(
'
gen ios manifest
'
,
async
()
=>
{
const
res
=
await
checkSwiftCompile
(
'
standard
'
,
pluginModuleOptions
)
expect
(
res
.
expired
).
toBe
(
false
)
expect
(
res
.
files
.
length
).
toBe
(
4
)
expect
(
res
.
files
.
length
).
toBe
(
5
)
expect
(
res
.
tips
).
toBe
(
''
)
const
res1
=
await
checkSwiftCompile
(
'
standard
'
,
pluginOptions
)
expect
(
res1
.
expired
).
toBe
(
false
)
expect
(
res1
.
files
.
length
).
toBe
(
4
)
expect
(
res1
.
tips
).
toBe
(
''
)
})
test
(
'
sourcemap
'
,
()
=>
{
expect
(
resolveSourceMapFilename
(
'
app-android
'
,
pluginModuleOptions
.
pluginRelativeDir
,
outputDir
,
true
).
endsWith
(
path
.
join
(
'
.sourcemap
'
,
'
app
'
,
'
uni_modules
'
,
pluginModuleOptions
.
id
,
'
utssdk
'
,
'
app-android
'
,
'
index.kt.map
'
)
)
).
toBe
(
true
)
expect
(
resolveSourceMapFilename
(
'
app-ios
'
,
pluginModuleOptions
.
pluginRelativeDir
,
outputDir
,
true
).
endsWith
(
path
.
join
(
'
.sourcemap
'
,
'
app
'
,
'
uni_modules
'
,
pluginModuleOptions
.
id
,
'
utssdk
'
,
'
app-ios
'
,
'
index.swift.map
'
)
)
).
toBe
(
true
)
expect
(
resolveSourceMapCacheFilename
(
'
app-android
'
,
cacheDir
,
pluginModuleOptions
.
pluginRelativeDir
).
endsWith
(
path
.
join
(
'
uni_modules
'
,
'
test-uts
'
,
'
index.kt.map
'
))
).
toBe
(
true
)
expect
(
resolveSourceMapCacheFilename
(
'
app-ios
'
,
cacheDir
,
pluginModuleOptions
.
pluginRelativeDir
).
endsWith
(
path
.
join
(
'
uni_modules
'
,
'
test-uts
'
,
'
index.swift.map
'
))
).
toBe
(
true
)
expect
(
resolveSourceMapFilename
(
'
app-android
'
,
pluginOptions
.
pluginRelativeDir
,
outputDir
,
false
).
endsWith
(
path
.
join
(
'
.sourcemap
'
,
'
app
'
,
'
utssdk
'
,
pluginOptions
.
id
,
'
app-android
'
,
'
index.kt.map
'
)
)
).
toBe
(
true
)
expect
(
resolveSourceMapFilename
(
'
app-ios
'
,
pluginOptions
.
pluginRelativeDir
,
outputDir
,
false
).
endsWith
(
path
.
join
(
'
.sourcemap
'
,
'
app
'
,
'
utssdk
'
,
pluginOptions
.
id
,
'
app-ios
'
,
'
index.swift.map
'
)
)
).
toBe
(
true
)
expect
(
resolveSourceMapCacheFilename
(
'
app-android
'
,
cacheDir
,
pluginOptions
.
pluginRelativeDir
).
endsWith
(
path
.
join
(
'
utssdk
'
,
'
test-uts
'
,
'
index.kt.map
'
))
).
toBe
(
true
)
expect
(
resolveSourceMapCacheFilename
(
'
app-ios
'
,
cacheDir
,
pluginOptions
.
pluginRelativeDir
).
endsWith
(
path
.
join
(
'
utssdk
'
,
'
test-uts
'
,
'
index.swift.map
'
))
).
toBe
(
true
)
})
})
packages/uni-uts-v1/__tests__/sourceMap.spec.ts
浏览文件 @
0be34a20
...
...
@@ -22,7 +22,6 @@ describe('uts:sourceMap', () => {
inputDir
,
outputDir
)
console
.
log
(
sourceMapFile
)
expect
(
sourceMapFile
).
toBeDefined
()
expect
(
resolveUtsPluginSourceMapFile
(
...
...
@@ -53,7 +52,6 @@ describe('uts:sourceMap', () => {
inputDir
,
outputDir
)
console
.
log
(
sourceMapFile
)
expect
(
sourceMapFile
).
toBeDefined
()
})
...
...
@@ -64,7 +62,6 @@ describe('uts:sourceMap', () => {
inputDir
,
outputDir
)
console
.
log
(
sourceMapFile
)
expect
(
sourceMapFile
).
toBeDefined
()
})
test
(
'
resolveUtsPluginSourceMapFile with utssdk uts=>swift
'
,
()
=>
{
...
...
@@ -74,7 +71,6 @@ describe('uts:sourceMap', () => {
inputDir
,
outputDir
)
console
.
log
(
sourceMapFile
)
expect
(
sourceMapFile
).
toBeDefined
()
})
...
...
@@ -85,7 +81,6 @@ describe('uts:sourceMap', () => {
inputDir
,
outputDir
)
console
.
log
(
sourceMapFile
)
expect
(
sourceMapFile
).
toBeDefined
()
})
test
(
'
resolveUtsPluginSourceMapFile with uni_modules swift
'
,
()
=>
{
...
...
@@ -95,7 +90,6 @@ describe('uts:sourceMap', () => {
inputDir
,
outputDir
)
console
.
log
(
sourceMapFile
)
expect
(
sourceMapFile
).
toBeDefined
()
})
test
(
'
resolveUtsPluginSourceMapFile with utssdk kt
'
,
()
=>
{
...
...
@@ -105,7 +99,6 @@ describe('uts:sourceMap', () => {
inputDir
,
outputDir
)
console
.
log
(
sourceMapFile
)
expect
(
sourceMapFile
).
toBeDefined
()
})
test
(
'
resolveUtsPluginSourceMapFile with utssdk swift
'
,
()
=>
{
...
...
@@ -115,7 +108,6 @@ describe('uts:sourceMap', () => {
inputDir
,
outputDir
)
console
.
log
(
sourceMapFile
)
expect
(
sourceMapFile
).
toBeDefined
()
})
test
(
'
generatedPositionFor
'
,
async
()
=>
{
...
...
packages/uni-uts-v1/src/index.ts
浏览文件 @
0be34a20
...
...
@@ -14,7 +14,13 @@ import {
generateCodeFrameWithKotlinStacktrace
,
generateCodeFrameWithSwiftStacktrace
,
}
from
'
./legacy
'
import
{
checkCompile
,
genManifestFile
,
initCheckOptionsEnv
}
from
'
./manifest
'
import
{
checkCompile
,
genManifestFile
,
initCheckOptionsEnv
,
restoreSourceMap
,
storeSourceMap
,
}
from
'
./manifest
'
export
const
sourcemap
=
{
generateCodeFrameWithKotlinStacktrace
,
...
...
@@ -90,14 +96,14 @@ export async function compile(pluginDir: string) {
if
(
isWindows
)
{
process
.
env
.
UNI_UTS_TIPS
=
`iOS手机在windows上真机运行时uts插件代码修改需提交云端打包自定义基座才能生效`
return
{
code
,
code
:
parseErrMsg
(
code
,
errMsg
)
,
deps
,
}
}
if
(
process
.
env
.
HX_USE_BASE_TYPE
===
'
standard
'
)
{
process
.
env
.
UNI_UTS_TIPS
=
`iOS手机在标准基座真机或模拟器运行暂不支持uts插件,如需调用uts插件请使用自定义基座`
return
{
code
,
code
:
parseErrMsg
(
code
,
errMsg
)
,
deps
,
}
}
...
...
@@ -106,7 +112,8 @@ export async function compile(pluginDir: string) {
// dev 模式
if
(
cacheDir
)
{
// 检查缓存
let
start
=
Date
.
now
()
// let start = Date.now()
// console.log('uts插件[' + pkg.id + ']start', start)
const
res
=
await
checkCompile
(
utsPlatform
,
process
.
env
.
HX_USE_BASE_TYPE
,
...
...
@@ -120,9 +127,11 @@ export async function compile(pluginDir: string) {
is_uni_modules
:
pkg
.
is_uni_modules
,
}
)
console
.
log
(
'
uts插件[
'
+
pkg
.
id
+
'
]缓存检查耗时:
'
,
Date
.
now
()
-
start
)
// console.log('uts插件[' + pkg.id + ']end', Date.now())
// console.log('uts插件[' + pkg.id + ']缓存检查耗时:', Date.now() - start)
if
(
!
res
.
expired
)
{
if
(
utsPlatform
===
'
app-android
'
)
{
// 拷贝 dex
const
cacheFile
=
resolveDexCacheFile
(
pluginRelativeDir
,
outputDir
)
if
(
cacheFile
)
{
copySync
(
...
...
@@ -131,12 +140,22 @@ export async function compile(pluginDir: string) {
)
}
}
// 还原 sourcemap
restoreSourceMap
(
utsPlatform
,
pluginRelativeDir
,
outputDir
,
cacheDir
,
pkg
.
is_uni_modules
)
if
(
res
.
tips
)
{
console
.
warn
(
res
.
tips
)
}
return
{
code
,
code
:
parseErrMsg
(
code
,
errMsg
)
,
// 所有文件加入依赖
deps
:
res
.
files
.
map
((
name
)
=>
join
(
pluginDir
,
name
)),
}
...
...
@@ -188,6 +207,15 @@ export async function compile(pluginDir: string) {
}
// 生成缓存文件
if
(
cacheDir
&&
isSuccess
)
{
// 存储 sourcemap
storeSourceMap
(
utsPlatform
,
pluginRelativeDir
,
outputDir
,
cacheDir
,
pkg
.
is_uni_modules
)
// 生成 manifest
genManifestFile
(
utsPlatform
,
{
pluginDir
,
env
,
...
...
packages/uni-uts-v1/src/kotlin.ts
浏览文件 @
0be34a20
...
...
@@ -306,7 +306,7 @@ export async function compile(
isPlugin
:
true
,
outDir
:
outputDir
,
package
:
parseKotlinPackage
(
filename
).
package
,
sourceMap
:
sourceMap
?
resolveUTSSourceMapPath
(
filename
)
:
false
,
sourceMap
:
sourceMap
?
resolveUTSSourceMapPath
()
:
false
,
extname
:
'
kt
'
,
imports
,
logFilename
:
true
,
...
...
packages/uni-uts-v1/src/manifest/index.ts
浏览文件 @
0be34a20
...
...
@@ -15,6 +15,8 @@ import {
export
{
genManifestFile
}
from
'
./manifest
'
export
{
restoreSourceMap
,
storeSourceMap
}
from
'
./sourceMap
'
interface
PlatformOptions
{
customRes
:
string
[]
}
...
...
packages/uni-uts-v1/src/manifest/manifest.ts
浏览文件 @
0be34a20
...
...
@@ -130,7 +130,15 @@ async function resolvePluginCommonFiles(
pluginDir
:
string
,
is_uni_modules
:
boolean
)
{
return
glob
([
'
*
'
,
(
is_uni_modules
?
'
utssdk/
'
:
''
)
+
'
common/**/*
'
],
{
const
patterns
=
[
'
*
'
]
if
(
is_uni_modules
)
{
patterns
.
push
(
'
utssdk/*.uts
'
)
patterns
.
push
(
'
utssdk/common/**/*
'
)
}
else
{
patterns
.
push
(
'
common/**/*
'
)
}
return
glob
(
patterns
,
{
ignore
:
[
'
changelog.md
'
,
'
readme.md
'
],
cwd
:
pluginDir
,
})
}
...
...
packages/uni-uts-v1/src/manifest/sourceMap.ts
0 → 100644
浏览文件 @
0be34a20
import
{
copySync
,
existsSync
}
from
'
fs-extra
'
import
{
join
}
from
'
path
'
import
{
resolveSourceMapPath
}
from
'
../shared
'
import
{
APP_PLATFORM
}
from
'
./utils
'
function
getSourceMapFilename
(
platform
:
APP_PLATFORM
)
{
return
`index
${
platform
===
'
app-android
'
?
'
.kt
'
:
'
.swift
'
}
.map`
}
/**
* 缓存 sourcemap
* @param pluginRelativeDir
* @param outputDir
* @param cacheDir
*/
export
function
storeSourceMap
(
platform
:
APP_PLATFORM
,
pluginRelativeDir
:
string
,
outputDir
:
string
,
cacheDir
:
string
,
is_uni_modules
:
boolean
)
{
const
sourceMapFilename
=
resolveSourceMapFilename
(
platform
,
pluginRelativeDir
,
outputDir
,
is_uni_modules
)
if
(
existsSync
(
sourceMapFilename
))
{
copySync
(
sourceMapFilename
,
resolveSourceMapCacheFilename
(
platform
,
cacheDir
,
pluginRelativeDir
)
)
return
true
}
return
false
}
/**
* 拷贝 sourcemap
* @param pluginRelativeDir
* @param outputDir
* @param cacheDir
*/
export
function
restoreSourceMap
(
platform
:
APP_PLATFORM
,
pluginRelativeDir
:
string
,
outputDir
:
string
,
cacheDir
:
string
,
is_uni_modules
:
boolean
)
{
const
sourceMapCacheFile
=
resolveSourceMapCacheFile
(
platform
,
cacheDir
,
pluginRelativeDir
)
if
(
sourceMapCacheFile
)
{
copySync
(
sourceMapCacheFile
,
resolveSourceMapFilename
(
platform
,
pluginRelativeDir
,
outputDir
,
is_uni_modules
)
)
}
}
export
function
resolveSourceMapFilename
(
platform
:
APP_PLATFORM
,
pluginRelativeDir
:
string
,
outputDir
:
string
,
is_uni_modules
:
boolean
)
{
return
join
(
resolveSourceMapPath
(
outputDir
,
'
app
'
),
pluginRelativeDir
,
is_uni_modules
?
'
utssdk
'
:
''
,
platform
,
getSourceMapFilename
(
platform
)
)
}
export
function
resolveSourceMapCacheFilename
(
platform
:
APP_PLATFORM
,
cacheDir
:
string
,
pluginRelativeDir
:
string
)
{
return
join
(
cacheDir
,
platform
,
'
uts
'
,
pluginRelativeDir
,
getSourceMapFilename
(
platform
)
)
}
function
resolveSourceMapCacheFile
(
platform
:
APP_PLATFORM
,
cacheDir
:
string
,
pluginRelativeDir
:
string
)
{
const
file
=
resolveSourceMapCacheFilename
(
platform
,
cacheDir
,
pluginRelativeDir
)
return
(
existsSync
(
file
)
&&
file
)
||
''
}
packages/uni-uts-v1/src/swift.ts
浏览文件 @
0be34a20
...
...
@@ -146,7 +146,7 @@ export async function compile(
isPlugin
:
true
,
outDir
:
outputDir
,
package
:
parseSwiftPackage
(
filename
).
namespace
,
sourceMap
:
sourceMap
?
resolveUTSSourceMapPath
(
filename
)
:
false
,
sourceMap
:
sourceMap
?
resolveUTSSourceMapPath
()
:
false
,
extname
:
'
swift
'
,
imports
:
[
'
DCUTSFoundation
'
],
logFilename
:
true
,
...
...
packages/uni-uts-v1/src/utils.ts
浏览文件 @
0be34a20
...
...
@@ -20,7 +20,7 @@ export type ToSwiftOptions = ToOptions
export
const
ERR_MSG_PLACEHOLDER
=
`___ERR_MSG___`
export
function
resolveUTSSourceMapPath
(
_filename
:
string
)
{
export
function
resolveUTSSourceMapPath
()
{
return
resolveSourceMapPath
()
}
...
...
@@ -98,10 +98,7 @@ export function moveRootIndexSourceMap(
)
{
if
(
isRootIndex
(
filename
,
platform
))
{
const
sourceMapFilename
=
path
.
resolve
(
resolveUTSSourceMapPath
(
filename
),
path
.
relative
(
inputDir
,
filename
)
)
.
resolve
(
resolveUTSSourceMapPath
(),
path
.
relative
(
inputDir
,
filename
))
.
replace
(
path
.
extname
(
filename
),
extname
+
'
.map
'
)
if
(
fs
.
existsSync
(
sourceMapFilename
))
{
const
newSourceMapFilename
=
path
.
resolve
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录