Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions packages/schema/src/plugins/enhancer/enhance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,19 @@ export class EnhancerGenerator {
}

// `models.ts` for exporting model types
const modelsTsContent = [
`export * from '${resultPrismaBaseImport}/models';`,
`export * from './json-types';`,
].join('\n');
const modelsTs = this.project.createSourceFile(path.join(this.outDir, 'models.ts'), modelsTsContent, {
overwrite: true,
});

const modelsTsContent = [`export * from '${resultPrismaBaseImport}/models';`];
if (this.model.declarations.some((d) => isTypeDef(d))) {
modelsTsContent.push(`export * from './json-types';`);
}

const modelsTs = this.project.createSourceFile(
path.join(this.outDir, 'models.ts'),
modelsTsContent.join('\n'),
{
overwrite: true,
}
);
this.saveSourceFile(modelsTs);

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

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

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

// Create a shared file for all JSON fields type definitions
const jsonFieldsFile = project.createSourceFile(path.join(this.outDir, 'json-types.ts'), undefined, {
overwrite: true,
});

this.generateExtraTypes(jsonFieldsFile);
await saveSourceFile(jsonFieldsFile);
if (this.model.declarations.some(isTypeDef)) {
const jsonFieldsFile = project.createSourceFile(path.join(this.outDir, 'json-types.ts'), undefined, {
overwrite: true,
});
this.generateExtraTypes(jsonFieldsFile);
await saveSourceFile(jsonFieldsFile);
}

for (const d of this.model.declarations.filter(isDataModel)) {
const fileName = `${prismaClientDir}/models/${d.name}.ts`;
Expand Down
4 changes: 3 additions & 1 deletion packages/schema/src/plugins/enhancer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
PluginError,
RUNTIME_PACKAGE,
createProject,
getPrismaClientGenerator,
normalizedRelative,
resolvePath,
type PluginFunction,
Expand Down Expand Up @@ -35,7 +36,8 @@ const run: PluginFunction = async (model, options, _dmmf, globalOptions) => {
// handle custom output path

// get the absolute path of the prisma client types
const prismaClientPathAbs = path.resolve(outDir, 'models');
const prismaGenerator = getPrismaClientGenerator(model);
const prismaClientPathAbs = path.resolve(outDir, prismaGenerator?.isNewGenerator ? 'client' : 'models');

// resolve it relative to the schema path
prismaClientPath = normalizedRelative(path.dirname(options.schemaPath), prismaClientPathAbs);
Expand Down
6 changes: 0 additions & 6 deletions packages/sdk/src/code-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function saveSourceFile(sourceFile: SourceFile) {
******************************************************************************/

/* eslint-disable */
// @ts-nocheck

${sourceFile.getText()}`
);
Expand All @@ -49,11 +48,6 @@ export async function saveProject(project: Project) {
* Emit a TS project to JS files.
*/
export async function emitProject(project: Project) {
// ignore type checking for all source files
for (const sf of project.getSourceFiles()) {
sf.insertStatements(0, '// @ts-nocheck');
}

const errors = project.getPreEmitDiagnostics().filter((d) => d.getCategory() === DiagnosticCategory.Error);
if (errors.length > 0) {
console.error('Error compiling generated code:');
Expand Down
Loading