@backtickjs/expo 0.0.0-stage → 0.2.1

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 Jean-François Bisson
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 CHANGED
@@ -1,3 +1,58 @@
1
- # Temporary Holding Version
1
+ # @backtickjs/expo
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [Backtick](https://backtickjs.com) for Expo apps: a config plugin that records the versions your app is built with, so it can tell your server which modules it carries, and a call that reloads the app when your server restarts in development.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @backtickjs/expo
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ **The config plugin** puts the installed version of each of your app's dependencies in the app config, which Expo embeds in the app:
14
+
15
+ ```json
16
+ // app.json
17
+ { "expo": { "plugins": ["@backtickjs/expo"] } }
18
+ ```
19
+
20
+ **The app reads them back** with `getBacktickExtra`, and sends the modules its module map offers, at those versions, with each request. Your server bundles each screen for exactly those modules:
21
+
22
+ ```ts
23
+ import { modulesOf } from "@backtickjs/core";
24
+ import { getBacktickExtra } from "@backtickjs/expo";
25
+ import Constants from "expo-constants";
26
+ import { moduleMap } from "./moduleMap";
27
+
28
+ const { installedPackages } = getBacktickExtra(Constants.expoConfig);
29
+ const modules = JSON.stringify(modulesOf(moduleMap, installedPackages));
30
+ fetch(url, { headers: { "x-backtick-modules": modules } });
31
+ ```
32
+
33
+ A reload keeps the config the app was opened with: after upgrading a package, close the app and open it again.
34
+
35
+ **Your server reloads the app** once it listens, so saving a server file shows its screens without pressing `r` in Expo's terminal:
36
+
37
+ ```ts
38
+ import { reloadExpo } from "@backtickjs/expo/server";
39
+
40
+ serve({ fetch: app.fetch, port: 3000 }, () => reloadExpo());
41
+ ```
42
+
43
+ Without Expo running, as on a deployed server, it does nothing.
44
+
45
+ ## API
46
+
47
+ - `@backtickjs/expo` in `app.json`'s `plugins`: the config plugin, which sets `extra.backtick.installedPackages` to `installedPackages(projectRoot)` from `@backtickjs/core/node`.
48
+ - `getBacktickExtra(expoConfig)`: what the plugin recorded, `{ installedPackages }`, from `Constants.expoConfig`. Throws as the app starts if the plugin isn't in `app.json`.
49
+ - `reloadExpo(port?)`, from `@backtickjs/expo/server`: reloads the apps Expo serves, as pressing `r` in its terminal does. `port` is Expo's, 8081 or `RCT_METRO_PORT` by default.
50
+
51
+ ## Related
52
+
53
+ - [`@backtickjs/core`](https://github.com/backtickjs/backtick/tree/main/packages/core#every-build-in-users-hands): `modulesOf`, and how every build in users' hands keeps being drawn for
54
+ - [`@backtickjs/bundler`](https://github.com/backtickjs/backtick/tree/main/packages/bundler): bundles a screen for the modules a build sends
55
+
56
+ ## License
57
+
58
+ MIT
package/app.plugin.js ADDED
@@ -0,0 +1,3 @@
1
+ // Where Expo looks for a package's config plugin, as
2
+ // `"plugins": ["@backtickjs/expo"]` names it.
3
+ export { default } from "./dist/plugin.js";
@@ -0,0 +1,14 @@
1
+ /** What the config plugin puts in the app config's `extra.backtick`. */
2
+ export type BacktickExtra = {
3
+ installedPackages: Readonly<Record<string, string>>;
4
+ };
5
+ /**
6
+ * What the config plugin recorded, from the app config Expo embeds: throws as
7
+ * the app starts if the plugin isn't in app.json, or what's there isn't its.
8
+ *
9
+ * const { installedPackages } = getBacktickExtra(Constants.expoConfig);
10
+ * const modules = JSON.stringify(modulesOf(moduleMap, installedPackages));
11
+ */
12
+ export declare function getBacktickExtra(expoConfig: {
13
+ extra?: Record<string, unknown>;
14
+ } | null | undefined): BacktickExtra;
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ // What the app imports: nothing of Node, so Metro can take it.
2
+ /**
3
+ * What the config plugin recorded, from the app config Expo embeds: throws as
4
+ * the app starts if the plugin isn't in app.json, or what's there isn't its.
5
+ *
6
+ * const { installedPackages } = getBacktickExtra(Constants.expoConfig);
7
+ * const modules = JSON.stringify(modulesOf(moduleMap, installedPackages));
8
+ */
9
+ export function getBacktickExtra(expoConfig) {
10
+ const backtick = expoConfig?.extra?.backtick;
11
+ if (backtick === undefined) {
12
+ throw new Error("No extra.backtick in the app config: is @backtickjs/expo in app.json's plugins?");
13
+ }
14
+ const { installedPackages } = backtick;
15
+ if (typeof installedPackages !== "object" ||
16
+ installedPackages === null ||
17
+ Array.isArray(installedPackages) ||
18
+ !Object.values(installedPackages).every((version) => typeof version === "string")) {
19
+ throw new Error("extra.backtick.installedPackages isn't { package: version }: is it written by @backtickjs/expo?");
20
+ }
21
+ return { installedPackages: installedPackages };
22
+ }
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAQ/D;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAAkE;IAElE,MAAM,QAAQ,GAAG,UAAU,EAAE,KAAK,EAAE,QAEvB,CAAC;IACd,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IACvC,IACE,OAAO,iBAAiB,KAAK,QAAQ;QACrC,iBAAiB,KAAK,IAAI;QAC1B,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC;QAChC,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,KAAK,CACrC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,KAAK,QAAQ,CACzC,EACD,CAAC;QACD,MAAM,IAAI,KAAK,CACb,iGAAiG,CAClG,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,iBAAiB,EAAE,iBAA2C,EAAE,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,15 @@
1
+ type ExpoConfig = {
2
+ extra?: Record<string, unknown>;
3
+ _internal?: {
4
+ projectRoot?: string;
5
+ };
6
+ };
7
+ /**
8
+ * The config plugin, as `"plugins": ["@backtickjs/expo"]` in app.json: puts
9
+ * the installed version of each of the app's dependencies in the config,
10
+ * `extra.backtick.installedPackages`, which `getBacktickExtra` reads.
11
+ */
12
+ export default function withBacktickExtra<Config extends ExpoConfig>(config: Config): Config & {
13
+ extra: Record<string, unknown>;
14
+ };
15
+ export {};
package/dist/plugin.js ADDED
@@ -0,0 +1,24 @@
1
+ import { installedPackages } from "@backtickjs/core/node";
2
+ /**
3
+ * The config plugin, as `"plugins": ["@backtickjs/expo"]` in app.json: puts
4
+ * the installed version of each of the app's dependencies in the config,
5
+ * `extra.backtick.installedPackages`, which `getBacktickExtra` reads.
6
+ */
7
+ export default function withBacktickExtra(config) {
8
+ const projectRoot = config._internal?.projectRoot;
9
+ if (projectRoot === undefined) {
10
+ throw new Error("@backtickjs/expo: Expo gave the config no projectRoot.");
11
+ }
12
+ const backtick = config.extra?.backtick;
13
+ return {
14
+ ...config,
15
+ extra: {
16
+ ...config.extra,
17
+ backtick: {
18
+ ...backtick,
19
+ installedPackages: installedPackages(projectRoot),
20
+ },
21
+ },
22
+ };
23
+ }
24
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAS1D;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,MAAc;IAEd,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC;IAClD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,QAElB,CAAC;IACd,OAAO;QACL,GAAG,MAAM;QACT,KAAK,EAAE;YACL,GAAG,MAAM,CAAC,KAAK;YACf,QAAQ,EAAE;gBACR,GAAG,QAAQ;gBACX,iBAAiB,EAAE,iBAAiB,CAAC,WAAW,CAAC;aAClD;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Reloads the apps Expo serves, as pressing `r` in its terminal does: a
3
+ * `reload` on its message socket, which it accepts from this computer. Call
4
+ * it once the server listens, so a restart after a save shows its screens.
5
+ * Without Expo running, it does nothing.
6
+ *
7
+ * serve({ fetch: app.fetch, port: 3000 }, () => reloadExpo());
8
+ */
9
+ export declare function reloadExpo(port?: number): void;
package/dist/server.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Reloads the apps Expo serves, as pressing `r` in its terminal does: a
3
+ * `reload` on its message socket, which it accepts from this computer. Call
4
+ * it once the server listens, so a restart after a save shows its screens.
5
+ * Without Expo running, it does nothing.
6
+ *
7
+ * serve({ fetch: app.fetch, port: 3000 }, () => reloadExpo());
8
+ */
9
+ export function reloadExpo(port = Number(process.env.RCT_METRO_PORT ?? 8081)) {
10
+ const socket = new WebSocket(`ws://127.0.0.1:${port}/message`);
11
+ socket.onopen = () => {
12
+ socket.send(JSON.stringify({ version: 2, method: "reload" }));
13
+ socket.close();
14
+ };
15
+ // Expo isn't running: there's no app to reload.
16
+ socket.onerror = () => { };
17
+ }
18
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CACxB,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,IAAI,CAAC;IAEjD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,kBAAkB,IAAI,UAAU,CAAC,CAAC;IAC/D,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE;QACnB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC9D,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC,CAAC;IACF,gDAAgD;IAChD,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAC5B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@backtickjs/expo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.1",
4
+ "description": "Backtick for Expo apps: the config plugin that records the app's installed packages, and reloading apps when the server restarts",
5
+ "keywords": [
6
+ "backtick",
7
+ "expo",
8
+ "react-native",
9
+ "server-driven-ui"
10
+ ],
11
+ "homepage": "https://backtickjs.com",
12
+ "bugs": {
13
+ "url": "https://github.com/backtickjs/backtick/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/backtickjs/backtick.git",
18
+ "directory": "packages/expo"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Jean-François Bisson <jf@backtickjs.com>",
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./server": {
29
+ "types": "./dist/server.d.ts",
30
+ "default": "./dist/server.js"
31
+ },
32
+ "./app.plugin.js": "./app.plugin.js"
33
+ },
34
+ "files": [
35
+ "app.plugin.js",
36
+ "dist",
37
+ "!dist/._cache",
38
+ "src"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "@backtickjs/core": "^0.2.1"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^25.9.1",
48
+ "@types/ws": "^8.18.2",
49
+ "prettier": "^3.6.2",
50
+ "typescript": "^6.0.3",
51
+ "ws": "^8.22.0"
52
+ },
53
+ "scripts": {
54
+ "build": "tsc -b",
55
+ "dev": "tsc -b --watch",
56
+ "format": "prettier --write --ignore-unknown .",
57
+ "format:check": "prettier --check --ignore-unknown .",
58
+ "test": "node --test \"test/**/*.test.ts\"",
59
+ "clean": "rm -rf node_modules dist .turbo"
60
+ }
6
61
  }
package/src/index.ts ADDED
@@ -0,0 +1,41 @@
1
+ // What the app imports: nothing of Node, so Metro can take it.
2
+
3
+ /** What the config plugin puts in the app config's `extra.backtick`. */
4
+ export type BacktickExtra = {
5
+ // the installed version of each of the app's dependencies, by package
6
+ installedPackages: Readonly<Record<string, string>>;
7
+ };
8
+
9
+ /**
10
+ * What the config plugin recorded, from the app config Expo embeds: throws as
11
+ * the app starts if the plugin isn't in app.json, or what's there isn't its.
12
+ *
13
+ * const { installedPackages } = getBacktickExtra(Constants.expoConfig);
14
+ * const modules = JSON.stringify(modulesOf(moduleMap, installedPackages));
15
+ */
16
+ export function getBacktickExtra(
17
+ expoConfig: { extra?: Record<string, unknown> } | null | undefined,
18
+ ): BacktickExtra {
19
+ const backtick = expoConfig?.extra?.backtick as
20
+ | { installedPackages?: unknown }
21
+ | undefined;
22
+ if (backtick === undefined) {
23
+ throw new Error(
24
+ "No extra.backtick in the app config: is @backtickjs/expo in app.json's plugins?",
25
+ );
26
+ }
27
+ const { installedPackages } = backtick;
28
+ if (
29
+ typeof installedPackages !== "object" ||
30
+ installedPackages === null ||
31
+ Array.isArray(installedPackages) ||
32
+ !Object.values(installedPackages).every(
33
+ (version) => typeof version === "string",
34
+ )
35
+ ) {
36
+ throw new Error(
37
+ "extra.backtick.installedPackages isn't { package: version }: is it written by @backtickjs/expo?",
38
+ );
39
+ }
40
+ return { installedPackages: installedPackages as Record<string, string> };
41
+ }
package/src/plugin.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { installedPackages } from "@backtickjs/core/node";
2
+
3
+ // The part of an Expo config this plugin reads and writes: `projectRoot` is
4
+ // set by Expo as it reads the config.
5
+ type ExpoConfig = {
6
+ extra?: Record<string, unknown>;
7
+ _internal?: { projectRoot?: string };
8
+ };
9
+
10
+ /**
11
+ * The config plugin, as `"plugins": ["@backtickjs/expo"]` in app.json: puts
12
+ * the installed version of each of the app's dependencies in the config,
13
+ * `extra.backtick.installedPackages`, which `getBacktickExtra` reads.
14
+ */
15
+ export default function withBacktickExtra<Config extends ExpoConfig>(
16
+ config: Config,
17
+ ): Config & { extra: Record<string, unknown> } {
18
+ const projectRoot = config._internal?.projectRoot;
19
+ if (projectRoot === undefined) {
20
+ throw new Error("@backtickjs/expo: Expo gave the config no projectRoot.");
21
+ }
22
+ const backtick = config.extra?.backtick as
23
+ | Record<string, unknown>
24
+ | undefined;
25
+ return {
26
+ ...config,
27
+ extra: {
28
+ ...config.extra,
29
+ backtick: {
30
+ ...backtick,
31
+ installedPackages: installedPackages(projectRoot),
32
+ },
33
+ },
34
+ };
35
+ }
package/src/server.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Reloads the apps Expo serves, as pressing `r` in its terminal does: a
3
+ * `reload` on its message socket, which it accepts from this computer. Call
4
+ * it once the server listens, so a restart after a save shows its screens.
5
+ * Without Expo running, it does nothing.
6
+ *
7
+ * serve({ fetch: app.fetch, port: 3000 }, () => reloadExpo());
8
+ */
9
+ export function reloadExpo(
10
+ port = Number(process.env.RCT_METRO_PORT ?? 8081),
11
+ ): void {
12
+ const socket = new WebSocket(`ws://127.0.0.1:${port}/message`);
13
+ socket.onopen = () => {
14
+ socket.send(JSON.stringify({ version: 2, method: "reload" }));
15
+ socket.close();
16
+ };
17
+ // Expo isn't running: there's no app to reload.
18
+ socket.onerror = () => {};
19
+ }