@protobase/cli 0.3.4 → 0.3.5

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,3 +1,4 @@
1
+ import path from "node:path";
1
2
  import { execFile } from "node:child_process";
2
3
  import { promisify } from "node:util";
3
4
  //#region src/build/bun-build.ts
@@ -6,7 +7,7 @@ const bunBuild = async (input, outFile) => {
6
7
  try {
7
8
  await run("bun", [
8
9
  "build",
9
- input,
10
+ path.basename(input),
10
11
  "--target",
11
12
  "bun",
12
13
  "--format",
@@ -15,9 +16,9 @@ const bunBuild = async (input, outFile) => {
15
16
  "external",
16
17
  "--outfile",
17
18
  outFile
18
- ]);
19
+ ], { cwd: path.dirname(input) });
19
20
  } catch (error) {
20
- if (error.code === "ENOENT") throw new Error("protobase build needs Bun to write the bundle, as the serve runtime runs it: install it from https://bun.sh and put `bun` on PATH");
21
+ if (error.code === "ENOENT") throw new Error("--bun needs Bun to write the bundle: install it from https://bun.sh and put `bun` on PATH, or build without --bun");
21
22
  throw error;
22
23
  }
23
24
  };
@@ -51,13 +51,14 @@ const servedImports = (native) => {
51
51
  }
52
52
  };
53
53
  };
