Skip to content

Commit 4fe8727

Browse files
Saadnajmiclaude
andcommitted
fix: fix "Invalid platform macos" in init integration test
Three fixes for the CI "Test react-native-macos init" job: 1. Simplify apple platform resolution in react-native.config.js to use the same pattern as ios/android (resolve from cwd directly). 2. Use glob patterns in package.json files array ("scripts/cocoapods/**" instead of "scripts/cocoapods") so yarn pack includes directory contents. See facebook#56407. 3. Replace `npm install <local-path>` (creates symlinks) with `yarn pack` + `npm install <tarball>` + `chmod +x`. The symlink approach caused module instance duplication (setFrameworkDefaults targeting wrong @react-native/metro-config instance) and missing pre-generated codegen headers. The tarball approach matches what users get from npm. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 34828e2 commit 4fe8727

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

.github/workflows/microsoft-test-react-native-macos-init.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ jobs:
2626
run: yarn install
2727

2828
- name: Build community CLI plugin
29-
run: yarn build
29+
run: |
30+
yarn build
31+
# yarn build rewrites package.json "exports" from ./src to ./dist
32+
# for publishing. Restore the original exports so that any
33+
# monorepo tooling that still runs from source continues to work.
34+
git checkout -- packages/*/package.json
3035
3136
- name: Build react-native-macos-init
3237
working-directory: packages/react-native-macos-init
@@ -47,11 +52,26 @@ jobs:
4752
npx --yes @react-native-community/cli init testcli --version ${{ steps.rn-version.outputs.version }}
4853
working-directory: ${{ runner.temp }}
4954

55+
- name: Pack local react-native-macos
56+
working-directory: packages/react-native
57+
run: |
58+
set -eox pipefail
59+
# Pack the local package into a tarball. This runs the "prepack"
60+
# script which generates the FBReactNativeSpec codegen headers
61+
# (React/FBReactNativeSpec/) that are shipped in published releases.
62+
yarn pack -o ${{ runner.temp }}/react-native-macos.tgz
63+
5064
- name: Install local react-native-macos
5165
working-directory: ${{ runner.temp }}/testcli
5266
run: |
5367
set -eox pipefail
54-
npm install ${{ github.workspace }}/packages/react-native
68+
# Install from the tarball so the test project matches a normal
69+
# user's node_modules layout: no symlinks (which cause module
70+
# instance duplication) and pre-generated codegen headers present
71+
# (which the build relies on to skip regeneration).
72+
npm install ${{ runner.temp }}/react-native-macos.tgz
73+
# yarn pack strips execute permissions from shell scripts
74+
chmod +x node_modules/react-native-macos/scripts/*.sh node_modules/react-native-macos/scripts/xcode/*.sh
5575
5676
- name: Apply macOS template
5777
working-directory: ${{ runner.temp }}/testcli

packages/react-native/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@
109109
"README.md",
110110
"rn-get-polyfills.js",
111111
"scripts/bundle.js",
112-
"scripts/cocoapods",
113-
"scripts/codegen",
112+
"scripts/cocoapods/**",
113+
"scripts/codegen/**",
114114
"scripts/compose-source-maps.js",
115115
"scripts/find-node-for-xcode.sh",
116116
"scripts/generate-codegen-artifacts.js",
@@ -133,7 +133,7 @@
133133
"scripts/xcode/ccache.conf",
134134
"scripts/xcode/with-environment.sh",
135135
"sdks/.hermesversion",
136-
"sdks/hermes-engine",
136+
"sdks/hermes-engine/**",
137137
"sdks/hermesc",
138138
"settings.gradle.kts",
139139
"src",

packages/react-native/react-native.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,9 @@ try {
7171
// [macOS
7272
let apple;
7373
try {
74-
const iosPath = require.resolve('@react-native-community/cli-platform-ios', {
75-
paths: [process.cwd()],
76-
});
7774
// $FlowFixMe[untyped-import]
7875
apple = findCommunityPlatformPackage(
7976
'@react-native-community/cli-platform-apple',
80-
iosPath,
8177
);
8278
} catch {
8379
if (verbose) {

0 commit comments

Comments
 (0)