-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test) react-native & @react-native/ packages version alignment
These have to be aligned, unless we're not on a stable branch.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |