forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade-react.js
34 lines (28 loc) · 1.05 KB
/
upgrade-react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// This file is used to run our nightly cron jobs to test gatsby
// against future versions of react.
// @see https://reactjs.org/blog/2019/10/22/react-release-channels.html
// It updates all of our packages react/react-dom to an experimental
// channel, for which the circle ci config then installs.
//
// This file intentionally does not use in node-packages because it is
// ran before we do an install.
const fs = require(`fs`)
const packages = fs.readdirSync(`./packages`)
function replace(deps, library) {
if (deps && deps[library]) {
deps[library] = process.env.REACT_CHANNEL || `next`
}
}
packages.forEach(packageName => {
const path = `${process.cwd()}/packages/${packageName}/package.json`
fs.readFile(path, (err, json) => {
if (err) return
const pkg = JSON.parse(json)
replace(pkg.dependencies, `react`)
replace(pkg.devDependencies, `react`)
replace(pkg.dependencies, `react-dom`)
replace(pkg.devDependencies, `react-dom`)
console.log(`updating ${path}`)
fs.writeFileSync(path, JSON.stringify(pkg, null, 2))
})
})