omar-dulaimi / prisma-trpc-generator

Prisma 2+ generator to emit fully implemented tRPC routers
MIT License
675 stars 34 forks source link

Wrong import path #32

Closed aske02 closed 2 years ago

aske02 commented 2 years ago

Bug description

It might just be my machine, but anyways. When running npx prisma generate I have the issue that the trpc-generator (with trpc-shield) makes an invalid include in routers/helpers/createRouter.ts. The line that is outputted will use \ as separators which I believe causes an issue where my import for example will look like: import { permissions } from "X:\Gamer 2\test-npm\prisma/shield/shield" when a path with \\ is expected.

How to reproduce

  1. Create a simple test project with a prisma client and trcp-shield
  2. Enable withShield in your prisma schema
  3. Run 'npx prisma generate'
  4. Check the file routers/helpers/createRouter.ts in your generated folder
  5. See that in the import it will have used single back slash instead of double back slash

Expected behavior

The import path should include the correct path to shield permissions

Prisma information

generator client {
    provider = "prisma-client-js"
}

generator trpc {
    provider = "prisma-trpc-generator"
    output   = "./trpc"
    withMiddleware = true
    withShield     = true
    contextPath    = "../../../../src/context"
}

datasource db {
    provider = "mysql"
    url      = env("DATABASE_URL")
}

model User {
    id        Int      @id @default(autoincrement())
    email     String   @unique(map: "email")
    password  String
    name      String
    rank      Rank
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}

enum Rank {
    Admin
    Moderator
    User
}

Environment & setup

Prisma Version

Environment variables loaded from .env
prisma                  : 4.3.1
@prisma/client          : 4.3.1
Current platform        : windows
Query Engine (Node-API) : libquery-engine c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Format Wasm             : @prisma/prisma-fmt-wasm 4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b
Default Engines Hash    : c875e43600dfe042452e0b868f7a48b817b9640b
Studio                  : 0.473.0
websaid commented 2 years ago

Push! Face same issue. Shouldn't be to hard to fix.

omar-dulaimi commented 2 years ago

@aske02 @Westsaid Should be fixed in https://github.com/omar-dulaimi/prisma-trpc-generator/releases/tag/0.4.4

Also, feel free to star this project if you find it useful!