prisma-json-types-generator
Advanced tools
Comparing version
@@ -23,20 +23,12 @@ "use strict"; | ||
if (isNewClient) { | ||
try { | ||
const modelsFolder = (0, node_path_1.join)(prismaClient.output.value, 'models'); | ||
const stat = await promises_1.default.stat(modelsFolder); | ||
if (stat.isDirectory()) { | ||
// Models are split into multiple files starting in prisma@6.7 | ||
for (const modelFile of await promises_1.default.readdir(modelsFolder)) { | ||
await handleDeclarationFile((0, node_path_1.join)(modelsFolder, modelFile), config, options, true); | ||
} | ||
await promises_1.default.writeFile((0, node_path_1.join)(prismaClient.output.value, 'pjtg.ts'), `${constants_1.LIB_HEADER}\n${await (0, declaration_writer_1.getNamespacePrelude)(config.namespace)}`); | ||
return; | ||
const modelsFolder = (0, node_path_1.join)(prismaClient.output.value, 'models'); | ||
const stat = await promises_1.default.stat(modelsFolder).catch(() => null); | ||
// Models are split into multiple files starting in prisma@6.7 | ||
if (stat?.isDirectory()) { | ||
for (const modelFile of await promises_1.default.readdir(modelsFolder)) { | ||
await handleDeclarationFile((0, node_path_1.join)(modelsFolder, modelFile), config, options, prismaClient.config.importFileExtension?.toString(), true); | ||
} | ||
await promises_1.default.writeFile((0, node_path_1.join)(prismaClient.output.value, 'pjtg.ts'), `${constants_1.LIB_HEADER}\n${await (0, declaration_writer_1.getNamespacePrelude)(config.namespace)}`); | ||
return; | ||
} | ||
catch (e) { | ||
// Ignore ENOENT since that likely means the `models` folder could not be found, indicating a <= v6.6 file structure | ||
if (!('code' in e) || e.code !== 'ENOENT') { | ||
console.error(e); | ||
} | ||
} | ||
} | ||
@@ -46,3 +38,3 @@ const clientOutput = isNewClient | ||
: (0, source_path_1.buildTypesFilePath)(prismaClient.output.value, config.clientOutput, options.schemaPath); | ||
await handleDeclarationFile(clientOutput, config, options); | ||
await handleDeclarationFile(clientOutput, config, options, prismaClient.config.importFileExtension?.toString(), false); | ||
} | ||
@@ -53,4 +45,4 @@ catch (error) { | ||
} | ||
async function handleDeclarationFile(filepath, config, options, multifile = false) { | ||
const writer = new declaration_writer_1.DeclarationWriter(filepath, config, multifile); | ||
async function handleDeclarationFile(filepath, config, options, importFileExtension, multifile) { | ||
const writer = new declaration_writer_1.DeclarationWriter(filepath, config, multifile, importFileExtension); | ||
// Reads the prisma declaration file content. | ||
@@ -57,0 +49,0 @@ await writer.load(); |
@@ -14,6 +14,7 @@ "use strict"; | ||
class DeclarationWriter { | ||
constructor(filepath, options, multifile = false) { | ||
constructor(filepath, options, multifile, importFileExtension) { | ||
this.filepath = filepath; | ||
this.options = options; | ||
this.multifile = multifile; | ||
this.importFileExtension = importFileExtension; | ||
/** The prisma's index.d.ts file content. */ | ||
@@ -25,3 +26,4 @@ this.content = ''; | ||
if (this.multifile) { | ||
return `${constants_1.MODIFIED_HEADER}\nimport type * as PJTG from '../pjtg';\n${this.content}`; | ||
const ext = this.importFileExtension ? `.${this.importFileExtension}` : ''; | ||
return `${constants_1.MODIFIED_HEADER}\nimport type * as PJTG from '../pjtg${ext}';\n${this.content}`; | ||
} | ||
@@ -28,0 +30,0 @@ return `${constants_1.MODIFIED_HEADER}\n${await getNamespacePrelude(this.options.namespace)}\n${this.content}`; |
{ | ||
"name": "prisma-json-types-generator", | ||
"version": "3.4.0", | ||
"version": "3.4.1", | ||
"description": "Changes JsonValues to your custom typescript type", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
77143
0.09%1043
-0.57%