Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
949060d
feat(cli): add sentry wizard with Next.js
sentry-junior[bot] Nov 26, 2026
76e162b
feat(cli): add the wizard's shared AST and URL helpers
sentry-junior[bot] Nov 26, 2026
0113841
feat(cli): reject the wizard's removed sign-up flags
sentry-junior[bot] Nov 26, 2026
7e5f894
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] Nov 26, 2026
f230698
feat(cli): add source maps and Cloudflare to sentry wizard
sentry-junior[bot] Nov 26, 2026
da594ec
Merge origin/feat/cli-wizard-shared-ast-helpers into feat/cli-wizard-…
sentry-junior[bot] Nov 26, 2026
94377df
feat(cli): read wizard source map upload target from .sentryclirc
sentry-junior[bot] Nov 26, 2026
0c11351
test(cli): list the Cloudflare wizard fixtures as unchecked TypeScript
sentry-junior[bot] Nov 26, 2026
39e20d5
fix(cli): address review findings in sentry wizard
sentry-junior[bot] Nov 26, 2026
c4786b3
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] Nov 26, 2026
e40669b
feat(cli): write the self-hosted URL to .sentryclirc in the wizard
sentry-junior[bot] Nov 26, 2026
2c98751
refactor(cli): reuse existing CLI helpers in the wizard AST utils
sentry-junior[bot] Nov 26, 2026
ac6b75d
feat(cli): use positionals and existing CLI flags in sentry wizard
sentry-junior[bot] Nov 26, 2026
4c93aa8
fix(cli): use the credential host for the project issues URL
sentry-junior[bot] Nov 26, 2026
2f2f91a
fix(mcp): regenerate the chart app after the for…of conversion
sentry-junior[bot] Nov 26, 2026
f0a48de
Merge remote-tracking branch 'origin/feat/cli-wizard-scaffold' into f…
sentry-junior[bot] Nov 26, 2026
553f2a9
fix(cli): update the source maps and Cloudflare wizards for the new w…
sentry-junior[bot] Nov 27, 2026
e99e91c
fix(cli): don't add a second source map upload when the build script …
sentry-junior[bot] Nov 27, 2026
5b0ee00
fix(cli): use the shared sentry-cli.ts from the Nuxt and Angular wizards
sentry-junior[bot] Nov 27, 2026
5bad502
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-sourc…
sentry-junior[bot] Nov 27, 2026
8506fd0
fix(cli): sync sentry-cli and Angular source map tools with #2525
sentry-junior[bot] Nov 27, 2026
c438f13
fix(cli): fix small bugs in the source maps and Cloudflare wizards
sentry-junior[bot] Nov 27, 2026
347f342
fix(cli): instrument new Cloudflare workers and harden the Wrangler flow
sentry-junior[bot] Nov 27, 2026
0ec23b4
fix(cli): write a JavaScript starter worker to a .js entry point
sentry-junior[bot] Nov 27, 2026
dee0693
fix(cli): add Wrangler deploy flags at the deploy command's position
sentry-junior[bot] Nov 27, 2026
f067cc1
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-sourc…
sentry-junior[bot] Nov 27, 2026
f484df5
Merge branch 'feat/cli-wizard-sourcemaps-cloudflare' into feat/cli-wi…
sentry-junior[bot] Nov 27, 2026
7cf6680
fix(cli): don't add a second SENTRY_RELEASE var on a wizard rerun
sentry-junior[bot] Nov 27, 2026
1191533
fix(cli): keep a Worker's existing compatibility_date
sentry-junior[bot] Nov 27, 2026
ef9384e
fix(cli): don't treat wrangler pages or versions deploy as a Workers …
sentry-junior[bot] Nov 27, 2026
ff1b39d
fix(cli): recognize every form of an existing SENTRY_RELEASE var
sentry-junior[bot] Nov 27, 2026
80debaa
fix(cli): don't take a runner flag's value for the wrangler CLI
sentry-junior[bot] Nov 27, 2026
698999a
fix(cli): look up runner value flags per runner
sentry-junior[bot] Nov 27, 2026
f3053fe
fix(cli): drop the redundant inject step from the sentry:sourcemaps s…
sentry-junior[bot] Nov 27, 2026
03510b3
docs(cli): say the wizard's source map script only runs the upload
sentry-junior[bot] Nov 27, 2026
a17c27a
Merge branch 'feat/cli-wizard-sourcemaps-cloudflare' into feat/cli-wi…
sentry-junior[bot] Nov 27, 2026
d43fdb7
fix(cli): find the runner's value flags after cross-env or FOO=1
sentry-junior[bot] Nov 27, 2026
0d6e736
fix(cli): edit only plain runner-wrapped wrangler deploy commands
sentry-junior[bot] Nov 27, 2026
62880e2
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-sourc…
sentry-junior[bot] Nov 27, 2026
e599ed8
Merge branch 'feat/cli-wizard-sourcemaps-cloudflare' into feat/cli-wi…
sentry-junior[bot] Nov 27, 2026
9984184
fix(cli): treat an empty JSON main as no Wrangler entry point
sentry-junior[bot] Nov 27, 2026
453ef22
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-sourc…
sentry-junior[bot] Nov 27, 2026
1800f33
Merge branch 'feat/cli-wizard-sourcemaps-cloudflare' into feat/cli-wi…
sentry-junior[bot] Nov 27, 2026
9bb011e
fix(cli): install the sentry CLI major the wizard runs on
sentry-junior[bot] Nov 27, 2026
cceeb47
Merge branch 'feat/cli-wizard-sourcemaps-cloudflare' into feat/cli-wi…
sentry-junior[bot] Nov 27, 2026
24ee699
fix(cli): install the running sentry CLI major in the Wrangler flow
sentry-junior[bot] Nov 28, 2026
61f2654
Merge branch 'feat/cli-wizard-sourcemaps-cloudflare' into feat/cli-wi…
sentry-junior[bot] Nov 28, 2026
22efe2d
fix(cli): report a Cloudflare worker wrap only when it happened
sentry-junior[bot] Nov 28, 2026
c13990f
fix(cli): keep the Yarn 2+ upload when the Wrangler deploy script can…
sentry-junior[bot] Nov 28, 2026
1474145
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-sourc…
sentry-junior[bot] Nov 28, 2026
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
5 changes: 4 additions & 1 deletion packages/cli/src/lib/wizard/cloudflare/cloudflare-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ async function runCloudflareWizardWithTelemetry(
binding: "CF_VERSION_METADATA",
},
},
{ removeCompatibilityFlags: ["nodejs_als"] },
{
removeCompatibilityFlags: ["nodejs_als"],
keepCompatibilityDate: true,
},
),
);

