Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-badgers-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openapi-ts-request': patch
---

fix: fix bug #644
16 changes: 15 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,23 @@ export async function translateChineseModuleNodeToEnglish(
});
});
resolve(translateMap);

// 在写入前再次读取缓存,合并多个任务的翻译结果
const existingContent = readFileSafelySync(
process.cwd() + '/openapi-ts-request.cache.json'
);
let existingCache: Record<string, string> = {};

if (existingContent !== null && isJSONString(existingContent)) {
existingCache = JSON.parse(existingContent) as Record<string, string>;
}

// 合并现有缓存和新的翻译结果(新结果优先)
const mergedCache = { ...existingCache, ...translateMap };

void writeFileAsync(
process.cwd() + '/openapi-ts-request.cache.json',
JSON.stringify(translateMap, null, 2)
JSON.stringify(mergedCache, null, 2)
);
})
.catch(() => {
Expand Down