@prenta/cli 0.16.2 → 0.16.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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @prenta/cli@0.16.2 build /home/runner/work/prenta/prenta/packages/cli
2
+ > @prenta/cli@0.16.3 build /home/runner/work/prenta/prenta/packages/cli
3
3
  > tsc
4
4
 
@@ -1,13 +1,13 @@
1
1
 
2
- > @prenta/cli@0.16.2 test /home/runner/work/prenta/prenta/packages/cli
2
+ > @prenta/cli@0.16.3 test /home/runner/work/prenta/prenta/packages/cli
3
3
  > vitest run "--no-file-parallelism"
4
4
 
5
5
 
6
6
   RUN  v4.1.8 /home/runner/work/prenta/prenta/packages/cli
7
7
 
8
- ✓ src/__tests__/deployment-diagnostics.test.ts (18 tests) 32ms
9
- ✓ src/__tests__/db-sync.test.ts (13 tests) 558ms
10
- ✓ src/__tests__/seed.test.ts (10 tests) 146ms
8
+ ✓ src/__tests__/deployment-diagnostics.test.ts (18 tests) 162ms
9
+ ✓ src/__tests__/db-sync.test.ts (13 tests) 525ms
10
+ ✓ src/__tests__/seed.test.ts (10 tests) 168ms
11
11
  - Reading canonical Prenta schema...
12
12
  ✔ Prenta CMS models added to schema.
13
13
  - Running prisma generate...
@@ -16,8 +16,8 @@
16
16
  ℹ Run `npx prisma migrate dev --name prenta-cms` to create the migration.
17
17
 
18
18
  - Reading canonical Prenta schema...
19
- ✖ Could not locate @prenta/core.
20
19
  stdout | src/__tests__/db-init.test.ts > db:init (WS-D D5 — canonical schema, no stale fragment) > command > fails clearly when cms-core cannot be located
20
+ ✖ Could not locate @prenta/core.
21
21
  ℹ Install it first: `npm install @prenta/core`.
22
22
 
23
23
  - Reading canonical Prenta schema...
@@ -29,7 +29,7 @@
29
29
 
30
30
  - Reading canonical Prenta schema...
31
31
  ℹ Prenta CMS models already present in schema. Use --force to overwrite.
32
- ✓ src/__tests__/db-init.test.ts (4 tests) 221ms
32
+ ✓ src/__tests__/db-init.test.ts (4 tests) 270ms
33
33
  stdout | src/__tests__/mcp-init.test.ts > mcp:init > creates both editor configs with placeholder key and git-ignores them
34
34
  ✔ Created .cursor/mcp.json
35
35
 
@@ -158,26 +158,27 @@ Next steps
158
158
  3. Restart Cursor / VS Code so the MCP server is picked up
159
159
  Tip: pass --url https://your-site.com to target a deployed CMS instead.
160
160
 
161
- ✓ src/__tests__/mcp-init.test.ts (6 tests) 242ms
162
- ✓ src/__tests__/form-seed.test.ts (10 tests) 17ms
163
- ✓ src/__tests__/prisma-client-path.test.ts (6 tests) 40ms
164
- ✓ src/__tests__/vercel-env-matrix.test.ts (6 tests) 25ms
165
- ✓ src/__tests__/upgrade.test.ts (3 tests) 34ms
166
- ✓ src/__tests__/load-dotenv.test.ts (3 tests) 17ms
161
+ ✓ src/__tests__/mcp-init.test.ts (6 tests) 416ms
162
+ ✓ src/__tests__/prisma-client-path.test.ts (8 tests) 97ms
163
+ ✓ src/__tests__/form-seed.test.ts (10 tests) 69ms
164
+ ✓ src/__tests__/vercel-env-matrix.test.ts (6 tests) 79ms
165
+ ✓ src/__tests__/upgrade.test.ts (3 tests) 57ms
166
+ ✓ src/__tests__/load-dotenv.test.ts (3 tests) 74ms
167
167
  - Reading canonical Prenta schema...
168
- ✔ Prenta CMS models added to schema.
169
- - Running prisma generate...
170
168
  stdout | src/__tests__/schema-fragment.test.ts > db:init schema fragment > injects all deploy-critical Prenta models
171
169
  ✔ Prisma client generated.
170
+ ✔ Prenta CMS models added to schema.
172
171
  ℹ Run `npx prisma migrate dev --name prenta-cms` to create the migration.
172
+ - Running prisma generate...
173
173
 
