Skip to content

Commit 0631832

Browse files
committed
feat: use react-native-macos namespace, update to nx 21
1 parent cd0ff85 commit 0631832

28 files changed

+197
-590
lines changed

nx.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@
1515
"workspaceChangelog": false
1616
},
1717
"projects": ["packages/react-native", "packages/virtualized-lists"],
18-
"projectsRelationship": "independent",
1918
"versionPlans": true,
2019
"version": {
21-
"generator": "@react-native-mac/nx-release-version:release-version",
22-
"generatorOptions": {
20+
"versionActions": "@react-native-macos/nx-release-version",
21+
"versionActionsOptions": {
2322
"currentVersionResolver": "registry",
2423
"currentVersionResolverMetadata": {
2524
"tag": "nightly"
2625
},
2726
"preid": "nightly"
2827
},
29-
"useLegacyVersioning": true
28+
"useLegacyVersioning": false
3029
}
3130
}
3231
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@react-native-mac/monorepo",
2+
"name": "@react-native-macos/monorepo",
33
"private": true,
44
"version": "1000.0.0",
55
"license": "MIT",

packages/nx-release-version/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# os/nx-release-version
2+
3+
Modern Nx 21 Version Actions for React Native macOS releases.
4+
5+
## Overview
6+
7+
This package provides custom Version Actions for Nx 21's modern release system (`useLegacyVersioning: false`). It extends the built-in `JsVersionActions` to include React Native platform-specific artifact updates.
8+
9+
## What it does
10+
11+
When versioning the `react-native-macos` project, this package automatically:
12+
13+
1. **Updates standard package.json files** (via the base `JsVersionActions`)
14+
2. **Updates React Native platform artifacts**:
15+
- `ReactAndroid/gradle.properties`
16+
- `ReactNativeVersion.java`
17+
- `RCTVersion.m`
18+
- `ReactNativeVersion.h`
19+
- `ReactNativeVersion.js`
20+
3. **Creates a `.rnm-publish` marker file** to indicate successful versioning
21+
22+
## Migration from Legacy
23+
24+
This package has been migrated from the legacy generator-based approach to the modern Nx 21 Version Actions API:
25+
26+
### Before (Legacy)
27+
```json
28+
{
29+
"release": {
30+
"version": {
31+
"generator": "@react-native-mac/nx-release-version:release-version",
32+
"generatorOptions": { ... },
33+
"useLegacyVersioning": true
34+
}
35+
}
36+
}
37+
```
38+
39+
### After (Modern)
40+
```json
41+
{
42+
"release": {
43+
"version": {
44+
"versionActions": "@react-native-mac/nx-release-version",
45+
"versionActionsOptions": { ... },
46+
"useLegacyVersioning": false
47+
}
48+
}
49+
}
50+
```
51+
52+
## Architecture
53+
54+
- **`index.js`**: Main entry point containing the `ReactNativeMacOSVersionActions` class that extends `JsVersionActions`
55+
- **Legacy files removed**: `generators.json`, `schema.json`, `src/` directory
56+
57+
## Benefits of Modern Approach
58+
59+
1. **Better Integration**: Seamless integration with Nx 21's release lifecycle
60+
2. **Type Safety**: Better TypeScript support and IDE integration
61+
3. **Ecosystem Support**: Works with other Nx 21 ecosystem plugins
62+
4. **Future Proof**: No longer depends on legacy APIs that will be removed in Nx 22
63+
64+
## Usage
65+
66+
This package is automatically used when running `nx release` commands. No direct invocation needed.
67+
68+
```bash
69+
# Version and release projects
70+
npx nx release
71+
72+
# Create version plans
73+
npx nx release plan patch
74+
75+
# Version with specific increment
76+
npx nx release version patch
77+
```

packages/nx-release-version/generators.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/nx-release-version/index.js

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// @ts-check
22

3-
const { releaseVersionGenerator } = require('@nx/js/src/generators/release-version/release-version');
3+
const {REPO_ROOT} = require('../../scripts/consts');
4+
const JsVersionActions = require('@nx/js/src/release/version-actions').default;
45
const fs = require('node:fs');
56
const path = require('node:path');
6-
const { REPO_ROOT } = require('../../scripts/consts');
77

88
/**
99
* @returns {Promise<string[]>}
1010
*/
1111
async function runSetVersion() {
12-
const rnmPkgJson = require.resolve('react-native-macos/package.json');
13-
const { updateReactNativeArtifacts } = require('../../scripts/releases/set-rn-artifacts-version');
12+
const rnmPkgJsonPath = path.join(REPO_ROOT, 'packages', 'react-native', 'package.json');
13+
const {updateReactNativeArtifacts} = require('../../scripts/releases/set-rn-artifacts-version');
1414

15-
const manifest = fs.readFileSync(rnmPkgJson, { encoding: 'utf-8' });
16-
const { version } = JSON.parse(manifest);
15+
const manifest = fs.readFileSync(rnmPkgJsonPath, {encoding: 'utf-8'});
16+
const {version} = JSON.parse(manifest);
1717

1818
await updateReactNativeArtifacts(version);
1919

@@ -66,23 +66,59 @@ async function runSetVersion() {
6666
];
6767
}
6868

