@protobase/cli 0.119.6 → 0.120.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.
@@ -56,7 +56,7 @@ const buildBundlePlugins = async ({ projectDir, publicDir, extensions, styles =
56
56
  name: manifest.name,
57
57
  path: `${folder}/${pluginManifestFile}`,
58
58
  api: manifest.api,
59
- protobase: manifest.protobase,
59
+ ...manifest.protobase && { protobase: manifest.protobase },
60
60
  ...manifest.fields && { fields: manifest.fields }
61
61
  });
62
62
  }
@@ -4,7 +4,8 @@ import { uiPackageDir } from "../project/admin-app.js";
4
4
  import { extensionImports } from "../project/extensions.js";
5
5
  import { bundledImports } from "../project/bundled-imports.js";
6
6
  import { sharedModules } from "../project/shared-modules.js";
7
- import { pluginFieldTypes } from "./plugin-fields.js";
7
+ import { readPluginConfig } from "./plugin-config.js";
8
+ import { sharedImports } from "./shared-imports.js";
8
9
  import { layerPluginUtilities } from "./plugin-styles.js";
9
10
  import { firstPartyCode } from "./first-party-code.js";
10
11
  import { createRequire } from "node:module";
@@ -26,9 +27,9 @@ const targetUiDir = (pluginDir, projectDir, bundled) => {
26
27
  return findPackageDirSync("@protobase/ui", pluginDir) ?? (projectDir === void 0 ? void 0 : findPackageDirSync("@protobase/ui", projectDir)) ?? uiPackageDir;
27
28
  };
28
29
  /**
29
- * What the plugin is built for, from its @protobase/ui (see `targetUiDir`): its plugin API, and Protobase from its
30
- * version on, unless the plugin's package.json names other versions in `engines.protobase`. Also that version's theme,
31
- * which the plugin's stylesheet draws with, and its folder.
30
+ * What the plugin is built for, from its @protobase/ui (see `targetUiDir`): its plugin API, and the Protobase versions
31
+ * the plugin's package.json names in `engines.protobase`, if any. Also that version's theme, which the plugin's
32
+ * stylesheet draws with, and its folder.
32
33
  */