174
- ✓ src/__tests__/schema-fragment.test.ts (1 test) 141ms
175
- ✓ src/__tests__/db-sync-resolver.test.ts (4 tests) 10ms
176
- ✓ src/__tests__/import-typescript.test.ts (3 tests) 186ms
177
- ✓ src/__tests__/init.test.ts (2 tests) 45ms
174
+ ✓ src/__tests__/schema-fragment.test.ts (1 test) 182ms
175
+ ✓ src/__tests__/db-sync-resolver.test.ts (4 tests) 28ms
176
+ ✓ src/__tests__/import-typescript.test.ts (3 tests) 355ms
177
+ ✓ loads a TypeScript file that imports a sibling without appending ?namespace=  332ms
178
+ ✓ src/__tests__/init.test.ts (2 tests) 43ms
178
179
 
179
180
   Test Files  14 passed (14)
180
-  Tests  89 passed (89)
181
-  Start at  05:35:02
182
-  Duration  16.87s (transform 2.03s, setup 0ms, import 4.77s, tests 1.71s, environment 13ms)
181
+  Tests  91 passed (91)
182
+  Start at  22:16:43
183
+  Duration  25.61s (transform 2.52s, setup 0ms, import 6.46s, tests 2.52s, environment 2ms)
183
184
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @actuate-media/cli
2
2
 
3
+ ## 0.16.3
4
+
5
+ ### Patch Changes
6
+
7
+ - ead6241: CLI database connect loads the generated Prisma client via tsx `file://` URLs and never evaluates `lib/prisma.ts` when that client exists — so Windows `migrate:*` no longer dies on `require('../generated/prisma/client')`. `POST /media/:id/probe` (and already-WebP `/optimize`) now write the 20px WebP blurHash placeholder, not just width/height.
8
+
3
9
  ## 0.16.2
4
10
 
5
11
  ### Patch Changes
@@ -2,15 +2,25 @@
2
2
  * Shared helper for CLI commands that need a live connection to the consumer
3
3
  * project's database (seed, populate, data migrations…).
4
4
  *
5
- * Resolution order mirrors how a scaffolded Prenta project exposes Prisma:
5
+ * Resolution order:
6
6
  * 1. If `cms-core` already has an initialized client (e.g. set up by the host
7
7
  * app in-process), reuse it.
8
- * 2. Otherwise call `getPrisma()` from `lib/prisma.ts` when the project ships
9
- * one (Prisma 7 + pg adapter / Accelerate — same path Next.js uses).
10
- * 3. Otherwise build a client from the schema's `output` path (custom or
11
- * default `generated/prisma/client.ts`) via tsx + pg driver adapter.
8
+ * 2. Load the generated Prisma client (`generated/prisma/client.ts`) via tsx's
9
+ * process-wide ESM hook and `file://` URLs, then construct PrismaClient
10
+ * with the pg adapter or Accelerate — same setup as a scaffolded
11
+ * `lib/prisma.ts`, without evaluating that file.
12
+ * 3. Only when no generated client exists, call `getPrisma()` from
13
+ * `lib/prisma.ts` (best-effort; a CJS `require` of a TypeScript client
14
+ * will fail on Windows).
12
15
  * 4. Fall back to a plain `@prisma/client` resolved from the project.
13
16
  *
17
+ * Evaluating `lib/prisma.ts` first is what broke `migrate:*` on Windows: tsx
18
+ * compiled its `import … from '../generated/prisma/client'` into
19
+ * `require('../generated/prisma/client')`, which cannot load the modern
20
+ * TypeScript `prisma-client` generator output. Each CJS fallback just moved
21
+ * the crash to the next `.ts` import. The generated-client ESM path is the
22
+ * durable fix.
23
+ *
14
24
  * The returned `disconnect()` only tears down clients this helper created — a
15
25
  * pre-initialized in-process client is left untouched.
16
26
  */
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC;IAEtD,EAAE,EAAE,GAAG,CAAA;IACP,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAChC,CAAC,CAiBD"}
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC;IAEtD,EAAE,EAAE,GAAG,CAAA;IACP,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAChC,CAAC,CAiBD"}
@@ -2,20 +2,30 @@ import { createRequire } from 'node:module';
2
2
  import path from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import { importProjectTypescript } from './import-typescript.js';
