Skip to content

fix(constants): inline LIB_VERSION via codegen to fix compiled output#1139

Open
marnelram wants to merge 4 commits into
software-mansion:mainfrom
marnelram:fix/lib-version-codegen
Open

fix(constants): inline LIB_VERSION via codegen to fix compiled output#1139
marnelram wants to merge 4 commits into
software-mansion:mainfrom
marnelram:fix/lib-version-codegen

Conversation

@marnelram
Copy link
Copy Markdown

@marnelram marnelram commented May 11, 2026

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
  • No

Type of change

  • 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

  • iOS
  • 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

  • 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
  • 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.

@chmjkb chmjkb added the bug fix PRs that are fixing bugs label May 11, 2026
@chmjkb chmjkb requested a review from mkopcins May 11, 2026 08:04
@chmjkb
Copy link
Copy Markdown
Collaborator

chmjkb commented May 11, 2026

cc @mkopcins, i believe we can also use that new constant for the model urls to avoid duplicating

@msluszniak
Copy link
Copy Markdown
Member

cc @mkopcins, i believe we can also use that new constant for the model urls to avoid duplicating

Do you mean something like this one?

[packages/react-native-executorch/versions.json]

{ "previousVersionTag": "v0.8.0" }

[packages/react-native-executorch/scripts/sync-versions.cjs]

const fs = require('fs');
const path = require('path');

const pkg = require('../package.json');
const input = require('../versions.json');

const current = `v${pkg.version}`;
const previous = input.previousVersionTag;

const out = `// AUTO-GENERATED by scripts/sync-versions.cjs — do not edit by hand.
// Sources: package.json#version (current) + versions.json#previousVersionTag (previous).
export const URL_PREFIX =
  'https://huggingface.co/software-mansion/react-native-executorch';
export const VERSION_TAG = 'resolve/${previous}';
export const NEXT_VERSION_TAG = 'resolve/${current}';
export const LIB_VERSION = '${pkg.version}';
`;

const target = path.join(__dirname, '..', 'src', 'constants', 'versions.ts');
fs.writeFileSync(target, out);
console.log(`[sync-versions] LIB_VERSION=${pkg.version}, VERSION_TAG=${previous}, NEXT_VERSION_TAG=${current}`);

[packages/react-native-executorch/src/constants/versions.ts]

// AUTO-GENERATED by scripts/sync-versions.cjs — do not edit by hand.
export const URL_PREFIX =
  'https://huggingface.co/software-mansion/react-native-executorch';
export const VERSION_TAG = 'resolve/v0.8.0';
export const NEXT_VERSION_TAG = 'resolve/v0.9.0';
export const LIB_VERSION = '0.9.0';

[packages/react-native-executorch/src/constants/resourceFetcher.ts]

export const DOWNLOAD_EVENT_ENDPOINT =
  'https://ai.swmansion.com/telemetry/downloads/api/downloads';
export { LIB_VERSION } from './versions';

[packages/react-native-executorch/package.json]

"prepare": "node scripts/sync-versions.cjs && bob build",
"version": "node scripts/sync-versions.cjs && git add src/constants/versions.ts"

@msluszniak msluszniak self-assigned this May 12, 2026
@msluszniak
Copy link
Copy Markdown
Member

Ok, we eventually decided, that we will include this lib version in the already existing file. Then, we will be able to completely remove codegen part. Regardless, way need to change the version manually during release.

…urceFetcher

The runtime `require('../../package.json')` was broken in the compiled
`lib/module/constants/resourceFetcher.js` (path resolves to a non-existent
`lib/package.json`), so any consumer reading the package via `main`/`module`
(web, Node) fails to bundle.

Replace the require with a literal `LIB_VERSION` in `constants/versions.ts`,
recycled into `NEXT_VERSION_TAG`, and re-exported from `resourceFetcher.ts`
for existing callers.

`VERSION_TAG` stays a manual string — the previous release isn't reliably
derivable from `LIB_VERSION` across major bumps.

Fixes software-mansion#1138.
@msluszniak msluszniak force-pushed the fix/lib-version-codegen branch from 02e1f92 to afe9287 Compare May 12, 2026 14:38
@msluszniak
Copy link
Copy Markdown
Member

We decided on changing VERSION_TAG to PREVIOUS_VERSION_TAG and NEXT_VERSION_TAG to VERSION_TAG.

…ote NEXT_VERSION_TAG to VERSION_TAG

Reflect what each tag means at the call site: the manual previous-release
string is now PREVIOUS_VERSION_TAG, and VERSION_TAG is the current release
derived from LIB_VERSION. All consumers in src/constants are updated;
hosted URLs are unchanged.
software-mansion#1120 landed on main with NEXT_VERSION_TAG references; rename them to
VERSION_TAG to match the convention introduced in this PR.
@msluszniak
Copy link
Copy Markdown
Member

@marnelram Could you check if this changes works for you in the current shape?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix PRs that are fixing bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LIB_VERSION resolves to non-existent lib/package.json after bob build, breaks web/Node consumers

4 participants