diff --git a/.craft.yml b/.craft.yml index bb8a6f71f..2e04fdbb7 100644 --- a/.craft.yml +++ b/.craft.yml @@ -138,8 +138,10 @@ workspaces: # `merge-jobs.yml` packs every one of them. To publish another package # from `packages/`, add its directory name here and to release.yml's # `product` options. No preReleaseCommand: - # Craft bumps package.json through the npm target. - packages/{http,logger}: + # Craft bumps package.json through the npm target. `wizard` is the + # deprecated @sentry/wizard forwarder; it starts at 10.0.0 so npm's `latest` + # moves forward from 9.x, and CLI releases don't bump or publish it. + packages/{http,logger,wizard}: changelog: policy: auto releaseBranchPrefix: "release/{{workspaceName}}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2a50f995f..d89158f0e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,6 +14,7 @@ on: - cli - http - logger + - wizard bump: description: "Version bump: auto (from commits), pre (next prerelease), or an explicit bump type" required: true diff --git a/AGENTS.md b/AGENTS.md index a078084a2..fa77c21da 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -42,7 +42,8 @@ toolkit/ │ ├── mcp-cloudflare/ # Web app + OAuth │ ├── mcp-server-evals/ # AI evaluation tests │ ├── mcp-server-mocks/ # MSW mocks -│ └── mcp-test-client/ # CLI test client +│ ├── mcp-test-client/ # CLI test client +│ └── wizard/ # Deprecated @sentry/wizard, forwards to `sentry wizard` └── docs/ # Toolkit contributor docs for CLI and MCP ``` diff --git a/docs/README.md b/docs/README.md index b083b8311..7b1472b4c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -37,7 +37,9 @@ shared primitives used by both products. `packages/logger/` is the structured logger the CLI uses, published to npm as `@sentry/logger`; see its [README](../packages/logger/README.md). `packages/http/` is the HTTP response cache, body codec, and retry logic, published to npm as `@sentry/http`; see -its [README](../packages/http/README.md). +its [README](../packages/http/README.md). `packages/wizard/` is the +deprecated `@sentry/wizard` package, which only forwards to `sentry wizard`; +see its [README](../packages/wizard/README.md). ## Ownership diff --git a/packages/wizard/LICENSE.md b/packages/wizard/LICENSE.md new file mode 100644 index 000000000..6e9bafc7a --- /dev/null +++ b/packages/wizard/LICENSE.md @@ -0,0 +1,105 @@ +# Functional Source License, Version 1.1, Apache 2.0 Future License + +## Abbreviation + +FSL-1.1-Apache-2.0 + +## Notice + +Copyright 2025 Functional Software, Inc. dba Sentry + +## Terms and Conditions + +### Licensor ("We") + +The party offering the Software under these Terms and Conditions. + +### The Software + +The "Software" is each version of the software that we make available under +these Terms and Conditions, as indicated by our inclusion of these Terms and +Conditions with the Software. + +### License Grant + +Subject to your compliance with this License Grant and the Patents, +Redistribution and Trademark clauses below, we hereby grant you the right to +use, copy, modify, create derivative works, publicly perform, publicly display +and redistribute the Software for any Permitted Purpose identified below. + +### Permitted Purpose + +A Permitted Purpose is any purpose other than a Competing Use. A Competing Use +means making the Software available to others in a commercial product or +service that: + +1. substitutes for the Software; + +2. substitutes for any other product or service we offer using the Software + that exists as of the date we make the Software available; or + +3. offers the same or substantially similar functionality as the Software. + +Permitted Purposes specifically include using the Software: + +1. for your internal use and access; + +2. for non-commercial education; + +3. for non-commercial research; and + +4. in connection with professional services that you provide to a licensee + using the Software in accordance with these Terms and Conditions. + +### Patents + +To the extent your use for a Permitted Purpose would necessarily infringe our +patents, the license grant above includes a license under our patents. If you +make a claim against any party that the Software infringes or contributes to +the infringement of any patent, then your patent license to the Software ends +immediately. + +### Redistribution + +The Terms and Conditions apply to all copies, modifications and derivatives of +the Software. + +If you redistribute any copies, modifications or derivatives of the Software, +you must include a copy of or a link to these Terms and Conditions and not +remove any copyright notices provided in or with the Software. + +### Disclaimer + +THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR +PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT. + +IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE +SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, +EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE. + +### Trademarks + +Except for displaying the License Details and identifying us as the origin of +the Software, you have no right under these Terms and Conditions to use our +trademarks, trade names, service marks or product names. + +## Grant of Future License + +We hereby irrevocably grant you an additional license to use the Software under +the Apache License, Version 2.0 that is effective on the second anniversary of +the date we make the Software available. On or after that date, you may use the +Software under the Apache License, Version 2.0, in which case the following +will apply: + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. + +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. diff --git a/packages/wizard/README.md b/packages/wizard/README.md new file mode 100644 index 000000000..a81156d8b --- /dev/null +++ b/packages/wizard/README.md @@ -0,0 +1,41 @@ +# @sentry/wizard + +> **Deprecated. Use `npx sentry wizard`.** The Sentry wizard is now the +> `sentry wizard` command of the [Sentry CLI](https://cli.sentry.dev). It +> takes the org and project first, then the integration: +> +> ```shell +> npx sentry wizard my-org/my-project nextjs +> ``` +> +> See the [`sentry wizard` docs](https://cli.sentry.dev/commands/wizard/). + +From version 10, this package only forwards to `sentry wizard`, so existing +`npx @sentry/wizard` commands keep working: + +```shell +# Runs `sentry wizard my-org/my-project nextjs` +npx @sentry/wizard -i nextjs --org my-org --project my-project +``` + +It prints a deprecation notice on stderr, then runs `sentry wizard` from the +[`sentry`](https://www.npmjs.com/package/sentry) package it depends on, with +the old flags translated: + +- `-i`/`--integration ` becomes the integration argument. +- `--org --project ` becomes `/`, and `--org` + alone becomes `/`. +- `--force-install`, `--ignore-git-changes`, `-f` and `--force` become `-f`. +- `-u`/`--url ` sets `SENTRY_URL` for the run. +- `--spotlight` sets `SENTRY_SPOTLIGHT=1` for the run. +- Positional arguments and `--help` pass through. + +Every other old flag is ignored with a notice, including `--project` without +`--org`, `--saas` and the sign-up flags (sign up at first). The exit code +and signals pass through. Version 9 stays on npm for anyone who pins it. + +## Development + +`bin/sentry-wizard.js` is the whole package, shipped as written. +`pnpm run test` runs it against a stand-in `sentry` package. It is released on +its own, from the `packages/wizard` Craft workspace, not with the CLI. diff --git a/packages/wizard/bin/sentry-wizard.js b/packages/wizard/bin/sentry-wizard.js new file mode 100755 index 000000000..de18ecca5 --- /dev/null +++ b/packages/wizard/bin/sentry-wizard.js @@ -0,0 +1,238 @@ +#!/usr/bin/env node +// `@sentry/wizard` 10 runs `sentry wizard` from the Sentry CLI, which replaced +// it. Old flags are translated to the command's syntax; stdio, the exit code, +// and signals pass through unchanged. +import { spawn } from "node:child_process"; +import { existsSync, readFileSync } from "node:fs"; +import { createRequire } from "node:module"; +import { constants } from "node:os"; +import { dirname, join, resolve } from "node:path"; + +const NOTICE = + "`@sentry/wizard` is deprecated. Use `npx sentry wizard` instead."; + +/** + * How long the first SIGINT waits before it is passed on. Ctrl-C signals the + * terminal's whole foreground process group, so the CLI has that one already, + * and a second SIGINT means "force quit" to it. A SIGINT sent to this process + * alone, such as `kill -INT`, still reaches the CLI after the wait. + */ +const INTERRUPT_GRACE_MS = 3000; + +/** + * Find the `sentry` package's bin script. Its `exports` don't include + * `package.json`, so resolve its entry point and walk up to its manifest. + * Resolving works in `node_modules` installs and under Yarn Plug'n'Play. + * + * @returns {string | undefined} + */ +function findSentryBin() { + let dir; + try { + dir = dirname(createRequire(import.meta.url).resolve("sentry")); + } catch { + return undefined; + } + for (;;) { + const manifestPath = join(dir, "package.json"); + if (existsSync(manifestPath)) { + /** @type {{ name?: string, bin?: string | Record }} */ + const manifest = JSON.parse(readFileSync(manifestPath, "utf8")); + if (manifest.name === "sentry") { + const bin = + typeof manifest.bin === "string" + ? manifest.bin + : manifest.bin?.["sentry"]; + return bin === undefined ? undefined : resolve(dir, bin); + } + } + const parent = dirname(dir); + if (parent === dir) { + return undefined; + } + dir = parent; + } +} + +/** Old flags with a `sentry wizard` equivalent, by name. */ +const TRANSLATED = new Map([ + ["i", "integration"], + ["integration", "integration"], + ["u", "url"], + ["url", "url"], + ["org", "org"], + ["project", "project"], +]); + +/** Flags that become `-f`, including `-f` itself. */ +const FORCE_FLAGS = new Set([ + "f", + "force", + "force-install", + "ignore-git-changes", +]); + +/** Old flags without an equivalent that take a value, which is dropped too. */ +const VALUE_FLAGS = new Set([ + "promo-code", + "coming-from", + "xcode-project-dir", + "app-target", + "hosted-test-target", +]); + +/** Old flags that take every value up to the next flag. */ +const ARRAY_FLAGS = new Set(["p", "platform"]); + +/** + * Translate `@sentry/wizard` arguments to `sentry wizard [/] + * [] [-f]`, plus the CLI's environment variables for `--url` and + * `--spotlight`. Other arguments, such as a target or integration already + * written as positionals, pass through. Values are never printed: some old + * flags carried tokens. + * + * @param {readonly string[]} args + * @returns {{ args: string[], env: Record, notices: string[] }} + */ +function translateArgs(args) { + /** @type {Map} */ + const values = new Map(); + /** @type {string[]} */ + const positionals = []; + /** @type {string[]} */ + const notices = []; + let force = false; + let help = false; + let spotlight = false; + for (let index = 0; index < args.length; index += 1) { + const arg = args[index] ?? ""; + if (arg === "--") { + positionals.push(...args.slice(index + 1)); + break; + } + if (!arg.startsWith("-") || arg === "-") { + positionals.push(arg); + continue; + } + if (arg === "-h" || arg === "--help") { + help = true; + continue; + } + const equals = arg.indexOf("="); + const flag = equals === -1 ? arg : arg.slice(0, equals); + const name = flag.replace(/^--?/, ""); + let value = equals === -1 ? undefined : arg.slice(equals + 1); + const isNextValue = () => !(args[index + 1] ?? "-").startsWith("-"); + const equivalent = TRANSLATED.get(name); + if ( + value === undefined && + (equivalent !== undefined || + VALUE_FLAGS.has(name) || + name.startsWith("preSelectedProject.")) && + isNextValue() + ) { + index += 1; + value = args[index]; + } + if (ARRAY_FLAGS.has(name)) { + while (value === undefined && isNextValue()) { + index += 1; + } + } + if (FORCE_FLAGS.has(name)) { + force = true; + } else if (name === "spotlight") { + spotlight = true; + } else if (equivalent === undefined) { + notices.push(`Ignoring ${flag}: \`sentry wizard\` has no such option.`); + } else if (value === undefined) { + notices.push(`Ignoring ${flag}: it needs a value.`); + } else { + values.set(equivalent, value); + } + } + + const org = values.get("org"); + const project = values.get("project"); + if (org === undefined && project !== undefined) { + notices.push( + "Ignoring --project: it needs --org, so the wizard asks for the project.", + ); + } + const integration = values.get("integration"); + const url = values.get("url"); + return { + args: [ + ...(org === undefined ? [] : [`${org}/${project ?? ""}`]), + ...positionals, + ...(integration === undefined ? [] : [integration]), + ...(force ? ["-f"] : []), + ...(help ? ["--help"] : []), + ], + env: { + ...(url === undefined ? {} : { SENTRY_URL: url }), + ...(spotlight ? { SENTRY_SPOTLIGHT: "1" } : {}), + }, + notices, + }; +} + +process.stderr.write(`${NOTICE}\n`); +const translated = translateArgs(process.argv.slice(2)); +for (const notice of translated.notices) { + process.stderr.write(`${notice}\n`); +} + +const sentryBin = findSentryBin(); +if (sentryBin === undefined) { + process.stderr.write( + "Could not find the `sentry` package. Run `npx sentry wizard` instead.\n", + ); + process.exit(1); +} + +const child = spawn( + process.execPath, + [sentryBin, "wizard", ...translated.args], + { + stdio: "inherit", + env: { ...process.env, ...translated.env }, + }, +); + +let interrupts = 0; +/** @type {NodeJS.Timeout | undefined} */ +let interruptFallback; +const onSigint = () => { + interrupts += 1; + clearTimeout(interruptFallback); + if (interrupts > 1) { + child.kill("SIGINT"); + return; + } + interruptFallback = setTimeout( + () => child.kill("SIGINT"), + INTERRUPT_GRACE_MS, + ); +}; +const onSigterm = () => child.kill("SIGTERM"); +process.on("SIGINT", onSigint); +process.on("SIGTERM", onSigterm); + +child.on("error", (error) => { + process.stderr.write(`Could not start the Sentry CLI: ${error.message}\n`); + process.exit(1); +}); + +child.on("exit", (code, signal) => { + clearTimeout(interruptFallback); + process.off("SIGINT", onSigint); + process.off("SIGTERM", onSigterm); + if (signal === null) { + process.exit(code ?? 1); + } + // End this process with the same signal, so callers see how the CLI ended. + process.kill(process.pid, signal); + // Only reached where the signal doesn't end the process, such as Windows. + process.exit(128 + constants.signals[signal]); +}); diff --git a/packages/wizard/package.json b/packages/wizard/package.json new file mode 100644 index 000000000..06e8f6058 --- /dev/null +++ b/packages/wizard/package.json @@ -0,0 +1,48 @@ +{ + "name": "@sentry/wizard", + "version": "10.0.0-dev.0", + "description": "Deprecated: forwards to `sentry wizard` from the Sentry CLI. Use `npx sentry wizard` instead.", + "type": "module", + "packageManager": "pnpm@12.18.0", + "engines": { + "node": ">=20.0" + }, + "publishConfig": { + "access": "public" + }, + "license": "FSL-1.1-Apache-2.0", + "author": "Sentry", + "homepage": "https://github.com/getsentry/toolkit/tree/main/packages/wizard#readme", + "keywords": [ + "sentry", + "wizard" + ], + "bugs": { + "url": "https://github.com/getsentry/toolkit/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/getsentry/toolkit.git", + "directory": "packages/wizard" + }, + "bin": { + "sentry-wizard": "./bin/sentry-wizard.js" + }, + "files": [ + "bin/sentry-wizard.js", + "LICENSE.md" + ], + "scripts": { + "test": "vitest run", + "test:ci": "vitest run --reporter=default --reporter=junit --outputFile=tests.junit.xml", + "typecheck": "tsc" + }, + "dependencies": { + "sentry": ">=0.52.0" + }, + "devDependencies": { + "@types/node": "catalog:", + "typescript": "catalog:", + "vitest": "catalog:" + } +} diff --git a/packages/wizard/test/sentry-wizard.test.ts b/packages/wizard/test/sentry-wizard.test.ts new file mode 100644 index 000000000..e0bebf746 --- /dev/null +++ b/packages/wizard/test/sentry-wizard.test.ts @@ -0,0 +1,326 @@ +import { type ChildProcess, spawn } from "node:child_process"; +import { once } from "node:events"; +import { + copyFileSync, + mkdirSync, + mkdtempSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { afterAll, beforeAll, describe, expect, test } from "vitest"; + +const SOURCE_BIN = fileURLToPath( + new URL("../bin/sentry-wizard.js", import.meta.url), +); +const NOTICE = + "`@sentry/wizard` is deprecated. Use `npx sentry wizard` instead.\n"; + +// A stand-in for the `sentry` package's bin. It prints its arguments, +// SENTRY_URL and SENTRY_SPOTLIGHT, then behaves as FAKE_SENTRY says: exit with a code, die from a signal, or wait +// and report the signals it gets. +const FAKE_SENTRY_BIN = ` +const [mode, value] = (process.env.FAKE_SENTRY ?? "exit:0").split(":"); +process.stdout.write( + JSON.stringify({ + args: process.argv.slice(2), + url: process.env.SENTRY_URL, + spotlight: process.env.SENTRY_SPOTLIGHT, + }) + "\\n", +); +if (mode === "exit") process.exit(Number(value)); +if (mode === "kill") process.kill(process.pid, value); +if (mode === "wait") { + for (const signal of ["SIGINT", "SIGTERM"]) { + process.on(signal, () => { + process.stdout.write(signal + "\\n"); + process.exit(Number(value)); + }); + } + process.stdout.write("ready\\n"); + setInterval(() => {}, 1000); +} +`; + +/** Install the forwarder, and the fake `sentry` unless `withSentry` is false. */ +function install(dir: string, withSentry = true): string { + const wizardDir = join(dir, "node_modules", "@sentry", "wizard"); + const bin = join(wizardDir, "bin", "sentry-wizard.js"); + mkdirSync(dirname(bin), { recursive: true }); + writeFileSync( + join(wizardDir, "package.json"), + JSON.stringify({ name: "@sentry/wizard", type: "module" }), + ); + copyFileSync(SOURCE_BIN, bin); + if (withSentry) { + const sentryDir = join(dir, "node_modules", "sentry"); + mkdirSync(join(sentryDir, "dist"), { recursive: true }); + writeFileSync( + join(sentryDir, "package.json"), + // Like the real package, its `exports` don't include package.json. + JSON.stringify({ + name: "sentry", + main: "./dist/index.cjs", + exports: { ".": { require: "./dist/index.cjs" } }, + bin: { sentry: "./dist/bin.cjs" }, + }), + ); + writeFileSync(join(sentryDir, "dist", "index.cjs"), ""); + writeFileSync(join(sentryDir, "dist", "bin.cjs"), FAKE_SENTRY_BIN); + } + return bin; +} + +type Run = { + child: ChildProcess; + stdout: () => string; + stderr: () => string; + done: Promise<{ code: number | null; signal: NodeJS.Signals | null }>; +}; + +function run(bin: string, args: string[], fake = "exit:0"): Run { + // `pnpm run` sets NODE_PATH to its store, where Node would find the + // workspace CLI instead of the fake. + const { + NODE_PATH: _nodePath, + SENTRY_URL: _sentryUrl, + SENTRY_SPOTLIGHT: _sentrySpotlight, + ...env + } = process.env; + const child = spawn(process.execPath, [bin, ...args], { + env: { ...env, FAKE_SENTRY: fake }, + stdio: ["ignore", "pipe", "pipe"], + }); + let stdout = ""; + let stderr = ""; + child.stdout.on("data", (chunk: Buffer) => (stdout += chunk.toString())); + child.stderr.on("data", (chunk: Buffer) => (stderr += chunk.toString())); + const done = once(child, "close").then(([code, signal]) => ({ + code: code as number | null, + signal: signal as NodeJS.Signals | null, + })); + return { child, stdout: () => stdout, stderr: () => stderr, done }; +} + +async function waitFor(check: () => boolean): Promise { + while (!check()) { + await new Promise((resolve) => setTimeout(resolve, 20)); + } +} + +let root: string; +let bin: string; + +beforeAll(() => { + root = mkdtempSync(join(tmpdir(), "sentry-wizard-test-")); + bin = install(join(root, "project")); +}); + +afterAll(() => { + rmSync(root, { recursive: true, force: true }); +}); + +describe("sentry-wizard", () => { + test("prints the deprecation notice and translates -i, --org and --project", async () => { + const result = run(bin, [ + "-i", + "nextjs", + "--org", + "my-org", + "--project", + "my-app", + ]); + + expect(await result.done).toEqual({ code: 0, signal: null }); + expect(result.stderr()).toBe(NOTICE); + expect(JSON.parse(result.stdout())).toEqual({ + args: ["wizard", "my-org/my-app", "nextjs"], + }); + }); + + test("reads --flag=value forms, and --org alone as an org target", async () => { + const result = run(bin, ["--integration=nextjs", "--org=my-org"]); + + expect(await result.done).toEqual({ code: 0, signal: null }); + expect(JSON.parse(result.stdout())).toEqual({ + args: ["wizard", "my-org/", "nextjs"], + }); + }); + + test("turns --force-install and --ignore-git-changes into one -f", async () => { + const result = run(bin, [ + "--force-install", + "-i", + "nextjs", + "--ignore-git-changes", + ]); + + expect(await result.done).toEqual({ code: 0, signal: null }); + expect(JSON.parse(result.stdout())).toEqual({ + args: ["wizard", "nextjs", "-f"], + }); + }); + + test.each([["-f"], ["--force"], ["-f", "--force", "--force-install"]])( + "passes %s through as one -f, with no notice", + async (...forceArgs) => { + const result = run(bin, ["-i", "nextjs", ...forceArgs]); + + expect(await result.done).toEqual({ code: 0, signal: null }); + expect(result.stderr()).toBe(NOTICE); + expect(JSON.parse(result.stdout())).toEqual({ + args: ["wizard", "nextjs", "-f"], + }); + }, + ); + + test("sets SENTRY_SPOTLIGHT=1 for --spotlight instead of passing it on", async () => { + const result = run(bin, ["--spotlight", "-i", "nextjs"]); + + expect(await result.done).toEqual({ code: 0, signal: null }); + expect(result.stderr()).toBe(NOTICE); + expect(JSON.parse(result.stdout())).toEqual({ + args: ["wizard", "nextjs"], + spotlight: "1", + }); + }); + + test.each([ + ["-u", "https://sentry.example.com"], + ["--url", "https://sentry.example.com"], + ["--url=https://sentry.example.com"], + ])("sets SENTRY_URL for %s instead of passing it on", async (...urlArgs) => { + const result = run(bin, [...urlArgs, "-i", "nextjs"]); + + expect(await result.done).toEqual({ code: 0, signal: null }); + expect(JSON.parse(result.stdout())).toEqual({ + args: ["wizard", "nextjs"], + url: "https://sentry.example.com", + }); + }); + + test("drops other old flags and their values, with a notice for each", async () => { + const result = run(bin, [ + "--project", + "my-app", + "--saas", + "--debug", + "--disable-telemetry", + "--promo-code", + "secret-code", + "--skip-connect", + "--quiet", + "--uninstall", + "-p", + "ios", + "android", + "-i", + "nextjs", + ]); + + expect(await result.done).toEqual({ code: 0, signal: null }); + expect(JSON.parse(result.stdout())).toEqual({ + args: ["wizard", "nextjs"], + }); + expect(result.stderr()).toBe( + NOTICE + + [ + "--saas", + "--debug", + "--disable-telemetry", + "--promo-code", + "--skip-connect", + "--quiet", + "--uninstall", + "-p", + ] + .map( + (flag) => + `Ignoring ${flag}: \`sentry wizard\` has no such option.\n`, + ) + .join("") + + "Ignoring --project: it needs --org, so the wizard asks for the project.\n", + ); + }); + + test("passes positionals and --help through", async () => { + const result = run(bin, ["my-org/my-app", "nextjs", "--help"]); + + expect(await result.done).toEqual({ code: 0, signal: null }); + expect(JSON.parse(result.stdout())).toEqual({ + args: ["wizard", "my-org/my-app", "nextjs", "--help"], + }); + }); + + test("exits with the CLI's exit code", async () => { + const result = run(bin, [], "exit:21"); + + expect(await result.done).toEqual({ code: 21, signal: null }); + }); + + test.skipIf(process.platform === "win32")( + "ends with the signal that killed the CLI", + async () => { + const result = run(bin, [], "kill:SIGTERM"); + + expect(await result.done).toEqual({ code: null, signal: "SIGTERM" }); + }, + ); + + test.skipIf(process.platform === "win32")( + "passes SIGTERM on to the CLI", + async () => { + const result = run(bin, [], "wait:7"); + await waitFor(() => result.stdout().includes("ready")); + + result.child.kill("SIGTERM"); + + expect(await result.done).toEqual({ code: 7, signal: null }); + expect(result.stdout()).toContain("SIGTERM\n"); + }, + ); + + test.skipIf(process.platform === "win32")( + "passes a second SIGINT on to the CLI right away", + async () => { + const result = run(bin, [], "wait:130"); + await waitFor(() => result.stdout().includes("ready")); + + // The first one stands for Ctrl-C, which the terminal sends the CLI too. + result.child.kill("SIGINT"); + await new Promise((resolve) => setTimeout(resolve, 200)); + expect(result.stdout()).not.toContain("SIGINT"); + result.child.kill("SIGINT"); + + expect(await result.done).toEqual({ code: 130, signal: null }); + expect(result.stdout()).toContain("SIGINT\n"); + }, + ); + + test.skipIf(process.platform === "win32")( + "passes a lone SIGINT on to the CLI after a wait", + async () => { + const result = run(bin, [], "wait:130"); + await waitFor(() => result.stdout().includes("ready")); + const start = Date.now(); + + result.child.kill("SIGINT"); + + expect(await result.done).toEqual({ code: 130, signal: null }); + expect(result.stdout()).toContain("SIGINT\n"); + expect(Date.now() - start).toBeGreaterThanOrEqual(2900); + }, + 10_000, + ); + + test("fails when the `sentry` package is missing", async () => { + const result = run(install(join(root, "no-sentry"), false), []); + + expect(await result.done).toEqual({ code: 1, signal: null }); + expect(result.stderr()).toBe( + `${NOTICE}Could not find the \`sentry\` package. Run \`npx sentry wizard\` instead.\n`, + ); + }); +}); diff --git a/packages/wizard/tsconfig.json b/packages/wizard/tsconfig.json new file mode 100644 index 000000000..d93805458 --- /dev/null +++ b/packages/wizard/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "target": "ES2022", + "lib": ["ES2023"], + "module": "NodeNext", + "moduleResolution": "NodeNext", + "types": ["node"], + "noEmit": true, + "allowJs": true, + "checkJs": true + }, + // The package ships its bin script as written, with no build step. + "include": ["bin", "test"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b8ff808aa..f3bd7a919 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -393,6 +393,7 @@ overrides: source-map-js: ^1.2.2 undici: ^7.30.1 zod: ^4.6.6 + '@sentry/wizard>sentry': workspace:* packageExtensionsChecksum: sha256-PIoL2jn0sFpFHgcMKW97dNeqBXVNxH6qFIzsWIBFOMY= @@ -1295,6 +1296,22 @@ importers: specifier: 'catalog:' version: 5.0.5(@opentelemetry/api@1.9.1)(@types/node@22.20.3)(@vitest/coverage-v8@5.0.5)(jsdom@28.1.0(supports-color@10.1.0))(msw@2.15.0(@types/node@22.20.3)(typescript@7.0.2))(vite@8.3.8(@types/node@22.20.3)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.1)) + packages/wizard: + dependencies: + sentry: + specifier: workspace:* + version: link:../cli + devDependencies: + '@types/node': + specifier: 'catalog:' + version: 22.20.3 + typescript: + specifier: 'catalog:' + version: 7.0.2 + vitest: + specifier: 'catalog:' + version: 5.0.5(@opentelemetry/api@1.9.1)(@types/node@22.20.3)(@vitest/coverage-v8@5.0.5)(jsdom@28.1.0(supports-color@10.1.0))(msw@2.15.0(@types/node@22.20.3)(typescript@7.0.2))(vite@8.3.8(@types/node@22.20.3)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.13)(yaml@2.9.1)) + packages: '@acemir/cssom@0.9.32': diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 29ddfdf5b..eb2a305ac 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -45,6 +45,10 @@ overrides: undici: ^7.30.1 # GHSA-mrhx-c7xc-m3w5: keep every zod copy at or above the patched release. zod: ^4.6.6 + # @sentry/wizard publishes `sentry: >=0.52.0`, which the CLI's -dev version + # never satisfies, so link the workspace CLI here instead. `pnpm pack` + # ignores overrides, so the tarball keeps the range. + "@sentry/wizard>sentry": "workspace:*" catalog: "@ast-grep/cli": ^0.51.2