nest-cli icon indicating copy to clipboard operation
nest-cli copied to clipboard

Nest CLI doesn't work as a devDependency

Open lvalencia opened this issue 8 years ago • 5 comments

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
```
                                    

lvalencia avatar May 30 '18 01:05 lvalencia

Hey @lvalencia ! Thanks for the issue ! Thinking it's a major feature ;-)

thomrick avatar May 30 '18 07:05 thomrick

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

JemiloII avatar Aug 07 '18 15:08 JemiloII

Anything in progress about this issue?

alber70g avatar Aug 20 '18 14:08 alber70g

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 !

thomrick avatar Aug 20 '18 15:08 thomrick

@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.

josiahdahl avatar Oct 27 '18 06:10 josiahdahl