Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: cli args parsing fails #3481

Closed
3 tasks done
jasperbosch opened this issue Jul 20, 2022 · 3 comments
Closed
3 tasks done

bug: cli args parsing fails #3481

jasperbosch opened this issue Jul 20, 2022 · 3 comments
Assignees
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@jasperbosch
Copy link

jasperbosch commented Jul 20, 2022

Prerequisites

Stencil Version

2.17.x

Current Behavior

When executing stencil test --spec --e2e --json --outputFile=output.json the outputFile-argument is badly parsed. It will result in jest --spec --e2e --json --outputFile=output.json output.json, wich will result in not executing jest.

However executing stencil test --spec --e2e --json --output-file output.json will succeed.

Cause is in the parse-flags.ts file:

args.forEach((arg, i) => {
    if (arg.startsWith(`--${dashCaseName}=`) || arg.startsWith(`--${configCaseName}=`)) {
      value = getEqualsValue(arg);
      matchingArg = arg;
    } else if (arg === `--${dashCaseName}` || arg === `--${configCaseName}`) {
      value = args[i + 1];
      matchingArg = arg;
    } else if (alias) {
      if (arg.startsWith(`-${alias}=`)) {
        value = getEqualsValue(arg);
        matchingArg = arg;
      } else if (arg === `-${alias}`) {
        value = args[i + 1];
        matchingArg = arg;
      }
    }
  });

matchingArg (on line 4) should only contain --outputFile= but now contains --outputFile=output.json

Expected Behavior

Expect to execute jest with: jest --spec --e2e --json --outputFile=output.json

Steps to Reproduce

execute stencil test --spec --e2e --json --outputFile=output.json

Code Reproduction URL

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Jul 20, 2022
@alicewriteswrongs alicewriteswrongs added the Bug: Validated This PR or Issue is verified to be a bug within Stencil label Jul 20, 2022
@ionitron-bot ionitron-bot bot removed the triage label Jul 20, 2022
@alicewriteswrongs
Copy link
Contributor

hey @jasperbosch, thanks for filing this issue and for doing some code spelunking! You're right that this is an issue. I was just in this code recently so I'll fix it today.

alicewriteswrongs added a commit that referenced this issue Jul 20, 2022
This fixes a bug with how these flags were being parsed which was
messing with Jest. Basically, the issue related to how the `knownArgs`
array on the `ConfigFlags` object was being populated. For CLI key-value
args of the format `--argName=value` the whole string
`"--argName=value"` was being added _as well as_ the value string
`"value"`, which had the effect of passing duplicate args to Jest.

This refactors how such arguments are handled to always parse apart the
argument name and the value, adding only the argument name and then the
argument value, so that if you pass, for instance,
`--outputFile=output.json`, the args passed to Jest will look like

```ts
['--outputFile', 'output.json']
```

See #3471 and #3481 for more details
@alicewriteswrongs alicewriteswrongs self-assigned this Jul 20, 2022
alicewriteswrongs added a commit that referenced this issue Jul 20, 2022
This fixes a bug with how these flags were being parsed which was
messing with Jest. Basically, the issue related to how the `knownArgs`
array on the `ConfigFlags` object was being populated. For CLI key-value
args of the format `--argName=value` the whole string
`"--argName=value"` was being added _as well as_ the value string
`"value"`, which had the effect of passing duplicate args to Jest.

This refactors how such arguments are handled to always parse apart the
argument name and the value, adding only the argument name and then the
argument value, so that if you pass, for instance,
`--outputFile=output.json`, the args passed to Jest will look like

```ts
['--outputFile', 'output.json']
```

See #3471 and #3481 for more details
rwaskiewicz pushed a commit that referenced this issue Jul 20, 2022
This fixes a bug with how these flags were being parsed which was
messing with Jest. Basically, the issue related to how the `knownArgs`
array on the `ConfigFlags` object was being populated. For CLI key-value
args of the format `--argName=value` the whole string
`"--argName=value"` was being added _as well as_ the value string
`"value"`, which had the effect of passing duplicate args to Jest.

This refactors how such arguments are handled to always parse apart the
argument name and the value, adding only the argument name and then the
argument value, so that if you pass, for instance,
`--outputFile=output.json`, the args passed to Jest will look like

```ts
['--outputFile', 'output.json']
```

See #3471 and #3481 for more details
@alicewriteswrongs
Copy link
Contributor

Thanks for reporting this! Just to update you, there's a bugfix PR up here: #3483 which just merged into main.

If you want to test it out to make sure it fixes your issue you could

  • clone the repo locally
  • check out the branch
  • do npm install, npm run build and npm pack
  • try installing the resulting .tgz file in our project by doing npm install ./path/to/stencil.tgz

If you'd rather wait for a pre-release or release build to try that out no worries :)

@rwaskiewicz
Copy link
Contributor

The fix for this issue has been officially released as a part of Stencil v2.17.2. As a result, I'm going to close this issue and mark it as completed. If the bug re-appears, please feel free to open a new issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
Development

No branches or pull requests

3 participants