5
- import { findLibPrismaHelper, resolveProjectPrismaClientModule } from './prisma-client-path.js';
5
+ import { resolvePrismaClientLoadPlan } from './prisma-client-path.js';
6
6
  /**
7
7
  * Shared helper for CLI commands that need a live connection to the consumer
8
8
  * project's database (seed, populate, data migrations…).
9
9
  *
10
- * Resolution order mirrors how a scaffolded Prenta project exposes Prisma:
10
+ * Resolution order:
11
11
  * 1. If `cms-core` already has an initialized client (e.g. set up by the host
12
12
  * app in-process), reuse it.
13
- * 2. Otherwise call `getPrisma()` from `lib/prisma.ts` when the project ships
14
- * one (Prisma 7 + pg adapter / Accelerate — same path Next.js uses).
15
- * 3. Otherwise build a client from the schema's `output` path (custom or
16
- * default `generated/prisma/client.ts`) via tsx + pg driver adapter.
13
+ * 2. Load the generated Prisma client (`generated/prisma/client.ts`) via tsx's
14
+ * process-wide ESM hook and `file://` URLs, then construct PrismaClient
15
+ * with the pg adapter or Accelerate — same setup as a scaffolded
16
+ * `lib/prisma.ts`, without evaluating that file.
17
+ * 3. Only when no generated client exists, call `getPrisma()` from
18
+ * `lib/prisma.ts` (best-effort; a CJS `require` of a TypeScript client
19
+ * will fail on Windows).
17
20
  * 4. Fall back to a plain `@prisma/client` resolved from the project.
18
21
  *
22
+ * Evaluating `lib/prisma.ts` first is what broke `migrate:*` on Windows: tsx
23
+ * compiled its `import … from '../generated/prisma/client'` into
24
+ * `require('../generated/prisma/client')`, which cannot load the modern
25
+ * TypeScript `prisma-client` generator output. Each CJS fallback just moved
26
+ * the crash to the next `.ts` import. The generated-client ESM path is the
27
+ * durable fix.
28
+ *
19
29
  * The returned `disconnect()` only tears down clients this helper created — a
20
30
  * pre-initialized in-process client is left untouched.
21
31
  */
@@ -46,52 +56,64 @@ async function importModule(specifier, requireFromProject) {
46
56
  const href = pathToFileURL(requireFromProject.resolve(specifier)).href;
47
57
  return import(href);
48
58
  }