Expand Down
87 changes: 37 additions & 50 deletions packages/cli/src/lib/wizard/cloudflare/sdk-setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Write the Sentry initialization into the worker entry point: wrap an
* existing handler, or create an entry point when the Wrangler config names
* none.
* Write the Sentry initialization into the worker entry point: wrap the
* existing handler, or create a starter worker and wrap that.
*/

import chalk from "chalk";
Expand All @@ -21,8 +20,10 @@ import {
import { wrapWorkerWithSentry } from "./wrap-worker.js";

/**
* Creates or updates the main worker file with Sentry initialization.
* Currently focused on Cloudflare Workers
* Wraps the worker entry point with Sentry initialization. When the entry
* point the Wrangler config names, or the default one, doesn't exist yet, it
* creates a starter worker there first, so every path ends with a wrapped
* worker.
*/
export async function createSentryInitFile(
dsn: string,
Expand All @@ -31,65 +32,51 @@ export async function createSentryInitFile(
},
reduceDataCollection: boolean,
): Promise<void> {
const entryPointFromConfig = getEntryPointFromWranglerConfig();
const entryPoint = getEntryPointFromWranglerConfig() ?? defaultEntryPoint;
const entryPointPath = path.join(process.cwd(), entryPoint);
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

if (!entryPointFromConfig) {
if (existsSync(entryPointPath)) {
clack.log.info(`Found existing entry point: ${chalk.cyan(entryPoint)}`);
} else {
clack.log.info(
"No entry point found in wrangler config, creating a new one.",
`No worker found at ${chalk.cyan(entryPoint)}, creating a new one.`,
);

const cloudflareWorkerTemplate = getCloudflareWorkerTemplateWithHandler();

await promises.mkdir(
path.join(process.cwd(), path.dirname(defaultEntryPoint)),
{
recursive: true,
},
);
await promises.mkdir(path.dirname(entryPointPath), { recursive: true });
await promises.writeFile(
path.join(process.cwd(), defaultEntryPoint),
cloudflareWorkerTemplate,
entryPointPath,
getCloudflareWorkerTemplateWithHandler(/\.[cm]?tsx?$/.test(entryPoint)),
{ encoding: "utf-8", flag: "w" },
);

clack.log.success(`Created ${chalk.cyan(defaultEntryPoint)}.`);

return;
clack.log.success(`Created ${chalk.cyan(entryPoint)}.`);
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}

const entryPointPath = path.join(process.cwd(), entryPointFromConfig);

if (existsSync(entryPointPath)) {
clack.log.info(
`Found existing entry point: ${chalk.cyan(entryPointFromConfig)}`,
try {
const wrapped = await wrapWorkerWithSentry(
entryPointPath,
dsn,
selectedFeatures,
reduceDataCollection,
);

try {
await wrapWorkerWithSentry(
entryPointPath,
dsn,
selectedFeatures,
reduceDataCollection,
);
if (wrapped) {
clack.log.success(
`Wrapped ${chalk.cyan(
entryPointFromConfig,
)} with Sentry initialization.`,
`Wrapped ${chalk.cyan(entryPoint)} with Sentry initialization.`,
);
} catch (error) {
debug(error);
clack.log.warn("Failed to wrap worker automatically.");
clack.log.step("Please wrap your handler with Sentry initialization:");
}
} catch (error) {
debug(error);
clack.log.warn("Failed to wrap worker automatically.");
clack.log.step("Please wrap your handler with Sentry initialization:");

clack.note(
chalk.cyan(
getCloudflareWorkerTemplate(
dsn,
selectedFeatures,
reduceDataCollection,
),
clack.note(
chalk.cyan(
getCloudflareWorkerTemplate(
dsn,
selectedFeatures,
reduceDataCollection,
),
);
}
),
);
}
}
12 changes: 9 additions & 3 deletions packages/cli/src/lib/wizard/cloudflare/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ export default Sentry.withSentry(
`;
}

export function getCloudflareWorkerTemplateWithHandler(): string {
/**
* A starter worker. With `typescript` unset, it leaves out the type
* annotations, for a `.js` or `.mjs` entry point.
*/
export function getCloudflareWorkerTemplateWithHandler(
typescript: boolean,
): string {
return `export default {
async fetch(request, env, ctx): Promise<Response> {
async fetch(request, env, ctx)${typescript ? ": Promise<Response>" : ""} {
const url = new URL(request.url);
switch (url.pathname) {
case '/message':
Expand All @@ -52,6 +58,6 @@ export function getCloudflareWorkerTemplateWithHandler(): string {
return new Response('Not Found', { status: 404 });
}
},
} satisfies ExportedHandler<Env>;
}${typescript ? " satisfies ExportedHandler<Env>" : ""};
`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export function getEntryPointFromWranglerConfig(): string | undefined {
mainProperty?.value.type === "Literal") &&
typeof mainProperty.value.value === "string"
) {
return mainProperty.value.value;
// An empty `main` names no file, as in the TOML branch.
return mainProperty.value.value || undefined;
}

return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { findWranglerConfig } from "./find-wrangler-config.js";
const b = recast.types.builders;

type WranglerConfigUpdates = {
main?: string;
compatibility_date?: string;
compatibility_flags?: string[];
version_metadata?: {
Expand All @@ -39,10 +40,19 @@ type WranglerConfigUpdateOptions = {
* e.g. flags superseded by one of the flags being added.
*/
removeCompatibilityFlags?: string[] | undefined;
/**
* Set `compatibility_date` only when the config doesn't have one yet: the
* date pins the Worker's runtime behaviour.
*/
keepCompatibilityDate?: boolean | undefined;
};

const getTomlConfigSnippet = (options: WranglerConfigUpdateOptions) => {
const getTomlConfigSnippet = (
updates: WranglerConfigUpdates,
options: WranglerConfigUpdateOptions,
) => {
const superseded = options.removeCompatibilityFlags ?? [];
const { main } = updates;

return makeCodeSnippet(true, (_unchanged, plus) =>
plus(
Expand All @@ -52,8 +62,10 @@ const getTomlConfigSnippet = (options: WranglerConfigUpdateOptions) => {
.map((flag) => `"${flag}"`)
.join(", ")} from compatibility_flags if present\n`
: ""
}compatibility_flags = ["nodejs_compat"]
compatibility_date = "${new Date().toISOString().slice(0, 10)}"
}${main ? `main = "${main}"\n` : ""}compatibility_flags = ["nodejs_compat"]
compatibility_date = "${new Date().toISOString().slice(0, 10)}"${
options.keepCompatibilityDate ? " # only if not set yet" : ""
}

[version_metadata]
binding = "CF_VERSION_METADATA"`,
Expand Down Expand Up @@ -98,7 +110,7 @@ export async function updateWranglerConfig(
case ".toml":
await showCopyPasteInstructions({
filename: configFile,
codeSnippet: getTomlConfigSnippet(options),
codeSnippet: getTomlConfigSnippet(updates, options),
});
break;
}
Expand Down Expand Up @@ -208,7 +220,13 @@ function updateJsoncObject(
options: WranglerConfigUpdateOptions = {},
): void {
for (const [key, value] of Object.entries(updates)) {
if (value === null || value === undefined) {
if (
value === null ||
value === undefined ||
(key === "compatibility_date" &&
options.keepCompatibilityDate &&
getObjectProperty(jsonObject, key))
) {
continue;
}

Expand Down
12 changes: 10 additions & 2 deletions packages/cli/src/lib/wizard/cloudflare/wrap-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const b = recast.types.builders;
* @param dsn - Sentry DSN for initialization
* @param selectedFeatures - Feature flags for optional Sentry features
* @param reduceDataCollection - Whether to add the PII-reducing `dataCollection` preset
* @returns Whether it wrapped the export: false when Sentry is already set up
* @throws When the file has no default export to wrap, leaving it unchanged
*/
export async function wrapWorkerWithSentry(
workerFilePath: string,
Expand All @@ -54,7 +56,7 @@ export async function wrapWorkerWithSentry(
performance: boolean;
},
reduceDataCollection: boolean,
): Promise<void> {
): Promise<boolean> {
const workerAst = await loadFile(workerFilePath);

if (hasSentryContent(workerAst.$ast as t.Program)) {
Expand All @@ -63,7 +65,12 @@ export async function wrapWorkerWithSentry(
workerFilePath,
)}. Skipping wrapping with Sentry.`,
);
return;
return false;
}

const program = workerAst.$ast as t.Program;
if (!program.body.some((node) => node.type === "ExportDefaultDeclaration")) {
throw new Error(`No default export to wrap in ${workerFilePath}`);
}

workerAst.imports.$add({
Expand Down Expand Up @@ -92,6 +99,7 @@ export async function wrapWorkerWithSentry(
});

await writeFile(workerAst.$ast, workerFilePath);
return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/wizard/sourcemaps/ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function configureCI(
return;
}

// Wrangler's `post<deploy>` script already runs `sentry:sourcemaps`
// The Wrangler deploy script already runs `sentry:sourcemaps` afterwards
if (isCliBasedFlowTool && selectedTool !== "wrangler") {
await traceStep("ci-npm-script-setup", setupNpmScriptInCI);
}
Expand Down
24 changes: 21 additions & 3 deletions packages/cli/src/lib/wizard/sourcemaps/tools/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import type { namedTypes as t } from "ast-types";
import type { ExpressionKind } from "ast-types/lib/gen/kinds.js";
import chalk from "chalk";
import { promises } from "node:fs";
import path from "node:path";
Expand Down Expand Up @@ -255,10 +256,18 @@ function addSentryWebpackPlugin(
);

if (pluginsProp) {
if (pluginsProp.value.type === "ArrayExpression") {
pluginsProp.value.elements.push(sentryPluginCall);
} else {
const plugins = pluginsProp.value;
if (plugins.type === "ArrayExpression") {
plugins.elements.push(sentryPluginCall);
} else if (isNullish(plugins)) {
pluginsProp.value = b.arrayExpression([sentryPluginCall]);
} else {
// A variable or call such as `getPlugins()`: keep its plugins and add
// Sentry after them.
pluginsProp.value = b.arrayExpression([
b.spreadElement(plugins as ExpressionKind),
sentryPluginCall,
]);
}
return true;
}
Expand All @@ -273,6 +282,15 @@ function addSentryWebpackPlugin(
return true;
}

/** `undefined` or `null`, which leaves no plugins to keep. */
function isNullish(node: t.Property["value"]): boolean {
return (
(node.type === "Identifier" && node.name === "undefined") ||
node.type === "NullLiteral" ||
(node.type === "Literal" && node.value === null)
);
}

function addSentryWebpackPluginImport(program: t.Program, importPath: string) {
const b = recast.types.builders;

Expand Down
Loading
Loading