Gateway: output is generated in wrong directory
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Current behavior
Motivation
My goal is to generate a gateway for specific entity / feature, e.g. users
. All features lie within a features
directory. So when generating NestJS elements for these features, I usually call something like this:
nest g controller features/users
or
nest g service features/users
For most cases this will generate the files in the features/users
directory,
so the path of the controller would be features/users/users.controller.ts
and the path of the service features/users/users.service.ts
Both will be correctly registered in the existing UsersModule
(features/users/users.module.ts
)
Issue
For gateways however, this command
nest g gateway features/users
will place the gateway at features/users.gateway.ts
and register it in the AppModule
instead.
Workaround
To generate the gateway in the correct directory, you’d have to run
nest g gateway features/users/users
This different behavior from all other schematics makes it hard predict the outcome when using the cli and reduces the trust in how the CLI will modify the project. This can be irritating for new NestJS developers and such a special case is hard to remember, even for experienced devs.
Console Output
Here’s the console output from running the different schematics
Minimum reproduction code
https://github.com/homj/nestjs-gateway-schematic-directory-bug
Steps to reproduce
- create a new nest application
- create the users module:
nest g module features/users
- create the users module:
nest g controller features/users
- create the users module:
nest g service features/users
- create the users gateway
nest g gateway features/users
- the gateway will be placed in the wrong directory and registered in the
AppModule
instead of theUsersModule
:
Expected behavior
The gateway schematic should behave like all other schematics and output the gateway at the specified path.
Package version
8.0.7
NestJS version
8.3.1
Node.js version
14.15.3
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
This is intentional. We should allow setting it to false though (explicitly through flag or config)
@micalevisk I’ve made a PR in the nest-cli repo: https://github.com/nestjs/nest-cli/pull/1561 Feedback is appreciated 😃