diff --git a/packages/react-native-executorch/package.json b/packages/react-native-executorch/package.json index ac32b09d5f..ee1dd01197 100644 --- a/packages/react-native-executorch/package.json +++ b/packages/react-native-executorch/package.json @@ -37,7 +37,8 @@ "typecheck": "tsc --noEmit", "lint": "eslint \"**/*.{js,ts,tsx}\"", "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib", - "prepare": "bob build", + "prepare": "node scripts/sync-version.cjs && bob build", + "version": "node scripts/sync-version.cjs && git add src/constants/libVersion.ts", "prepack": "cp ../../README.md ./README.md", "postpack": "rm ./README.md" }, diff --git a/packages/react-native-executorch/scripts/sync-version.cjs b/packages/react-native-executorch/scripts/sync-version.cjs new file mode 100644 index 0000000000..a955c3da45 --- /dev/null +++ b/packages/react-native-executorch/scripts/sync-version.cjs @@ -0,0 +1,24 @@ +#!/usr/bin/env node +// Reads this package's package.json#version and writes it into +// src/constants/libVersion.ts as a literal export. We do this so the +// compiled output (lib/module/constants/libVersion.js) does not need +// a runtime require('../../package.json') — that path is correct from +// src/constants/ but wrong from lib/module/constants/ after bob's output +// nesting, and breaks any consumer that resolves through the "main"/ +// "module" fields instead of the "react-native" field (e.g. web/Node). + +const { readFileSync, writeFileSync } = require('node:fs'); +const { resolve } = require('node:path'); + +const pkgPath = resolve(__dirname, '..', 'package.json'); +const outPath = resolve(__dirname, '..', 'src', 'constants', 'libVersion.ts'); + +const { version } = JSON.parse(readFileSync(pkgPath, 'utf8')); + +const body = + '// AUTO-GENERATED by scripts/sync-version.cjs — do not edit by hand.\n' + + '// Source of truth: package.json#version.\n' + + `export const LIB_VERSION: string = '${version}';\n`; + +writeFileSync(outPath, body, 'utf8'); +console.log(`[sync-version] wrote ${outPath} (LIB_VERSION=${version})`); diff --git a/packages/react-native-executorch/src/constants/libVersion.ts b/packages/react-native-executorch/src/constants/libVersion.ts new file mode 100644 index 0000000000..d7ae51c1f9 --- /dev/null +++ b/packages/react-native-executorch/src/constants/libVersion.ts @@ -0,0 +1,3 @@ +// AUTO-GENERATED by scripts/sync-version.cjs — do not edit by hand. +// Source of truth: package.json#version. +export const LIB_VERSION: string = '0.9.0'; diff --git a/packages/react-native-executorch/src/constants/resourceFetcher.ts b/packages/react-native-executorch/src/constants/resourceFetcher.ts index ae6c5f1a3b..f825584473 100644 --- a/packages/react-native-executorch/src/constants/resourceFetcher.ts +++ b/packages/react-native-executorch/src/constants/resourceFetcher.ts @@ -1,4 +1,4 @@ export const DOWNLOAD_EVENT_ENDPOINT = 'https://ai.swmansion.com/telemetry/downloads/api/downloads'; -export const LIB_VERSION: string = require('../../package.json').version; +export { LIB_VERSION } from './libVersion';