Julien-R44 / tuyau

RPC / E2E Client For AdonisJS
https://tuyau.julr.dev
MIT License
54 stars 0 forks source link

nudging tuyau to the location of controllers #8

Open Fawwaz-2009 opened 3 hours ago

Fawwaz-2009 commented 3 hours ago

I'm using module base folder structure and it's seems tuyau can't find the controllers, is there is a way to nudge tuyau on where to look for the controllers?

image

Julien-R44 commented 3 hours ago

How do you define your routes? In what files + via what kind of import?

If possible a reproduction would be super helpful

Fawwaz-2009 commented 2 hours ago

hey Julien thanks for the quick reply and sure thing will create a reproduction soon

Fawwaz-2009 commented 2 hours ago

Hey Julien 👋 please find the reproduction below, also many thanks for you and the team for making this, I'm new to adonisjs and I like a lot about it but the type safety to inertia has been a big annoyance, so many thanks again 🙏

https://github.com/Fawwaz-2009/tuyau-adonisjs-reproduction

image

Julien-R44 commented 2 hours ago

Thank you very much for reproducing the issue I don't have a clean solution in the short term, but I can offer you a workaround.

Here's the problem: try running node ace list:routes --json on your reproduction. You'll get the following output:

[
  // ....
  {
    "name": "",
    "pattern": "/some-thing",
    "methods": [
      "GET"
    ],
    "handler": {
      "type": "controller",
      "moduleNameOrPath": "../controllers/index.js",
      "method": "index"
    },
    "middleware": []
  }
]

As you can see, the path to the controller is relative from the file where you defined your route, meaning: app/someModule/routes/index.ts. And from Tuyau, I don't have that information. Therefore, I'm unable to determine where your controller is located.

I hope that makes sense. There might potentially be a patch that can be applied to @adonisjs/http-server to fix this, but I need to discuss it with the team first.

Now, the workaround I can suggest is to use subpath imports to register your routes:

import router from '@adonisjs/core/services/router'
const SomeController = () => import('#my-module/controllers/someControllers')

function someModuleRoutes() {
  router.get('/some-thing', [SomeController, 'index'])
}

export default someModuleRoutes

Of course, don't forget to register this subpath import in your package.json. And it will work!