mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 23:08:36 +02:00
CODEBASE: Allow specifying migrator when migrating player's scripts (#2418)
This commit is contained in:
@@ -26,6 +26,16 @@ export interface VersionBreakingChange {
|
|||||||
apiBreakingChanges: APIBreakInfo[];
|
apiBreakingChanges: APIBreakInfo[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NormalMigration = {
|
||||||
|
replaceValue: string;
|
||||||
|
migrator?: never;
|
||||||
|
};
|
||||||
|
|
||||||
|
type MigrationWithCustomLogic = {
|
||||||
|
replaceValue?: never;
|
||||||
|
migrator: (line: string) => string;
|
||||||
|
};
|
||||||
|
|
||||||
export interface APIBreakInfo {
|
export interface APIBreakInfo {
|
||||||
/** The API functions impacted by the API break */
|
/** The API functions impacted by the API break */
|
||||||
brokenAPIs: {
|
brokenAPIs: {
|
||||||
@@ -33,8 +43,7 @@ export interface APIBreakInfo {
|
|||||||
migration?: {
|
migration?: {
|
||||||
/** We may need to use a custom search value instead of name */
|
/** We may need to use a custom search value instead of name */
|
||||||
searchValue: string | RegExp;
|
searchValue: string | RegExp;
|
||||||
replaceValue: string;
|
} & (NormalMigration | MigrationWithCustomLogic);
|
||||||
};
|
|
||||||
}[];
|
}[];
|
||||||
/** Info that should be shown to the player, alongside the list of impacted scripts */
|
/** Info that should be shown to the player, alongside the list of impacted scripts */
|
||||||
info: string;
|
info: string;
|
||||||
@@ -67,8 +76,13 @@ function detectImpactAndMigrateLines(script: Script, brokenFunctions: APIBreakIn
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
impactedLines.push(i + 1);
|
impactedLines.push(i + 1);
|
||||||
if (brokenFunction.migration) {
|
if (!brokenFunction.migration) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!brokenFunction.migration.migrator) {
|
||||||
lines[i] = lines[i].replaceAll(brokenFunction.migration.searchValue, brokenFunction.migration.replaceValue);
|
lines[i] = lines[i].replaceAll(brokenFunction.migration.searchValue, brokenFunction.migration.replaceValue);
|
||||||
|
} else {
|
||||||
|
lines[i] = brokenFunction.migration.migrator(lines[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user