fix(config): migrate legacy release arrays during config fixes and validate release config shape
This commit is contained in:
@@ -19,6 +19,38 @@ const ensureObject = (parent: Record<string, any>, key: string): Record<string,
|
||||
return parent[key];
|
||||
};
|
||||
|
||||
const normalizeRegistryList = (registries: unknown[]): string[] => {
|
||||
const result: string[] = [];
|
||||
for (const registry of registries) {
|
||||
if (typeof registry !== "string" || !registry.trim()) {
|
||||
continue;
|
||||
}
|
||||
const normalizedRegistry = normalizeRegistryUrl(registry);
|
||||
if (!result.includes(normalizedRegistry)) {
|
||||
result.push(normalizedRegistry);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const migrateLegacyReleaseArray = (smartconfigJson: Record<string, any>): boolean => {
|
||||
const cliConfig = ensureObject(smartconfigJson, CLI_NAMESPACE);
|
||||
if (!Array.isArray(cliConfig.release)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const registries = normalizeRegistryList(cliConfig.release);
|
||||
cliConfig.release = {
|
||||
targets: {
|
||||
npm: {
|
||||
enabled: registries.length > 0,
|
||||
registries,
|
||||
},
|
||||
},
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
const migrateNamespaceKeys = (smartconfigJson: Record<string, any>): boolean => {
|
||||
let migrated = false;
|
||||
const migrations = [
|
||||
@@ -50,9 +82,9 @@ const migrateNamespaceKeys = (smartconfigJson: Record<string, any>): boolean =>
|
||||
|
||||
const migrateToV2 = (smartconfigJson: Record<string, any>): boolean => {
|
||||
const cliConfig = ensureObject(smartconfigJson, CLI_NAMESPACE);
|
||||
let migrated = migrateLegacyReleaseArray(smartconfigJson);
|
||||
const releaseConfig = ensureObject(cliConfig, "release");
|
||||
|
||||
let migrated = false;
|
||||
const targets = ensureObject(releaseConfig, "targets");
|
||||
const shipzoneConfig = smartconfigJson["@ship.zone/szci"];
|
||||
|
||||
@@ -192,6 +224,10 @@ export const migrateSmartconfigData = (
|
||||
const fromVersion = typeof cliConfig.schemaVersion === "number" ? cliConfig.schemaVersion : 1;
|
||||
let currentVersion = fromVersion;
|
||||
|
||||
if (targetVersion >= 2) {
|
||||
migrated = migrateLegacyReleaseArray(smartconfigJson) || migrated;
|
||||
}
|
||||
|
||||
if (currentVersion < 2 && targetVersion >= 2) {
|
||||
migrated = migrateToV2(smartconfigJson) || migrated;
|
||||
currentVersion = 2;
|
||||
|
||||
Reference in New Issue
Block a user