@protobase/cli 0.33.1 → 0.33.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.
@@ -30,7 +30,7 @@ const sources = async (projectDir, extensions) => {
30
30
  * Builds the project's protobase.ui.tsx and each extension's as a plugin under `publicDir`/plugins/<name>/, as
31
31
  * `protobase build-plugin` builds one: the app loads them like any other, from what `/meta` names.
32
32
  */
33
- const buildBundlePlugins = async ({ projectDir, publicDir, extensions, ignore }) => {
33
+ const buildBundlePlugins = async ({ projectDir, publicDir, extensions, ignore, sourceMaps }) => {
34
34
  const plugins = [];
35
35
  for (const source of await sources(projectDir, extensions)) {
36
36
  const folder = path.join(pluginsFolder, folderOf(source.name));
@@ -39,7 +39,8 @@ const buildBundlePlugins = async ({ projectDir, publicDir, extensions, ignore })
39
39
  outDir: path.join(publicDir, folder),
40
40
  name: source.name,
41
41
  projectDir,
42
- ignore
42
+ ignore,
43
+ sourceMaps
43
44
  });
44
45
  plugins.push({
45
46
  name: manifest.name,
@@ -23,8 +23,8 @@ const removeOwnNodeModules = async (outDir) => {
23
23
  force: true
24
24
  });
25
25
  };
26
- const copyShell = async (publicDir) => {
27
- const { dir, shell, scratch } = await shellForBuild();
26
+ const copyShell = async (publicDir, sourceMaps) => {
27
+ const { dir, sourceMapsDir, shell, scratch } = await shellForBuild(sourceMaps);
28
28
  try {
29
29
  await rm(publicDir, {
30
30
  recursive: true,
@@ -34,15 +34,16 @@ const copyShell = async (publicDir) => {
34
34
  recursive: true,
35
35
  filter: (file) => path.basename(file) !== shellManifestFile
36
36
  });
37
+ if (sourceMapsDir) await cp(sourceMapsDir, publicDir, { recursive: true });
37
38
  } finally {
38
- if (scratch) await rm(dir, {
39
+ if (scratch) await rm(scratch, {
39
40
  recursive: true,
40
41
  force: true
41
42
  });
42
43
  }
43
44
  return shell;
44
45
  };
45
- const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], onWarning }) => {
46
+ const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], sourceMaps = false, onWarning }) => {
46
47
  await removeOwnNodeModules(outDir);
47
48
  const components = /* @__PURE__ */ new Set();
48
49
  const native = await buildConfigBundle({
@@ -56,12 +57,13 @@ const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], onW
56
57
  await checkUi(projectDir, extensions, components);
57
58
  const packages = native.length > 0 ? await copyPackages(native, path.join(outDir, bundleNodeModules)) : [];
58
59
  const publicDir = path.join(outDir, bundleLayout.public);
59
- const shell = await copyShell(publicDir);
60
+ const shell = await copyShell(publicDir, sourceMaps);
60
61
  const plugins = await buildBundlePlugins({
61
62
  projectDir,
62
63
  publicDir,
63
64
  extensions,
64
- ignore: [outDir, path.join(projectDir, protobaseFolder)]
65
+ ignore: [outDir, path.join(projectDir, protobaseFolder)],
66
+ sourceMaps
65
67
  });
66
68
  for (const warning of await buildTheme({
67
69
  projectDir,
@@ -91,7 +91,7 @@ const checkOutDir = (pluginDir, outDir) => {
91
91
  * shared modules by name, its stylesheet, and plugin.json naming both and the field types it registers. The app loads
92
92
  * it from the plugin.json's URL.
93
93
  */
94
- const buildPlugin = async ({ pluginDir, outDir, name, projectDir, ignore = [] }) => {
94
+ const buildPlugin = async ({ pluginDir, outDir, name, projectDir, ignore = [], sourceMaps = false }) => {
95
95
  const entry = path.join(pluginDir, pluginEntryFile);
96
96
  if (!existsSync(entry)) throw new Error(`There is no ${pluginEntryFile} in ${pluginDir}; a plugin exports its components and action handlers from it`);
97
97
  checkOutDir(pluginDir, outDir);
@@ -117,10 +117,12 @@ const buildPlugin = async ({ pluginDir, outDir, name, projectDir, ignore = [] })
117
117
  tailwindcss(),
118
118
  layeredStyles()
119
119
  ],
120
+ worker: { rolldownOptions: { output: { sourcemapDebugIds: sourceMaps } } },
120
121
  build: {
121
122
  outDir,
122
123
  emptyOutDir: true,
123
124
  modulePreload: false,
125
+ sourcemap: sourceMaps && "hidden",
124
126
  rolldownOptions: {
125
127
  input: {
126
128
  index: entry,
@@ -130,7 +132,8 @@ const buildPlugin = async ({ pluginDir, outDir, name, projectDir, ignore = [] })
130
132
  output: {
131
133
  entryFileNames: "assets/[name]-[hash].js",
132
134
  chunkFileNames: "assets/[name]-[hash].js",
133
- assetFileNames: "assets/[name]-[hash][extname]"
135
+ assetFileNames: "assets/[name]-[hash][extname]",
136
+ sourcemapDebugIds: sourceMaps
134
137
  }
135
138
  }
136
139
  }
@@ -6,10 +6,11 @@ import { faviconLink } from "../project/favicon-link.js";
6
6
  import { themeLink } from "../project/theme-link.js";
7
7
  import { serviceWorkerFile } from "./service-worker-code.js";
8
8
  import { serviceWorker } from "../project/service-worker.js";
9
+ import { moveSourceMaps } from "./source-maps.js";
9
10
  import { existsSync } from "node:fs";
10
11
  import path from "node:path";
11
12
  import { build } from "vite";
12
- import { mkdtemp, readFile, writeFile } from "node:fs/promises";
13
+ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
13
14
  import tailwindcss from "@tailwindcss/vite";
14
15
  import react from "@vitejs/plugin-react";
15
16
  import { tmpdir } from "node:os";
@@ -24,6 +25,11 @@ const shellPaths = [
24
25
  ];
25
26
  /** Where @protobase/ui's package ships its prebuilt shell, which `protobase build` copies and `protobase serve` serves. */
26
27
  const prebuiltShellDir = path.join(uiPackageDir, "dist", "shell");
28
+ /**
29
+ * Where @protobase/ui's package ships the prebuilt shell's source maps: beside the shell, in the same layout, rather
30
+ * than in it, so a server of the shell serves none and `protobase build --source-maps` copies them next to the scripts.
31
+ */
32
+ const prebuiltShellSourceMapsDir = path.join(uiPackageDir, "dist", "shell-source-maps");
27
33
  const shellIdentity = async () => {
28
34
  const ui = await readPackageJson(uiPackageDir);
29
35
  if (!ui.version || ui.protobase?.pluginApi === void 0) throw new Error(`${uiPackageDir} names no version or plugin API`);
@@ -38,9 +44,11 @@ const shellIdentity = async () => {
38
44
  * with protobase.shell.json saying which version it is. Asset URLs are absolute, so index.html works as the answer to
39
45
  * any deep link. It calls /api on its own origin and loads the project's UI, like every plugin, from what `/meta`
40
46
  * names, and links the project's theme at /protobase.theme.css and its favicon at /protobase.favicon.svg, and registers its service worker. The modules plugins share with it have entries of
41
- * their own, which index.html's import map names.
47
+ * their own, which index.html's import map names. With `sourceMapsDir`, each script ends with a `//# debugId=` comment
48
+ * and names no map, and its source map, carrying the same debug id, goes to the same place under `sourceMapsDir`.
42
49
  */
43
- const buildShell = async (outDir) => {
50
+ const buildShell = async (outDir, sourceMapsDir) => {
51
+ const sourceMaps = sourceMapsDir !== void 0;
44
52
  const nodeEnv = process.env.NODE_ENV;
45
53
  process.env.NODE_ENV = "production";
46
54
  await build({
@@ -59,15 +67,25 @@ const buildShell = async (outDir) => {
59
67
  react(),
60
68
  tailwindcss()
61
69
  ],
70
+ worker: { rolldownOptions: { output: { sourcemapDebugIds: sourceMaps } } },
62
71
  build: {
63
72
  outDir,
64
73
  emptyOutDir: true,
65
- chunkSizeWarningLimit: 4096
74
+ chunkSizeWarningLimit: 4096,
75
+ sourcemap: sourceMaps && "hidden",
76
+ rolldownOptions: { output: { sourcemapDebugIds: sourceMaps } }
66
77
  }
67
78
  }).finally(() => {
68
79
  if (nodeEnv === void 0) delete process.env.NODE_ENV;
69
80
  else process.env.NODE_ENV = nodeEnv;
70
81
  });
82
+ if (sourceMapsDir !== void 0) {
83
+ await rm(sourceMapsDir, {
84
+ recursive: true,
85
+ force: true
86
+ });
87
+ await moveSourceMaps(outDir, sourceMapsDir);
88
+ }
71
89
  const shell = await shellIdentity();
72
90
  await writeFile(path.join(outDir, shellManifestFile), `${JSON.stringify(shell, null, 2)}\n`);
73
91
  return shell;
@@ -81,20 +99,28 @@ const readShell = async (dir) => {
81
99
  /** The shell `protobase serve` has of its own: the installed @protobase/ui's, none when the CLI runs from sources. */
82
100
  const installedShellDir = path.extname(uiEntry) === ".js" ? prebuiltShellDir : void 0;
83
101
  /**
84
- * The shell `protobase build` copies into a bundle: the prebuilt one of the installed @protobase/ui, or, when the CLI
85
- * runs from this repository's sources, one built from them into a scratch folder, so it is never older than the code.
102
+ * The shell `protobase build` copies into a bundle, with its source maps' folder when `sourceMaps` asks for them: the
103
+ * prebuilt one of the installed @protobase/ui, or, when the CLI runs from this repository's sources, one built from
104
+ * them into the `scratch` folder, so it is never older than the code.
86
105
  */
87
- const shellForBuild = async () => {
88
- if (installedShellDir) return {
89
- dir: installedShellDir,
90
- shell: await readShell(installedShellDir)
91
- };
92
- const dir = await mkdtemp(path.join(tmpdir(), "protobase-shell-"));
106
+ const shellForBuild = async (sourceMaps) => {
107
+ if (installedShellDir) {
108
+ if (sourceMaps && !existsSync(prebuiltShellSourceMapsDir)) throw new Error(`The installed @protobase/ui ships no source maps of its shell (${prebuiltShellSourceMapsDir}); install a version that does, or build without --source-maps`);
109
+ return {
110
+ dir: installedShellDir,
111
+ ...sourceMaps && { sourceMapsDir: prebuiltShellSourceMapsDir },
112
+ shell: await readShell(installedShellDir)
113
+ };
114
+ }
115
+ const scratch = await mkdtemp(path.join(tmpdir(), "protobase-shell-"));
116
+ const dir = path.join(scratch, "shell");
117
+ const sourceMapsDir = sourceMaps ? path.join(scratch, "source-maps") : void 0;
93
118
  return {
94
119
  dir,
95
- shell: await buildShell(dir),
96
- scratch: true
120
+ ...sourceMapsDir && { sourceMapsDir },
121
+ shell: await buildShell(dir, sourceMapsDir),
122
+ scratch
97
123
  };
98
124
  };
99
125
  //#endregion
100
- export { buildShell, installedShellDir, prebuiltShellDir, readShell, shellForBuild, shellManifestFile, shellPaths };
126
+ export { buildShell, installedShellDir, prebuiltShellDir, prebuiltShellSourceMapsDir, readShell, shellForBuild, shellManifestFile, shellPaths };
@@ -0,0 +1,21 @@
1
+ import path from "node:path";
2
+ import { mkdir, readdir, rename } from "node:fs/promises";
3
+ //#region src/build/source-maps.ts
4
+ /**
5
+ * Moves every source map under `fromDir` to the same place under `toDir`, so a folder that is served holds no maps
6
+ * and a copy of both folders into one puts each map back beside its script.
7
+ */
8
+ const moveSourceMaps = async (fromDir, toDir) => {
9
+ const files = await readdir(fromDir, {
10
+ recursive: true,
11
+ withFileTypes: true
12
+ });
13
+ for (const file of files.filter((entry) => entry.isFile() && entry.name.endsWith(".map"))) {
14
+ const from = path.join(file.parentPath, file.name);
15
+ const to = path.join(toDir, path.relative(fromDir, from));
16
+ await mkdir(path.dirname(to), { recursive: true });
17
+ await rename(from, to);
18
+ }
19
+ };
20
+ //#endregion
21
+ export { moveSourceMaps };
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.33.1";
2
+ var version = "0.33.2";
3
3
  //#endregion
4
4
  export { version };
package/dist/main.js CHANGED
@@ -72,7 +72,7 @@ program.command("dev").description("Serve the admin app and API for the project
72
72
  process.once("SIGINT", () => void server.close().then(() => process.exit(0)));
73
73
  process.once("SIGTERM", () => void server.close().then(() => process.exit(0)));
74
74
  });
75
- program.command("build").description("Build the deploy bundle of the project in the current directory: its config module, the admin app with the project's UI as a plugin, and the manifest").option("--out <dir>", "output folder", "dist").option("--bun", "have Bun's bundler write the config module, for a bundle only Bun serves (needs bun on PATH)", false).option("--extend <dir>", "merge the protobase.config.ts and protobase.ui.tsx in this folder before the project's, repeatable", collect, []).action(async (opts) => {
75
+ program.command("build").description("Build the deploy bundle of the project in the current directory: its config module, the admin app with the project's UI as a plugin, and the manifest").option("--out <dir>", "output folder", "dist").option("--bun", "have Bun's bundler write the config module, for a bundle only Bun serves (needs bun on PATH)", false).option("--extend <dir>", "merge the protobase.config.ts and protobase.ui.tsx in this folder before the project's, repeatable", collect, []).option("--source-maps", "end each script with a //# debugId= comment and write its source map, carrying the same id, beside it", false).action(async (opts) => {
76
76
  const extensions = resolveExtensions(opts.extend);
77
77
  const onWarning = (message) => process.stderr.write(`warning: ${message}\n`);
78
78
  const manifest = await buildDeployBundle({
@@ -80,25 +80,27 @@ program.command("build").description("Build the deploy bundle of the project in
80
80
  outDir: path.resolve(opts.out),
81
81
  bun: opts.bun,
82
82
  extensions,
83
+ sourceMaps: opts.sourceMaps,
83
84
  onWarning
84
85
  });
85
86
  const packages = manifest.nodeModules ? `, ${manifest.nodeModules}/` : "";
86
87
  const plugins = manifest.plugins.length > 0 ? ` with plugins ${manifest.plugins.map((plugin) => plugin.name).join(", ")}` : "";
87
88
  out(`built ${opts.out}: ${manifest.server}${packages}, ${manifest.public}/${plugins} and ${manifestFile} (api ${manifest.api.join(", ")})\n`);
88
89
  });
89
- program.command("build-plugin").description("Build a plugin the admin app loads at runtime: its protobase.ui.tsx as one ES module, its stylesheet and plugin.json").argument("[dir]", "the plugin folder, holding protobase.ui.tsx", ".").option("--out <dir>", "output folder (default: dist in the plugin folder)").option("--name <name>", "the plugin's name (default: its package.json name)").action(async (dir, opts) => {
90
+ program.command("build-plugin").description("Build a plugin the admin app loads at runtime: its protobase.ui.tsx as one ES module, its stylesheet and plugin.json").argument("[dir]", "the plugin folder, holding protobase.ui.tsx", ".").option("--out <dir>", "output folder (default: dist in the plugin folder)").option("--name <name>", "the plugin's name (default: its package.json name)").option("--source-maps", "end each script with a //# debugId= comment and write its source map, carrying the same id, beside it", false).action(async (dir, opts) => {
90
91
  const pluginDir = path.resolve(dir);
91
92
  const outDir = path.resolve(opts.out ?? path.join(dir, "dist"));
92
93
  const manifest = await buildPlugin({
93
94
  pluginDir,
94
95
  outDir,
96
+ sourceMaps: opts.sourceMaps,
95
97
  ...opts.name && { name: opts.name }
96
98
  });
97
99
  const shown = path.relative(process.cwd(), outDir);
98
100
  out(`built ${shown.startsWith("..") ? outDir : shown || "."}: ${pluginManifestFile}, ${manifest.entry} and ${manifest.css} (${manifest.name}, plugin API ${manifest.api}, Protobase ${manifest.protobase})\n`);
99
101
  });
100
- 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").action(async (outDir) => {
101
- const shell = await buildShell(path.resolve(outDir));
102
+ 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) => {
103
+ const shell = await buildShell(path.resolve(outDir), opts.sourceMaps && path.resolve(opts.sourceMaps));
102
104
  out(`built ${outDir}: the shell of Protobase ${shell.protobase} (plugin API ${shell.pluginApi})\n`);
103
105
  });
104
106
  program.command("build-serve").description("Bundle the serve runtime into one file for Bun: bun --no-install protobase-serve.js <bundle.js>").option("--out <file>", "output file", "dist/protobase-serve.js").option("--bun", "have Bun's bundler write the file (needs bun on PATH)", false).action(async (opts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.33.1",
3
+ "version": "0.33.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.7",
37
37
  "@hono/node-server": "^2.1.3",
38
38
  "@hono/vite-dev-server": "^0.26.1",
39
- "@protobase/layout": "0.33.1",
40
- "@protobase/query": "0.33.1",
41
- "@protobase/schema": "0.33.1",
42
- "@protobase/server": "0.33.1",
43
- "@protobase/ui": "0.33.1",
39
+ "@protobase/layout": "0.33.2",
40
+ "@protobase/query": "0.33.2",
41
+ "@protobase/schema": "0.33.2",
42
+ "@protobase/server": "0.33.2",
43
+ "@protobase/ui": "0.33.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",
@@ -167,7 +167,7 @@ A config's `name` names it in these errors; an extension should set one. Nothing
167
167
  ## `build`
168
168
 
169
169
  ```sh
170
- protobase build [--out dist] [--bun] [--extend <dir>] # run inside a project, e.g. bun run --cwd examples/erp protobase build
170
+ protobase build [--out dist] [--bun] [--extend <dir>] [--source-maps] # run inside a project, e.g. bun run --cwd examples/erp protobase build
171
171
  ```
172
172
 
173
173
  Writes the project's deploy bundle, the folder a deployment ships:
@@ -193,6 +193,8 @@ A token the [theme](theme.md)) sets that the app does not read prints a `warning
193
193
 
194
194
  By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun only, as the Protobase images and the cloud serve it: Bun's bundler writes the config module (see [the config module](#the-config-module)), so the build needs `bun` on `PATH` and fails without it.
195
195
 
196
+ `--source-maps` writes a source map beside each script of the shell and the plugins, `assets/<name>-<hash>.js.map`, for an error tracker to read the browser's stack frames with. Each script ends with a `//# debugId=<uuid>` comment, and its map carries the same `debugId`; the scripts name no map, but a host serves the maps with the rest of `public/` unless it moves them out. The shell's maps come prebuilt in `@protobase/ui`'s `dist/shell-source-maps/`. Without the option the bundle has no maps.
197
+
196
198
  ### Extensions
197
199
 
198
200
  `--extend <dir>` (repeatable) adds an extension to the bundle without touching the project's files: a folder with a `protobase.config.ts`, a `protobase.ui.tsx` or both. Its `protobase.config.ts` is merged into the config module before the project's own, as if the project [extended](#extending-a-config) it, in the order given. Its `protobase.ui.tsx` becomes one more [plugin](plugins.md)) of the bundle, in `public/plugins/<name>/`, named by its `package.json`'s `name`, else its folder's. A host adds its own assistant tools and widgets to every app it builds this way; to add React code to apps without building them, serve a plugin instead.
@@ -315,7 +317,7 @@ docker run --rm -p 8787:8787 -e DATABASE_URL -e BETTER_AUTH_SECRET \
315
317
  ## `build-plugin`
316
318
 
317
319
  ```sh
318
- protobase build-plugin [dir] [--out <dir>] [--name <name>]
320
+ protobase build-plugin [dir] [--out <dir>] [--name <name>] [--source-maps]
319
321
  ```
320
322
 
321
323
  Builds the [plugin](plugins.md)) in `dir` (default: the current folder), whose entry is its `protobase.ui.tsx`, into `--out` (default: `dir/dist`):
@@ -331,6 +333,7 @@ dist/
331
333
  - 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.
332
334
  - 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)`).
333
335
  - `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, which the build needs: `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))).
336
+ - `--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.
334
337
 
335
338
  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 `options.plugins` (see [loading](plugins.md#loading))).
336
339