build-sass: Use native Node.js parseArgs utility#9642
Merged
Conversation
changelog: Internal, Packages, Replace third-party dependency with native equivalent
aduth
commented
Nov 22, 2023
Comment on lines
-29
to
+30
| const isWatching = flags.watch; | ||
| const outDir = flags['out-dir']; | ||
| const loadPaths = [...flags['load-path'], ...getDefaultLoadPaths()]; | ||
| const { watch: isWatching, 'out-dir': outDir, 'load-path': loadPaths = [] } = flags; | ||
| loadPaths.push(...getDefaultLoadPaths()); |
Contributor
Author
There was a problem hiding this comment.
The polyfill doesn't reflect that flags['load-path'] may be undefined, which TypeScript flagged as not being possible to splat into an array from the prior logic:
app/javascript/packages/build-sass/cli.js:31:23 - error TS2488: Type 'string[] | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.
31 const loadPaths = [...flags['load-path'], ...getDefaultLoadPaths()];
~~~~~~~~~~~~~~~~~~
So effectively this is adding a default empty array. I could have inlined it, though I chose a bit of a rewrite to destructure the entire flags object and use that as the point at which to assign the default values.
matthinz
approved these changes
Nov 22, 2023
Contributor
matthinz
left a comment
There was a problem hiding this comment.
LGTM, and TIL about node's built in parseArgs support. In general I think we should to require latest LTS for packages we publish (and not feel too bad about the downstream consequences), but definitely appreciate the care & thought you've put in here.
zachmargolis
approved these changes
Nov 22, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠 Summary of changes
Updates
@18f/identity-build-sassto use the native Node.jsutil.parseArgsin place of the third-party package polyfill.This is a public, published package, so there is a consideration of downstream impact of using a feature in a newer version of Node.js. However, since this package is largely for internal projects, and the feature has been supported since 2 LTS releases, I think it's reasonable to drop support for Node.js v16 and older.
The benefit is largely in reducing download size and vulnerability surface area incurred through use of third-party packages. It also simplifies consideration for LTS upgrades such as #9639.
📜 Testing Plan
Observe no regressions in building CSS: