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

fix(cli): fix a bug in CLI argument parsing #5646

Merged
merged 1 commit into from Apr 12, 2024

Conversation

alicewriteswrongs
Copy link
Member

This fixes a bug related to parsing of Boolean CLI arguments using the --argName=value type syntax.
We intend to support using that syntax to pass a boolean CLI flag (like --watch) but actually at present the way it is 'parsed' will result in such flags always being set to true! Not good!

This is because we were setting the value of the boolean CLI flag to Boolean('false') if you pass --argName=false, which does not result in a value of false but instead a value of true. This is changed to instead use a check that the value equals 'true' to turn the value into a boolean, and regression tests are added.

This was noticed when investigating #5640, but that bug actually has to do with how we convert CLI arguments into a Jest configuration.

What is the current behavior?

If you pass a boolean CLI flag with the =value syntax it will always be set to true.

One sort of amusing way to reproduce this is to do:

npx stencil build --watch=false

which, contrary to expectations, starts the compiler in watch mode.

What is the new behavior?

now if you do something like --watch=false we correctly parse the actual value after the equals sign for a boolean CLI flag.

Does this introduce a breaking change?

  • Yes
  • No

Testing

Here's how you can test this:

  1. create a test project
  2. try doing npx stencil build --watch=false and note that the compiler is started in watch mode
  3. build, pack, and then install this branch in your test project
  4. note how the same command now does not start the compiler in watch mode

This fixes a bug related to parsing of Boolean CLI arguments using
the `--argName=value` type syntax.
We intend to support using that syntax to pass a boolean CLI flag (like
`--watch`) but actually at present the way it is 'parsed' will result in
such flags always being set to true! Not good!

This is because we were setting the value of the boolean CLI flag to
`Boolean('false')` if you pass `--argName=false`, which does _not_
result in a value of `false` but instead a value of `true`. This is
changed to instead use a check that the value equals `'true'` to turn
the value into a boolean, and regression tests are added.

This was noticed when investigating #5640, but that bug actually has to
do with how we convert CLI arguments into a Jest configuration.
Copy link
Contributor

--strictNullChecks error report

Typechecking with --strictNullChecks resulted in 1137 errors on this branch.

That's the same number of errors on main, so at least we're not creating new ones!

reports and statistics

Our most error-prone files
Path Error Count
src/dev-server/index.ts 37
src/dev-server/server-process.ts 32
src/compiler/prerender/prerender-main.ts 22
src/runtime/client-hydrate.ts 20
src/testing/puppeteer/puppeteer-element.ts 20
src/screenshot/connector-base.ts 19
src/runtime/vdom/vdom-render.ts 17
src/dev-server/request-handler.ts 15
src/compiler/prerender/prerender-optimize.ts 14
src/compiler/sys/stencil-sys.ts 14
src/sys/node/node-sys.ts 14
src/compiler/prerender/prerender-queue.ts 13
src/compiler/sys/in-memory-fs.ts 13
src/runtime/connected-callback.ts 13
src/runtime/set-value.ts 13
src/compiler/output-targets/output-www.ts 12
src/compiler/transformers/test/parse-vdom.spec.ts 12
src/compiler/transformers/transform-utils.ts 12
src/compiler/transpile/transpile-module.ts 12
src/mock-doc/test/attribute.spec.ts 12
Our most common errors
Typescript Error Code Count
TS2322 361
TS2345 344
TS18048 204
TS18047 82
TS2722 37
TS2532 24
TS2531 21
TS2454 14
TS2790 11
TS2352 9
TS2769 8
TS2538 8
TS2416 7
TS2493 3
TS18046 2
TS2684 1
TS2430 1

Unused exports report

There are 14 unused exports on this PR. That's the same number of errors on main, so at least we're not creating new ones!

Unused exports
File Line Identifier
src/runtime/bootstrap-lazy.ts 21 setNonce
src/screenshot/screenshot-fs.ts 18 readScreenshotData
src/testing/testing-utils.ts 198 withSilentWarn
src/utils/index.ts 145 CUSTOM
src/utils/index.ts 269 normalize
src/utils/index.ts 7 escapeRegExpSpecialCharacters
src/compiler/app-core/app-data.ts 25 BUILD
src/compiler/app-core/app-data.ts 115 Env
src/compiler/app-core/app-data.ts 117 NAMESPACE
src/compiler/fs-watch/fs-watch-rebuild.ts 123 updateCacheFromRebuild
src/compiler/types/validate-primary-package-output-target.ts 61 satisfies
src/compiler/types/validate-primary-package-output-target.ts 61 Record
src/testing/puppeteer/puppeteer-declarations.ts 485 WaitForEventOptions
src/compiler/sys/fetch/write-fetch-success.ts 7 writeFetchSuccessSync

