Skip to content

Commit e3183c6

Browse files
maciekstosioja1ns
authored andcommitted
fix: Fixes to sync archs scripts (software-mansion#2259)
## Description Fixes to software-mansion#2224, that came out in other repos. ## Changes - Bump version of GitHub actions - Fix warning when trying to copy non existing codegen interface ## Test code and steps to reproduce Duplicate `android/src/paper/java/com/facebook/react/viewmanagers/RNSSearchBarManagerDelegate.java` with name change for example with ` copy` at the end. Before it would fail because file wouldn't be found. Now there will be warning in logs.
1 parent dfaf20e commit e3183c6

File tree

4 files changed

+61
-36
lines changed

4 files changed

+61
-36
lines changed

.github/workflows/check-archs-consistency.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ on:
66
paths:
77
- src/fabric/**
88
- android/src/paper/java/com/facebook/react/viewmanagers/**
9+
- .github/workflows/check-archs-consistency.yml
10+
push:
11+
branches:
12+
- main
13+
workflow_dispatch:
14+
915
jobs:
1016
check:
1117
runs-on: ubuntu-latest
@@ -14,13 +20,13 @@ jobs:
1420
cancel-in-progress: true
1521
steps:
1622
- name: checkout
17-
uses: actions/checkout@v2
23+
uses: actions/checkout@v4
1824
- name: Use Node.js 18
19-
uses: actions/setup-node@v2
25+
uses: actions/setup-node@v4
2026
with:
2127
node-version: 18
2228
cache: 'yarn'
2329
- name: Install node dependencies
2430
run: yarn
2531
- name: Check Android Paper & Fabric generated interfaces consistency
26-
run: yarn check-archs-consistency
32+
run: yarn architectures-consistency-check

android/src/paper/java/com/swmansion/rnscreens/NativeScreensModuleSpec.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
package com.swmansion.rnscreens;
1414

15+
import com.facebook.proguard.annotations.DoNotStrip;
1516
import com.facebook.react.bridge.ReactApplicationContext;
1617
import com.facebook.react.bridge.ReactContextBaseJavaModule;
18+
import com.facebook.react.bridge.ReactMethod;
1719
import com.facebook.react.bridge.ReactModuleWithSpec;
1820
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
1921
import javax.annotation.Nonnull;
@@ -29,4 +31,6 @@ public NativeScreensModuleSpec(ReactApplicationContext reactContext) {
2931
public @Nonnull String getName() {
3032
return NAME;
3133
}
34+
35+
3236
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"lint": "yarn lint-js && yarn lint-android",
2020
"release": "yarn prepare && npm login && release-it",
2121
"prepare": "bob build && husky install",
22-
"check-archs-consistency": "node ./scripts/codegen-check-consistency.js",
23-
"sync-archs": "node ./scripts/codegen-sync-archs.js"
22+
"architectures-consistency-check": "node ./scripts/codegen-check-consistency.js",
23+
"sync-architectures": "node ./scripts/codegen-sync-archs.js"
2424
},
2525
"main": "lib/commonjs/index",
2626
"module": "lib/module/index",
@@ -130,7 +130,7 @@
130130
"android/src/main/cpp/.{cpp, h}": "yarn format-android-cpp",
131131
"android/**/*.kt": "yarn format-android",
132132
"ios/**/*.{h,m,mm,cpp}": "yarn format-ios",
133-
"src/fabric/*.ts": "yarn sync-archs"
133+
"src/fabric/*.ts": "yarn sync-architectures"
134134
},
135135
"react-native-builder-bob": {
136136
"source": "src",

scripts/codegen-utils.js

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,31 @@ const RN_CODEGEN_DIR = path.resolve(
1616
'node_modules/@react-native/codegen',
1717
);
1818

19-
const SOURCE_FOLDERS = 'java/com/facebook/react/viewmanagers';
20-
const CODEGEN_FILES_DIR = `${GENERATED_DIR}/source/codegen/${SOURCE_FOLDERS}`;
21-
const OLD_ARCH_FILES_DIR = `${OLD_ARCH_DIR}/${SOURCE_FOLDERS}`;
19+
const SOURCE_FOLDER = 'java/com/facebook/react/viewmanagers';
20+
const SCREENS_SOURCE_FOLDER = 'java/com/swmansion/rnscreens'
21+
22+
const SOURCE_FOLDERS = [
23+
{codegenPath: `${GENERATED_DIR}/source/codegen/${SOURCE_FOLDER}`, oldArchPath: `${OLD_ARCH_DIR}/${SOURCE_FOLDER}`},
24+
{codegenPath: `${GENERATED_DIR}/source/codegen/${SCREENS_SOURCE_FOLDER}`, oldArchPath: `${OLD_ARCH_DIR}/${SCREENS_SOURCE_FOLDER}`},
25+
]
26+
27+
const BLACKLISTED_FILES = new Set([
28+
'FabricEnabledViewGroup.kt',
29+
]);
30+
2231

2332
function exec(command) {
2433
console.log(`[${ERROR_PREFIX}]> ` + command);
2534
execSync(command);
2635
}
2736

37+
function readdirSync(dir) {
38+
return fs.readdirSync(dir).filter(file => !BLACKLISTED_FILES.has(file));
39+
}
40+
2841
function fixOldArchJavaForRN72Compat(dir) {
2942
// see https://github.com/rnmapbox/maps/issues/3193
30-
const files = fs.readdirSync(dir);
43+
const files = readdirSync(dir);
3144
files.forEach(file => {
3245
const filePath = path.join(dir, file);
3346
const fileExtension = path.extname(file);
@@ -70,34 +83,34 @@ async function generateCodegen() {
7083
async function generateCodegenJavaOldArch() {
7184
await generateCodegen();
7285

73-
const generatedFiles = fs.readdirSync(CODEGEN_FILES_DIR);
74-
const oldArchFiles = fs.readdirSync(OLD_ARCH_FILES_DIR);
75-
const existingFilesSet = new Set(oldArchFiles.map(fileName => fileName));
86+
SOURCE_FOLDERS.forEach(({codegenPath, oldArchPath}) => {
87+
const generatedFiles = readdirSync(codegenPath);
88+
const oldArchFiles = readdirSync(oldArchPath);
89+
const existingFilesSet = new Set(oldArchFiles.map(fileName => fileName));
7690

77-
generatedFiles.forEach(generatedFile => {
78-
if (!existingFilesSet.has(generatedFile)) {
79-
console.warn(
80-
`[${ERROR_PREFIX}] ${generatedFile} not found in paper dir, if it's used on Android you need to copy it manually and implement yourself before using auto-copy feature.`,
81-
);
82-
}
83-
});
84-
85-
if (oldArchFiles.length === 0) {
86-
console.warn(
87-
`[${ERROR_PREFIX}] Paper destination with codegen interfaces is empty. This might be okay if you don't have any interfaces/delegates used on Android, otherwise please check if OLD_ARCH_DIR and SOURCE_FOLDERS are set properly.`,
88-
);
89-
}
91+
generatedFiles.forEach(generatedFile => {
92+
if (!existingFilesSet.has(generatedFile)) {
93+
console.warn(
94+
`[${ERROR_PREFIX}] ${generatedFile} not found in paper dir, if it's used on Android you need to copy it manually and implement yourself before using auto-copy feature.`,
95+
);
96+
}
97+
});
9098

91-
oldArchFiles.forEach(oldArchFile => {
92-
if (!fs.existsSync(`${CODEGEN_FILES_DIR}/${oldArchFile}`)) {
99+
if (oldArchFiles.length === 0) {
93100
console.warn(
94-
`[${ERROR_PREFIX}] ${existingFile.name} file does not exist in codegen artifacts source destination. Please check if you still need this interface/delagete.`,
101+
`[${ERROR_PREFIX}] Paper destination with codegen interfaces is empty. This might be okay if you don't have any interfaces/delegates used on Android, otherwise please check if OLD_ARCH_DIR and SOURCE_FOLDERS are set properly.`,
95102
);
96103
}
97-
});
98104

99-
oldArchFiles.forEach(file => {
100-
exec(`cp -rf ${CODEGEN_FILES_DIR}/${file} ${OLD_ARCH_FILES_DIR}/${file}`);
105+
oldArchFiles.forEach(file => {
106+
if (!fs.existsSync(`${codegenPath}/${file}`)) {
107+
console.warn(
108+
`[${ERROR_PREFIX}] ${file} file does not exist in codegen artifacts source destination. Please check if you still need this interface/delagete.`
109+
);
110+
} else {
111+
exec(`cp -rf ${codegenPath}/${file} ${oldArchPath}/${file}`);
112+
}
113+
});
101114
});
102115
}
103116

@@ -107,17 +120,19 @@ function compareFileAtTwoPaths(filename, firstPath, secondPath) {
107120

108121
if (fileA !== fileB) {
109122
throw new Error(
110-
`[${ERROR_PREFIX}] File ${filename} is different at ${firstPath} and ${secondPath}. Make sure you commited codegen autogenerated files.`,
123+
`[${ERROR_PREFIX}] File ${filename} is different at ${firstPath} and ${secondPath}. Make sure you committed codegen autogenerated files.`,
111124
);
112125
}
113126
}
114127

115128
async function checkCodegenIntegrity() {
116129
await generateCodegen();
117130

118-
const oldArchFiles = fs.readdirSync(OLD_ARCH_FILES_DIR);
119-
oldArchFiles.forEach(file => {
120-
compareFileAtTwoPaths(file, CODEGEN_FILES_DIR, OLD_ARCH_FILES_DIR);
131+
SOURCE_FOLDERS.forEach(({codegenPath, oldArchPath}) => {
132+
const oldArchFiles = readdirSync(oldArchPath);
133+
oldArchFiles.forEach(file => {
134+
compareFileAtTwoPaths(file, codegenPath, oldArchPath);
135+
});
121136
});
122137
}
123138

0 commit comments

Comments
 (0)