nestjs / nest-cli

CLI tool for Nest applications 🍹
https://nestjs.com
Other
1.97k stars 394 forks source link

[`nest start`] JSON Option Parsed and then Repassed #2242

Closed eabrouwer3 closed 1 year ago

eabrouwer3 commented 1 year ago

Is there an existing issue for this?

Current behavior

I'm using nest-commander, but this isn't an issue with them. There's two options to run the CLI command with the JSON argument, and when I build the project and then run it, I don't get any issues. When I run with nest start however, I get an error because there's something that happens during that command.

Option 1 (No Error)

nest build
node dist/main.js json-command --json '{"foo": "bar"}'

 > [
     '/Users/ebrouwer.dev/.local/share/nvm/v18.16.1/bin/node',
     '/Users/ebrouwer.dev/tmp/app/dist/main.js',
     'json-command',
     '--json',
     '{"foo": "bar"}'
   ]
   Processed successfully!
   { json: { foo: 'bar' } }

Option 2 (Error!)

nest start -- json-command --json '{"foo": "bar"}'

 > [
     '/Users/ebrouwer.dev/.local/share/nvm/v18.16.1/bin/node',
     '/Users/ebrouwer.dev/tmp/app/dist/main',
     'json-command',
     '--json',
     '{foo:',
     'bar}'
   ]
   SyntaxError: Unexpected token f in JSON at position 1

Basically, when using nest start to run the command, the JSON string '{"foo": "bar"}' is parsed, and then sent through without the string delimiters. I've tried a few different ways to get it to get passed through nicely, none of which have worked. They all yield the same exact error.

  1. '{"foo": "bar"}'
  2. "{\"foo\": \"bar\"}"
  3. {\"foo\":\ \"bar\"}

Minimum reproduction code

https://github.com/eabrouwer3/nest-json-option-repro

Steps to reproduce

No response

Expected behavior

Both ways of running the code should yield the same result.

Package version

10.1.11

NestJS version

10.1.3

Node.js version

v18.16.1

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 1 year ago

Would you like to create a PR for this issue?

eabrouwer3 commented 1 year ago

I can give it a go.

eabrouwer3 commented 1 year ago

Ok, I've put a code change in a PR (#2244). Would love some help to determine if it's a breaking change and what documentation or tests need to be updated.

kamilmysliwiec commented 1 year ago

Let's track this here https://github.com/nestjs/nest-cli/pull/2244