49
- async function tryLibPrismaClient() {
50
- const helperPath = findLibPrismaHelper();
51
- if (!helperPath)
52
- return null;
53
- const mod = (await importProjectTypescript(helperPath));
54
- const getPrisma = mod.getPrisma ?? mod.default?.getPrisma;
55
- if (typeof getPrisma !== 'function')
59
+ async function tryLibPrismaClient(helperPath) {
60
+ try {
61
+ const mod = (await importProjectTypescript(helperPath));
62
+ const getPrisma = mod.getPrisma ?? mod.default?.getPrisma;
63
+ if (typeof getPrisma !== 'function')
64
+ return null;
65
+ return getPrisma();
66
+ }
67
+ catch {
68
+ // `lib/prisma.ts` often `require()`s the generated TypeScript client.
69
+ // That cannot work on Windows; callers fall through or throw from the
70
+ // generated-client path instead.
56
71
  return null;
57
- return getPrisma();
72
+ }
73
+ }
74
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above.
75
+ async function createClientFromGenerated(generatedClient) {
76
+ const requireFromProject = createRequire(path.join(process.cwd(), 'package.json'));
77
+ const url = process.env.DATABASE_URL;
78
+ const [clientModule, adapterModule, pgModule] = await Promise.all([
79
+ importProjectTypescript(generatedClient),
80
+ importModule('@prisma/adapter-pg', requireFromProject),
81
+ importModule('pg', requireFromProject),
82
+ ]);
83
+ const { PrismaClient } = clientModule;
84
+ if (isAcceleratedDbUrl(url)) {
85
+ let withAccelerate;
86
+ try {
87
+ const ext = (await importModule('@prisma/extension-accelerate', requireFromProject));
88
+ withAccelerate = ext.withAccelerate;
89
+ }
90
+ catch {
91
+ throw new Error('DATABASE_URL uses Prisma Accelerate but @prisma/extension-accelerate is not installed. Install the extension or use a postgresql:// URL.');
92
+ }
93
+ const client = new PrismaClient({ accelerateUrl: url }).$extends(withAccelerate());
94
+ return client;
95
+ }
96
+ const { PrismaPg } = adapterModule;
97
+ const pg = pgModule.default ?? pgModule;
98
+ const pool = new pg.Pool({ connectionString: url });
99
+ const adapter = new PrismaPg(pool);
100
+ return new PrismaClient({ adapter });
58
101
  }
59
102
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above.
60
103
  async function createProjectPrismaClient() {
61
104
  if (!process.env.DATABASE_URL) {
62
105
  throw new Error('DATABASE_URL is required to connect to the project database.');
63
106
  }
64
- const fromLib = await tryLibPrismaClient();
65
- if (fromLib)
66
- return fromLib;
67
- const requireFromProject = createRequire(path.join(process.cwd(), 'package.json'));
68
- const generatedClient = resolveProjectPrismaClientModule();
69
- if (generatedClient) {
70
- const url = process.env.DATABASE_URL;
71
- const [clientModule, adapterModule, pgModule] = await Promise.all([
72
- importProjectTypescript(generatedClient),
73
- importModule('@prisma/adapter-pg', requireFromProject),
74
- importModule('pg', requireFromProject),
75
- ]);
76
- const { PrismaClient } = clientModule;
77
- if (isAcceleratedDbUrl(url)) {
78
- let withAccelerate;
79
- try {
80
- const ext = (await importModule('@prisma/extension-accelerate', requireFromProject));
81
- withAccelerate = ext.withAccelerate;
82
- }
83
- catch {
84
- throw new Error('DATABASE_URL uses Prisma Accelerate but @prisma/extension-accelerate is not installed. Run `lib/prisma.ts` via adding it, or install the extension.');
85
- }
86
- const client = new PrismaClient({ accelerateUrl: url }).$extends(withAccelerate());
87
- return client;
88
- }
89
- const { PrismaPg } = adapterModule;
90
- const pg = pgModule.default ?? pgModule;
91
- const pool = new pg.Pool({ connectionString: url });
92
- const adapter = new PrismaPg(pool);
93
- return new PrismaClient({ adapter });
107
+ const plan = resolvePrismaClientLoadPlan();
108
+ if (plan.source === 'generated') {
109
+ return createClientFromGenerated(plan.clientPath);
94
110
  }
111
+ if (plan.source === 'lib-prisma') {
112
+ const fromLib = await tryLibPrismaClient(plan.helperPath);
113
+ if (fromLib)
114
+ return fromLib;
115
+ }
116
+ const requireFromProject = createRequire(path.join(process.cwd(), 'package.json'));
95
117
  const clientModule = (await importModule('@prisma/client', requireFromProject));
96
118
  return new clientModule.PrismaClient();
97
119
  }
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAChE,OAAO,EAAE,mBAAmB,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAA;AAE/F;;;;;;;;;;;;;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AAE,GAAG,aAA6D,CAAA;IAClF,MAAM,EAAE,GAAI,QAA0C,CAAC,OAAO,IAAI,QAAQ,CAAA;IAC1E,MAAM,IAAI,GAAG,IAAK,EAAU,CAAC,IAAI,CAAC,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAA;IAC5D,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAA;IAClC,OAAO,IAAI,YAAY,CAAC,EAAE,OAAO,EAAS,CAAC,CAAA;AAC7C,CAAC;AAED,4EAA4E;AAC5E,KAAK,UAAU,yBAAyB;IACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAA;IACjF,CAAC;IAED,MAAM,IAAI,GAAG,2BAA2B,EAAE,CAAA;IAC1C,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,yBAAyB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACnD,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACzD,IAAI,OAAO;YAAE,OAAO,OAAO,CAAA;IAC7B,CAAC;IAED,MAAM,kBAAkB,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC,CAAA;IAClF,MAAM,YAAY,GAAG,CAAC,MAAM,YAAY,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAE7E,CAAA;IACD,OAAO,IAAI,YAAY,CAAC,YAAY,EAAE,CAAA;AACxC,CAAC"}
@@ -14,7 +14,23 @@ export declare function resolveClientEntryInDir(dir: string): string | null;
14
14
  * scaffold locations (`generated/prisma`, `src/generated`, …).
15
15
  */
16
16
  export declare function resolveProjectPrismaClientModule(cwd?: string): string | null;
17
- /** Project helpers that wrap Prisma 7 + driver adapters (preferred when present). */
17
+ /** Project helpers that wrap Prisma 7 + driver adapters. Used only when no generated client exists. */
18
18
  export declare const LIB_PRISMA_HELPERS: readonly ["lib/prisma.ts", "lib/prisma.js", "lib/prisma.mjs"];
19
19
  export declare function findLibPrismaHelper(cwd?: string): string | null;
20
+ export type PrismaClientLoadPlan = {
21
+ source: 'generated';
22
+ clientPath: string;
23
+ } | {
24
+ source: 'lib-prisma';
25
+ helperPath: string;
26
+ } | {
27
+ source: 'legacy-package';
28
+ };
29
+ /**
30
+ * Generated TypeScript client always wins over `lib/prisma.ts`. Evaluating the
31
+ * helper first compiled its import of `../generated/prisma/client` into a CJS
32
+ * `require()`, which cannot load the modern `prisma-client` generator output
33
+ * on Windows.
34
+ */
35
+ export declare function resolvePrismaClientLoadPlan(cwd?: string): PrismaClientLoadPlan;
20
36
  //# sourceMappingURL=prisma-client-path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prisma-client-path.d.ts","sourceRoot":"","sources":["../../src/utils/prisma-client-path.ts"],"names":[],"mappings":"AASA,wDAAwD;AACxD,wBAAgB,oBAAoB,CAAC,GAAG,SAAgB,GAAG,MAAM,GAAG,IAAI,CAMvE;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAc/E;AAED,4DAA4D;AAC5D,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMlE;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,GAAG,SAAgB,GAAG,MAAM,GAAG,IAAI,CAgBnF;AAED,qFAAqF;AACrF,eAAO,MAAM,kBAAkB,+DAAgE,CAAA;AAE/F,wBAAgB,mBAAmB,CAAC,GAAG,SAAgB,GAAG,MAAM,GAAG,IAAI,CAMtE"}
1
+ {"version":3,"file":"prisma-client-path.d.ts","sourceRoot":"","sources":["../../src/utils/prisma-client-path.ts"],"names":[],"mappings":"AASA,wDAAwD;AACxD,wBAAgB,oBAAoB,CAAC,GAAG,SAAgB,GAAG,MAAM,GAAG,IAAI,CAMvE;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAc/E;AAED,4DAA4D;AAC5D,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMlE;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,GAAG,SAAgB,GAAG,MAAM,GAAG,IAAI,CAgBnF;AAED,uGAAuG;AACvG,eAAO,MAAM,kBAAkB,+DAAgE,CAAA;AAE/F,wBAAgB,mBAAmB,CAAC,GAAG,SAAgB,GAAG,MAAM,GAAG,IAAI,CAMtE;AAED,MAAM,MAAM,oBAAoB,GAC5B;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAC3C;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAAA;AAEhC;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,SAAgB,GAAG,oBAAoB,CAMrF"}
@@ -64,7 +64,7 @@ export function resolveProjectPrismaClientModule(cwd = process.cwd()) {
64
64
  }
65
65
  return null;
66
66
  }
67
- /** Project helpers that wrap Prisma 7 + driver adapters (preferred when present). */
67
+ /** Project helpers that wrap Prisma 7 + driver adapters. Used only when no generated client exists. */
68
68
  export const LIB_PRISMA_HELPERS = ['lib/prisma.ts', 'lib/prisma.js', 'lib/prisma.mjs'];
69
69
  export function findLibPrismaHelper(cwd = process.cwd()) {
70
70
  for (const rel of LIB_PRISMA_HELPERS) {
@@ -74,4 +74,19 @@ export function findLibPrismaHelper(cwd = process.cwd()) {
74
74
  }
75
75
  return null;
76
76
  }
77
+ /**
78
+ * Generated TypeScript client always wins over `lib/prisma.ts`. Evaluating the
79
+ * helper first compiled its import of `../generated/prisma/client` into a CJS
80
+ * `require()`, which cannot load the modern `prisma-client` generator output
81
+ * on Windows.
82
+ */
83
+ export function resolvePrismaClientLoadPlan(cwd = process.cwd()) {
84
+ const generated = resolveProjectPrismaClientModule(cwd);
85
+ if (generated)
86
+ return { source: 'generated', clientPath: generated };
87
+ const helper = findLibPrismaHelper(cwd);
88
+ if (helper)
89
+ return { source: 'lib-prisma', helperPath: helper };
90
+ return { source: 'legacy-package' };
91
+ }
77
92
  //# sourceMappingURL=prisma-client-path.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prisma-client-path.js","sourceRoot":"","sources":["../../src/utils/prisma-client-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,MAAM,iBAAiB,GAAG,CAAC,sBAAsB,EAAE,eAAe,CAAU,CAAA;AAE5E,MAAM,kBAAkB,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,CAAU,CAAA;AAEpG,MAAM,oBAAoB,GAAG,CAAC,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,CAAU,CAAA;AAEpG,wDAAwD;AACxD,MAAM,UAAU,oBAAoB,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IACtD,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACpC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QACrC,IAAI,UAAU,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAA;IAC7C,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU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AAE,CAAA;IACpE,MAAM,MAAM,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAA;IACvC,IAAI,MAAM;QAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;IAC/D,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAA;AACrC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prenta/cli",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "license": "MIT",
5
5
  "description": "CLI for Prenta CMS — migrations, codegen, imports, exports, and upgrades",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "devDependencies": {
30
30
  "typescript": "^5.7.0",
31
31
  "vitest": "^4.1.0",
32
- "@prenta/core": "2.3.1"
32
+ "@prenta/core": "2.3.2"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsc",
@@ -7,6 +7,7 @@ import {
7
7
  findPrismaSchemaFile,
8
8
  parsePrismaGeneratorOutputDir,
9
9
  resolveClientEntryInDir,
10
+ resolvePrismaClientLoadPlan,
10
11
  resolveProjectPrismaClientModule,
11
12
  } from '../utils/prisma-client-path.js'
12
13
 
@@ -84,4 +85,31 @@ datasource db {
84
85
  writeFileSync(path.join(tempDir, 'client.ts'), 'export class PrismaClient {}')
85
86
  expect(resolveClientEntryInDir(tempDir)).toBe(path.join(tempDir, 'client.ts'))
86
87
  })
88
+
89
+ it('prefers the generated TypeScript client over lib/prisma.ts', () => {
90
+ tempDir = mkdtempSync(path.join(tmpdir(), 'prenta-cli-prisma-plan-'))
91
+ writeSchema(tempDir, '../generated/prisma')
92
+ const clientPath = path.join(tempDir, 'generated', 'prisma', 'client.ts')
93
+ writeClient(clientPath)
94
+ mkdirSync(path.join(tempDir, 'lib'), { recursive: true })
95
+ writeFileSync(
96
+ path.join(tempDir, 'lib', 'prisma.ts'),
97
+ "const { PrismaClient } = require('../generated/prisma/client')\nexport function getPrisma() { return new PrismaClient() }\n",
98
+ )
99
+ expect(resolvePrismaClientLoadPlan(tempDir)).toEqual({
100
+ source: 'generated',
101
+ clientPath,
102
+ })
103
+ })
104
+
105
+ it('uses lib/prisma.ts only when no generated client exists', () => {
106
+ tempDir = mkdtempSync(path.join(tmpdir(), 'prenta-cli-prisma-lib-'))
107
+ mkdirSync(path.join(tempDir, 'lib'), { recursive: true })
108
+ const helperPath = path.join(tempDir, 'lib', 'prisma.ts')
109
+ writeFileSync(helperPath, 'export function getPrisma() { return null }\n')
110
+ expect(resolvePrismaClientLoadPlan(tempDir)).toEqual({
111
+ source: 'lib-prisma',
112
+ helperPath,
113
+ })
114
+ })
87
115
  })
