Skip to content

Commit bfec14f

Browse files
authored
use Bun/global fetch, improve resources check, update lib entries (#1891)
1 parent c571e39 commit bfec14f

16 files changed

Lines changed: 124 additions & 151 deletions

bun.lock

Lines changed: 13 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/Library/UpdateAtView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { StyleSheet, View } from 'react-native';
44
import { A, colors, darkColors } from '~/common/styleguide';
55
import Tooltip from '~/components/Tooltip';
66
import CustomAppearanceContext from '~/context/CustomAppearanceContext';
7-
import { parseGitHubUrl } from '~/scripts/helpers';
87
import { type LibraryType } from '~/types';
98
import { getTimeSinceToday } from '~/util/datetime';
9+
import { parseGitHubUrl } from '~/util/parseGitHubUrl';
1010

1111
import { Calendar } from '../Icons';
1212

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"data:validate": "ajv validate -s react-native-libraries.schema.json -d react-native-libraries.json --verbose --allowUnionTypes",
1111
"libraries:cleanup": "bun scripts/cleanup-libraries-json && bun libraries:format",
1212
"libraries:recalculate": "bun scripts/recalculate-scores",
13-
"libraries:format": "prettier --write react-native-libraries.json",
13+
"libraries:format": "prettier --experimental-cli --write react-native-libraries.json",
1414
"libraries:check": "bun scripts/check-resources",
1515
"ci:cleanup-blobs": "bun scripts/cleanup-data-blobs",
1616
"ci:validate": "bun scripts/validate-new-entries",
@@ -25,7 +25,7 @@
2525
"@react-native-picker/picker": "^2.11.2",
2626
"@sentry/react": "^10.12.0",
2727
"@vercel/blob": "^0.27.3",
28-
"expo": "54.0.8",
28+
"expo": "54.0.9",
2929
"expo-font": "^14.0.8",
3030
"lodash": "^4.17.21",
3131
"next": "^15.5.3",
@@ -49,9 +49,8 @@
4949
"ajv-cli": "^5.0.0",
5050
"browserslist": "^4.26.2",
5151
"cheerio": "^1.1.2",
52-
"cross-fetch": "^4.1.0",
5352
"dotenv": "^17.2.2",
54-
"eslint": "^9.35.0",
53+
"eslint": "^9.36.0",
5554
"eslint-config-next": "^15.5.3",
5655
"eslint-config-universe": "^15.0.3",
5756
"lint-staged": "^16.1.6",

pages/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'cross-fetch';
21
import { NextPageContext } from 'next';
32
import { useRouter } from 'next/router';
43
import { type ParsedUrlQuery } from 'node:querystring';

pages/popular.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'cross-fetch';
21
import { NextPageContext } from 'next';
32
import { StyleSheet } from 'react-native';
43

react-native-libraries.json

Lines changed: 50 additions & 59 deletions
Large diffs are not rendered by default.

scripts/build-and-score-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BlobAccessError, list, put } from '@vercel/blob';
2-
import fetch from 'cross-fetch';
2+
import { fetch } from 'bun';
33
import chunk from 'lodash/chunk';
44
import fs from 'node:fs';
55
import path from 'node:path';
@@ -37,7 +37,7 @@ const DATA_PATH = path.resolve('assets', 'data.json');
3737
const GITHUB_RESULTS_PATH = path.join('scripts', 'raw-github-results.json');
3838

3939
const CHUNK_SIZE = 25;
40-
const SLEEP_TIME = 500;
40+
const SLEEP_TIME = 400;
4141

4242
const invalidRepos: string[] = [];
4343
const mismatchedRepos: LibraryType[] = [];

scripts/check-resources.ts

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1-
import fetch from 'cross-fetch';
1+
import { fetch } from 'bun';
2+
3+
import { LibraryDataEntryType } from '~/types';
24

35
import libraries from '../react-native-libraries.json';
46
import { sleep } from './helpers';
57

6-
console.log('⬇️ Attempting to fetch examples and images');
8+
async function runThrottledFetches(libraries: LibraryDataEntryType[], delayMs = 50) {
9+
const urlList: string[] = [];
710

8-
libraries.forEach(lib => {
9-
if (lib.examples) {
10-
lib.examples.forEach(async (example: string, index: number) => {
11-
await sleep(500);
12-
setTimeout(() => {
13-
fetch(example)
14-
.then(response => {
15-
if (response.status !== 200) {
16-
console.warn(`EXAMPLE: ${example} returned ${response.status}`);
17-
}
18-
})
19-
.catch(error => {
20-
console.warn(`EXAMPLE: errored! ${error}`);
21-
});
22-
}, 150 * index);
23-
});
11+
for (const lib of libraries) {
12+
if (lib.examples) {
13+
for (const exampleUrl of lib.examples) {
14+
urlList.push(exampleUrl);
15+
}
16+
}
17+
if (lib.images) {
18+
for (const imgUrl of lib.images) {
19+
urlList.push(imgUrl);
20+
}
21+
}
2422
}
2523

26-
if (lib.images) {
27-
lib.images.forEach(async (img: string, index: number) => {
28-
await sleep(500);
29-
setTimeout(() => {
30-
fetch(img)
31-
.then(response => {
32-
if (response.status !== 200) {
33-
console.warn(`IMG: ${img} returned ${response.status}`);
34-
}
35-
})
36-
.catch(error => {
37-
console.warn(`IMG: errored! ${error}`);
38-
});
39-
}, 150 * index);
40-
});
24+
console.log(`⬇️ Attempting to fetch examples and images (${urlList.length} URLs)`);
25+
26+
for (const url of urlList) {
27+
try {
28+
const response = await fetch(url);
29+
if (response.status !== 200) {
30+
console.warn(`${url} returned ${response.status}`);
31+
}
32+
} catch (err: any) {
33+
console.warn(`${url} errored!`, err);
34+
}
35+
await sleep(delayMs);
4136
}
37+
}
38+
39+
runThrottledFetches(libraries).catch(err => {
40+
console.error('❌ Unexpected error in throttled fetcher:', err);
4241
});

scripts/fetch-github-data.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ import { config } from 'dotenv';
22

33
import { LibraryType } from '~/types';
44
import hasNativeCode from '~/util/hasNativeCode';
5+
import { parseGitHubUrl } from '~/util/parseGitHubUrl';
56

6-
import {
7-
processTopics,
8-
sleep,
9-
REQUEST_SLEEP,
10-
makeGraphqlQuery,
11-
parseGitHubUrl,
12-
getUpdatedUrl,
13-
} from './helpers';
7+
import { processTopics, sleep, REQUEST_SLEEP, makeGraphqlQuery, getUpdatedUrl } from './helpers';
148
import GitHubLicensesQuery from './queries/GitHubLicensesQuery';
159
import GitHubRepositoryQuery from './queries/GitHubRepositoryQuery';
1610

scripts/fetch-npm-download-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fetch from 'cross-fetch';
1+
import { fetch } from 'bun';
22

33
import { LibraryType } from '~/types';
44

0 commit comments

Comments
 (0)