-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
chore(remix): replace yargs with native util.parseArgs #19532
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
Open
roli-lpci
wants to merge
1
commit into
getsentry:develop
Choose a base branch
from
roli-lpci:chore/remix-replace-yargs-with-parseargs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+64
−59
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,68 +1,74 @@ | ||||||||||||||||||
| #!/usr/bin/env node | ||||||||||||||||||
| const yargs = require('yargs'); | ||||||||||||||||||
| const { parseArgs } = require('node:util'); | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| const { createRelease } = require('./createRelease'); | ||||||||||||||||||
| const { injectDebugId } = require('./injectDebugId'); | ||||||||||||||||||
|
|
||||||||||||||||||
| const DEFAULT_URL_PREFIX = '~/build/'; | ||||||||||||||||||
| const DEFAULT_BUILD_PATH = 'public/build'; | ||||||||||||||||||
|
|
||||||||||||||||||
| const argv = yargs(process.argv.slice(2)) | ||||||||||||||||||
| .option('release', { | ||||||||||||||||||
| type: 'string', | ||||||||||||||||||
| describe: | ||||||||||||||||||
| 'The release number\n' + | ||||||||||||||||||
| "If not provided, a new release id will be determined by Sentry CLI's `propose-version`.\n" + | ||||||||||||||||||
| 'See: https://docs.sentry.io/product/releases/suspect-commits/#using-the-cli\n', | ||||||||||||||||||
| }) | ||||||||||||||||||
| .option('org', { | ||||||||||||||||||
| type: 'string', | ||||||||||||||||||
| describe: 'The Sentry organization slug', | ||||||||||||||||||
| }) | ||||||||||||||||||
| .option('project', { | ||||||||||||||||||
| type: 'string', | ||||||||||||||||||
| describe: 'The Sentry project slug', | ||||||||||||||||||
| }) | ||||||||||||||||||
| .option('url', { | ||||||||||||||||||
| type: 'string', | ||||||||||||||||||
| describe: 'The Sentry server URL', | ||||||||||||||||||
| }) | ||||||||||||||||||
| .option('urlPrefix', { | ||||||||||||||||||
| type: 'string', | ||||||||||||||||||
| describe: 'URL prefix to add to the beginning of all filenames', | ||||||||||||||||||
| default: DEFAULT_URL_PREFIX, | ||||||||||||||||||
| }) | ||||||||||||||||||
| .option('buildPath', { | ||||||||||||||||||
| type: 'string', | ||||||||||||||||||
| describe: 'The path to the build directory', | ||||||||||||||||||
| default: DEFAULT_BUILD_PATH, | ||||||||||||||||||
| }) | ||||||||||||||||||
| .option('disableDebugIds', { | ||||||||||||||||||
| type: 'boolean', | ||||||||||||||||||
| describe: 'Disable the injection and upload of debug ids', | ||||||||||||||||||
| default: false, | ||||||||||||||||||
| }) | ||||||||||||||||||
| .option('deleteAfterUpload', { | ||||||||||||||||||
| type: 'boolean', | ||||||||||||||||||
| describe: 'Delete sourcemaps after uploading', | ||||||||||||||||||
| default: true, | ||||||||||||||||||
| }) | ||||||||||||||||||
| .usage( | ||||||||||||||||||
| 'Usage: $0\n' + | ||||||||||||||||||
| ' [--release RELEASE]\n' + | ||||||||||||||||||
| ' [--org ORG]\n' + | ||||||||||||||||||
| ' [--project PROJECT]\n' + | ||||||||||||||||||
| ' [--url URL]\n' + | ||||||||||||||||||
| ' [--urlPrefix URL_PREFIX]\n' + | ||||||||||||||||||
| ' [--buildPath BUILD_PATH]\n\n' + | ||||||||||||||||||
| ' [--disableDebugIds true|false]\n\n' + | ||||||||||||||||||
| ' [--deleteAfterUpload true|false]\n\n' + | ||||||||||||||||||
| 'This CLI tool will upload sourcemaps to Sentry for the given release.\n' + | ||||||||||||||||||
| 'It has defaults for URL prefix and build path for Remix builds, but you can override them.\n\n' + | ||||||||||||||||||
| 'If you need a more advanced configuration, you can use `sentry-cli` instead.\n' + | ||||||||||||||||||
| 'https://github.com/getsentry/sentry-cli', | ||||||||||||||||||
| ) | ||||||||||||||||||
| .wrap(120).argv; | ||||||||||||||||||
| const USAGE = `Usage: sentry-upload-sourcemaps [options] | ||||||||||||||||||
|
|
||||||||||||||||||
| Options: | ||||||||||||||||||
| --release RELEASE The release number. If not provided, a new release | ||||||||||||||||||
| id will be determined by Sentry CLI's propose-version. | ||||||||||||||||||
| See: https://docs.sentry.io/product/releases/suspect-commits/#using-the-cli | ||||||||||||||||||
| --org ORG The Sentry organization slug | ||||||||||||||||||
| --project PROJECT The Sentry project slug | ||||||||||||||||||
| --url URL The Sentry server URL | ||||||||||||||||||
| --urlPrefix URL_PREFIX URL prefix to add to the beginning of all filenames | ||||||||||||||||||
| [default: "${DEFAULT_URL_PREFIX}"] | ||||||||||||||||||
| --buildPath BUILD_PATH The path to the build directory | ||||||||||||||||||
| [default: "${DEFAULT_BUILD_PATH}"] | ||||||||||||||||||
| --disableDebugIds Disable the injection and upload of debug ids | ||||||||||||||||||
| [default: false] | ||||||||||||||||||
| --deleteAfterUpload Delete sourcemaps after uploading | ||||||||||||||||||
| [default: true] | ||||||||||||||||||
| --keepAfterUpload Keep sourcemaps after uploading (prevents deletion). | ||||||||||||||||||
| Use this instead of --no-deleteAfterUpload for | ||||||||||||||||||
| compatibility with Node < 20.16. | ||||||||||||||||||
| [default: false] | ||||||||||||||||||
| -h, --help Show this help message | ||||||||||||||||||
|
|
||||||||||||||||||
| This CLI tool will upload sourcemaps to Sentry for the given release. | ||||||||||||||||||
| It has defaults for URL prefix and build path for Remix builds, but you | ||||||||||||||||||
| can override them. | ||||||||||||||||||
|
|
||||||||||||||||||
| If you need a more advanced configuration, you can use sentry-cli instead. | ||||||||||||||||||
| https://github.com/getsentry/sentry-cli`; | ||||||||||||||||||
|
|
||||||||||||||||||
| // Note: Unlike yargs, util.parseArgs with strict mode (the default): | ||||||||||||||||||
| // - Rejects unknown flags (stricter, catches typos) | ||||||||||||||||||
| // - Does not auto-convert kebab-case to camelCase (use --urlPrefix, not --url-prefix) | ||||||||||||||||||
| // - Boolean flags cannot take =true/=false values (use bare --flag to enable) | ||||||||||||||||||
| const { values: argv } = parseArgs({ | ||||||||||||||||||
| args: process.argv.slice(2), | ||||||||||||||||||
| options: { | ||||||||||||||||||
| release: { type: 'string' }, | ||||||||||||||||||
| org: { type: 'string' }, | ||||||||||||||||||
| project: { type: 'string' }, | ||||||||||||||||||
| url: { type: 'string' }, | ||||||||||||||||||
| urlPrefix: { type: 'string', default: DEFAULT_URL_PREFIX }, | ||||||||||||||||||
| buildPath: { type: 'string', default: DEFAULT_BUILD_PATH }, | ||||||||||||||||||
| disableDebugIds: { type: 'boolean', default: false }, | ||||||||||||||||||
| deleteAfterUpload: { type: 'boolean', default: true }, | ||||||||||||||||||
| keepAfterUpload: { type: 'boolean', default: false }, | ||||||||||||||||||
| help: { type: 'boolean', short: 'h', default: false }, | ||||||||||||||||||
| }, | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (argv.help) { | ||||||||||||||||||
| // eslint-disable-next-line no-console | ||||||||||||||||||
| console.log(USAGE); | ||||||||||||||||||
| process.exit(0); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // --keepAfterUpload overrides --deleteAfterUpload to prevent source map deletion. | ||||||||||||||||||
| // This flag exists because util.parseArgs does not support --no-deleteAfterUpload | ||||||||||||||||||
| // on Node < 20.16, so without it there is no way to disable deletion. | ||||||||||||||||||
| if (argv.keepAfterUpload) { | ||||||||||||||||||
| argv.deleteAfterUpload = false; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const buildPath = argv.buildPath || DEFAULT_BUILD_PATH; | ||||||||||||||||||
| const urlPrefix = argv.urlPrefix || DEFAULT_URL_PREFIX; | ||||||||||||||||||
|
|
||||||||||||||||||
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.
There was a problem hiding this comment.
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 thepackage.jsonallowing these versions.Severity: MEDIUM
Suggested Fix
Update the
package.jsonenginesfield to require"node": ">=18.3.0". Alternatively, add a runtime check forutil.parseArgsand provide a helpful error message or a fallback implementation for older Node.js versions.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
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
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add
@pkgjs/parseargsas 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.