@forthtilliath/expo-release-updates 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Forthtilliath
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # @forthtilliath/expo-release-updates
2
+
3
+ Self-update a sideloaded Android Expo app from its GitHub Releases: check the latest release, show a release history, download and trigger the install of a new APK. No backend needed — just a GitHub repo that publishes an `.apk` asset on each release.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @forthtilliath/expo-release-updates expo-file-system expo-intent-launcher
9
+ ```
10
+
11
+ Or, from within this monorepo, as a workspace dependency:
12
+
13
+ ```json
14
+ {
15
+ "dependencies": {
16
+ "@forthtilliath/expo-release-updates": "workspace:*"
17
+ }
18
+ }
19
+ ```
20
+
21
+ `expo-file-system` and `expo-intent-launcher` are peer dependencies — install them in the consuming app if not already present.
22
+
23
+ ## Usage
24
+
25
+ Each function is its own module — import the file you need directly:
26
+
27
+ ```ts
28
+ import { compareVersions } from "@forthtilliath/expo-release-updates/compareVersions";
29
+ import {
30
+ fetchLatestRelease,
31
+ fetchReleaseHistory,
32
+ } from "@forthtilliath/expo-release-updates/githubReleases";
33
+ import { downloadAndInstallApk } from "@forthtilliath/expo-release-updates/downloadAndInstallApk";
34
+ import { parseChangelogNotes } from "@forthtilliath/expo-release-updates/parseChangelogNotes";
35
+ ```
36
+
37
+ ### `compareVersions(a, b)`
38
+
39
+ Compares two `"x.y.z"` version strings, segment by segment. Returns `-1` if `a < b`, `0` if equal, `1` if `a > b`.
40
+
41
+ ```ts
42
+ compareVersions("1.2.0", "1.10.0"); // -1 (numeric, not lexicographic)
43
+ compareVersions("2.0.0", "1.9.9"); // 1
44
+ compareVersions("1.2.3", "1.2.3"); // 0
45
+ ```
46
+
47
+ ### `fetchLatestRelease({ owner, repo })`
48
+
49
+ Fetches the latest GitHub release and its `.apk` asset. Returns `null` if the latest release has no `.apk` attached; throws if the GitHub API request fails.
50
+
51
+ ```ts
52
+ const release = await fetchLatestRelease({ owner: "acme", repo: "app" });
53
+ if (release && compareVersions(release.version, currentVersion) > 0) {
54
+ // an update is available: release.version, release.notes, release.apkUrl
55
+ }
56
+ ```
57
+
58
+ ### `fetchReleaseHistory({ owner, repo, limit? })`
59
+
60
+ Fetches the most recent releases (version, notes, publish date), most recent first. `limit` defaults to `10` — useful for a "release history" / "what's new" screen.
61
+
62
+ ```ts
63
+ const history = await fetchReleaseHistory({
64
+ owner: "acme",
65
+ repo: "app",
66
+ limit: 5,
67
+ });
68
+ // [{ version: "1.11.0", notes: "### Added\n- ...", publishedAt: "2026-07-30T..." }, ...]
69
+ ```
70
+
71
+ ### `downloadAndInstallApk({ apkUrl, fileName, onProgress? })`
72
+
73
+ Downloads an APK to the app's cache directory and triggers the Android install-package intent. **Android only** — there is no iOS equivalent (sideloading isn't possible there).
74
+
75
+ ```ts
76
+ await downloadAndInstallApk({
77
+ apkUrl: release.apkUrl,
78
+ fileName: "myapp-update.apk",
79
+ onProgress: (fraction) => setProgress(fraction),
80
+ });
81
+ ```
82
+
83
+ ### `parseChangelogNotes(notes)`
84
+
85
+ Parses a small subset of Markdown (`### heading`, `- item`, `**bold**`) commonly found in GitHub release notes into a list of typed blocks (`heading` / `item` / `text`, each with `bold`-aware segments), ready for a UI layer to render without a full Markdown dependency. Pair it with `@forthtilliath/react-native-kit`'s `ChangelogNotes` component to render the result directly.
86
+
87
+ ```ts
88
+ parseChangelogNotes("### Added\n- **Auto-backup**: saves every 5 minutes.");
89
+ // [
90
+ // { type: "heading", text: "Added" },
91
+ // {
92
+ // type: "item",
93
+ // segments: [
94
+ // { text: "Auto-backup", bold: true },
95
+ // { text: ": saves every 5 minutes.", bold: false },
96
+ // ],
97
+ // },
98
+ // ]
99
+ ```
100
+
101
+ ## Scripts
102
+
103
+ ```bash
104
+ pnpm run dev # tsc --watch -> dist/
105
+ pnpm run build # tsc -> dist/
106
+ pnpm run check-types # tsc --noEmit
107
+ pnpm run lint # eslint
108
+ pnpm run test # vitest run
109
+ pnpm run test:watch # vitest
110
+ ```
111
+
112
+ Built to `dist/` (see the `exports` field in `package.json`), so run `pnpm run build` (or `dev`) after source changes for consumers to see them.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Compares two "x.y.z" version strings, segment by segment.
3
+ *
4
+ * @returns -1 if `a` < `b`, 0 if they're equal, 1 if `a` > `b`.
5
+ */
6
+ export declare function compareVersions(a: string, b: string): number;
7
+ //# sourceMappingURL=compareVersions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compareVersions.d.ts","sourceRoot":"","sources":["../src/compareVersions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAU5D"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Compares two "x.y.z" version strings, segment by segment.
3
+ *
4
+ * @returns -1 if `a` < `b`, 0 if they're equal, 1 if `a` > `b`.
5
+ */
6
+ export function compareVersions(a, b) {
7
+ const partsA = a.split(".").map(Number);
8
+ const partsB = b.split(".").map(Number);
9
+ const length = Math.max(partsA.length, partsB.length);
10
+ for (let i = 0; i < length; i++) {
11
+ const numA = partsA[i] ?? 0;
12
+ const numB = partsB[i] ?? 0;
13
+ if (numA !== numB)
14
+ return numA > numB ? 1 : -1;
15
+ }
16
+ return 0;
17
+ }
@@ -0,0 +1,13 @@
1
+ export interface DownloadAndInstallApkOptions {
2
+ apkUrl: string;
3
+ /** Temp filename in the cache directory, e.g. "myapp-update.apk". */
4
+ fileName: string;
5
+ onProgress?: (fraction: number) => void;
6
+ }
7
+ /**
8
+ * Downloads an APK to the cache directory and triggers the Android
9
+ * install-package intent. Android only — there is no equivalent flow on iOS,
10
+ * which doesn't allow installing a downloaded package outside the App Store.
11
+ */
12
+ export declare function downloadAndInstallApk({ apkUrl, fileName, onProgress, }: DownloadAndInstallApkOptions): Promise<void>;
13
+ //# sourceMappingURL=downloadAndInstallApk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"downloadAndInstallApk.d.ts","sourceRoot":"","sources":["../src/downloadAndInstallApk.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,4BAA4B;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,MAAM,EACN,QAAQ,EACR,UAAU,GACX,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB9C"}
@@ -0,0 +1,26 @@
1
+ import { File, Paths } from "expo-file-system";
2
+ import * as IntentLauncher from "expo-intent-launcher";
3
+ /**
4
+ * Downloads an APK to the cache directory and triggers the Android
5
+ * install-package intent. Android only — there is no equivalent flow on iOS,
6
+ * which doesn't allow installing a downloaded package outside the App Store.
7
+ */
8
+ export async function downloadAndInstallApk({ apkUrl, fileName, onProgress, }) {
9
+ const destination = new File(Paths.cache, fileName);
10
+ if (destination.exists)
11
+ destination.delete();
12
+ const task = File.createDownloadTask(apkUrl, destination, {
13
+ onProgress: ({ bytesWritten, totalBytes }) => {
14
+ if (totalBytes > 0)
15
+ onProgress?.(bytesWritten / totalBytes);
16
+ },
17
+ });
18
+ const file = await task.downloadAsync();
19
+ if (!file)
20
+ throw new Error("The download failed.");
21
+ await IntentLauncher.startActivityAsync("android.intent.action.VIEW", {
22
+ data: file.contentUri,
23
+ flags: 1,
24
+ type: "application/vnd.android.package-archive",
25
+ });
26
+ }
@@ -0,0 +1,29 @@
1
+ export interface GithubRepoRef {
2
+ owner: string;
3
+ repo: string;
4
+ }
5
+ export interface LatestRelease {
6
+ version: string;
7
+ notes: string;
8
+ apkUrl: string;
9
+ }
10
+ export interface ReleaseHistoryEntry {
11
+ version: string;
12
+ notes: string;
13
+ publishedAt: string;
14
+ }
15
+ /**
16
+ * Fetches the latest GitHub release for a repo, along with its `.apk` asset.
17
+ *
18
+ * @returns `null` if the latest release has no `.apk` asset attached.
19
+ * @throws if the GitHub API request fails.
20
+ */
21
+ export declare function fetchLatestRelease(ref: GithubRepoRef): Promise<LatestRelease | null>;
22
+ /**
23
+ * Fetches the most recent releases for a repo (version, notes, publish
24
+ * date), most recent first — useful for a "release history" screen.
25
+ */
26
+ export declare function fetchReleaseHistory(ref: GithubRepoRef & {
27
+ limit?: number;
28
+ }): Promise<ReleaseHistoryEntry[]>;
29
+ //# sourceMappingURL=githubReleases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"githubReleases.d.ts","sourceRoot":"","sources":["../src/githubReleases.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB;AAkBD;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,aAAa,GACjB,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAkB/B;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,aAAa,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACtC,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAiBhC"}
@@ -0,0 +1,43 @@
1
+ function releasesUrl({ owner, repo }) {
2
+ return `https://api.github.com/repos/${owner}/${repo}/releases`;
3
+ }
4
+ /**
5
+ * Fetches the latest GitHub release for a repo, along with its `.apk` asset.
6
+ *
7
+ * @returns `null` if the latest release has no `.apk` asset attached.
8
+ * @throws if the GitHub API request fails.
9
+ */
10
+ export async function fetchLatestRelease(ref) {
11
+ const response = await fetch(`${releasesUrl(ref)}/latest`, {
12
+ headers: { Accept: "application/vnd.github+json" },
13
+ });
14
+ if (!response.ok)
15
+ throw new Error(`GitHub responded with ${String(response.status)}`);
16
+ const data = (await response.json());
17
+ const apkAsset = (data.assets ?? []).find((asset) => asset.name.endsWith(".apk"));
18
+ if (!apkAsset)
19
+ return null;
20
+ return {
21
+ version: (data.tag_name ?? "").replace(/^v/, ""),
22
+ notes: data.body ?? "",
23
+ apkUrl: apkAsset.browser_download_url,
24
+ };
25
+ }
26
+ /**
27
+ * Fetches the most recent releases for a repo (version, notes, publish
28
+ * date), most recent first — useful for a "release history" screen.
29
+ */
30
+ export async function fetchReleaseHistory(ref) {
31
+ const { limit = 10 } = ref;
32
+ const response = await fetch(`${releasesUrl(ref)}?per_page=${String(limit)}`, {
33
+ headers: { Accept: "application/vnd.github+json" },
34
+ });
35
+ if (!response.ok)
36
+ throw new Error(`GitHub responded with ${String(response.status)}`);
37
+ const data = (await response.json());
38
+ return data.map((release) => ({
39
+ version: (release.tag_name ?? "").replace(/^v/, ""),
40
+ notes: release.body ?? "",
41
+ publishedAt: release.published_at ?? "",
42
+ }));
43
+ }
@@ -0,0 +1,16 @@
1
+ export interface ChangelogSegment {
2
+ text: string;
3
+ bold: boolean;
4
+ }
5
+ export type ChangelogBlock = {
6
+ type: "heading";
7
+ text: string;
8
+ } | {
9
+ type: "item";
10
+ segments: ChangelogSegment[];
11
+ } | {
12
+ type: "text";
13
+ segments: ChangelogSegment[];
14
+ };
15
+ export declare function parseChangelogNotes(notes: string): ChangelogBlock[];
16
+ //# sourceMappingURL=parseChangelogNotes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseChangelogNotes.d.ts","sourceRoot":"","sources":["../src/parseChangelogNotes.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,gBAAgB,EAAE,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,gBAAgB,EAAE,CAAA;CAAE,CAAC;AAsBnD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,EAAE,CAiBnE"}
@@ -0,0 +1,43 @@
1
+ // GitHub release notes are usually written in a small subset of Markdown
2
+ // ("### Heading", "- item", "**bold**"). Rendered as-is in a plain <Text>,
3
+ // the raw syntax shows up unstyled — this parser turns it into a small set
4
+ // of typed blocks a UI layer can render (heading / bullet item / plain
5
+ // text), without pulling in a full Markdown dependency for this narrow use
6
+ // case.
7
+ function parseInlineSegments(text) {
8
+ const segments = [];
9
+ const boldPattern = /\*\*(.+?)\*\*/g;
10
+ let lastIndex = 0;
11
+ let match;
12
+ while ((match = boldPattern.exec(text)) !== null) {
13
+ if (match.index > lastIndex) {
14
+ segments.push({ text: text.slice(lastIndex, match.index), bold: false });
15
+ }
16
+ // The capture group is mandatory in the pattern, so it always matches —
17
+ // the `?? ""` fallback is only here to satisfy `noUncheckedIndexedAccess`.
18
+ segments.push({ text: match[1] ?? "", bold: true });
19
+ lastIndex = boldPattern.lastIndex;
20
+ }
21
+ if (lastIndex < text.length) {
22
+ segments.push({ text: text.slice(lastIndex), bold: false });
23
+ }
24
+ return segments;
25
+ }
26
+ export function parseChangelogNotes(notes) {
27
+ return notes
28
+ .split("\n")
29
+ .map((line) => line.trim())
30
+ .filter((line) => line.length > 0)
31
+ .map((line) => {
32
+ if (line.startsWith("### ")) {
33
+ return { type: "heading", text: line.slice(4).trim() };
34
+ }
35
+ if (line.startsWith("- ")) {
36
+ return {
37
+ type: "item",
38
+ segments: parseInlineSegments(line.slice(2).trim()),
39
+ };
40
+ }
41
+ return { type: "text", segments: parseInlineSegments(line) };
42
+ });
43
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@forthtilliath/expo-release-updates",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/Forthtilliath/turborepo.git",
12
+ "directory": "packages/expo-release-updates"
13
+ },
14
+ "homepage": "https://github.com/Forthtilliath/turborepo/tree/main/packages/expo-release-updates#readme",
15
+ "bugs": "https://github.com/Forthtilliath/turborepo/issues",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "exports": {
20
+ "./*": "./dist/*.js"
21
+ },
22
+ "peerDependencies": {
23
+ "expo-file-system": ">=54.0.0",
24
+ "expo-intent-launcher": ">=12.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "eslint": "10.7.0",
28
+ "expo-file-system": "~57.0.1",
29
+ "expo-intent-launcher": "~57.0.1",
30
+ "typescript": "^5.9.3",
31
+ "vitest": "^4.1.10",
32
+ "@forthtilliath/eslint-config": "0.0.0",
33
+ "@forthtilliath/typescript-config": "0.0.0"
34
+ },
35
+ "scripts": {
36
+ "lint": "eslint . --max-warnings 0",
37
+ "check-types": "tsc --noEmit",
38
+ "clean": "rm -rf dist",
39
+ "dev": "tsc --watch -p tsconfig.build.json",
40
+ "build": "pnpm run clean && tsc -p tsconfig.build.json",
41
+ "test": "vitest run",
42
+ "test:watch": "vitest"
43
+ }
44
+ }