54
- const buildConfigBundle = async ({ projectDir, outFile }) => {
54
+ const buildConfigBundle = async ({ projectDir, outFile, bun }) => {
55
55
  const file = path.join(projectDir, "protobase-bundle-entry.js");
56
56
  const native = /* @__PURE__ */ new Map();
57
57
  await viteBundle({
58
58
  root: projectDir,
59
59
  entry: file,
60
60
  outFile,
61
+ bun,
61
62
  plugins: [
62
63
  layoutCheck(),
63
64
  servedImports(native),
@@ -17,11 +17,12 @@ const removeOwnNodeModules = async (outDir) => {
17
17
  force: true
18
18
  });
19
19
  };
20
- const buildDeployBundle = async ({ projectDir, outDir }) => {
20
+ const buildDeployBundle = async ({ projectDir, outDir, bun }) => {
21
21
  await removeOwnNodeModules(outDir);
22
22
  const native = await buildConfigBundle({
23
23
  projectDir,
24
- outFile: path.join(outDir, bundleLayout.server)
24
+ outFile: path.join(outDir, bundleLayout.server),
25
+ bun
25
26
  });
26
27
  const packages = native.length > 0 ? await copyPackages(native, path.join(outDir, bundleNodeModules)) : [];
27
28
  await buildUiBundle({
@@ -4,11 +4,12 @@ import { fileURLToPath } from "node:url";
4
4
  //#region src/build/serve-runtime.ts
5
5
  const cliRoot = fileURLToPath(new URL("../..", import.meta.url));
6
6
  const serveMain = moduleFile("../serve/main", import.meta.url);
7
- const buildServeRuntime = async ({ outFile }) => {
7
+ const buildServeRuntime = async ({ outFile, bun }) => {
8
8
  await viteBundle({
9
9
  root: cliRoot,
10
10
  entry: serveMain,
11
11
  outFile,
12
+ bun,
12
13
  plugins: []
13
14
  });
14
15
  };
@@ -34,16 +34,15 @@ const viteBuild = async ({ root, entry, outFile, plugins }) => {
34
34
  }
35
35
  });
36
36
  };
37
- const viteBundle = async ({ root, entry, outFile, plugins }) => {
37
+ const viteBundle = async ({ bun, ...input }) => {
38
+ if (!bun) return viteBuild(input);
38
39
  const scratch = await mkdtemp(path.join(tmpdir(), "protobase-bundle-"));
39
40
  try {
40
41
  await viteBuild({
41
- root,
42
- entry,
43
- outFile: path.join(scratch, "bundle.js"),
44
- plugins
42
+ ...input,
43
+ outFile: path.join(scratch, "bundle.js")
45
44
  });
46
- await bunBuild(path.join(scratch, "bundle.js"), outFile);
45
+ await bunBuild(path.join(scratch, "bundle.js"), input.outFile);
47
46
  } finally {
48
47
  await rm(scratch, {
49
48
  recursive: true,
@@ -12,9 +12,9 @@ const startHint = async (projectDir) => {
12
12
  throw error;
13
13
  });
14
14
  if (!manifest) return "";
15
- const { name, scripts } = JSON.parse(manifest);
15
+ const { scripts } = JSON.parse(manifest);
16
16
  if (!scripts?.["db:up"]) return "";
17
- return `\nStart it with: pnpm --filter ${name} db:up`;
17
+ return "\nStart it with the project's db:up script.";
18
18
  };
19
19
  const reasons = {
20
20
  ECONNREFUSED: "the connection was refused, so no Postgres is listening there",
package/dist/main.js CHANGED
@@ -57,16 +57,20 @@ program.command("dev").description("Serve the admin app and API for the project
57
57
  process.once("SIGINT", () => void server.close().then(() => process.exit(0)));
58
58
  process.once("SIGTERM", () => void server.close().then(() => process.exit(0)));
59
59
  });
60
- program.command("build").description("Build the deploy bundle of the project in the current directory: its config module, admin UI and manifest").option("--out <dir>", "output folder", "dist").action(async (opts) => {
60
+ program.command("build").description("Build the deploy bundle of the project in the current directory: its config module, admin UI and 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).action(async (opts) => {
61
61
  const manifest = await buildDeployBundle({
62
62
  projectDir: process.cwd(),
63
- outDir: path.resolve(opts.out)
63
+ outDir: path.resolve(opts.out),
64
+ bun: opts.bun
64
65
  });
65
66
  const packages = manifest.nodeModules ? `, ${manifest.nodeModules}/` : "";
66
67
  out(`built ${opts.out}: ${manifest.server}${packages}, ${manifest.public}/ and ${manifestFile} (api ${manifest.api.join(", ")})\n`);
67
68
  });
68
- 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").action(async (opts) => {
69
- await buildServeRuntime({ outFile: path.resolve(opts.out) });
69
+ 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) => {
70
+ await buildServeRuntime({
71
+ outFile: path.resolve(opts.out),
72
+ bun: opts.bun
73
+ });
70
74
  out(`built ${opts.out}\n`);
71
75
  });
72
76
  program.command("serve").description("Serve a bundle written by `protobase build` until SIGTERM or SIGINT: a folder as a host serves it, a config module as its API alone").argument("<bundle>", "the bundle folder, e.g. dist, or its dist/protobase.config.js").action(async (bundle) => {
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.3.4";
2
+ var version = "0.3.5";
3
3
  //#endregion
4
4
  export { version };
@@ -1,6 +1,11 @@
1
- import { pathToFileURL } from "node:url";
2
- import { tsImport } from "tsx/esm/api";
1
+ import { runnerImport } from "vite";
3
2
  //#region src/project/import-project-file.ts
4
- const importProjectFile = (file) => tsImport(pathToFileURL(file).href, import.meta.url);
3
+ const importProjectFile = async (file) => {
4
+ const { module } = await runnerImport(file, {
5
+ configFile: false,
6
+ logLevel: "error"
7
+ });
8
+ return module;
9
+ };
5
10
  //#endregion
6
11
  export { importProjectFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -24,12 +24,21 @@
24
24
  "bin/protobase.mjs",
25
25
  "dist"
26
26
  ],
27
+ "scripts": {
28
+ "build": "tsdown",
29
+ "prepack": "tsdown"
30
+ },
27
31
  "publishConfig": {
28
32
  "access": "public"
29
33
  },
30
34
  "dependencies": {
31
35
  "@hono/node-server": "^2.1.3",
32
36
  "@hono/vite-dev-server": "^0.26.1",
37
+ "@protobase/layout": "0.3.5",
38
+ "@protobase/query": "0.3.5",
39
+ "@protobase/schema": "0.3.5",
40
+ "@protobase/server": "0.3.5",
41
+ "@protobase/ui": "0.3.5",
33
42
  "@scalar/hono-api-reference": "^0.12.10",
34
43
  "@tailwindcss/vite": "^4.3.3",
35
44
  "@vitejs/plugin-react": "^6.1.2",
@@ -43,16 +52,10 @@
43
52
  "pg": "^8.23.1",
44
53
  "postgres": "^3.4.9",
45
54
  "ts-morph": "^28.0.0",
46
- "tsx": "^4.23.15",
47
55
  "vite": "^8.3.3",
48
- "zod": "^4.6.5",
49
- "@protobase/query": "0.3.4",
50
- "@protobase/server": "0.3.4",
51
- "@protobase/schema": "0.3.4",
52
- "@protobase/layout": "0.3.4",
53
- "@protobase/ui": "0.3.4"
56
+ "zod": "^4.6.5"
54
57
  },
55
- "scripts": {
56
- "build": "tsdown"
58
+ "devDependencies": {
59
+ "tsx": "^4.23.15"
57
60
  }
58
- }
61
+ }