Nest CLI doesn't work as a devDependency
I'm submitting a...
[ ] Regression
[x] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
if you try running Nest CLI generate as a local install (either with npx or manually) you get an error because the location of schematics is incorrect
$ ./node_modules/.bin/nest generate controller mycontroller
/bin/sh:/PROJECT_PATH/node_modules/@nestjs/cli/node_modules/.bin/schematics: No such file or directory
🙀 Failed to execute command: /PROJECT_PATH/node_modules/@nestjs/cli/node_modules/.bin/schematics @nestjs/schematics:pipe --name=game --dry-run=false
Expected behavior
when installed locally it should try to run the command from
/PROJECT_PATH/node_modules/.bin/schematics
or it should include schematics as a dependency
Minimal reproduction of the problem with instructions
install nest-cli as a project devDependency, run
npx nest generate controller mycontroller
or
./node_modules/.bin/nest generate controller mycontroller
What is the motivation / use case for changing the behavior?
If I want to pin the version of the nest/cli used for a particular project to a particular version, I should be able to do that in the package.json since that's how manage devDependencies, and this is a devDependency.
Environment
```
[System Information]
OS Version : macOS Sierra
NodeJS Version : v9.11.1
NPM Version : 6.1.0
[Nest Information]
microservices version : 5.0.0
websockets version : 5.0.0
swagger version : 2.0.0
testing version : 5.0.0
common version : 5.0.0
core version : 5.0.0
```
Hey @lvalencia ! Thanks for the issue ! Thinking it's a major feature ;-)
Any updates on this? I'd like to use this locally too. I don't like having globally installed packages since I use nvm and bounce around node versions and updating the versions to their respective latest often.
Is how I use nest locally. However one could just do $(npm bin)/nest as well~
# npm local executables
PATH=$PATH:node_modules/.bin
Anything in progress about this issue?
Hey guys ! Sorry for the delay ! Missing time to develop on the project right now. If someone can PR on this it would be awesome !
@lvalencia @ThomRick I've got a PR on the way to fix this.
Currently, the SchematicRunner class expects the schematics file to be two levels up from the file directory then at node_modules/.bin/schematics. When it's installed as a dev dependency it's actually up three levels and down into node_modules.
https://github.com/nestjs/nest-cli/blob/5a8920a129db56bb2028ab2d7d2d0c04189751a0/lib/runners/schematic.runner.ts#L6
When a package is installed globally, there is node_modules is inside of the package directory, i.e.
@ nestjs/
- cli/
- node_modules/
- .bin/
- schematics
- lib/
When it is installed locally, the package is inside node_modules and therefore up one more level.
@ nestjs/
- cli/
- lib/
.bin/
- schematics
My proposed solution is to walk up the file tree until there exists a node_modules directory then use .bin/schematics. I'm not sure if there's a better way to determine if it's being called from local node_modules or global. If you get a chance, let me know if that makes sense and is the best way to resolve it. I'll be able to finish implementing it on Sunday.