From f1c4f74cd8b62e9ddfb349781d5d6403e9cb1275 Mon Sep 17 00:00:00 2001 From: Blake Friedman Date: Wed, 13 Nov 2024 12:52:14 +0000 Subject: [PATCH] feat(test) react-native & @react-native/ packages version alignment These have to be aligned, unless we're not on a stable branch. --- scripts/__tests__/package_json-test.js | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 scripts/__tests__/package_json-test.js diff --git a/scripts/__tests__/package_json-test.js b/scripts/__tests__/package_json-test.js new file mode 100644 index 0000000..9b7ec47 --- /dev/null +++ b/scripts/__tests__/package_json-test.js @@ -0,0 +1,34 @@ +const fs = require('fs'); +const {execSync} = require('child_process'); + +const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); + +const isStableBranch = /\d+\.\d+-stable$/.test(branch); + +const isReactNativePackage = pkg => pkg === "react-native" || pkg.startsWith("@react-native/"); + +const label = isStableBranch ? 'react-native and ' : ''; + +describe("react-native packages on a version branch need to be aligned", () => { + it(`has a consistent version for ${label}@react-native/ scoped packages in the template/package.json`, () => { + const pkgJson = JSON.parse(fs.readFileSync('template/package.json')); + + const everything = Object.entries({ + ...pkgJson.dependencies, + ...pkgJson.devDependencies, + ...pkgJson.peerDependencies ?? {} + }); + + const versions = Object.fromEntries(everything.filter(([name]) => isReactNativePackage(name))); + + if (!isStableBranch) { + // This is the one case where "react-native" doesn't have to match + delete versions["react-native"]; + } + + const allReactNativeVersions = new Set(Object.values(versions)); + + // Only a single version + expect(allReactNativeVersions.size).toEqual(1); + }); +});