Skip to content

build-sass: Use native Node.js parseArgs utility#9642

Merged
aduth merged 2 commits intomainfrom
aduth-build-sass-native-parseargs
Nov 27, 2023
Merged

build-sass: Use native Node.js parseArgs utility#9642
aduth merged 2 commits intomainfrom
aduth-build-sass-native-parseargs

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Nov 22, 2023

🛠 Summary of changes

Updates @18f/identity-build-sass to use the native Node.js util.parseArgs in 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:

make run
  1. Go to http://localhost:3000
  2. Observe no visual regressions

changelog: Internal, Packages, Replace third-party dependency with native equivalent
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());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@matthinz matthinz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@aduth aduth merged commit 851b7fe into main Nov 27, 2023
@aduth aduth deleted the aduth-build-sass-native-parseargs branch November 27, 2023 13:40
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.

3 participants