Skip to content

Commit 04dd257

Browse files
hryhoriiK97cursoragenteszlamczyk
authored
refactor: download vendored assets at postinstall to reduce package size (#660)
* feat: download vendored assets at postinstall to reduce package size Move tree-sitter grammars (~169 MB) and RaTeX XCFramework (~47 MB) out of the npm tarball. A postinstall script downloads them from the npm registry and GitHub releases on the consumer's machine, reducing the published package from ~230 MB to a few MB. - Add postinstall.mjs as a thin wrapper that spawns vendor-grammars.mjs and vendor-ratex.mjs with consumer-mode flags (--from-npm, --vendor-dir, --manifest, --output) - Extend vendor-grammars.mjs with npm registry download support - Extend vendor-ratex.mjs with configurable manifest/output paths - Update prepack/postpack to strip heavy content and ship vendor scripts - Clean up dead repo/tag fields from grammar-versions.json Co-authored-by: Cursor <cursoragent@cursor.com> * docs: update documentation * chore: exclude ios/vendor from npm tarball via package.json files array --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Ernest <ernest.szlamczyk@swmansion.com>
1 parent bc90019 commit 04dd257

13 files changed

Lines changed: 536 additions & 146 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ We can help you build your next dream product –
4646

4747
- [Prerequisites](#prerequisites)
4848
- [Installation](#installation)
49+
- [Native assets (install-time download)](docs/NATIVE_ASSETS.md)
4950
- [EnrichedMarkdownText](#enrichedmarkdowntext-1)
5051
- [Usage](docs/TEXT.md#usage)
5152
- [Supported Markdown Elements](docs/TEXT.md#supported-markdown-elements)
@@ -120,6 +121,13 @@ yarn add react-native-enriched-markdown
120121
>
121122
> Nightly versions are published to npm automatically and may contain breaking changes.
122123
124+
> [!NOTE]
125+
> On install, a `postinstall` script downloads the large native assets used by code highlighting
126+
> and iOS LaTeX math (kept out of the npm tarball to keep it ~1 MB). This needs network access to
127+
> `registry.npmjs.org` and `github.com`. If you install offline, with `--ignore-scripts`, or with
128+
> **pnpm** (which blocks dependency scripts by default), see
129+
> [Native assets](docs/NATIVE_ASSETS.md) for how to restore them.
130+
123131
#### 2. Install iOS / macOS dependencies
124132
125133
The library includes native code so you will need to re-build the native app.
@@ -151,6 +159,10 @@ npx expo prebuild
151159
> [!NOTE]
152160
> The library won't work in Expo Go as it needs native changes.
153161
162+
> [!NOTE]
163+
> `npx expo install` runs the same `postinstall` asset download described under
164+
> [Native assets](docs/NATIVE_ASSETS.md); it needs network access and does not work with Yarn PnP.
165+
154166
> [!IMPORTANT]
155167
> **iOS: Save to Camera Roll**
156168
>

apps/react-native-example/ios/Podfile.lock

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,89 +2558,89 @@ EXTERNAL SOURCES:
25582558
SPEC CHECKSUMS:
25592559
EnrichedMarkdownCore: de5d43b832522f5bcb74ea6431e5d82b37c7ade8
25602560
FBLazyVector: b3e7ad108f0d882e30445c5527d774e3fd432f3d
2561-
hermes-engine: 1622a566d44d0dd4d377a1532e3ac82be7a0443c
2561+
hermes-engine: 4a0ceceb51f483aef72bfeb288e965aff6defa54
25622562
RCTDeprecation: 2a74a2c57675e64419bd89078efde81f7c1de90b
25632563
RCTRequired: 30451112e6fef4e6f31b4e7eee0845156e35e4b0
25642564
RCTSwiftUI: 5aaf0b07e747ba749dc6acc94d8bd41eea4b570f
2565-
RCTSwiftUIWrapper: 1feaf484029fd6294fe8bc401d28e1d803eca142
2565+
RCTSwiftUIWrapper: ab2ca548be15d63afa95103afc8685a7c3eab78b
25662566
RCTTypeSafety: 3eaed17dbddb0b989208b062ea14c44d412b9780
25672567
React: 2574546f2d017abd14d0c9b48cf2b6a0547c2591
25682568
React-callinvoker: 03cd4b931d1d583d87aae99b8f7b6fe26bf571ee
2569-
React-Core: b0a0038e05720fb8148759404e9c354e3e60043c
2570-
React-Core-prebuilt: 7da85c26e5616d52f119b81ce5e3e6fc5c9bda49
2571-
React-CoreModules: a1121b3182200be11e078940159c67ff95ee98b4
2572-
React-cxxreact: 8f74977959064bee99af63bb0ad95b6c3dbec921
2569+
React-Core: 1c824d9c7dd8aa760b5f1b50d5a54c2a3f598f87
2570+
React-Core-prebuilt: 13924a267683b3d6fa4bde9c80380becf83a9c5c
2571+
React-CoreModules: 2f9ed75bca7f6dea2b70e8a1f4a5ca9b6be52d76
2572+
React-cxxreact: 7103d5ba69848c039e11079e74ceede05efe795e
25732573
React-debug: 8cc8d99ccc664ef9e873027f7fc3fb0a50496012
2574-
React-defaultsnativemodule: 7c8182addbb79ec576c589186b51e3fb405da7da
2575-
React-domnativemodule: 576bd1e6ad81477997dcb556e6db1f005134356b
2576-
React-Fabric: 4cbd22315ddb9e33441437f851117d314d1b4ad3
2577-
React-FabricComponents: efe374aecaf1bbc2fb9a195ece4b50fd9f66bfa0
2578-
React-FabricImage: cfeffc0b527de8bc2dc5a50618dad119361d0ec3
2579-
React-featureflags: 98931b22f5f4b861a3985b75bd79c5fcbe4618ab
2580-
React-featureflagsnativemodule: 518c2e279cdb3835604f7e8fb15f4c2691336b4c
2581-
React-graphics: ac9ff09da733d98c0e5eddb589dc7f9f082c9531
2582-
React-hermes: bd1a14a982e63ee75e9c9cb8d11d3d4b5f330196
2583-
React-idlecallbacksnativemodule: b6378d3bca83d8284e1abaa51251ee1ce570d85a
2584-
React-ImageManager: 4936349da191d1bc29ed2bbaf5a2dd74bfdf5ed8
2585-
React-intersectionobservernativemodule: d9a6451f2aa1f1c989d5d5e0d967db2c07d0c48c
2586-
React-jserrorhandler: 2455567e21fcc036f96015b2b8eb4eb13e0d8d05
2587-
React-jsi: bf5ec8e7a7b26bddc39ab7f821af5aad8bb94a33
2588-
React-jsiexecutor: cf6c957f578dd491ec8ae516a39aff2cf7369f1a
2589-
React-jsinspector: 63e9b9f9a5b6c51bf38deea2b379a63754c0ab0d
2590-
React-jsinspectorcdp: 327082854cdebb1f500a669c51146b9fd871058c
2591-
React-jsinspectornetwork: bbc5c2e881252075d63dc679f18cd856c2def94e
2592-
React-jsinspectortracing: ea6ec857ead0de4e6bbb2e12ee48ae4381938874
2593-
React-jsitooling: 52e278666b35e856414d613d7dc50d1f0d50d9a5
2594-
React-jsitracing: 642172314677a1d1780b81f4e2e4a3f4d3ccf238
2595-
React-logger: 35cda3ab8977c6c4546e3cf6dc8f91bacec25934
2596-
React-Mapbuffer: c058c051f571589e37a29bce18d0e9b730faa9d0
2597-
React-microtasksnativemodule: 03752e60738a797bb49f4d6cb0291dfa398099b8
2598-
React-mutationobservernativemodule: 2e568e13c98bd185fe83266795233fa7ad2cbc19
2599-
react-native-safe-area-context: 650ba9c4c3ce2d68bbd7c450d08b7250c7b58623
2600-
react-native-slider: 8824cf332b11bf5149f6576c8c8b32b4f93f82ac
2601-
React-NativeModulesApple: a4713821c9caae40ae33eef933a6e692a6f4a81d
2602-
React-networking: b344a1a41a4729ef859123b7a234f3092761cb25
2574+
React-defaultsnativemodule: 603c108411d39d7bb5ccb8c270f1f50cb6207e10
2575+
React-domnativemodule: c49a502edc85f515a029c341fe5fba155fa6675c
2576+
React-Fabric: acc4915d719db793c5853e5c74b54ea5aa48e865
2577+
React-FabricComponents: aebebc98914a4a8fc962fa7b5b98ebaf250acb68
2578+
React-FabricImage: 42e99e48ff73c8b20cee229e622977d0b97b6247
2579+
React-featureflags: c6d8d8d52acf3a956485726076b73eeff7935340
2580+
React-featureflagsnativemodule: c992de92dcf30dcf09efdec17752abe4128ec55f
2581+
React-graphics: 239fd9b0512e539d3563f0825618f4e49795eefd
2582+
React-hermes: ae4685ca9fa5f47003bc594d3f146e29284136d1
2583+
React-idlecallbacksnativemodule: 10a5be842ab181953c772a3f28cdf94572833eb0
2584+
React-ImageManager: c36a56c3b13eba92e1d0d30da35d0a1ccf29cd6c
2585+
React-intersectionobservernativemodule: 71404bfa47d31e4143cc9db3e26178b5cfcd07e1
2586+
React-jserrorhandler: ca2eeb03c1a77bbfab1b5425b943e3e8d92295f2
2587+
React-jsi: c4b6daf8a31ac54f2db49cd6cce29720fec1f3a8
2588+
React-jsiexecutor: acdc1a217b7ea29bcf6315b770d01e6b1c2fca14
2589+
React-jsinspector: 95d6394efe9fb4a64ed33afc076b32a6384c8514
2590+
React-jsinspectorcdp: 6ce51378a552feaaaac1a7b0d995fa0c49fa4f8c
2591+
React-jsinspectornetwork: 0db435c9264f200635fdf294a3b643dd3946d4cf
2592+
React-jsinspectortracing: 2e4470e1f301ff597bd65299aa95da4bae6e5c4f
2593+
React-jsitooling: 796bc991cdce68e2cc059d0271a28e0d4f8b0891
2594+
React-jsitracing: f3008e7b5e1d9de8d9f2ca1b85824ed86b0cea00
2595+
React-logger: fff73f4ceecad968c97baafdc77dcf84befc38b6
2596+
React-Mapbuffer: ce449ccdf3b80384415b925606be8a4bdcfc65d3
2597+
React-microtasksnativemodule: 2eb3f49d0d8e77b5343455eccd057010b8d38b6b
2598+
React-mutationobservernativemodule: f0a0d5ae9b51caf7becbeabf836d716cfedb6bf2
2599+
react-native-safe-area-context: 58eeaba7cb5b8e03bfe91a655d995042f89a74df
2600+
react-native-slider: 08ecfc4e9cc16cc388a56dd9caeca51b55cd9bb7
2601+
React-NativeModulesApple: a092d89b58f635ebfab88048b0eda9fb516819fd
2602+
React-networking: 968bbbe73590149feb1e72b2af4f6a68e4796ece
26032603
React-oscompat: 0b72a7e926954a0415ccd83e0748b6561fe45367
2604-
React-perflogger: a0d581c6cc174e847877107ddac3f4fc9b518dc7
2605-
React-performancecdpmetrics: 91d3d0dce2e3a239ea68cc2882e75b11a61cbf2e
2606-
React-performancetimeline: 4b9e04002c1ddba95167276a86424e5face65605
2604+
React-perflogger: 865984e492514aa6e5279fc3e663132cfa4d5022
2605+
React-performancecdpmetrics: 2efbf9bdb48c8d8446f4dd10e8bf0dc5d711772f
2606+
React-performancetimeline: 9d256484bff1513481be9f234baba694dc3b52e2
26072607
React-RCTActionSheet: 902c79deec52f99cc48b1051b59bcbe86787d339
2608-
React-RCTAnimation: f50eac1c9dbea36c4abc69cb24e2da4364374055
2609-
React-RCTAppDelegate: a5d746fec869d15a8f6eecce60510c18e52135d5
2610-
React-RCTBlob: e544dc72edc6f277c67e85493b0a405e1993c250
2611-
React-RCTFabric: 8003ea99830c294857d41469a888b033e5ad91a6
2612-
React-RCTFBReactNativeSpec: 8a3506041284fdc75da90e6fa40fb9b575414a39
2613-
React-RCTImage: fb85496986a53d9e11a835124a083b7c7c33f898
2614-
React-RCTLinking: b8eafcdedaebf981a18396db61d1190f5279ea81
2615-
React-RCTNetwork: 03573c4fcc73e28f48fea7aea69310b6955a749c
2616-
React-RCTRuntime: 08d58920b217b2d7715d5da595794e63520cd2d9
2617-
React-RCTSettings: f9b278b46e5de1ff8b843bb7aefaee721f06572d
2618-
React-RCTText: 7266943febf3382dac8adce9ba0de95b90c26e9e
2619-
React-RCTVibration: 27e1952701ec858922062f25a59b0c48e7153151
2608+
React-RCTAnimation: 09cf722039ae30ff5d64e2b011ff054ae651c3b6
2609+
React-RCTAppDelegate: a47de6fddb7eb0c028abba83138a5ce283bd7e77
2610+
React-RCTBlob: 38c418d067e0c61818223503063310122e44c588
2611+
React-RCTFabric: 480ca2a105730e1790cfd13291d086cb53725825
2612+
React-RCTFBReactNativeSpec: 63131378510a5191515a4adfc308e65b465106f4
2613+
React-RCTImage: 3ce36f82441b76b715818ee7ee95f6f5b34f9ee1
2614+
React-RCTLinking: 2f7b5ed4983122e5115732d25a4360960eab583c
2615+
React-RCTNetwork: dcd3b180f33da86f5dc5e928a816eb5464fa7f16
2616+
React-RCTRuntime: 6ef8e778fbab426b12eb5a9b5f7a0e86313c5a10
2617+
React-RCTSettings: b97727ec8c55c35bd284457a647c938c040b942b
2618+
React-RCTText: 4d1b88f6d3e1a43afe46706d956ec6664c87b984
2619+
React-RCTVibration: 415d14d6a1a64bf947fcef6b193915a494431168
26202620
React-rendererconsistency: ef8519bdd9931261c6561bfad6506356b8108387
2621-
React-renderercss: edc1b0a18b12d681f8edbc779039dc6db32cf7b2
2622-
React-rendererdebug: 074ec3420f3bab2bea498da65e5a17e9288c90d0
2623-
React-RuntimeApple: 180682587e82ae4fc525f7d6636ed5db39c1e78c
2624-
React-RuntimeCore: 991cdb27072f7885750fdad4a70c2b919533e4ef
2625-
React-runtimeexecutor: bfec6ca5e62c6b2460a4adf0fddce0c4db0a8748
2626-
React-RuntimeHermes: dcb07afe0f38c1cbaf48b7a1bf4904e867529726
2627-
React-runtimescheduler: fdf0b71e519e416ad38c76525df43eba8dd78db2
2628-
React-timing: 7b538f379678210bf30d8541eb4cf007c000c6f3
2629-
React-utils: a15da1da76aee3dd0ed9f51d62bf1c09be17c221
2630-
React-viewtransitionnativemodule: 8556c844dcd691ab3fe1b32bbf8f58c8c9a49c75
2631-
React-webperformancenativemodule: 4d1d0258107fe0cb8ef5c9ac17a6a099785f2995
2632-
ReactAppDependencyProvider: adf5403892170fbe996fce485a703f25df08db66
2633-
ReactCodegen: ee39bbc365b4791c9b5183b52c533ebf586e1d8d
2634-
ReactCommon: 4d01bfb533b93a2103329dfefc74db6a9e272888
2621+
React-renderercss: 1aa1bf99fa2ace143eb87d5190fd43609fc1e832
2622+
React-rendererdebug: 40a4fb3dea21a7ac1759ca0eb6c88a924aecb075
2623+
React-RuntimeApple: 84fadbb4fe8ca531e15e29a22af05911f17569c6
2624+
React-RuntimeCore: f4d9af5f16d37e63308cb03b36c89d01e7f68a06
2625+
React-runtimeexecutor: 4d59410f66af529d04c84c8b152ced07dabc471e
2626+
React-RuntimeHermes: fd719d8f4d9ce79636fe2e09e94b0ac31b7b263b
2627+
React-runtimescheduler: 784033620aa5515e2f45a60369eed4d32f9400b8
2628+
React-timing: a16df9ae98f950396d9ce3abf43cb0cb2f21194c
2629+
React-utils: b68ee619aef28d8f9b85532d98db0327f7bdf743
2630+
React-viewtransitionnativemodule: 11fe091101d381451b1542c37b2745900254f096
2631+
React-webperformancenativemodule: b5d249419f1546663845c82f24de4e18a3180997
2632+
ReactAppDependencyProvider: dcdd0e1b9559a6d8d8aea05286f4ed085091978e
2633+
ReactCodegen: afe0d436ee089d7bea6418429d8312b1d23a6801
2634+
ReactCommon: d5c1bb4427bf51c443de5926aac332c89ddd9363
26352635
ReactNativeDependencies: fa0a54b3f5319ae0e3b9aff32bfee7a424b88e66
2636-
ReactNativeEnrichedMarkdown: aeb0aae0d55e90212ad07aa796d4f2a481bb4f98
2637-
RNCAsyncStorage: c5cc7057fed9368e15f9ee41d328327a86d30e38
2638-
RNDateTimePicker: c33c46d089998652b576a58ac08108db8c9af6f1
2639-
RNGestureHandler: a21ad1bb32b203570440c29b7e406a342a690842
2640-
RNReanimated: 786fbca32bbd50c274f25af01253a6f33fb4989e
2641-
RNScreens: 63cc2156368ac1a8239e9131103c2fef901fc381
2642-
RNSVG: 5a15a0cf553a18ab64bb38eeb4041e7e6d97bcec
2643-
RNWorklets: cfa6ca17fcc5ea7b6c1e391fb1c7c980e2d69407
2636+
ReactNativeEnrichedMarkdown: c18d5a79ed109265d5fbf55ea73edcb9b582fb23
2637+
RNCAsyncStorage: d0aafe51ea74a65afce26acb739a4ea975a7a884
2638+
RNDateTimePicker: 7b2738f1e595f83c14580a11c476872755c5befc
2639+
RNGestureHandler: 92172e79df6e88e0e93b6341f9dcd8b5a02746ba
2640+
RNReanimated: a9bf68fb5f19ce1c363b7d1413dcf8ee323185b8
2641+
RNScreens: 01b065ded2dfe7987bcce770ff3a196be417ff41
2642+
RNSVG: 3fe8590403ac9f107b4d14591bc6e54da4894e5c
2643+
RNWorklets: ae7f2b95d75b903387e6359583f2fd67bc9a93ff
26442644
Yoga: fe50ab299e578f397fef753cf309c6703a4db29b
26452645

26462646
PODFILE CHECKSUM: c50941eff996f01b8b4099a0640ffde77228a027

docs/CODE_HIGHLIGHT.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,13 @@ the tree-sitter runtime (`vendor/tree-sitter/`) is fetched and sha256-verified f
134134
release tarball, the ~178 MB of grammar `parser.c` tables (`vendor/grammars/`) are copied from the
135135
pinned grammar devDependencies, and the default registry (`vendor/generated/`) is codegen'd from them.
136136
It is wired into the package `prepare` script (so a plain `yarn install` restores everything, with
137-
`.stamp` guards making repeats a no-op) and into `prepack` (so the published npm tarball still ships
138-
the full set — consumers install it prebaked and never fetch anything).
137+
`.stamp` guards making repeats a no-op).
138+
139+
The published npm tarball ships only the small default registry, **not** the heavy grammar/runtime
140+
source — that would bloat every install to ~230 MB. Instead a `postinstall` script downloads the
141+
grammar sources (from the npm registry) and the tree-sitter runtime (from the pinned GitHub release)
142+
into the installed package, sha256-verified and idempotent. See [Native assets](./NATIVE_ASSETS.md)
143+
for the install-time behavior, network requirements, and how to recover an offline/pnpm install.
139144

140145
Highlighting runs synchronously when a code block is applied and is cached per block, with a size cap
141146
(~50 KB / ~2000 lines) that falls back to plain rendering for pathological inputs. Maintainers re-pin

docs/LATEX_MATH.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ This excludes **RaTeX** from the build. Rebuild the app after running `pod insta
9797
> versions required `use_frameworks! :linkage => :dynamic` to resolve RaTeX as a Swift
9898
> Package; that is no longer the case.)
9999
100+
> [!NOTE]
101+
> The RaTeX XCFramework is **not** bundled in the npm tarball — it is downloaded at install time by
102+
> a `postinstall` script (see [Native assets](./NATIVE_ASSETS.md)). If `pod install` fails with a
103+
> missing `ios/vendor/RaTeX.xcframework`, the download did not run (offline, `--ignore-scripts`, or
104+
> pnpm); restore it with `node node_modules/react-native-enriched-markdown/postinstall.mjs`, or
105+
> disable math as shown below.
106+
100107
> [!IMPORTANT]
101108
> **Upgrading from a version that used `use_frameworks! :linkage => :dynamic` for math?**
102109
> The pod changed from a dynamic framework to a static library. After `pod install`,

docs/NATIVE_ASSETS.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Native assets (install-time download)
2+
3+
Two pieces of the library's native layer are large prebuilt/vendored assets: the
4+
tree-sitter runtime and grammar sources used for [code-block highlighting](./CODE_HIGHLIGHT.md)
5+
(~170 MB of C source across every supported grammar) and the RaTeX static XCFramework used for
6+
[iOS LaTeX math](./LATEX_MATH.md) (~47 MB). Shipping them inside the npm tarball would make every
7+
install download ~230 MB even for apps that use neither feature.
8+
9+
Instead they are **downloaded once at install time** by a `postinstall` script, keeping the
10+
published package small (~1 MB packed / ~7.5 MB unpacked). The download is verified by sha256 and is
11+
idempotent — a `.stamp` fingerprint in each vendor directory makes repeated installs a no-op.
12+
13+
## What gets downloaded, and from where
14+
15+
| Asset | Source | Used by |
16+
|---|---|---|
17+
| tree-sitter runtime | GitHub release tarball (`github.com/tree-sitter/tree-sitter`) | code highlighting (iOS + Android) |
18+
| grammar sources (`parser.c`/`scanner.c`/`highlights.scm`) | npm registry (`registry.npmjs.org`) | code highlighting (iOS + Android) |
19+
| RaTeX XCFramework + fonts | GitHub release (`github.com/erweixin/RaTeX`) | LaTeX math (iOS only) |
20+
21+
The pins live in `grammar-versions.json` and `ratex-version.json` inside the installed package. The
22+
pre-built highlight registry for the default language set **is** shipped in the tarball, so the only
23+
thing fetched for a default build is the grammar C source it compiles.
24+
25+
Files land under `node_modules/react-native-enriched-markdown/` in
26+
`cpp/highlight/vendor/` (grammars + runtime) and `ios/vendor/` (RaTeX). Because this runs during
27+
`npm install` / `yarn add`, the assets are in place before `pod install` or the Android build reads
28+
them.
29+
30+
## Requirements
31+
32+
- **Network access at install time** to `registry.npmjs.org` and `github.com`.
33+
- `tar` (present on macOS, Linux, and Windows 10+). RaTeX also needs `unzip`; it is absent on stock
34+
Windows, but RaTeX is iOS-only so this only affects Windows dev machines and is non-fatal.
35+
36+
The postinstall step **never fails the install**: if a download does not complete it prints a warning
37+
and exits successfully. The missing assets only surface later, as a clear error when the native build
38+
runs (the iOS podspec, for example, raises an actionable message if `ios/vendor/RaTeX.xcframework` is
39+
absent while math is enabled).
40+
41+
## Re-running or recovering
42+
43+
If installs happened offline, behind a firewall, or with scripts disabled, restore the assets by
44+
re-running the script from your project root:
45+
46+
```sh
47+
node node_modules/react-native-enriched-markdown/postinstall.mjs
48+
```
49+
50+
Then re-run `pod install` (iOS) or rebuild (Android).
51+
52+
## Package-manager notes
53+
54+
- **npm / Yarn Classic / Yarn Berry (node-modules linker)**: works out of the box.
55+
- **pnpm**: recent pnpm blocks dependency lifecycle scripts by default. Allow this package to run its
56+
`postinstall` so the assets download — for example:
57+
58+
```yaml
59+
# pnpm-workspace.yaml (or package.json "pnpm" field)
60+
onlyBuiltDependencies:
61+
- react-native-enriched-markdown
62+
```
63+
64+
Without this the native build fails until you run the recovery command above.
65+
- **Yarn PnP** is not supported for this package — PnP stores dependencies as read-only archives, so
66+
the postinstall cannot write the vendored assets into the package. Use the `node-modules` linker
67+
(`nodeLinker: node-modules`), which is the norm for React Native projects anyway.
68+
- **`--ignore-scripts`**: the assets will not download. Run the recovery command above afterward.
69+
70+
## Disabling the features
71+
72+
If you don't use a feature you can turn it off so its assets are never compiled/linked (a failed or
73+
skipped download then never matters):
74+
75+
- Code highlighting: see [Choosing languages / reducing binary size](./CODE_HIGHLIGHT.md#choosing-languages--reducing-binary-size).
76+
- LaTeX math: see [Disabling LaTeX Math](./LATEX_MATH.md#disabling-latex-math-reducing-bundle-size).

eslint.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export default defineConfig([
2929
'packages/react-native-enriched-markdown/lib/',
3030
// Emscripten-generated WASM glue — not human-authored
3131
'packages/react-native-enriched-markdown/src/web/wasm/md4c.js',
32+
// Standalone ESM postinstall script — not part of the library source
33+
'packages/react-native-enriched-markdown/postinstall.mjs',
3234
],
3335
},
3436
]);

packages/react-native-enriched-markdown/ReactNativeEnrichedMarkdown.podspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ Pod::Spec.new do |s|
5454
# error. Fail early with an actionable message instead.
5555
unless File.directory?(File.join(__dir__, 'ios/vendor/RaTeX.xcframework'))
5656
raise '[ReactNativeEnrichedMarkdown] LaTeX math is enabled but the vendored RaTeX ' \
57-
'XCFramework is missing at ios/vendor/RaTeX.xcframework. Run `yarn prepare` (or ' \
58-
'`node vendor/vendor-ratex.mjs`) to restore it, or disable math by setting ' \
59-
"ENV['ENRICHED_MARKDOWN_ENABLE_MATH'] = '0' in your Podfile. See docs/LATEX_MATH.md."
57+
'XCFramework is missing at ios/vendor/RaTeX.xcframework. ' \
58+
'For published installs, re-run: node node_modules/react-native-enriched-markdown/postinstall.mjs ' \
59+
'For monorepo development, run `yarn prepare` (or `node vendor/vendor-ratex.mjs`). ' \
60+
"To disable math, set ENV['ENRICHED_MARKDOWN_ENABLE_MATH'] = '0' in your Podfile. See docs/LATEX_MATH.md."
6061
end
6162
# Prebuilt static XCFramework (device + simulator[arm64,x86_64] + macOS). Vendored
6263
# rather than pulled via spm_dependency, which compiled RaTeX's Swift wrapper per

packages/react-native-enriched-markdown/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
"jest.js",
1717
"jest.d.ts",
1818
"react-native.config.js",
19+
"postinstall.mjs",
20+
"vendor-grammars.mjs",
21+
"vendor-ratex.mjs",
22+
"ratex-version.json",
1923
"!ios/build",
24+
"!ios/vendor",
2025
"!android/build",
2126
"!android/gradle",
2227
"!android/gradlew",
@@ -31,6 +36,7 @@
3136
"docs"
3237
],
3338
"scripts": {
39+
"postinstall": "node postinstall.mjs",
3440
"build:wasm": "bash ../core/cpp/wasm/build.sh",
3541
"typecheck": "tsc",
3642
"test": "jest",

0 commit comments

Comments
 (0)