33
34
  const pluginTarget = async (pluginDir, own, projectDir, bundled) => {
34
35
  const uiDir = targetUiDir(pluginDir, projectDir, bundled);
@@ -36,8 +37,8 @@ const pluginTarget = async (pluginDir, own, projectDir, bundled) => {
36
37
  const api = ui.protobase?.pluginApi;
37
38
  const theme = ui.exports?.["./theme.css"];
38
39
  if (api === void 0 || typeof theme !== "string") throw new Error(`@protobase/ui ${ui.version} loads no plugins; install a version that does`);
39
- const protobase = own.engines?.protobase ?? `>=${ui.version}`;
40
- if (inRange(ui.version ?? "", protobase) === void 0) throw new Error(`engines.protobase "${protobase}" is not a range the app reads; write comparators such as >=0.12.0 <1.0.0`);
40
+ const protobase = own.engines?.protobase;
41
+ if (protobase !== void 0 && inRange(ui.version ?? "", protobase) === void 0) throw new Error(`engines.protobase "${protobase}" is not a range the app reads; write comparators such as >=0.12.0 <1.0.0`);
41
42
  return {
42
43
  api,
43
44
  protobase,
@@ -153,18 +154,24 @@ const buildPlugin = async ({ pluginDir, outDir, name, projectDir, ignore = [], s
153
154
  const module = output.find((file) => file.type === "chunk" && file.isEntry && file.facadeModuleId === entry);
154
155
  const css = output.find((file) => file.type === "asset" && file.fileName.endsWith(".css"));
155
156
  if (!module || !css) throw new Error("The plugin build wrote no module or no stylesheet");
156
- const fields = stylesOnly ? {} : await pluginFieldTypes({
157
+ const { fields, extensionPoints } = stylesOnly ? {
158
+ fields: {},
159
+ extensionPoints: []
160
+ } : await readPluginConfig({
157
161
  pluginDir,
158
162
  entry,
159
163
  uiDir: target.uiDir,
160
164
  projectDir,
161
165
  bundled
162
166
  });
167
+ const chunks = output.flatMap((file) => file.type === "chunk" ? [file] : []);
163
168
  const manifest = {
164
169
  name: pluginName,
165
170
  ...own.version && { version: own.version },
166
171
  api: target.api,
167
- protobase: target.protobase,
172
+ ...target.protobase !== void 0 && { protobase: target.protobase },
173
+ imports: sharedImports(chunks),
174
+ extensionPoints,
168
175
  entry: module.fileName,
169
176
  css: css.fileName,
170
177
  ...Object.keys(fields).length > 0 && { fields }
@@ -7,41 +7,46 @@ import path from "node:path";
7
7
  import { pathToFileURL } from "node:url";
8
8
  import { mkdtemp, rm } from "node:fs/promises";
9
9
  import { tmpdir } from "node:os";
10
- //#region src/build/plugin-fields.ts
11
- const fieldsCode = (entry) => [
10
+ //#region src/build/plugin-config.ts
11
+ const configCode = (entry) => [
12
12
  `import * as ui from ${JSON.stringify(entry)}`,
13
- `import { mergeUi, uiFromModule } from '@protobase/ui'`,
14
- "const { fields = {} } = mergeUi(uiFromModule(ui))",
15
- "export default Object.fromEntries(Object.entries(fields).map(([name, type]) => [name, type.of]))",
13
+ `import * as protobaseUi from '@protobase/ui'`,
14
+ "const merged = protobaseUi.mergeUi(protobaseUi.uiFromModule(ui))",
15
+ "const { fields = {} } = merged",
16
+ "export default {",
17
+ " fields: Object.fromEntries(Object.entries(fields).map(([name, type]) => [name, type.of])),",
18
+ " extensionPoints: protobaseUi.extensionPointsOf?.(merged),",
19
+ "}",
16
20
  ""
17
21
  ].join("\n");
18
- const fieldsEntry = (file, code) => ({
19
- name: "protobase-plugin-fields",
22
+ const configEntry = (file, code) => ({
23
+ name: "protobase-plugin-config",
20
24
  resolveId: (id) => id === file ? `\0${file}` : void 0,
21
25
  load: (id) => id === `\0${file}` ? code : void 0
22
26
  });
23
27
  const sharedFromUi = (uiDir) => {
24
28
  const require = createRequire(path.join(uiDir, "package.json"));
25
29
  return {
26
- name: "protobase-plugin-fields-shared",
30
+ name: "protobase-plugin-config-shared",
27
31
  enforce: "pre",
28
32
  resolveId: (id) => id === "@protobase/ui" || !sharedModules.includes(id) ? void 0 : require.resolve(id)
29
33
  };
30
34
  };
31
- const isStorageTypes = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
35
+ const isNames = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
32
36
  /**
33
37
  * The field types a plugin registers (`definePlugin({ fields })`), each with the storage types it shows (`of`), which
34
- * the server checks the views against at startup. The plugin's module is loaded once in Node, everything bundled into
38
+ * the server checks the views against at startup, and the extension points it fills, which the app checks it has
39
+ * before it loads the plugin (see `extensionPointsOf` in @protobase/ui). The plugin's module is loaded once in Node, everything bundled into
35
40
  * a scratch file, as `protobase build` loads a project's UI to check its names; nothing is rendered. A plugin of a
36
41
  * bundled project imports the CLI's @protobase packages, as its build does.
37
42
  */
38
- const pluginFieldTypes = async ({ pluginDir, entry, uiDir, projectDir, bundled = false }) => {
39
- const file = path.join(pluginDir, "protobase-plugin-fields.js");
40
- const scratch = await mkdtemp(path.join(tmpdir(), "protobase-plugin-fields-"));
41
- const outFile = path.join(scratch, "fields.mjs");
43
+ const readPluginConfig = async ({ pluginDir, entry, uiDir, projectDir, bundled = false }) => {
44
+ const file = path.join(pluginDir, "protobase-plugin-config.js");
45
+ const scratch = await mkdtemp(path.join(tmpdir(), "protobase-plugin-config-"));
46
+ const outFile = path.join(scratch, "config.mjs");
42
47
  try {
43
48
  const plugins = [
44
- fieldsEntry(file, fieldsCode(entry)),
49
+ configEntry(file, configCode(entry)),
45
50
  sharedFromUi(uiDir),
46
51
  ...bundled && projectDir !== void 0 ? [bundledImports([projectDir, pluginDir])] : [],
47
52
  ...projectDir === void 0 ? [] : [extensionImports(projectDir, [{ dir: pluginDir }])]
@@ -53,10 +58,14 @@ const pluginFieldTypes = async ({ pluginDir, entry, uiDir, projectDir, bundled =
53
58
  plugins,
54
59
  logLevel: "error"
55
60
  });
56
- const fields = (await import(pathToFileURL(outFile).href)).default;
57
- const wrong = Object.entries(fields).find(([, of]) => !isStorageTypes(of));
61
+ const { fields, extensionPoints } = (await import(pathToFileURL(outFile).href)).default;
62
+ const wrong = Object.entries(fields).find(([, of]) => !isNames(of));
58
63
  if (wrong) throw new Error(`The field type "${wrong[0]}" names no storage types it shows; give it of: ['integer'] or the like`);
59
- return fields;
64
+ if (!isNames(extensionPoints)) throw new Error(`The @protobase/ui in ${uiDir} does not name the extension points a plugin fills; install a version that does`);
65
+ return {
66
+ fields,
67
+ extensionPoints
68
+ };
60
69
  } finally {
61
70
  await rm(scratch, {
62
71
  recursive: true,
@@ -65,4 +74,4 @@ const pluginFieldTypes = async ({ pluginDir, entry, uiDir, projectDir, bundled =
65
74
  }
66
75
  };
67
76
  //#endregion
68
- export { pluginFieldTypes };
77
+ export { readPluginConfig };
@@ -0,0 +1,35 @@
1
+ import { sharedModules } from "../project/shared-modules.js";
2
+ import { parseAst } from "vite";
3
+ //#region src/build/shared-imports.ts
4
+ const isShared = (source) => typeof source === "string" && sharedModules.includes(source);
5
+ const takenName = (specifier) => {
6
+ if (specifier.type === "ImportDefaultSpecifier") return "default";
7
+ if (specifier.type === "ImportNamespaceSpecifier") return "*";
8
+ const taken = specifier.type === "ExportSpecifier" ? specifier.local : specifier.imported;
9
+ return taken?.name ?? taken?.value ?? "*";
10
+ };
11
+ const byNameOnly = "@protobase/ui";
12
+ /**
13
+ * The names a plugin's built chunks take from each module shared with plugins, sorted: what is left once the build
14
+ * has dropped unused code, from its imports, re-exports and `export *`, and `*` for a whole module it imports with
15
+ * `import * as` or `import()`. Taking @protobase/ui whole fails the build, since the app could not tell whether it
16
+ * has the names the plugin reads.
17
+ */
18
+ const sharedImports = (chunks) => {
19
+ const taken = /* @__PURE__ */ new Map();
20
+ const take = (module, name) => taken.set(module, (taken.get(module) ?? /* @__PURE__ */ new Set()).add(name));
21
+ for (const chunk of chunks) {
22
+ for (const module of chunk.dynamicImports.filter(isShared)) take(module, "*");
23
+ for (const node of parseAst(chunk.code).body) {
24
+ if (node.type !== "ImportDeclaration" && node.type !== "ExportNamedDeclaration" && node.type !== "ExportAllDeclaration") continue;
25
+ const source = node.source?.value;
26
+ if (!isShared(source)) continue;
27
+ if (node.type === "ExportAllDeclaration") take(source, "*");
28
+ else for (const specifier of node.specifiers) take(source, takenName(specifier));
29
+ }
30
+ }
31
+ if (taken.get(byNameOnly)?.has("*")) throw new Error(`The plugin takes all of ${byNameOnly} (import * as, export * or import()), so an app cannot check that it has what the plugin uses: import the names it uses instead, as in import { useList } from '${byNameOnly}'`);
32
+ return Object.fromEntries([...taken].sort(([a], [b]) => a < b ? -1 : 1).map(([module, names]) => [module, [...names].sort()]));
33
+ };
34
+ //#endregion
35
+ export { sharedImports };
@@ -17,7 +17,7 @@ const bundleMigrations = "migrations";
17
17
  const isStringList = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
18
18
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
19
19
  const isFieldTypes = (value) => isObject(value) && Object.values(value).every(isStringList);
20
- const isPlugin = (value) => isObject(value) && typeof value.name === "string" && typeof value.path === "string" && Number.isInteger(value.api) && typeof value.protobase === "string" && (value.fields === void 0 || isFieldTypes(value.fields));
20
+ const isPlugin = (value) => isObject(value) && typeof value.name === "string" && typeof value.path === "string" && Number.isInteger(value.api) && (value.protobase === void 0 || typeof value.protobase === "string") && (value.fields === void 0 || isFieldTypes(value.fields));
21
21
  const isShell = (value) => isObject(value) && typeof value.protobase === "string" && Number.isInteger(value.pluginApi) && isStringList(value.paths) && (value.builtAt === void 0 || isTime(value.builtAt));
22
22
  const isTime = (value) => Number.isSafeInteger(value) && value >= 0;
23
23
  const isVersions = (value) => isObject(value) && Object.values(value).every((item) => typeof item === "string");
@@ -27,7 +27,7 @@ const parseManifest = (value, file) => {
27
27
  if (manifest?.version !== 3) throw new Error(`${file} is not a version 3 bundle manifest; rebuild it with \`protobase build\``);
28
28
  const { builtAt, server, public: publicDir, api, spa, plugins, theme, shell, icons, native, mobile, nodeModules, migrations } = manifest;
29
29
  if (typeof server !== "string" || typeof publicDir !== "string" || typeof spa !== "string" || typeof theme !== "string" || !isStringList(api)) throw new Error(`${file} needs server, public, spa and theme paths and an api list`);
30
- if (!Array.isArray(plugins) || !plugins.every(isPlugin)) throw new Error(`${file} needs a plugins list, each with a name, path, api and protobase`);
30
+ if (!Array.isArray(plugins) || !plugins.every(isPlugin)) throw new Error(`${file} needs a plugins list, each with a name, path and api`);
31
31
  if (!isShell(shell)) throw new Error(`${file} needs a shell with its protobase version, pluginApi and paths`);
32
32
  if (builtAt !== void 0 && !isTime(builtAt)) throw new Error(`${file} has a builtAt that is no time in ms`);
33
33
  if (icons !== void 0 && !isIcons(icons)) throw new Error(`${file} has icons that are not a favicon flag and a list of PNG icons`);
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.119.6";
2
+ var version = "0.120.0";
3
3
  //#endregion
4
4
  export { version };
package/dist/main.js CHANGED
@@ -147,7 +147,7 @@ program.command("build-plugin").description("Build a plugin the admin app loads
147
147
  ...opts.name && { name: opts.name }
148
148
  });
149
149
  const shown = path.relative(process.cwd(), outDir);
150
- out(`built ${shown.startsWith("..") ? outDir : shown || "."}: ${pluginManifestFile}, ${manifest.entry} and ${manifest.css} (${manifest.name}, plugin API ${manifest.api}, Protobase ${manifest.protobase})\n`);
150
+ out(`built ${shown.startsWith("..") ? outDir : shown || "."}: ${pluginManifestFile}, ${manifest.entry} and ${manifest.css} (${manifest.name}, plugin API ${manifest.api}${manifest.protobase ? `, Protobase ${manifest.protobase}` : ""})\n`);
151
151
  });
152
152
  program.command("build-shell", { hidden: true }).description("Build the admin app every bundle shares, as @protobase/ui's package and the protobase image ship it").argument("<out>", "output folder").option("--source-maps <dir>", "end each script with a //# debugId= comment and write its source map, carrying the same id, to this folder").action(async (outDir, opts) => {
153
153
  const { buildShell } = await import("./build/shell.js");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.119.6",
3
+ "version": "0.120.0",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -43,13 +43,13 @@
43
43
  "dependencies": {
44
44
  "@better-auth/core": "^1.7.12",
45
45
  "@hono/node-server": "^2.1.3",
46
- "@protobase/config": "0.119.6",
47
- "@protobase/layout": "0.119.6",
48
- "@protobase/query": "0.119.6",
49
- "@protobase/schema": "0.119.6",
50
- "@protobase/server": "0.119.6",
51
- "@protobase/ui": "0.119.6",
52
- "@protobase/workflows": "0.119.6",
46
+ "@protobase/config": "0.120.0",
47
+ "@protobase/layout": "0.120.0",
48
+ "@protobase/query": "0.120.0",
49
+ "@protobase/schema": "0.120.0",
50
+ "@protobase/server": "0.120.0",
51
+ "@protobase/ui": "0.120.0",
52
+ "@protobase/workflows": "0.120.0",
53
53
  "@react-email/render": "^2.1.0",
54
54
  "@scalar/hono-api-reference": "^0.12.10",
55
55
  "@sentry/vite-plugin": "^11.10.0",
@@ -23,7 +23,8 @@ React components, field types, pages and handlers of your own, loaded as plugins
23
23
  - [Shell slots](../reference/custom-components.md#shell-slots): Your own components in the top bar, in a panel beside every page, or as the sidebar logo.
24
24
  - [Plugins](../reference/plugins.md#how-a-plugin-stays-working): Your React code is a plugin that the app loads at start and that keeps working across Protobase releases without changes.
25
25
  - [Plugin settings](../reference/plugins.md#loading): Plugins are loaded from the config, limited to roles and given settings.
26
- - [Plugin fallbacks](../reference/plugins.md#when-a-plugin-is-off): A plugin that fails or does not fit the version is turned off alone, and admins see why.
26
+ - [Plugins load where the app has what they use](../reference/plugins.md#versions): The plugin build records the Protobase exports and extension points a plugin needs, and an app turns a plugin off when one is missing, naming it, rather than for its version; the plugin API and a range the plugin names itself still count.
27
+ - [Plugin fallbacks](../reference/plugins.md#when-a-plugin-is-off): A plugin that fails or does not fit the app is turned off alone, and admins see why.
27
28
  - [Before sign-in](../reference/plugins.md#before-sign-in): A plugin can run around the sign-in page, for example to sign someone in from a link.
28
29
  - [Unstable modules](../reference/plugins.md#the-unstable-entry): UI with its own build imports any module of the app's UI, without a promise that it stays the same, instead of copying it.
29
30
  - [Focus page parts](../reference/custom-components.md#focus-pages) (beta): Fill a focus page's bar, notice and side panels from your own surface or component, with the record's draft and Save from the framework.
@@ -77,17 +77,18 @@ bun run protobase build-plugin
77
77
  ```
78
78
 
79
79
  ```
80
- built dist: plugin.json, assets/index-DDnoullN.js and assets/styles-CToS5pKa.css (sales-tools, plugin API 1, Protobase >=0.11.1)
80
+ built dist: plugin.json, assets/index-DDnoullN.js and assets/styles-CToS5pKa.css (sales-tools, plugin API 1)
81
81
  ```
82
82
 
83
- `dist/assets/index-<hash>.js` is the plugin's module: its own code, with `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui` left as imports for the app to supply. `styles-<hash>.css` holds the utilities its classes use, and nothing else. `plugin.json` names both, the plugin API they are built for and the Protobase versions they run on:
83
+ `dist/assets/index-<hash>.js` is the plugin's module: its own code, with `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui` left as imports for the app to supply. `styles-<hash>.css` holds the utilities its classes use, and nothing else. `plugin.json` names both, the plugin API they are built for and what the plugin uses from the app, which the app checks it has before it loads the plugin:
84
84
 
85
85
  ```json
86
86
  {
87
87
  "name": "sales-tools",
88
88
  "version": "1.0.0",
89
89
  "api": 1,
90
- "protobase": ">=0.11.1",
90
+ "imports": { "@protobase/ui": ["RecordLink", "definePlugin", "useList", "usePlugin"], "react/jsx-runtime": ["jsx", "jsxs"] },
91
+ "extensionPoints": ["components"],
91
92
  "entry": "assets/index-DDnoullN.js",
92
93
  "css": "assets/styles-CToS5pKa.css"
93
94
  }
@@ -163,4 +164,4 @@ Put `dist/` on a static host, and list its `plugin.json` in the deployed app's `
163
164
 
164
165
  The app updates to a new release of Protobase. Nothing happens to the plugin: within plugin API 1, every release keeps what the plugin imports, and the plugin runs on the newer `@protobase/ui` it is handed, its fixes included.
165
166
 
166
- If the app were older than the plugin needs, it would not load the plugin at all. Its admins would see a notice below the top bar, such as "The plugin sales-tools is off: it needs Protobase >=0.12.0, and this app runs 0.11.1.", and the card would show a warning in place of the drafts, while the rest of the app works as before. [Versions](../reference/plugins.md#versions) has the rules.
167
+ If the app lacked something the plugin uses, such as an export of `@protobase/ui` from a newer release, it would not load the plugin at all. Its admins would see a notice below the top bar naming what is missing, such as "The plugin sales-tools is off: it uses what this app does not have: useList from @protobase/ui.", and the card would show a warning in place of the drafts, while the rest of the app works as before. [Versions](../reference/plugins.md#versions) has the rules.
@@ -62,4 +62,4 @@ Nothing changes: `protobase dev` builds `protobase.ui.tsx` into its page with ho
62
62
 
63
63
  ## After the move
64
64
 
65
- From now on, a release of Protobase within the same minor needs no rebuild of the project's UI: the app it runs in is the release's, and the plugin keeps working within its [plugin API](../reference/plugins.md#versions). The server config runs on the runtime the project is pinned to (see [Bundles and runtimes](../reference/versioning.md#bundles-and-runtimes)), so moving the pin to a new minor below 1.0 is still a rebuild.
65
+ From now on, a release of Protobase within the same minor needs no rebuild of the project's UI: the app it runs in is the release's, and the plugin keeps working within its [plugin API](../reference/plugins.md#versions). A plugin built on a newer release also loads in an app on an older one, as long as that app is on the plugin's plugin API, has every export and extension point the plugin uses, and is in the `engines.protobase` range of the plugin's `package.json` when it names one. The server config runs on the runtime the project is pinned to (see [Bundles and runtimes](../reference/versioning.md#bundles-and-runtimes)), so moving the pin to a new minor below 1.0 is still a rebuild.
@@ -282,7 +282,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
282
282
  "api": ["/api", "/.well-known/oauth-authorization-server", "/.well-known/oauth-protected-resource", "/.well-known/openid-configuration"],
283
283
  "theme": "protobase.theme.css",
284
284
  "plugins": [
285
- { "name": "app", "path": "plugins/app/plugin.json", "api": 1, "protobase": ">=0.12.0", "fields": { "steps": ["enum"] } }
285
+ { "name": "app", "path": "plugins/app/plugin.json", "api": 1, "fields": { "steps": ["enum"] } }
286
286
  ],
287
287
  "shell": { "protobase": "0.12.0", "pluginApi": 1, "paths": ["/index.html", "/assets", "/protobase.sw.js"] },
288
288
  "native": { "@capacitor/core": "8.5.3", "@capacitor/ios": "8.5.3" },
@@ -294,7 +294,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
294
294
 
295
295
  - `protobase` is the Protobase version of the copies the build used: the building CLI's own in a bundled project, and in a locked one the `@protobase` packages its lockfile installed, whichever CLI built the bundle. A host serves the bundle on the runtime of that version (see [Versioning](versioning.md#bundles-and-runtimes)). A bundled project needs nothing installed; a locked one fails without its `@protobase` packages installed.
296
296
  - `server`, `public`, `nodeModules` and `migrations` are relative to the bundle folder; `spa`, `theme` and each plugin's `path` to `public`.
297
- - `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.
297
+ - `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 it is built for, the Protobase versions it is limited to only when its `package.json` names some, 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.
298
298
  - `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 may serve its own for those paths instead (see [The UI](#the-ui)), so the app gets that release's fixes without a rebuild.
299
299
  - `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.
300
300
  - `mobile` is present only when the project's config has a `mobile` section, so a host learns that the app has a mobile build without running the config: the section's `appId`, which the statement of a signed mobile release binds, its `plugins`, name to the spec it gives, `{}` when it gives none, and `push`, whether the config has [`notifications()`](notifications.md), with which the binaries compile native push in; the fingerprint of the mobile release names both besides `native`. A bundle built before it names no `appId`, and one built before `push` none, which counts as `false`. The build checks the section as `protobase mobile` does.
@@ -422,7 +422,7 @@ dist/
422
422
  - The output folder is emptied first, so it must not be the plugin's folder or hold it.
423
423
  - The module is `protobase.ui.tsx` with everything it imports bundled, except the four modules the app shares (`react`, `react/jsx-runtime`, `react-dom`, `@protobase/ui`), which stay imports by those names. Any other module of those packages, such as `react-dom/client`, fails the build. React's production build and JSX runtime are used, whatever `NODE_ENV` says, and every export of `protobase.ui.tsx` is kept.
424
424
  - The stylesheet is Tailwind's utilities for the classes in the plugin's folder: no reset, no theme values. Each utility reads the theme of the app that loads it, with Tailwind's default as the fallback (`text-sm` is `font-size: var(--text-sm, 0.875rem)`).
425
- - `plugin.json` names the plugin (`--name`, else its `package.json`'s `name`, else its folder's), its own `version`, the plugin API (`api`) and the Protobase versions (`protobase`) it is built for, the module (`entry`) and stylesheet (`css`), relative to it, and the [field types](plugins.md#field-types) it registers (`fields`), each with the storage types it shows. Both versions come from the `@protobase/ui` installed for the plugin, else for the project it extends, else the CLI's own: `api` is its plugin API, and `protobase` is `>=` its version unless the plugin's `package.json` names a range in `engines.protobase` (see [Plugins](plugins.md#versions)).
425
+ - `plugin.json` names the plugin (`--name`, else its `package.json`'s `name`, else its folder's), its own `version`, the plugin API it is built for (`api`), what it uses (`imports` and `extensionPoints`), the Protobase versions its `package.json` names in `engines.protobase`, if any (`protobase`), the module (`entry`) and stylesheet (`css`), relative to it, and the [field types](plugins.md#field-types) it registers (`fields`), each with the storage types it shows. `api` and the extension points come from the `@protobase/ui` installed for the plugin, else for the project it extends, else the CLI's own (see [Plugins](plugins.md#versions)).
426
426
  - `--source-maps` ends each script with a `//# debugId=<uuid>` comment, naming no map, and writes its source map, `<script>.js.map` carrying the same `debugId`, beside it, for an error tracker to read the browser's stack frames with.
427
427
 
428
428
  To read its field types, the build loads the plugin's module once in Node, with everything bundled; nothing is rendered, but code at the top level of its modules runs, so keep browser-only work (`window`, `document`) inside components and handlers. The app loads it from wherever `plugin.json` is served, listed in `PROTOBASE_PLUGINS` or the config's `plugins` (see [loading](plugins.md#loading)).
@@ -25,7 +25,7 @@ Code built together with the app is frozen at the app it was built with: a newer
25
25
  1. **The app is built once per release.** The admin app, the shell, is the same for every project. Each release of `@protobase/ui` ships it prebuilt, and `protobase build` copies it into the bundle beside the project's plugins and theme. A host that has the shell of a newer release can serve that one in its place (see [the shell](#the-shell)), so an app gets the release's fixes without a rebuild of its own code.
26
26
  2. **The app shares its modules.** The admin app hands four modules to plugins: `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui`. Its `index.html` maps those names to the app's own files with an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap), so a plugin's `import { useList } from '@protobase/ui'` runs on the app's copy: one React, one query cache, one signed-in session and the app's version of every hook and component. A plugin carries only its own code, and gets the fixes of every release the app moves to.
27
27
  3. **The plugin API is a promise.** What a plugin can import, the four modules and every export of `@protobase/ui`, is the plugin API, numbered: `pluginApi` is 1. Releases add to it but never remove or change what is in it; only a new plugin API does, as for a new major version of React. So a plugin keeps working on every release of the plugin API it was built for, with no rebuild. Below 1.0 a minor release may change how a project's config is written, but not the plugin API.
28
- 4. **The app checks before it loads.** A plugin's `plugin.json` says which plugin API and which Protobase versions it is built for. The app loads a plugin only when it has that plugin API and its own version is in the plugin's range; it never runs the code of one that does not fit.
28
+ 4. **The app checks before it loads.** A plugin's `plugin.json` says which plugin API it is built for and what it uses: the names it imports from the shared modules and the extension points it fills. The app loads a plugin only when it has that plugin API and everything the plugin uses, whichever release built the plugin; it never runs the code of one that does not fit.
29
29
  5. **A plugin that does not fit is turned off, not the app.** Each place it would fill draws a fallback, the app's admins see why it is off, and everything else works as before. A component that throws while drawing shows its fallback in its own place.
30
30
  6. **The look is values, not rules.** A project themes the app with a [`protobase.theme.css`](theme.md) that holds only values of the app's tokens, and a plugin's stylesheet holds only utilities that read those tokens. Neither reaches into the app's markup, so neither breaks when the app's markup changes.
31
31
 
@@ -72,7 +72,7 @@ export default definePlugin({ name: 'sales-tools', actions: { remindCustomer } }
72
72
 
73
73
  It is written as a project's `protobase.ui.tsx` is: each component exported under the PascalCase name the config declares, from a file of its own, and the rest in the default export, `definePlugin({ name, actions, fields, shell, beforeSignIn, extends, ... })` (`defineUi` is the same function), with the keys of [Extension points](#extension-points). Its components use the hooks and components of `@protobase/ui`, which read the API as the signed-in user, under the same access rules as everything else.
74
74
 
75
- **Imports.** `react`, `react/jsx-runtime` (the JSX), `react-dom` and `@protobase/ui`, by those names, come from the app. Everything else a plugin imports, its own files, icons or a chart library, is built into it. Other modules of those packages, such as `react-dom/client` or a file inside `@protobase/ui`, fail the build: a copy of its own would not work with the app's. Read data with `@protobase/ui`'s hooks (`useList`, `useRecord`, `useClient`), which share the app's cache: a data library of the plugin's own keeps a cache of its own. For anything else, such as another API's answer, `useQuery` and `useQueryClient` from `@protobase/ui` are TanStack Query's, on the app's own client, so their answers are kept in the [start cache](installable-app.md#starting-from-the-last-pages-seen) and draw on the next start before the network answers.
75
+ **Imports.** `react`, `react/jsx-runtime` (the JSX), `react-dom` and `@protobase/ui`, by those names, come from the app. Everything else a plugin imports, its own files, icons or a chart library, is built into it. Other modules of those packages, such as `react-dom/client` or a file inside `@protobase/ui`, fail the build: a copy of its own would not work with the app's. So does taking all of `@protobase/ui` at once (`import * as`, `export *` or `import()`), since the app could not check that it has the names the plugin reads: import them by name. Read data with `@protobase/ui`'s hooks (`useList`, `useRecord`, `useClient`), which share the app's cache: a data library of the plugin's own keeps a cache of its own. For anything else, such as another API's answer, `useQuery` and `useQueryClient` from `@protobase/ui` are TanStack Query's, on the app's own client, so their answers are kept in the [start cache](installable-app.md#starting-from-the-last-pages-seen) and draw on the next start before the network answers.
76
76
 
77
77
  **Styling.** Use Tailwind classes, as the app's own code does. The plugin's stylesheet holds the utilities its files use and nothing else, no reset and no global style, and each reads the app's [tokens](theme.md): `bg-primary` is the app's primary color and `rounded-md` its radius, whatever the app's version and whatever its theme, and a token the app does not set falls back to Tailwind's default.
78
78
 
@@ -233,7 +233,8 @@ The output folder is emptied first, so it must not hold the plugin's own files.
233
233
  "name": "sales-tools",
234
234
  "version": "1.0.0",
235
235
  "api": 1,
236
- "protobase": ">=0.12.0",
236
+ "imports": { "@protobase/ui": ["definePlugin", "useList"], "react/jsx-runtime": ["jsx", "jsxs"] },
237
+ "extensionPoints": ["components", "fields"],
237
238
  "entry": "assets/index-DDnoullN.js",
238
239
  "css": "assets/styles-CToS5pKa.css",
239
240
  "fields": { "steps": ["enum"] }
@@ -245,7 +246,9 @@ The output folder is emptied first, so it must not hold the plugin's own files.
245
246
  | `name` | The plugin's name: `--name`, else its `package.json`'s `name`, else its folder's. A project's own is `app`. |
246
247
  | `version` | Its `package.json`'s `version`, when it has one. |
247
248
  | `api` | The plugin API of the `@protobase/ui` it is built with. |
248
- | `protobase` | The Protobase versions it runs on: from that `@protobase/ui`'s version on, unless its `package.json` says otherwise (see [versions](#versions)). |
249
+ | `imports` | The names its built code imports from each module the app shares, `*` for a whole module of React (`import * as`, `import()`); code the build leaves out does not count (see [versions](#versions)). |
250
+ | `extensionPoints` | The [extension points](#extension-points) it fills, such as `components` or `shell.rightPanel`. |
251
+ | `protobase` | The Protobase versions its `package.json` names in `engines.protobase`, only when it names some (see [versions](#versions)). |
249
252
  | `entry`, `css` | The module and the stylesheet, relative to `plugin.json`. |
250
253
  | `fields` | The field types it registers, each with the storage types it shows. Only when it registers some. |
251
254
 
@@ -345,18 +348,23 @@ A host that keeps the shells of its releases can serve the shell of a newer one
345
348
 
346
349
  ## Versions
347
350
 
348
- A plugin is built for one plugin API and a range of Protobase versions, both written by `build-plugin` into `plugin.json`:
351
+ A plugin is built for one plugin API and records what it uses, both written by `build-plugin` into `plugin.json`:
349
352
 
350
353
  - `api` is the plugin API of the `@protobase/ui` installed for the plugin, else the CLI's own (always the CLI's for the UI of a bundled project).
351
- - `protobase` is `>=` that `@protobase/ui`'s version: the plugin may use anything that version has. To run on older releases too, name the range in the plugin's `package.json`:
354
+ - `imports` names what the plugin's built code imports from `react`, `react/jsx-runtime`, `react-dom` and `@protobase/ui`, read from the build's output, so an import only an unused file or a re-export nobody reads makes is not in it, and one its own files make is.
355
+ - `extensionPoints` names the extension points its config fills, as that `@protobase/ui` reads them.
352
356
 
353
- ```json
354
- { "engines": { "protobase": ">=0.12.0" } }
355
- ```
357
+ The app loads a plugin when the plugin's `api` is its own and it has every name in `imports` and every extension point in `extensionPoints`, whatever its version; only a plugin that names a `protobase` range also needs the app's version in it. A plugin built with a newer `@protobase/ui` loads in an app on an older release that checks what plugins use, as long as the older release has what the plugin uses; when something is missing, the plugin stays off and its notice names what, such as "it uses what this app does not have: NewPicker from @protobase/ui, the extension point shell.bell". Releases from before that check compare versions only: they need a `protobase` range in `plugin.json`, turn off a plugin without one, and do not read `imports` or `extensionPoints`.
356
358
 
357
- A range is comparators separated by spaces, all of which must hold: `>=`, `>`, `<=`, `<` or `=` and an `x.y.z` version, such as `>=0.12.0 <2.0.0`. The build checks only the range's form; which versions it holds is the app's to compare when it loads the plugin, where a prerelease such as a build from main counts too, just before its own release: `0.94.4-main.4f8859dd` is in `>=0.12.9`, and `0.13.0-main.4f8859dd` is in `<0.13.0` but not in `>=0.13.0`. If the plugin uses something an older release in its range does not have, it fails to load there and is turned off, as described below.
359
+ A plugin author who wants to limit the plugin to some releases anyway names a range in its `package.json`, which the build copies into `plugin.json` as `protobase`:
358
360
 
359
- The app loads a plugin when the plugin's `api` is its own and its version is in the plugin's `protobase` range. Protobase keeps the plugin API through its releases and starts a new one only when a plugin built for the old one could break:
361
+ ```json
362
+ { "engines": { "protobase": ">=0.12.0 <2.0.0" } }
363
+ ```
364
+
365
+ The app then also needs its version in that range. A range is comparators separated by spaces, all of which must hold: `>=`, `>`, `<=`, `<` or `=` and an `x.y.z` version. The build checks only the range's form; which versions it holds is the app's to compare when it loads the plugin, where a prerelease such as a build from main counts too, just before its own release: `0.94.4-main.4f8859dd` is in `>=0.12.9`, and `0.13.0-main.4f8859dd` is in `<0.13.0` but not in `>=0.13.0`.
366
+
367
+ Protobase keeps the plugin API through its releases and starts a new one only when a plugin built for the old one could break:
360
368
 
361
369
  - an export of `@protobase/ui` removed, or changed in a way its users would notice;
362
370
  - an extension point's props changed in a way a plugin would notice;
@@ -371,10 +379,11 @@ Nothing a plugin does stops the app. Each of these turns off that plugin alone:
371
379
 
372
380
  - its `plugin.json` cannot be read, or is not one;
373
381
  - it is built for another plugin API, or for a range without the app's version;
382
+ - it uses an export, a shared module or an extension point the app does not have;
374
383
  - its module cannot be loaded, or does not link: it imports something the app's `@protobase/ui` does not have;
375
384
  - it defines a name an earlier plugin defines.
376
385
 
377
- Every place it would fill then draws its fallback (see [Extension points](#extension-points)). The app's admins (the `admin` role) see a notice below the top bar naming each plugin that is off and why, such as "The plugin sales-tools is off: it needs Protobase >=0.12.3, and this app runs 0.12.1." Everyone else sees only the fallbacks. An action handler that throws shows its error in a toast, as a project's does, and a part that throws while drawing shows its fallback in its own place.
386
+ Every place it would fill then draws its fallback (see [Extension points](#extension-points)). The app's admins (the `admin` role) see a notice below the top bar naming each plugin that is off and why, such as "The plugin sales-tools is off: it uses what this app does not have: NewPicker from @protobase/ui." Everyone else sees only the fallbacks. An action handler that throws shows its error in a toast, as a project's does, and a part that throws while drawing shows its fallback in its own place.
378
387
 
379
388
  ## API
380
389
 
@@ -87,7 +87,7 @@ Nothing else compares versions: not the build, not the serve runtime. `protobase
87
87
 
88
88
  ## Plugins
89
89
 
90
- [Plugins](plugins.md) are versioned by a plugin API of their own: `@protobase/ui`'s `pluginApi`, 1 so far. A plugin's `plugin.json` names the plugin API it is built for and a range of Protobase versions, from the `@protobase/ui` it is built with on. An app loads a plugin of its own plugin API whose range holds its version, and turns off any other, telling its admins why.
90
+ [Plugins](plugins.md) are versioned by a plugin API of their own: `@protobase/ui`'s `pluginApi`, 1 so far. A plugin's `plugin.json` names the plugin API it is built for and what it uses: the names it imports from the modules the app shares and the extension points it fills. An app loads a plugin of its own plugin API when it has everything the plugin uses, whichever release built it, and turns off any other, telling its admins what is missing. A plugin whose author names a range of Protobase versions (`engines.protobase`) also needs the app's version in it (see [versions](plugins.md#versions)).
91
91
 
92
92
  A project's own `protobase.ui.tsx` is a plugin of its bundle, so the same rule holds for it. The admin app it runs in, the shell, is prebuilt once per release; a host that serves a newer release's shell for a bundle whose plugins all load in it gives the app that release's fixes without a rebuild (see [the shell](plugins.md#the-shell)).
93
93