@looma/prisma-cli 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -15,6 +15,23 @@ pnpm prisma-cli auth login
15
15
  pnpm prisma-cli app deploy
16
16
  ```
17
17
 
18
+ Minimal Bun smoke flow:
19
+
20
+ ```bash
21
+ mkdir my-bun-app
22
+ cd my-bun-app
23
+ bun init --yes
24
+ pnpm add -D @looma/prisma-cli
25
+ ```
26
+
27
+ Then replace `index.ts` with a small `Bun.serve(...)` server and run:
28
+
29
+ ```bash
30
+ pnpm prisma-cli app build
31
+ pnpm prisma-cli auth login
32
+ pnpm prisma-cli app deploy --app my-bun-app
33
+ ```
34
+
18
35
  Notes:
19
36
 
20
37
  - the official Prisma ORM package still owns the `prisma` executable
@@ -0,0 +1,39 @@
1
+ import path from "node:path";
2
+ import { access, readFile } from "node:fs/promises";
3
+ //#region src/lib/app/bun-project.ts
4
+ async function readBunPackageJson(appPath) {
5
+ const packageJsonPath = path.join(appPath, "package.json");
6
+ let content;
7
+ try {
8
+ content = await readFile(packageJsonPath, "utf8");
9
+ } catch (error) {
10
+ if (error.code === "ENOENT") return null;
11
+ throw new Error(`Failed to read ${packageJsonPath}: ${error instanceof Error ? error.message : String(error)}`);
12
+ }
13
+ try {
14
+ return JSON.parse(content);
15
+ } catch (error) {
16
+ throw new Error(`Failed to parse ${packageJsonPath}: ${error instanceof Error ? error.message : String(error)}`);
17
+ }
18
+ }
19
+ function readBunPackageEntrypoint(packageJson) {
20
+ if (typeof packageJson?.main === "string") return packageJson.main;
21
+ if (typeof packageJson?.module === "string") return packageJson.module;
22
+ }
23
+ async function resolveBunEntrypoint(appPath, explicitEntrypoint) {
24
+ const packageJson = await readBunPackageJson(appPath);
25
+ const candidate = explicitEntrypoint ?? readBunPackageEntrypoint(packageJson);
26
+ if (!candidate) throw new Error("Entrypoint is required. Pass --entry or define package.json main or module.");
27
+ if (path.isAbsolute(candidate)) throw new Error("Entrypoint must be a relative path.");
28
+ const normalized = path.normalize(candidate);
29
+ if (normalized.startsWith("..") || path.isAbsolute(normalized) || normalized.includes(`${path.sep}..${path.sep}`)) throw new Error("Entrypoint must not escape the app directory.");
30
+ const entrypointPath = path.join(appPath, normalized);
31
+ try {
32
+ await access(entrypointPath);
33
+ } catch {
34
+ throw new Error(`Entrypoint file does not exist: ${entrypointPath}`);
35
+ }
36
+ return normalized.split(path.sep).join("/");
37
+ }
38
+ //#endregion
39
+ export { readBunPackageEntrypoint, readBunPackageJson, resolveBunEntrypoint };
@@ -1,5 +1,6 @@
1
+ import { readBunPackageEntrypoint, readBunPackageJson, resolveBunEntrypoint } from "./bun-project.js";
1
2
  import path from "node:path";
2
- import { access, readFile } from "node:fs/promises";
3
+ import { access } from "node:fs/promises";
3
4
  import { spawn } from "node:child_process";
4
5
  //#region src/lib/app/local-dev.ts
5
6
  const NEXT_CONFIG_FILENAMES = [
@@ -18,21 +19,6 @@ async function detectLocalBuildType(appPath) {
18
19
  if (await isBunProject(appPath)) return "bun";
19
20
  return null;
20
21
  }
21
- async function resolveBunEntrypoint(appPath, explicitEntrypoint) {
22
- const packageJson = await readPackageJson(appPath);
23
- const candidate = explicitEntrypoint ?? (typeof packageJson?.main === "string" ? packageJson.main : void 0);
24
- if (!candidate) throw new Error("Entrypoint is required. Pass --entry or define package.json main.");
25
- if (path.isAbsolute(candidate)) throw new Error("Entrypoint must be a relative path.");
26
- const normalized = path.normalize(candidate);
27
- if (normalized.startsWith("..") || path.isAbsolute(normalized) || normalized.includes(`${path.sep}..${path.sep}`)) throw new Error("Entrypoint must not escape the app directory.");
28
- const entrypointPath = path.join(appPath, normalized);
29
- try {
30
- await access(entrypointPath);
31
- } catch {
32
- throw new Error(`Entrypoint file does not exist: ${entrypointPath}`);
33
- }
34
- return normalized.split(path.sep).join("/");
35
- }
36
22
  async function runLocalApp(options) {
37
23
  const spawnImpl = options.spawnImpl ?? spawn;
38
24
  if (options.buildType === "nextjs") {
@@ -108,7 +94,7 @@ async function isNextProject(appPath) {
108
94
  await access(path.join(appPath, fileName));
109
95
  return true;
110
96
  } catch {}
111
- return hasDependency(await readPackageJson(appPath), "next");
97
+ return hasDependency(await readBunPackageJson(appPath), "next");
112
98
  }
113
99
  async function isBunProject(appPath) {
114
100
  try {
@@ -119,32 +105,17 @@ async function isBunProject(appPath) {
119
105
  await access(path.join(appPath, "bun.lockb"));
120
106
  return true;
121
107
  } catch {}
122
- const packageJson = await readPackageJson(appPath);
108
+ const packageJson = await readBunPackageJson(appPath);
123
109
  if (!packageJson) return false;
124
- const hasMain = typeof packageJson.main === "string";
110
+ const hasEntrypoint = typeof readBunPackageEntrypoint(packageJson) === "string";
125
111
  const hasBunDependency = hasDependency(packageJson, "@types/bun") || hasDependency(packageJson, "bun");
126
112
  const usesBunScripts = (typeof packageJson.scripts === "object" && packageJson.scripts !== null ? Object.values(packageJson.scripts) : []).some((value) => typeof value === "string" && /\bbun\b/.test(value));
127
- return hasMain && (hasBunDependency || usesBunScripts);
113
+ return hasEntrypoint && (hasBunDependency || usesBunScripts);
128
114
  }
129
115
  function hasDependency(packageJson, dependencyName) {
130
116
  if (!packageJson) return false;
131
117
  return [packageJson.dependencies, packageJson.devDependencies].some((group) => typeof group === "object" && group !== null && dependencyName in group);
132
118
  }
133
- async function readPackageJson(appPath) {
134
- const packageJsonPath = path.join(appPath, "package.json");
135
- let content;
136
- try {
137
- content = await readFile(packageJsonPath, "utf8");
138
- } catch (error) {
139
- if (error.code === "ENOENT") return null;
140
- throw new Error(`Failed to read ${packageJsonPath}: ${error instanceof Error ? error.message : String(error)}`);
141
- }
142
- try {
143
- return JSON.parse(content);
144
- } catch (error) {
145
- throw new Error(`Failed to parse ${packageJsonPath}: ${error instanceof Error ? error.message : String(error)}`);
146
- }
147
- }
148
119
  async function runWithFallback(candidates, options, spawnImpl, missingCommandMessage) {
149
120
  for (const candidate of candidates) try {
150
121
  const result = await spawnCommand(candidate, options, spawnImpl);
@@ -1,3 +1,4 @@
1
+ import { resolveBunEntrypoint } from "./bun-project.js";
1
2
  import path from "node:path";
2
3
  import { chmod, copyFile, cp, lstat, mkdir, mkdtemp, readFile, readdir, readlink, rm, stat } from "node:fs/promises";
3
4
  import os from "node:os";
@@ -59,23 +60,27 @@ async function resolvePrototypeBuildStrategy(options) {
59
60
  buildType: "nextjs",
60
61
  strategy: new PrototypeNextjsBuild({ appPath: options.appPath })
61
62
  };
62
- if (options.buildType === "bun") return {
63
- buildType: "bun",
64
- strategy: new BunBuild({
65
- appPath: options.appPath,
66
- entrypoint: options.entrypoint
67
- })
68
- };
63
+ if (options.buildType === "bun") {
64
+ const entrypoint = await resolveBunEntrypoint(options.appPath, options.entrypoint);
65
+ return {
66
+ buildType: "bun",
67
+ strategy: new BunBuild({
68
+ appPath: options.appPath,
69
+ entrypoint
70
+ })
71
+ };
72
+ }
69
73
  const nextjsStrategy = new PrototypeNextjsBuild({ appPath: options.appPath });
70
74
  if (await nextjsStrategy.canBuild()) return {
71
75
  buildType: "nextjs",
72
76
  strategy: nextjsStrategy
73
77
  };
78
+ const entrypoint = await resolveBunEntrypoint(options.appPath, options.entrypoint);
74
79
  return {
75
80
  buildType: "bun",
76
81
  strategy: new BunBuild({
77
82
  appPath: options.appPath,
78
- entrypoint: options.entrypoint
83
+ entrypoint
79
84
  })
80
85
  };
81
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@looma/prisma-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Prototype Prisma Compute CLI.",
5
5
  "type": "module",
6
6
  "bin": {