Skip to content

Commit 92760f3

Browse files
committed
fix: several compilation issues with the new "prisma-client" generator
fixes #2243
1 parent 75f5482 commit 92760f3

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

packages/schema/src/plugins/enhancer/enhance/index.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,19 @@ export class EnhancerGenerator {
129129
}
130130

131131
// `models.ts` for exporting model types
132-
const modelsTsContent = [
133-
`export * from '${resultPrismaBaseImport}/models';`,
134-
`export * from './json-types';`,
135-
].join('\n');
136-
const modelsTs = this.project.createSourceFile(path.join(this.outDir, 'models.ts'), modelsTsContent, {
137-
overwrite: true,
138-
});
132+
133+
const modelsTsContent = [`export * from '${resultPrismaBaseImport}/models';`];
134+
if (this.model.declarations.some((d) => isTypeDef(d))) {
135+
modelsTsContent.push(`export * from './json-types';`);
136+
}
137+
138+
const modelsTs = this.project.createSourceFile(
139+
path.join(this.outDir, 'models.ts'),
140+
modelsTsContent.join('\n'),
141+
{
142+
overwrite: true,
143+
}
144+
);
139145
this.saveSourceFile(modelsTs);
140146

141147
// `enums.ts` for exporting enums
@@ -159,7 +165,8 @@ export class EnhancerGenerator {
159165
this.saveSourceFile(clientTs);
160166

161167
// `enhance.ts` and `enhance-edge.ts`
162-
for (const target of ['node', 'edge'] as const) {
168+
const targets = this.isNewPrismaClientGenerator ? (['node'] as const) : (['node', 'edge'] as const);
169+
for (const target of targets) {
163170
this.generateEnhance(prismaImport, `${resultPrismaBaseImport}/client`, needsLogicalClient, target);
164171
}
165172

@@ -596,12 +603,13 @@ export type Enhanced<Client> =
596603
fs.renameSync(internalFilenameFixed, internalFilename);
597604

598605
// Create a shared file for all JSON fields type definitions
599-
const jsonFieldsFile = project.createSourceFile(path.join(this.outDir, 'json-types.ts'), undefined, {
600-
overwrite: true,
601-
});
602-
603-
this.generateExtraTypes(jsonFieldsFile);
604-
await saveSourceFile(jsonFieldsFile);
606+
if (this.model.declarations.some(isTypeDef)) {
607+
const jsonFieldsFile = project.createSourceFile(path.join(this.outDir, 'json-types.ts'), undefined, {
608+
overwrite: true,
609+
});
610+
this.generateExtraTypes(jsonFieldsFile);
611+
await saveSourceFile(jsonFieldsFile);
612+
}
605613

606614
for (const d of this.model.declarations.filter(isDataModel)) {
607615
const fileName = `${prismaClientDir}/models/${d.name}.ts`;

packages/schema/src/plugins/enhancer/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
PluginError,
33
RUNTIME_PACKAGE,
44
createProject,
5+
getPrismaClientGenerator,
56
normalizedRelative,
67
resolvePath,
78
type PluginFunction,
@@ -35,7 +36,8 @@ const run: PluginFunction = async (model, options, _dmmf, globalOptions) => {
3536
// handle custom output path
3637

3738
// get the absolute path of the prisma client types
38-
const prismaClientPathAbs = path.resolve(outDir, 'models');
39+
const prismaGenerator = getPrismaClientGenerator(model);
40+
const prismaClientPathAbs = path.resolve(outDir, prismaGenerator?.isNewGenerator ? 'client' : 'models');
3941

4042
// resolve it relative to the schema path
4143
prismaClientPath = normalizedRelative(path.dirname(options.schemaPath), prismaClientPathAbs);

packages/sdk/src/code-gen.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export function saveSourceFile(sourceFile: SourceFile) {
2929
******************************************************************************/
3030
3131
/* eslint-disable */
32-
// @ts-nocheck
3332
3433
${sourceFile.getText()}`
3534
);
@@ -49,11 +48,6 @@ export async function saveProject(project: Project) {
4948
* Emit a TS project to JS files.
5049
*/
5150
export async function emitProject(project: Project) {
52-
// ignore type checking for all source files
53-
for (const sf of project.getSourceFiles()) {
54-
sf.insertStatements(0, '// @ts-nocheck');
55-
}
56-
5751
const errors = project.getPreEmitDiagnostics().filter((d) => d.getCategory() === DiagnosticCategory.Error);
5852
if (errors.length > 0) {
5953
console.error('Error compiling generated code:');

0 commit comments

Comments
 (0)