Skip to content

Commit 91bd03a

Browse files
tido64Saadnajmi
andauthored
chore: add post-version step to Nx Release (#2418)
## Summary: Adds a post-version step to Nx Release for updating generated artifacts (e.g., `RCTVersion.m`). ## Test Plan: Bump the version and run `nx release`: ``` yarn nx release plan --only-touched=false patch yarn nx release --skip-publish --verbose ``` Verify that generated artifacts have been updated with the latest version number. --------- Co-authored-by: Saad Najmi <[email protected]>
1 parent 47d60b2 commit 91bd03a

File tree

7 files changed

+211
-0
lines changed

7 files changed

+211
-0
lines changed

nx.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"projectsRelationship": "independent",
2424
"versionPlans": true,
2525
"version": {
26+
"generator": "@react-native-mac/nx-release-version:release-version",
2627
"generatorOptions": {
2728
"currentVersionResolver": "registry",
2829
"currentVersionResolverMetadata": {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@react-native-macos/nx-release-version",
3+
"version": "0.0.1",
4+
"generators": {
5+
"release-version": {
6+
"factory": "./index.js",
7+
"schema": "./schema.json",
8+
"description": "DO NOT INVOKE DIRECTLY WITH `nx generate`. Use `nx release version` instead.",
9+
"hidden": true
10+
}
11+
}
12+
}

packages/nx-release-version/index.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// @ts-check
2+
3+
const { releaseVersionGenerator } = require('@nx/js/src/generators/release-version/release-version');
4+
const fs = require('node:fs');
5+
const path = require('node:path');
6+
7+
async function runSetVersion() {
8+
const rnmPkgJson = require.resolve('react-native-macos/package.json');
9+
const { REPO_ROOT } = require('../../scripts/consts');
10+
const { updateReactNativeArtifacts } = require('../../scripts/releases/set-rn-artifacts-version');
11+
12+
const manifest = fs.readFileSync(rnmPkgJson, { encoding: 'utf-8' });
13+
const { version } = JSON.parse(manifest);
14+
15+
await updateReactNativeArtifacts(version);
16+
17+
return [
18+
path.join(
19+
REPO_ROOT,
20+
'packages',
21+
'react-native',
22+
'ReactAndroid',
23+
'gradle.properties',
24+
),
25+
path.join(
26+
REPO_ROOT,
27+
'packages',
28+
'react-native',
29+
'ReactAndroid',
30+
'src',
31+
'main',
32+
'java',
33+
'com',
34+
'facebook',
35+
'react',
36+
'modules',
37+
'systeminfo',
38+
'ReactNativeVersion.java',
39+
),
40+
path.join(REPO_ROOT,
41+
'packages',
42+
'react-native',
43+
'React',
44+
'Base',
45+
'RCTVersion.m',
46+
),
47+
path.join(
48+
REPO_ROOT,
49+
'packages',
50+
'react-native',
51+
'ReactCommon',
52+
'cxxreact',
53+
'ReactNativeVersion.h',
54+
),
55+
path.join(
56+
REPO_ROOT,
57+
'packages',
58+
'react-native',
59+
'Libraries',
60+
'Core',
61+
'ReactNativeVersion.js',
62+
),
63+
];
64+
}
65+
66+
/** @type {typeof releaseVersionGenerator} */
67+
module.exports = async function(tree, options) {
68+
const { data, callback } = await releaseVersionGenerator(tree, options);
69+
return {
70+
data,
71+
callback: async (tree, options) => {
72+
const result = await callback(tree, options);
73+
74+
const versionedFiles = await runSetVersion();
75+
if (versionedFiles) {
76+
const changedFiles = Array.isArray(result) ? result : result.changedFiles;
77+
changedFiles.push(...versionedFiles);
78+
}
79+
80+
return result;
81+
},
82+
};
83+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"private": true,
3+
"name": "@react-native-mac/nx-release-version",
4+
"version": "0.0.1-dev",
5+
"description": "Nx Release plugin that adds post-versioning logic",
6+
"homepage": "https://github.com/microsoft/react-native-macos/tree/HEAD/packages/nx-release-version#readme",
7+
"license": "MIT",
8+
"files": [
9+
"generators.json",
10+
"index.js",
11+
"schema.json"
12+
],
13+
"main": "index.js",
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/microsoft/react-native-macos.git",
17+
"directory": "packages/nx-release-version"
18+
},
19+
"dependencies": {
20+
"@nx/js": "~20.0.0"
21+
},
22+
"devDependencies": {
23+
"@rnx-kit/tsconfig": "^2.0.0",
24+
"typescript": "^5.6.3"
25+
},
26+
"engines": {
27+
"node": ">=18"
28+
},
29+
"generators": "./generators.json"
30+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
{
3+
"$schema": "https://json-schema.org/schema",
4+
"$id": "NxJSReleaseVersionGeneratorCopy",
5+
"cli": "nx",
6+
"title": "Implementation details of `nx release version`",
7+
"description": "DO NOT INVOKE DIRECTLY WITH `nx generate`. Use `nx release version` instead.",
8+
"type": "object",
9+
"properties": {
10+
"projects": {
11+
"type": "array",
12+
"description": "The ProjectGraphProjectNodes being versioned in the current execution.",
13+
"items": {
14+
"type": "object"
15+
}
16+
},
17+
"projectGraph": {
18+
"type": "object",
19+
"description": "ProjectGraph instance"
20+
},
21+
"specifier": {
22+
"type": "string",
23+
"description": "Exact version or semver keyword to apply to the selected release group. Overrides specifierSource."
24+
},
25+
"releaseGroup": {
26+
"type": "object",
27+
"description": "The resolved release group configuration, including name, relevant to all projects in the current execution."
28+
},
29+
"specifierSource": {
30+
"type": "string",
31+
"default": "prompt",
32+
"description": "Which approach to use to determine the semver specifier used to bump the version of the project.",
33+
"enum": ["prompt", "conventional-commits", "version-plans"]
34+
},
35+
"preid": {
36+
"type": "string",
37+
"description": "The optional prerelease identifier to apply to the version, in the case that the specifier argument has been set to prerelease."
38+
},
39+
"packageRoot": {
40+
"type": "string",
41+
"description": "The root directory of the directory (containing a manifest file at its root) to publish. Defaults to the project root"
42+
},
43+
"currentVersionResolver": {
44+
"type": "string",
45+
"default": "disk",
46+
"description": "Which approach to use to determine the current version of the project.",
47+
"enum": ["registry", "disk", "git-tag"]
48+
},
49+
"currentVersionResolverMetadata": {
50+
"type": "object",
51+
"description": "Additional metadata to pass to the current version resolver.",
52+
"default": {}
53+
},
54+
"skipLockFileUpdate": {
55+
"type": "boolean",
56+
"description": "Whether to skip updating the lock file after updating the version."
57+
},
58+
"installArgs": {
59+
"type": "string",
60+
"description": "Additional arguments to pass to the package manager when updating the lock file with an install command."
61+
},
62+
"installIgnoreScripts": {
63+
"type": "boolean",
64+
"description": "Whether to ignore install lifecycle scripts when updating the lock file with an install command."
65+
}
66+
},
67+
"required": ["projects", "projectGraph", "releaseGroup"]
68+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "@rnx-kit/tsconfig/tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true
5+
},
6+
"include": ["index.js"]
7+
}

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,16 @@ __metadata:
27432743
languageName: unknown
27442744
linkType: soft
27452745

2746+
"@react-native-mac/nx-release-version@workspace:packages/nx-release-version":
2747+
version: 0.0.0-use.local
2748+
resolution: "@react-native-mac/nx-release-version@workspace:packages/nx-release-version"
2749+
dependencies:
2750+
"@nx/js": "npm:~20.0.0"
2751+
"@rnx-kit/tsconfig": "npm:^2.0.0"
2752+
typescript: "npm:^5.6.3"
2753+
languageName: unknown
2754+
linkType: soft
2755+
27462756
"@react-native-mac/virtualized-lists@workspace:*, @react-native-mac/virtualized-lists@workspace:packages/virtualized-lists":
27472757
version: 0.0.0-use.local
27482758
resolution: "@react-native-mac/virtualized-lists@workspace:packages/virtualized-lists"

0 commit comments

Comments
 (0)