version-changes.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.dev/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. exports.getChangesForTarget = getChangesForTarget;
  11. exports.getAllChanges = getAllChanges;
  12. const target_version_1 = require("./target-version");
  13. /**
  14. * Gets the changes for a given target version from the specified version changes object.
  15. *
  16. * For readability and a good overview of breaking changes, the version change data always
  17. * includes the related Pull Request link. Since this data is not needed when performing the
  18. * upgrade, this unused data can be removed and the changes data can be flattened into an
  19. * easy iterable array.
  20. */
  21. function getChangesForTarget(target, data) {
  22. if (!data) {
  23. const version = target_version_1.TargetVersion[target];
  24. throw new Error(`No data could be found for target version: ${version}`);
  25. }
  26. return (data[target] || []).reduce((result, prData) => result.concat(prData.changes), []);
  27. }
  28. /**
  29. * Gets all changes from the specified version changes object. This is helpful in case a migration
  30. * rule does not distinguish data based on the target version, but for readability the
  31. * upgrade data is separated for each target version.
  32. */
  33. function getAllChanges(data) {
  34. return Object.keys(data)
  35. .map(targetVersion => getChangesForTarget(targetVersion, data))
  36. .reduce((result, versionData) => result.concat(versionData), []);
  37. }
  38. //# sourceMappingURL=version-changes.js.map