Skip to content

Commit a97bcac

Browse files
committed
feat: 优化文件内容为空检测策略
1 parent 3c77275 commit a97bcac

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

packages/uni-uts-v1/src/code.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ interface Meta {
102102
}
103103
}
104104
export interface GenProxyCodeOptions {
105+
platform?: 'app-android' | 'app-ios'
105106
is_uni_modules: boolean
106107
id: string
107108
name: string
@@ -695,6 +696,7 @@ async function parseModuleDecls(module: string, options: GenProxyCodeOptions) {
695696
// 优先合并 ios + android,如果没有,查找根目录 index.uts
696697
const iosDecls = (
697698
await parseFile(
699+
options.platform === 'app-ios',
698700
resolvePlatformIndex('app-ios', module, options),
699701
options,
700702
options.iosPreprocessor
@@ -710,6 +712,7 @@ async function parseModuleDecls(module: string, options: GenProxyCodeOptions) {
710712
})
711713
const androidDecls = (
712714
await parseFile(
715+
options.platform === 'app-android',
713716
resolvePlatformIndex('app-android', module, options),
714717
options,
715718
options.androidPreprocessor
@@ -730,7 +733,7 @@ async function parseModuleDecls(module: string, options: GenProxyCodeOptions) {
730733
const decls = mergeDecls(androidDecls, iosDecls)
731734
// 如果没有平台特有,查找 root index.uts
732735
if (!decls.length) {
733-
return await parseFile(resolveRootIndex(module, options), options)
736+
return await parseFile(true, resolveRootIndex(module, options), options)
734737
}
735738
return decls
736739
}
@@ -818,6 +821,7 @@ function mergeDecls(from: ProxyDecl[], to: ProxyDecl[]) {
818821
}
819822

820823
async function parseFile(
824+
checkEmpty: boolean,
821825
filename: string | undefined | false,
822826
options: GenProxyCodeOptions,
823827
preprocessor?: SyncUniModulesFilePreprocessor
@@ -828,14 +832,10 @@ async function parseFile(
828832
if (fs.existsSync(filename)) {
829833
const code = fs.readFileSync(filename, 'utf8')
830834
if (!code || code.trim() === '') {
831-
console.error(
832-
parseUTSSyntaxError(
833-
new Error(
834-
`文件内容不能为空: ${relative(filename, options.inputDir!)}`
835-
),
836-
process.env.UNI_INPUT_DIR
837-
)
838-
)
835+
if (checkEmpty) {
836+
console.error(`error: 文件内容为空,请检查。`)
837+
console.error(`at ${relative(filename, options.inputDir!)}:1`)
838+
}
839839
return []
840840
}
841841
return parseCode(

packages/uni-uts-v1/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export async function compile(
247247
} catch (e) {}
248248
const proxyCodeOptions: GenProxyCodeOptions = extend(
249249
{
250+
platform: utsPlatform as 'app-android' | 'app-ios',
250251
androidComponents,
251252
iosComponents,
252253
customElements,

packages/uni-uts-v1/src/kotlin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@ export async function compile(
559559
outputDir,
560560
sourceMap,
561561
components,
562-
customElements,
563562
isX,
564563
isSingleThread,
565564
isPlugin,

0 commit comments

Comments
 (0)