|
1 | 1 | // @ts-check |
2 | 2 |
|
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; |
4 | 5 | const fs = require('node:fs'); |
5 | 6 | const path = require('node:path'); |
6 | | -const { REPO_ROOT } = require('../../scripts/consts'); |
7 | 7 |
|
8 | 8 | async function runSetVersion() { |
9 | | - const rnmPkgJson = require.resolve('react-native-macos/package.json'); |
10 | | - const { REPO_ROOT } = require('../../scripts/consts'); |
11 | | - const { updateReactNativeArtifacts } = require('../../scripts/releases/set-rn-artifacts-version'); |
| 9 | + const rnmPkgJsonPath = path.join(REPO_ROOT, 'packages', 'react-native', 'package.json'); |
| 10 | + const {updateReactNativeArtifacts} = require('../../scripts/releases/set-rn-artifacts-version'); |
12 | 11 |
|
13 | | - const manifest = fs.readFileSync(rnmPkgJson, { encoding: 'utf-8' }); |
14 | | - const { version } = JSON.parse(manifest); |
| 12 | + const manifest = fs.readFileSync(rnmPkgJsonPath, {encoding: 'utf-8'}); |
| 13 | + const {version} = JSON.parse(manifest); |
15 | 14 |
|
16 | 15 | await updateReactNativeArtifacts(version); |
17 | 16 |
|
@@ -64,21 +63,59 @@ async function runSetVersion() { |
64 | 63 | ]; |
65 | 64 | } |
66 | 65 |
|
67 | | -/** @type {typeof releaseVersionGenerator} */ |
68 | | -module.exports = async function(tree, options) { |
69 | | - const { data, callback } = await releaseVersionGenerator(tree, options); |
70 | | - return { |
71 | | - data, |
72 | | - callback: async (tree, options) => { |
73 | | - const result = await callback(tree, options); |
| 66 | +/** |
| 67 | + * Custom Version Actions for React Native macOS |
| 68 | + * Extends the built-in JsVersionActions to add React Native artifact updates |
| 69 | + */ |
| 70 | +class ReactNativeMacOSVersionActions extends JsVersionActions { |
| 71 | + /** |
| 72 | + * @override |
| 73 | + * Override updateProjectVersion to include React Native artifact updates |
| 74 | + * @param {import('@nx/devkit').Tree} tree |
| 75 | + * @param {string} newVersion |
| 76 | + * @returns {Promise<string[]>} |
| 77 | + */ |
| 78 | + async updateProjectVersion(tree, newVersion) { |
| 79 | + // First, run the standard JS version update (package.json, etc.) |
| 80 | + const standardLogMessages = await super.updateProjectVersion(tree, newVersion); |
74 | 81 |
|
75 | | - const versionedFiles = await runSetVersion(); |
76 | | - if (versionedFiles) { |
77 | | - const changedFiles = Array.isArray(result) ? result : result.changedFiles; |
78 | | - changedFiles.push(...versionedFiles); |
| 82 | + // Only update React Native artifacts for the react-native-macos project |
| 83 | + if (this.projectGraphNode.name === 'react-native-macos') { |
| 84 | + try { |
| 85 | + // Create the .rnm-publish file to indicate versioning has occurred |
| 86 | + fs.writeFileSync(path.join(REPO_ROOT, '.rnm-publish'), ''); |
| 87 | + |
| 88 | + // Update React Native artifacts |
| 89 | + const versionedFiles = await runSetVersion(); |
| 90 | + |
| 91 | + // Add the versioned files to the tree so they are tracked by Nx |
| 92 | + for (const filePath of versionedFiles) { |
| 93 | + if (fs.existsSync(filePath)) { |
| 94 | + const content = fs.readFileSync(filePath, 'utf-8'); |
| 95 | + const relativePath = path.relative(REPO_ROOT, filePath); |
| 96 | + tree.write(relativePath, content); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + return [ |
| 101 | + ...standardLogMessages, |
| 102 | + `✅ Updated React Native platform artifacts for version ${newVersion}`, |
| 103 | + `📁 Updated ${versionedFiles.length} platform-specific files`, |
| 104 | + '🏷️ Created .rnm-publish marker file', |
| 105 | + ]; |
| 106 | + } catch (error) { |
| 107 | + console.error('Failed to update React Native artifacts:', error); |
| 108 | + const errorMessage = error instanceof Error ? error.message : String(error); |
| 109 | + return [ |
| 110 | + ...standardLogMessages, |
| 111 | + `❌ Failed to update React Native artifacts: ${errorMessage}`, |
| 112 | + ]; |
79 | 113 | } |
| 114 | + } |
| 115 | + |
| 116 | + return standardLogMessages; |
| 117 | + } |
| 118 | +} |
80 | 119 |
|
81 | | - return result; |
82 | | - }, |
83 | | - }; |
84 | | -}; |
| 120 | +module.exports = ReactNativeMacOSVersionActions; |
| 121 | +module.exports.default = ReactNativeMacOSVersionActions; |
0 commit comments