Skip to content

chore(remix): replace yargs with native util.parseArgs#19532

Open
roli-lpci wants to merge 1 commit intogetsentry:developfrom
roli-lpci:chore/remix-replace-yargs-with-parseargs
Open

chore(remix): replace yargs with native util.parseArgs#19532
roli-lpci wants to merge 1 commit intogetsentry:developfrom
roli-lpci:chore/remix-replace-yargs-with-parseargs

Conversation

@roli-lpci
Copy link

Replaces the yargs dependency in @sentry/remix with Node's built-in util.parseArgs for CLI argument parsing in the sentry-upload-sourcemaps script.

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).
  • Link an issue if there is one related to your pull request.

Ref #19447

What this does

Replaces yargs with util.parseArgs (built-in since Node 18.3) for parsing CLI flags in the source map upload script. Adds --keepAfterUpload flag as a cross-version alternative to yargs' --no-deleteAfterUpload boolean negation.

Removes yargs and ~10 transitive dependencies (cliui, escalade, string-width, y18n, yargs-parser, wrap-ansi, etc.).

Behavioral changes from yargs

  • Unknown flags now throw an error (yargs silently ignored them). This catches typos like --relase early.
  • Kebab-case aliases (--url-prefix) no longer work. Use the documented camelCase names (--urlPrefix).
  • Boolean flags no longer accept =true/=false syntax. Use the bare flag (--disableDebugIds) to enable, or --keepAfterUpload to prevent source map deletion.

Why --keepAfterUpload?

util.parseArgs does not support boolean negation (--no-deleteAfterUpload) on Node < 20.16. Since @sentry/remix supports Node >= 18, --keepAfterUpload provides a cross-version way to prevent source map deletion after upload.

Replaces the yargs dependency with Node's built-in util.parseArgs for CLI
argument parsing in the sentry-upload-sourcemaps script.

Adds --keepAfterUpload flag as a cross-version alternative to yargs'
--no-deleteAfterUpload boolean negation (which requires Node >= 20.16).

Behavioral changes from yargs:
- Unknown flags now throw (stricter, catches typos early)
- Kebab-case aliases (--url-prefix) no longer supported; use camelCase
- Boolean flags do not accept =true/=false values

Removes ~10 transitive dependencies (cliui, escalade, string-width, etc.).

Ref: getsentry#19447

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@@ -1,68 +1,74 @@
#!/usr/bin/env node
const yargs = require('yargs');
const { parseArgs } = require('node:util');
Copy link

Choose a reason for hiding this comment

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

Bug: The script uses util.parseArgs, which will crash on Node.js versions 18.0.0-18.2.x, despite the package.json allowing these versions.
Severity: MEDIUM

Suggested Fix

Update the package.json engines field to require "node": ">=18.3.0". Alternatively, add a runtime check for util.parseArgs and provide a helpful error message or a fallback implementation for older Node.js versions.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/remix/scripts/sentry-upload-sourcemaps.js#L2

Potential issue: The `sentry-upload-sourcemaps.js` script utilizes the `util.parseArgs`
function, which is only available in Node.js versions 18.3.0 and later. The project's
`package.json` declares support for Node.js version 18.0.0 and above (`"node": ">=18"`).
Consequently, users running the script on Node.js versions between 18.0.0 and 18.2.x
will encounter a runtime crash because the `util.parseArgs` function does not exist in
their environment. The current CI setup does not test against these specific older patch
versions of Node 18, so this issue would not be caught automatically.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member

Choose a reason for hiding this comment

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

Since our minimum is 18.0 we need to have a fallback for utils.parseArgs

Copy link
Member

@isaacs isaacs Feb 26, 2026

Choose a reason for hiding this comment

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

We could add @pkgjs/parseargs as a dependency instead of yargs, and keep that around until we drop v18 support. It's at least less of a cost than yargs, because it's much smaller.

@logaretm
Copy link
Member

Thanks for the PR, we probably need to have a fallback for util.parseArgs and resolve the current conflict. Then I will approve a CI run and see how it goes.

@@ -1,68 +1,74 @@
#!/usr/bin/env node
const yargs = require('yargs');
const { parseArgs } = require('node:util');
Copy link
Member

@isaacs isaacs Feb 26, 2026

Choose a reason for hiding this comment

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

Suggested change
const { parseArgs } = require('node:util');
// TODO: remove when node v18 support drops
let parseArgs;
try {
parseArgs = require('node:util').parseArgs;
} catch {
parseArgs = require('@pkgjs/parseargs').parseArgs;
}

@isaacs
Copy link
Member

isaacs commented Feb 26, 2026

To be honest, the behavioral changes from yargs to util.parseArgs feel like they are too great a breaking change to do within a major release line. Perhaps this should be pushed off until the v11 milestone, and then we can consider dropping node 18, and not need the fallback at all?

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