Skip to content

Commit 70957aa

Browse files
fix(constants): inline LIB_VERSION via codegen to fix compiled output (#1139)
## Description `src/constants/resourceFetcher.ts` reads the library version with a runtime `require('../../package.json').version`. That path resolves correctly from `src/constants/`, but `react-native-builder-bob` emits the file at `lib/module/constants/` — one level deeper — and babel leaves the relative `require` literal unchanged. From the compiled location it points at a non-existent `lib/package.json`, so any consumer that resolves via `main`/`module` (web, Node) fails to bundle. iOS/Android Metro is unaffected because the package's `"react-native": "src/index"` entry reads source directly. Replace the JSON `require` with a literal `LIB_VERSION` in `constants/versions.ts`, derive the current-release tag from it, and re-export `LIB_VERSION` from `resourceFetcher.ts` for existing callers. While here, rename the version constants to match what they actually mean at the call site: `VERSION_TAG` is now the current release (derived from `LIB_VERSION`) and `PREVIOUS_VERSION_TAG` is the manual previous-release string — kept manual because the previous release isn't reliably derivable from `LIB_VERSION` across major bumps. All consumers in `src/constants` are updated; hosted URLs are unchanged. ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [x] Bug fix (change which fixes an issue) - [ ] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [ ] Other (chores, tests, code style improvements etc.) ### Tested on - [x] iOS - [x] Android ### Testing instructions 1. `yarn workspace react-native-executorch run prepare`. 2. Inspect `packages/react-native-executorch/lib/module/constants/resourceFetcher.js` — it should re-export `LIB_VERSION` from `./versions` with no `require('../../package.json')` left. 3. `yarn typecheck` passes — covers the rename across `versions.ts`, `modelUrls.ts`, `ocr/models.ts`, `tts/models.ts`, `tts/voices.ts`. 4. In a fresh Expo app with `react-native-web`, install the package from this branch and run `npx expo start --web` — the bundler no longer errors on the missing `lib/package.json`. 5. iOS/Android demo apps continue to build and report the expected version. Exercise a model pinned to `PREVIOUS_VERSION_TAG` (e.g. any Llama-3.2 / Qwen-3 / Whisper download) and one pinned to `VERSION_TAG` (e.g. Qwen-3.5, YOLO26-pose, distiluse multilingual, privacy-filter) — both should resolve to the same HuggingFace URLs as before the rename. ### Screenshots ### Related issues Fixes #1138. ### Checklist - [x] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings ### Additional notes `LIB_VERSION` is hardcoded next to the other version constants, so it must be bumped manually alongside `package.json#version` (same release step that already touches `PREVIOUS_VERSION_TAG`). `VERSION_TAG` is derived from `LIB_VERSION`, so it updates automatically. A codegen approach was considered but not adopted to keep the fix minimal. --------- Co-authored-by: Mateusz Słuszniak <mateusz.sluszniak@swmansion.com>
1 parent 51a4e91 commit 70957aa

6 files changed

Lines changed: 187 additions & 185 deletions

File tree

packages/react-native-executorch/src/constants/modelUrls.ts

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

packages/react-native-executorch/src/constants/ocr/models.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { alphabets, symbols } from './symbols';
22

3-
import { URL_PREFIX, VERSION_TAG } from '../versions';
3+
import { URL_PREFIX, PREVIOUS_VERSION_TAG } from '../versions';
44

5-
const DETECTOR_CRAFT_MODEL = `${URL_PREFIX}-detector-craft/${VERSION_TAG}/xnnpack_quantized/xnnpack_craft_quantized.pte`;
5+
const DETECTOR_CRAFT_MODEL = `${URL_PREFIX}-detector-craft/${PREVIOUS_VERSION_TAG}/xnnpack_quantized/xnnpack_craft_quantized.pte`;
66

77
const createHFRecognizerDownloadUrl = (alphabet: keyof typeof alphabets) =>
8-
`${URL_PREFIX}-recognizer-crnn.en/${VERSION_TAG}/xnnpack/${alphabet}/xnnpack_crnn_${alphabet}.pte`;
8+
`${URL_PREFIX}-recognizer-crnn.en/${PREVIOUS_VERSION_TAG}/xnnpack/${alphabet}/xnnpack_crnn_${alphabet}.pte`;
99

1010
const RECOGNIZER_ENGLISH_CRNN = createHFRecognizerDownloadUrl('english');
1111
const RECOGNIZER_LATIN_CRNN = createHFRecognizerDownloadUrl('latin');
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
export { LIB_VERSION } from './versions';
2+
13
export const DOWNLOAD_EVENT_ENDPOINT =
24
'https://ai.swmansion.com/telemetry/downloads/api/downloads';
3-
4-
export const LIB_VERSION: string = require('../../package.json').version;

packages/react-native-executorch/src/constants/tts/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { URL_PREFIX, VERSION_TAG } from '../versions';
1+
import { URL_PREFIX, PREVIOUS_VERSION_TAG } from '../versions';
22

33
// Text to speech (tts) - Kokoro model(s)
4-
const KOKORO_EN_MODELS_ROOT = `${URL_PREFIX}-kokoro/${VERSION_TAG}/xnnpack`;
4+
const KOKORO_EN_MODELS_ROOT = `${URL_PREFIX}-kokoro/${PREVIOUS_VERSION_TAG}/xnnpack`;
55
const KOKORO_EN_SMALL_MODELS_ROOT = `${KOKORO_EN_MODELS_ROOT}/small`;
66
const KOKORO_EN_MEDIUM_MODELS_ROOT = `${KOKORO_EN_MODELS_ROOT}/medium`;
77

packages/react-native-executorch/src/constants/tts/voices.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { KokoroVoiceExtras, VoiceConfig } from '../../types/tts';
2-
import { URL_PREFIX, VERSION_TAG } from '../versions';
2+
import { URL_PREFIX, PREVIOUS_VERSION_TAG } from '../versions';
33

44
// Kokoro voices - phonemizers
5-
const KOKORO_PHONEMIZER_PREFIX = `${URL_PREFIX}-kokoro/${VERSION_TAG}/phonemizer`;
5+
const KOKORO_PHONEMIZER_PREFIX = `${URL_PREFIX}-kokoro/${PREVIOUS_VERSION_TAG}/phonemizer`;
66
const KOKORO_PHONEMIZER_TAGGER_DATA = `${KOKORO_PHONEMIZER_PREFIX}/tags.json`;
77
const KOKORO_PHONEMIZER_LEXICON_EN_US_DATA = `${KOKORO_PHONEMIZER_PREFIX}/us_merged.json`;
88
const KOKORO_PHONEMIZER_LEXICON_EN_GB_DATA = `${KOKORO_PHONEMIZER_PREFIX}/gb_merged.json`;
@@ -17,7 +17,7 @@ const EN_GB_RESOURCES = {
1717
} as KokoroVoiceExtras;
1818

1919
// Kokoro voices
20-
const KOKORO_VOICE_PREFIX = `${URL_PREFIX}-kokoro/${VERSION_TAG}/voices`;
20+
const KOKORO_VOICE_PREFIX = `${URL_PREFIX}-kokoro/${PREVIOUS_VERSION_TAG}/voices`;
2121
/**
2222
* @category TTS Supported Voices
2323
*/
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
export const LIB_VERSION = '0.9.0';
2+
13
export const URL_PREFIX =
24
'https://huggingface.co/software-mansion/react-native-executorch';
3-
export const VERSION_TAG = 'resolve/v0.8.0';
4-
export const NEXT_VERSION_TAG = 'resolve/v0.9.0';
5+
export const PREVIOUS_VERSION_TAG = 'resolve/v0.8.0';
6+
export const VERSION_TAG = `resolve/v${LIB_VERSION}`;

0 commit comments

Comments
 (0)