chore(remix): replace yargs with native util.parseArgs#19532
chore(remix): replace yargs with native util.parseArgs#19532roli-lpci wants to merge 1 commit intogetsentry:developfrom
Conversation
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'); | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Since our minimum is 18.0 we need to have a fallback for utils.parseArgs
There was a problem hiding this comment.
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.
|
Thanks for the PR, we probably need to have a fallback for |
| @@ -1,68 +1,74 @@ | |||
| #!/usr/bin/env node | |||
| const yargs = require('yargs'); | |||
| const { parseArgs } = require('node:util'); | |||
There was a problem hiding this comment.
| 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; | |
| } |
|
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? |
Replaces the
yargsdependency in@sentry/remixwith Node's built-inutil.parseArgsfor CLI argument parsing in thesentry-upload-sourcemapsscript.yarn lint) & (yarn test).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--keepAfterUploadflag as a cross-version alternative to yargs'--no-deleteAfterUploadboolean negation.Removes yargs and ~10 transitive dependencies (cliui, escalade, string-width, y18n, yargs-parser, wrap-ansi, etc.).
Behavioral changes from yargs
--relaseearly.--url-prefix) no longer work. Use the documented camelCase names (--urlPrefix).=true/=falsesyntax. Use the bare flag (--disableDebugIds) to enable, or--keepAfterUploadto prevent source map deletion.Why --keepAfterUpload?
util.parseArgsdoes not support boolean negation (--no-deleteAfterUpload) on Node < 20.16. Since@sentry/remixsupports Node >= 18,--keepAfterUploadprovides a cross-version way to prevent source map deletion after upload.