@protobase/cli 0.45.0 → 0.45.2

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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.45.0";
2
+ var version = "0.45.2";
3
3
  //#endregion
4
4
  export { version };
@@ -1,11 +1,12 @@
1
1
  import { createHash } from "node:crypto";
2
2
  //#region src/mobile/fingerprint.ts
3
3
  /**
4
- * Names the app's native code: the native packages @protobase/mobile pins, name → version (`pinnedNative`), and the
5
- * project's `mobile.plugins`, name → the spec it gives. A release of the app's files runs only on a binary of the same
6
- * fingerprint. It holds no Protobase version, so a Protobase release that pins the same native packages keeps
7
- * binaries on live updates. A plugin's spec counts, not the version npm installed: its floor is what the app's files
8
- * need of it, so raise the floor when they start using a newer native feature, which changes the fingerprint.
4
+ * Names the app's native code: what @protobase/mobile carries, name → version (`pinnedNative`: the native packages it
5
+ * pins and its own native contract), and the project's `mobile.plugins`, name → the spec it gives. A release of the
6
+ * app's files runs only on a binary of the same fingerprint. It holds no Protobase version, so a Protobase release that
7
+ * pins the same native packages and native contract keeps binaries on live updates. A plugin's spec counts, not the
8
+ * version npm installed: its floor is what the app's files need of it, so raise the floor when they start using a
9
+ * newer native feature, which changes the fingerprint.
9
10
  */
