-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Run tests periodically with
react@next
(#18008)
- Loading branch information
Showing
2 changed files
with
88 additions
and
1 deletion.
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
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,55 @@ | ||
/* eslint-disable no-console */ | ||
/** | ||
* Given an environment variable called `REACT_DIST_TAG` fetch the corresponding | ||
* version and make sure this version is used throughout the repository. | ||
* | ||
* If you work on this file: | ||
* WARNING: This script can only use built-in modules since it has to run before | ||
* `yarn install` | ||
*/ | ||
const childProcess = require('child_process'); | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
const { promisify } = require('util'); | ||
|
||
const exec = promisify(childProcess.exec); | ||
|
||
// packages published from the react monorepo using the same version | ||
const reactPackageNames = ['react', 'react-dom', 'react-is', 'react-test-renderer', 'scheduler']; | ||
|
||
async function main(distTag) { | ||
if (typeof distTag !== 'string') { | ||
throw new TypeError(`expected distTag: string but got '${distTag}'`); | ||
} | ||
|
||
if (distTag === 'stable') { | ||
console.log('nothing to do with stable'); | ||
return; | ||
} | ||
|
||
const { stdout: versions } = await exec(`npm dist-tag ls react ${distTag}`); | ||
const tagMapping = versions.split('\n').find(mapping => { | ||
return mapping.startsWith(`${distTag}: `); | ||
}); | ||
if (tagMapping === undefined) { | ||
throw new Error(`Could not find '${distTag}' in "${versions}"`); | ||
} | ||
|
||
const version = tagMapping.replace(`${distTag}: `, ''); | ||
|
||
const packageJsonPath = path.resolve(__dirname, '../package.json'); | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' })); | ||
|
||
reactPackageNames.forEach(reactPackageName => { | ||
packageJson.resolutions[reactPackageName] = version; | ||
}); | ||
|
||
// CircleCI seemingly times out if it has a newline diff at the end | ||
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}${os.EOL}`); | ||
} | ||
|
||
main(process.env.REACT_DIST_TAG).catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |