@prenta/cli 0.16.1 → 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.
- package/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +25 -192
- package/CHANGELOG.md +12 -0
- package/dist/commands/migrate-media-optimize.d.ts.map +1 -1
- package/dist/commands/migrate-media-optimize.js +2 -4
- package/dist/commands/migrate-media-optimize.js.map +1 -1
- package/dist/commands/migrate-meta.d.ts.map +1 -1
- package/dist/commands/migrate-meta.js +2 -4
- package/dist/commands/migrate-meta.js.map +1 -1
- package/dist/commands/migrate-schema.d.ts.map +1 -1
- package/dist/commands/migrate-schema.js +2 -4
- package/dist/commands/migrate-schema.js.map +1 -1
- package/dist/commands/seed.d.ts.map +1 -1
- package/dist/commands/seed.js +3 -4
- package/dist/commands/seed.js.map +1 -1
- package/dist/utils/database.d.ts +15 -5
- package/dist/utils/database.d.ts.map +1 -1
- package/dist/utils/database.js +59 -47
- package/dist/utils/database.js.map +1 -1
- package/dist/utils/import-typescript.d.ts +17 -0
- package/dist/utils/import-typescript.d.ts.map +1 -0
- package/dist/utils/import-typescript.js +31 -0
- package/dist/utils/import-typescript.js.map +1 -0
- package/dist/utils/prisma-client-path.d.ts +17 -1
- package/dist/utils/prisma-client-path.d.ts.map +1 -1
- package/dist/utils/prisma-client-path.js +16 -1
- package/dist/utils/prisma-client-path.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/fixtures/tsx-loader/client.ts +3 -0
- package/src/__tests__/fixtures/tsx-loader/enums.ts +1 -0
- package/src/__tests__/import-typescript.test.ts +30 -0
- package/src/__tests__/prisma-client-path.test.ts +28 -0
- package/src/commands/migrate-media-optimize.ts +2 -4
- package/src/commands/migrate-meta.ts +2 -4
- package/src/commands/migrate-schema.ts +2 -4
- package/src/commands/seed.ts +3 -4
- package/src/utils/database.ts +66 -57
- package/src/utils/import-typescript.ts +32 -0
- package/src/utils/prisma-client-path.ts +20 -1
- package/tsconfig.json +2 -1
- package/vitest.config.ts +8 -0
- package/dist/__tests__/db-init.test.d.ts +0 -2
- package/dist/__tests__/db-init.test.d.ts.map +0 -1
- package/dist/__tests__/db-init.test.js +0 -127
- package/dist/__tests__/db-init.test.js.map +0 -1
- package/dist/__tests__/db-sync-resolver.test.d.ts +0 -2
- package/dist/__tests__/db-sync-resolver.test.d.ts.map +0 -1
- package/dist/__tests__/db-sync-resolver.test.js +0 -25
- package/dist/__tests__/db-sync-resolver.test.js.map +0 -1
- package/dist/__tests__/db-sync.test.d.ts +0 -2
- package/dist/__tests__/db-sync.test.d.ts.map +0 -1
- package/dist/__tests__/db-sync.test.js +0 -214
- package/dist/__tests__/db-sync.test.js.map +0 -1
- package/dist/__tests__/deployment-diagnostics.test.d.ts +0 -2
- package/dist/__tests__/deployment-diagnostics.test.d.ts.map +0 -1
- package/dist/__tests__/deployment-diagnostics.test.js +0 -401
- package/dist/__tests__/deployment-diagnostics.test.js.map +0 -1
- package/dist/__tests__/form-seed.test.d.ts +0 -2
- package/dist/__tests__/form-seed.test.d.ts.map +0 -1
- package/dist/__tests__/form-seed.test.js +0 -79
- package/dist/__tests__/form-seed.test.js.map +0 -1
- package/dist/__tests__/init.test.d.ts +0 -2
- package/dist/__tests__/init.test.d.ts.map +0 -1
- package/dist/__tests__/init.test.js +0 -25
- package/dist/__tests__/init.test.js.map +0 -1
- package/dist/__tests__/load-dotenv.test.d.ts +0 -2
- package/dist/__tests__/load-dotenv.test.d.ts.map +0 -1
- package/dist/__tests__/load-dotenv.test.js +0 -40
- package/dist/__tests__/load-dotenv.test.js.map +0 -1
- package/dist/__tests__/mcp-init.test.d.ts +0 -2
- package/dist/__tests__/mcp-init.test.d.ts.map +0 -1
- package/dist/__tests__/mcp-init.test.js +0 -100
- package/dist/__tests__/mcp-init.test.js.map +0 -1
- package/dist/__tests__/prisma-client-path.test.d.ts +0 -2
- package/dist/__tests__/prisma-client-path.test.d.ts.map +0 -1
- package/dist/__tests__/prisma-client-path.test.js +0 -66
- package/dist/__tests__/prisma-client-path.test.js.map +0 -1
- package/dist/__tests__/schema-fragment.test.d.ts +0 -2
- package/dist/__tests__/schema-fragment.test.d.ts.map +0 -1
- package/dist/__tests__/schema-fragment.test.js +0 -40
- package/dist/__tests__/schema-fragment.test.js.map +0 -1
- package/dist/__tests__/seed.test.d.ts +0 -2
- package/dist/__tests__/seed.test.d.ts.map +0 -1
- package/dist/__tests__/seed.test.js +0 -207
- package/dist/__tests__/seed.test.js.map +0 -1
- package/dist/__tests__/upgrade.test.d.ts +0 -2
- package/dist/__tests__/upgrade.test.d.ts.map +0 -1
- package/dist/__tests__/upgrade.test.js +0 -41
- package/dist/__tests__/upgrade.test.js.map +0 -1
- package/dist/__tests__/vercel-env-matrix.test.d.ts +0 -2
- package/dist/__tests__/vercel-env-matrix.test.d.ts.map +0 -1
- package/dist/__tests__/vercel-env-matrix.test.js +0 -56
- package/dist/__tests__/vercel-env-matrix.test.js.map +0 -1
package/dist/utils/database.js
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import {
|
|
4
|
+
import { importProjectTypescript } from './import-typescript.js';
|
|
5
|
+
import { resolvePrismaClientLoadPlan } from './prisma-client-path.js';
|
|
5
6
|
/**
|
|
6
7
|
* Shared helper for CLI commands that need a live connection to the consumer
|
|
7
8
|
* project's database (seed, populate, data migrations…).
|
|
8
9
|
*
|
|
9
|
-
* Resolution order
|
|
10
|
+
* Resolution order:
|
|
10
11
|
* 1. If `cms-core` already has an initialized client (e.g. set up by the host
|
|
11
12
|
* app in-process), reuse it.
|
|
12
|
-
* 2.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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).
|
|
16
20
|
* 4. Fall back to a plain `@prisma/client` resolved from the project.
|
|
17
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
|
+
*
|
|
18
29
|
* The returned `disconnect()` only tears down clients this helper created — a
|
|
19
30
|
* pre-initialized in-process client is left untouched.
|
|
20
31
|
*/
|
|
@@ -45,63 +56,64 @@ async function importModule(specifier, requireFromProject) {
|
|
|
45
56
|
const href = pathToFileURL(requireFromProject.resolve(specifier)).href;
|
|
46
57
|
return import(href);
|
|
47
58
|
}
|
|
48
|
-
async function tryLibPrismaClient() {
|
|
49
|
-
const helperPath = findLibPrismaHelper();
|
|
50
|
-
if (!helperPath)
|
|
51
|
-
return null;
|
|
59
|
+
async function tryLibPrismaClient(helperPath) {
|
|
52
60
|
try {
|
|
53
|
-
const
|
|
54
|
-
// Parent must be a file:// URL. tsx appends `?namespace=` to resolved
|
|
55
|
-
// absolute paths; on Windows (especially with spaces) Node's ESM loader
|
|
56
|
-
// then rejects `@prisma/adapter-pg` and every `migrate:*` command dies.
|
|
57
|
-
const parent = pathToFileURL(path.join(process.cwd(), 'package.json')).href;
|
|
58
|
-
const mod = (await tsImport(pathToFileURL(helperPath).href, parent));
|
|
61
|
+
const mod = (await importProjectTypescript(helperPath));
|
|
59
62
|
const getPrisma = mod.getPrisma ?? mod.default?.getPrisma;
|
|
60
63
|
if (typeof getPrisma !== 'function')
|
|
61
64
|
return null;
|
|
62
65
|
return getPrisma();
|
|
63
66
|
}
|
|
64
67
|
catch {
|
|
65
|
-
//
|
|
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.
|
|
66
71
|
return null;
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
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 });
|
|
101
|
+
}
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above.
|
|
70
103
|
async function createProjectPrismaClient() {
|
|
71
104
|
if (!process.env.DATABASE_URL) {
|
|
72
105
|
throw new Error('DATABASE_URL is required to connect to the project database.');
|
|
73
106
|
}
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
import('tsx/esm/api'),
|
|
83
|
-
importModule('@prisma/adapter-pg', requireFromProject),
|
|
84
|
-
importModule('pg', requireFromProject),
|
|
85
|
-
]);
|
|
86
|
-
const { PrismaClient } = (await tsImport(pathToFileURL(generatedClient).href, import.meta.url));
|
|
87
|
-
if (isAcceleratedDbUrl(url)) {
|
|
88
|
-
let withAccelerate;
|
|
89
|
-
try {
|
|
90
|
-
const ext = (await importModule('@prisma/extension-accelerate', requireFromProject));
|
|
91
|
-
withAccelerate = ext.withAccelerate;
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
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.');
|
|
95
|
-
}
|
|
96
|
-
const client = new PrismaClient({ accelerateUrl: url }).$extends(withAccelerate());
|
|
97
|
-
return client;
|
|
98
|
-
}
|
|
99
|
-
const { PrismaPg } = adapterModule;
|
|
100
|
-
const pg = pgModule.default ?? pgModule;
|
|
101
|
-
const pool = new pg.Pool({ connectionString: url });
|
|
102
|
-
const adapter = new PrismaPg(pool);
|
|
103
|
-
return new PrismaClient({ adapter });
|
|
107
|
+
const plan = resolvePrismaClientLoadPlan();
|
|
108
|
+
if (plan.source === 'generated') {
|
|
109
|
+
return createClientFromGenerated(plan.clientPath);
|
|
110
|
+
}
|
|
111
|
+
if (plan.source === 'lib-prisma') {
|
|
112
|
+
const fromLib = await tryLibPrismaClient(plan.helperPath);
|
|
113
|
+
if (fromLib)
|
|
114
|
+
return fromLib;
|
|
104
115
|
}
|
|
116
|
+
const requireFromProject = createRequire(path.join(process.cwd(), 'package.json'));
|
|
105
117
|
const clientModule = (await importModule('@prisma/client', requireFromProject));
|
|
106
118
|
return new clientModule.PrismaClient();
|
|
107
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,
|
|
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,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB;IAK1C,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAA;IAEvE,IAAI,eAAe,EAAE,EAAE,CAAC;QACtB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAO,EAAE,UAAU,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC,EAAE,CAAA;IACzD,CAAC;IAED,MAAM,EAAE,GAAG,MAAM,yBAAyB,EAAE,CAAA;IAC5C,MAAM,CAAC,EAAE,CAAC,CAAA;IACV,OAAO;QACL,EAAE;QACF,UAAU,EAAE,KAAK,IAAI,EAAE;YACrB,IAAI,OAAO,EAAE,CAAC,WAAW,KAAK,UAAU,EAAE,CAAC;gBAC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AE,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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn a filesystem path into a `file://` URL with no query string.
|
|
3
|
+
*
|
|
4
|
+
* `tsx`'s `tsImport()` appends `?namespace=` to child specifiers. On Windows
|
|
5
|
+
* those leak through as raw paths (`C:\Git Local\...\enums.ts?namespace=1`),
|
|
6
|
+
* which `fs.open` rejects. Every project TS load must stay on a file URL.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toProjectFileUrl(filePath: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Load a consumer TypeScript file (prenta.config.ts, lib/prisma.ts,
|
|
11
|
+
* generated/prisma/client.ts) via tsx's process-wide ESM hook.
|
|
12
|
+
*
|
|
13
|
+
* Do not use `tsImport()` — its namespaced loader is what produced the
|
|
14
|
+
* Windows `?namespace=` crashes on adapter-pg and then enums.ts.
|
|
15
|
+
*/
|
|
16
|
+
export declare function importProjectTypescript(filePath: string): Promise<unknown>;
|
|
17
|
+
//# sourceMappingURL=import-typescript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-typescript.d.ts","sourceRoot":"","sources":["../../src/utils/import-typescript.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOhF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
let registered = false;
|
|
4
|
+
/**
|
|
5
|
+
* Turn a filesystem path into a `file://` URL with no query string.
|
|
6
|
+
*
|
|
7
|
+
* `tsx`'s `tsImport()` appends `?namespace=` to child specifiers. On Windows
|
|
8
|
+
* those leak through as raw paths (`C:\Git Local\...\enums.ts?namespace=1`),
|
|
9
|
+
* which `fs.open` rejects. Every project TS load must stay on a file URL.
|
|
10
|
+
*/
|
|
11
|
+
export function toProjectFileUrl(filePath) {
|
|
12
|
+
if (filePath.startsWith('file:'))
|
|
13
|
+
return filePath;
|
|
14
|
+
return pathToFileURL(path.resolve(filePath)).href;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Load a consumer TypeScript file (prenta.config.ts, lib/prisma.ts,
|
|
18
|
+
* generated/prisma/client.ts) via tsx's process-wide ESM hook.
|
|
19
|
+
*
|
|
20
|
+
* Do not use `tsImport()` — its namespaced loader is what produced the
|
|
21
|
+
* Windows `?namespace=` crashes on adapter-pg and then enums.ts.
|
|
22
|
+
*/
|
|
23
|
+
export async function importProjectTypescript(filePath) {
|
|
24
|
+
if (!registered) {
|
|
25
|
+
const { register } = await import('tsx/esm/api');
|
|
26
|
+
register();
|
|
27
|
+
registered = true;
|
|
28
|
+
}
|
|
29
|
+
return import(toProjectFileUrl(filePath));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=import-typescript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-typescript.js","sourceRoot":"","sources":["../../src/utils/import-typescript.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,IAAI,UAAU,GAAG,KAAK,CAAA;AAEtB;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,QAAQ,CAAA;IACjD,OAAO,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAA;AACnD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,QAAgB;IAC5D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAA;QAChD,QAAQ,EAAE,CAAA;QACV,UAAU,GAAG,IAAI,CAAA;IACnB,CAAC;IACD,OAAO,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAA;AAC3C,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
|
|
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,
|
|
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
|
|
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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version": "0.16.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "CLI for Prenta CMS — migrations, codegen, imports, exports, and upgrades",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"chalk": "^5.4.1",
|
|
22
22
|
"commander": "^13.1.0",
|
|
23
23
|
"ora": "^8.2.0",
|
|
24
|
-
"tsx": "^4.
|
|
24
|
+
"tsx": "^4.23.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@prenta/core": ">=0.1.0"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"typescript": "^5.7.0",
|
|
31
31
|
"vitest": "^4.1.0",
|
|
32
|
-
"@prenta/core": "2.3.
|
|
32
|
+
"@prenta/core": "2.3.2"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsc",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const MediaKind = 'image'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
|
|
5
|
+
import { importProjectTypescript, toProjectFileUrl } from '../utils/import-typescript.js'
|
|
6
|
+
|
|
7
|
+
describe('toProjectFileUrl', () => {
|
|
8
|
+
it('converts a path with spaces into a file URL without a query', () => {
|
|
9
|
+
const href = toProjectFileUrl(
|
|
10
|
+
path.join('Git Local', 'upchat', 'generated', 'prisma', 'enums.ts'),
|
|
11
|
+
)
|
|
12
|
+
expect(href.startsWith('file:')).toBe(true)
|
|
13
|
+
expect(href.includes('?')).toBe(false)
|
|
14
|
+
expect(href).toContain('Git%20Local')
|
|
15
|
+
expect(href.endsWith('enums.ts')).toBe(true)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('leaves an existing file URL unchanged', () => {
|
|
19
|
+
const href = 'file:///C:/Git%20Local/upchat/lib/prisma.ts'
|
|
20
|
+
expect(toProjectFileUrl(href)).toBe(href)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('importProjectTypescript', () => {
|
|
25
|
+
it('loads a TypeScript file that imports a sibling without appending ?namespace=', async () => {
|
|
26
|
+
const parent = fileURLToPath(new URL('./fixtures/tsx-loader/client.ts', import.meta.url))
|
|
27
|
+
const mod = (await importProjectTypescript(parent)) as { marker: string }
|
|
28
|
+
expect(mod.marker).toBe('image')
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -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
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Command } from 'commander'
|
|
2
2
|
import { resolve } from 'node:path'
|
|
3
|
-
import { pathToFileURL } from 'node:url'
|
|
4
3
|
import ora from 'ora'
|
|
5
4
|
import { connectProjectDatabase } from '../utils/database.js'
|
|
5
|
+
import { importProjectTypescript } from '../utils/import-typescript.js'
|
|
6
6
|
import { loadProjectEnv } from '../utils/load-dotenv.js'
|
|
7
7
|
import { logger } from '../utils/logger.js'
|
|
8
8
|
|
|
@@ -18,9 +18,7 @@ async function loadProjectConfig(configPath: string): Promise<void> {
|
|
|
18
18
|
try {
|
|
19
19
|
const { setPrentaConfig, setStorageAdapter, autoWireStorageAdapter } =
|
|
20
20
|
await import('@prenta/core')
|
|
21
|
-
const
|
|
22
|
-
const abs = pathToFileURL(resolve(configPath)).href
|
|
23
|
-
const mod = (await tsImport(abs, import.meta.url)) as {
|
|
21
|
+
const mod = (await importProjectTypescript(resolve(configPath))) as {
|
|
24
22
|
default?: unknown
|
|
25
23
|
config?: unknown
|
|
26
24
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Command } from 'commander'
|
|
2
2
|
import { resolve } from 'node:path'
|
|
3
|
-
import { pathToFileURL } from 'node:url'
|
|
4
3
|
import ora from 'ora'
|
|
5
4
|
import { connectProjectDatabase } from '../utils/database.js'
|
|
5
|
+
import { importProjectTypescript } from '../utils/import-typescript.js'
|
|
6
6
|
import { loadProjectEnv } from '../utils/load-dotenv.js'
|
|
7
7
|
import { logger } from '../utils/logger.js'
|
|
8
8
|
|
|
@@ -15,9 +15,7 @@ interface MigrateMetaOptions {
|
|
|
15
15
|
async function loadProjectConfig(configPath: string): Promise<void> {
|
|
16
16
|
try {
|
|
17
17
|
const { setPrentaConfig } = await import('@prenta/core')
|
|
18
|
-
const
|
|
19
|
-
const abs = pathToFileURL(resolve(configPath)).href
|
|
20
|
-
const mod = (await tsImport(abs, import.meta.url)) as {
|
|
18
|
+
const mod = (await importProjectTypescript(resolve(configPath))) as {
|
|
21
19
|
default?: unknown
|
|
22
20
|
config?: unknown
|
|
23
21
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Command } from 'commander'
|
|
2
2
|
import { resolve } from 'node:path'
|
|
3
|
-
import { pathToFileURL } from 'node:url'
|
|
4
3
|
import ora from 'ora'
|
|
5
4
|
import { connectProjectDatabase } from '../utils/database.js'
|
|
5
|
+
import { importProjectTypescript } from '../utils/import-typescript.js'
|
|
6
6
|
import { loadProjectEnv } from '../utils/load-dotenv.js'
|
|
7
7
|
import { logger } from '../utils/logger.js'
|
|
8
8
|
|
|
@@ -15,9 +15,7 @@ interface MigrateSchemaOptions {
|
|
|
15
15
|
async function loadProjectConfig(configPath: string): Promise<void> {
|
|
16
16
|
try {
|
|
17
17
|
const { setPrentaConfig } = await import('@prenta/core')
|
|
18
|
-
const
|
|
19
|
-
const abs = pathToFileURL(resolve(configPath)).href
|
|
20
|
-
const mod = (await tsImport(abs, import.meta.url)) as {
|
|
18
|
+
const mod = (await importProjectTypescript(resolve(configPath))) as {
|
|
21
19
|
default?: unknown
|
|
22
20
|
config?: unknown
|
|
23
21
|
}
|
package/src/commands/seed.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { readFile } from 'node:fs/promises'
|
|
|
3
3
|
import { existsSync } from 'node:fs'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import { createInterface } from 'node:readline/promises'
|
|
6
|
-
import { pathToFileURL } from 'node:url'
|
|
7
6
|
import ora from 'ora'
|
|
8
7
|
import { logger } from '../utils/logger.js'
|
|
9
8
|
import { connectProjectDatabase } from '../utils/database.js'
|
|
10
9
|
import { validateFormSeeds } from '../utils/form-seed.js'
|
|
10
|
+
import { importProjectTypescript, toProjectFileUrl } from '../utils/import-typescript.js'
|
|
11
11
|
|
|
12
12
|
async function confirm(question: string): Promise<boolean> {
|
|
13
13
|
const rl = createInterface({ input: process.stdin, output: process.stdout })
|
|
@@ -345,11 +345,10 @@ async function loadSeedFile(filePath: string): Promise<unknown> {
|
|
|
345
345
|
return JSON.parse(raw)
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
const fileUrl = pathToFileURL(path.resolve(filePath)).href
|
|
349
348
|
const mod =
|
|
350
349
|
extension === '.ts'
|
|
351
|
-
? await
|
|
352
|
-
: await import(
|
|
350
|
+
? await importProjectTypescript(filePath)
|
|
351
|
+
: await import(toProjectFileUrl(filePath))
|
|
353
352
|
|
|
354
353
|
return (mod as { default?: unknown; seed?: unknown }).default ?? (mod as { seed?: unknown }).seed
|
|
355
354
|
}
|