69-
/** @type {typeof releaseVersionGenerator} */
70-
module.exports = async function(tree, options) {
71-
const { data, callback } = await releaseVersionGenerator(tree, options);
72-
return {
73-
data,
74-
callback: async (tree, options) => {
75-
const result = await callback(tree, options);
69+
/**
70+
* Custom Version Actions for React Native macOS
71+
* Extends the built-in JsVersionActions to add React Native artifact updates
72+
*/
73+
class ReactNativeMacOSVersionActions extends JsVersionActions {
74+
/**
75+
* @override
76+
* Override updateProjectVersion to include React Native artifact updates
77+
* @param {import('@nx/devkit').Tree} tree
78+
* @param {string} newVersion
79+
* @returns {Promise<string[]>}
80+
*/
81+
async updateProjectVersion(tree, newVersion) {
82+
// First, run the standard JS version update (package.json, etc.)
83+
const standardLogMessages = await super.updateProjectVersion(tree, newVersion);
7684

77-
// Only update artifacts if there were changes
78-
const changedFiles = Array.isArray(result) ? result : result.changedFiles;
79-
if (changedFiles.length > 0) {
80-
fs.writeFile(path.join(REPO_ROOT, '.rnm-publish'), '', () => null);
85+
// Only update React Native artifacts for the react-native-macos project
86+
if (this.projectGraphNode.name === 'react-native-macos') {
87+
try {
88+
// Create the .rnm-publish file to indicate versioning has occurred
89+
fs.writeFileSync(path.join(REPO_ROOT, '.rnm-publish'), '');
90+
91+
// Update React Native artifacts
8192
const versionedFiles = await runSetVersion();
82-
changedFiles.push(...versionedFiles);
93+
94+
// Add the versioned files to the tree so they are tracked by Nx
95+
for (const filePath of versionedFiles) {
96+
if (fs.existsSync(filePath)) {
97+
const content = fs.readFileSync(filePath, 'utf-8');
98+
const relativePath = path.relative(REPO_ROOT, filePath);
99+
tree.write(relativePath, content);
100+
}
101+
}
102+
103+
return [
104+
...standardLogMessages,
105+
`✅ Updated React Native platform artifacts for version ${newVersion}`,
106+
`📁 Updated ${versionedFiles.length} platform-specific files`,
107+
'🏷️ Created .rnm-publish marker file',
108+
];
109+
} catch (error) {
110+
console.error('Failed to update React Native artifacts:', error);
111+
const errorMessage = error instanceof Error ? error.message : String(error);
112+
return [
113+
...standardLogMessages,
114+
`❌ Failed to update React Native artifacts: ${errorMessage}`,
115+
];
83116
}
117+
}
118+
119+
return standardLogMessages;
120+
}
121+
}
84122

85-
return result;
86-
},
87-
};
88-
};
123+
module.exports = ReactNativeMacOSVersionActions;
124+
module.exports.default = ReactNativeMacOSVersionActions;
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
{
2-
"private": true,
3-
"name": "@react-native-mac/nx-release-version",
2+
"name": "@react-native-macos/nx-release-version",
43
"version": "0.0.1-dev",
5-
"description": "Nx Release plugin that adds post-versioning logic",
4+
"description": "Nx Release Version Actions for React Native macOS",
65
"homepage": "https://github.com/microsoft/react-native-macos/tree/HEAD/packages/nx-release-version#readme",
76
"license": "MIT",
87
"files": [
9-
"generators.json",
10-
"index.js",
11-
"schema.json"
8+
"index.js"
129
],
1310
"main": "index.js",
1411
"repository": {
@@ -17,14 +14,13 @@
1714
"directory": "packages/nx-release-version"
1815
},
1916
"dependencies": {
20-
"@nx/js": "~20.0.0"
17+
"@nx/js": "21.2.4"
2118
},
2219
"devDependencies": {
2320
"@rnx-kit/tsconfig": "^2.0.0",
2421
"typescript": "^5.6.3"
2522
},
2623
"engines": {
2724
"node": ">=18"
28-
},
29-
"generators": "./generators.json"
25+
}
3026
}

packages/nx-release-version/schema.json

Lines changed: 0 additions & 68 deletions
This file was deleted.

packages/react-native/Libraries/Inspector/NetworkOverlay.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import type {RenderItemProps} from '@react-native-mac/virtualized-lists'; // [macOS]
13+
import type {RenderItemProps} from '@react-native-macos/virtualized-lists'; // [macOS]
1414

1515
const ScrollView = require('../Components/ScrollView/ScrollView');
1616
const TouchableHighlight = require('../Components/Touchable/TouchableHighlight');

packages/react-native/Libraries/Lists/FillRateHelper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
'use strict';
1212

13-
import {typeof FillRateHelper as FillRateHelperType} from '@react-native-mac/virtualized-lists'; // [macOS]
13+
import {typeof FillRateHelper as FillRateHelperType} from '@react-native-macos/virtualized-lists'; // [macOS]
1414

1515
const FillRateHelper: FillRateHelperType =
16-
require('@react-native-mac/virtualized-lists').FillRateHelper; // [macOS]
16+
require('@react-native-macos/virtualized-lists').FillRateHelper; // [macOS]
1717

18-
export type {FillRateInfo} from '@react-native-mac/virtualized-lists'; // [macOS]
18+
export type {FillRateInfo} from '@react-native-macos/virtualized-lists'; // [macOS]
1919
module.exports = FillRateHelper;

packages/react-native/Libraries/Lists/FlatList.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
ViewToken,
1414
VirtualizedListProps,
1515
ViewabilityConfig,
16-
} from '@react-native-mac/virtualized-lists'; // [macOS]
16+
} from '@react-native-macos/virtualized-lists'; // [macOS]
1717
import type {ScrollViewComponent} from '../Components/ScrollView/ScrollView';
1818
import type {StyleProp} from '../StyleSheet/StyleSheet';
1919
import type {ViewStyle} from '../StyleSheet/StyleSheetTypes';

0 commit comments

Comments
 (0)