@@ -3,21 +3,31 @@ import path from 'node:path'
3
3
  import { pathToFileURL } from 'node:url'
4
4
 
5
5
  import { importProjectTypescript } from './import-typescript.js'
6
- import { findLibPrismaHelper, resolveProjectPrismaClientModule } from './prisma-client-path.js'
6
+ import { resolvePrismaClientLoadPlan } from './prisma-client-path.js'
7
7
 
8
8
  /**
9
9
  * Shared helper for CLI commands that need a live connection to the consumer
10
10
  * project's database (seed, populate, data migrations…).
11
11
  *
12
- * Resolution order mirrors how a scaffolded Prenta project exposes Prisma:
12
+ * Resolution order:
13
13
  * 1. If `cms-core` already has an initialized client (e.g. set up by the host
14
14
  * app in-process), reuse it.
15
- * 2. Otherwise call `getPrisma()` from `lib/prisma.ts` when the project ships
16
- * one (Prisma 7 + pg adapter / Accelerate — same path Next.js uses).
17
- * 3. Otherwise build a client from the schema's `output` path (custom or
18
- * default `generated/prisma/client.ts`) via tsx + pg driver adapter.
15
+ * 2. Load the generated Prisma client (`generated/prisma/client.ts`) via tsx's
16
+ * process-wide ESM hook and `file://` URLs, then construct PrismaClient
17
+ * with the pg adapter or Accelerate — same setup as a scaffolded
18
+ * `lib/prisma.ts`, without evaluating that file.
19
+ * 3. Only when no generated client exists, call `getPrisma()` from
20
+ * `lib/prisma.ts` (best-effort; a CJS `require` of a TypeScript client
21
+ * will fail on Windows).
19
22
  * 4. Fall back to a plain `@prisma/client` resolved from the project.
20
23
  *
24
+ * Evaluating `lib/prisma.ts` first is what broke `migrate:*` on Windows: tsx
25
+ * compiled its `import … from '../generated/prisma/client'` into
26
+ * `require('../generated/prisma/client')`, which cannot load the modern
27
+ * TypeScript `prisma-client` generator output. Each CJS fallback just moved
28
+ * the crash to the next `.ts` import. The generated-client ESM path is the
29
+ * durable fix.
30
+ *
21
31
  * The returned `disconnect()` only tears down clients this helper created — a
22
32
  * pre-initialized in-process client is left untouched.
23
33
  */
