diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4cc2948a..67f6e793 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,10 @@ on: push: branches: [main] pull_request: + # Weekly, so a new major of a peer that the README installs unpinned fails + # here before a customer's install does. + schedule: + - cron: '17 13 * * 1' # A newer commit on the same PR cancels the older run; each push to main keeps # its own run. @@ -36,3 +40,18 @@ jobs: - run: npm test -- --ci # scripts/validate-ios.sh compiles the native module inside a local Expo # app; it stays a manual pre-release step. + + install-lines: + # The README install lines, resolved with npm's strict peer rules against + # today's published versions. `test` above installs with + # --legacy-peer-deps and so cannot see a peer conflict. Lockfile only: no + # node_modules, no app build. + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 22 + - name: README install lines resolve without peer conflicts + run: node scripts/check-install-lines.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index d1b11bb4..531752f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ Minor version. Read the install change below before upgrading. ### Changed - `uuid` is now `^11.1.1` (was `^10.0.0`). This clears the one production advisory. The SDK only uses `v4()`; ids keep the same format. `@types/uuid` is gone, since uuid 11 ships its own types. -- The Expo modules the SDK loads are now declared as optional peer dependencies: `expo-application`, `expo-device`, `expo-network`, `expo-router`, `expo` and `@expo/config-plugins` (Expo SDK 52 or later, the same floor as `expo-modules-core`). Your package manager now warns about a version it cannot work with. Nothing is installed for you. The unused `expo-tracking-transparency` entry is removed. +- The Expo modules the SDK loads are now declared as optional peer dependencies: `expo-application`, `expo-device`, `expo-network`, `expo` and `@expo/config-plugins` (Expo SDK 52 or later, the same floor as `expo-modules-core`). Your package manager now warns about a version it cannot work with. Nothing is installed for you. The unused `expo-tracking-transparency` entry is removed. `expo-router` is not declared: npm checks an optional peer against its newest version even when it is not installed, and expo-router's own peers then conflict with an older Expo SDK (`ERESOLVE`). The SDK loads it only when you use the Expo Router screen-tracking hook. - `debug: true` now turns on the SDK's debug logs in a release build. Before, they printed only in a development build (`__DEV__`) and the option did nothing else. - SKAdNetwork and AdAttributionKit success messages, and failed Apple Search Ads, advertiser-info and Play Install Referrer lookups in the native bridge, now log only when debug logging is on (`__DEV__` or `debug: true`). Warnings for a missing native module and failed SKAdNetwork updates are unchanged. - iOS: `setPostbackEnvironment` no longer writes an `NSLog` line; the JS side logs the result when debug logging is on. @@ -41,12 +41,16 @@ Minor version. Read the install change below before upgrading. - When a flush stops on a temporary failure, the events it already delivered are removed from disk at once. ### Install change -- `@react-native-async-storage/async-storage` (1.17 or later, or 2.x) and `react-native-get-random-values` are now peer dependencies, not dependencies. Install them in your app: - - Bare React Native: `npm install @datalyr/react-native expo-modules-core @react-native-async-storage/async-storage@^2 react-native-get-random-values` (pin `@^2`: an unpinned install takes 3.x, which is outside the peer range) +- `@react-native-async-storage/async-storage` (1.17 or later, or 2.x) and `react-native-get-random-values` (1.11 or later, or 2.x) are now peer dependencies, not dependencies. Install them in your app: + - Bare React Native: `npx install-expo-modules@latest`, then `npx expo install @datalyr/react-native expo-modules-core @react-native-async-storage/async-storage react-native-get-random-values`, then `cd ios && pod install`. Run `install-expo-modules` first: it adds the Expo SDK that matches your React Native, and `npx expo install` then picks versions for it. A plain `npm install` takes the newest `expo-modules-core` (and AsyncStorage 3.x), which an older Expo SDK cannot use. - Expo: `npx expo install @datalyr/react-native expo-application expo-device expo-network @react-native-async-storage/async-storage react-native-get-random-values` Both are native modules. React Native CLI autolinking links only the packages listed in the app's own `package.json`, and Expo before SDK 54 does the same, so as nested dependencies they could load without their native code. An app that already lists both needs no change. AsyncStorage 3.x is not supported yet (it renames `multiRemove` to `removeMany`). + `react-native-get-random-values` 2.x works only on React Native 0.81 or later with the New Architecture on (Expo SDK 54 or later with it on). On an older React Native, or with the New Architecture off, install `react-native-get-random-values@^1`. On React Native older than 0.81, npm refuses 2.x (`ERESOLVE`); with the New Architecture off, 2.x installs without a warning, but its iOS native module is registered only for the New Architecture, so the SDK fails at start and sends no events. `npx expo install` picks the version your Expo SDK expects (1.11 for Expo SDK 52 to 57, 2.x for SDK 58). + + Bare apps on Expo SDK 53 or 54 (React Native 0.78 to 0.81): `install-expo-modules` does not add `bindReactNativeFactory(factory)` to `AppDelegate.swift`, and the app crashes at start without it. Add it after `reactNativeFactory = factory` (Expo's manual installation steps show it). + ## [1.8.0] - 2026-10-30 diff --git a/README.md b/README.md index c77b09e2..4cbd1bd9 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,14 @@ Use the option that matches your app. **Bare React Native:** ```bash -npm install @datalyr/react-native expo-modules-core @react-native-async-storage/async-storage@^2 react-native-get-random-values npx install-expo-modules@latest +npx expo install @datalyr/react-native expo-modules-core @react-native-async-storage/async-storage react-native-get-random-values cd ios && pod install ``` -The SDK is built on Expo Modules. You must install `expo-modules-core` in a bare app too. AsyncStorage and `react-native-get-random-values` are native modules: React Native links only the packages your app lists, so install them in your app. +The SDK is built on Expo Modules. `install-expo-modules` adds the Expo SDK that matches your React Native version; run it first, so that `npx expo install` then picks versions for that Expo SDK. Do not use a plain `npm install` for these packages: it takes the newest `expo-modules-core`, which does not match an older Expo SDK, and `pod install` fails. AsyncStorage and `react-native-get-random-values` are native modules: React Native links only the packages your app lists, so install them in your app. + +On Expo SDK 53 or 54 (React Native 0.78 to 0.81), check that `AppDelegate.swift` calls `bindReactNativeFactory(factory)` after `reactNativeFactory = factory`. `install-expo-modules` does not add it, and without it the app crashes at start (`Missing factory in ExpoAppDelegate`). See Expo's [manual installation steps](https://docs.expo.dev/bare/installing-expo-modules/). **Expo:** @@ -39,6 +41,8 @@ The SDK is built on Expo Modules. You must install `expo-modules-core` in a bare npx expo install @datalyr/react-native expo-application expo-device expo-network @react-native-async-storage/async-storage react-native-get-random-values ``` +`npx expo install` picks the versions your Expo SDK expects, in both options above. If you add `react-native-get-random-values` another way, use 2.x only on React Native 0.81 or later (Expo SDK 54 or later) with the New Architecture on; otherwise install `react-native-get-random-values@^1`. On React Native older than 0.81, npm refuses 2.x (`ERESOLVE`). With the New Architecture off, 2.x installs without a warning, but its iOS native module is registered only for the New Architecture, so the SDK fails at start and sends no events. + Add the config plugin to `app.json`: ```json diff --git a/package.json b/package.json index 2b524ac2..978f05c0 100644 --- a/package.json +++ b/package.json @@ -63,11 +63,10 @@ "expo-device": ">=7.0.0", "expo-modules-core": ">=2.0.0", "expo-network": ">=7.0.0", - "expo-router": ">=4.0.0", "react": ">=18.0.0", "react-native": ">=0.72.0", "react-native-device-info": ">=12.0.0", - "react-native-get-random-values": "^1.8.0" + "react-native-get-random-values": "^1.11.0 || ^2.0.0" }, "dependencies": { "uuid": "^11.1.1" @@ -135,9 +134,6 @@ }, "@react-native-community/netinfo": { "optional": true - }, - "expo-router": { - "optional": true } } } diff --git a/scripts/check-install-lines.mjs b/scripts/check-install-lines.mjs new file mode 100644 index 00000000..a52ba833 --- /dev/null +++ b/scripts/check-install-lines.mjs @@ -0,0 +1,222 @@ +#!/usr/bin/env node +// Checks that the README install steps resolve with npm's strict peer rules +// (no --legacy-peer-deps), against today's published versions, in throwaway +// lockfile-only apps. The packed SDK stands in for @datalyr/react-native. +// +// - Bare: an app with the react-native (and react) that an Expo SDK bundles; +// then that Expo SDK's `expo` package, which is what +// `npx install-expo-modules` adds for that React Native; then the README's +// bare `npx expo install` line, each package at the version that expo's +// bundledNativeModules.json names (what `expo install` picks), or latest +// when it names none. Run for the newest Expo SDK, SDK 54 (React Native +// 0.81) and SDK 52 (React Native 0.76, the oldest the SDK supports). +// - Expo: an app with that Expo SDK's expo, react and react-native, then the +// README's Expo line the same way. Newest SDK and SDK 52. +// - The README's react-native-get-random-values@^1 advice, on Expo SDK 54. +// +// Each case fails on ERESOLVE (error or "overriding peer dependency"), on an +// invalid or missing package in `npm ls`, or on a second copy of +// expo-modules-core (an app copy that does not match its Expo SDK; pod +// install then fails). It logs the resolved versions. +// +// Not covered (needs a real app build): what install-expo-modules writes into +// the native projects, CocoaPods resolution in `pod install`, Gradle, and +// autolinking. Only a lockfile is written: nothing beyond package metadata is +// downloaded and no app is built. +// +// Usage: node scripts/check-install-lines.mjs +// INSTALL_CHECK_DIR sets the scratch directory (default: a new temp dir). + +import { execFileSync, spawnSync } from 'node:child_process'; +import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join, resolve } from 'node:path'; + +const repoRoot = resolve(import.meta.dirname, '..'); +const readme = readFileSync(join(repoRoot, 'README.md'), 'utf8').split('\n'); + +const INSTALL = 'npx expo install'; +const bareStart = readme.indexOf('**Bare React Native:**'); +const expoStart = readme.indexOf('**Expo:**'); +if (bareStart < 0 || expoStart < bareStart) { + console.error('README: could not find the Bare React Native and Expo sections'); + process.exit(1); +} +const bareSection = readme.slice(bareStart, expoStart); +const expoSection = readme.slice(expoStart); +const isInstallLine = (line) => line.startsWith(`${INSTALL} @datalyr/react-native `); +const bareLine = bareSection.find(isInstallLine); +const expoLine = expoSection.find(isInstallLine); +const addExpoAt = bareSection.findIndex((line) => line.startsWith('npx install-expo-modules')); +if (!bareLine || !expoLine) { + console.error(`README: could not find a "${INSTALL} @datalyr/react-native" line in both sections`); + process.exit(1); +} +if (addExpoAt < 0 || addExpoAt > bareSection.indexOf(bareLine)) { + console.error('README: the bare steps must run npx install-expo-modules before npx expo install'); + process.exit(1); +} +const pinOne = readme.join('\n').match(/`(react-native-get-random-values@\^1)`/); +if (!pinOne) { + console.error('README: could not find the react-native-get-random-values@^1 advice'); + process.exit(1); +} + +const base = process.env.INSTALL_CHECK_DIR + ? resolve(process.env.INSTALL_CHECK_DIR) + : mkdtempSync(join(tmpdir(), 'install-lines-')); +mkdirSync(base, { recursive: true }); + +function run(cmd, args, cwd) { + console.log(`$ (${cwd}) ${cmd} ${args.join(' ')}`); + return execFileSync(cmd, args, { cwd, stdio: ['ignore', 'pipe', 'inherit'], encoding: 'utf8' }); +} + +const npmFlags = ['--package-lock-only', '--no-audit', '--no-fund', '--ignore-scripts']; + +// npm either stops on a peer conflict (`npm error ERESOLVE`) or, when the +// conflicting package is named in the same command, installs it anyway with +// `npm warn ERESOLVE overriding peer dependency`. Both are a broken install +// for a customer, so both fail here. +function npmInstall(args, cwd) { + console.log(`$ (${cwd}) npm install ${args.join(' ')}`); + const res = spawnSync('npm', ['install', ...npmFlags, ...args], { cwd, encoding: 'utf8' }); + const lines = `${res.stdout}\n${res.stderr}`.split('\n').filter((l) => !/npm warn deprecated/.test(l)); + console.log(lines.join('\n').trim()); + if (res.status !== 0) throw new Error(`npm install exited ${res.status}`); + if (lines.some((l) => l.includes('ERESOLVE'))) throw new Error('npm reported ERESOLVE (peer conflict)'); +} + +// Every dependency in the resulting lockfile must be valid, and there must be +// one expo-modules-core, the one the Expo SDK uses. +function checkTree(cwd) { + console.log(`$ (${cwd}) npm ls --all --package-lock-only`); + const res = spawnSync('npm', ['ls', '--all', '--package-lock-only'], { cwd, encoding: 'utf8' }); + const bad = `${res.stdout}\n${res.stderr}`.split('\n').filter((l) => /invalid|ERR|missing/.test(l)); + if (res.status !== 0 || bad.length) { + console.log(bad.join('\n')); + throw new Error('npm ls found an invalid or missing dependency'); + } + const lock = JSON.parse(readFileSync(join(cwd, 'package-lock.json'), 'utf8')); + const copies = Object.entries(lock.packages) + .filter(([path]) => path.endsWith('node_modules/expo-modules-core')) + .map(([path, meta]) => `${path}@${meta.version}`); + if (copies.length !== 1) { + console.log(copies.join('\n')); + throw new Error(`expected one expo-modules-core, found ${copies.length}`); + } +} + +// The versions the lockfile resolved, so the log shows what was checked. +function logResolved(dir) { + const lock = JSON.parse(readFileSync(join(dir, 'package-lock.json'), 'utf8')); + const names = [ + 'react-native', + 'expo', + 'expo-modules-core', + '@react-native-async-storage/async-storage', + 'react-native-get-random-values', + ]; + const found = names + .map((name) => [name, lock.packages[`node_modules/${name}`]?.version]) + .filter(([, version]) => version) + .map(([name, version]) => `${name}@${version}`); + console.log(`RESOLVED: ${found.join(' ')}`); +} + +// Pack the SDK as a customer receives it. +const packDir = join(base, 'pack'); +mkdirSync(packDir, { recursive: true }); +const packed = JSON.parse(run('npm', ['pack', '--json', '--ignore-scripts', '--pack-destination', packDir], repoRoot)); +const tarball = join(packDir, packed[0].filename); + +const packagesOf = (line) => line.slice(INSTALL.length).trim().split(/\s+/).filter((w) => w && !w.startsWith('-')); +const nameOf = (spec) => spec.replace(/(.)@[^/]*$/, '$1'); + +function newApp(name) { + const dir = join(base, name.replace(/[^\w.-]/g, '_')); + mkdirSync(dir, { recursive: true }); + writeFileSync(join(dir, 'package.json'), JSON.stringify({ name: 'app', version: '0.0.0', private: true }, null, 2)); + return dir; +} + +let failed = false; +function scenario(title, fn) { + console.log(`\n=== ${title} ===`); + try { + fn(); + console.log(`PASS: ${title}`); + } catch (err) { + failed = true; + console.error(`FAIL: ${title} (${err.message.split('\n')[0]})`); + } +} + +// expo's bundledNativeModules.json is a file in the package, not in its +// registry metadata: read that one file from a package CDN. +function fetchBundled(version) { + const urls = [ + `https://cdn.jsdelivr.net/npm/expo@${version}/bundledNativeModules.json`, + `https://unpkg.com/expo@${version}/bundledNativeModules.json`, + ]; + for (const url of urls) { + try { + return JSON.parse(execFileSync('curl', ['-fsSL', '--retry', '2', url], { encoding: 'utf8' })); + } catch { + console.log(`could not read ${url}`); + } + } + throw new Error(`could not read bundledNativeModules.json for expo@${version}`); +} + +function expoSdk(range, dir) { + const versions = JSON.parse(run('npm', ['view', `expo@${range}`, 'version', '--json'], dir)); + const version = Array.isArray(versions) ? versions[versions.length - 1] : versions; + const bundled = fetchBundled(version); + // `expo install` passes the bundled version, or the bare name when expo + // names none (npm then takes the latest). + const pin = (name) => (bundled[name] ? `${name}@${bundled[name]}` : name); + return { version, pin }; +} + +function installLine(line, dir, pin, replace = {}) { + const args = packagesOf(line).map((spec) => + spec === '@datalyr/react-native' ? tarball : (replace[nameOf(spec)] ?? pin(nameOf(spec))), + ); + console.log(`expo install picks: ${args.filter((a) => a !== tarball).join(' ')}`); + npmInstall(args, dir); + checkTree(dir); + logResolved(dir); +} + +function bareScenario(range) { + scenario(`bare README steps on the React Native of expo@${range}`, () => { + const dir = newApp(`bare-${range}`); + const { version, pin } = expoSdk(range, dir); + // The bare app as the customer has it. + npmInstall([pin('react-native'), pin('react')], dir); + // npx install-expo-modules: adds the expo package for that React Native. + npmInstall([`expo@${version}`], dir); + installLine(bareLine, dir, pin); + }); +} + +function expoScenario(range, replace = {}, label = '') { + scenario(`Expo README line on expo@${range}${label}`, () => { + const dir = newApp(`expo-${range}${label}`); + const { version, pin } = expoSdk(range, dir); + npmInstall([`expo@${version}`, pin('react'), pin('react-native')], dir); + installLine(expoLine, dir, pin, replace); + }); +} + +bareScenario('latest'); +bareScenario('^54.0.0'); +bareScenario('^52.0.0'); +expoScenario('latest'); +expoScenario('^52.0.0'); +// The README's advice for the New Architecture off (React Native 0.81 can +// still turn it off): the Expo line with react-native-get-random-values@^1. +expoScenario('^54.0.0', { 'react-native-get-random-values': pinOne[1] }, ` with ${pinOne[1]}`); + +process.exit(failed ? 1 : 0); diff --git a/tests/dependency-declarations.test.ts b/tests/dependency-declarations.test.ts index 04d57bce..a48e2e8b 100644 --- a/tests/dependency-declarations.test.ts +++ b/tests/dependency-declarations.test.ts @@ -35,17 +35,26 @@ describe('W6 — uuid', () => { describe('W6 — optional Expo peers', () => { // src/utils-expo.ts imports these three statically (the Expo entry); - // src/expo.ts requires expo-router lazily; app.plugin.js requires - // expo/config-plugins, falling back to @expo/config-plugins. + // app.plugin.js requires expo/config-plugins, falling back to + // @expo/config-plugins. const expoPeers = [ 'expo-application', 'expo-device', 'expo-network', - 'expo-router', 'expo', '@expo/config-plugins', ]; + test('expo-router is not a peer (an optional peer still makes npm check the newest expo-router)', () => { + // npm resolves an optional peer that is not installed against its newest + // version: expo-router 58 wants expo-constants 58, and a bare app on Expo + // SDK 54 then fails `npx expo install @datalyr/react-native` with ERESOLVE. + // src/expo.ts requires expo-router only when the app calls + // useDatalyrScreenTracking, so only apps that have it load it. + expect(pkg.peerDependencies['expo-router']).toBeUndefined(); + expect(pkg.peerDependenciesMeta['expo-router']).toBeUndefined(); + }); + test.each(expoPeers)('%s is an optional peer dependency', (name) => { expect(typeof pkg.peerDependencies[name]).toBe('string'); expect(pkg.peerDependenciesMeta[name]).toEqual({ optional: true }); @@ -93,6 +102,14 @@ describe('W6 — native modules the app must list itself', () => { expect(pkg.peerDependencies['@react-native-async-storage/async-storage']).toBe('^1.17.0 || ^2.0.0'); }); + test('get-random-values peer range is 1.11+ or 2.x (the unpinned README lines take 2.x)', () => { + // 2.x needs React Native 0.81+ with the New Architecture; 1.11 is the first + // 1.x with bridgeless support, and Expo SDK 52-57 bundle ~1.11.0. The SDK + // only imports it for its crypto.getRandomValues polyfill, which 1.x and + // 2.x install the same way. + expect(pkg.peerDependencies['react-native-get-random-values']).toBe('^1.11.0 || ^2.0.0'); + }); + test.each(nativeModules)('the README install lines name %s', (name) => { const readme = readFileSync(join(repoRoot, 'README.md'), 'utf8'); const installLines = readme @@ -105,9 +122,21 @@ describe('W6 — native modules the app must list itself', () => { } }); - test('the bare install line pins AsyncStorage to 2.x (latest is 3.x, outside the peer range)', () => { + test('the bare steps add the matching Expo SDK first, then install with expo install (SDK-matched versions)', () => { + // A plain npm install takes the newest expo-modules-core (pod install then + // fails on an older Expo SDK) and AsyncStorage 3.x (outside the peer range). const readme = readFileSync(join(repoRoot, 'README.md'), 'utf8'); - const bare = readme.split('\n').find((line) => line.startsWith('npm install @datalyr/react-native')); - expect(bare?.split(' ')).toContain('@react-native-async-storage/async-storage@^2'); + const lines = readme.split('\n'); + const bareStart = lines.indexOf('**Bare React Native:**'); + const expoStart = lines.indexOf('**Expo:**'); + expect(bareStart).toBeGreaterThan(-1); + expect(expoStart).toBeGreaterThan(bareStart); + const bare = lines.slice(bareStart, expoStart); + const addExpo = bare.indexOf('npx install-expo-modules@latest'); + const install = bare.findIndex((line) => line.startsWith('npx expo install @datalyr/react-native ')); + expect(addExpo).toBeGreaterThan(-1); + expect(install).toBeGreaterThan(addExpo); + expect(bare[install].split(' ')).toContain('expo-modules-core'); + expect(lines.some((line) => /^(npm install|yarn add|pnpm add) .*@datalyr\/react-native/.test(line))).toBe(false); }); });