7nohe / laravel-typegen

The library lets you generate TypeScript types from your Laravel code
79 stars 5 forks source link

Windows incompatibility due to namespaced model in `model:show` #37

Closed vintagesucks closed 3 months ago

vintagesucks commented 4 months ago

https://github.com/7nohe/laravel-typegen/blob/ee03e079fe595bb8feb27e8c5da3732176600f7b/src/generate.ts#L64

Hi, when I tried this package I noticed that type generation failed on Windows, but worked on macOS.


php artisan model:show App\\Models\\User --json (current format)

◐ [Model] Running 'php artisan model:show App\\Models\\User --json'                                                                                                                                                          17:40:40  
PHP Fatal error:  Cannot declare class App\Models\User, because the name is already in use in app\Models\User.php on line 12
[17:40:42] ℹ [Model] Failed to get model data for User'. You still can generate types by running php artisan model:show App\\Models\\User --json manually and then run 'laravel-typegen' with SKIP_ARTISAN_COMMAND=true environment variable.

 ERROR  [Model] Command failed: php artisan model:show App\\Models\\User --json                                                                                                                                              17:40:42  
PHP Fatal error:  Cannot declare class App\Models\User, because the name is already in use in app\Models\User.php on line 12

php artisan model:show App/Models/User --json

7nohe commented 4 months ago

@vintagesucks Thank you for reporting the issue. I have fixed it in #38. Could you please specify the branch as below and check if the issue has been resolved?

package.json:

{
  "devDependencies": {
        "@7nohe/laravel-typegen": "github:7nohe/laravel-typegen#fix/namespaced-models-for-windows",
  }
}
vintagesucks commented 4 months ago

@7nohe Thank you for looking into this.

Yarn wouldn't let me specify the branch in that format without errors, but after I manually applied the changes from #38 to generate.js and utils.js via yarn patch, it worked on both Windows and macOS! 🚀