提交 54fc6287 编写于 作者: fxy060608's avatar fxy060608

wip(uts): compiler

上级 eb68b159
......@@ -132,11 +132,12 @@ export function resolveUtsAppModule(id: string, importer: string) {
const parts = normalizePath(id).split('/')
const parentDir = parts[parts.length - 2]
if (parentDir === 'uni_modules' || parentDir === 'utssdk') {
if (fs.existsSync(path.resolve(id, 'index.uts'))) {
const basedir = parentDir === 'uni_modules' ? 'utssdk' : ''
if (fs.existsSync(path.resolve(id, basedir, 'index.uts'))) {
return id
}
const resolvePlatformDir = (p: typeof process.env.UNI_UTS_PLATFORM) => {
return path.resolve(id, parentDir === 'uni_modules' ? 'utssdk' : '', p)
return path.resolve(id, basedir, p)
}
const extname = ['.uts']
if (resolveUtsFile(resolvePlatformDir('app-android'), extname)) {
......@@ -169,15 +170,16 @@ export function resolveUtsModule(
const parts = normalizePath(id).split('/')
const parentDir = parts[parts.length - 2]
if (parentDir === 'uni_modules' || parentDir === 'utssdk') {
const basedir = parentDir === 'uni_modules' ? 'utssdk' : ''
const resolvePlatformDir = (p: typeof process.env.UNI_UTS_PLATFORM) => {
return path.resolve(id, parentDir === 'uni_modules' ? 'utssdk' : '', p)
return path.resolve(id, basedir, p)
}
let index = resolveUtsFile(resolvePlatformDir(platform))
if (index) {
return index
}
index = path.resolve(id, 'index.uts')
index = path.resolve(id, basedir, 'index.uts')
if (fs.existsSync(index)) {
return index
}
......
......@@ -54,7 +54,7 @@ export function uniUtsV1Plugin(): Plugin {
) {
const filename =
resolvePlatformIndex('app-android', module, pkg) ||
resolveRootIndex(module)
resolveRootIndex(module, pkg)
if (filename) {
await getCompiler('kotlin').runProd(filename)
}
......@@ -65,7 +65,7 @@ export function uniUtsV1Plugin(): Plugin {
) {
const filename =
resolvePlatformIndex('app-ios', module, pkg) ||
resolveRootIndex(module)
resolveRootIndex(module, pkg)
if (filename) {
await getCompiler('swift').runProd(filename)
}
......@@ -75,7 +75,7 @@ export function uniUtsV1Plugin(): Plugin {
if (process.env.UNI_UTS_PLATFORM === 'app-android') {
const filename =
resolvePlatformIndex('app-android', module, pkg) ||
resolveRootIndex(module)
resolveRootIndex(module, pkg)
if (filename) {
const res = await getCompiler('kotlin').runDev(filename)
if (!isFirst && res) {
......
......@@ -39,8 +39,12 @@ ${genModuleCode(await parseModuleDecls(module, options))}
`
}
export function resolveRootIndex(module: string) {
const filename = path.resolve(module, 'index.uts')
export function resolveRootIndex(module: string, options: GenProxyCodeOptions) {
const filename = path.resolve(
module,
options.is_uni_modules ? 'utssdk' : '',
'index.uts'
)
return fs.existsSync(filename) && filename
}
......@@ -120,7 +124,7 @@ async function parseModuleDecls(module: string, options: GenProxyCodeOptions) {
const decls = mergeDecls(androidDecls, iosDecls)
// 如果没有平台特有,查找 root index.uts
if (!decls.length) {
return await parseFile(resolveRootIndex(module), options)
return await parseFile(resolveRootIndex(module, options), options)
}
return decls
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册