10
11
  const nativeFingerprint = (pinned, plugins = {}) => {
11
12
  const entries = Object.entries({
@@ -1,5 +1,6 @@
1
1
  //#region ../mobile/package.json
2
2
  var name = "@protobase/mobile";
3
+ var nativeContract = 2;
3
4
  var dependencies = {
4
5
  "@capacitor/android": "8.5.3",
5
6
  "@capacitor/app": "8.1.2",
@@ -10,4 +11,4 @@ var dependencies = {
10
11
  "@capawesome/capacitor-live-update": "8.7.1"
11
12
  };
12
13
  //#endregion
13
- export { dependencies, name };
14
+ export { dependencies, name, nativeContract };
@@ -1,4 +1,4 @@
1
- import { dependencies, name } from "./package.js";
1
+ import { dependencies, name, nativeContract } from "./package.js";
2
2
  import { installedPackage } from "./installed-package.js";
3
3
  //#region src/mobile/pinned-packages.ts
4
4
  /**
@@ -8,10 +8,15 @@ import { installedPackage } from "./installed-package.js";
8
8
  */
9
9
  const pinnedPackages = /* @__PURE__ */ new Set([name, ...Object.keys(dependencies)]);
10
10
  /**
11
- * The native packages @protobase/mobile pins, name → exact version, which a native fingerprint names. Never its
12
- * @protobase/* packages, whose version is Protobase's: every Protobase release would cut the binaries off updates.
11
+ * The native code an app's binary carries from @protobase/mobile, name → version, which a native fingerprint names:
12
+ * the native packages it pins, at their versions, and its own native code by its `nativeContract`, `native-<n>`. Never
13
+ * its npm version, which is Protobase's: every Protobase release would cut the binaries off updates. Raise
14
+ * `nativeContract` whenever its Android (later iOS) sources change; its test fails until it is.
13
15
  */
14
- const pinnedNative = Object.fromEntries(Object.entries(dependencies).filter(([name]) => !name.startsWith("@protobase/")));
16
+ const pinnedNative = {
17
+ ...Object.fromEntries(Object.entries(dependencies).filter(([name]) => !name.startsWith("@protobase/"))),
18
+ [name]: `native-${nativeContract}`
19
+ };
15
20
  const liveUpdate = "@capawesome/capacitor-live-update";
16
21
  /** Why the plugin `key`, a package that is or names `name`, may not be listed; `undefined` when it may. */
17
22
  const pinnedProblem = (key, name = key) => {
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { readFile } from "node:fs/promises";
2
+ import { readFile, writeFile } from "node:fs/promises";
3
3
  //#region src/mobile/protobase-plugin.ts
4
4
  /** The classes of Protobase's native plugin that keep page script away from the session, by Java class name. */
5
5
  const protobasePluginClasses = [
@@ -9,16 +9,43 @@ const protobasePluginClasses = [
9
9
  "RefusedWebView",
10
10
  "LocalServerGuard"
11
11
  ].map((name) => `net.protobase.mobile.${name}`);
12
+ const liveUpdatePackage = "@capawesome/capacitor-live-update";
13
+ const stockLiveUpdate = "io.capawesome.capacitorjs.plugins.liveupdate.LiveUpdatePlugin";
14
+ const guardedLiveUpdate = {
15
+ pkg: "@protobase/mobile",
16
+ classpath: "net.protobase.mobile.GuardedLiveUpdate"
17
+ };
18
+ const pluginsFile = (ws) => path.join(ws, "android", "app", "src", "main", "assets", "capacitor.plugins.json");
19
+ const readPlugins = async (ws) => JSON.parse(await readFile(pluginsFile(ws), "utf8"));
20
+ /**
21
+ * Puts Protobase's guarded live updater in the stock one's place in the plugin list `cap add android` writes, so page
22
+ * script reaches only what the shell needs; listing both would run two updaters. The guard compiles from the same
23
+ * plugin list, and the build checks it again (@protobase/mobile's build.gradle). An app without the plugin is left as is.
24
+ */
25
+ const guardLiveUpdate = async (ws) => {
26
+ const entries = await readPlugins(ws);
27
+ if (!entries.some(({ classpath }) => classpath === stockLiveUpdate)) return;
28
+ const guarded = entries.map((entry) => entry.classpath === stockLiveUpdate ? guardedLiveUpdate : entry);
29
+ await writeFile(pluginsFile(ws), JSON.stringify(guarded, null, " "));
30
+ };
12
31
  /**
13
32
  * Checks that `cap add android` compiled Protobase's native plugin into the app, from the plugin list it writes: an
14
- * installed @protobase/mobile older than the CLI's, as a workspace left from an earlier CLI may hold, has none.
33
+ * installed @protobase/mobile older than the CLI's, as a workspace left from an earlier CLI may hold, has none. Refuses
34
+ * any class of the live updater's own package still listed, which no guard stands in front of.
15
35
  */
16
36
  const checkProtobasePlugin = async (ws) => {
17
- const file = path.join(ws, "android", "app", "src", "main", "assets", "capacitor.plugins.json");
18
- const listed = new Set(JSON.parse(await readFile(file, "utf8")).map(({ classpath }) => classpath));
37
+ const entries = await readPlugins(ws);
38
+ const unguarded = entries.find(({ pkg, classpath }) => pkg === liveUpdatePackage || classpath === stockLiveUpdate);
39
+ if (unguarded) throw new Error(`The Android app lists ${unguarded.classpath}, which hands page script the live updater unguarded`);
40
+ const listed = new Set(entries.map(({ classpath }) => classpath));
19
41
  const missing = protobasePluginClasses.filter((name) => !listed.has(name));
20
42
  if (missing.length === 0) return;
21
43
  throw new Error(`The Android app lacks Protobase's native plugin (${missing.join(", ")}): delete ${ws} and run the command again`);
22
44
  };
45
+ /** Refuses the live updater on iOS, which has no guard yet, from the class list `cap add ios` writes. */
46
+ const checkIosPlugins = async (ws) => {
47
+ if (!JSON.parse(await readFile(path.join(ws, "ios", "App", "App", "capacitor.config.json"), "utf8")).packageClassList?.includes("LiveUpdatePlugin")) return;
48
+ throw new Error("The iOS app lists LiveUpdatePlugin, which has no guard against page script on iOS yet");
49
+ };
23
50
  //#endregion
24
- export { checkProtobasePlugin, protobasePluginClasses };
51
+ export { checkIosPlugins, checkProtobasePlugin, guardLiveUpdate, protobasePluginClasses };
@@ -12,7 +12,7 @@ import { generatePlatform } from "./generate.js";
12
12
  import { checkMobileConfig } from "./mobile-config.js";
13
13
  import { loadMobileProject } from "./load-project.js";
14
14
  import { signForDevelopment } from "./development-signing.js";
15
- import { checkProtobasePlugin } from "./protobase-plugin.js";
15
+ import { checkIosPlugins, checkProtobasePlugin, guardLiveUpdate } from "./protobase-plugin.js";
16
16
  import { mobileSpec, prepareWorkspace, workspaceDir, workspacePackageJson } from "./workspace.js";
17
17
  import path from "node:path";
18
18
  import { defaultAppName } from "@protobase/server";
@@ -57,7 +57,10 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
57
57
  }));
58
58
  const cap = capacitorRunner(ws, env, run);
59
59
  await generatePlatform(ws, platform, allowances, cap);
60
- if (platform === "android") await checkProtobasePlugin(ws);
60
+ if (platform === "android") {
61
+ await guardLiveUpdate(ws);
62
+ await checkProtobasePlugin(ws);
63
+ } else await checkIosPlugins(ws);
61
64
  return {
62
65
  ws,
63
66
  url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.45.0",
3
+ "version": "0.45.2",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -36,11 +36,11 @@
36
36
  "@better-auth/core": "^1.7.12",
37
37
  "@hono/node-server": "^2.1.3",
38
38
  "@hono/vite-dev-server": "^0.26.1",
39
- "@protobase/layout": "0.45.0",
40
- "@protobase/query": "0.45.0",
41
- "@protobase/schema": "0.45.0",
42
- "@protobase/server": "0.45.0",
43
- "@protobase/ui": "0.45.0",
39
+ "@protobase/layout": "0.45.2",
40
+ "@protobase/query": "0.45.2",
41
+ "@protobase/schema": "0.45.2",
42
+ "@protobase/server": "0.45.2",
43
+ "@protobase/ui": "0.45.2",
44
44
  "@react-email/render": "^2.1.0",
45
45
  "@scalar/hono-api-reference": "^0.12.10",
46
46
  "@tailwindcss/vite": "^4.3.3",
@@ -234,7 +234,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
234
234
  - `server`, `public`, `nodeModules` and `migrations` are relative to the bundle folder; `spa`, `theme` and each plugin's `path` to `public`.
235
235
  - `plugins` are the bundle's own plugins, in the order the app merges them: the extensions', then the project's (`app`). Each names its `plugin.json`, the plugin API and Protobase versions it is built for, and the [field types](plugins.md#field-types) it registers with the storage types each shows, which the serve runtime checks the views against at startup. `/api/meta` names them to everyone, before any other plugin.
236
236
  - `shell` is the admin app `public/` holds a copy of: its Protobase version and plugin API, and its files as URL paths. A host with a shell of its own, of a release every plugin of the bundle loads in, may serve its own for those paths instead (see [The UI](#the-ui)), so the app gets that release's fixes without a rebuild.
237
- - `native` is the native packages, name to version, that `shell` runs on in the [mobile app](../guides/mobile-app.md): those `@protobase/mobile` pins. The fingerprint of the bundle's [mobile release](#mobile-releases) names them. A bundle built before it serves no mobile release.
237
+ - `native` is the native code, name to version, that `shell` runs on in the [mobile app](../guides/mobile-app.md): the native packages `@protobase/mobile` pins, and `@protobase/mobile` itself at its native contract, such as `native-1`, which Protobase raises when its own native code changes. The fingerprint of the bundle's [mobile release](#mobile-releases) names them. A bundle built before it serves no mobile release.
238
238
  - `theme` is the project's [theme](theme.md), which the app links at `/protobase.theme.css`. It is always there, empty when the project has none.
239
239
  - `nodeModules` is present only when the config module imports [native packages](#native-packages). It is always the `node_modules` folder beside `server`, where Bun and Node resolve the module's imports from, and holds plain packages: JavaScript, `package.json` files and native binaries for linux x64 and arm64 (glibc), which the runtime loads with `dlopen`. A host keeps it next to the server module and must not mount it `noexec` (an add-on there then fails with `failed to map segment from shared object`). Its binaries link nothing but glibc, `libstdc++.so.6`, `libgcc_s.so.1` and libraries in the bundle itself, so the run image must have those three. Without `nodeModules`, the server module is the only file the runtime reads.
240
240
  - `migrations` is present only when the project has a `db/migrations` folder: its `.sql` files, which the runtime's `migrate` applies (see [Deploy](../guides/deploy.md)). A host never serves it.
@@ -551,7 +551,7 @@ Builds the project in the current directory as an iOS or Android app with Capaci
551
551
  - `build` makes a signed release, an `.aab` (Android) or `.ipa` (iOS), and copies it to `--out`, which ignores itself in git when the command creates it, as `<appId>-<version>-<build number>`. Android signs through Gradle with the keystore, alias and passwords in `PROTOBASE_ANDROID_KEYSTORE`, `PROTOBASE_ANDROID_KEY_ALIAS`, `PROTOBASE_ANDROID_KEYSTORE_PASSWORD` and `PROTOBASE_ANDROID_KEY_PASSWORD`; iOS runs Capacitor's build with `--team`, and `--certificate` with `--profile` for manual signing.
552
552
  - A release calls an https server that is not this machine, and `--app-version` (one to three numbers) and `--build-number` (1 to 2100000000) are required.
553
553
  - npm and Capacitor get the CLI's environment without any variable named in the current directory's `.env*` files, nor the four `PROTOBASE_ANDROID_*` signing variables, which only Gradle gets, and with `CI=true`, which keeps Capacitor's telemetry off.
554
- - It prints the workspace, the API origin and the native fingerprint, which the app also sends in its user agent as `ProtobaseNative/<fingerprint>`: a hash of the native packages `@protobase/mobile` pins, at their versions, and the section's `plugins`, at the versions they give. A [mobile release](#mobile-releases) runs only on a binary of its own fingerprint. A Protobase release that pins the same native packages keeps it; raise a plugin's version when the app's files start using a newer native feature of it, which changes it.
554
+ - It prints the workspace, the API origin and the native fingerprint, which the app also sends in its user agent as `ProtobaseNative/<fingerprint>`: a hash of the native packages `@protobase/mobile` pins, at their versions, its own native contract, and the section's `plugins`, at the versions they give. A [mobile release](#mobile-releases) runs only on a binary of its own fingerprint. A Protobase release that pins the same native packages and keeps the same native contract keeps it; raise a plugin's version when the app's files start using a newer native feature of it, which changes it.
555
555
  - The app's files carry the live updater's manifest of them, so an update downloads only the files that changed.
556
556
 
557
557
  ## `token`