8. Publish the module as a package
The trip tracker as an npm package that apps install and compile with their own modules.
{ "name": "trip-tracker", "version": "1.0.0", "files": [ "index.ts", "src", "lucent.json" ], "main": "index.ts", "lucent": { "sources": "src", "compatible": ">=0.0.3" }}{ "ios": { "infoPlist": { "NSLocationWhenInUseUsageDescription": "Trip Tracker records your route while you track a trip." } }}export * from "./src/trip.lucent";export * from "./src/location.lucent";import { useEffect, useState } from "react";import { PermissionsAndroid, Platform, Text } from "react-native";import { requestPermission, stop, watch } from "./src/location.lucent";import { Trip, type TripSummary } from "./src/trip.lucent";import { requestPermission, stop, Trip, type TripSummary, watch } from "trip-tracker";
const trip = new Trip();Move src/ into a folder of its own, trip-tracker/, and add these three files. The package ships the modules as source: an app that installs it compiles them with its own modules, into its one native package.
lucent.sourcesnames the folder with the modules.lucent.compatibleis the range of Lucent versions the package supports.index.tsre-exports the modules. Metro swaps each for its proxy, as in an app.lucent.jsonlists what the modules need from the app. Here it's theInfo.plistentry, so apps no longer add it by hand.- The modules are named
trip-tracker/tripandtrip-tracker/location, so they can't clash with an app's owntripmodule.
npm publishIn an app that installs trip-tracker, lucent build finds it and builds its modules. The Expo config plugin writes the Info.plist entry. In a bare app, lucent build names the missing key:
โ Native package .lucent/native! trip-tracker needs NSLocationWhenInUseUsageDescription in ios/App/Info.plist (the Expo config plugin adds it)
modules trip-tracker/location ios android trip-tracker/trip sharedYou've built a module with shared logic, async work, errors, platform code, callbacks and permissions, and published it. The examples show more modules built the same way.