Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
25aedc80
U
uni-app
项目概览
DCloud
/
uni-app
通知
698
Star
38702
Fork
3641
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
25aedc80
编写于
3月 13, 2024
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(uts): uts插件支持三方uts插件依赖
上级
83080191
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
127 addition
and
21 deletion
+127
-21
packages/uni-cli-shared/lib/uts/uni_modules.js
packages/uni-cli-shared/lib/uts/uni_modules.js
+76
-3
packages/uni-cli-shared/lib/uts/uts-loader.js
packages/uni-cli-shared/lib/uts/uts-loader.js
+36
-11
packages/uni-cli-shared/lib/uts/uts.js
packages/uni-cli-shared/lib/uts/uts.js
+15
-7
未找到文件。
packages/uni-cli-shared/lib/uts/uni_modules.js
浏览文件 @
25aedc80
...
...
@@ -3,9 +3,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
parseInjects
=
exports
.
parseUniExtApis
=
void
0
;
exports
.
parseUTSModuleDeps
=
exports
.
capitalize
=
exports
.
camelize
=
exports
.
parseInjects
=
exports
.
parseUniExtApis
=
exports
.
getUniExtApiProviderRegisters
=
exports
.
getUniExtApiProviders
=
void
0
;
// 重要:此文件编译后的js,需同步至 vue2 编译器中 uni-cli-shared/lib/uts/uni_modules.js
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
fs_extra_1
=
__importDefault
(
require
(
"
fs-extra
"
));
const
extApiProviders
=
[];
function
getUniExtApiProviders
()
{
return
extApiProviders
;
}
exports
.
getUniExtApiProviders
=
getUniExtApiProviders
;
function
getUniExtApiProviderRegisters
()
{
const
result
=
[];
extApiProviders
.
forEach
((
provider
)
=>
{
if
(
provider
.
name
&&
provider
.
service
)
{
result
.
push
({
name
:
provider
.
name
,
service
:
provider
.
service
,
class
:
`uts.sdk.modules.
${(
0
,
exports
.
camelize
)(
provider
.
plugin
)}
.
${(
0
,
exports
.
capitalize
)((
0
,
exports
.
camelize
)(
'
uni-ext-api-
'
+
provider
.
service
+
'
-
'
+
provider
.
name
+
'
-provider
'
))}
`
,
});
}
});
return
result
;
}
exports
.
getUniExtApiProviderRegisters
=
getUniExtApiProviderRegisters
;
function
parseUniExtApis
(
vite
=
true
,
platform
,
language
=
'
javascript
'
)
{
if
(
!
process
.
env
.
UNI_INPUT_DIR
)
{
return
{};
...
...
@@ -15,6 +39,7 @@ function parseUniExtApis(vite = true, platform, language = 'javascript') {
return
{};
}
const
injects
=
{};
extApiProviders
.
length
=
0
;
fs_extra_1
.
default
.
readdirSync
(
uniModulesDir
).
forEach
((
uniModuleDir
)
=>
{
// 必须以 uni- 开头
if
(
!
uniModuleDir
.
startsWith
(
'
uni-
'
))
{
...
...
@@ -32,6 +57,11 @@ function parseUniExtApis(vite = true, platform, language = 'javascript') {
exports
=
pkg
.
uni_modules
[
'
uni-ext-api
'
];
}
if
(
exports
)
{
const
provider
=
exports
.
provider
;
if
(
provider
&&
provider
.
service
)
{
provider
.
plugin
=
uniModuleDir
;
extApiProviders
.
push
(
provider
);
}
const
curInjects
=
parseInjects
(
vite
,
platform
,
language
,
`@/uni_modules/
${
uniModuleDir
}
`
,
uniModuleRootDir
,
exports
);
Object
.
assign
(
injects
,
curInjects
);
}
...
...
@@ -74,9 +104,10 @@ function parseInjects(vite = true, platform, language, source, uniModuleRootDir,
});
const
injects
=
{};
if
(
Object
.
keys
(
rootDefines
).
length
)
{
const
platformIndexFileName
=
path_1
.
default
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
platform
);
const
rootIndexFileName
=
path_1
.
default
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
'
index.uts
'
);
let
hasPlatformFile
=
uniModuleRootDir
?
fs_extra_1
.
default
.
existsSync
(
path_1
.
default
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
'
index.uts
'
))
||
fs_extra_1
.
default
.
existsSync
(
path_1
.
default
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
platform
))
?
fs_extra_1
.
default
.
existsSync
(
rootIndexFileName
)
||
fs_extra_1
.
default
.
existsSync
(
platformIndexFileName
)
:
true
;
if
(
!
hasPlatformFile
)
{
if
(
platform
===
'
app
'
)
{
...
...
@@ -85,6 +116,17 @@ function parseInjects(vite = true, platform, language, source, uniModuleRootDir,
fs_extra_1
.
default
.
existsSync
(
path_1
.
default
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
'
app-ios
'
));
}
}
// 其他平台修改source,直接指向目标文件,否则 uts2js 找不到类型信息
if
(
platform
!==
'
app
'
&&
platform
!==
'
app-android
'
&&
platform
!==
'
app-ios
'
)
{
if
(
fs_extra_1
.
default
.
existsSync
(
platformIndexFileName
))
{
source
=
`
${
source
}
/utssdk/
${
platform
}
/index.uts`
;
}
else
if
(
fs_extra_1
.
default
.
existsSync
(
rootIndexFileName
))
{
source
=
`
${
source
}
/utssdk/index.uts`
;
}
}
for
(
const
key
in
rootDefines
)
{
Object
.
assign
(
injects
,
parseInject
(
vite
,
platform
,
language
,
source
,
'
uni
'
,
rootDefines
[
key
],
hasPlatformFile
));
}
...
...
@@ -173,3 +215,34 @@ const toTypeString = (value) => objectToString.call(value);
function
isPlainObject
(
val
)
{
return
toTypeString
(
val
)
===
'
[object Object]
'
;
}
const
cacheStringFunction
=
(
fn
)
=>
{
const
cache
=
Object
.
create
(
null
);
return
((
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
});
};
const
camelizeRE
=
/-
(\w)
/g
;
/**
* @private
*/
exports
.
camelize
=
cacheStringFunction
((
str
)
=>
{
return
str
.
replace
(
camelizeRE
,
(
_
,
c
)
=>
(
c
?
c
.
toUpperCase
()
:
''
));
});
/**
* @private
*/
exports
.
capitalize
=
cacheStringFunction
((
str
)
=>
str
.
charAt
(
0
).
toUpperCase
()
+
str
.
slice
(
1
));
/**
* 解析 UTS 类型的模块依赖列表
* @param deps
* @param inputDir
* @returns
*/
function
parseUTSModuleDeps
(
deps
,
inputDir
)
{
const
modulesDir
=
path_1
.
default
.
resolve
(
inputDir
,
'
uni_modules
'
);
return
deps
.
filter
((
dep
)
=>
{
return
fs_extra_1
.
default
.
existsSync
(
path_1
.
default
.
resolve
(
modulesDir
,
dep
,
'
utssdk
'
));
});
}
exports
.
parseUTSModuleDeps
=
parseUTSModuleDeps
;
packages/uni-cli-shared/lib/uts/uts-loader.js
浏览文件 @
25aedc80
...
...
@@ -3,17 +3,42 @@ const {
resolveUTSCompiler
,
parseUniExtApiNamespacesOnce
}
=
require
(
'
./uts
'
)
module
.
exports
=
function
(
content
)
{
const
{
parseUTSModuleDeps
}
=
require
(
'
./uni_modules
'
)
module
.
exports
=
async
function
(
content
)
{
const
callback
=
this
.
async
()
resolveUTSCompiler
().
compile
(
path
.
dirname
(
this
.
resourcePath
),
{
isX
:
false
,
isPlugin
:
true
,
extApis
:
parseUniExtApiNamespacesOnce
(
process
.
env
.
UNI_UTS_PLATFORM
,
process
.
env
.
UNI_UTS_TARGET_LANGUAGE
),
sourceMap
:
process
.
env
.
NODE_ENV
===
'
development
'
}).
then
(
result
=>
{
const
compilePlugin
=
async
(
pluginDir
)
=>
{
const
pkgJson
=
require
(
path
.
join
(
pluginDir
,
'
package.json
'
))
const
compiler
=
resolveUTSCompiler
()
// 处理依赖的 uts 插件
const
deps
=
parseUTSModuleDeps
(
pkgJson
.
uni_modules
?.
dependencies
||
[],
process
.
env
.
UNI_INPUT_DIR
)
if
(
deps
.
length
)
{
for
(
const
dep
of
deps
)
{
await
compilePlugin
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
uni_modules
'
,
dep
)
)
}
}
return
compiler
.
compile
(
pluginDir
,
{
isX
:
false
,
isPlugin
:
true
,
extApis
:
parseUniExtApiNamespacesOnce
(
process
.
env
.
UNI_UTS_PLATFORM
,
process
.
env
.
UNI_UTS_TARGET_LANGUAGE
),
sourceMap
:
process
.
env
.
NODE_ENV
===
'
development
'
,
uni_modules
:
deps
})
}
const
pluginDir
=
path
.
dirname
(
this
.
resourcePath
)
compilePlugin
(
pluginDir
).
then
(
result
=>
{
if
(
result
)
{
result
.
deps
.
forEach
((
dep
)
=>
{
this
.
addDependency
(
dep
)
...
...
@@ -25,4 +50,4 @@ module.exports = function (content) {
}).
catch
(
err
=>
{
callback
(
err
)
})
}
}
packages/uni-cli-shared/lib/uts/uts.js
浏览文件 @
25aedc80
...
...
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
parseUniExtApiNamespacesJsOnce
=
exports
.
parseUniExtApiNamespacesOnce
=
exports
.
parseSwiftPackageWithPluginId
=
exports
.
parseKotlinPackageWithPluginId
=
exports
.
initUTSComponents
=
exports
.
parseUTSComponent
=
exports
.
isUTSComponent
=
exports
.
resolveUTSCompiler
=
exports
.
resolveUTSModule
=
exports
.
resolveUTSAppModule
=
void
0
;
// 重要,该文件编译后的 js 需要同步到 vue2 编译器 uni-cli-shared/lib/uts
const
fs_1
=
__importDefault
(
require
(
"
fs
"
));
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
fast_glob_1
=
__importDefault
(
require
(
"
fast-glob
"
));
const
hbx_1
=
require
(
"
./hbx
"
);
const
utils_1
=
require
(
"
./utils
"
);
const
uni_modules_1
=
require
(
"
./uni_modules
"
);
// 重要,该文件编译后的 js 需要同步到 vue2 编译器 uni-cli-shared/lib/uts
function
once
(
fn
,
ctx
=
null
)
{
let
res
;
return
((...
args
)
=>
{
...
...
@@ -103,8 +103,18 @@ function resolveUTSCompiler() {
});
}
catch
(
e
)
{
let
utsCompilerVersion
=
utils_1
.
version
;
if
(
utils_1
.
version
.
startsWith
(
'
2.0.
'
))
{
let
utsCompilerVersion
=
''
;
try
{
utsCompilerVersion
=
require
(
'
../package.json
'
).
version
;
}
catch
(
e
)
{
try
{
// vue2
utsCompilerVersion
=
require
(
'
../../package.json
'
).
version
;
}
catch
(
e
)
{
}
}
if
(
utsCompilerVersion
.
startsWith
(
'
2.0.
'
))
{
utsCompilerVersion
=
'
^3.0.0-alpha-3060920221117001
'
;
}
console
.
error
((
0
,
utils_1
.
installDepTips
)(
'
devDependencies
'
,
'
@dcloudio/uni-uts-v1
'
,
utsCompilerVersion
));
...
...
@@ -135,9 +145,7 @@ exports.parseUTSComponent = parseUTSComponent;
function
initUTSComponents
(
inputDir
,
platform
)
{
utsComponents
.
clear
();
const
components
=
[];
if
(
platform
!==
'
app
'
&&
platform
!==
'
app-plus
'
)
{
return
components
;
}
const
isApp
=
platform
===
'
app
'
||
platform
===
'
app-plus
'
;
const
easycomsObj
=
{};
const
dirs
=
resolveUTSComponentDirs
(
inputDir
);
dirs
.
forEach
((
dir
)
=>
{
...
...
@@ -162,7 +170,7 @@ function initUTSComponents(inputDir, platform) {
if
(
name
)
{
const
importDir
=
(
0
,
utils_1
.
normalizePath
)(
is_uni_modules_utssdk
?
path_1
.
default
.
dirname
(
dir
)
:
dir
);
easycomsObj
[
`^
${
name
}
$`
]
=
{
source
:
`
${
importDir
}
?uts-proxy`
,
source
:
isApp
?
`
${
importDir
}
?uts-proxy`
:
(
0
,
utils_1
.
normalizePath
)(
file
)
,
kotlinPackage
:
parseKotlinPackageWithPluginId
(
pluginId
,
is_uni_modules_utssdk
),
swiftModule
:
parseSwiftPackageWithPluginId
(
pluginId
,
is_uni_modules_utssdk
),
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录