From f09acd5c3647f290bb7c0fdeb6db91da1b676ab1 Mon Sep 17 00:00:00 2001 From: kleene Date: Sun, 13 Jul 2025 23:03:47 +0800 Subject: [PATCH] fix with so prefix Issue: ICLYAQ Signed-off-by: kleene Change-Id: If2cc2b1aade68672c18590fd34be864cc8ddd816 --- ets2panda/driver/build_system/src/utils.ts | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ets2panda/driver/build_system/src/utils.ts b/ets2panda/driver/build_system/src/utils.ts index b87c6c462a..b811a34bed 100644 --- a/ets2panda/driver/build_system/src/utils.ts +++ b/ets2panda/driver/build_system/src/utils.ts @@ -48,7 +48,7 @@ export function isMac(): boolean { } export function changeFileExtension(file: string, targetExt: string, originExt = ''): string { - let currentExt = originExt.length === 0 ? path.extname(file) : originExt; + let currentExt = originExt.length === 0 ? getFileExtension(file) : originExt; let fileWithoutExt = file.substring(0, file.lastIndexOf(currentExt)); return fileWithoutExt + targetExt; } @@ -148,3 +148,26 @@ export function isSubPathOf(targetPath: string, parentDir: string): boolean { const resolvedTarget = toUnixPath(path.resolve(targetPath)); return resolvedTarget === resolvedParent || resolvedTarget.startsWith(resolvedParent + '/'); } + +/** + * Get the full extension of a file, supporting composite extensions like '.d.ts', '.test.ts', '.d.ets', etc. + * @param filePath - File path or file name. + * @param knownCompositeExts - Optional list of known composite extensions to match against. + * @returns The full extension (e.g., '.d.ts'). Returns an empty string if no extension is found. + */ +export function getFileExtension( + filePath: string, + knownCompositeExts: string[] = ['.d.ts', '.test.ts', '.d.ets'] +): string { + const baseName = path.basename(filePath); + + // Match known composite extensions first + for (const ext of knownCompositeExts) { + if (baseName.endsWith(ext)) { + return ext; + } + } + + // Fallback to default behavior: return the last segment after the final dot + return path.extname(baseName); +} -- Gitee