Skip to content

Commit

Permalink
Merge pull request #10 from simplyStyle/main
Browse files Browse the repository at this point in the history
fix luciaPrisma merge
  • Loading branch information
tianyingchun authored May 23, 2024
2 parents 902701f + f8fa41c commit e392533
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 23 deletions.
4 changes: 0 additions & 4 deletions packages/next-auth/flatjs-forge.config.ts
Original file line number Diff line number Diff line change
@@ -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'],
Expand All @@ -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',
Expand Down
1 change: 0 additions & 1 deletion packages/next-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-demo/prisma-merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
15 changes: 8 additions & 7 deletions packages/next-prisma/src/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const { getDMMF, getConfig } = getPrismaConfig;
export interface prismaMergeOptions {
input: string[];
output: string;
prePrismaModel?: string;
luciaPrismaModel?: string;
}

const readFile = promisify(fs.readFile);
Expand Down Expand Up @@ -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)) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/next-prisma/tests/prisma-merge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('merge prisma', async () => {
`;

await prismaMerge({
prePrismaModel: luciaPrismaContent,
luciaPrismaModel: luciaPrismaContent,
input: ['tests/prisma/test1.prisma'],
output: 'tests/prisma/testMerge1.prisma',
});
Expand All @@ -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',
});
Expand Down
4 changes: 2 additions & 2 deletions packages/next-prisma/tests/prisma/testMerge1.prisma
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/next-prisma/tests/prisma/testMerge2.prisma
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e392533

Please sign in to comment.