Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/cli-docs/src/content/docs/migrating-from-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,19 @@ Two behavioral differences to be aware of:
directory.
- **Flags:** v4 `sourcemap upload` keeps `--release`, `--dist`, `--url-prefix`,
`--ext`, `--ignore`, `--ignore-file`, `--strip-prefix`,
`--strip-common-prefix`, `--no-rewrite`, `--allow-empty`. These v3 flags are
`--strip-common-prefix`, `--no-rewrite`, `--allow-empty`, `--wait`. These
v3 flags are
**not present** in v4: `--url-suffix`, `--note`, `--validate`, `--decompress`,
`--wait`, `--wait-for`, `--no-sourcemap-reference`, `--debug-id-reference`,
`--wait-for` (use `--wait=<seconds>`), `--no-sourcemap-reference`, `--debug-id-reference`,
`--bundle`, `--bundle-sourcemap`, `--strict`. `sourcemap inject` also drops
`--release`. Run `sentry sourcemap upload --help` for the current set.
- **`--wait` is on by default in CI:** when a CI environment variable such as
`CI` or `GITHUB_ACTIONS` is set, `sourcemap upload` waits up to five minutes
for Sentry to process the upload and exits with an error if processing
fails or times out. Pass `--no-wait` to return as soon as Sentry accepts the
upload, or `--wait` to wait outside CI. Replace v3's `--wait-for 600` with
`--wait=600`; `--wait=0` waits with no limit. The value must be attached
with `=`, because `--wait 600` reads `600` as the directory.
- **`--debug-id-reference` is now automatic:** in v3 that flag let `sourcemaps
upload` take the debug ID from the linked sourcemap when it couldn't verify
one in the bundle itself, for example in binary bundles.
Expand Down
8 changes: 8 additions & 0 deletions apps/cli-docs/src/fragments/commands/sourcemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ common cause is a bundler that isn't emitting `.map` files:
For CI steps that may run against legitimately-empty directories (e.g.,
library-only repos, conditional release skips), pass `--allow-empty` to
suppress the error.

Sentry processes an upload after it accepts it, and processing can still
fail. In CI, `sentry sourcemap upload` waits up to five minutes for
processing to finish and exits with an error if it fails or times out.
Outside CI it exits once Sentry accepts the upload. Pass `--wait` or
`--no-wait` to choose, and `--wait=<seconds>` to change the limit
(`--wait=0` waits with no limit). Attach the value with `=`: `--wait 600`
reads `600` as the directory.
152 changes: 122 additions & 30 deletions packages/cli/patches/@stricli%2Fcore@1.2.8.patch

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Upload sourcemaps to Sentry
- `--strip-common-prefix - Automatically strip the longest common path prefix from all files`
- `--no-rewrite - Upload files as-is without injecting debug IDs`
- `--allow-empty - Exit successfully when no JS + sourcemap pairs are found (default: error out to catch silent build misconfigurations)`
- `--wait[=<value>] - Wait for the server to fully process the uploaded files, up to the given seconds (default: 300, 0 = no limit; on in CI)`
- `--no-wait - Exit once Sentry accepts the upload, even in CI`

**Examples:**

Expand Down Expand Up @@ -92,6 +94,12 @@ sentry sourcemap upload ./dist --no-rewrite

# Only upload some extensions
sentry sourcemap upload ./dist --ext .js,.mjs

# Wait for Sentry to process the upload outside CI
sentry sourcemap upload ./dist --wait

