Skip to content

Commit e9a4c0d

Browse files
authored
improve validation checks and cleanup scripts (#1957)
1 parent 6244053 commit e9a4c0d

5 files changed

Lines changed: 91 additions & 32 deletions

File tree

react-native-libraries.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10791,7 +10791,7 @@
1079110791
},
1079210792
{
1079310793
"githubUrl": "https://github.com/Richou/react-native-android-location-enabler",
10794-
"example": [
10794+
"examples": [
1079510795
"https://github.com/Richou/react-native-android-location-enabler/tree/main/example"
1079610796
],
1079710797
"images": [
@@ -13729,7 +13729,7 @@
1372913729
"examples": ["https://github.com/liveakshay/expo-spellchecker/tree/main/example"],
1373013730
"ios": true,
1373113731
"android": true,
13732-
"expo": true,
13732+
"expoGo": true,
1373313733
"newArchitecture": true
1373413734
},
1373513735
{
@@ -13750,7 +13750,7 @@
1375013750
"ios": true,
1375113751
"android": true,
1375213752
"web": true,
13753-
"expo": true,
13753+
"expoGo": true,
1375413754
"newArchitecture": true
1375513755
},
1375613756
{
@@ -13762,7 +13762,7 @@
1376213762
"ios": true,
1376313763
"android": true,
1376413764
"web": true,
13765-
"expo": true,
13765+
"expoGo": true,
1376613766
"newArchitecture": true,
1376713767
"fireos": true
1376813768
},
@@ -13772,7 +13772,7 @@
1377213772
"ios": true,
1377313773
"android": true,
1377413774
"web": true,
13775-
"expo": true,
13775+
"expoGo": true,
1377613776
"newArchitecture": true,
1377713777
"fireos": true
1377813778
},
@@ -13781,7 +13781,7 @@
1378113781
"ios": true,
1378213782
"android": true,
1378313783
"web": true,
13784-
"expo": true,
13784+
"expoGo": true,
1378513785
"newArchitecture": true,
1378613786
"fireos": true
1378713787
},
@@ -13791,7 +13791,7 @@
1379113791
"android": true,
1379213792
"web": true,
1379313793
"fireos": true,
13794-
"expo": true,
13794+
"expoGo": true,
1379513795
"newArchitecture": true
1379613796
},
1379713797
{
@@ -13800,7 +13800,7 @@
1380013800
"ios": true,
1380113801
"android": true,
1380213802
"web": true,
13803-
"expo": true,
13803+
"expoGo": true,
1380413804
"newArchitecture": true
1380513805
},
1380613806
{
@@ -13809,36 +13809,36 @@
1380913809
"ios": true,
1381013810
"android": true,
1381113811
"web": true,
13812-
"expo": true
13812+
"expoGo": true
1381313813
},
1381413814
{
1381513815
"githubUrl": "https://github.com/FortAwesome/Font-Awesome/tree/6.x/js-packages/@fortawesome/free-regular-svg-icons",
1381613816
"npmPkg": "@fortawesome/free-regular-svg-icons",
1381713817
"ios": true,
1381813818
"android": true,
1381913819
"web": true,
13820-
"expo": true
13820+
"expoGo": true
1382113821
},
1382213822
{
1382313823
"githubUrl": "https://github.com/FortAwesome/Font-Awesome/tree/6.x/js-packages/@fortawesome/free-solid-svg-icons",
1382413824
"npmPkg": "@fortawesome/free-solid-svg-icons",
1382513825
"ios": true,
1382613826
"android": true,
1382713827
"web": true,
13828-
"expo": true
13828+
"expoGo": true
1382913829
},
1383013830
{
1383113831
"githubUrl": "https://github.com/FilipiRafael/react-native-motion-tabs",
1383213832
"ios": true,
1383313833
"android": true,
13834-
"expo": true,
13834+
"expoGo": true,
1383513835
"newArchitecture": true
1383613836
},
1383713837
{
1383813838
"githubUrl": "https://github.com/vantuan88291/react-native-ota-hot-update",
1383913839
"ios": true,
1384013840
"android": true,
13841-
"expo": true,
13841+
"expoGo": true,
1384213842
"newArchitecture": true,
1384313843
"configPlugin": true
1384413844
},
@@ -17428,7 +17428,7 @@
1742817428
{
1742917429
"githubUrl": "https://github.com/avas-app/react-native-android-otp-autofill",
1743017430
"npmPkg": "@avasapp/react-native-otp-autofill",
17431-
"example": ["https://github.com/avas-app/react-native-android-otp-autofill/tree/main/example"],
17431+
"examples": ["https://github.com/avas-app/react-native-android-otp-autofill/tree/main/example"],
1743217432
"ios": true,
1743317433
"android": true,
1743417434
"newArchitecture": true,
@@ -17732,20 +17732,16 @@
1773217732
},
1773317733
{
1773417734
"githubUrl": "https://github.com/orcunorcun/react-native-cookie-handler",
17735-
"npmPkg": "react-native-cookie-handler",
17736-
"examples": [
17737-
"https://github.com/orcunorcun/react-native-cookie-handler/tree/master/example"
17738-
],
17735+
"examples": ["https://github.com/orcunorcun/react-native-cookie-handler/tree/master/example"],
1773917736
"ios": true,
1774017737
"android": true
1774117738
},
1774217739
{
1774317740
"githubUrl": "https://github.com/mCodex/react-native-nitro-sfsymbols",
17744-
"npmPkg": "react-native-nitro-sfsymbols",
17745-
"examples": [
17746-
"https://github.com/mCodex/react-native-nitro-sfsymbols/tree/main/example"
17741+
"examples": ["https://github.com/mCodex/react-native-nitro-sfsymbols/tree/main/example"],
17742+
"images": [
17743+
"https://raw.githubusercontent.com/mCodex/react-native-nitro-sfsymbols/refs/heads/main/example.gif"
1774717744
],
17748-
"images": ["https://raw.githubusercontent.com/mCodex/react-native-nitro-sfsymbols/refs/heads/main/example.gif"],
1774917745
"ios": true,
1775017746
"macos": true,
1775117747
"tvos": true,
@@ -17754,16 +17750,20 @@
1775417750
},
1775517751
{
1775617752
"githubUrl": "https://github.com/sbaiahmed1/react-native-menus",
17757-
"npmPkg": "react-native-menus",
17758-
"examples": [
17759-
"https://github.com/sbaiahmed1/react-native-menus/tree/main/example"
17760-
],
17753+
"examples": ["https://github.com/sbaiahmed1/react-native-menus/tree/main/example"],
1776117754
"images": [
1776217755
"https://raw.githubusercontent.com/sbaiahmed1/react-native-menus/refs/heads/main/android-image.png",
1776317756
"https://raw.githubusercontent.com/sbaiahmed1/react-native-menus/refs/heads/main/ios-image.png"
1776417757
],
1776517758
"ios": true,
17766-
"expo": true,
17759+
"android": true,
17760+
"newArchitecture": true,
17761+
"expoGo": true
17762+
},
17763+
{
17764+
"githubUrl": "https://github.com/software-mansion-labs/react-native-shine",
17765+
"examples": ["https://github.com/software-mansion-labs/react-native-shine/tree/main/example"],
17766+
"ios": true,
1776717767
"android": true,
1776817768
"newArchitecture": true,
1776917769
"expoGo": true

scripts/cleanup-libraries-json.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'node:path';
44

55
import libraries from '~/react-native-libraries.json';
66
import { type LibraryDataEntryType } from '~/types';
7+
import { VALID_ENTRY_KEYS } from '~/util/Constants';
78

89
const LIBRARIES_JSON_PATH = path.join('react-native-libraries.json');
910

@@ -14,6 +15,16 @@ function removeEmptyArray(lib: LibraryDataEntryType, key: 'examples' | 'images')
1415
}
1516

1617
const processedLibraries = libraries
18+
// Remove invalid keys in entry
19+
.map(lib => {
20+
const invalidKeys = Object.keys(lib).filter(key => !VALID_ENTRY_KEYS.has(key));
21+
22+
if (invalidKeys.length > 0) {
23+
return omit(lib, invalidKeys);
24+
}
25+
26+
return lib;
27+
})
1728
// Remove redundant `npmPkg` for libraries with the correct GitHub repository name
1829
.map((lib: LibraryDataEntryType) =>
1930
lib.npmPkg && !lib.npmPkg.includes('/') && lib.githubUrl.endsWith(`/${lib.npmPkg}`)

scripts/validate-libraries.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { fillNpmName } from '~/scripts/helpers';
12
import { type LibraryType } from '~/types';
3+
import { VALID_ENTRY_KEYS } from '~/util/Constants';
24

35
import libraries from '../react-native-libraries.json';
46

@@ -11,27 +13,37 @@ function validateLibrariesFormat(libraries: LibraryType[]) {
1113
const errorsList = libraries.reduce<Record<string, string[]>>((errors, library, index) => {
1214
const libraryErrors = [];
1315
const libraryProperties = Object.keys(library);
16+
const libraryWithNpmName = fillNpmName(library);
1417

1518
// Check that it has the githubUrl property and that it is in the correct format
1619
if (!libraryProperties.includes('githubUrl')) {
17-
libraryErrors.push('Must contain a githubUrl property');
20+
libraryErrors.push(`- Must contain a 'githubUrl' property`);
1821
} else if (!library.githubUrl.match(GITHUB_URL_PATTERN)) {
1922
libraryErrors.push(
20-
`The githubUrl of ${library.githubUrl} must be in the format:\nhttps://github.com/owner/repo-name or https://github.com/owner/repo-name/tree/default-branch/name for monorepos`
23+
`- The 'githubUrl' of ${library.githubUrl} must be in the format:\nhttps://github.com/owner/repo-name or https://github.com/owner/repo-name/tree/default-branch/name for monorepos`
2124
);
2225
}
2326

27+
const invalidKeys = libraryProperties.filter(key => !VALID_ENTRY_KEYS.has(key));
28+
29+
if (invalidKeys.length > 0) {
30+
invalidKeys.forEach(key => {
31+
libraryErrors.push(`- Uses invalid key - ${key}`);
32+
});
33+
}
34+
2435
// If there were errors, add them to the object
2536
if (libraryErrors.length > 0) {
26-
errors[index] = libraryErrors;
37+
errors[libraryWithNpmName.npmPkg] = libraryErrors;
2738
}
2839

2940
return errors;
3041
}, {});
3142

3243
if (Object.keys(errorsList).length > 0) {
3344
const errorDescriptions = Object.entries(errorsList).map(
34-
([index, libraryErrors]) => `Library at index ${index}:\n${libraryErrors.join('\n')}`
45+
([npmPkg, libraryErrors], index) =>
46+
`Library entry for '${npmPkg}' contains errors:\n${libraryErrors.join('\n')}`
3547
);
3648
console.error('❌ Malformed libraries found:\n' + errorDescriptions.join('\n'));
3749
process.exit(1);

scripts/validate-new-entries.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { fetch } from 'bun';
22
import { differenceWith, isEqual } from 'es-toolkit';
33

4+
import { VALID_ENTRY_KEYS } from '~/util/Constants';
5+
46
import { fetchGithubData } from './fetch-github-data';
57
import { fetchNpmDownloadData } from './fetch-npm-download-data';
68
import { fillNpmName, hasMismatchedPackageData } from './helpers';
@@ -20,7 +22,7 @@ if (libraries.length === mainData.length) {
2022
process.exit(0);
2123
}
2224

23-
console.log('🔍️ Detected changes in data entries, checking!');
25+
console.log('🚩️ Detected changes in data entries, checking!');
2426

2527
const modifiedEntries = differenceWith(libraries, mainData, isEqual);
2628

@@ -80,6 +82,16 @@ const checkResults = await Promise.all(
8082

8183
return false;
8284
}
85+
86+
const invalidKeys = Object.keys(entry).filter(key => !VALID_ENTRY_KEYS.has(key));
87+
88+
if (invalidKeys.length > 0) {
89+
console.error(
90+
`Package entry for '${entryWithGitHubData.npmPkg}' contains invalid fields: ${invalidKeys.map(key => `'${key}'`).join(', ')}. Correct or remove the listed keys to fix the definition.`
91+
);
92+
return false;
93+
}
94+
8395
return true;
8496
})
8597
);
@@ -88,4 +100,5 @@ if (checkResults.filter(result => !result).length > 0) {
88100
console.error('\n❌ There were errors spotted during new entries check!');
89101
process.exit(1);
90102
}
103+
91104
console.log('✅ All checks have passed!');

util/Constants.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
11
export const NUM_PER_PAGE = 30;
2+
3+
export const VALID_ENTRY_KEYS = new Set([
4+
'githubUrl',
5+
'ios',
6+
'android',
7+
'web',
8+
'expoGo',
9+
'windows',
10+
'macos',
11+
'fireos',
12+
'tvos',
13+
'visionos',
14+
'unmaintained',
15+
'dev',
16+
'template',
17+
'newArchitecture',
18+
'newArchitectureNote',
19+
'configPlugin',
20+
'alternatives',
21+
'npmPkg',
22+
'examples',
23+
'images',
24+
]);

0 commit comments

Comments
 (0)