Repository: Quramy/prisma-fabbrica (ts)

Issue:
Import paths in generated code without transpilation are different across Windows and Linux
When the setting `noTransplie` is set to `true`, part of the import path is escaped `\\` on Windows vs on Linux which uses `/`.

Example:

`Windows`
```javascript
import type { User } from "./..\\..\\prisma-client\\dist\\client";
```
`Linux`
```javascript
import type { User } from "./../../prisma-client/dist/client";
```

This results in issues with version control when the code is complied across operating systems.

Pull request:
fix: prismaClientModuleSpecifier for win32
It fixes #168 

Patch:
diff --git a/packages/prisma-fabbrica/src/generator.ts b/packages/prisma-fabbrica/src/generator.ts
index 1cceda9..9dffce8 100644
--- a/packages/prisma-fabbrica/src/generator.ts
+++ b/packages/prisma-fabbrica/src/generator.ts
@@ -9,6 +9,7 @@ import { logger } from "@prisma/internals";
 
 import { getSourceFile } from "./templates";
 import { createPrinter } from "./templates/ast-tools/printer";
+import { getClientModuleSpecifier } from "./getClientModuleSpecifier";
 
 function readTsConfig(tsconfigPath: string) {
   const opt: ts.CompilerOptions = {
@@ -55,11 +56,7 @@ generatorHandler({
       return;
     }
 
-    const prismaClientModuleSpecifier = clientGeneratorOutputPath.endsWith(
-      ["node_modules", "@prisma", "client"].join(path.sep),
-    )
-      ? "@prisma/client"
-      : "./" + path.relative(outputDirname, clientGeneratorOutputPath).replace("\\", "/");
+    const prismaClientModuleSpecifier = getClientModuleSpecifier(clientGeneratorOutputPath, outputDirname);
 
     const printer = createPrinter();
     const contents = printer.print(getSourceFile({ document: options.dmmf, prismaClientModuleSpecifier }));
diff --git a/packages/prisma-fabbrica/src/getClientModuleSpecifier.ts b/packages/prisma-fabbrica/src/getClientModuleSpecifier.ts
new file mode 100644
index 0000000..c52dc0c
--- /dev/null
+++ b/packages/prisma-fabbrica/src/getClientModuleSpecifier.ts
@@ -0,0 +1,18 @@
+import _path from "node:path";
+
+const path = _path.posix;
+
+export function getClientModuleSpecifier(clientGeneratorOutputPath: string | undefined, outputDirname: string) {
+  if (!clientGeneratorOutputPath) {
+    return "@prisma/client";
+  }
+  const clientGeneratorOutputPosixPath = clientGeneratorOutputPath.replace(/\\/g, path.sep);
+  const outputPosixDirname = outputDirname.replace(/\\/g, path.sep);
+
+  const prismaClientModuleSpecifier = path
+    .normalize(clientGeneratorOutputPosixPath)
+    .endsWith(["node_modules", "@prisma", "client"].join(path.sep))
+    ? "@prisma/client"
+    : path.normalize("./" + path.relative(outputPosixDirname, clientGeneratorOutputPosixPath));
+  return prismaClientModuleSpecifier;
+}


Test patch:
diff --git a/packages/prisma-fabbrica/src/getClientModuleSpecifier.test.ts b/packages/prisma-fabbrica/src/getClientModuleSpecifier.test.ts
new file mode 100644
index 0000000..290a57c
--- /dev/null
+++ b/packages/prisma-fabbrica/src/getClientModuleSpecifier.test.ts
@@ -0,0 +1,19 @@
+import { getClientModuleSpecifier } from "./getClientModuleSpecifier";
+
+describe(getClientModuleSpecifier, () => {
+  test.each([
+    { outputDirname: "dist", clientGeneratorOutputPath: undefined, expected: "@prisma/client" },
+    { outputDirname: "dist", clientGeneratorOutputPath: "node_modules/@prisma/client", expected: "@prisma/client" },
+    { outputDirname: "dist", clientGeneratorOutputPath: "node_modules\\@prisma\\client", expected: "@prisma/client" },
+    { outputDirname: "dist", clientGeneratorOutputPath: "prisma-client", expected: "../prisma-client" },
+    { outputDirname: "dist", clientGeneratorOutputPath: "../prisma-client", expected: "../../prisma-client" },
+    { outputDirname: "./dist", clientGeneratorOutputPath: "../prisma-client", expected: "../../prisma-client" },
+    { outputDirname: ".\\dist", clientGeneratorOutputPath: "..\\prisma-client", expected: "../../prisma-client" },
+    { outputDirname: "dist", clientGeneratorOutputPath: "..\\..\\prisma-client", expected: "../../../prisma-client" },
+  ])(
+    "outputDirname: $outputDirname, clientGeneratorOutputPath: $clientGeneratorOutputPath, expected: $expected",
+    ({ outputDirname, clientGeneratorOutputPath, expected }) => {
+      expect(getClientModuleSpecifier(clientGeneratorOutputPath, outputDirname)).toBe(expected);
+    },
+  );
+});