From 363fddffa66ba12cf2469c620421466da736bba7 Mon Sep 17 00:00:00 2001 From: "wenhua.shi" Date: Thu, 23 May 2024 09:58:30 +0800 Subject: [PATCH 1/2] feat: fix luciaPrisma merge --- packages/next-prisma/src/merge.ts | 15 ++++++++------- .../tests/__snapshots__/prisma-merge.spec.ts.snap | 8 ++++---- packages/next-prisma/tests/prisma-merge.spec.ts | 4 ++-- .../next-prisma/tests/prisma/testMerge1.prisma | 4 ++-- .../next-prisma/tests/prisma/testMerge2.prisma | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/next-prisma/src/merge.ts b/packages/next-prisma/src/merge.ts index 7e36964..071e0f8 100644 --- a/packages/next-prisma/src/merge.ts +++ b/packages/next-prisma/src/merge.ts @@ -31,7 +31,7 @@ const { getDMMF, getConfig } = getPrismaConfig; export interface prismaMergeOptions { input: string[]; output: string; - prePrismaModel?: string; + luciaPrismaModel?: string; } const readFile = promisify(fs.readFile); @@ -215,15 +215,10 @@ export async function prismaMerge(options: prismaMergeOptions) { const { input: inputs, output = 'prisma/schema.prisma', - prePrismaModel = '', + luciaPrismaModel = '', } = options; const schemasToMix: Schema[] = []; - if (prePrismaModel) { - const luciaSchema = await getSchema(prePrismaModel, 'luciaPrisma'); - if (luciaSchema) schemasToMix.push(luciaSchema); - } - // load the schema data for all inputs for (const input of inputs) { for (const file of glob.sync(input)) { @@ -236,6 +231,12 @@ export async function prismaMerge(options: prismaMergeOptions) { } } + // load the schema data for the lucia.prisma to cover all models + if (luciaPrismaModel) { + const luciaSchema = await getSchema(luciaPrismaModel, 'luciaPrisma'); + if (luciaSchema) schemasToMix.push(luciaSchema); + } + // extract all models and mix let models: Model[] = []; for (const schema of schemasToMix) { diff --git a/packages/next-prisma/tests/__snapshots__/prisma-merge.spec.ts.snap b/packages/next-prisma/tests/__snapshots__/prisma-merge.spec.ts.snap index c417037..b042637 100644 --- a/packages/next-prisma/tests/__snapshots__/prisma-merge.spec.ts.snap +++ b/packages/next-prisma/tests/__snapshots__/prisma-merge.spec.ts.snap @@ -3,10 +3,10 @@ exports[`merge prisma 1`] = ` "// *** GENERATED BY next-prisma :: DO NOT EDIT *** model User { - id Int @unique - name String + id String @unique content Int desc String + name String } model Post { id String @unique @@ -17,10 +17,10 @@ model Post { exports[`merge prisma cover 1`] = ` "// *** GENERATED BY next-prisma :: DO NOT EDIT *** model User { - id Int @unique - name Int + id String @unique content String desc String + name String } model Post { id String @unique diff --git a/packages/next-prisma/tests/prisma-merge.spec.ts b/packages/next-prisma/tests/prisma-merge.spec.ts index 51b1193..ca0e411 100644 --- a/packages/next-prisma/tests/prisma-merge.spec.ts +++ b/packages/next-prisma/tests/prisma-merge.spec.ts @@ -14,7 +14,7 @@ test('merge prisma', async () => { `; await prismaMerge({ - prePrismaModel: luciaPrismaContent, + luciaPrismaModel: luciaPrismaContent, input: ['tests/prisma/test1.prisma'], output: 'tests/prisma/testMerge1.prisma', }); @@ -34,7 +34,7 @@ test('merge prisma cover', async () => { `; await prismaMerge({ - prePrismaModel: luciaPrismaContent, + luciaPrismaModel: luciaPrismaContent, input: ['tests/prisma/test1.prisma', 'tests/prisma/test2.prisma'], output: 'tests/prisma/testMerge2.prisma', }); diff --git a/packages/next-prisma/tests/prisma/testMerge1.prisma b/packages/next-prisma/tests/prisma/testMerge1.prisma index 8a1354b..d8ce904 100644 --- a/packages/next-prisma/tests/prisma/testMerge1.prisma +++ b/packages/next-prisma/tests/prisma/testMerge1.prisma @@ -1,9 +1,9 @@ // *** GENERATED BY next-prisma :: DO NOT EDIT *** model User { - id Int @unique - name String + id String @unique content Int desc String + name String } model Post { id String @unique diff --git a/packages/next-prisma/tests/prisma/testMerge2.prisma b/packages/next-prisma/tests/prisma/testMerge2.prisma index 069d3c8..37e9e52 100644 --- a/packages/next-prisma/tests/prisma/testMerge2.prisma +++ b/packages/next-prisma/tests/prisma/testMerge2.prisma @@ -1,9 +1,9 @@ // *** GENERATED BY next-prisma :: DO NOT EDIT *** model User { - id Int @unique - name Int + id String @unique content String desc String + name String } model Post { id String @unique From f8fa41c723a350da1e4f93d43edcb991b6f19921 Mon Sep 17 00:00:00 2001 From: "wenhua.shi" Date: Thu, 23 May 2024 10:00:18 +0800 Subject: [PATCH 2/2] fix: del unuseful rollup-plugin --- packages/next-auth/flatjs-forge.config.ts | 4 ---- packages/next-auth/package.json | 1 - packages/next-demo/prisma-merge.js | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/next-auth/flatjs-forge.config.ts b/packages/next-auth/flatjs-forge.config.ts index 7dd3e96..cc25b00 100644 --- a/packages/next-auth/flatjs-forge.config.ts +++ b/packages/next-auth/flatjs-forge.config.ts @@ -1,5 +1,4 @@ import { defineConfig } from '@flatjs/forge'; -import preserveDirectives from 'rollup-plugin-preserve-directives'; export default defineConfig({ input: ['src/index.ts', 'src/providers/index.ts'], @@ -16,15 +15,12 @@ export default defineConfig({ dtsFilter: (dtsFile) => dtsFile.split('/').length <= 2 && /index.d.ts/.test(dtsFile), }, - externals: ['rollup-plugin-preserve-directives'], plugin: { pluginConfigs: { babelOptions: { usePreset: 'react', }, }, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - extraPlugins: [(preserveDirectives as any)()], }, output: { format: 'esm', diff --git a/packages/next-auth/package.json b/packages/next-auth/package.json index 4b2393c..8f0bc54 100644 --- a/packages/next-auth/package.json +++ b/packages/next-auth/package.json @@ -65,7 +65,6 @@ "prisma": "^5.13.0", "react": "^18.3.1", "rimraf": "5.0.5", - "rollup-plugin-preserve-directives": "0.4.0", "ts-node": "10.9.2", "typescript": "5.4.5", "vite": "5.2.11", diff --git a/packages/next-demo/prisma-merge.js b/packages/next-demo/prisma-merge.js index 029abb0..ebd957f 100644 --- a/packages/next-demo/prisma-merge.js +++ b/packages/next-demo/prisma-merge.js @@ -2,7 +2,7 @@ import { prismaMerge } from '@hyperse-io/next-prisma'; import { luciaPrismaContent } from '@hyperse-io/next-auth'; prismaMerge({ - prePrismaModel: luciaPrismaContent, + luciaPrismaModel: luciaPrismaContent, input: ['prisma/base.prisma'], }) .then(() => {