@solcreek/cli 0.4.27 → 0.4.29

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.
@@ -163,7 +163,7 @@ const migrateCommand = defineCommand({
163
163
  },
164
164
  dir: {
165
165
  type: "string",
166
- description: "Migration directory path. Default: auto-detect drizzle/, drizzle/migrations/, migrations/, sql/",
166
+ description: "Migration directory path. Default: auto-detect drizzle/, drizzle/migrations/, prisma/migrations/, migrations/, sql/",
167
167
  required: false,
168
168
  },
169
169
  "dry-run": {
@@ -198,7 +198,7 @@ const migrateCommand = defineCommand({
198
198
  if (!migrationDir) {
199
199
  const msg = args.dir
200
200
  ? `Migration directory not found: ${args.dir}`
201
- : "No migration directory found. Looked for: drizzle/, drizzle/migrations/, migrations/, sql/. Use --dir to specify.";
201
+ : "No migration directory found. Looked for: drizzle/, drizzle/migrations/, prisma/migrations/, migrations/, sql/. Use --dir to specify.";
202
202
  if (jsonMode)
203
203
  jsonOutput({ ok: false, error: "no_migration_dir", message: msg }, 1);
204
204
  consola.error(msg);
@@ -6,8 +6,8 @@
6
6
  */
7
7
  /**
8
8
  * Find the migration directory relative to cwd.
9
- * Returns the absolute path of the first candidate that exists and
10
- * contains at least one .sql file, or null if none found.
9
+ * Returns the absolute path of the first candidate that holds migrations
10
+ * (flat `.sql` or Prisma's nested `<name>/migration.sql`), or null.
11
11
  */
12
12
  export declare function detectMigrationDir(cwd: string): string | null;
13
13
  export interface MigrationFile {
@@ -17,8 +17,13 @@ export interface MigrationFile {
17
17
  path: string;
18
18
  }
19
19
  /**
20
- * Read .sql files from a directory, sorted lexicographically.
21
- * Non-.sql files and empty .sql files are skipped.
20
+ * Read migrations from a directory in either layout, sorted lexicographically
21
+ * by name (Drizzle's `NNNN_` prefixes and Prisma's `<timestamp>_` prefixes both
22
+ * sort chronologically). Empty migrations are skipped.
23
+ *
24
+ * - flat: each `.sql` file is a migration; name = file name (e.g. `0001_init.sql`)
25
+ * - nested: each `<name>/migration.sql` is a migration; name = subdir name
26
+ * (e.g. `20260614120000_init`) — the identifier Prisma tracks
22
27
  */
23
28
  export declare function parseMigrationFiles(dir: string): MigrationFile[];
24
29
  /**
@@ -10,33 +10,49 @@ import { join, resolve } from "node:path";
10
10
  const CANDIDATE_DIRS = [
11
11
  "drizzle",
12
12
  "drizzle/migrations",
13
+ "prisma/migrations",
13
14
  "migrations",
14
15
  "sql",
15
16
  ];
17
+ /**
18
+ * Whether a directory holds migrations in either supported layout:
19
+ * - flat: `.sql` files directly in the dir (Drizzle `drizzle-kit generate`,
20
+ * plain SQL dirs)
21
+ * - nested: `<name>/migration.sql` per migration (Prisma `prisma migrate`)
22
+ */
23
+ function hasMigrations(dir) {
24
+ let entries;
25
+ try {
26
+ entries = readdirSync(dir);
27
+ }
28
+ catch {
29
+ return false; // Permission error or not a directory.
30
+ }
31
+ if (entries.some((f) => f.endsWith(".sql")))
32
+ return true;
33
+ return entries.some((f) => existsSync(join(dir, f, "migration.sql")));
34
+ }
16
35
  /**
17
36
  * Find the migration directory relative to cwd.
18
- * Returns the absolute path of the first candidate that exists and
19
- * contains at least one .sql file, or null if none found.
37
+ * Returns the absolute path of the first candidate that holds migrations
38
+ * (flat `.sql` or Prisma's nested `<name>/migration.sql`), or null.
20
39
  */
21
40
  export function detectMigrationDir(cwd) {
22
41
  for (const dir of CANDIDATE_DIRS) {
23
42
  const abs = resolve(cwd, dir);
24
- if (existsSync(abs)) {
25
- try {
26
- const files = readdirSync(abs);
27
- if (files.some((f) => f.endsWith(".sql")))
28
- return abs;
29
- }
30
- catch {
31
- // Permission error or not a directory — skip
32
- }
33
- }
43
+ if (existsSync(abs) && hasMigrations(abs))
44
+ return abs;
34
45
  }
35
46
  return null;
36
47
  }
37
48
  /**
38
- * Read .sql files from a directory, sorted lexicographically.
39
- * Non-.sql files and empty .sql files are skipped.
49
+ * Read migrations from a directory in either layout, sorted lexicographically
50
+ * by name (Drizzle's `NNNN_` prefixes and Prisma's `<timestamp>_` prefixes both
51
+ * sort chronologically). Empty migrations are skipped.
52
+ *
53
+ * - flat: each `.sql` file is a migration; name = file name (e.g. `0001_init.sql`)
54
+ * - nested: each `<name>/migration.sql` is a migration; name = subdir name
55
+ * (e.g. `20260614120000_init`) — the identifier Prisma tracks
40
56
  */
41
57
  export function parseMigrationFiles(dir) {
42
58
  let entries;
@@ -46,10 +62,19 @@ export function parseMigrationFiles(dir) {
46
62
  catch {
47
63
  return [];
48
64
  }
49
- return entries
50
- .filter((f) => f.endsWith(".sql"))
51
- .sort()
52
- .map((name) => ({ name, path: join(dir, name) }))
65
+ const files = [];
66
+ for (const name of entries) {
67
+ if (name.endsWith(".sql")) {
68
+ files.push({ name, path: join(dir, name) });
69
+ continue;
70
+ }
71
+ // Prisma nests each migration as `<name>/migration.sql`.
72
+ const nested = join(dir, name, "migration.sql");
73
+ if (existsSync(nested))
74
+ files.push({ name, path: nested });
75
+ }
76
+ return files
77
+ .sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
53
78
  .filter((f) => {
54
79
  try {
55
80
  const content = readFileSync(f.path, "utf-8").trim();
@@ -45,6 +45,22 @@ export declare function readAdapterCompat(cwd: string): {
45
45
  * the Creek adapter handles middleware via typed AdapterOutputs.
46
46
  */
47
47
  export declare function patchBundledWorker(bundleDir: string, openNextDir: string): void;
48
+ /**
49
+ * Ensure @prisma/adapter-d1 is resolvable at build time for the zero-change
50
+ * Prisma-on-D1 swap. adapter-creek aliases `@prisma/adapter-better-sqlite3` to
51
+ * a PrismaD1-backed shim that imports `@prisma/adapter-d1`; that package is an
52
+ * OPTIONAL peer of the adapter (not shipped to non-Prisma projects), so it is
53
+ * lazily installed into .creek only when the project actually uses the
54
+ * better-sqlite3 Prisma adapter. Installed matching the project's Prisma
55
+ * version — the adapter packages release in lockstep with @prisma/client, so a
56
+ * matching driver-adapter interface avoids subtle version skew.
57
+ *
58
+ * No-op unless @prisma/adapter-better-sqlite3 is present, or if adapter-d1 is
59
+ * already resolvable (project dep or a prior .creek install).
60
+ *
61
+ * Exported for tests.
62
+ */
63
+ export declare function ensurePrismaD1(cwd: string): void;
48
64
  /**
49
65
  * Fix the standalone output path for monorepo builds.
50
66
  *
@@ -128,6 +128,7 @@ export function buildNextjs(cwd, isMonorepo, projectName) {
128
128
  if (version && semverGte(version, "16.2.3")) {
129
129
  const adapterPath = ensureAdapter(cwd);
130
130
  if (adapterPath) {
131
+ ensurePrismaD1(cwd);
131
132
  buildWithAdapter(cwd, adapterPath);
132
133
  return;
133
134
  }
@@ -205,6 +206,10 @@ const OPENNEXT_PKG = "@opennextjs/cloudflare";
205
206
  const OPENNEXT_VERSION = "^1.18.0";
206
207
  const ADAPTER_PKG = "@solcreek/adapter-creek";
207
208
  const ADAPTER_VERSION = "^0.2.2";
209
+ // Zero-change Prisma-on-D1: the adapter's build-time swap targets this
210
+ // adapter and imports @prisma/adapter-d1 (an optional peer it doesn't ship).
211
+ const PRISMA_BSQLITE_PKG = "@prisma/adapter-better-sqlite3";
212
+ const PRISMA_D1_PKG = "@prisma/adapter-d1";
208
213
  // Adapter < 0.2.2 resolves its dependencies against paths that don't exist
209
214
  // under the .creek lazy install (0.2.0: the cache handler; 0.2.1: the
210
215
  // wrangler bin) — npm hoists them to the top of the tree, so the adapter's
@@ -283,6 +288,56 @@ function ensureAdapter(cwd) {
283
288
  consola.success(` ${ADAPTER_PKG} installed`);
284
289
  return resolved;
285
290
  }
291
+ /**
292
+ * Ensure @prisma/adapter-d1 is resolvable at build time for the zero-change
293
+ * Prisma-on-D1 swap. adapter-creek aliases `@prisma/adapter-better-sqlite3` to
294
+ * a PrismaD1-backed shim that imports `@prisma/adapter-d1`; that package is an
295
+ * OPTIONAL peer of the adapter (not shipped to non-Prisma projects), so it is
296
+ * lazily installed into .creek only when the project actually uses the
297
+ * better-sqlite3 Prisma adapter. Installed matching the project's Prisma
298
+ * version — the adapter packages release in lockstep with @prisma/client, so a
299
+ * matching driver-adapter interface avoids subtle version skew.
300
+ *
301
+ * No-op unless @prisma/adapter-better-sqlite3 is present, or if adapter-d1 is
302
+ * already resolvable (project dep or a prior .creek install).
303
+ *
304
+ * Exported for tests.
305
+ */
306
+ export function ensurePrismaD1(cwd) {
307
+ const projectRequire = createRequire(join(cwd, "noop.js"));
308
+ try {
309
+ projectRequire.resolve(PRISMA_BSQLITE_PKG);
310
+ }
311
+ catch {
312
+ return; // Not a Prisma-on-D1 (better-sqlite3 adapter) project.
313
+ }
314
+ // createRequire from .creek walks up into the project's node_modules too, so
315
+ // this single check covers both a prior .creek install and a project dep.
316
+ const creekDir = join(cwd, CREEK_DIR);
317
+ try {
318
+ createRequire(join(creekDir, "noop.js")).resolve(PRISMA_D1_PKG);
319
+ return; // Already available.
320
+ }
321
+ catch {
322
+ // Fall through to install.
323
+ }
324
+ let version = "latest";
325
+ try {
326
+ const clientPkg = JSON.parse(readFileSync(projectRequire.resolve("@prisma/client/package.json"), "utf-8"));
327
+ if (clientPkg.version)
328
+ version = clientPkg.version;
329
+ }
330
+ catch {
331
+ // No @prisma/client version readable — fall back to latest.
332
+ }
333
+ consola.start(` Installing ${PRISMA_D1_PKG}@${version} (Prisma on D1)...`);
334
+ if (installCreekDep(creekDir, PRISMA_D1_PKG, version)) {
335
+ consola.success(` ${PRISMA_D1_PKG} installed`);
336
+ }
337
+ else {
338
+ consola.warn(` Could not install ${PRISMA_D1_PKG} — Prisma build may fail`);
339
+ }
340
+ }
286
341
  /**
287
342
  * Ensure @opennextjs/cloudflare is available in .creek/node_modules.
288
343
  * Returns the path to the opennextjs-cloudflare CLI binary.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solcreek/cli",
3
- "version": "0.4.27",
3
+ "version": "0.4.29",
4
4
  "description": "CLI for the Creek deployment platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -44,6 +44,7 @@
44
44
  "hono": "^4.7.4",
45
45
  "jsdom": "^29.0.1",
46
46
  "miniflare": "^4.20260317.3",
47
+ "msw": "^2.12.14",
47
48
  "react": "^19.2.4",
48
49
  "react-dom": "^19.2.4",
49
50
  "typescript": "^5.8.2",