Copy link
Contributor

PR built and packed!

Download the tarball here: https://github.com/ionic-team/stencil/actions/runs/8633485215/artifacts/1401904123

If your browser saves files to ~/Downloads you can install it like so:

unzip -d ~/Downloads ~/Downloads/stencil-core-4.15.0-dev.1712761417.c55abef.tgz.zip && npm install ~/Downloads/stencil-core-4.15.0-dev.1712761417.c55abef.tgz

@alicewriteswrongs alicewriteswrongs marked this pull request as ready for review April 10, 2024 15:10
@alicewriteswrongs alicewriteswrongs requested a review from a team as a code owner April 10, 2024 15:10
@alicewriteswrongs alicewriteswrongs added this pull request to the merge queue Apr 12, 2024
Merged via the queue into main with commit 1fdea63 Apr 12, 2024
121 checks passed
@alicewriteswrongs alicewriteswrongs deleted the ap/boolean-equals-arg-parse branch April 12, 2024 16:50
alicewriteswrongs added a commit that referenced this pull request Apr 15, 2024
This adds some manual string -> boolean type coercion to the code that
we use to convert CLI flags to a Jest config (after parsing them with
yargs).

This fixes an issue documented in #5640 where boolean CLI flags like
`--watchAll` were being passed to Jest as strings, instead of as
booleans, so that it was not possible to _disable_ a flag by doing
`--flagName=false` (the value of the flag would be set to the string
`"false"` which is a truthy value).

There was also a somewhat related issue with not properly parsing
boolean flags in our CLI parser which was recently fixed in #5646.

fixes #5640
STENCIL-1259
alicewriteswrongs added a commit that referenced this pull request Apr 15, 2024
This adds some manual string -> boolean type coercion to the code that
we use to convert CLI flags to a Jest config (after parsing them with
yargs).

This fixes an issue documented in #5640 where boolean CLI flags like
`--watchAll` were being passed to Jest as strings, instead of as
booleans, so that it was not possible to _disable_ a flag by doing
`--flagName=false` (the value of the flag would be set to the string
`"false"` which is a truthy value).

There was also a somewhat related issue with not properly parsing
boolean flags in our CLI parser which was recently fixed in #5646.