@@ -57,17 +67,57 @@ async function importModule(specifier: string, requireFromProject: NodeRequire):
57
67
  return import(href)
58
68
  }
59
69
 
60
- async function tryLibPrismaClient(): Promise<any | null> {
61
- const helperPath = findLibPrismaHelper()
62
- if (!helperPath) return null
70
+ async function tryLibPrismaClient(helperPath: string): Promise<any | null> {
71
+ try {
72
+ const mod = (await importProjectTypescript(helperPath)) as {
73
+ getPrisma?: () => unknown
74
+ default?: { getPrisma?: () => unknown }
75
+ }
76
+ const getPrisma = mod.getPrisma ?? mod.default?.getPrisma
77
+ if (typeof getPrisma !== 'function') return null
78
+ return getPrisma()
79
+ } catch {
80
+ // `lib/prisma.ts` often `require()`s the generated TypeScript client.
81
+ // That cannot work on Windows; callers fall through or throw from the
82
+ // generated-client path instead.
83
+ return null
84
+ }
85
+ }
86
+
87
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above.
88
+ async function createClientFromGenerated(generatedClient: string): Promise<any> {
89
+ const requireFromProject = createRequire(path.join(process.cwd(), 'package.json'))
90
+ const url = process.env.DATABASE_URL
91
+ const [clientModule, adapterModule, pgModule] = await Promise.all([
92
+ importProjectTypescript(generatedClient),
93
+ importModule('@prisma/adapter-pg', requireFromProject),
94
+ importModule('pg', requireFromProject),
95
+ ])
96
+ const { PrismaClient } = clientModule as {
97
+ PrismaClient: new (options?: unknown) => any
98
+ }
63
99
 
64
- const mod = (await importProjectTypescript(helperPath)) as {
65
- getPrisma?: () => unknown
66
- default?: { getPrisma?: () => unknown }
100
+ if (isAcceleratedDbUrl(url)) {
101
+ let withAccelerate: () => unknown
102
+ try {
103
+ const ext = (await importModule('@prisma/extension-accelerate', requireFromProject)) as {
104
+ withAccelerate: () => unknown
105
+ }
106
+ withAccelerate = ext.withAccelerate
107
+ } catch {
108
+ throw new Error(
109
+ 'DATABASE_URL uses Prisma Accelerate but @prisma/extension-accelerate is not installed. Install the extension or use a postgresql:// URL.',
110
+ )
111
+ }
112
+ const client = new PrismaClient({ accelerateUrl: url } as never).$extends(withAccelerate())
113
+ return client
67
114
  }
68
- const getPrisma = mod.getPrisma ?? mod.default?.getPrisma
69
- if (typeof getPrisma !== 'function') return null
70
- return getPrisma()
115
+
116
+ const { PrismaPg } = adapterModule as { PrismaPg: new (pool: unknown) => unknown }
117
+ const pg = (pgModule as { default?: typeof pgModule }).default ?? pgModule
118
+ const pool = new (pg as any).Pool({ connectionString: url })
119
+ const adapter = new PrismaPg(pool)
120
+ return new PrismaClient({ adapter } as any)
71
121
  }
72
122
 
73
123
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above.
@@ -76,46 +126,17 @@ async function createProjectPrismaClient(): Promise<any> {
76
126
  throw new Error('DATABASE_URL is required to connect to the project database.')
77
127
  }
78
128
 
79
- const fromLib = await tryLibPrismaClient()
80
- if (fromLib) return fromLib
81
-
82
- const requireFromProject = createRequire(path.join(process.cwd(), 'package.json'))
83
- const generatedClient = resolveProjectPrismaClientModule()
84
-
85
- if (generatedClient) {
86
- const url = process.env.DATABASE_URL
87
- const [clientModule, adapterModule, pgModule] = await Promise.all([
88
- importProjectTypescript(generatedClient),
89
- importModule('@prisma/adapter-pg', requireFromProject),
90
- importModule('pg', requireFromProject),
91
- ])
92
- const { PrismaClient } = clientModule as {
93
- PrismaClient: new (options?: unknown) => any
94
- }
95
-
96
- if (isAcceleratedDbUrl(url)) {
97
- let withAccelerate: () => unknown
98
- try {
99
- const ext = (await importModule('@prisma/extension-accelerate', requireFromProject)) as {
100
- withAccelerate: () => unknown
101
- }
102
- withAccelerate = ext.withAccelerate
103
- } catch {
104
- throw new Error(
105
- 'DATABASE_URL uses Prisma Accelerate but @prisma/extension-accelerate is not installed. Run `lib/prisma.ts` via adding it, or install the extension.',
106
- )
107
- }
108
- const client = new PrismaClient({ accelerateUrl: url } as never).$extends(withAccelerate())
109
- return client
110
- }
129
+ const plan = resolvePrismaClientLoadPlan()
130
+ if (plan.source === 'generated') {
131
+ return createClientFromGenerated(plan.clientPath)
132
+ }
111
133
 
112
- const { PrismaPg } = adapterModule as { PrismaPg: new (pool: unknown) => unknown }
113
- const pg = (pgModule as { default?: typeof pgModule }).default ?? pgModule
114
- const pool = new (pg as any).Pool({ connectionString: url })
115
- const adapter = new PrismaPg(pool)
116
- return new PrismaClient({ adapter } as any)
134
+ if (plan.source === 'lib-prisma') {
135
+ const fromLib = await tryLibPrismaClient(plan.helperPath)
136
+ if (fromLib) return fromLib
117
137
  }
118
138
 
139
+ const requireFromProject = createRequire(path.join(process.cwd(), 'package.json'))
119
140
  const clientModule = (await importModule('@prisma/client', requireFromProject)) as {
120
141
  PrismaClient: new () => any
121
142
  }
@@ -69,7 +69,7 @@ export function resolveProjectPrismaClientModule(cwd = process.cwd()): string |
69
69
  return null
70
70
  }
71
71
 
72
- /** Project helpers that wrap Prisma 7 + driver adapters (preferred when present). */
72
+ /** Project helpers that wrap Prisma 7 + driver adapters. Used only when no generated client exists. */
73
73
  export const LIB_PRISMA_HELPERS = ['lib/prisma.ts', 'lib/prisma.js', 'lib/prisma.mjs'] as const
74
74
 
75
75
  export function findLibPrismaHelper(cwd = process.cwd()): string | null {
@@ -79,3 +79,22 @@ export function findLibPrismaHelper(cwd = process.cwd()): string | null {
79
79
  }
80
80
  return null
81
81
  }
82
+
83
+ export type PrismaClientLoadPlan =
84
+ | { source: 'generated'; clientPath: string }
85
+ | { source: 'lib-prisma'; helperPath: string }
86
+ | { source: 'legacy-package' }
87
+
88
+ /**
89
+ * Generated TypeScript client always wins over `lib/prisma.ts`. Evaluating the
90
+ * helper first compiled its import of `../generated/prisma/client` into a CJS
91
+ * `require()`, which cannot load the modern `prisma-client` generator output
92
+ * on Windows.
93
+ */
94
+ export function resolvePrismaClientLoadPlan(cwd = process.cwd()): PrismaClientLoadPlan {
95
+ const generated = resolveProjectPrismaClientModule(cwd)
96
+ if (generated) return { source: 'generated', clientPath: generated }
97
+ const helper = findLibPrismaHelper(cwd)
98
+ if (helper) return { source: 'lib-prisma', helperPath: helper }
99
+ return { source: 'legacy-package' }
100
+ }