-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
refactor: automation to tag and version the template when releasing (#30
) There was a discussion on Discord, where we looked at implementing what was originally proposed. This is that implementation. It'll need to land with a [cli](react-native-community/cli#2422) change to use the update template + tagging. - feat: add mutating react-native & @react-native/ packages Support for doing this on nightly and release workflows - feat: added node ./scripts/updateReactNativeVersion.js <version> Sets the version of react-native and the @react-native/ scoped packages. It will also normalize tags to concrete versions. E.g. latest -> 0.74.2 - refactor: move scripts into a ./scripts folder
- 0.79.0-rc.0-1e903dc
- 0.78.0
- 0.78.0-rc.5-a1d0840
- 0.78.0-rc.4-8361fc9
- 0.78.0-rc.3-1df26ec
- 0.78.0-rc.2-3675170
- 0.78.0-rc.1-4587239
- 0.78.0-rc.0-222da7e
- 0.77.1
- 0.77.0
- 0.77.0-rc.7-152cc23
- 0.77.0-rc.6-7e4e2fb
- 0.77.0-rc.5-c0dfbea
- 0.77.0-rc.4-963a3f0
- 0.77.0-rc.3-a43e563
- 0.77.0-rc.2-911a07b
- 0.77.0-rc.1-6fcf6a7
- 0.77.0-rc.0-796a664
- 0.76.7
- 0.76.6
- 0.76.5
- 0.76.4
- 0.76.3
- 0.76.2
- 0.76.1
- 0.76.0
- 0.76.0-rc.6-6e56f8a
- 0.76.0-rc.5-140012e
- 0.76.0-rc.4-fa7ebf3
- 0.76.0-rc.3-577ec06
- 0.76.0-rc.2-3b1a411
- 0.76.0-rc.1-7345250
- 0.76.0-rc.0-897b92d
Showing
7 changed files
with
116 additions
and
4 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
scripts/ | ||
|
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,25 @@ | ||
const {execSync} = require('child_process'); | ||
|
||
const registry = getNpmRegistryUrl(); | ||
|
||
function getNpmRegistryUrl() { | ||
try { | ||
return execSync("npm config get registry").toString().trim(); | ||
} catch { | ||
return "https://registry.npmjs.org/"; | ||
} | ||
} | ||
|
||
/** | ||
* Convert an npm tag to a concrete version, for example: | ||
* - next -> 0.75.0-rc.0 | ||
* - nightly -> 0.75.0-nightly-20240618-5df5ed1a8 | ||
*/ | ||
async function npmMaterializeVersion(packageName, tagOrVersion) { | ||
const url = new URL(registry); | ||
url.pathname = `${packageName}/${tagOrVersion}`; | ||
const json = await fetch(url).then((resp) => resp.json()); | ||
return json.version; | ||
} | ||
|
||
module.exports.npmMaterializeVersion = npmMaterializeVersion; |
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,84 @@ | ||
const fs = require("fs"); | ||
const { npmMaterializeVersion } = require("./lib/lib.js"); | ||
|
||
function updateDependencies(pkgJson, update) { | ||
console.log("Changing package.json dependencies:"); | ||
|
||
for (const [pkg, value] of Object.entries(update.dependencies ?? {})) { | ||
const old = pkgJson.dependencies[pkg]; | ||
if (old) { | ||
console.log(` - ${pkg}: ${old} → ${value}`); | ||
} else { | ||
console.log(` - ${pkg}: ${value}`); | ||
} | ||
pkgJson.dependencies[pkg] = value; | ||
} | ||
|
||
for (const [pkg, value] of Object.entries(update.devDependencies ?? {})) { | ||
const old = pkgJson.devDependencies[pkg]; | ||
if (old) { | ||
console.log(` - ${pkg}: ${old} → ${value}`); | ||
} else { | ||
console.log(` - ${pkg}: ${value}`); | ||
} | ||
pkgJson.devDependencies[pkg] = value; | ||
} | ||
|
||
return pkgJson; | ||
} | ||
|
||
const REACT_NATIVE_SCOPE = "@react-native/"; | ||
|
||
/** | ||
* Packages that are scoped under @react-native need a consistent version | ||
*/ | ||
function normalizeReactNativeDeps(deps, version) { | ||
const updated = {}; | ||
for (const key of Object.keys(deps ?? {}).filter((pkg) => | ||
pkg.startsWith(REACT_NATIVE_SCOPE), | ||
)) { | ||
updated[key] = version; | ||
} | ||
return updated; | ||
} | ||
|
||
async function main(version) { | ||
const PKG_JSON_PATH = "template/package.json"; | ||
// Update the react-native dependency if using the new @react-native-community/template. | ||
// We can figure this out as it ships with [email protected] set to a dummy version. | ||
let pkgJson = JSON.parse(fs.readFileSync(PKG_JSON_PATH, "utf8")); | ||
|
||
// Materialize a tag to a version. E.g. next -> 0.75.0-rc.0 | ||
const concreteVersion = await npmMaterializeVersion("react-native", version); | ||
console.log( | ||
`Normalizing: react-native@${version} -> react-native@${concreteVersion}`, | ||
); | ||
|
||
pkgJson = updateDependencies(pkgJson, { | ||
dependencies: { | ||
"react-native": concreteVersion, | ||
...normalizeReactNativeDeps(pkgJson.dependencies, concreteVersion), | ||
}, | ||
devDependencies: { | ||
...normalizeReactNativeDeps(pkgJson.devDependencies, concreteVersion), | ||
}, | ||
}); | ||
|
||
const updated = JSON.stringify(pkgJson, null, 2); | ||
console.log(`Writing update package.json to ${PKG_JSON_PATH}:\n\n${updated}`); | ||
fs.writeFileSync(PKG_JSON_PATH, updated); | ||
} | ||
|
||
if (require.main === module) { | ||
if (process.argv.length < 3) { | ||
console.log(`USAGE: updateReactNativeVersion.js <version> | ||
Updates 'react-native' and '@react-native/' scoped packages to a common version within | ||
the template. | ||
`); | ||
process.exit(1); | ||
} | ||
main(process.argv.pop()).catch((e) => { | ||
throw e; | ||
}); | ||
} |
File renamed without changes.