refactor(auth,config): split 2260-line login.ts into focused modules and normalize CorpConfig fields
This commit is contained in:
1 parent
2d744d283b
commit
2b220bc5d9
7 files changed
+1786
-1661
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { CorpConfig, CorpConfigSchema, GlobalConfig, GlobalConfigSchema } from "./types.js";
|
||||
import { CorpConfig, CorpConfigSchema, GlobalConfig, GlobalConfigSchema, normalizeCorpConfig } from "./types.js";
|
||||
|
||||
const CONFIG_ENV = "HOSE_ENTERPRISES_DIR";
|
||||
const USER_DIR_ENV = "HOSE_USER_ENTERPRISES_DIR";
|
||||
@@ -194,7 +194,7 @@ export function loadCorpConfigs(overrideDirs?: string[]): CorpConfig[] {
|
||||
try {
|
||||
const content = readFileSync(join(dir, file), "utf-8");
|
||||
const parsed = JSON.parse(content);
|
||||
const corp = CorpConfigSchema.parse(parsed);
|
||||
const corp = normalizeCorpConfig(CorpConfigSchema.parse(parsed));
|
||||
// 相同企业 ID 以先出现的为准(工作区优先于全局,全局优先于历史)
|
||||
if (!byId.has(corp.id)) {
|
||||
byId.set(corp.id, corp);
|
||||
@@ -238,7 +238,7 @@ export function saveCorpConfig(config: CorpConfig, dir?: string): string {
|
||||
// ignore malformed existing file
|
||||
}
|
||||
}
|
||||
const validated = CorpConfigSchema.parse(config);
|
||||
const validated = normalizeCorpConfig(CorpConfigSchema.parse(config));
|
||||
const filePath = join(targetDir, `${validated.id}.json`);
|
||||
writeSecureFile(filePath, JSON.stringify(validated, null, 2));
|
||||
return filePath;
|
||||
|
||||
Reference in new issue
Block a user