@sentry/wizard 6.11.0 → 6.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/dist/e2e-tests/tests/cloudflare-worker.test.js +5 -0
- package/dist/e2e-tests/tests/cloudflare-worker.test.js.map +1 -1
- package/dist/e2e-tests/tests/pnpm-workspace.test.js +2 -1
- package/dist/e2e-tests/tests/pnpm-workspace.test.js.map +1 -1
- package/dist/e2e-tests/tests/react-router-instrumentation-api.test.d.ts +1 -0
- package/dist/e2e-tests/tests/react-router-instrumentation-api.test.js +96 -0
- package/dist/e2e-tests/tests/react-router-instrumentation-api.test.js.map +1 -0
- package/dist/e2e-tests/tests/react-router.test.js +3 -1
- package/dist/e2e-tests/tests/react-router.test.js.map +1 -1
- package/dist/e2e-tests/tests/sveltekit-tracing.test.js +2 -1
- package/dist/e2e-tests/tests/sveltekit-tracing.test.js.map +1 -1
- package/dist/src/apple/code-tools.js +17 -3
- package/dist/src/apple/code-tools.js.map +1 -1
- package/dist/src/apple/configure-package-manager.js +18 -5
- package/dist/src/apple/configure-package-manager.js.map +1 -1
- package/dist/src/cloudflare/cloudflare-wizard.js +5 -0
- package/dist/src/cloudflare/cloudflare-wizard.js.map +1 -1
- package/dist/src/cloudflare/sdk-setup.d.ts +1 -0
- package/dist/src/cloudflare/sdk-setup.js.map +1 -1
- package/dist/src/cloudflare/templates.d.ts +1 -0
- package/dist/src/cloudflare/templates.js +7 -1
- package/dist/src/cloudflare/templates.js.map +1 -1
- package/dist/src/cloudflare/wrap-worker.d.ts +1 -0
- package/dist/src/cloudflare/wrap-worker.js +7 -0
- package/dist/src/cloudflare/wrap-worker.js.map +1 -1
- package/dist/src/react-native/expo.d.ts +6 -0
- package/dist/src/react-native/expo.js +27 -1
- package/dist/src/react-native/expo.js.map +1 -1
- package/dist/src/react-native/git.d.ts +5 -0
- package/dist/src/react-native/git.js +32 -1
- package/dist/src/react-native/git.js.map +1 -1
- package/dist/src/react-native/javascript.js +3 -1
- package/dist/src/react-native/javascript.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.js +12 -6
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/react-router/codemods/client.entry.d.ts +1 -1
- package/dist/src/react-router/codemods/client.entry.js +69 -12
- package/dist/src/react-router/codemods/client.entry.js.map +1 -1
- package/dist/src/react-router/codemods/react-router-config.js +1 -1
- package/dist/src/react-router/codemods/react-router-config.js.map +1 -1
- package/dist/src/react-router/codemods/root.js +1 -2
- package/dist/src/react-router/codemods/root.js.map +1 -1
- package/dist/src/react-router/codemods/server-entry.d.ts +1 -1
- package/dist/src/react-router/codemods/server-entry.js +39 -4
- package/dist/src/react-router/codemods/server-entry.js.map +1 -1
- package/dist/src/react-router/codemods/vite.js +46 -1
- package/dist/src/react-router/codemods/vite.js.map +1 -1
- package/dist/src/react-router/react-router-wizard.js +52 -5
- package/dist/src/react-router/react-router-wizard.js.map +1 -1
- package/dist/src/react-router/sdk-setup.d.ts +4 -2
- package/dist/src/react-router/sdk-setup.js +32 -5
- package/dist/src/react-router/sdk-setup.js.map +1 -1
- package/dist/src/react-router/templates.d.ts +2 -2
- package/dist/src/react-router/templates.js +72 -2
- package/dist/src/react-router/templates.js.map +1 -1
- package/dist/src/sourcemaps/tools/vite.js +1 -1
- package/dist/src/sourcemaps/tools/vite.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup/vite.js +1 -1
- package/dist/src/sveltekit/sdk-setup/vite.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +10 -0
- package/dist/src/utils/ast-utils.js +19 -1
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/test/apple/code-tools.test.js +78 -0
- package/dist/test/apple/code-tools.test.js.map +1 -1
- package/dist/test/apple/configure-package-manager.test.d.ts +1 -0
- package/dist/test/apple/configure-package-manager.test.js +161 -0
- package/dist/test/apple/configure-package-manager.test.js.map +1 -0
- package/dist/test/cloudflare/sdk-setup.test.js +20 -2
- package/dist/test/cloudflare/sdk-setup.test.js.map +1 -1
- package/dist/test/cloudflare/templates.test.js +54 -0
- package/dist/test/cloudflare/templates.test.js.map +1 -1
- package/dist/test/cloudflare/wrap-worker.test.js +74 -11
- package/dist/test/cloudflare/wrap-worker.test.js.map +1 -1
- package/dist/test/react-native/expo.test.js +140 -0
- package/dist/test/react-native/expo.test.js.map +1 -1
- package/dist/test/react-native/git.test.d.ts +1 -0
- package/dist/test/react-native/git.test.js +160 -0
- package/dist/test/react-native/git.test.js.map +1 -0
- package/dist/test/react-router/codemods/client-entry.test.js +29 -0
- package/dist/test/react-router/codemods/client-entry.test.js.map +1 -1
- package/dist/test/react-router/codemods/root.test.js +4 -0
- package/dist/test/react-router/codemods/root.test.js.map +1 -1
- package/dist/test/react-router/codemods/server-entry.test.js +70 -0
- package/dist/test/react-router/codemods/server-entry.test.js.map +1 -1
- package/dist/test/react-router/codemods/vite.test.js +89 -0
- package/dist/test/react-router/codemods/vite.test.js.map +1 -1
- package/dist/test/react-router/sdk-setup.test.js +62 -6
- package/dist/test/react-router/sdk-setup.test.js.map +1 -1
- package/dist/test/react-router/templates.test.js +50 -0
- package/dist/test/react-router/templates.test.js.map +1 -1
- package/dist/test/sourcemaps/tools/vite.test.js +12 -8
- package/dist/test/sourcemaps/tools/vite.test.js.map +1 -1
- package/dist/test/utils/ast-utils.test.js +22 -0
- package/dist/test/utils/ast-utils.test.js.map +1 -1
- package/package.json +2 -2
|
@@ -36,6 +36,7 @@ const magicast_1 = require("magicast");
|
|
|
36
36
|
const prompts_1 = __importDefault(require("@clack/prompts"));
|
|
37
37
|
const chalk_1 = __importDefault(require("chalk"));
|
|
38
38
|
const ast_utils_1 = require("../../utils/ast-utils");
|
|
39
|
+
const debug_1 = require("../../utils/debug");
|
|
39
40
|
/**
|
|
40
41
|
* Extracts ObjectExpression from function body.
|
|
41
42
|
* Handles both arrow functions with object returns and block statements with explicit returns.
|
|
@@ -85,6 +86,48 @@ function createSentryPluginCall(orgSlug, projectSlug) {
|
|
|
85
86
|
b.identifier('config'),
|
|
86
87
|
]);
|
|
87
88
|
}
|
|
89
|
+
/** Adds @sentry/react-router to optimizeDeps.exclude to prevent 504 errors during dev. */
|
|
90
|
+
function addOptimizeDepsExclude(configObj) {
|
|
91
|
+
const b = recast.types.builders;
|
|
92
|
+
const optimizeDeps = (0, ast_utils_1.findProperty)(configObj, 'optimizeDeps');
|
|
93
|
+
const optimizeDepsObj = optimizeDeps?.type === 'ObjectProperty' &&
|
|
94
|
+
optimizeDeps.value?.type === 'ObjectExpression'
|
|
95
|
+
? optimizeDeps.value
|
|
96
|
+
: null;
|
|
97
|
+
let targetDepsObj;
|
|
98
|
+
if (!optimizeDepsObj) {
|
|
99
|
+
if (optimizeDeps) {
|
|
100
|
+
(0, debug_1.debug)('optimizeDeps is not a static object, skipping exclude');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
targetDepsObj = b.objectExpression([]);
|
|
104
|
+
configObj.properties.push(b.objectProperty(b.identifier('optimizeDeps'), targetDepsObj));
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
targetDepsObj = optimizeDepsObj;
|
|
108
|
+
}
|
|
109
|
+
const excludeProp = (0, ast_utils_1.findProperty)(targetDepsObj, 'exclude');
|
|
110
|
+
const excludeArr = excludeProp?.type === 'ObjectProperty' &&
|
|
111
|
+
excludeProp.value?.type === 'ArrayExpression'
|
|
112
|
+
? excludeProp.value
|
|
113
|
+
: null;
|
|
114
|
+
let targetArr;
|
|
115
|
+
if (!excludeArr) {
|
|
116
|
+
if (excludeProp) {
|
|
117
|
+
(0, debug_1.debug)('optimizeDeps.exclude is not a static array, skipping');
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
targetArr = b.arrayExpression([]);
|
|
121
|
+
targetDepsObj.properties.push(b.objectProperty(b.identifier('exclude'), targetArr));
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
targetArr = excludeArr;
|
|
125
|
+
}
|
|
126
|
+
const isAlreadyExcluded = targetArr.elements.some((el) => el?.type === 'StringLiteral' && el.value === '@sentry/react-router');
|
|
127
|
+
if (!isAlreadyExcluded) {
|
|
128
|
+
targetArr.elements.push(b.stringLiteral('@sentry/react-router'));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
88
131
|
function addReactRouterPluginToViteConfig(program, orgSlug, projectSlug) {
|
|
89
132
|
const b = recast.types.builders;
|
|
90
133
|
let wasConverted = false;
|
|
@@ -135,6 +178,8 @@ function addReactRouterPluginToViteConfig(program, orgSlug, projectSlug) {
|
|
|
135
178
|
else {
|
|
136
179
|
return { success: false, wasConverted };
|
|
137
180
|
}
|
|
181
|
+
// Prevent 504 "Outdated Optimize Dep" errors in dev (https://github.com/vitejs/vite/issues/13506)
|
|
182
|
+
addOptimizeDepsExclude(configObj);
|
|
138
183
|
return { success: true, wasConverted };
|
|
139
184
|
}
|
|
140
185
|
exports.addReactRouterPluginToViteConfig = addReactRouterPluginToViteConfig;
|
|
@@ -161,7 +206,7 @@ async function instrumentViteConfig(orgSlug, projectSlug) {
|
|
|
161
206
|
if (!success) {
|
|
162
207
|
throw new Error('Failed to modify Vite config structure');
|
|
163
208
|
}
|
|
164
|
-
const code = (0, magicast_1.generateCode)(mod.$ast).code;
|
|
209
|
+
const code = (0, ast_utils_1.preserveTrailingNewline)(configContent, (0, magicast_1.generateCode)(mod.$ast).code);
|
|
165
210
|
await fs.promises.writeFile(configPath, code);
|
|
166
211
|
return { wasConverted };
|
|
167
212
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../../../src/react-router/codemods/vite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AACjC,2CAA6B;AAC7B,uCAAyB;AAEzB,kFAAkF;AAClF,uCAAqD;AAErD,+EA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,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IAED,MAAM,IAAI,GAAG,IAAA,uBAAY,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;IACzC,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAE9C,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC;AA1CD,oDA0CC","sourcesContent":["import type { namedTypes as t } from 'ast-types';\nimport * as recast from 'recast';\nimport * as path from 'path';\nimport * as fs from 'fs';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { parseModule, generateCode } from 'magicast';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport { hasSentryContent, findProperty } from '../../utils/ast-utils';\n\n/**\n * Extracts ObjectExpression from function body.\n * Handles both arrow functions with object returns and block statements with explicit returns.\n *\n * - Arrow with object-return: (config) => ({ ... })\n * - Arrow with block: (config) => { return { ... }; }\n * - Function with block: function(config) { return { ... }; }\n *\n * @param body - The function body to extract from\n * @returns The ObjectExpression if found, undefined otherwise\n */\nfunction extractFromFunctionBody(\n body: t.Expression | t.BlockStatement,\n): t.ObjectExpression | undefined {\n if (body.type === 'ObjectExpression') {\n return body as t.ObjectExpression;\n }\n\n if (body.type === 'BlockStatement') {\n const blockBody = body as t.BlockStatement;\n const returnStatement = blockBody.body.find(\n (stmt: t.Statement): stmt is t.ReturnStatement =>\n stmt.type === 'ReturnStatement',\n );\n\n return returnStatement?.argument?.type === 'ObjectExpression'\n ? returnStatement.argument\n : undefined;\n }\n\n return undefined;\n}\n\n/**\n * Creates the sentryReactRouter Vite plugin call expression.\n *\n * Generates AST for:\n * sentryReactRouter({\n * org: \"...\",\n * project: \"...\",\n * authToken: process.env.SENTRY_AUTH_TOKEN\n * }, config)\n *\n * @param orgSlug - Sentry organization slug\n * @param projectSlug - Sentry project slug\n * @returns CallExpression node for the Sentry Vite plugin\n */\nfunction createSentryPluginCall(\n orgSlug: string,\n projectSlug: string,\n): t.CallExpression {\n const b = recast.types.builders;\n return b.callExpression(b.identifier('sentryReactRouter'), [\n b.objectExpression([\n b.objectProperty(b.identifier('org'), b.stringLiteral(orgSlug)),\n b.objectProperty(b.identifier('project'), b.stringLiteral(projectSlug)),\n b.objectProperty(\n b.identifier('authToken'),\n b.memberExpression(\n b.memberExpression(b.identifier('process'), b.identifier('env')),\n b.identifier('SENTRY_AUTH_TOKEN'),\n ),\n ),\n ]),\n b.identifier('config'),\n ]);\n}\n\nexport function addReactRouterPluginToViteConfig(\n program: t.Program,\n orgSlug: string,\n projectSlug: string,\n): { success: boolean; wasConverted: boolean } {\n const b = recast.types.builders;\n let wasConverted = false;\n\n const defaultExport = program.body.find(\n (node) => node.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration | undefined;\n\n if (!defaultExport) {\n return { success: false, wasConverted: false };\n }\n\n let configObj: t.ObjectExpression | undefined;\n let defineConfigCall: t.CallExpression | undefined;\n\n if (\n defaultExport.declaration.type === 'CallExpression' &&\n defaultExport.declaration.callee.type === 'Identifier' &&\n defaultExport.declaration.callee.name === 'defineConfig'\n ) {\n defineConfigCall = defaultExport.declaration;\n\n // Early exit if not single argument\n if (defineConfigCall.arguments.length !== 1) {\n return { success: false, wasConverted: false };\n }\n\n const arg = defineConfigCall.arguments[0];\n\n if (arg.type === 'ObjectExpression') {\n configObj = arg;\n // Convert to function form\n const arrowFunction = b.arrowFunctionExpression(\n [b.identifier('config')],\n configObj,\n );\n defineConfigCall.arguments[0] = arrowFunction;\n wasConverted = true;\n } else if (\n arg.type === 'ArrowFunctionExpression' ||\n arg.type === 'FunctionExpression'\n ) {\n configObj = extractFromFunctionBody(arg.body);\n }\n }\n\n if (!configObj) {\n return { success: false, wasConverted };\n }\n\n const pluginsProp = findProperty(configObj, 'plugins');\n const sentryPluginCall = createSentryPluginCall(orgSlug, projectSlug);\n\n if (!pluginsProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('plugins'),\n b.arrayExpression([sentryPluginCall]),\n ),\n );\n } else if (\n pluginsProp.value.type === 'ArrayExpression' &&\n pluginsProp.type === 'ObjectProperty'\n ) {\n const arrayExpr = pluginsProp.value;\n // Defensive: ensure elements array exists\n if (!arrayExpr.elements) {\n arrayExpr.elements = [];\n }\n arrayExpr.elements.push(sentryPluginCall);\n } else {\n return { success: false, wasConverted };\n }\n\n return { success: true, wasConverted };\n}\n\nexport async function instrumentViteConfig(\n orgSlug: string,\n projectSlug: string,\n): Promise<{ wasConverted: boolean }> {\n const configPath = fs.existsSync(path.join(process.cwd(), 'vite.config.ts'))\n ? path.join(process.cwd(), 'vite.config.ts')\n : path.join(process.cwd(), 'vite.config.js');\n\n if (!fs.existsSync(configPath)) {\n throw new Error('Could not find vite.config.ts or vite.config.js');\n }\n\n const configContent = await fs.promises.readFile(configPath, 'utf-8');\n const filename = chalk.cyan(path.basename(configPath));\n\n const mod = parseModule(configContent);\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n clack.log.info(`${filename} already contains sentryReactRouter plugin.`);\n return { wasConverted: false };\n }\n\n mod.imports.$add({\n from: '@sentry/react-router',\n imported: 'sentryReactRouter',\n local: 'sentryReactRouter',\n });\n\n const { success, wasConverted } = addReactRouterPluginToViteConfig(\n mod.$ast as t.Program,\n orgSlug,\n projectSlug,\n );\n\n if (!success) {\n throw new Error('Failed to modify Vite config structure');\n }\n\n const code = generateCode(mod.$ast).code;\n await fs.promises.writeFile(configPath, code);\n\n return { wasConverted };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../../../src/react-router/codemods/vite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AACjC,2CAA6B;AAC7B,uCAAyB;AAEzB,kFAAkF;AAClF,uCAAqD;AAErD,+EAA+E;AAC/E,6DAAmC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BAAW,EAAC,aAAa,CAAC,CAAC;IAEvC,IAAI,IAAA,4BAAgB,EAAC,GAAG,CAAC,IAAiB,CAAC,EAAE;QAC3C,iBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,QAAQ,6CAA6C,CAAC,CAAC;QACzE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;KAChC;IAED,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;QACf,IAAI,EAAE,sBAAsB;QAC5B,QAAQ,EAAE,mBAAmB;QAC7B,KAAK,EAAE,mBAAmB;KAC3B,CAAC,CAAC;IAEH,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,gCAAgC,CAChE,GAAG,CAAC,IAAiB,EACrB,OAAO,EACP,WAAW,CACZ,CAAC;IAEF,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IAED,MAAM,IAAI,GAAG,IAAA,mCAAuB,EAClC,aAAa,EACb,IAAA,uBAAY,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAC5B,CAAC;IACF,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAE9C,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC;AA7CD,oDA6CC","sourcesContent":["import type { namedTypes as t } from 'ast-types';\nimport * as recast from 'recast';\nimport * as path from 'path';\nimport * as fs from 'fs';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { parseModule, generateCode } from 'magicast';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport {\n hasSentryContent,\n findProperty,\n preserveTrailingNewline,\n} from '../../utils/ast-utils';\nimport { debug } from '../../utils/debug';\n\n/**\n * Extracts ObjectExpression from function body.\n * Handles both arrow functions with object returns and block statements with explicit returns.\n *\n * - Arrow with object-return: (config) => ({ ... })\n * - Arrow with block: (config) => { return { ... }; }\n * - Function with block: function(config) { return { ... }; }\n *\n * @param body - The function body to extract from\n * @returns The ObjectExpression if found, undefined otherwise\n */\nfunction extractFromFunctionBody(\n body: t.Expression | t.BlockStatement,\n): t.ObjectExpression | undefined {\n if (body.type === 'ObjectExpression') {\n return body as t.ObjectExpression;\n }\n\n if (body.type === 'BlockStatement') {\n const blockBody = body as t.BlockStatement;\n const returnStatement = blockBody.body.find(\n (stmt: t.Statement): stmt is t.ReturnStatement =>\n stmt.type === 'ReturnStatement',\n );\n\n return returnStatement?.argument?.type === 'ObjectExpression'\n ? returnStatement.argument\n : undefined;\n }\n\n return undefined;\n}\n\n/**\n * Creates the sentryReactRouter Vite plugin call expression.\n *\n * Generates AST for:\n * sentryReactRouter({\n * org: \"...\",\n * project: \"...\",\n * authToken: process.env.SENTRY_AUTH_TOKEN\n * }, config)\n *\n * @param orgSlug - Sentry organization slug\n * @param projectSlug - Sentry project slug\n * @returns CallExpression node for the Sentry Vite plugin\n */\nfunction createSentryPluginCall(\n orgSlug: string,\n projectSlug: string,\n): t.CallExpression {\n const b = recast.types.builders;\n return b.callExpression(b.identifier('sentryReactRouter'), [\n b.objectExpression([\n b.objectProperty(b.identifier('org'), b.stringLiteral(orgSlug)),\n b.objectProperty(b.identifier('project'), b.stringLiteral(projectSlug)),\n b.objectProperty(\n b.identifier('authToken'),\n b.memberExpression(\n b.memberExpression(b.identifier('process'), b.identifier('env')),\n b.identifier('SENTRY_AUTH_TOKEN'),\n ),\n ),\n ]),\n b.identifier('config'),\n ]);\n}\n\n/** Adds @sentry/react-router to optimizeDeps.exclude to prevent 504 errors during dev. */\nfunction addOptimizeDepsExclude(configObj: t.ObjectExpression): void {\n const b = recast.types.builders;\n\n const optimizeDeps = findProperty(configObj, 'optimizeDeps');\n const optimizeDepsObj =\n optimizeDeps?.type === 'ObjectProperty' &&\n optimizeDeps.value?.type === 'ObjectExpression'\n ? optimizeDeps.value\n : null;\n\n let targetDepsObj: t.ObjectExpression;\n if (!optimizeDepsObj) {\n if (optimizeDeps) {\n debug('optimizeDeps is not a static object, skipping exclude');\n return;\n }\n targetDepsObj = b.objectExpression([]);\n configObj.properties.push(\n b.objectProperty(b.identifier('optimizeDeps'), targetDepsObj),\n );\n } else {\n targetDepsObj = optimizeDepsObj;\n }\n\n const excludeProp = findProperty(targetDepsObj, 'exclude');\n const excludeArr =\n excludeProp?.type === 'ObjectProperty' &&\n excludeProp.value?.type === 'ArrayExpression'\n ? excludeProp.value\n : null;\n\n let targetArr: t.ArrayExpression;\n if (!excludeArr) {\n if (excludeProp) {\n debug('optimizeDeps.exclude is not a static array, skipping');\n return;\n }\n targetArr = b.arrayExpression([]);\n targetDepsObj.properties.push(\n b.objectProperty(b.identifier('exclude'), targetArr),\n );\n } else {\n targetArr = excludeArr;\n }\n\n const isAlreadyExcluded = targetArr.elements.some(\n (el) => el?.type === 'StringLiteral' && el.value === '@sentry/react-router',\n );\n if (!isAlreadyExcluded) {\n targetArr.elements.push(b.stringLiteral('@sentry/react-router'));\n }\n}\n\nexport function addReactRouterPluginToViteConfig(\n program: t.Program,\n orgSlug: string,\n projectSlug: string,\n): { success: boolean; wasConverted: boolean } {\n const b = recast.types.builders;\n let wasConverted = false;\n\n const defaultExport = program.body.find(\n (node) => node.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration | undefined;\n\n if (!defaultExport) {\n return { success: false, wasConverted: false };\n }\n\n let configObj: t.ObjectExpression | undefined;\n let defineConfigCall: t.CallExpression | undefined;\n\n if (\n defaultExport.declaration.type === 'CallExpression' &&\n defaultExport.declaration.callee.type === 'Identifier' &&\n defaultExport.declaration.callee.name === 'defineConfig'\n ) {\n defineConfigCall = defaultExport.declaration;\n\n // Early exit if not single argument\n if (defineConfigCall.arguments.length !== 1) {\n return { success: false, wasConverted: false };\n }\n\n const arg = defineConfigCall.arguments[0];\n\n if (arg.type === 'ObjectExpression') {\n configObj = arg;\n // Convert to function form\n const arrowFunction = b.arrowFunctionExpression(\n [b.identifier('config')],\n configObj,\n );\n defineConfigCall.arguments[0] = arrowFunction;\n wasConverted = true;\n } else if (\n arg.type === 'ArrowFunctionExpression' ||\n arg.type === 'FunctionExpression'\n ) {\n configObj = extractFromFunctionBody(arg.body);\n }\n }\n\n if (!configObj) {\n return { success: false, wasConverted };\n }\n\n const pluginsProp = findProperty(configObj, 'plugins');\n const sentryPluginCall = createSentryPluginCall(orgSlug, projectSlug);\n\n if (!pluginsProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('plugins'),\n b.arrayExpression([sentryPluginCall]),\n ),\n );\n } else if (\n pluginsProp.value.type === 'ArrayExpression' &&\n pluginsProp.type === 'ObjectProperty'\n ) {\n const arrayExpr = pluginsProp.value;\n // Defensive: ensure elements array exists\n if (!arrayExpr.elements) {\n arrayExpr.elements = [];\n }\n arrayExpr.elements.push(sentryPluginCall);\n } else {\n return { success: false, wasConverted };\n }\n\n // Prevent 504 \"Outdated Optimize Dep\" errors in dev (https://github.com/vitejs/vite/issues/13506)\n addOptimizeDepsExclude(configObj);\n\n return { success: true, wasConverted };\n}\n\nexport async function instrumentViteConfig(\n orgSlug: string,\n projectSlug: string,\n): Promise<{ wasConverted: boolean }> {\n const configPath = fs.existsSync(path.join(process.cwd(), 'vite.config.ts'))\n ? path.join(process.cwd(), 'vite.config.ts')\n : path.join(process.cwd(), 'vite.config.js');\n\n if (!fs.existsSync(configPath)) {\n throw new Error('Could not find vite.config.ts or vite.config.js');\n }\n\n const configContent = await fs.promises.readFile(configPath, 'utf-8');\n const filename = chalk.cyan(path.basename(configPath));\n\n const mod = parseModule(configContent);\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n clack.log.info(`${filename} already contains sentryReactRouter plugin.`);\n return { wasConverted: false };\n }\n\n mod.imports.$add({\n from: '@sentry/react-router',\n imported: 'sentryReactRouter',\n local: 'sentryReactRouter',\n });\n\n const { success, wasConverted } = addReactRouterPluginToViteConfig(\n mod.$ast as t.Program,\n orgSlug,\n projectSlug,\n );\n\n if (!success) {\n throw new Error('Failed to modify Vite config structure');\n }\n\n const code = preserveTrailingNewline(\n configContent,\n generateCode(mod.$ast).code,\n );\n await fs.promises.writeFile(configPath, code);\n\n return { wasConverted };\n}\n"]}
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -7,6 +30,7 @@ exports.runReactRouterWizard = void 0;
|
|
|
7
30
|
// @ts-expect-error - clack is ESM and TS complains about that. It works though
|
|
8
31
|
const prompts_1 = __importDefault(require("@clack/prompts"));
|
|
9
32
|
const chalk_1 = __importDefault(require("chalk"));
|
|
33
|
+
const Sentry = __importStar(require("@sentry/node"));
|
|
10
34
|
const telemetry_1 = require("../telemetry");
|
|
11
35
|
const clack_1 = require("../utils/clack");
|
|
12
36
|
const mcp_config_1 = require("../utils/clack/mcp-config");
|
|
@@ -75,6 +99,18 @@ async function runReactRouterWizardWithTelemetry(options) {
|
|
|
75
99
|
enabledHint: 'recommended for production debugging',
|
|
76
100
|
},
|
|
77
101
|
]);
|
|
102
|
+
// Only ask about Instrumentation API when Tracing is enabled, since it depends on it
|
|
103
|
+
let instrumentationAPISelected = false;
|
|
104
|
+
if (featureSelection.performance) {
|
|
105
|
+
const instrumentationAPISelection = await (0, clack_1.featureSelectionPrompt)([
|
|
106
|
+
{
|
|
107
|
+
id: 'instrumentationAPI',
|
|
108
|
+
prompt: `Do you want to use the ${chalk_1.default.bold('Instrumentation API')} for automatic tracing of loaders, actions, and middleware?`,
|
|
109
|
+
enabledHint: 'recommended',
|
|
110
|
+
},
|
|
111
|
+
]);
|
|
112
|
+
instrumentationAPISelected = instrumentationAPISelection.instrumentationAPI;
|
|
113
|
+
}
|
|
78
114
|
if (featureSelection.profiling) {
|
|
79
115
|
const profilingAlreadyInstalled = (0, package_json_1.hasPackageInstalled)('@sentry/profiling-node', packageJson);
|
|
80
116
|
await (0, clack_1.installPackage)({
|
|
@@ -94,14 +130,25 @@ Please create your entry files manually using React Router v7 commands.`);
|
|
|
94
130
|
(0, debug_1.debug)(e);
|
|
95
131
|
}
|
|
96
132
|
});
|
|
133
|
+
Sentry.setTag('instrumentation-api-selected', instrumentationAPISelected);
|
|
134
|
+
let useInstrumentationAPI = instrumentationAPISelected;
|
|
135
|
+
if (useInstrumentationAPI && !(0, sdk_setup_1.supportsInstrumentationAPI)(packageJson)) {
|
|
136
|
+
Sentry.setTag('instrumentation-api-version-guard', true);
|
|
137
|
+
const detectedVersion = (0, sdk_setup_1.getReactRouterVersion)(packageJson) ?? 'unknown';
|
|
138
|
+
prompts_1.default.log.warn(`The Instrumentation API requires React Router ${chalk_1.default.cyan('>=7.9.5')} (detected ${chalk_1.default.cyan(detectedVersion)}). Your version does not meet this requirement.\n` +
|
|
139
|
+
`Continuing without the Instrumentation API. Please upgrade React Router to use this feature:\n` +
|
|
140
|
+
chalk_1.default.dim('https://docs.sentry.io/platforms/javascript/guides/react-router/'));
|
|
141
|
+
useInstrumentationAPI = false;
|
|
142
|
+
}
|
|
143
|
+
Sentry.setTag('use-instrumentation-api', useInstrumentationAPI);
|
|
97
144
|
await (0, telemetry_1.traceStep)('Initialize Sentry on client entry', async () => {
|
|
98
145
|
try {
|
|
99
|
-
await (0, sdk_setup_1.initializeSentryOnEntryClient)(selectedProject.keys[0].dsn.public, featureSelection.performance, featureSelection.replay, featureSelection.logs, typeScriptDetected);
|
|
146
|
+
await (0, sdk_setup_1.initializeSentryOnEntryClient)(selectedProject.keys[0].dsn.public, featureSelection.performance, featureSelection.replay, featureSelection.logs, typeScriptDetected, useInstrumentationAPI);
|
|
100
147
|
}
|
|
101
148
|
catch (e) {
|
|
102
149
|
prompts_1.default.log.warn(`Could not initialize Sentry on client entry automatically.`);
|
|
103
150
|
const clientEntryFilename = `entry.client.${typeScriptDetected ? 'tsx' : 'jsx'}`;
|
|
104
|
-
const manualClientContent = (0, templates_1.getManualClientEntryContent)(selectedProject.keys[0].dsn.public, featureSelection.performance, featureSelection.replay, featureSelection.logs);
|
|
151
|
+
const manualClientContent = (0, templates_1.getManualClientEntryContent)(selectedProject.keys[0].dsn.public, featureSelection.performance, featureSelection.replay, featureSelection.logs, useInstrumentationAPI);
|
|
105
152
|
await (0, clack_1.showCopyPasteInstructions)({
|
|
106
153
|
filename: clientEntryFilename,
|
|
107
154
|
codeSnippet: manualClientContent,
|
|
@@ -128,12 +175,12 @@ Please create your entry files manually using React Router v7 commands.`);
|
|
|
128
175
|
});
|
|
129
176
|
await (0, telemetry_1.traceStep)('Instrument server entry', async () => {
|
|
130
177
|
try {
|
|
131
|
-
await (0, sdk_setup_1.instrumentSentryOnEntryServer)(typeScriptDetected);
|
|
178
|
+
await (0, sdk_setup_1.instrumentSentryOnEntryServer)(typeScriptDetected, useInstrumentationAPI);
|
|
132
179
|
}
|
|
133
180
|
catch (e) {
|
|
134
181
|
prompts_1.default.log.warn(`Could not initialize Sentry on server entry automatically.`);
|
|
135
182
|
const serverEntryFilename = `entry.server.${typeScriptDetected ? 'tsx' : 'jsx'}`;
|
|
136
|
-
const manualServerContent = (0, templates_1.getManualServerEntryContent)();
|
|
183
|
+
const manualServerContent = (0, templates_1.getManualServerEntryContent)(useInstrumentationAPI);
|
|
137
184
|
await (0, clack_1.showCopyPasteInstructions)({
|
|
138
185
|
filename: serverEntryFilename,
|
|
139
186
|
codeSnippet: manualServerContent,
|
|
@@ -174,7 +221,7 @@ Please create your entry files manually using React Router v7 commands.`);
|
|
|
174
221
|
return unchanged(`{
|
|
175
222
|
scripts: {
|
|
176
223
|
${minus('"start": "react-router dev"')}
|
|
177
|
-
${plus('"start": "NODE_OPTIONS=\'--import ./instrument.server.mjs\' react-router-serve ./build/server/index.js"')}
|
|
224
|
+
${plus('"start": "NODE_ENV=production NODE_OPTIONS=\'--import ./instrument.server.mjs\' react-router-serve ./build/server/index.js"')}
|
|
178
225
|
${minus('"dev": "react-router dev"')}
|
|
179
226
|
${plus('"dev": "NODE_OPTIONS=\'--import ./instrument.server.mjs\' react-router dev"')}
|
|
180
227
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-router-wizard.js","sourceRoot":"","sources":["../../../src/react-router/react-router-wizard.ts"],"names":[],"mappings":";;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAG1B,4CAAwD;AACxD,0CAawB;AACxB,0DAAwE;AACxE,wDAA4D;AAC5D,0CAAuC;AACvC,+CAAkD;AAClD,2CAUqB;AACrB,2CAOqB;AACrB,kGAA0F;AAEnF,KAAK,UAAU,oBAAoB,CACx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import clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport type { WizardOptions } from '../utils/types';\nimport { withTelemetry, traceStep } from '../telemetry';\nimport {\n askShouldCreateExamplePage,\n confirmContinueIfNoOrDirtyGitRepo,\n featureSelectionPrompt,\n getOrAskForProjectData,\n getPackageDotJson,\n isUsingTypeScript,\n printWelcome,\n installPackage,\n addDotEnvSentryBuildPluginFile,\n showCopyPasteInstructions,\n makeCodeSnippet,\n runPrettierIfInstalled,\n} from '../utils/clack';\nimport { offerProjectScopedMcpConfig } from '../utils/clack/mcp-config';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport { debug } from '../utils/debug';\nimport { createExamplePage } from './sdk-example';\nimport {\n isReactRouterV7,\n runReactRouterReveal,\n initializeSentryOnEntryClient,\n instrumentRootRoute,\n createServerInstrumentationFile,\n updatePackageJsonScripts,\n instrumentSentryOnEntryServer,\n configureReactRouterConfig,\n configureReactRouterVitePlugin,\n} from './sdk-setup';\nimport {\n getManualClientEntryContent,\n getManualServerEntryContent,\n getManualRootContent,\n getManualServerInstrumentContent,\n getManualReactRouterConfigContent,\n getManualViteConfigContent,\n} from './templates';\nimport { abortIfSpotlightNotSupported } from '../utils/abort-if-sportlight-not-supported';\n\nexport async function runReactRouterWizard(\n options: WizardOptions,\n): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'reactRouter',\n wizardOptions: options,\n },\n () => runReactRouterWizardWithTelemetry(options),\n );\n}\n\nasync function runReactRouterWizardWithTelemetry(\n options: WizardOptions,\n): Promise<void> {\n printWelcome({\n wizardName: 'Sentry React Router Wizard',\n promoCode: options.promoCode,\n });\n\n const packageJson = await getPackageDotJson();\n\n if (!packageJson) {\n clack.log.error(\n 'Could not find a package.json file in the current directory',\n );\n return;\n }\n\n const typeScriptDetected = isUsingTypeScript();\n\n if (!isReactRouterV7(packageJson)) {\n clack.log.error(\n 'This wizard requires React Router v7. Please upgrade your React Router version to v7.0.0 or higher.\\n\\nFor upgrade instructions, visit: https://react-router.dev/upgrade/v7',\n );\n return;\n }\n\n await confirmContinueIfNoOrDirtyGitRepo({\n ignoreGitChanges: options.ignoreGitChanges,\n cwd: undefined,\n });\n\n const sentryAlreadyInstalled = hasPackageInstalled(\n '@sentry/react-router',\n packageJson,\n );\n\n const projectData = await getOrAskForProjectData(\n options,\n 'javascript-react-router',\n );\n\n if (projectData.spotlight) {\n return abortIfSpotlightNotSupported('React Router');\n }\n\n const { selectedProject, authToken, selfHosted, sentryUrl } = projectData;\n\n await installPackage({\n packageName: '@sentry/react-router',\n alreadyInstalled: sentryAlreadyInstalled,\n });\n\n const featureSelection = await featureSelectionPrompt([\n {\n id: 'performance',\n prompt: `Do you want to enable ${chalk.bold(\n 'Tracing',\n )} to track the performance of your application?`,\n enabledHint: 'recommended',\n },\n {\n id: 'replay',\n prompt: `Do you want to enable ${chalk.bold(\n 'Session Replay',\n )} to get a video-like reproduction of errors during a user session?`,\n enabledHint: 'recommended, but increases bundle size',\n },\n {\n id: 'logs',\n prompt: `Do you want to enable ${chalk.bold(\n 'Logs',\n )} to send your application logs to Sentry?`,\n enabledHint: 'recommended',\n },\n {\n id: 'profiling',\n prompt: `Do you want to enable ${chalk.bold(\n 'Profiling',\n )} to track application performance in detail?`,\n enabledHint: 'recommended for production debugging',\n },\n ]);\n\n if (featureSelection.profiling) {\n const profilingAlreadyInstalled = hasPackageInstalled(\n '@sentry/profiling-node',\n packageJson,\n );\n\n await installPackage({\n packageName: '@sentry/profiling-node',\n alreadyInstalled: profilingAlreadyInstalled,\n });\n }\n\n const createExamplePageSelection = await askShouldCreateExamplePage();\n\n traceStep('Reveal missing entry files', () => {\n try {\n runReactRouterReveal();\n clack.log.success('Entry files are ready for instrumentation');\n } catch (e) {\n clack.log.warn(`Could not run 'npx react-router reveal'.\nPlease create your entry files manually using React Router v7 commands.`);\n debug(e);\n }\n });\n\n await traceStep('Initialize Sentry on client entry', async () => {\n try {\n await initializeSentryOnEntryClient(\n selectedProject.keys[0].dsn.public,\n featureSelection.performance,\n featureSelection.replay,\n featureSelection.logs,\n typeScriptDetected,\n );\n } catch (e) {\n clack.log.warn(\n `Could not initialize Sentry on client entry automatically.`,\n );\n\n const clientEntryFilename = `entry.client.${\n typeScriptDetected ? 'tsx' : 'jsx'\n }`;\n\n const manualClientContent = getManualClientEntryContent(\n selectedProject.keys[0].dsn.public,\n featureSelection.performance,\n featureSelection.replay,\n featureSelection.logs,\n );\n\n await showCopyPasteInstructions({\n filename: clientEntryFilename,\n codeSnippet: manualClientContent,\n hint: 'This enables error tracking and performance monitoring for your React Router app',\n });\n\n debug(e);\n }\n });\n\n await traceStep('Instrument root route', async () => {\n try {\n await instrumentRootRoute(typeScriptDetected);\n } catch (e) {\n clack.log.warn(`Could not instrument root route automatically.`);\n\n const rootFilename = `app/root.${typeScriptDetected ? 'tsx' : 'jsx'}`;\n const manualRootContent = getManualRootContent(typeScriptDetected);\n\n await showCopyPasteInstructions({\n filename: rootFilename,\n codeSnippet: manualRootContent,\n hint: 'This adds error boundary integration to capture exceptions in your React Router app',\n });\n\n debug(e);\n }\n });\n\n await traceStep('Instrument server entry', async () => {\n try {\n await instrumentSentryOnEntryServer(typeScriptDetected);\n } catch (e) {\n clack.log.warn(\n `Could not initialize Sentry on server entry automatically.`,\n );\n\n const serverEntryFilename = `entry.server.${\n typeScriptDetected ? 'tsx' : 'jsx'\n }`;\n const manualServerContent = getManualServerEntryContent();\n\n await showCopyPasteInstructions({\n filename: serverEntryFilename,\n codeSnippet: manualServerContent,\n hint: 'This configures server-side request handling and error tracking',\n });\n\n debug(e);\n }\n });\n\n await traceStep('Create server instrumentation file', async () => {\n try {\n createServerInstrumentationFile(selectedProject.keys[0].dsn.public, {\n performance: featureSelection.performance,\n replay: featureSelection.replay,\n logs: featureSelection.logs,\n profiling: featureSelection.profiling,\n });\n } catch (e) {\n clack.log.warn(\n 'Could not create a server instrumentation file automatically.',\n );\n\n const manualServerInstrumentContent = getManualServerInstrumentContent(\n selectedProject.keys[0].dsn.public,\n featureSelection.performance,\n featureSelection.profiling,\n featureSelection.logs,\n );\n\n await showCopyPasteInstructions({\n filename: 'instrument.server.mjs',\n codeSnippet: manualServerInstrumentContent,\n hint: 'Create the file if it does not exist - this initializes Sentry before your application starts',\n });\n\n debug(e);\n }\n });\n\n await traceStep('Update package.json scripts', async () => {\n try {\n await updatePackageJsonScripts();\n } catch (e) {\n clack.log.warn('Could not update start script automatically.');\n\n await showCopyPasteInstructions({\n filename: 'package.json',\n codeSnippet: makeCodeSnippet(true, (unchanged, plus, minus) => {\n return unchanged(`{\n scripts: {\n ${minus('\"start\": \"react-router dev\"')}\n ${plus(\n '\"start\": \"NODE_OPTIONS=\\'--import ./instrument.server.mjs\\' react-router-serve ./build/server/index.js\"',\n )}\n ${minus('\"dev\": \"react-router dev\"')}\n ${plus(\n '\"dev\": \"NODE_OPTIONS=\\'--import ./instrument.server.mjs\\' react-router dev\"',\n )}\n },\n // ... rest of your package.json\n }`);\n }),\n });\n\n debug(e);\n }\n });\n\n await traceStep('Create build plugin env file', async () => {\n try {\n await addDotEnvSentryBuildPluginFile(authToken);\n } catch (e) {\n clack.log.warn(\n 'Could not create .env.sentry-build-plugin file. Please create it manually.',\n );\n debug(e);\n }\n });\n\n // Validate auth token before configuring sourcemap uploads\n if (!authToken) {\n clack.log.warn(\n `${chalk.yellow(\n 'Warning:',\n )} No auth token found. Sourcemap uploads will not work without ${chalk.cyan(\n 'SENTRY_AUTH_TOKEN',\n )}.\\n` +\n `Please set ${chalk.cyan('SENTRY_AUTH_TOKEN')} in your ${chalk.cyan(\n '.env.sentry-build-plugin',\n )} file or environment variables.`,\n );\n }\n\n // Configure Vite plugin for sourcemap uploads\n await traceStep('Configure Vite plugin for sourcemap uploads', async () => {\n try {\n await configureReactRouterVitePlugin(\n selectedProject.organization.slug,\n selectedProject.slug,\n );\n } catch (e) {\n clack.log.warn(\n `Could not configure Vite plugin for sourcemap uploads automatically.`,\n );\n\n await showCopyPasteInstructions({\n filename: `vite.config.${typeScriptDetected ? 'ts' : 'js'}`,\n codeSnippet: getManualViteConfigContent(\n selectedProject.organization.slug,\n selectedProject.slug,\n ),\n hint: 'This enables automatic sourcemap uploads during build for better error tracking',\n });\n\n debug(e);\n }\n });\n\n // Configure React Router config for build hook\n await traceStep('Configure React Router build hook', async () => {\n try {\n await configureReactRouterConfig(typeScriptDetected);\n } catch (e) {\n clack.log.warn(\n `Could not configure React Router build hook automatically.`,\n );\n\n await showCopyPasteInstructions({\n filename: `react-router.config.${typeScriptDetected ? 'ts' : 'js'}`,\n codeSnippet: getManualReactRouterConfigContent(typeScriptDetected),\n hint: 'This enables automatic sourcemap uploads at the end of the build process',\n });\n\n debug(e);\n }\n });\n\n // Create example page if requested\n if (createExamplePageSelection) {\n await traceStep('Create example page', async () => {\n await createExamplePage({\n selfHosted,\n orgSlug: selectedProject.organization.slug,\n projectId: selectedProject.id,\n url: sentryUrl,\n isTS: typeScriptDetected,\n projectDir: process.cwd(),\n });\n });\n }\n\n await runPrettierIfInstalled({ cwd: undefined });\n\n // Offer optional project-scoped MCP config for Sentry with org and project scope\n await offerProjectScopedMcpConfig(\n selectedProject.organization.slug,\n selectedProject.slug,\n );\n\n clack.outro(\n `${chalk.green('Successfully installed the Sentry React Router SDK!')}${\n createExamplePageSelection\n ? `\\n\\nYou can validate your setup by visiting ${chalk.cyan(\n '\"/sentry-example-page\"',\n )} in your application.`\n : ''\n }`,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"react-router-wizard.js","sourceRoot":"","sources":["../../../src/react-router/react-router-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,qDAAuC;AAGvC,4CAAwD;AACxD,0CAawB;AACxB,0DAAwE;AACxE,wDAA4D;AAC5D,0CAAuC;AACvC,+CAAkD;AAClD,2CAYqB;AACrB,2CAOqB;AACrB,kGAA0F;AAEnF,KAAK,UAAU,oBAA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AAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;gBACnE,WAAW,EAAE,IAAA,6CAAiC,EAAC,kBAAkB,CAAC;gBAClE,IAAI,EAAE,0EAA0E;aACjF,CAAC,CAAC;YAEH,IAAA,aAAK,EAAC,CAAC,CAAC,CAAC;SACV;IACH,CAAC,CAAC,CAAC;IAEH,mCAAmC;IACnC,IAAI,0BAA0B,EAAE;QAC9B,MAAM,IAAA,qBAAS,EAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;YAChD,MAAM,IAAA,+BAAiB,EAAC;gBACtB,UAAU;gBACV,OAAO,EAAE,eAAe,CAAC,YAAY,CAAC,IAAI;gBAC1C,SAAS,EAAE,eAAe,CAAC,EAAE;gBAC7B,GAAG,EAAE,SAAS;gBACd,IAAI,EAAE,kBAAkB;gBACxB,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE;aAC1B,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;KACJ;IAED,MAAM,IAAA,8BAAsB,EAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;IAEjD,iFAAiF;IACjF,MAAM,IAAA,wCAA2B,EAC/B,eAAe,CAAC,YAAY,CAAC,IAAI,EACjC,eAAe,CAAC,IAAI,CACrB,CAAC;IAEF,iBAAK,CAAC,KAAK,CACT,GAAG,eAAK,CAAC,KAAK,CAAC,qDAAqD,CAAC,GACnE,0BAA0B;QACxB,CAAC,CAAC,+CAA+C,eAAK,CAAC,IAAI,CACvD,wBAAwB,CACzB,uBAAuB;QAC1B,CAAC,CAAC,EACN,EAAE,CACH,CAAC;AACJ,CAAC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as Sentry from '@sentry/node';\n\nimport type { WizardOptions } from '../utils/types';\nimport { withTelemetry, traceStep } from '../telemetry';\nimport {\n askShouldCreateExamplePage,\n confirmContinueIfNoOrDirtyGitRepo,\n featureSelectionPrompt,\n getOrAskForProjectData,\n getPackageDotJson,\n isUsingTypeScript,\n printWelcome,\n installPackage,\n addDotEnvSentryBuildPluginFile,\n showCopyPasteInstructions,\n makeCodeSnippet,\n runPrettierIfInstalled,\n} from '../utils/clack';\nimport { offerProjectScopedMcpConfig } from '../utils/clack/mcp-config';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport { debug } from '../utils/debug';\nimport { createExamplePage } from './sdk-example';\nimport {\n isReactRouterV7,\n getReactRouterVersion,\n supportsInstrumentationAPI,\n runReactRouterReveal,\n initializeSentryOnEntryClient,\n instrumentRootRoute,\n createServerInstrumentationFile,\n updatePackageJsonScripts,\n instrumentSentryOnEntryServer,\n configureReactRouterConfig,\n configureReactRouterVitePlugin,\n} from './sdk-setup';\nimport {\n getManualClientEntryContent,\n getManualServerEntryContent,\n getManualRootContent,\n getManualServerInstrumentContent,\n getManualReactRouterConfigContent,\n getManualViteConfigContent,\n} from './templates';\nimport { abortIfSpotlightNotSupported } from '../utils/abort-if-sportlight-not-supported';\n\nexport async function runReactRouterWizard(\n options: WizardOptions,\n): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'reactRouter',\n wizardOptions: options,\n },\n () => runReactRouterWizardWithTelemetry(options),\n );\n}\n\nasync function runReactRouterWizardWithTelemetry(\n options: WizardOptions,\n): Promise<void> {\n printWelcome({\n wizardName: 'Sentry React Router Wizard',\n promoCode: options.promoCode,\n });\n\n const packageJson = await getPackageDotJson();\n\n if (!packageJson) {\n clack.log.error(\n 'Could not find a package.json file in the current directory',\n );\n return;\n }\n\n const typeScriptDetected = isUsingTypeScript();\n\n if (!isReactRouterV7(packageJson)) {\n clack.log.error(\n 'This wizard requires React Router v7. Please upgrade your React Router version to v7.0.0 or higher.\\n\\nFor upgrade instructions, visit: https://react-router.dev/upgrade/v7',\n );\n return;\n }\n\n await confirmContinueIfNoOrDirtyGitRepo({\n ignoreGitChanges: options.ignoreGitChanges,\n cwd: undefined,\n });\n\n const sentryAlreadyInstalled = hasPackageInstalled(\n '@sentry/react-router',\n packageJson,\n );\n\n const projectData = await getOrAskForProjectData(\n options,\n 'javascript-react-router',\n );\n\n if (projectData.spotlight) {\n return abortIfSpotlightNotSupported('React Router');\n }\n\n const { selectedProject, authToken, selfHosted, sentryUrl } = projectData;\n\n await installPackage({\n packageName: '@sentry/react-router',\n alreadyInstalled: sentryAlreadyInstalled,\n });\n\n const featureSelection = await featureSelectionPrompt([\n {\n id: 'performance',\n prompt: `Do you want to enable ${chalk.bold(\n 'Tracing',\n )} to track the performance of your application?`,\n enabledHint: 'recommended',\n },\n {\n id: 'replay',\n prompt: `Do you want to enable ${chalk.bold(\n 'Session Replay',\n )} to get a video-like reproduction of errors during a user session?`,\n enabledHint: 'recommended, but increases bundle size',\n },\n {\n id: 'logs',\n prompt: `Do you want to enable ${chalk.bold(\n 'Logs',\n )} to send your application logs to Sentry?`,\n enabledHint: 'recommended',\n },\n {\n id: 'profiling',\n prompt: `Do you want to enable ${chalk.bold(\n 'Profiling',\n )} to track application performance in detail?`,\n enabledHint: 'recommended for production debugging',\n },\n ]);\n\n // Only ask about Instrumentation API when Tracing is enabled, since it depends on it\n let instrumentationAPISelected = false;\n if (featureSelection.performance) {\n const instrumentationAPISelection = await featureSelectionPrompt([\n {\n id: 'instrumentationAPI',\n prompt: `Do you want to use the ${chalk.bold(\n 'Instrumentation API',\n )} for automatic tracing of loaders, actions, and middleware?`,\n enabledHint: 'recommended',\n },\n ]);\n instrumentationAPISelected = instrumentationAPISelection.instrumentationAPI;\n }\n\n if (featureSelection.profiling) {\n const profilingAlreadyInstalled = hasPackageInstalled(\n '@sentry/profiling-node',\n packageJson,\n );\n\n await installPackage({\n packageName: '@sentry/profiling-node',\n alreadyInstalled: profilingAlreadyInstalled,\n });\n }\n\n const createExamplePageSelection = await askShouldCreateExamplePage();\n\n traceStep('Reveal missing entry files', () => {\n try {\n runReactRouterReveal();\n clack.log.success('Entry files are ready for instrumentation');\n } catch (e) {\n clack.log.warn(`Could not run 'npx react-router reveal'.\nPlease create your entry files manually using React Router v7 commands.`);\n debug(e);\n }\n });\n\n Sentry.setTag('instrumentation-api-selected', instrumentationAPISelected);\n\n let useInstrumentationAPI = instrumentationAPISelected;\n\n if (useInstrumentationAPI && !supportsInstrumentationAPI(packageJson)) {\n Sentry.setTag('instrumentation-api-version-guard', true);\n const detectedVersion = getReactRouterVersion(packageJson) ?? 'unknown';\n clack.log.warn(\n `The Instrumentation API requires React Router ${chalk.cyan(\n '>=7.9.5',\n )} (detected ${chalk.cyan(\n detectedVersion,\n )}). Your version does not meet this requirement.\\n` +\n `Continuing without the Instrumentation API. Please upgrade React Router to use this feature:\\n` +\n chalk.dim(\n 'https://docs.sentry.io/platforms/javascript/guides/react-router/',\n ),\n );\n useInstrumentationAPI = false;\n }\n\n Sentry.setTag('use-instrumentation-api', useInstrumentationAPI);\n\n await traceStep('Initialize Sentry on client entry', async () => {\n try {\n await initializeSentryOnEntryClient(\n selectedProject.keys[0].dsn.public,\n featureSelection.performance,\n featureSelection.replay,\n featureSelection.logs,\n typeScriptDetected,\n useInstrumentationAPI,\n );\n } catch (e) {\n clack.log.warn(\n `Could not initialize Sentry on client entry automatically.`,\n );\n\n const clientEntryFilename = `entry.client.${\n typeScriptDetected ? 'tsx' : 'jsx'\n }`;\n\n const manualClientContent = getManualClientEntryContent(\n selectedProject.keys[0].dsn.public,\n featureSelection.performance,\n featureSelection.replay,\n featureSelection.logs,\n useInstrumentationAPI,\n );\n\n await showCopyPasteInstructions({\n filename: clientEntryFilename,\n codeSnippet: manualClientContent,\n hint: 'This enables error tracking and performance monitoring for your React Router app',\n });\n\n debug(e);\n }\n });\n\n await traceStep('Instrument root route', async () => {\n try {\n await instrumentRootRoute(typeScriptDetected);\n } catch (e) {\n clack.log.warn(`Could not instrument root route automatically.`);\n\n const rootFilename = `app/root.${typeScriptDetected ? 'tsx' : 'jsx'}`;\n const manualRootContent = getManualRootContent(typeScriptDetected);\n\n await showCopyPasteInstructions({\n filename: rootFilename,\n codeSnippet: manualRootContent,\n hint: 'This adds error boundary integration to capture exceptions in your React Router app',\n });\n\n debug(e);\n }\n });\n\n await traceStep('Instrument server entry', async () => {\n try {\n await instrumentSentryOnEntryServer(\n typeScriptDetected,\n useInstrumentationAPI,\n );\n } catch (e) {\n clack.log.warn(\n `Could not initialize Sentry on server entry automatically.`,\n );\n\n const serverEntryFilename = `entry.server.${\n typeScriptDetected ? 'tsx' : 'jsx'\n }`;\n const manualServerContent = getManualServerEntryContent(\n useInstrumentationAPI,\n );\n\n await showCopyPasteInstructions({\n filename: serverEntryFilename,\n codeSnippet: manualServerContent,\n hint: 'This configures server-side request handling and error tracking',\n });\n\n debug(e);\n }\n });\n\n await traceStep('Create server instrumentation file', async () => {\n try {\n createServerInstrumentationFile(selectedProject.keys[0].dsn.public, {\n performance: featureSelection.performance,\n replay: featureSelection.replay,\n logs: featureSelection.logs,\n profiling: featureSelection.profiling,\n });\n } catch (e) {\n clack.log.warn(\n 'Could not create a server instrumentation file automatically.',\n );\n\n const manualServerInstrumentContent = getManualServerInstrumentContent(\n selectedProject.keys[0].dsn.public,\n featureSelection.performance,\n featureSelection.profiling,\n featureSelection.logs,\n );\n\n await showCopyPasteInstructions({\n filename: 'instrument.server.mjs',\n codeSnippet: manualServerInstrumentContent,\n hint: 'Create the file if it does not exist - this initializes Sentry before your application starts',\n });\n\n debug(e);\n }\n });\n\n await traceStep('Update package.json scripts', async () => {\n try {\n await updatePackageJsonScripts();\n } catch (e) {\n clack.log.warn('Could not update start script automatically.');\n\n await showCopyPasteInstructions({\n filename: 'package.json',\n codeSnippet: makeCodeSnippet(true, (unchanged, plus, minus) => {\n return unchanged(`{\n scripts: {\n ${minus('\"start\": \"react-router dev\"')}\n ${plus(\n '\"start\": \"NODE_ENV=production NODE_OPTIONS=\\'--import ./instrument.server.mjs\\' react-router-serve ./build/server/index.js\"',\n )}\n ${minus('\"dev\": \"react-router dev\"')}\n ${plus(\n '\"dev\": \"NODE_OPTIONS=\\'--import ./instrument.server.mjs\\' react-router dev\"',\n )}\n },\n // ... rest of your package.json\n }`);\n }),\n });\n\n debug(e);\n }\n });\n\n await traceStep('Create build plugin env file', async () => {\n try {\n await addDotEnvSentryBuildPluginFile(authToken);\n } catch (e) {\n clack.log.warn(\n 'Could not create .env.sentry-build-plugin file. Please create it manually.',\n );\n debug(e);\n }\n });\n\n // Validate auth token before configuring sourcemap uploads\n if (!authToken) {\n clack.log.warn(\n `${chalk.yellow(\n 'Warning:',\n )} No auth token found. Sourcemap uploads will not work without ${chalk.cyan(\n 'SENTRY_AUTH_TOKEN',\n )}.\\n` +\n `Please set ${chalk.cyan('SENTRY_AUTH_TOKEN')} in your ${chalk.cyan(\n '.env.sentry-build-plugin',\n )} file or environment variables.`,\n );\n }\n\n // Configure Vite plugin for sourcemap uploads\n await traceStep('Configure Vite plugin for sourcemap uploads', async () => {\n try {\n await configureReactRouterVitePlugin(\n selectedProject.organization.slug,\n selectedProject.slug,\n );\n } catch (e) {\n clack.log.warn(\n `Could not configure Vite plugin for sourcemap uploads automatically.`,\n );\n\n await showCopyPasteInstructions({\n filename: `vite.config.${typeScriptDetected ? 'ts' : 'js'}`,\n codeSnippet: getManualViteConfigContent(\n selectedProject.organization.slug,\n selectedProject.slug,\n ),\n hint: 'This enables automatic sourcemap uploads during build for better error tracking',\n });\n\n debug(e);\n }\n });\n\n // Configure React Router config for build hook\n await traceStep('Configure React Router build hook', async () => {\n try {\n await configureReactRouterConfig(typeScriptDetected);\n } catch (e) {\n clack.log.warn(\n `Could not configure React Router build hook automatically.`,\n );\n\n await showCopyPasteInstructions({\n filename: `react-router.config.${typeScriptDetected ? 'ts' : 'js'}`,\n codeSnippet: getManualReactRouterConfigContent(typeScriptDetected),\n hint: 'This enables automatic sourcemap uploads at the end of the build process',\n });\n\n debug(e);\n }\n });\n\n // Create example page if requested\n if (createExamplePageSelection) {\n await traceStep('Create example page', async () => {\n await createExamplePage({\n selfHosted,\n orgSlug: selectedProject.organization.slug,\n projectId: selectedProject.id,\n url: sentryUrl,\n isTS: typeScriptDetected,\n projectDir: process.cwd(),\n });\n });\n }\n\n await runPrettierIfInstalled({ cwd: undefined });\n\n // Offer optional project-scoped MCP config for Sentry with org and project scope\n await offerProjectScopedMcpConfig(\n selectedProject.organization.slug,\n selectedProject.slug,\n );\n\n clack.outro(\n `${chalk.green('Successfully installed the Sentry React Router SDK!')}${\n createExamplePageSelection\n ? `\\n\\nYou can validate your setup by visiting ${chalk.cyan(\n '\"/sentry-example-page\"',\n )} in your application.`\n : ''\n }`,\n );\n}\n"]}
|
|
@@ -3,7 +3,9 @@ export declare function getRouteFilePath(filename: string, isTS: boolean): strin
|
|
|
3
3
|
export declare function tryRevealAndGetManualInstructions(missingFilename: string, filePath: string): Promise<boolean>;
|
|
4
4
|
export declare function runReactRouterReveal(): void;
|
|
5
5
|
export declare function isReactRouterV7(packageJson: PackageDotJson): boolean;
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function getReactRouterVersion(packageJson: PackageDotJson): string | undefined;
|
|
7
|
+
export declare function supportsInstrumentationAPI(packageJson: PackageDotJson): boolean;
|
|
8
|
+
export declare function initializeSentryOnEntryClient(dsn: string, enableTracing: boolean, enableReplay: boolean, enableLogs: boolean, isTS: boolean, useInstrumentationAPI?: boolean): Promise<void>;
|
|
7
9
|
export declare function instrumentRootRoute(isTS: boolean): Promise<void>;
|
|
8
10
|
export declare function createServerInstrumentationFile(dsn: string, selectedFeatures: {
|
|
9
11
|
performance: boolean;
|
|
@@ -12,6 +14,6 @@ export declare function createServerInstrumentationFile(dsn: string, selectedFea
|
|
|
12
14
|
profiling: boolean;
|
|
13
15
|
}): string;
|
|
14
16
|
export declare function updatePackageJsonScripts(): Promise<void>;
|
|
15
|
-
export declare function instrumentSentryOnEntryServer(isTS: boolean): Promise<void>;
|
|
17
|
+
export declare function instrumentSentryOnEntryServer(isTS: boolean, useInstrumentationAPI?: boolean): Promise<void>;
|
|
16
18
|
export declare function configureReactRouterVitePlugin(orgSlug: string, projectSlug: string): Promise<void>;
|
|
17
19
|
export declare function configureReactRouterConfig(isTS: boolean): Promise<void>;
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.configureReactRouterConfig = exports.configureReactRouterVitePlugin = exports.instrumentSentryOnEntryServer = exports.updatePackageJsonScripts = exports.createServerInstrumentationFile = exports.instrumentRootRoute = exports.initializeSentryOnEntryClient = exports.isReactRouterV7 = exports.runReactRouterReveal = exports.tryRevealAndGetManualInstructions = exports.getRouteFilePath = void 0;
|
|
29
|
+
exports.configureReactRouterConfig = exports.configureReactRouterVitePlugin = exports.instrumentSentryOnEntryServer = exports.updatePackageJsonScripts = exports.createServerInstrumentationFile = exports.instrumentRootRoute = exports.initializeSentryOnEntryClient = exports.supportsInstrumentationAPI = exports.getReactRouterVersion = exports.isReactRouterV7 = exports.runReactRouterReveal = exports.tryRevealAndGetManualInstructions = exports.getRouteFilePath = void 0;
|
|
30
30
|
const fs = __importStar(require("fs"));
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
32
|
const childProcess = __importStar(require("child_process"));
|
|
@@ -128,11 +128,32 @@ function isReactRouterV7(packageJson) {
|
|
|
128
128
|
return (0, semver_1.gte)(minVer, '7.0.0');
|
|
129
129
|
}
|
|
130
130
|
exports.isReactRouterV7 = isReactRouterV7;
|
|
131
|
-
|
|
131
|
+
function getReactRouterVersion(packageJson) {
|
|
132
|
+
const rangeVersion = (0, package_json_1.getPackageVersion)('@react-router/dev', packageJson);
|
|
133
|
+
if (!rangeVersion) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
const coerced = (0, semver_1.coerce)(rangeVersion);
|
|
137
|
+
return coerced ? coerced.version : rangeVersion;
|
|
138
|
+
}
|
|
139
|
+
exports.getReactRouterVersion = getReactRouterVersion;
|
|
140
|
+
function supportsInstrumentationAPI(packageJson) {
|
|
141
|
+
const reactRouterVersion = (0, package_json_1.getPackageVersion)('@react-router/dev', packageJson);
|
|
142
|
+
if (!reactRouterVersion) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
const minVer = (0, semver_1.minVersion)(reactRouterVersion);
|
|
146
|
+
if (!minVer) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return (0, semver_1.gte)(minVer, '7.9.5');
|
|
150
|
+
}
|
|
151
|
+
exports.supportsInstrumentationAPI = supportsInstrumentationAPI;
|
|
152
|
+
async function initializeSentryOnEntryClient(dsn, enableTracing, enableReplay, enableLogs, isTS, useInstrumentationAPI = false) {
|
|
132
153
|
const clientEntryPath = getAppFilePath('entry.client', isTS);
|
|
133
154
|
const clientEntryFilename = path.basename(clientEntryPath);
|
|
134
155
|
await ensureEntryFileExists(clientEntryFilename, clientEntryPath);
|
|
135
|
-
await (0, client_entry_1.instrumentClientEntry)(clientEntryPath, dsn, enableTracing, enableReplay, enableLogs);
|
|
156
|
+
await (0, client_entry_1.instrumentClientEntry)(clientEntryPath, dsn, enableTracing, enableReplay, enableLogs, useInstrumentationAPI);
|
|
136
157
|
prompts_1.default.log.success(`Updated ${chalk_1.default.cyan(clientEntryFilename)} with Sentry initialization.`);
|
|
137
158
|
}
|
|
138
159
|
exports.initializeSentryOnEntryClient = initializeSentryOnEntryClient;
|
|
@@ -192,14 +213,20 @@ async function updatePackageJsonScripts() {
|
|
|
192
213
|
else {
|
|
193
214
|
packageJson.scripts.start = mergeNodeOptions(startScript);
|
|
194
215
|
}
|
|
216
|
+
// Prevent React CJS dev/prod bundle mismatch when --import loads react
|
|
217
|
+
// before react-router-serve sets NODE_ENV
|
|
218
|
+
if (packageJson.scripts.start.includes('--import') &&
|
|
219
|
+
!packageJson.scripts.start.includes('NODE_ENV=')) {
|
|
220
|
+
packageJson.scripts.start = `NODE_ENV=production ${packageJson.scripts.start}`;
|
|
221
|
+
}
|
|
195
222
|
await fs.promises.writeFile('package.json', JSON.stringify(packageJson, null, 2));
|
|
196
223
|
}
|
|
197
224
|
exports.updatePackageJsonScripts = updatePackageJsonScripts;
|
|
198
|
-
async function instrumentSentryOnEntryServer(isTS) {
|
|
225
|
+
async function instrumentSentryOnEntryServer(isTS, useInstrumentationAPI = false) {
|
|
199
226
|
const serverEntryPath = getAppFilePath('entry.server', isTS);
|
|
200
227
|
const serverEntryFilename = path.basename(serverEntryPath);
|
|
201
228
|
await ensureEntryFileExists(serverEntryFilename, serverEntryPath);
|
|
202
|
-
await (0, server_entry_1.instrumentServerEntry)(serverEntryPath);
|
|
229
|
+
await (0, server_entry_1.instrumentServerEntry)(serverEntryPath, useInstrumentationAPI);
|
|
203
230
|
prompts_1.default.log.success(`Updated ${chalk_1.default.cyan(serverEntryFilename)} with Sentry error handling.`);
|
|
204
231
|
}
|
|
205
232
|
exports.instrumentSentryOnEntryServer = instrumentSentryOnEntryServer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-setup.js","sourceRoot":"","sources":["../../../src/react-router/sdk-setup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,4DAA8C;AAE9C,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,mCAAyC;AAGzC,wDAA0D;AAC1D,0CAAuC;AACvC,2CAAoE;AACpE,0CAAiD;AACjD,0DAAgE;AAChE,0CAAmD;AACnD,0DAAgE;AAChE,0CAAuD;AACvD,wEAA6E;AAE7E,MAAM,2BAA2B,GAAG,yBAAyB,CAAC;AAC9D,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AACrD,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC,SAAS,yBAAyB,CAChC,QAAgB,EAChB,YAAoB,EACpB,YAAoB;IAEpB,OAAO,CAC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AI,CAAC,CAAC;QAElE,IAAI,iBAAiB,EAAE;YACrB,iBAAK,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,QAAQ,6BAA6B,CAAC,CAAC;SACrE;aAAM;YACL,iBAAK,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,QAAQ,6BAA6B,CAAC,CAAC;SACrE;QAED,IAAI,aAAa,EAAE;YACjB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,GAAG,eAAK,CAAC,MAAM,CACb,OAAO,CACR,sDAAsD,eAAK,CAAC,IAAI,CAC/D,WAAW,CACZ,qEAAqE,CACvE,CAAC;SACH;KACF;IAAC,OAAO,CAAC,EAAE;QACV,IAAA,aAAK,EAAC,uCAAuC,EAAE,CAAC,CAAC,CAAC;QAClD,MAAM,YAAY,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAChE,MAAM,IAAI,KAAK,CACb,yBAAyB,CACvB,QAAQ,EACR,YAAY,EACZ,iDAAiD,CAClD,CACF,CAAC;KACH;AACH,CAAC;AApCD,gEAoCC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport * as childProcess from 'child_process';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport { gte, minVersion } from 'semver';\n\nimport type { PackageDotJson } from '../utils/package-json';\nimport { getPackageVersion } from '../utils/package-json';\nimport { debug } from '../utils/debug';\nimport { getSentryInstrumentationServerContent } from './templates';\nimport { instrumentRoot } from './codemods/root';\nimport { instrumentServerEntry } from './codemods/server-entry';\nimport { getPackageDotJson } from '../utils/clack';\nimport { instrumentClientEntry } from './codemods/client.entry';\nimport { instrumentViteConfig } from './codemods/vite';\nimport { instrumentReactRouterConfig } from './codemods/react-router-config';\n\nconst REACT_ROUTER_REVEAL_COMMAND = 'npx react-router reveal';\nconst INSTRUMENTATION_FILE = 'instrument.server.mjs';\nconst APP_DIRECTORY = 'app';\nconst ROUTES_DIRECTORY = 'routes';\n\nfunction _formatConfigErrorMessage(\n filename: string,\n errorMessage: string,\n fallbackHint: string,\n): string {\n return (\n `Could not automatically configure ${filename}. ${errorMessage}\\n` +\n `This may happen if your config has an unusual format. ` +\n `${fallbackHint}`\n );\n}\n\nfunction getAppFilePath(\n filename: string,\n isTS: boolean,\n isPage = true,\n): string {\n const ext = isPage ? (isTS ? 'tsx' : 'jsx') : isTS ? 'ts' : 'js';\n return path.join(process.cwd(), APP_DIRECTORY, `${filename}.${ext}`);\n}\n\nexport function getRouteFilePath(filename: string, isTS: boolean): string {\n const ext = isTS ? 'tsx' : 'jsx';\n return path.join(\n process.cwd(),\n APP_DIRECTORY,\n ROUTES_DIRECTORY,\n `${filename}.${ext}`,\n );\n}\n\nexport async function tryRevealAndGetManualInstructions(\n missingFilename: string,\n filePath: string,\n): Promise<boolean> {\n const shouldTryReveal = await clack.confirm({\n message: `Would you like to try running ${chalk.cyan(\n REACT_ROUTER_REVEAL_COMMAND,\n )} to generate entry files?`,\n initialValue: true,\n });\n\n if (shouldTryReveal) {\n try {\n clack.log.info(`Running ${chalk.cyan(REACT_ROUTER_REVEAL_COMMAND)}...`);\n const output = childProcess.execSync(REACT_ROUTER_REVEAL_COMMAND, {\n encoding: 'utf8',\n stdio: 'pipe',\n });\n clack.log.info(output);\n\n if (fs.existsSync(filePath)) {\n clack.log.success(\n `Found ${chalk.cyan(missingFilename)} after running reveal.`,\n );\n return true;\n } else {\n clack.log.warn(\n `${chalk.cyan(\n missingFilename,\n )} still not found after running reveal.`,\n );\n }\n } catch (e) {\n debug('Failed to run React Router reveal command:', e);\n clack.log.warn(\n `Failed to run ${chalk.cyan(\n REACT_ROUTER_REVEAL_COMMAND,\n )}. This command generates entry files for React Router v7.`,\n );\n }\n }\n\n return false; // File still doesn't exist, manual intervention needed\n}\n\nasync function ensureEntryFileExists(\n filename: string,\n filePath: string,\n): Promise<void> {\n if (fs.existsSync(filePath)) {\n return; // File exists, nothing to do\n }\n\n clack.log.warn(`Could not find ${chalk.cyan(filename)}.`);\n\n const fileExists = await tryRevealAndGetManualInstructions(\n filename,\n filePath,\n );\n\n if (!fileExists) {\n throw new Error(\n `Failed to create or find ${filename}. Please create this file manually or ensure your React Router v7 project structure is correct.`,\n );\n }\n}\n\nexport function runReactRouterReveal(): void {\n if (\n !fs.existsSync(path.join(process.cwd(), 'app', 'entry.client.tsx')) &&\n !fs.existsSync(path.join(process.cwd(), 'app', 'entry.client.jsx'))\n ) {\n try {\n childProcess.execSync(REACT_ROUTER_REVEAL_COMMAND, {\n encoding: 'utf8',\n stdio: 'pipe',\n });\n } catch (e) {\n debug('Failed to run React Router reveal command:', e);\n throw e;\n }\n }\n}\n\nexport function isReactRouterV7(packageJson: PackageDotJson): boolean {\n const reactRouterVersion = getPackageVersion(\n '@react-router/dev',\n packageJson,\n );\n if (!reactRouterVersion) {\n return false;\n }\n\n const minVer = minVersion(reactRouterVersion);\n\n if (!minVer) {\n return false;\n }\n\n return gte(minVer, '7.0.0');\n}\n\nexport async function initializeSentryOnEntryClient(\n dsn: string,\n enableTracing: boolean,\n enableReplay: boolean,\n enableLogs: boolean,\n isTS: boolean,\n): Promise<void> {\n const clientEntryPath = getAppFilePath('entry.client', isTS);\n const clientEntryFilename = path.basename(clientEntryPath);\n\n await ensureEntryFileExists(clientEntryFilename, clientEntryPath);\n\n await instrumentClientEntry(\n clientEntryPath,\n dsn,\n enableTracing,\n enableReplay,\n enableLogs,\n );\n\n clack.log.success(\n `Updated ${chalk.cyan(clientEntryFilename)} with Sentry initialization.`,\n );\n}\n\nexport async function instrumentRootRoute(isTS: boolean): Promise<void> {\n const rootPath = getAppFilePath('root', isTS);\n const rootFilename = path.basename(rootPath);\n\n if (!fs.existsSync(rootPath)) {\n throw new Error(\n `${rootFilename} not found in app directory. Please ensure your React Router v7 app has a root.tsx/jsx file in the app folder.`,\n );\n }\n\n await instrumentRoot(rootFilename);\n clack.log.success(`Updated ${chalk.cyan(rootFilename)} with ErrorBoundary.`);\n}\n\nexport function createServerInstrumentationFile(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n profiling: boolean;\n },\n): string {\n const instrumentationPath = path.join(process.cwd(), INSTRUMENTATION_FILE);\n\n const content = getSentryInstrumentationServerContent(\n dsn,\n selectedFeatures.performance,\n selectedFeatures.profiling,\n selectedFeatures.logs,\n );\n\n fs.writeFileSync(instrumentationPath, content);\n clack.log.success(`Created ${chalk.cyan(INSTRUMENTATION_FILE)}.`);\n return instrumentationPath;\n}\n\nexport async function updatePackageJsonScripts(): Promise<void> {\n const packageJson = await getPackageDotJson();\n\n if (!packageJson?.scripts) {\n throw new Error(\n 'Could not find a `scripts` section in your package.json file. Please add scripts manually or ensure your package.json is valid.',\n );\n }\n\n if (!packageJson.scripts.start) {\n throw new Error(\n 'Could not find a `start` script in your package.json. Please add: \"start\": \"react-router-serve ./build/server/index.js\" and re-run the wizard.',\n );\n }\n\n function mergeNodeOptions(\n scriptCommand: string,\n instrumentPath = './instrument.server.mjs',\n ): string {\n if (scriptCommand.includes(instrumentPath)) {\n return scriptCommand;\n }\n\n const quotedMatch = scriptCommand.match(/NODE_OPTIONS=(['\"])([^'\"]*)\\1/);\n if (quotedMatch) {\n const existingOptions = quotedMatch[2];\n const mergedOptions =\n `${existingOptions} --import ${instrumentPath}`.trim();\n return scriptCommand.replace(\n /NODE_OPTIONS=(['\"])([^'\"]*)\\1/,\n `NODE_OPTIONS='${mergedOptions}'`,\n );\n }\n\n const unquotedMatch = scriptCommand.match(\n /NODE_OPTIONS=([^\\s]+(?:\\s+[^\\s]+)*?)(\\s+(?:react-router-serve|react-router|node|npx|tsx))/,\n );\n if (unquotedMatch) {\n const existingOptions = unquotedMatch[1];\n const commandPart = unquotedMatch[2];\n const mergedOptions =\n `${existingOptions} --import ${instrumentPath}`.trim();\n return scriptCommand.replace(\n /NODE_OPTIONS=([^\\s]+(?:\\s+[^\\s]+)*?)(\\s+(?:react-router-serve|react-router|node|npx|tsx))/,\n `NODE_OPTIONS='${mergedOptions}'${commandPart}`,\n );\n }\n\n return `NODE_OPTIONS='--import ${instrumentPath}' ${scriptCommand}`;\n }\n\n if (packageJson.scripts.dev) {\n packageJson.scripts.dev = mergeNodeOptions(packageJson.scripts.dev);\n }\n\n const startScript = packageJson.scripts.start;\n if (\n !startScript.includes(INSTRUMENTATION_FILE) &&\n !startScript.includes('NODE_OPTIONS')\n ) {\n packageJson.scripts.start = `NODE_OPTIONS='--import ./${INSTRUMENTATION_FILE}' react-router-serve ./build/server/index.js`;\n } else {\n packageJson.scripts.start = mergeNodeOptions(startScript);\n }\n\n await fs.promises.writeFile(\n 'package.json',\n JSON.stringify(packageJson, null, 2),\n );\n}\n\nexport async function instrumentSentryOnEntryServer(\n isTS: boolean,\n): Promise<void> {\n const serverEntryPath = getAppFilePath('entry.server', isTS);\n const serverEntryFilename = path.basename(serverEntryPath);\n\n await ensureEntryFileExists(serverEntryFilename, serverEntryPath);\n\n await instrumentServerEntry(serverEntryPath);\n\n clack.log.success(\n `Updated ${chalk.cyan(serverEntryFilename)} with Sentry error handling.`,\n );\n}\n\nexport async function configureReactRouterVitePlugin(\n orgSlug: string,\n projectSlug: string,\n): Promise<void> {\n const configPath = fs.existsSync(path.join(process.cwd(), 'vite.config.ts'))\n ? path.join(process.cwd(), 'vite.config.ts')\n : path.join(process.cwd(), 'vite.config.js');\n const filename = chalk.cyan(path.basename(configPath));\n\n try {\n const { wasConverted } = await instrumentViteConfig(orgSlug, projectSlug);\n\n clack.log.success(`Updated ${filename} with sentryReactRouter plugin.`);\n\n if (wasConverted) {\n clack.log.info(\n `Converted your Vite config to function form ${chalk.dim(\n '(defineConfig(config => ({ ... })))',\n )} to support the Sentry React Router plugin.`,\n );\n }\n } catch (e) {\n debug('Failed to modify vite config:', e);\n const errorMessage = e instanceof Error ? e.message : String(e);\n throw new Error(\n _formatConfigErrorMessage(\n filename,\n errorMessage,\n 'You may need to add the plugin manually.',\n ),\n );\n }\n}\n\nexport async function configureReactRouterConfig(isTS: boolean): Promise<void> {\n const configFilename = `react-router.config.${isTS ? 'ts' : 'js'}`;\n const configPath = path.join(process.cwd(), configFilename);\n const filename = chalk.cyan(configFilename);\n\n try {\n const fileExistedBefore = fs.existsSync(configPath);\n\n const { ssrWasChanged } = await instrumentReactRouterConfig(isTS);\n\n if (fileExistedBefore) {\n clack.log.success(`Updated ${filename} with Sentry buildEnd hook.`);\n } else {\n clack.log.success(`Created ${filename} with Sentry buildEnd hook.`);\n }\n\n if (ssrWasChanged) {\n clack.log.warn(\n `${chalk.yellow(\n 'Note:',\n )} SSR has been enabled in your React Router config (${chalk.cyan(\n 'ssr: true',\n )}). This is required for Sentry sourcemap uploads to work correctly.`,\n );\n }\n } catch (e) {\n debug('Failed to modify react-router.config:', e);\n const errorMessage = e instanceof Error ? e.message : String(e);\n throw new Error(\n _formatConfigErrorMessage(\n filename,\n errorMessage,\n 'You may need to add the buildEnd hook manually.',\n ),\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sdk-setup.js","sourceRoot":"","sources":["../../../src/react-router/sdk-setup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,4DAA8C;AAE9C,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,mCAAiD;AAGjD,wDAA0D;AAC1D,0CAAuC;AACvC,2CAAoE;AACpE,0CAAiD;AACjD,0DAAgE;AAChE,0CAAmD;AACnD,0DAAgE;AAChE,0CAAuD;AACvD,wEAA6E;AAE7E,MAAM,2BAA2B,GAAG,yBAAyB,CAAC;AAC9D,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AACrD,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC,SAAS,yBAAyB,CAChC,QAAgB,EAChB,YAAoB,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AAC;SACrE;aAAM;YACL,iBAAK,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,QAAQ,6BAA6B,CAAC,CAAC;SACrE;QAED,IAAI,aAAa,EAAE;YACjB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,GAAG,eAAK,CAAC,MAAM,CACb,OAAO,CACR,sDAAsD,eAAK,CAAC,IAAI,CAC/D,WAAW,CACZ,qEAAqE,CACvE,CAAC;SACH;KACF;IAAC,OAAO,CAAC,EAAE;QACV,IAAA,aAAK,EAAC,uCAAuC,EAAE,CAAC,CAAC,CAAC;QAClD,MAAM,YAAY,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAChE,MAAM,IAAI,KAAK,CACb,yBAAyB,CACvB,QAAQ,EACR,YAAY,EACZ,iDAAiD,CAClD,CACF,CAAC;KACH;AACH,CAAC;AApCD,gEAoCC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport * as childProcess from 'child_process';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport { gte, minVersion, coerce } from 'semver';\n\nimport type { PackageDotJson } from '../utils/package-json';\nimport { getPackageVersion } from '../utils/package-json';\nimport { debug } from '../utils/debug';\nimport { getSentryInstrumentationServerContent } from './templates';\nimport { instrumentRoot } from './codemods/root';\nimport { instrumentServerEntry } from './codemods/server-entry';\nimport { getPackageDotJson } from '../utils/clack';\nimport { instrumentClientEntry } from './codemods/client.entry';\nimport { instrumentViteConfig } from './codemods/vite';\nimport { instrumentReactRouterConfig } from './codemods/react-router-config';\n\nconst REACT_ROUTER_REVEAL_COMMAND = 'npx react-router reveal';\nconst INSTRUMENTATION_FILE = 'instrument.server.mjs';\nconst APP_DIRECTORY = 'app';\nconst ROUTES_DIRECTORY = 'routes';\n\nfunction _formatConfigErrorMessage(\n filename: string,\n errorMessage: string,\n fallbackHint: string,\n): string {\n return (\n `Could not automatically configure ${filename}. ${errorMessage}\\n` +\n `This may happen if your config has an unusual format. ` +\n `${fallbackHint}`\n );\n}\n\nfunction getAppFilePath(\n filename: string,\n isTS: boolean,\n isPage = true,\n): string {\n const ext = isPage ? (isTS ? 'tsx' : 'jsx') : isTS ? 'ts' : 'js';\n return path.join(process.cwd(), APP_DIRECTORY, `${filename}.${ext}`);\n}\n\nexport function getRouteFilePath(filename: string, isTS: boolean): string {\n const ext = isTS ? 'tsx' : 'jsx';\n return path.join(\n process.cwd(),\n APP_DIRECTORY,\n ROUTES_DIRECTORY,\n `${filename}.${ext}`,\n );\n}\n\nexport async function tryRevealAndGetManualInstructions(\n missingFilename: string,\n filePath: string,\n): Promise<boolean> {\n const shouldTryReveal = await clack.confirm({\n message: `Would you like to try running ${chalk.cyan(\n REACT_ROUTER_REVEAL_COMMAND,\n )} to generate entry files?`,\n initialValue: true,\n });\n\n if (shouldTryReveal) {\n try {\n clack.log.info(`Running ${chalk.cyan(REACT_ROUTER_REVEAL_COMMAND)}...`);\n const output = childProcess.execSync(REACT_ROUTER_REVEAL_COMMAND, {\n encoding: 'utf8',\n stdio: 'pipe',\n });\n clack.log.info(output);\n\n if (fs.existsSync(filePath)) {\n clack.log.success(\n `Found ${chalk.cyan(missingFilename)} after running reveal.`,\n );\n return true;\n } else {\n clack.log.warn(\n `${chalk.cyan(\n missingFilename,\n )} still not found after running reveal.`,\n );\n }\n } catch (e) {\n debug('Failed to run React Router reveal command:', e);\n clack.log.warn(\n `Failed to run ${chalk.cyan(\n REACT_ROUTER_REVEAL_COMMAND,\n )}. This command generates entry files for React Router v7.`,\n );\n }\n }\n\n return false; // File still doesn't exist, manual intervention needed\n}\n\nasync function ensureEntryFileExists(\n filename: string,\n filePath: string,\n): Promise<void> {\n if (fs.existsSync(filePath)) {\n return; // File exists, nothing to do\n }\n\n clack.log.warn(`Could not find ${chalk.cyan(filename)}.`);\n\n const fileExists = await tryRevealAndGetManualInstructions(\n filename,\n filePath,\n );\n\n if (!fileExists) {\n throw new Error(\n `Failed to create or find ${filename}. Please create this file manually or ensure your React Router v7 project structure is correct.`,\n );\n }\n}\n\nexport function runReactRouterReveal(): void {\n if (\n !fs.existsSync(path.join(process.cwd(), 'app', 'entry.client.tsx')) &&\n !fs.existsSync(path.join(process.cwd(), 'app', 'entry.client.jsx'))\n ) {\n try {\n childProcess.execSync(REACT_ROUTER_REVEAL_COMMAND, {\n encoding: 'utf8',\n stdio: 'pipe',\n });\n } catch (e) {\n debug('Failed to run React Router reveal command:', e);\n throw e;\n }\n }\n}\n\nexport function isReactRouterV7(packageJson: PackageDotJson): boolean {\n const reactRouterVersion = getPackageVersion(\n '@react-router/dev',\n packageJson,\n );\n if (!reactRouterVersion) {\n return false;\n }\n\n const minVer = minVersion(reactRouterVersion);\n\n if (!minVer) {\n return false;\n }\n\n return gte(minVer, '7.0.0');\n}\n\nexport function getReactRouterVersion(\n packageJson: PackageDotJson,\n): string | undefined {\n const rangeVersion = getPackageVersion('@react-router/dev', packageJson);\n if (!rangeVersion) {\n return undefined;\n }\n\n const coerced = coerce(rangeVersion);\n return coerced ? coerced.version : rangeVersion;\n}\n\nexport function supportsInstrumentationAPI(\n packageJson: PackageDotJson,\n): boolean {\n const reactRouterVersion = getPackageVersion(\n '@react-router/dev',\n packageJson,\n );\n if (!reactRouterVersion) {\n return false;\n }\n\n const minVer = minVersion(reactRouterVersion);\n\n if (!minVer) {\n return false;\n }\n\n return gte(minVer, '7.9.5');\n}\n\nexport async function initializeSentryOnEntryClient(\n dsn: string,\n enableTracing: boolean,\n enableReplay: boolean,\n enableLogs: boolean,\n isTS: boolean,\n useInstrumentationAPI = false,\n): Promise<void> {\n const clientEntryPath = getAppFilePath('entry.client', isTS);\n const clientEntryFilename = path.basename(clientEntryPath);\n\n await ensureEntryFileExists(clientEntryFilename, clientEntryPath);\n\n await instrumentClientEntry(\n clientEntryPath,\n dsn,\n enableTracing,\n enableReplay,\n enableLogs,\n useInstrumentationAPI,\n );\n\n clack.log.success(\n `Updated ${chalk.cyan(clientEntryFilename)} with Sentry initialization.`,\n );\n}\n\nexport async function instrumentRootRoute(isTS: boolean): Promise<void> {\n const rootPath = getAppFilePath('root', isTS);\n const rootFilename = path.basename(rootPath);\n\n if (!fs.existsSync(rootPath)) {\n throw new Error(\n `${rootFilename} not found in app directory. Please ensure your React Router v7 app has a root.tsx/jsx file in the app folder.`,\n );\n }\n\n await instrumentRoot(rootFilename);\n clack.log.success(`Updated ${chalk.cyan(rootFilename)} with ErrorBoundary.`);\n}\n\nexport function createServerInstrumentationFile(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n profiling: boolean;\n },\n): string {\n const instrumentationPath = path.join(process.cwd(), INSTRUMENTATION_FILE);\n\n const content = getSentryInstrumentationServerContent(\n dsn,\n selectedFeatures.performance,\n selectedFeatures.profiling,\n selectedFeatures.logs,\n );\n\n fs.writeFileSync(instrumentationPath, content);\n clack.log.success(`Created ${chalk.cyan(INSTRUMENTATION_FILE)}.`);\n return instrumentationPath;\n}\n\nexport async function updatePackageJsonScripts(): Promise<void> {\n const packageJson = await getPackageDotJson();\n\n if (!packageJson?.scripts) {\n throw new Error(\n 'Could not find a `scripts` section in your package.json file. Please add scripts manually or ensure your package.json is valid.',\n );\n }\n\n if (!packageJson.scripts.start) {\n throw new Error(\n 'Could not find a `start` script in your package.json. Please add: \"start\": \"react-router-serve ./build/server/index.js\" and re-run the wizard.',\n );\n }\n\n function mergeNodeOptions(\n scriptCommand: string,\n instrumentPath = './instrument.server.mjs',\n ): string {\n if (scriptCommand.includes(instrumentPath)) {\n return scriptCommand;\n }\n\n const quotedMatch = scriptCommand.match(/NODE_OPTIONS=(['\"])([^'\"]*)\\1/);\n if (quotedMatch) {\n const existingOptions = quotedMatch[2];\n const mergedOptions =\n `${existingOptions} --import ${instrumentPath}`.trim();\n return scriptCommand.replace(\n /NODE_OPTIONS=(['\"])([^'\"]*)\\1/,\n `NODE_OPTIONS='${mergedOptions}'`,\n );\n }\n\n const unquotedMatch = scriptCommand.match(\n /NODE_OPTIONS=([^\\s]+(?:\\s+[^\\s]+)*?)(\\s+(?:react-router-serve|react-router|node|npx|tsx))/,\n );\n if (unquotedMatch) {\n const existingOptions = unquotedMatch[1];\n const commandPart = unquotedMatch[2];\n const mergedOptions =\n `${existingOptions} --import ${instrumentPath}`.trim();\n return scriptCommand.replace(\n /NODE_OPTIONS=([^\\s]+(?:\\s+[^\\s]+)*?)(\\s+(?:react-router-serve|react-router|node|npx|tsx))/,\n `NODE_OPTIONS='${mergedOptions}'${commandPart}`,\n );\n }\n\n return `NODE_OPTIONS='--import ${instrumentPath}' ${scriptCommand}`;\n }\n\n if (packageJson.scripts.dev) {\n packageJson.scripts.dev = mergeNodeOptions(packageJson.scripts.dev);\n }\n\n const startScript = packageJson.scripts.start;\n if (\n !startScript.includes(INSTRUMENTATION_FILE) &&\n !startScript.includes('NODE_OPTIONS')\n ) {\n packageJson.scripts.start = `NODE_OPTIONS='--import ./${INSTRUMENTATION_FILE}' react-router-serve ./build/server/index.js`;\n } else {\n packageJson.scripts.start = mergeNodeOptions(startScript);\n }\n\n // Prevent React CJS dev/prod bundle mismatch when --import loads react\n // before react-router-serve sets NODE_ENV\n if (\n packageJson.scripts.start.includes('--import') &&\n !packageJson.scripts.start.includes('NODE_ENV=')\n ) {\n packageJson.scripts.start = `NODE_ENV=production ${packageJson.scripts.start}`;\n }\n\n await fs.promises.writeFile(\n 'package.json',\n JSON.stringify(packageJson, null, 2),\n );\n}\n\nexport async function instrumentSentryOnEntryServer(\n isTS: boolean,\n useInstrumentationAPI = false,\n): Promise<void> {\n const serverEntryPath = getAppFilePath('entry.server', isTS);\n const serverEntryFilename = path.basename(serverEntryPath);\n\n await ensureEntryFileExists(serverEntryFilename, serverEntryPath);\n\n await instrumentServerEntry(serverEntryPath, useInstrumentationAPI);\n\n clack.log.success(\n `Updated ${chalk.cyan(serverEntryFilename)} with Sentry error handling.`,\n );\n}\n\nexport async function configureReactRouterVitePlugin(\n orgSlug: string,\n projectSlug: string,\n): Promise<void> {\n const configPath = fs.existsSync(path.join(process.cwd(), 'vite.config.ts'))\n ? path.join(process.cwd(), 'vite.config.ts')\n : path.join(process.cwd(), 'vite.config.js');\n const filename = chalk.cyan(path.basename(configPath));\n\n try {\n const { wasConverted } = await instrumentViteConfig(orgSlug, projectSlug);\n\n clack.log.success(`Updated ${filename} with sentryReactRouter plugin.`);\n\n if (wasConverted) {\n clack.log.info(\n `Converted your Vite config to function form ${chalk.dim(\n '(defineConfig(config => ({ ... })))',\n )} to support the Sentry React Router plugin.`,\n );\n }\n } catch (e) {\n debug('Failed to modify vite config:', e);\n const errorMessage = e instanceof Error ? e.message : String(e);\n throw new Error(\n _formatConfigErrorMessage(\n filename,\n errorMessage,\n 'You may need to add the plugin manually.',\n ),\n );\n }\n}\n\nexport async function configureReactRouterConfig(isTS: boolean): Promise<void> {\n const configFilename = `react-router.config.${isTS ? 'ts' : 'js'}`;\n const configPath = path.join(process.cwd(), configFilename);\n const filename = chalk.cyan(configFilename);\n\n try {\n const fileExistedBefore = fs.existsSync(configPath);\n\n const { ssrWasChanged } = await instrumentReactRouterConfig(isTS);\n\n if (fileExistedBefore) {\n clack.log.success(`Updated ${filename} with Sentry buildEnd hook.`);\n } else {\n clack.log.success(`Created ${filename} with Sentry buildEnd hook.`);\n }\n\n if (ssrWasChanged) {\n clack.log.warn(\n `${chalk.yellow(\n 'Note:',\n )} SSR has been enabled in your React Router config (${chalk.cyan(\n 'ssr: true',\n )}). This is required for Sentry sourcemap uploads to work correctly.`,\n );\n }\n } catch (e) {\n debug('Failed to modify react-router.config:', e);\n const errorMessage = e instanceof Error ? e.message : String(e);\n throw new Error(\n _formatConfigErrorMessage(\n filename,\n errorMessage,\n 'You may need to add the buildEnd hook manually.',\n ),\n );\n }\n}\n"]}
|
|
@@ -2,8 +2,8 @@ export declare const ERROR_BOUNDARY_TEMPLATE: string;
|
|
|
2
2
|
export declare const EXAMPLE_PAGE_TEMPLATE_TSX = "import type { Route } from \"./+types/sentry-example-page\";\n\nexport async function loader() {\n throw new Error(\"some error thrown in a loader\");\n}\n\nexport default function SentryExamplePage() {\n return <div>Loading this page will throw an error</div>;\n}";
|
|
3
3
|
export declare const EXAMPLE_PAGE_TEMPLATE_JSX = "export async function loader() {\n throw new Error(\"some error thrown in a loader\");\n}\n\nexport default function SentryExamplePage() {\n return <div>Loading this page will throw an error</div>;\n}";
|
|
4
4
|
export declare const getSentryInstrumentationServerContent: (dsn: string, enableTracing: boolean, enableProfiling?: boolean, enableLogs?: boolean) => string;
|
|
5
|
-
export declare const getManualClientEntryContent: (dsn: string, enableTracing: boolean, enableReplay: boolean, enableLogs: boolean) => string;
|
|
6
|
-
export declare const getManualServerEntryContent: () => string;
|
|
5
|
+
export declare const getManualClientEntryContent: (dsn: string, enableTracing: boolean, enableReplay: boolean, enableLogs: boolean, useInstrumentationAPI?: boolean) => string;
|
|
6
|
+
export declare const getManualServerEntryContent: (useInstrumentationAPI?: boolean) => string;
|
|
7
7
|
export declare const getManualHandleRequestContent: () => string;
|
|
8
8
|
export declare const getManualRootContent: (isTs: boolean) => string;
|
|
9
9
|
export declare const getManualServerInstrumentContent: (dsn: string, enableTracing: boolean, enableProfiling: boolean, enableLogs?: boolean) => string;
|