Add [ReactNativeDirectory] supported platforms badge (#12066)

* add React Native Directory supported platforms badge

* tweak platforms order, replace mocked tests with live ones

* update platforms separator
This commit is contained in:
Bartosz Kaszubowski authored and GitHub committed 2026-08-02 18:45:58 +00:00
1 parent ec20a6a0b8
commit 91e87d8020
2 files changed
+110

No files matched your search

@@ -0,0 +1,90 @@
import Joi from 'joi'
import { BaseJsonService, NotFound, pathParams } from '../index.js'
import { packageNameDescription } from '../npm/npm-base.js'
const librarySchema = Joi.object({
ios: Joi.boolean(),
android: Joi.boolean(),
web: Joi.boolean(),
windows: Joi.boolean(),
macos: Joi.boolean(),
tvos: Joi.boolean(),
visionos: Joi.boolean(),
expoGo: Joi.boolean(),
fireos: Joi.boolean(),
harmony: Joi.alternatives().try(Joi.boolean(), Joi.string()),
horizon: Joi.boolean(),
vegaos: Joi.alternatives().try(Joi.boolean(), Joi.string()),
})
.unknown(true)
.required()
const schema = Joi.object().pattern(Joi.string(), librarySchema).required()
const platforms = {
android: 'Android',
ios: 'iOS',
web: 'Web',
macos: 'macOS',
tvos: 'tvOS',
visionos: 'visionOS',
windows: 'Windows',
expoGo: 'Expo Go',
fireos: 'Fire OS',
harmony: 'Harmony',
horizon: 'Horizon',
vegaos: 'VegaOS',
}
export default class ReactNativeDirectory extends BaseJsonService {
static category = 'platform-support'
static route = {
base: 'react-native-directory',
pattern: ':scope(@[^/]+)?/:packageName',
}
static openApi = {
'/react-native-directory/{packageName}': {
get: {
summary: 'React Native Directory Supported Platforms',
parameters: pathParams({
name: 'packageName',
example: 'react-native-reanimated',
description: packageNameDescription,
}),
},
},
}
static defaultBadgeData = { label: 'platforms' }
static render(library) {
const supportedPlatforms = Object.entries(platforms)
.filter(([key]) => library[key])
.map(([, name]) => name)
return {
message:
supportedPlatforms.length > 0 ? supportedPlatforms.join(' | ') : 'none',
}
}
async handle({ scope, packageName }) {
const name = scope ? `${scope}/${packageName}` : packageName
const response = await this._requestJson({
schema,
url: `https://reactnative.directory/api/library?name=${encodeURIComponent(
name,
)}`,
httpErrors: { 404: 'package not found' },
})
const library = response[name]
if (!library) {
throw new NotFound({ prettyMessage: 'package not found' })
}
return this.constructor.render(library)
}
}
@@ -0,0 +1,20 @@
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
t.create('supported platforms of react-native-reanimated')
.get('/react-native-reanimated.json')
.expectBadge({
label: 'platforms',
message:
'Android | iOS | Web | macOS | tvOS | visionOS | Expo Go | Fire OS | Harmony | VegaOS',
})
t.create('supported platforms of @react-native-menu/menu')
.get('/@react-native-menu/menu.json')
.expectBadge({ label: 'platforms', message: 'Android | iOS | visionOS' })
t.create('package not found').get('/not-a-package.json').expectBadge({
label: 'platforms',
message: 'package not found',
})