# Wait up to ten minutes for processing
sentry sourcemap upload ./dist --wait=600
```

### `sentry sourcemap resolve <directory>`
Expand Down
17 changes: 17 additions & 0 deletions packages/cli/script/check-patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ for (const [key, patchPath] of Object.entries(patches)) {
* `-v`=version alias in `runApplication` so `-v` stays the Sentry CLI's
* `--verbose` alias at every position; `--version` remains the version flag.
* The stale marker is the original `inputs[0] === "-v"` version check.
*
* @stricli/core (`inlineOnly` parsed flags): the patch lets a parsed flag take
* its value only as `--flag=value`, so bare `--wait` never consumes the next
* argument. Pure insertion, guarded by the `inlineOnly` required marker. Its
* absence means `sourcemap upload --wait ./dist` reads `./dist` as the limit.
*/
const CONTENT_ASSERTIONS: ReadonlyArray<{
/** Installed file to inspect, relative to the resolved node_modules dir. */
Expand Down Expand Up @@ -318,6 +323,18 @@ const CONTENT_ASSERTIONS: ReadonlyArray<{
description:
"@stricli/core CJS: pluggable `renderHelp` hook missing (`sentry --help --json` will fall back to text help instead of structured JSON)",
},
{
file: "@stricli/core/dist/index.js",
requiredMarker: "inlineOnly",
description:
"@stricli/core ESM: `inlineOnly` flag scanning missing (`sentry sourcemap upload --wait ./dist` will read `./dist` as the wait limit)",
},
{
file: "@stricli/core/dist/index.cjs",
requiredMarker: "inlineOnly",
description:
"@stricli/core CJS: `inlineOnly` flag scanning missing (`sentry sourcemap upload --wait ./dist` will read `./dist` as the wait limit)",
},
];

for (const assertion of CONTENT_ASSERTIONS) {
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/script/generate-command-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ function formatFlagRow(
if (alias) {
syntax = `-${alias}, ${syntax}`;
}
if ((flag.kind === "parsed" || flag.kind === "enum") && !flag.variadic) {
if (flag.inlineOnly) {
syntax += `[=<${flag.name}>]`;
} else if (
(flag.kind === "parsed" || flag.kind === "enum") &&
!flag.variadic
) {
syntax += ` <${flag.name}>`;
} else if (flag.variadic) {
syntax += ` <${flag.name}>...`;
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/script/generate-skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ function formatFlag(flag: FlagInfo, aliases: Record<string, string>): string {
if (alias) {
syntax = `-${alias}, ${syntax}`;
}
if ((flag.kind === "parsed" || flag.kind === "enum") && !flag.variadic) {
if (flag.inlineOnly) {
syntax += "[=<value>]";
} else if (
(flag.kind === "parsed" || flag.kind === "enum") &&
!flag.variadic
) {
syntax += " <value>";
} else if (flag.variadic) {
syntax += " <value>...";
Expand Down
77 changes: 76 additions & 1 deletion packages/cli/src/commands/sourcemap/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import {
import type { SentryContext } from "../../context.js";
import {
type ArtifactFile,
DEFAULT_UPLOAD_MAX_WAIT_MS,
uploadSourcemaps,
} from "../../lib/api/sourcemaps.js";
import { isCi } from "../../lib/ci.js";
import { buildCommand } from "../../lib/command.js";
import {
choiceListParser,
Expand Down Expand Up @@ -77,6 +79,25 @@ function formatUploadResult(data: UploadCommandResult): string {

const usageHint = () => sentry`sourcemap upload <directory>`;

/**
* Parse `--wait[=seconds]` into a wait limit in seconds.
*
* Bare `--wait` parses `""` and keeps the default limit. `0` means no limit.
*/
export function parseWaitSeconds(input: string): number {
if (input === "") {
return DEFAULT_UPLOAD_MAX_WAIT_MS / 1000;
}
const seconds = Number(input);
if (!Number.isInteger(seconds) || seconds < 0) {
throw new ValidationError(
`--wait takes a whole number of seconds (got "${input}"). Use --wait=0 to wait with no limit.`,
"wait",
);
}
return seconds;
}

/**
* Compute the longest common directory prefix across a list of paths.
*
Expand Down Expand Up @@ -223,7 +244,12 @@ export const uploadCommand = buildCommand({
"Exits with an error if zero JS + sourcemap pairs are discovered " +
"(typical cause: bundler not emitting .map files). Pass " +
"--allow-empty to suppress this check for directories that may " +
"legitimately be empty.",
"legitimately be empty.\n\n" +
"In CI, the command waits up to five minutes for Sentry to finish " +
"processing the upload and exits with an error if processing fails. " +
"Elsewhere it exits once Sentry accepts the upload. Pass --wait or " +
"--no-wait to override, and --wait=<seconds> to change the limit " +
"(--wait=0 waits with no limit). The value must be attached with =.",
examples: [
{
description: "Upload sourcemaps from dist/",
Expand Down Expand Up @@ -257,6 +283,14 @@ export const uploadCommand = buildCommand({
description: "Only upload some extensions",
run: "sourcemap upload ./dist --ext .js,.mjs",
},
{
description: "Wait for Sentry to process the upload outside CI",
run: "sourcemap upload ./dist --wait",
},
{
description: "Wait up to ten minutes for processing",
run: "sourcemap upload ./dist --wait=600",
},
],
},
output: {
Expand Down Expand Up @@ -340,6 +374,22 @@ export const uploadCommand = buildCommand({
optional: true,
default: false,
},
wait: {
kind: "parsed",
parse: parseWaitSeconds,
brief:
"Wait for the server to fully process the uploaded files, up to " +
"the given seconds (default: 300, 0 = no limit; on in CI)",
placeholder: "seconds",
optional: true,
inlineOnly: true,
},
"no-wait": {
kind: "boolean",
brief: "Exit once Sentry accepts the upload, even in CI",
optional: true,
default: false,
},
},
},
async *func(
Expand All @@ -355,9 +405,32 @@ export const uploadCommand = buildCommand({
"strip-common-prefix"?: boolean;
"no-rewrite"?: boolean;
"allow-empty"?: boolean;
wait?: number | string;
"no-wait"?: boolean;
},
dir: string,
) {
if (flags.wait !== undefined && flags["no-wait"]) {
throw new ValidationError(
"--wait and --no-wait cannot be used together.",
"wait",
);
}
// CI must fail when Sentry rejects the bundle, so wait there by default.
const wait = flags["no-wait"]
? false
: flags.wait !== undefined || isCi(this.env);
// SDK callers may supply the public string form without Stricli parsing.
const waitSeconds =
typeof flags.wait === "string"
? parseWaitSeconds(flags.wait)
: flags.wait;
let maxWaitMs = DEFAULT_UPLOAD_MAX_WAIT_MS;
if (waitSeconds !== undefined) {
maxWaitMs =
waitSeconds === 0 ? Number.POSITIVE_INFINITY : waitSeconds * 1000;
}

// Validate the directory and discover pairs read-only first so we
// don't write debug IDs when the upload won't proceed (empty dir,
// typoed path, missing credentials).
Expand Down Expand Up @@ -475,6 +548,8 @@ export const uploadCommand = buildCommand({
release: flags.release,
dist: flags.dist,
files: artifactFiles,
wait,
maxWaitMs,
});

// Count actually-uploaded pairs (one minified_source entry per pair).
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/src/lib/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,12 @@ function formatFlagHuman(
if (alias) {
syntax = `-${alias}, ${syntax}`;
}
if ((flag.kind === "parsed" || flag.kind === "enum") && !flag.variadic) {
if (flag.inlineOnly) {
syntax += "[=<value>]";
} else if (
(flag.kind === "parsed" || flag.kind === "enum") &&
!flag.variadic
) {
syntax += " <value>";
} else if (flag.variadic) {
syntax += " <value>...";
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/lib/introspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export type FlagDef = {
variadic?: boolean;
placeholder?: string;
hidden?: boolean;
/** Takes a value only as `--flag=value` (our Stricli patch); bare, it consumes nothing. */
inlineOnly?: boolean;
/** Stricli parser; completion-aware parsers carry a {@link CompletionTarget}. */
parse?: unknown;
/** Accepted values of an `enum` flag. */
Expand Down Expand Up @@ -144,6 +146,8 @@ export type FlagInfo = {
optional: boolean;
variadic: boolean;
hidden: boolean;
/** Value attaches only as `--flag=value`. */
inlineOnly?: boolean;
};

/** Extracted metadata for a route group or standalone command */
Expand Down Expand Up @@ -289,6 +293,7 @@ export function extractFlags(
optional: def.optional ?? def.kind === "boolean",
variadic: def.variadic ?? false,
hidden: def.hidden ?? false,
...(def.inlineOnly ? { inlineOnly: true } : {}),
}));
}

Expand Down Expand Up @@ -484,7 +489,9 @@ function getCommandCompletion(command: Command): CommandCompletion {
const flagKinds: Record<string, CompletionTarget | null> = {};
const datasets: Record<string, DatasetCompletion> = {};
for (const [name, def] of Object.entries(flags)) {
if (def.kind !== "boolean") {
// An inline-only flag never takes the next word, so completion treats it
// like a boolean.
if (def.kind !== "boolean" && !def.inlineOnly) {
const { kind, values } = argumentCompletion(
def.parse,
def.kind === "enum" ? def.values : undefined,
Expand Down
Loading
Loading