fixes #5640
STENCIL-1259
jcfranco added a commit to Esri/calcite-design-system that referenced this pull request Apr 16, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@stencil/core](https://stenciljs.com/)
([source](https://togithub.com/ionic-team/stencil)) | [`4.13.0` ->
`4.15.0`](https://renovatebot.com/diffs/npm/@stencil%2fcore/4.13.0/4.15.0)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@stencil%2fcore/4.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@stencil%2fcore/4.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@stencil%2fcore/4.13.0/4.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@stencil%2fcore/4.13.0/4.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>ionic-team/stencil (@&#8203;stencil/core)</summary>

### 

[`v4.16.0`](https://togithub.com/ionic-team/stencil/blob/HEAD/CHANGELOG.md#-4150-2024-04-08)

[Compare 
Source](ionic-team/stencil@v4.15.0...v4.16.0)

##### Bug Fixes

* **cli:** fix a bug in CLI argument parsing
([#5646](ionic-team/stencil#5646))
([1fdea63](ionic-team/stencil@1fdea63)),
refs [#5640](ionic-team/stencil#5640)
* **testing:** prevent `find` from throwing error when query has no
match ([#5641](ionic-team/stencil#5641))
([b3886aa](ionic-team/stencil@b3886aa)),
closes [#5639](ionic-team/stencil#5639)

##### Features

* **dev-server:** dark mode support
([#5642](ionic-team/stencil#5642))
([89a5e40](ionic-team/stencil@89a5e40))
* **typescript:** Update dependency typescript to v5.4.5
([#5663](ionic-team/stencil#5663))
([2596536](ionic-team/stencil@2596536))

###

[`v4.15.0`](https://togithub.com/ionic-team/stencil/blob/HEAD/CHANGELOG.md#-4150-2024-04-08)

[Compare

Source](https://togithub.com/ionic-team/stencil/compare/v4.14.1...v4.15.0)

##### Features

- **compiler:** perform automatic key insertion in more situations
([#&#8203;5594](https://togithub.com/ionic-team/stencil/issues/5594))

([8ee071b](https://togithub.com/ionic-team/stencil/commit/8ee071bf3aae4b2240b50f7af433035c8bf8aa49))
- **typescript:** Update dependency typescript to v5.4.4
([#&#8203;5636](https://togithub.com/ionic-team/stencil/issues/5636))

([a463871](https://togithub.com/ionic-team/stencil/commit/a46387123082d1af9fc17b5909530597dc5b5c68))

####

[`4.14.1`](https://togithub.com/ionic-team/stencil/compare/v4.14.0...v4.14.1)

##### Bug Fixes

- **compiler:** don't mistake aliased paths for collections imports
([#&#8203;5620](https://togithub.com/ionic-team/stencil/issues/5620))

([af22bb8](https://togithub.com/ionic-team/stencil/commit/af22bb858d64b60a97ce93c86f5585ef36b31c3f)),
closes
[#&#8203;2319](https://togithub.com/ionic-team/stencil/issues/2319)
- **runtime:** nested multiple default slot relocation
([#&#8203;5403](https://togithub.com/ionic-team/stencil/issues/5403))

([363c07b](https://togithub.com/ionic-team/stencil/commit/363c07b4723941954dc748189a744eec01d5b74c)),
partially closes
[#&#8203;5335](https://togithub.com/ionic-team/stencil/issues/5335)
- **runtime:** prevent ref callbacks from being called too early
([#&#8203;5614](https://togithub.com/ionic-team/stencil/issues/5614))

([81fa375](https://togithub.com/ionic-team/stencil/commit/81fa37587eb853d42bc7f92102318a3446cdea7b)),
closes
[#&#8203;4074](https://togithub.com/ionic-team/stencil/issues/4074)

###

[`v4.14.1`](https://togithub.com/ionic-team/stencil/blob/HEAD/CHANGELOG.md#-4141-2024-04-04)

[Compare

Source](https://togithub.com/ionic-team/stencil/compare/v4.14.0...v4.14.1)

##### Bug Fixes

- **compiler:** don't mistake aliased paths for collections imports
([#&#8203;5620](https://togithub.com/ionic-team/stencil/issues/5620))

([af22bb8](https://togithub.com/ionic-team/stencil/commit/af22bb858d64b60a97ce93c86f5585ef36b31c3f)),
closes
[#&#8203;2319](https://togithub.com/ionic-team/stencil/issues/2319)
- **runtime:** nested multiple default slot relocation
([#&#8203;5403](https://togithub.com/ionic-team/stencil/issues/5403))

([363c07b](https://togithub.com/ionic-team/stencil/commit/363c07b4723941954dc748189a744eec01d5b74c)),
partially closes
[#&#8203;5335](https://togithub.com/ionic-team/stencil/issues/5335)
- **runtime:** prevent ref callbacks from being called too early
([#&#8203;5614](https://togithub.com/ionic-team/stencil/issues/5614))

([81fa375](https://togithub.com/ionic-team/stencil/commit/81fa37587eb853d42bc7f92102318a3446cdea7b)),
closes
[#&#8203;4074](https://togithub.com/ionic-team/stencil/issues/4074)

###

[`v4.14.0`](https://togithub.com/ionic-team/stencil/blob/HEAD/CHANGELOG.md#-4140-2024-04-01)

[Compare

Source](https://togithub.com/ionic-team/stencil/compare/v4.13.0...v4.14.0)

##### Bug Fixes

- **mock-doc:** provide a local name
([#&#8203;5480](https://togithub.com/ionic-team/stencil/issues/5480))

([2f67b35](https://togithub.com/ionic-team/stencil/commit/2f67b3526c7160a0c9ac71727c401a438d282474)),
closes
[#&#8203;5342](https://togithub.com/ionic-team/stencil/issues/5342)
- **mock-doc:** resolve type issue for localName
([#&#8203;5595](https://togithub.com/ionic-team/stencil/issues/5595))

([d91af87](https://togithub.com/ionic-team/stencil/commit/d91af87d4e309a2da3cb145165cf7fe3c79ac1e7)),
closes
[#&#8203;5342](https://togithub.com/ionic-team/stencil/issues/5342)

##### Features

- **testing:** allow to set screenshot timeout option in Jest v28+
([#&#8203;5537](https://togithub.com/ionic-team/stencil/issues/5537))

([6df12b2](https://togithub.com/ionic-team/stencil/commit/6df12b2a445ffe431f8412758f298a6e1c8fe3ac))
- **testing:** support deep piercing with Puppeteer
([#&#8203;5481](https://togithub.com/ionic-team/stencil/issues/5481))

([13d5d41](https://togithub.com/ionic-team/stencil/commit/13d5d4188ac0d3d8d002ce93c4ec7abdde5c8086))
- **typescript:** Update dependency typescript to v5.4.3
([#&#8203;5588](https://togithub.com/ionic-team/stencil/issues/5588))

([9d489e4](https://togithub.com/ionic-team/stencil/commit/9d489e42a60391d2eb88cb0f7827a9368de18140))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 5am every weekday" in timezone
America/Los_Angeles, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/Esri/calcite-design-system).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI5My4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Ben Elan <no-reply@benelan.dev>
Co-authored-by: JC Franco <jfranco@esri.com>
alicewriteswrongs added a commit that referenced this pull request Apr 17, 2024
This adds some manual string -> boolean type casting to the code that
we use to convert CLI flags to a Jest config (after parsing them with
yargs).

This fixes an issue documented in #5640 where boolean CLI flags like
`--watchAll` were being passed to Jest as strings, instead of as
booleans, so that it was not possible to _disable_ a flag by doing
`--flagName=false` (the value of the flag would be set to the string
`"false"` which is a truthy value).

There was also a somewhat related issue with not properly parsing
boolean flags in our CLI parser which was recently fixed in #5646.

Note that to get this working it was necessary to make some module
resolution-related changes in a few places since there's now a
dependency between the `testing/` and `cli/` modules (`testing/` now
imports and using `BOOLEAN_CLI_FLAGS`). This involved a `paths` alias in
the TypeScript config, esbuild- and rollup-specific module mapping
configuration / aliases, and a change in the Jest config to allow
`@stencil/core/cli` to be resolved in all these contexts.

fixes #5640
STENCIL-1259
alicewriteswrongs added a commit that referenced this pull request Apr 22, 2024
This adds some manual string -> boolean type casting to the code that
we use to convert CLI flags to a Jest config (after parsing them with
yargs).

This fixes an issue documented in #5640 where boolean CLI flags like
`--watchAll` were being passed to Jest as strings, instead of as
booleans, so that it was not possible to _disable_ a flag by doing
`--flagName=false` (the value of the flag would be set to the string
`"false"` which is a truthy value).

There was also a somewhat related issue with not properly parsing
boolean flags in our CLI parser which was recently fixed in #5646.

Note that to get this working it was necessary to make some module
resolution-related changes in a few places since there's now a
dependency between the `testing/` and `cli/` modules (`testing/` now
imports and using `BOOLEAN_CLI_FLAGS`). This involved a `paths` alias in
the TypeScript config, esbuild- and rollup-specific module mapping
configuration / aliases, and a change in the Jest config to allow
`@stencil/core/cli` to be resolved in all these contexts.

fixes #5640
STENCIL-1259
github-merge-queue bot pushed a commit that referenced this pull request Apr 22, 2024
…5672)

This adds some manual string -> boolean type casting to the code that
we use to convert CLI flags to a Jest config (after parsing them with
yargs).

This fixes an issue documented in #5640 where boolean CLI flags like
`--watchAll` were being passed to Jest as strings, instead of as
booleans, so that it was not possible to _disable_ a flag by doing
`--flagName=false` (the value of the flag would be set to the string
`"false"` which is a truthy value).

There was also a somewhat related issue with not properly parsing
boolean flags in our CLI parser which was recently fixed in #5646.

Note that to get this working it was necessary to make some module
resolution-related changes in a few places since there's now a
dependency between the `testing/` and `cli/` modules (`testing/` now
imports and using `BOOLEAN_CLI_FLAGS`). This involved a `paths` alias in
the TypeScript config, esbuild- and rollup-specific module mapping
configuration / aliases, and a change in the Jest config to allow
`@stencil/core/cli` to be resolved in all these contexts.

fixes #5640
STENCIL-1259
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants