Skip to content

Commit

Permalink
feat(test) react-native & @react-native/ packages version alignment
Browse files Browse the repository at this point in the history
These have to be aligned, unless we're not on a stable branch.
  • Loading branch information
blakef committed Nov 13, 2024
1 parent ba029fb commit f1c4f74
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions scripts/__tests__/package_json-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit f1c4f74

Please sign in to comment.