Skip to content

fix: Ship compiled test mock entry point (fix TS under RN 0.87) - #771

Open
huntie wants to merge 1 commit into
Expensify:mainfrom
huntie:fix-mock-build-entry
Open

fix: Ship compiled test mock entry point (fix TS under RN 0.87)#771
huntie wants to merge 1 commit into
Expensify:mainfrom
huntie:fix-mock-build-entry

Conversation

@huntie

@huntie huntie commented Jul 30, 2026

Copy link
Copy Markdown

Details

Minimal fix for @expensify/react-native-live-markdown compatibility in React Native 0.87+ projects that wire up the test mock from a TypeScript setup file. See react-native-community/template#245.

Context

React Native 0.87 ships the Strict TypeScript API by default (moving to a user opt-out).

Typically, this change is scoped to the user's project (@react-native/typescript-config includes skipLibCheck: true) and does not reach library source code.

However, this library ships a Jest mock at @expensify/react-native-live-markdown/mock, which is an exception that crosses this boundary.

Problem

@expensify/react-native-live-markdown/mock resolved to raw mock/index.ts — no sibling .d.ts existed at that path — so it pulled this library's ../src/* into the scope of the user's TypeScript analysis instead of the compiled lib/ code. That produces a type error against deep imports such as react-native/Libraries/Types/CodegenTypes, which no longer resolve under the Strict TypeScript API (TS2307, see also AppAndFlow/react-native-safe-area-context#744). skipLibCheck does not contain it because it does not apply to .ts/.tsx.

This diff

Move the mock into the builder-bob build so consuming projects only ever see this library's .d.ts files, which are exempt from typechecking. Same fix as AppAndFlow/react-native-safe-area-context#745, independent of the deep-import cleanup in #744.

  • Move mock/index.ts to src/mock/index.ts so builder-bob compiles it like the rest of the library; repoint its imports from '../src' to '..'.
  • Preserve the @expensify/react-native-live-markdown/mock subpath via shims: mock/index.js re-exports ../lib/commonjs/mock/index.js, mock/index.d.ts re-exports ../lib/typescript/src/mock/index.
  • Drop mock/**/* from tsconfig include so the source is only picked up under src/, and lint-ignore mock/**/* since the shims point into build output.
  • ✅ Consuming projects now only see this library's .d.ts files, which are exempt from typechecking due to skipLibCheck: true.

No exports map is introduced — the package has none today, and shims are the conservative, non-breaking equivalent.

Related Issues

Manual Tests

  • yarn typecheck, yarn lint:root, and the Jest suite (153 tests) all pass.
  • yarn prepare (bob build) emits lib/commonjs/mock/index.js, lib/module/mock/index.js, and lib/typescript/src/mock/index.d.ts; the stale lib/typescript/mock/ is gone.
  • npm pack --dry-run confirms the three lib/**/mock outputs plus the mock/index.js / mock/index.d.ts shims ship, and mock/index.ts no longer appears at the public mock/ path.
  • Verified the emitted lib/commonjs/mock/index.js retains the module-scope global.jsi_* assignments and the 'worklet' directive.

Linked PRs

Minimal fix for `@expensify/react-native-live-markdown` compatibility in React Native 0.87+ projects that wire up the test mock from a TypeScript setup file. See react-native-community/template#245.

**Context**

React Native 0.87 ships the Strict TypeScript API by default (moving to a user opt-out).

Typically, this change is scoped to the user's project (`@react-native/typescript-config` includes `skipLibCheck: true`) and does not reach library source code.

However, this library ships a Jest mock at `@expensify/react-native-live-markdown/mock`, which is an exception that crosses this boundary.

**Problem**

`@expensify/react-native-live-markdown/mock` resolved to raw `mock/index.ts` — no sibling `.d.ts` existed at that path — so it pulled this library's `../src/*` into the scope of the user's TypeScript analysis instead of the compiled `lib/` code. That produces a type error against deep imports such as `react-native/Libraries/Types/CodegenTypes`, which no longer resolve under the Strict TypeScript API (`TS2307`). `skipLibCheck` does not contain it because it does not apply to `.ts`/`.tsx`.

**This diff**

Move the mock into the builder-bob build so consuming projects only ever see this library's `.d.ts` files, which are exempt from typechecking.

- Move `mock/index.ts` to `src/mock/index.ts` so builder-bob compiles it like the rest of the library; repoint its imports from `'../src'` to `'..'`.
- Preserve the `@expensify/react-native-live-markdown/mock` subpath via shims: `mock/index.js` re-exports `../lib/commonjs/mock/index.js`, `mock/index.d.ts` re-exports `../lib/typescript/src/mock/index`.
- Drop `mock/**/*` from tsconfig `include` so the source is only picked up under `src/`, and lint-ignore `mock/**/*` since the shims point into build output.

No `exports` map is introduced — the package has none today, and shims are the conservative, non-breaking equivalent.

Changelog: [Fixed] - Ship a compiled `/mock` entry point so consumers resolve declarations instead of raw source
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@huntie
huntie marked this pull request as ready for review July 30, 2026 16:40
@huntie

huntie commented Jul 30, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

exfy-clabot Bot added a commit to Expensify/CLA that referenced this pull request Jul 30, 2026
@tomekzaw
tomekzaw requested a review from war-in July 30, 2026 16:41
@huntie huntie changed the title fix: Ship compiled test mock entry point fix: Ship compiled test mock entry point (fix TS under RN 0.87) Jul 30, 2026
Comment thread mock/index.js
@@ -0,0 +1 @@
module.exports = require('../lib/commonjs/mock/index.js');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shims prevent this from being a breaking change. Also achievable by introducing a package.json "exports" field.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant