|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | +const { execSync } = require('child_process'); |
| 4 | + |
| 5 | +function resolveNpmVersion(pkgName, versionRange) { |
| 6 | + const spec = `${pkgName}@${versionRange}`; |
| 7 | + try { |
| 8 | + const rawOutput = execSync(`npm view "${spec}" version --json`, { |
| 9 | + encoding: 'utf8', |
| 10 | + stdio: ['ignore', 'pipe', 'pipe'], |
| 11 | + }).trim(); |
| 12 | + |
| 13 | + if (!rawOutput) { |
| 14 | + return null; |
| 15 | + } |
| 16 | + |
| 17 | + const parsed = JSON.parse(rawOutput); |
| 18 | + if (Array.isArray(parsed)) { |
| 19 | + return parsed[parsed.length - 1]; |
| 20 | + } |
| 21 | + |
| 22 | + return parsed; |
| 23 | + } catch { |
| 24 | + return null; |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +function toRange(version) { |
| 29 | + return version.includes('x') ? version : `${version}.x`; |
| 30 | +} |
| 31 | + |
| 32 | +const compatibilityPath = path.join( |
| 33 | + __dirname, |
| 34 | + '..', |
| 35 | + '..', |
| 36 | + '..', |
| 37 | + 'packages', |
| 38 | + 'react-native-reanimated', |
| 39 | + 'compatibility.json' |
| 40 | +); |
| 41 | + |
| 42 | +const workletsCompatibilityPath = path.join( |
| 43 | + __dirname, |
| 44 | + '..', |
| 45 | + '..', |
| 46 | + '..', |
| 47 | + 'packages', |
| 48 | + 'react-native-worklets', |
| 49 | + 'compatibility.json' |
| 50 | +); |
| 51 | + |
| 52 | +const compatibilityData = JSON.parse( |
| 53 | + fs.readFileSync(compatibilityPath, 'utf8') |
| 54 | +); |
| 55 | +const workletsCompatibilityData = JSON.parse( |
| 56 | + fs.readFileSync(workletsCompatibilityPath, 'utf8') |
| 57 | +); |
| 58 | + |
| 59 | +const fabricCompatibility = compatibilityData.fabric; |
| 60 | +const matrixEntries = []; |
| 61 | + |
| 62 | +for (const [reanimatedRange, details] of Object.entries(fabricCompatibility)) { |
| 63 | + if (reanimatedRange === 'nightly') { |
| 64 | + continue; |
| 65 | + } |
| 66 | + |
| 67 | + const workletsRanges = details['react-native-worklets']; |
| 68 | + const reactNativeVersions = details['react-native'] || []; |
| 69 | + |
| 70 | + if (!Array.isArray(workletsRanges) || workletsRanges.length === 0) { |
| 71 | + continue; |
| 72 | + } |
| 73 | + |
| 74 | + if (reactNativeVersions.length === 0) { |
| 75 | + continue; |
| 76 | + } |
| 77 | + |
| 78 | + const reanimatedNpmRange = toRange(reanimatedRange); |
| 79 | + const resolvedReanimatedVersion = resolveNpmVersion( |
| 80 | + 'react-native-reanimated', |
| 81 | + reanimatedNpmRange |
| 82 | + ); |
| 83 | + |
| 84 | + if (!resolvedReanimatedVersion) { |
| 85 | + continue; |
| 86 | + } |
| 87 | + |
| 88 | + for (const workletsRange of workletsRanges) { |
| 89 | + const workletsDetails = workletsCompatibilityData[workletsRange]; |
| 90 | + const workletsReactNativeVersions = workletsDetails?.['react-native'] || []; |
| 91 | + |
| 92 | + if (workletsReactNativeVersions.length === 0) { |
| 93 | + continue; |
| 94 | + } |
| 95 | + |
| 96 | + const commonReactNativeVersions = reactNativeVersions.filter((version) => |
| 97 | + workletsReactNativeVersions.includes(version) |
| 98 | + ); |
| 99 | + |
| 100 | + if (commonReactNativeVersions.length === 0) { |
| 101 | + continue; |
| 102 | + } |
| 103 | + |
| 104 | + const workletsNpmRange = toRange(workletsRange); |
| 105 | + const resolvedWorkletsVersion = resolveNpmVersion( |
| 106 | + 'react-native-worklets', |
| 107 | + workletsNpmRange |
| 108 | + ); |
| 109 | + |
| 110 | + if (!resolvedWorkletsVersion) { |
| 111 | + continue; |
| 112 | + } |
| 113 | + |
| 114 | + for (const rnMinor of commonReactNativeVersions) { |
| 115 | + const reactNativeRange = toRange(rnMinor); |
| 116 | + const resolvedReactNativeVersion = resolveNpmVersion( |
| 117 | + 'react-native', |
| 118 | + reactNativeRange |
| 119 | + ); |
| 120 | + |
| 121 | + if (!resolvedReactNativeVersion) { |
| 122 | + continue; |
| 123 | + } |
| 124 | + |
| 125 | + matrixEntries.push({ |
| 126 | + reactNativeVersion: resolvedReactNativeVersion, |
| 127 | + reanimatedVersion: resolvedReanimatedVersion, |
| 128 | + workletsVersion: resolvedWorkletsVersion, |
| 129 | + }); |
| 130 | + } |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +const uniqueEntries = new Map(); |
| 135 | +for (const entry of matrixEntries) { |
| 136 | + const key = `${entry.reactNativeVersion}-${entry.reanimatedVersion}-${entry.workletsVersion}`; |
| 137 | + uniqueEntries.set(key, entry); |
| 138 | +} |
| 139 | + |
| 140 | +const matrix = Array.from(uniqueEntries.values()); |
| 141 | + |
| 142 | +fs.writeFileSync( |
| 143 | + '/tmp/reanimated-worklets-matrix.json', |
| 144 | + JSON.stringify(matrix) |
| 145 | +); |
0 commit comments