@sentry/wizard 5.4.0 → 6.1.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 +14 -0
- package/dist/e2e-tests/tests/angular-17.test.js +6 -0
- package/dist/e2e-tests/tests/angular-17.test.js.map +1 -1
- package/dist/e2e-tests/tests/angular-19.test.js +7 -1
- package/dist/e2e-tests/tests/angular-19.test.js.map +1 -1
- package/dist/e2e-tests/tests/nextjs-14.test.js +5 -1
- package/dist/e2e-tests/tests/nextjs-14.test.js.map +1 -1
- package/dist/e2e-tests/tests/nextjs-15.test.js +5 -1
- package/dist/e2e-tests/tests/nextjs-15.test.js.map +1 -1
- package/dist/e2e-tests/tests/nuxt-3.test.js +9 -1
- package/dist/e2e-tests/tests/nuxt-3.test.js.map +1 -1
- package/dist/e2e-tests/tests/nuxt-4.test.js +9 -1
- package/dist/e2e-tests/tests/nuxt-4.test.js.map +1 -1
- package/dist/e2e-tests/tests/remix.test.js +8 -2
- package/dist/e2e-tests/tests/remix.test.js.map +1 -1
- package/dist/e2e-tests/tests/sveltekit.test.js +15 -3
- package/dist/e2e-tests/tests/sveltekit.test.js.map +1 -1
- package/dist/src/angular/angular-wizard.js +5 -0
- package/dist/src/angular/angular-wizard.js.map +1 -1
- package/dist/src/angular/codemods/main.d.ts +4 -1
- package/dist/src/angular/codemods/main.js +3 -0
- package/dist/src/angular/codemods/main.js.map +1 -1
- package/dist/src/angular/sdk-setup.d.ts +1 -0
- package/dist/src/angular/sdk-setup.js.map +1 -1
- package/dist/src/apple/xcode-manager.d.ts +5 -0
- package/dist/src/apple/xcode-manager.js +44 -40
- package/dist/src/apple/xcode-manager.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +5 -0
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.d.ts +3 -0
- package/dist/src/nextjs/templates.js +15 -2
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/nuxt/sdk-setup.js +5 -0
- package/dist/src/nuxt/sdk-setup.js.map +1 -1
- package/dist/src/nuxt/templates.d.ts +1 -0
- package/dist/src/nuxt/templates.js +3 -2
- package/dist/src/nuxt/templates.js.map +1 -1
- package/dist/src/remix/codemods/handle-error.js +3 -6
- package/dist/src/remix/codemods/handle-error.js.map +1 -1
- package/dist/src/remix/codemods/{root-common.d.ts → root.d.ts} +1 -0
- package/dist/src/remix/codemods/{root-v2.js → root.js} +47 -12
- package/dist/src/remix/codemods/root.js.map +1 -0
- package/dist/src/remix/remix-wizard.js +12 -5
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/remix/sdk-setup.d.ts +8 -11
- package/dist/src/remix/sdk-setup.js +13 -18
- package/dist/src/remix/sdk-setup.js.map +1 -1
- package/dist/src/remix/templates.d.ts +2 -2
- package/dist/src/remix/templates.js +3 -3
- package/dist/src/remix/templates.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup.js +11 -0
- package/dist/src/sveltekit/sdk-setup.js.map +1 -1
- package/dist/src/sveltekit/templates.d.ts +2 -0
- package/dist/src/sveltekit/templates.js +10 -0
- package/dist/src/sveltekit/templates.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/nextjs/templates.test.js +119 -0
- package/dist/test/nextjs/templates.test.js.map +1 -1
- package/dist/test/nuxt/templates.test.js +119 -0
- package/dist/test/nuxt/templates.test.js.map +1 -1
- package/dist/test/remix/client-entry.test.js +56 -0
- package/dist/test/remix/client-entry.test.js.map +1 -1
- package/dist/test/remix/root.test.d.ts +1 -0
- package/dist/test/remix/root.test.js +31 -0
- package/dist/test/remix/root.test.js.map +1 -0
- package/dist/test/remix/server-instrumentation.test.js +37 -1
- package/dist/test/remix/server-instrumentation.test.js.map +1 -1
- package/dist/test/sveltekit/templates.test.js +67 -0
- package/dist/test/sveltekit/templates.test.js.map +1 -1
- package/package.json +1 -1
- package/dist/src/remix/codemods/root-common.js +0 -70
- package/dist/src/remix/codemods/root-common.js.map +0 -1
- package/dist/src/remix/codemods/root-v1.d.ts +0 -1
- package/dist/src/remix/codemods/root-v1.js +0 -52
- package/dist/src/remix/codemods/root-v1.js.map +0 -1
- package/dist/src/remix/codemods/root-v2.d.ts +0 -1
- package/dist/src/remix/codemods/root-v2.js.map +0 -1
|
@@ -39,8 +39,7 @@ const semver_1 = require("semver");
|
|
|
39
39
|
const magicast_1 = require("magicast");
|
|
40
40
|
const package_json_1 = require("../utils/package-json");
|
|
41
41
|
const utils_1 = require("./utils");
|
|
42
|
-
const
|
|
43
|
-
const root_v2_1 = require("./codemods/root-v2");
|
|
42
|
+
const root_1 = require("./codemods/root");
|
|
44
43
|
const handle_error_1 = require("./codemods/handle-error");
|
|
45
44
|
const clack_1 = require("../utils/clack");
|
|
46
45
|
const express_server_1 = require("./codemods/express-server");
|
|
@@ -69,6 +68,10 @@ function getInitCallArgs(dsn, type, selectedFeatures) {
|
|
|
69
68
|
if (selectedFeatures.performance) {
|
|
70
69
|
initCallArgs.tracesSampleRate = 1.0;
|
|
71
70
|
}
|
|
71
|
+
// Adding logs for both client and server
|
|
72
|
+
if (selectedFeatures.logs) {
|
|
73
|
+
initCallArgs.enableLogs = true;
|
|
74
|
+
}
|
|
72
75
|
// Adding integrations and replay options only for client
|
|
73
76
|
if (type === 'client' &&
|
|
74
77
|
(selectedFeatures.performance || selectedFeatures.replay)) {
|
|
@@ -143,7 +146,7 @@ Skipping adding instrumentation functionality to ${chalk_1.default.cyan(path.bas
|
|
|
143
146
|
return true;
|
|
144
147
|
}
|
|
145
148
|
exports.insertServerInstrumentationFile = insertServerInstrumentationFile;
|
|
146
|
-
function isRemixV2(
|
|
149
|
+
function isRemixV2(packageJson) {
|
|
147
150
|
const remixVersion = (0, package_json_1.getPackageVersion)('@remix-run/react', packageJson);
|
|
148
151
|
if (!remixVersion) {
|
|
149
152
|
return false;
|
|
@@ -152,8 +155,7 @@ function isRemixV2(remixConfig, packageJson) {
|
|
|
152
155
|
if (!minVer) {
|
|
153
156
|
return false;
|
|
154
157
|
}
|
|
155
|
-
|
|
156
|
-
return isV2Remix || remixConfig?.future?.v2_errorBoundary || false;
|
|
158
|
+
return (0, semver_1.gte)(minVer, '2.0.0');
|
|
157
159
|
}
|
|
158
160
|
exports.isRemixV2 = isRemixV2;
|
|
159
161
|
async function loadRemixConfig() {
|
|
@@ -177,14 +179,9 @@ async function loadRemixConfig() {
|
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
181
|
exports.loadRemixConfig = loadRemixConfig;
|
|
180
|
-
async function instrumentRootRoute(
|
|
182
|
+
async function instrumentRootRoute(isTS) {
|
|
181
183
|
const rootFilename = `root.${isTS ? 'tsx' : 'jsx'}`;
|
|
182
|
-
|
|
183
|
-
await (0, root_v2_1.instrumentRootRouteV2)(rootFilename);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
await (0, root_v1_1.instrumentRootRouteV1)(rootFilename);
|
|
187
|
-
}
|
|
184
|
+
await (0, root_1.instrumentRoot)(rootFilename);
|
|
188
185
|
prompts_1.default.log.success(`Successfully instrumented root route ${chalk_1.default.cyan(rootFilename)}.`);
|
|
189
186
|
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
|
|
190
187
|
}
|
|
@@ -285,7 +282,7 @@ async function updateStartScript(instrumentationFile) {
|
|
|
285
282
|
prompts_1.default.log.success(`Successfully updated ${chalk_1.default.cyan('start')} script in ${chalk_1.default.cyan('package.json')} to include Sentry initialization on start.`);
|
|
286
283
|
}
|
|
287
284
|
exports.updateStartScript = updateStartScript;
|
|
288
|
-
async function instrumentSentryOnEntryServer(
|
|
285
|
+
async function instrumentSentryOnEntryServer(isTS) {
|
|
289
286
|
const serverEntryFilename = `entry.server.${isTS ? 'tsx' : 'jsx'}`;
|
|
290
287
|
const originalEntryServer = path.join(process.cwd(), 'app', serverEntryFilename);
|
|
291
288
|
const originalEntryServerMod = await (0, magicast_1.loadFile)(originalEntryServer);
|
|
@@ -297,11 +294,9 @@ async function instrumentSentryOnEntryServer(isV2, isTS) {
|
|
|
297
294
|
imported: '*',
|
|
298
295
|
local: 'Sentry',
|
|
299
296
|
});
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
prompts_1.default.log.success(`Instrumented ${chalk_1.default.cyan('handleError')} in ${chalk_1.default.cyan(`${serverEntryFilename}`)}`);
|
|
304
|
-
}
|
|
297
|
+
const handleErrorInstrumented = (0, handle_error_1.instrumentHandleError)(originalEntryServerMod, serverEntryFilename);
|
|
298
|
+
if (handleErrorInstrumented) {
|
|
299
|
+
prompts_1.default.log.success(`Instrumented ${chalk_1.default.cyan('handleError')} in ${chalk_1.default.cyan(`${serverEntryFilename}`)}`);
|
|
305
300
|
}
|
|
306
301
|
await (0, magicast_1.writeFile)(originalEntryServerMod.$ast, path.join(process.cwd(), 'app', serverEntryFilename));
|
|
307
302
|
prompts_1.default.log.success(`Successfully initialized Sentry on server entry point ${chalk_1.default.cyan(serverEntryFilename)}.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-setup.js","sourceRoot":"","sources":["../../../src/remix/sdk-setup.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAO5D,uCAAyB;AACzB,2CAA6B;AAC7B,yCAA2B;AAC3B,4DAA8C;AAE9C,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,mCAAyC;AAEzC,uCAOkB;AAElB,wDAA0D;AAC1D,mCAIiB;AACjB,gDAA2D;AAC3D,gDAA2D;AAC3D,0DAAgE;AAChE,0CAAmD;AACnD,8DAAkF;AAclF,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAC5C,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAEhD,SAAgB,cAAc,CAAC,IAAa;IAC1C,qCAAqC;IACrC,MAAM,mBAAmB,GAAG,gBAAgB,IAAI,CAAC,CAAC,CA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,OAAO;KACR;IAED,sBAAsB,CAAC,OAAO,CAAC,IAAI,CAAC;QAClC,IAAI,EAAE,eAAe;QACrB,QAAQ,EAAE,GAAG;QACb,KAAK,EAAE,QAAQ;KAChB,CAAC,CAAC;IAEH,IAAI,IAAI,EAAE;QACR,MAAM,uBAAuB,GAAG,IAAA,oCAAqB,EACnD,sBAAsB,EACtB,mBAAmB,CACpB,CAAC;QAEF,IAAI,uBAAuB,EAAE;YAC3B,iBAAK,CAAC,GAAG,CAAC,OAAO,CACf,gBAAgB,eAAK,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,eAAK,CAAC,IAAI,CACxD,GAAG,mBAAmB,EAAE,CACzB,EAAE,CACJ,CAAC;SACH;KACF;IAED,MAAM,IAAA,oBAAS,EACb,sBAAsB,CAAC,IAAI,EAC3B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,mBAAmB,CAAC,CACrD,CAAC;IAEF,iBAAK,CAAC,GAAG,CAAC,OAAO,CACf,yDAAyD,eAAK,CAAC,IAAI,CACjE,mBAAmB,CACpB,GAAG,CACL,CAAC;AACJ,CAAC;AAjDD,sEAiDC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport type { Program } from '@babel/types';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { Proxified, ProxifiedModule } from 'magicast';\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as url from 'url';\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 {\n builders,\n generateCode,\n loadFile,\n parseModule,\n writeFile,\n // @ts-expect-error - magicast is ESM and TS complains about that. It works though\n} from 'magicast';\nimport type { PackageDotJson } from '../utils/package-json';\nimport { getPackageVersion } from '../utils/package-json';\nimport {\n getAfterImportsInsertionIndex,\n hasSentryContent,\n serverHasInstrumentationImport,\n} from './utils';\nimport { instrumentRootRouteV1 } from './codemods/root-v1';\nimport { instrumentRootRouteV2 } from './codemods/root-v2';\nimport { instrumentHandleError } from './codemods/handle-error';\nimport { getPackageDotJson } from '../utils/clack';\nimport { findCustomExpressServerImplementation } from './codemods/express-server';\n\nexport type PartialRemixConfig = {\n unstable_dev?: boolean;\n future?: {\n v2_dev?: boolean;\n v2_errorBoundary?: boolean;\n v2_headers?: boolean;\n v2_meta?: boolean;\n v2_normalizeFormMethod?: boolean;\n v2_routeConvention?: boolean;\n };\n};\n\nconst REMIX_CONFIG_FILE = 'remix.config.js';\nconst REMIX_REVEAL_COMMAND = 'npx remix reveal';\n\nexport function runRemixReveal(isTS: boolean): void {\n // Check if entry files already exist\n const clientEntryFilename = `entry.client.${isTS ? 'tsx' : 'jsx'}`;\n const serverEntryFilename = `entry.server.${isTS ? 'tsx' : 'jsx'}`;\n\n const clientEntryPath = path.join(process.cwd(), 'app', clientEntryFilename);\n const serverEntryPath = path.join(process.cwd(), 'app', serverEntryFilename);\n\n if (fs.existsSync(clientEntryPath) && fs.existsSync(serverEntryPath)) {\n clack.log.info(\n `Found entry files ${chalk.cyan(clientEntryFilename)} and ${chalk.cyan(\n serverEntryFilename,\n )}.`,\n );\n } else {\n clack.log.info(\n `Couldn't find entry files in your project. Trying to run ${chalk.cyan(\n REMIX_REVEAL_COMMAND,\n )}...`,\n );\n\n clack.log.info(childProcess.execSync(REMIX_REVEAL_COMMAND).toString());\n }\n}\n\ninterface SdkAstOptions {\n dsn: string;\n tracesSampleRate?: number;\n replaysSessionSampleRate?: number;\n replaysOnErrorSampleRate?: number;\n integrations?: Array<Proxified>;\n}\n\nfunction getInitCallArgs(\n dsn: string,\n type: 'client' | 'server',\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n },\n) {\n const initCallArgs: SdkAstOptions = {\n dsn,\n };\n\n // Adding tracing sample rate for both client and server\n if (selectedFeatures.performance) {\n initCallArgs.tracesSampleRate = 1.0;\n }\n\n // Adding integrations and replay options only for client\n if (\n type === 'client' &&\n (selectedFeatures.performance || selectedFeatures.replay)\n ) {\n initCallArgs.integrations = [] as Array<Proxified>;\n\n if (selectedFeatures.performance) {\n initCallArgs.integrations.push(\n builders.functionCall(\n 'browserTracingIntegration',\n builders.raw('{ useEffect, useLocation, useMatches }'),\n ),\n );\n }\n\n if (selectedFeatures.replay) {\n initCallArgs.integrations.push(\n builders.functionCall('replayIntegration', {\n maskAllText: true,\n blockAllMedia: true,\n }),\n );\n\n initCallArgs.replaysSessionSampleRate = 0.1;\n initCallArgs.replaysOnErrorSampleRate = 1.0;\n }\n }\n\n return initCallArgs;\n}\n\nfunction insertClientInitCall(\n dsn: string,\n // MagicAst returns `ProxifiedModule<any>` so therefore we have to use `any` here\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalHooksMod: ProxifiedModule<any>,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n },\n): void {\n const initCallArgs = getInitCallArgs(dsn, 'client', selectedFeatures);\n const initCall = builders.functionCall('init', initCallArgs);\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n const initCallInsertionIndex =\n getAfterImportsInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n}\n\nexport function generateServerInstrumentationFile(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n },\n) {\n // create an empty file named `instrument.server.mjs`\n const instrumentationFile = 'instrumentation.server.mjs';\n const instrumentationFileMod = parseModule('');\n\n instrumentationFileMod.imports.$add({\n from: '@sentry/remix',\n imported: '*',\n local: 'Sentry',\n });\n\n const initCallArgs = getInitCallArgs(dsn, 'server', selectedFeatures);\n const initCall = builders.functionCall('Sentry.init', initCallArgs);\n\n const instrumentationFileModAST = instrumentationFileMod.$ast as Program;\n\n const initCallInsertionIndex = getAfterImportsInsertionIndex(\n instrumentationFileModAST,\n );\n\n instrumentationFileModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n\n return { instrumentationFile, instrumentationFileMod };\n}\n\nexport async function createServerInstrumentationFile(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n },\n) {\n const { instrumentationFile, instrumentationFileMod } =\n generateServerInstrumentationFile(dsn, selectedFeatures);\n\n await writeFile(instrumentationFileMod.$ast, instrumentationFile);\n\n return instrumentationFile;\n}\n\nexport async function insertServerInstrumentationFile(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n },\n) {\n const instrumentationFile = await createServerInstrumentationFile(\n dsn,\n selectedFeatures,\n );\n\n const expressServerPath = await findCustomExpressServerImplementation();\n\n if (!expressServerPath) {\n return false;\n }\n\n const originalExpressServerMod = await loadFile(expressServerPath);\n\n if (\n serverHasInstrumentationImport(\n expressServerPath,\n originalExpressServerMod.$code,\n )\n ) {\n clack.log.warn(\n `File ${chalk.cyan(\n path.basename(expressServerPath),\n )} already contains instrumentation import.\nSkipping adding instrumentation functionality to ${chalk.cyan(\n path.basename(expressServerPath),\n )}.`,\n );\n\n return true;\n }\n\n originalExpressServerMod.$code = `import './${instrumentationFile}';\\n${originalExpressServerMod.$code}`;\n\n fs.writeFileSync(expressServerPath, originalExpressServerMod.$code);\n\n return true;\n}\n\nexport function isRemixV2(\n remixConfig: PartialRemixConfig,\n packageJson: PackageDotJson,\n): boolean {\n const remixVersion = getPackageVersion('@remix-run/react', packageJson);\n if (!remixVersion) {\n return false;\n }\n\n const minVer = minVersion(remixVersion);\n\n if (!minVer) {\n return false;\n }\n\n const isV2Remix = gte(minVer, '2.0.0');\n\n return isV2Remix || remixConfig?.future?.v2_errorBoundary || false;\n}\n\nexport async function loadRemixConfig(): Promise<PartialRemixConfig> {\n const configFilePath = path.join(process.cwd(), REMIX_CONFIG_FILE);\n\n try {\n if (!fs.existsSync(configFilePath)) {\n return {};\n }\n\n const configUrl = url.pathToFileURL(configFilePath).href;\n const remixConfigModule = (await import(configUrl)) as {\n default: PartialRemixConfig;\n };\n\n return remixConfigModule?.default || {};\n } catch (e: unknown) {\n clack.log.error(`Couldn't load ${REMIX_CONFIG_FILE}.`);\n clack.log.info(\n chalk.dim(\n typeof e === 'object' && e != null && 'toString' in e\n ? e.toString()\n : typeof e === 'string'\n ? e\n : 'Unknown error',\n ),\n );\n\n return {};\n }\n}\n\nexport async function instrumentRootRoute(\n isV2?: boolean,\n isTS?: boolean,\n): Promise<void> {\n const rootFilename = `root.${isTS ? 'tsx' : 'jsx'}`;\n\n if (isV2) {\n await instrumentRootRouteV2(rootFilename);\n } else {\n await instrumentRootRouteV1(rootFilename);\n }\n\n clack.log.success(\n `Successfully instrumented root route ${chalk.cyan(rootFilename)}.`,\n );\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n}\n\nexport async function updateBuildScript(args: {\n org: string;\n project: string;\n url?: string;\n isHydrogen: boolean;\n}): Promise<void> {\n const packageJson = await getPackageDotJson();\n\n if (!packageJson.scripts) {\n packageJson.scripts = {};\n }\n\n const buildCommand = args.isHydrogen\n ? 'shopify hydrogen build'\n : 'remix build';\n\n const instrumentedBuildCommand =\n `${buildCommand} --sourcemap && sentry-upload-sourcemaps --org ${args.org} --project ${args.project}` +\n (args.url ? ` --url ${args.url}` : '') +\n (args.isHydrogen ? ' --buildPath ./dist' : '');\n\n if (!packageJson.scripts.build) {\n packageJson.scripts.build = instrumentedBuildCommand;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n } else if (packageJson.scripts.build.includes(buildCommand)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n packageJson.scripts.build = packageJson.scripts.build.replace(\n buildCommand,\n instrumentedBuildCommand,\n );\n } else {\n throw new Error(\n \"`build` script doesn't contain a known build command. Please update it manually.\",\n );\n }\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageJson, null, 2),\n );\n\n clack.log.success(\n `Successfully updated ${chalk.cyan('build')} script in ${chalk.cyan(\n 'package.json',\n )} to generate and upload sourcemaps.`,\n );\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n}\n\nexport function updateEntryClientMod(\n // MagicAst returns `ProxifiedModule<any>` so therefore we have to use `any` here\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalEntryClientMod: ProxifiedModule<any>,\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): ProxifiedModule<any> {\n const imports = ['init'];\n if (selectedFeatures.replay) {\n imports.push('replayIntegration');\n }\n if (selectedFeatures.performance) {\n imports.push('browserTracingIntegration');\n }\n originalEntryClientMod.imports.$add({\n from: '@sentry/remix',\n imported: `${imports.join(', ')}`,\n });\n\n if (selectedFeatures.performance) {\n originalEntryClientMod.imports.$add({\n from: '@remix-run/react',\n imported: 'useLocation',\n local: 'useLocation',\n });\n\n originalEntryClientMod.imports.$add({\n from: '@remix-run/react',\n imported: 'useMatches',\n local: 'useMatches',\n });\n\n originalEntryClientMod.imports.$add({\n from: 'react',\n imported: 'useEffect',\n local: 'useEffect',\n });\n }\n\n insertClientInitCall(dsn, originalEntryClientMod, selectedFeatures);\n\n return originalEntryClientMod;\n}\n\nexport async function initializeSentryOnEntryClient(\n dsn: string,\n isTS: boolean,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n },\n): Promise<void> {\n const clientEntryFilename = `entry.client.${isTS ? 'tsx' : 'jsx'}`;\n\n const originalEntryClient = path.join(\n process.cwd(),\n 'app',\n clientEntryFilename,\n );\n\n const originalEntryClientMod = await loadFile(originalEntryClient);\n\n if (hasSentryContent(originalEntryClient, originalEntryClientMod.$code)) {\n return;\n }\n\n const updatedEntryClientMod = updateEntryClientMod(\n originalEntryClientMod,\n dsn,\n selectedFeatures,\n );\n\n await writeFile(\n updatedEntryClientMod.$ast,\n path.join(process.cwd(), 'app', clientEntryFilename),\n );\n\n clack.log.success(\n `Successfully initialized Sentry on client entry point ${chalk.cyan(\n clientEntryFilename,\n )}`,\n );\n}\n\nexport async function updateStartScript(instrumentationFile: string) {\n const packageJson = await getPackageDotJson();\n\n if (!packageJson.scripts || !packageJson.scripts.start) {\n throw new Error(\n \"Couldn't find a `start` script in your package.json. Please add one manually.\",\n );\n }\n\n if (packageJson.scripts.start.includes('NODE_OPTIONS')) {\n clack.log.warn(\n `Found existing NODE_OPTIONS in ${chalk.cyan(\n 'start',\n )} script. Skipping adding Sentry initialization.`,\n );\n\n return;\n }\n\n if (\n !packageJson.scripts.start.includes('remix-serve') &&\n // Adding a following empty space not to match a path that includes `node`\n !packageJson.scripts.start.includes('node ')\n ) {\n clack.log.warn(\n `Found a ${chalk.cyan('start')} script that doesn't use ${chalk.cyan(\n 'remix-serve',\n )} or ${chalk.cyan('node')}. Skipping adding Sentry initialization.`,\n );\n\n return;\n }\n\n const startCommand = packageJson.scripts.start;\n\n packageJson.scripts.start = `NODE_OPTIONS='--import ./${instrumentationFile}' ${startCommand}`;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageJson, null, 2),\n );\n\n clack.log.success(\n `Successfully updated ${chalk.cyan('start')} script in ${chalk.cyan(\n 'package.json',\n )} to include Sentry initialization on start.`,\n );\n}\n\nexport async function instrumentSentryOnEntryServer(\n isV2: boolean,\n isTS: boolean,\n): Promise<void> {\n const serverEntryFilename = `entry.server.${isTS ? 'tsx' : 'jsx'}`;\n\n const originalEntryServer = path.join(\n process.cwd(),\n 'app',\n serverEntryFilename,\n );\n\n const originalEntryServerMod = await loadFile(originalEntryServer);\n\n if (hasSentryContent(originalEntryServer, originalEntryServerMod.$code)) {\n return;\n }\n\n originalEntryServerMod.imports.$add({\n from: '@sentry/remix',\n imported: '*',\n local: 'Sentry',\n });\n\n if (isV2) {\n const handleErrorInstrumented = instrumentHandleError(\n originalEntryServerMod,\n serverEntryFilename,\n );\n\n if (handleErrorInstrumented) {\n clack.log.success(\n `Instrumented ${chalk.cyan('handleError')} in ${chalk.cyan(\n `${serverEntryFilename}`,\n )}`,\n );\n }\n }\n\n await writeFile(\n originalEntryServerMod.$ast,\n path.join(process.cwd(), 'app', serverEntryFilename),\n );\n\n clack.log.success(\n `Successfully initialized Sentry on server entry point ${chalk.cyan(\n serverEntryFilename,\n )}.`,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sdk-setup.js","sourceRoot":"","sources":["../../../src/remix/sdk-setup.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAO5D,uCAAyB;AACzB,2CAA6B;AAC7B,yCAA2B;AAC3B,4DAA8C;AAE9C,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,mCAAyC;AAEzC,uCAOkB;AAElB,wDAA0D;AAC1D,mCAIiB;AACjB,0CAAiD;AACjD,0DAAgE;AAChE,0CAAmD;AACnD,8DAAkF;AAMlF,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAC5C,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAEhD,SAAgB,cAAc,CAAC,IAAa;IAC1C,qCAAqC;IACrC,MAAM,mBAAmB,GAAG,gBAAgB,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;IACnE,MAAM,mBAAmB,GAAG,gBAAgB,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;IAEnE,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC;IAC7E,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,mBAAmB,CAAC,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C,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,mBAAmB,CAAC,CACrD,CAAC;IAEF,iBAAK,CAAC,GAAG,CAAC,OAAO,CACf,yDAAyD,eAAK,CAAC,IAAI,CACjE,mBAAmB,CACpB,GAAG,CACL,CAAC;AACJ,CAAC;AA9CD,sEA8CC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport type { Program } from '@babel/types';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { Proxified, ProxifiedModule } from 'magicast';\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as url from 'url';\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 {\n builders,\n generateCode,\n loadFile,\n parseModule,\n writeFile,\n // @ts-expect-error - magicast is ESM and TS complains about that. It works though\n} from 'magicast';\nimport type { PackageDotJson } from '../utils/package-json';\nimport { getPackageVersion } from '../utils/package-json';\nimport {\n getAfterImportsInsertionIndex,\n hasSentryContent,\n serverHasInstrumentationImport,\n} from './utils';\nimport { instrumentRoot } from './codemods/root';\nimport { instrumentHandleError } from './codemods/handle-error';\nimport { getPackageDotJson } from '../utils/clack';\nimport { findCustomExpressServerImplementation } from './codemods/express-server';\n\nexport type PartialRemixConfig = {\n unstable_dev?: boolean;\n};\n\nconst REMIX_CONFIG_FILE = 'remix.config.js';\nconst REMIX_REVEAL_COMMAND = 'npx remix reveal';\n\nexport function runRemixReveal(isTS: boolean): void {\n // Check if entry files already exist\n const clientEntryFilename = `entry.client.${isTS ? 'tsx' : 'jsx'}`;\n const serverEntryFilename = `entry.server.${isTS ? 'tsx' : 'jsx'}`;\n\n const clientEntryPath = path.join(process.cwd(), 'app', clientEntryFilename);\n const serverEntryPath = path.join(process.cwd(), 'app', serverEntryFilename);\n\n if (fs.existsSync(clientEntryPath) && fs.existsSync(serverEntryPath)) {\n clack.log.info(\n `Found entry files ${chalk.cyan(clientEntryFilename)} and ${chalk.cyan(\n serverEntryFilename,\n )}.`,\n );\n } else {\n clack.log.info(\n `Couldn't find entry files in your project. Trying to run ${chalk.cyan(\n REMIX_REVEAL_COMMAND,\n )}...`,\n );\n\n clack.log.info(childProcess.execSync(REMIX_REVEAL_COMMAND).toString());\n }\n}\n\ninterface SdkAstOptions {\n dsn: string;\n tracesSampleRate?: number;\n replaysSessionSampleRate?: number;\n replaysOnErrorSampleRate?: number;\n integrations?: Array<Proxified>;\n enableLogs?: boolean;\n}\n\nfunction getInitCallArgs(\n dsn: string,\n type: 'client' | 'server',\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n) {\n const initCallArgs: SdkAstOptions = {\n dsn,\n };\n\n // Adding tracing sample rate for both client and server\n if (selectedFeatures.performance) {\n initCallArgs.tracesSampleRate = 1.0;\n }\n\n // Adding logs for both client and server\n if (selectedFeatures.logs) {\n initCallArgs.enableLogs = true;\n }\n\n // Adding integrations and replay options only for client\n if (\n type === 'client' &&\n (selectedFeatures.performance || selectedFeatures.replay)\n ) {\n initCallArgs.integrations = [] as Array<Proxified>;\n\n if (selectedFeatures.performance) {\n initCallArgs.integrations.push(\n builders.functionCall(\n 'browserTracingIntegration',\n builders.raw('{ useEffect, useLocation, useMatches }'),\n ),\n );\n }\n\n if (selectedFeatures.replay) {\n initCallArgs.integrations.push(\n builders.functionCall('replayIntegration', {\n maskAllText: true,\n blockAllMedia: true,\n }),\n );\n\n initCallArgs.replaysSessionSampleRate = 0.1;\n initCallArgs.replaysOnErrorSampleRate = 1.0;\n }\n }\n\n return initCallArgs;\n}\n\nfunction insertClientInitCall(\n dsn: string,\n // MagicAst returns `ProxifiedModule<any>` so therefore we have to use `any` here\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalHooksMod: ProxifiedModule<any>,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n): void {\n const initCallArgs = getInitCallArgs(dsn, 'client', selectedFeatures);\n const initCall = builders.functionCall('init', initCallArgs);\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n const initCallInsertionIndex =\n getAfterImportsInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n}\n\nexport function generateServerInstrumentationFile(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n) {\n // create an empty file named `instrument.server.mjs`\n const instrumentationFile = 'instrumentation.server.mjs';\n const instrumentationFileMod = parseModule('');\n\n instrumentationFileMod.imports.$add({\n from: '@sentry/remix',\n imported: '*',\n local: 'Sentry',\n });\n\n const initCallArgs = getInitCallArgs(dsn, 'server', selectedFeatures);\n const initCall = builders.functionCall('Sentry.init', initCallArgs);\n\n const instrumentationFileModAST = instrumentationFileMod.$ast as Program;\n\n const initCallInsertionIndex = getAfterImportsInsertionIndex(\n instrumentationFileModAST,\n );\n\n instrumentationFileModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n\n return { instrumentationFile, instrumentationFileMod };\n}\n\nexport async function createServerInstrumentationFile(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n) {\n const { instrumentationFile, instrumentationFileMod } =\n generateServerInstrumentationFile(dsn, selectedFeatures);\n\n await writeFile(instrumentationFileMod.$ast, instrumentationFile);\n\n return instrumentationFile;\n}\n\nexport async function insertServerInstrumentationFile(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n) {\n const instrumentationFile = await createServerInstrumentationFile(\n dsn,\n selectedFeatures,\n );\n\n const expressServerPath = await findCustomExpressServerImplementation();\n\n if (!expressServerPath) {\n return false;\n }\n\n const originalExpressServerMod = await loadFile(expressServerPath);\n\n if (\n serverHasInstrumentationImport(\n expressServerPath,\n originalExpressServerMod.$code,\n )\n ) {\n clack.log.warn(\n `File ${chalk.cyan(\n path.basename(expressServerPath),\n )} already contains instrumentation import.\nSkipping adding instrumentation functionality to ${chalk.cyan(\n path.basename(expressServerPath),\n )}.`,\n );\n\n return true;\n }\n\n originalExpressServerMod.$code = `import './${instrumentationFile}';\\n${originalExpressServerMod.$code}`;\n\n fs.writeFileSync(expressServerPath, originalExpressServerMod.$code);\n\n return true;\n}\n\nexport function isRemixV2(packageJson: PackageDotJson): boolean {\n const remixVersion = getPackageVersion('@remix-run/react', packageJson);\n if (!remixVersion) {\n return false;\n }\n\n const minVer = minVersion(remixVersion);\n\n if (!minVer) {\n return false;\n }\n\n return gte(minVer, '2.0.0');\n}\n\nexport async function loadRemixConfig(): Promise<PartialRemixConfig> {\n const configFilePath = path.join(process.cwd(), REMIX_CONFIG_FILE);\n\n try {\n if (!fs.existsSync(configFilePath)) {\n return {};\n }\n\n const configUrl = url.pathToFileURL(configFilePath).href;\n const remixConfigModule = (await import(configUrl)) as {\n default: PartialRemixConfig;\n };\n\n return remixConfigModule?.default || {};\n } catch (e: unknown) {\n clack.log.error(`Couldn't load ${REMIX_CONFIG_FILE}.`);\n clack.log.info(\n chalk.dim(\n typeof e === 'object' && e != null && 'toString' in e\n ? e.toString()\n : typeof e === 'string'\n ? e\n : 'Unknown error',\n ),\n );\n\n return {};\n }\n}\n\nexport async function instrumentRootRoute(isTS?: boolean): Promise<void> {\n const rootFilename = `root.${isTS ? 'tsx' : 'jsx'}`;\n\n await instrumentRoot(rootFilename);\n\n clack.log.success(\n `Successfully instrumented root route ${chalk.cyan(rootFilename)}.`,\n );\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n}\n\nexport async function updateBuildScript(args: {\n org: string;\n project: string;\n url?: string;\n isHydrogen: boolean;\n}): Promise<void> {\n const packageJson = await getPackageDotJson();\n\n if (!packageJson.scripts) {\n packageJson.scripts = {};\n }\n\n const buildCommand = args.isHydrogen\n ? 'shopify hydrogen build'\n : 'remix build';\n\n const instrumentedBuildCommand =\n `${buildCommand} --sourcemap && sentry-upload-sourcemaps --org ${args.org} --project ${args.project}` +\n (args.url ? ` --url ${args.url}` : '') +\n (args.isHydrogen ? ' --buildPath ./dist' : '');\n\n if (!packageJson.scripts.build) {\n packageJson.scripts.build = instrumentedBuildCommand;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n } else if (packageJson.scripts.build.includes(buildCommand)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n packageJson.scripts.build = packageJson.scripts.build.replace(\n buildCommand,\n instrumentedBuildCommand,\n );\n } else {\n throw new Error(\n \"`build` script doesn't contain a known build command. Please update it manually.\",\n );\n }\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageJson, null, 2),\n );\n\n clack.log.success(\n `Successfully updated ${chalk.cyan('build')} script in ${chalk.cyan(\n 'package.json',\n )} to generate and upload sourcemaps.`,\n );\n /* eslint-enable @typescript-eslint/no-unsafe-member-access */\n}\n\nexport function updateEntryClientMod(\n // MagicAst returns `ProxifiedModule<any>` so therefore we have to use `any` here\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalEntryClientMod: ProxifiedModule<any>,\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): ProxifiedModule<any> {\n const imports = ['init'];\n if (selectedFeatures.replay) {\n imports.push('replayIntegration');\n }\n if (selectedFeatures.performance) {\n imports.push('browserTracingIntegration');\n }\n originalEntryClientMod.imports.$add({\n from: '@sentry/remix',\n imported: `${imports.join(', ')}`,\n });\n\n if (selectedFeatures.performance) {\n originalEntryClientMod.imports.$add({\n from: '@remix-run/react',\n imported: 'useLocation',\n local: 'useLocation',\n });\n\n originalEntryClientMod.imports.$add({\n from: '@remix-run/react',\n imported: 'useMatches',\n local: 'useMatches',\n });\n\n originalEntryClientMod.imports.$add({\n from: 'react',\n imported: 'useEffect',\n local: 'useEffect',\n });\n }\n\n insertClientInitCall(dsn, originalEntryClientMod, selectedFeatures);\n\n return originalEntryClientMod;\n}\n\nexport async function initializeSentryOnEntryClient(\n dsn: string,\n isTS: boolean,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n): Promise<void> {\n const clientEntryFilename = `entry.client.${isTS ? 'tsx' : 'jsx'}`;\n\n const originalEntryClient = path.join(\n process.cwd(),\n 'app',\n clientEntryFilename,\n );\n\n const originalEntryClientMod = await loadFile(originalEntryClient);\n\n if (hasSentryContent(originalEntryClient, originalEntryClientMod.$code)) {\n return;\n }\n\n const updatedEntryClientMod = updateEntryClientMod(\n originalEntryClientMod,\n dsn,\n selectedFeatures,\n );\n\n await writeFile(\n updatedEntryClientMod.$ast,\n path.join(process.cwd(), 'app', clientEntryFilename),\n );\n\n clack.log.success(\n `Successfully initialized Sentry on client entry point ${chalk.cyan(\n clientEntryFilename,\n )}`,\n );\n}\n\nexport async function updateStartScript(instrumentationFile: string) {\n const packageJson = await getPackageDotJson();\n\n if (!packageJson.scripts || !packageJson.scripts.start) {\n throw new Error(\n \"Couldn't find a `start` script in your package.json. Please add one manually.\",\n );\n }\n\n if (packageJson.scripts.start.includes('NODE_OPTIONS')) {\n clack.log.warn(\n `Found existing NODE_OPTIONS in ${chalk.cyan(\n 'start',\n )} script. Skipping adding Sentry initialization.`,\n );\n\n return;\n }\n\n if (\n !packageJson.scripts.start.includes('remix-serve') &&\n // Adding a following empty space not to match a path that includes `node`\n !packageJson.scripts.start.includes('node ')\n ) {\n clack.log.warn(\n `Found a ${chalk.cyan('start')} script that doesn't use ${chalk.cyan(\n 'remix-serve',\n )} or ${chalk.cyan('node')}. Skipping adding Sentry initialization.`,\n );\n\n return;\n }\n\n const startCommand = packageJson.scripts.start;\n\n packageJson.scripts.start = `NODE_OPTIONS='--import ./${instrumentationFile}' ${startCommand}`;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageJson, null, 2),\n );\n\n clack.log.success(\n `Successfully updated ${chalk.cyan('start')} script in ${chalk.cyan(\n 'package.json',\n )} to include Sentry initialization on start.`,\n );\n}\n\nexport async function instrumentSentryOnEntryServer(\n isTS: boolean,\n): Promise<void> {\n const serverEntryFilename = `entry.server.${isTS ? 'tsx' : 'jsx'}`;\n\n const originalEntryServer = path.join(\n process.cwd(),\n 'app',\n serverEntryFilename,\n );\n\n const originalEntryServerMod = await loadFile(originalEntryServer);\n\n if (hasSentryContent(originalEntryServer, originalEntryServerMod.$code)) {\n return;\n }\n\n originalEntryServerMod.imports.$add({\n from: '@sentry/remix',\n imported: '*',\n local: 'Sentry',\n });\n\n const handleErrorInstrumented = instrumentHandleError(\n originalEntryServerMod,\n serverEntryFilename,\n );\n\n if (handleErrorInstrumented) {\n clack.log.success(\n `Instrumented ${chalk.cyan('handleError')} in ${chalk.cyan(\n `${serverEntryFilename}`,\n )}`,\n );\n }\n\n await writeFile(\n originalEntryServerMod.$ast,\n path.join(process.cwd(), 'app', serverEntryFilename),\n );\n\n clack.log.success(\n `Successfully initialized Sentry on server entry point ${chalk.cyan(\n serverEntryFilename,\n )}.`,\n );\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
1
|
+
export declare const ERROR_BOUNDARY_TEMPLATE = "const ErrorBoundary = () => {\n const error = useRouteError();\n captureRemixErrorBoundaryError(error);\n return <div>Something went wrong</div>;\n};\n";
|
|
2
|
+
export declare const HANDLE_ERROR_TEMPLATE = "const handleError = Sentry.wrapHandleErrorWithSentry((error, { request }) => {\n // Custom handleError implementation\n});\n";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.HANDLE_ERROR_TEMPLATE = exports.ERROR_BOUNDARY_TEMPLATE = void 0;
|
|
4
|
+
exports.ERROR_BOUNDARY_TEMPLATE = `const ErrorBoundary = () => {
|
|
5
5
|
const error = useRouteError();
|
|
6
6
|
captureRemixErrorBoundaryError(error);
|
|
7
7
|
return <div>Something went wrong</div>;
|
|
8
8
|
};
|
|
9
9
|
`;
|
|
10
|
-
exports.
|
|
10
|
+
exports.HANDLE_ERROR_TEMPLATE = `const handleError = Sentry.wrapHandleErrorWithSentry((error, { request }) => {
|
|
11
11
|
// Custom handleError implementation
|
|
12
12
|
});
|
|
13
13
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/remix/templates.ts"],"names":[],"mappings":";;;AAAa,QAAA,
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/remix/templates.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAG;;;;;CAKtC,CAAC;AAEW,QAAA,qBAAqB,GAAG;;;CAGpC,CAAC","sourcesContent":["export const ERROR_BOUNDARY_TEMPLATE = `const ErrorBoundary = () => {\n const error = useRouteError();\n captureRemixErrorBoundaryError(error);\n return <div>Something went wrong</div>;\n};\n`;\n\nexport const HANDLE_ERROR_TEMPLATE = `const handleError = Sentry.wrapHandleErrorWithSentry((error, { request }) => {\n // Custom handleError implementation\n});\n`;\n"]}
|
|
@@ -56,6 +56,11 @@ async function createOrMergeSvelteKitFiles(projectInfo, svelteConfig) {
|
|
|
56
56
|
prompt: `Do you want to enable ${chalk_1.default.bold('Session Replay')} to get a video-like reproduction of errors during a user session?`,
|
|
57
57
|
enabledHint: 'recommended, but increases bundle size',
|
|
58
58
|
},
|
|
59
|
+
{
|
|
60
|
+
id: 'logs',
|
|
61
|
+
prompt: `Do you want to enable ${chalk_1.default.bold('Logs')} to send your application logs to Sentry?`,
|
|
62
|
+
enabledHint: 'recommended',
|
|
63
|
+
},
|
|
59
64
|
]);
|
|
60
65
|
const { clientHooksPath, serverHooksPath } = getHooksConfigDirs(svelteConfig);
|
|
61
66
|
// full file paths with correct file ending (or undefined if not found)
|
|
@@ -180,6 +185,9 @@ originalHooksMod, selectedFeatures) {
|
|
|
180
185
|
initArgs.replaysOnErrorSampleRate = 1.0;
|
|
181
186
|
initArgs.integrations = [magicast_1.builders.functionCall('Sentry.replayIntegration')];
|
|
182
187
|
}
|
|
188
|
+
if (selectedFeatures.logs) {
|
|
189
|
+
initArgs.enableLogs = true;
|
|
190
|
+
}
|
|
183
191
|
// This assignment of any values is fine because we're just creating a function call in magicast
|
|
184
192
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
185
193
|
const initCall = magicast_1.builders.functionCall('Sentry.init', initArgs);
|
|
@@ -203,6 +211,9 @@ originalHooksMod, selectedFeatures) {
|
|
|
203
211
|
if (selectedFeatures.performance) {
|
|
204
212
|
initArgs.tracesSampleRate = 1.0;
|
|
205
213
|
}
|
|
214
|
+
if (selectedFeatures.logs) {
|
|
215
|
+
initArgs.enableLogs = true;
|
|
216
|
+
}
|
|
206
217
|
// This assignment of any values is fine because we're just creating a function call in magicast
|
|
207
218
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
208
219
|
const initCall = magicast_1.builders.functionCall('Sentry.init', initArgs);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-setup.js","sourceRoot":"","sources":["../../../src/sveltekit/sdk-setup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uCAAyB;AACzB,2CAA6B;AAC7B,yCAA2B;AAC3B,kDAA0B;AAE1B,qDAAuC;AAEvC,8EAA8E;AAC9E,6DAAmC;AAGnC,kFAAkF;AAClF,uCAAyE;AACzE,kFAAkF;AAClF,8CAAiD;AACjD,2CAA6E;AAC7E,0CAIwB;AACxB,0CAAuC;AACvC,kDA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,CAAC;QAC7D,CAAC,CAAC,CAAC,CAAC;IACN,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,mBAAmB,CAChC,cAAoC,EACpC,MAAc,EACd,QAAsD;IAEtD,IAAI;QACF,MAAM,IAAA,qBAAS,EAAC,GAAG,QAAQ,IAAI,MAAM,EAAE,EAAE,cAAc,CAAC,CAAC;KAC1D;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,MAAM,CAAC,YAAY,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,GAAG,QAAQ,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACrD,MAAM,CAAC,CAAC;KACT;AACH,CAAC","sourcesContent":["import type { ExportNamedDeclaration, Program } from '@babel/types';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as url from 'url';\nimport chalk from 'chalk';\n\nimport * as Sentry from '@sentry/node';\n\n//@ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { builders, generateCode, loadFile, parseModule } from 'magicast';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\nimport { getClientHooksTemplate, getServerHooksTemplate } from './templates';\nimport {\n abortIfCancelled,\n featureSelectionPrompt,\n isUsingTypeScript,\n} from '../utils/clack';\nimport { debug } from '../utils/debug';\nimport { findFile, hasSentryContent } from '../utils/ast-utils';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\nimport { traceStep } from '../telemetry';\n\nconst SVELTE_CONFIG_FILE = 'svelte.config.js';\n\nexport type PartialSvelteConfig = {\n kit?: {\n files?: {\n hooks?: {\n client?: string;\n server?: string;\n };\n routes?: string;\n };\n };\n};\n\ntype ProjectInfo = {\n dsn: string;\n org: string;\n project: string;\n selfHosted: boolean;\n url: string;\n};\n\nexport async function createOrMergeSvelteKitFiles(\n projectInfo: ProjectInfo,\n svelteConfig: PartialSvelteConfig,\n): Promise<void> {\n const selectedFeatures = 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 ] as const);\n\n const { clientHooksPath, serverHooksPath } = getHooksConfigDirs(svelteConfig);\n\n // full file paths with correct file ending (or undefined if not found)\n const originalClientHooksFile = findFile(clientHooksPath);\n const originalServerHooksFile = findFile(serverHooksPath);\n\n const viteConfig = findFile(path.resolve(process.cwd(), 'vite.config'));\n\n const fileEnding = isUsingTypeScript() ? 'ts' : 'js';\n\n const { dsn } = projectInfo;\n\n Sentry.setTag(\n 'client-hooks-file-strategy',\n originalClientHooksFile ? 'merge' : 'create',\n );\n if (!originalClientHooksFile) {\n clack.log.info('No client hooks file found, creating a new one.');\n await createNewHooksFile(\n `${clientHooksPath}.${fileEnding}`,\n 'client',\n dsn,\n selectedFeatures,\n );\n } else {\n await mergeHooksFile(\n originalClientHooksFile,\n 'client',\n dsn,\n selectedFeatures,\n );\n }\n\n Sentry.setTag(\n 'server-hooks-file-strategy',\n originalServerHooksFile ? 'merge' : 'create',\n );\n if (!originalServerHooksFile) {\n clack.log.info('No server hooks file found, creating a new one.');\n await createNewHooksFile(\n `${serverHooksPath}.${fileEnding}`,\n 'server',\n dsn,\n selectedFeatures,\n );\n } else {\n await mergeHooksFile(\n originalServerHooksFile,\n 'server',\n dsn,\n selectedFeatures,\n );\n }\n\n if (viteConfig) {\n await modifyViteConfig(viteConfig, projectInfo);\n }\n}\n\n/**\n * Attempts to read the svelte.config.js file to find the location of the hooks files.\n * If users specified a custom location, we'll use that. Otherwise, we'll use the default.\n */\nfunction getHooksConfigDirs(svelteConfig: PartialSvelteConfig): {\n clientHooksPath: string;\n serverHooksPath: string;\n} {\n const relativeUserClientHooksPath = svelteConfig?.kit?.files?.hooks?.client;\n const relativeUserServerHooksPath = svelteConfig?.kit?.files?.hooks?.server;\n const userClientHooksPath =\n relativeUserClientHooksPath &&\n path.resolve(process.cwd(), relativeUserClientHooksPath);\n const userServerHooksPath =\n relativeUserServerHooksPath &&\n path.resolve(process.cwd(), relativeUserServerHooksPath);\n\n const defaulHooksDir = path.resolve(process.cwd(), 'src');\n const defaultClientHooksPath = path.resolve(defaulHooksDir, 'hooks.client'); // file ending missing on purpose\n const defaultServerHooksPath = path.resolve(defaulHooksDir, 'hooks.server'); // same here\n\n return {\n clientHooksPath: userClientHooksPath || defaultClientHooksPath,\n serverHooksPath: userServerHooksPath || defaultServerHooksPath,\n };\n}\n\n/**\n * Reads the template, replaces the dsn placeholder with the actual dsn and writes the file to @param hooksFileDest\n */\nasync function createNewHooksFile(\n hooksFileDest: string,\n hooktype: 'client' | 'server',\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n },\n): Promise<void> {\n const filledTemplate =\n hooktype === 'client'\n ? getClientHooksTemplate(dsn, selectedFeatures)\n : getServerHooksTemplate(dsn, selectedFeatures);\n\n await fs.promises.mkdir(path.dirname(hooksFileDest), { recursive: true });\n await fs.promises.writeFile(hooksFileDest, filledTemplate);\n\n clack.log.success(`Created ${hooksFileDest}`);\n Sentry.setTag(`created-${hooktype}-hooks`, 'success');\n}\n\n/**\n * Merges the users' hooks file with Sentry-related code.\n *\n * Both hooks:\n * - add import * as Sentry\n * - add Sentry.init\n * - add handleError hook wrapper\n *\n * Additionally in Server hook:\n * - add handle hook handler\n */\nasync function mergeHooksFile(\n hooksFile: string,\n hookType: 'client' | 'server',\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n },\n): Promise<void> {\n const originalHooksMod = await loadFile(hooksFile);\n\n const file: 'server-hooks' | 'client-hooks' = `${hookType}-hooks`;\n\n if (hasSentryContent(originalHooksMod.$ast as t.Program)) {\n // We don't want to mess with files that already have Sentry content.\n // Let's just bail out at this point.\n clack.log.warn(\n `File ${chalk.cyan(\n path.basename(hooksFile),\n )} already contains Sentry code.\nSkipping adding Sentry functionality to.`,\n );\n Sentry.setTag(`modified-${file}`, 'fail');\n Sentry.setTag(`${file}-fail-reason`, 'has-sentry-content');\n return;\n }\n\n await modifyAndRecordFail(\n () =>\n originalHooksMod.imports.$add({\n from: '@sentry/sveltekit',\n imported: '*',\n local: 'Sentry',\n }),\n 'import-injection',\n file,\n );\n\n await modifyAndRecordFail(\n () => {\n if (hookType === 'client') {\n insertClientInitCall(dsn, originalHooksMod, selectedFeatures);\n } else {\n insertServerInitCall(dsn, originalHooksMod, selectedFeatures);\n }\n },\n 'init-call-injection',\n file,\n );\n\n await modifyAndRecordFail(\n () => wrapHandleError(originalHooksMod),\n 'wrap-handle-error',\n file,\n );\n\n if (hookType === 'server') {\n await modifyAndRecordFail(\n () => wrapHandle(originalHooksMod),\n 'wrap-handle',\n 'server-hooks',\n );\n }\n\n await modifyAndRecordFail(\n async () => {\n const modifiedCode = originalHooksMod.generate().code;\n await fs.promises.writeFile(hooksFile, modifiedCode);\n },\n 'write-file',\n file,\n );\n\n clack.log.success(`Added Sentry code to ${hooksFile}`);\n Sentry.setTag(`modified-${hookType}-hooks`, 'success');\n}\n\nfunction insertClientInitCall(\n dsn: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalHooksMod: ProxifiedModule<any>,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n },\n): void {\n const initCallComment = `\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.`;\n\n const initArgs: {\n dsn: string;\n tracesSampleRate?: number;\n replaysSessionSampleRate?: number;\n replaysOnErrorSampleRate?: number;\n integrations?: string[];\n } = {\n dsn,\n };\n\n if (selectedFeatures.performance) {\n initArgs.tracesSampleRate = 1.0;\n }\n\n if (selectedFeatures.replay) {\n initArgs.replaysSessionSampleRate = 0.1;\n initArgs.replaysOnErrorSampleRate = 1.0;\n initArgs.integrations = [builders.functionCall('Sentry.replayIntegration')];\n }\n\n // This assignment of any values is fine because we're just creating a function call in magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const initCall = builders.functionCall('Sentry.init', initArgs);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const initCallWithComment = builders.raw(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n `${initCallComment}\\n${generateCode(initCall).code}`,\n );\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n\n const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCallWithComment).code,\n );\n}\n\nfunction insertServerInitCall(\n dsn: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalHooksMod: ProxifiedModule<any>,\n selectedFeatures: {\n performance: boolean;\n },\n): void {\n const initArgs: {\n dsn: string;\n tracesSampleRate?: number;\n } = {\n dsn,\n };\n\n if (selectedFeatures.performance) {\n initArgs.tracesSampleRate = 1.0;\n }\n\n // This assignment of any values is fine because we're just creating a function call in magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const initCall = builders.functionCall('Sentry.init', initArgs);\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n\n const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction wrapHandleError(mod: ProxifiedModule<any>): void {\n const modAst = mod.exports.$ast as Program;\n const namedExports = modAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n let foundHandleError = false;\n\n namedExports.forEach((modExport) => {\n const declaration = modExport.declaration;\n if (!declaration) {\n return;\n }\n if (declaration.type === 'FunctionDeclaration') {\n if (!declaration.id || declaration.id.name !== 'handleError') {\n return;\n }\n foundHandleError = true;\n const userCode = generateCode(declaration).code;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handleError = builders.raw(\n `Sentry.handleErrorWithSentry(${userCode.replace(\n 'handleError',\n '_handleError',\n )})`,\n );\n // because magicast doesn't overwrite the original function export, we need to remove it manually\n modAst.body = modAst.body.filter((node) => node !== modExport);\n } else if (declaration.type === 'VariableDeclaration') {\n const declarations = declaration.declarations;\n declarations.forEach((declaration) => {\n // @ts-expect-error - id should always have a name in this case\n if (!declaration.id || declaration.id.name !== 'handleError') {\n return;\n }\n foundHandleError = true;\n const userCode = declaration.init;\n const stringifiedUserCode = userCode ? generateCode(userCode).code : '';\n // @ts-expect-error - we can just place a string here, magicast will convert it to a node\n declaration.init = `Sentry.handleErrorWithSentry(${stringifiedUserCode})`;\n });\n }\n });\n\n if (!foundHandleError) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handleError = builders.functionCall(\n 'Sentry.handleErrorWithSentry',\n );\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction wrapHandle(mod: ProxifiedModule<any>): void {\n const modAst = mod.exports.$ast as Program;\n const namedExports = modAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n let foundHandle = false;\n\n namedExports.forEach((modExport) => {\n const declaration = modExport.declaration;\n if (!declaration) {\n return;\n }\n if (declaration.type === 'FunctionDeclaration') {\n if (!declaration.id || declaration.id.name !== 'handle') {\n return;\n }\n foundHandle = true;\n const userCode = generateCode(declaration).code;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handle = builders.raw(\n `sequence(Sentry.sentryHandle(), ${userCode.replace(\n 'handle',\n '_handle',\n )})`,\n );\n // because of an issue with magicast, we need to remove the original export\n modAst.body = modAst.body.filter((node) => node !== modExport);\n } else if (declaration.type === 'VariableDeclaration') {\n const declarations = declaration.declarations;\n declarations.forEach((declaration) => {\n if (\n !declaration.id ||\n declaration.id.type !== 'Identifier' ||\n (declaration.id.name && declaration.id.name !== 'handle')\n ) {\n return;\n }\n const userCode = declaration.init;\n const stringifiedUserCode = userCode ? generateCode(userCode).code : '';\n // @ts-expect-error - we can just place a string here, magicast will convert it to a node\n declaration.init = `sequence(Sentry.sentryHandle(), ${stringifiedUserCode})`;\n foundHandle = true;\n });\n }\n });\n\n if (!foundHandle) {\n // can't use builders.functionCall here because it doesn't yet\n // support member expressions (Sentry.sentryHandle()) in args\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handle = builders.raw('sequence(Sentry.sentryHandle())');\n }\n\n try {\n mod.imports.$add({\n from: '@sveltejs/kit/hooks',\n imported: 'sequence',\n local: 'sequence',\n });\n } catch (_) {\n // It's possible sequence is already imported. in this case, magicast throws but that's fine.\n }\n}\n\nexport async function loadSvelteConfig(): Promise<PartialSvelteConfig> {\n const configFilePath = path.join(process.cwd(), SVELTE_CONFIG_FILE);\n\n try {\n if (!fs.existsSync(configFilePath)) {\n return {};\n }\n\n const configUrl = url.pathToFileURL(configFilePath).href;\n const svelteConfigModule = (await import(configUrl)) as {\n default: PartialSvelteConfig;\n };\n\n return svelteConfigModule?.default || {};\n } catch (e: unknown) {\n clack.log.error(`Couldn't load ${SVELTE_CONFIG_FILE}.\nPlease make sure, you're running this wizard with Node 16 or newer`);\n clack.log.info(\n chalk.dim(\n typeof e === 'object' && e != null && 'toString' in e\n ? e.toString()\n : typeof e === 'string'\n ? e\n : 'Unknown error',\n ),\n );\n\n return {};\n }\n}\n\nasync function modifyViteConfig(\n viteConfigPath: string,\n projectInfo: ProjectInfo,\n): Promise<void> {\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath, 'utf-8')\n ).toString();\n\n const { org, project, url, selfHosted } = projectInfo;\n\n const prettyViteConfigFilename = chalk.cyan(path.basename(viteConfigPath));\n\n try {\n const viteModule = parseModule(viteConfigContent);\n\n if (hasSentryContent(viteModule.$ast as t.Program)) {\n clack.log.warn(\n `File ${prettyViteConfigFilename} already contains Sentry code.\nSkipping adding Sentry functionality to.`,\n );\n Sentry.setTag(`modified-vite-cfg`, 'fail');\n Sentry.setTag(`vite-cfg-fail-reason`, 'has-sentry-content');\n return;\n }\n\n await modifyAndRecordFail(\n () =>\n addVitePlugin(viteModule, {\n imported: 'sentrySvelteKit',\n from: '@sentry/sveltekit',\n constructor: 'sentrySvelteKit',\n options: {\n sourceMapsUploadOptions: {\n org,\n project,\n ...(selfHosted && { url }),\n },\n },\n index: 0,\n }),\n 'add-vite-plugin',\n 'vite-cfg',\n );\n\n await modifyAndRecordFail(\n async () => {\n const code = generateCode(viteModule.$ast).code;\n await fs.promises.writeFile(viteConfigPath, code);\n },\n 'write-file',\n 'vite-cfg',\n );\n } catch (e) {\n debug(e);\n await showFallbackViteCopyPasteSnippet(\n viteConfigPath,\n getViteConfigCodeSnippet(org, project, selfHosted, url),\n );\n Sentry.captureException('Sveltekit Vite Config Modification Fail');\n }\n\n clack.log.success(`Added Sentry code to ${prettyViteConfigFilename}`);\n Sentry.setTag(`modified-vite-cfg`, 'success');\n}\n\nasync function showFallbackViteCopyPasteSnippet(\n viteConfigPath: string,\n codeSnippet: string,\n) {\n const viteConfigFilename = path.basename(viteConfigPath);\n\n clack.log.warning(\n `Couldn't automatically modify your ${chalk.cyan(viteConfigFilename)}\n${chalk.dim(`This sometimes happens when we encounter more complex vite configs.\nIt may not seem like it but sometimes our magical powers are limited ;)`)}`,\n );\n\n clack.log.info(\"But don't worry - it's super easy to do this yourself!\");\n\n clack.log.step(\n `Add the following code to your ${chalk.cyan(viteConfigFilename)}:`,\n );\n\n // Intentionally logging to console here for easier copy/pasting\n // eslint-disable-next-line no-console\n console.log(codeSnippet);\n\n await abortIfCancelled(\n clack.select({\n message: 'Did you copy the snippet above?',\n options: [\n { label: 'Yes!', value: true, hint: \"Great, that's already it!\" },\n ],\n initialValue: true,\n }),\n );\n}\n\nconst getViteConfigCodeSnippet = (\n org: string,\n project: string,\n selfHosted: boolean,\n url: string,\n) =>\n chalk.gray(`\nimport { sveltekit } from '@sveltejs/kit/vite';\nimport { defineConfig } from 'vite';\n${chalk.greenBright(\"import { sentrySvelteKit } from '@sentry/sveltekit'\")}\n\nexport default defineConfig({\n plugins: [\n // Make sure \\`sentrySvelteKit\\` is registered before \\`sveltekit\\`\n ${chalk.greenBright(`sentrySvelteKit({\n sourceMapsUploadOptions: {\n org: '${org}',\n project: '${project}',${selfHosted ? `\\n url: '${url}',` : ''}\n }\n }),`)}\n sveltekit(),\n ]\n});\n`);\n\n/**\n * We want to insert the init call on top of the file but after all import statements\n */\nfunction getInitCallInsertionIndex(originalHooksModAST: Program): number {\n // We need to deep-copy here because reverse mutates in place\n const copiedBodyNodes = [...originalHooksModAST.body];\n const lastImportDeclaration = copiedBodyNodes\n .reverse()\n .find((node) => node.type === 'ImportDeclaration');\n\n const initCallInsertionIndex = lastImportDeclaration\n ? originalHooksModAST.body.indexOf(lastImportDeclaration) + 1\n : 0;\n return initCallInsertionIndex;\n}\n\n/**\n * Applies the @param modifyCallback and records Sentry tags if the call failed.\n * In case of a failure, a tag is set with @param reason as a fail reason\n * and the error is rethrown.\n */\nasync function modifyAndRecordFail<T>(\n modifyCallback: () => T | Promise<T>,\n reason: string,\n fileType: 'server-hooks' | 'client-hooks' | 'vite-cfg',\n): Promise<void> {\n try {\n await traceStep(`${fileType}-${reason}`, modifyCallback);\n } catch (e) {\n Sentry.setTag(`modified-${fileType}`, 'fail');\n Sentry.setTag(`${fileType}-mod-fail-reason`, reason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EACf,UAAmB,EACnB,GAAW,EACX,EAAE,CACF,eAAK,CAAC,IAAI,CAAC;;;EAGX,eAAK,CAAC,WAAW,CAAC,qDAAqD,CAAC;;;;;MAKpE,eAAK,CAAC,WAAW,CAAC;;gBAER,GAAG;oBACC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE;;QAEpE,CAAC;;;;CAIR,CAAC,CAAC;AAEH;;GAEG;AACH,SAAS,yBAAyB,CAAC,mBAA4B;IAC7D,6DAA6D;IAC7D,MAAM,eAAe,GAAG,CAAC,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACtD,MAAM,qBAAqB,GAAG,eAAe;SAC1C,OAAO,EAAE;SACT,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,mBAAmB,CAAC,CAAC;IAErD,MAAM,sBAAsB,GAAG,qBAAqB;QAClD,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,GAAG,CAAC;QAC7D,CAAC,CAAC,CAAC,CAAC;IACN,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,mBAAmB,CAChC,cAAoC,EACpC,MAAc,EACd,QAAsD;IAEtD,IAAI;QACF,MAAM,IAAA,qBAAS,EAAC,GAAG,QAAQ,IAAI,MAAM,EAAE,EAAE,cAAc,CAAC,CAAC;KAC1D;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,MAAM,CAAC,YAAY,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC;QAC9C,MAAM,CAAC,MAAM,CAAC,GAAG,QAAQ,kBAAkB,EAAE,MAAM,CAAC,CAAC;QACrD,MAAM,CAAC,CAAC;KACT;AACH,CAAC","sourcesContent":["import type { ExportNamedDeclaration, Program } from '@babel/types';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as url from 'url';\nimport chalk from 'chalk';\n\nimport * as Sentry from '@sentry/node';\n\n//@ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { builders, generateCode, loadFile, parseModule } from 'magicast';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\nimport { getClientHooksTemplate, getServerHooksTemplate } from './templates';\nimport {\n abortIfCancelled,\n featureSelectionPrompt,\n isUsingTypeScript,\n} from '../utils/clack';\nimport { debug } from '../utils/debug';\nimport { findFile, hasSentryContent } from '../utils/ast-utils';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\nimport { traceStep } from '../telemetry';\n\nconst SVELTE_CONFIG_FILE = 'svelte.config.js';\n\nexport type PartialSvelteConfig = {\n kit?: {\n files?: {\n hooks?: {\n client?: string;\n server?: string;\n };\n routes?: string;\n };\n };\n};\n\ntype ProjectInfo = {\n dsn: string;\n org: string;\n project: string;\n selfHosted: boolean;\n url: string;\n};\n\nexport async function createOrMergeSvelteKitFiles(\n projectInfo: ProjectInfo,\n svelteConfig: PartialSvelteConfig,\n): Promise<void> {\n const selectedFeatures = 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 ] as const);\n\n const { clientHooksPath, serverHooksPath } = getHooksConfigDirs(svelteConfig);\n\n // full file paths with correct file ending (or undefined if not found)\n const originalClientHooksFile = findFile(clientHooksPath);\n const originalServerHooksFile = findFile(serverHooksPath);\n\n const viteConfig = findFile(path.resolve(process.cwd(), 'vite.config'));\n\n const fileEnding = isUsingTypeScript() ? 'ts' : 'js';\n\n const { dsn } = projectInfo;\n\n Sentry.setTag(\n 'client-hooks-file-strategy',\n originalClientHooksFile ? 'merge' : 'create',\n );\n if (!originalClientHooksFile) {\n clack.log.info('No client hooks file found, creating a new one.');\n await createNewHooksFile(\n `${clientHooksPath}.${fileEnding}`,\n 'client',\n dsn,\n selectedFeatures,\n );\n } else {\n await mergeHooksFile(\n originalClientHooksFile,\n 'client',\n dsn,\n selectedFeatures,\n );\n }\n\n Sentry.setTag(\n 'server-hooks-file-strategy',\n originalServerHooksFile ? 'merge' : 'create',\n );\n if (!originalServerHooksFile) {\n clack.log.info('No server hooks file found, creating a new one.');\n await createNewHooksFile(\n `${serverHooksPath}.${fileEnding}`,\n 'server',\n dsn,\n selectedFeatures,\n );\n } else {\n await mergeHooksFile(\n originalServerHooksFile,\n 'server',\n dsn,\n selectedFeatures,\n );\n }\n\n if (viteConfig) {\n await modifyViteConfig(viteConfig, projectInfo);\n }\n}\n\n/**\n * Attempts to read the svelte.config.js file to find the location of the hooks files.\n * If users specified a custom location, we'll use that. Otherwise, we'll use the default.\n */\nfunction getHooksConfigDirs(svelteConfig: PartialSvelteConfig): {\n clientHooksPath: string;\n serverHooksPath: string;\n} {\n const relativeUserClientHooksPath = svelteConfig?.kit?.files?.hooks?.client;\n const relativeUserServerHooksPath = svelteConfig?.kit?.files?.hooks?.server;\n const userClientHooksPath =\n relativeUserClientHooksPath &&\n path.resolve(process.cwd(), relativeUserClientHooksPath);\n const userServerHooksPath =\n relativeUserServerHooksPath &&\n path.resolve(process.cwd(), relativeUserServerHooksPath);\n\n const defaulHooksDir = path.resolve(process.cwd(), 'src');\n const defaultClientHooksPath = path.resolve(defaulHooksDir, 'hooks.client'); // file ending missing on purpose\n const defaultServerHooksPath = path.resolve(defaulHooksDir, 'hooks.server'); // same here\n\n return {\n clientHooksPath: userClientHooksPath || defaultClientHooksPath,\n serverHooksPath: userServerHooksPath || defaultServerHooksPath,\n };\n}\n\n/**\n * Reads the template, replaces the dsn placeholder with the actual dsn and writes the file to @param hooksFileDest\n */\nasync function createNewHooksFile(\n hooksFileDest: string,\n hooktype: 'client' | 'server',\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n): Promise<void> {\n const filledTemplate =\n hooktype === 'client'\n ? getClientHooksTemplate(dsn, selectedFeatures)\n : getServerHooksTemplate(dsn, selectedFeatures);\n\n await fs.promises.mkdir(path.dirname(hooksFileDest), { recursive: true });\n await fs.promises.writeFile(hooksFileDest, filledTemplate);\n\n clack.log.success(`Created ${hooksFileDest}`);\n Sentry.setTag(`created-${hooktype}-hooks`, 'success');\n}\n\n/**\n * Merges the users' hooks file with Sentry-related code.\n *\n * Both hooks:\n * - add import * as Sentry\n * - add Sentry.init\n * - add handleError hook wrapper\n *\n * Additionally in Server hook:\n * - add handle hook handler\n */\nasync function mergeHooksFile(\n hooksFile: string,\n hookType: 'client' | 'server',\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n): Promise<void> {\n const originalHooksMod = await loadFile(hooksFile);\n\n const file: 'server-hooks' | 'client-hooks' = `${hookType}-hooks`;\n\n if (hasSentryContent(originalHooksMod.$ast as t.Program)) {\n // We don't want to mess with files that already have Sentry content.\n // Let's just bail out at this point.\n clack.log.warn(\n `File ${chalk.cyan(\n path.basename(hooksFile),\n )} already contains Sentry code.\nSkipping adding Sentry functionality to.`,\n );\n Sentry.setTag(`modified-${file}`, 'fail');\n Sentry.setTag(`${file}-fail-reason`, 'has-sentry-content');\n return;\n }\n\n await modifyAndRecordFail(\n () =>\n originalHooksMod.imports.$add({\n from: '@sentry/sveltekit',\n imported: '*',\n local: 'Sentry',\n }),\n 'import-injection',\n file,\n );\n\n await modifyAndRecordFail(\n () => {\n if (hookType === 'client') {\n insertClientInitCall(dsn, originalHooksMod, selectedFeatures);\n } else {\n insertServerInitCall(dsn, originalHooksMod, selectedFeatures);\n }\n },\n 'init-call-injection',\n file,\n );\n\n await modifyAndRecordFail(\n () => wrapHandleError(originalHooksMod),\n 'wrap-handle-error',\n file,\n );\n\n if (hookType === 'server') {\n await modifyAndRecordFail(\n () => wrapHandle(originalHooksMod),\n 'wrap-handle',\n 'server-hooks',\n );\n }\n\n await modifyAndRecordFail(\n async () => {\n const modifiedCode = originalHooksMod.generate().code;\n await fs.promises.writeFile(hooksFile, modifiedCode);\n },\n 'write-file',\n file,\n );\n\n clack.log.success(`Added Sentry code to ${hooksFile}`);\n Sentry.setTag(`modified-${hookType}-hooks`, 'success');\n}\n\nfunction insertClientInitCall(\n dsn: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalHooksMod: ProxifiedModule<any>,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n): void {\n const initCallComment = `\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration,\n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.`;\n\n const initArgs: {\n dsn: string;\n tracesSampleRate?: number;\n replaysSessionSampleRate?: number;\n replaysOnErrorSampleRate?: number;\n integrations?: string[];\n enableLogs?: boolean;\n } = {\n dsn,\n };\n\n if (selectedFeatures.performance) {\n initArgs.tracesSampleRate = 1.0;\n }\n\n if (selectedFeatures.replay) {\n initArgs.replaysSessionSampleRate = 0.1;\n initArgs.replaysOnErrorSampleRate = 1.0;\n initArgs.integrations = [builders.functionCall('Sentry.replayIntegration')];\n }\n\n if (selectedFeatures.logs) {\n initArgs.enableLogs = true;\n }\n\n // This assignment of any values is fine because we're just creating a function call in magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const initCall = builders.functionCall('Sentry.init', initArgs);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const initCallWithComment = builders.raw(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n `${initCallComment}\\n${generateCode(initCall).code}`,\n );\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n\n const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCallWithComment).code,\n );\n}\n\nfunction insertServerInitCall(\n dsn: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalHooksMod: ProxifiedModule<any>,\n selectedFeatures: {\n performance: boolean;\n logs: boolean;\n },\n): void {\n const initArgs: {\n dsn: string;\n tracesSampleRate?: number;\n enableLogs?: boolean;\n } = {\n dsn,\n };\n\n if (selectedFeatures.performance) {\n initArgs.tracesSampleRate = 1.0;\n }\n\n if (selectedFeatures.logs) {\n initArgs.enableLogs = true;\n }\n\n // This assignment of any values is fine because we're just creating a function call in magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const initCall = builders.functionCall('Sentry.init', initArgs);\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n\n const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction wrapHandleError(mod: ProxifiedModule<any>): void {\n const modAst = mod.exports.$ast as Program;\n const namedExports = modAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n let foundHandleError = false;\n\n namedExports.forEach((modExport) => {\n const declaration = modExport.declaration;\n if (!declaration) {\n return;\n }\n if (declaration.type === 'FunctionDeclaration') {\n if (!declaration.id || declaration.id.name !== 'handleError') {\n return;\n }\n foundHandleError = true;\n const userCode = generateCode(declaration).code;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handleError = builders.raw(\n `Sentry.handleErrorWithSentry(${userCode.replace(\n 'handleError',\n '_handleError',\n )})`,\n );\n // because magicast doesn't overwrite the original function export, we need to remove it manually\n modAst.body = modAst.body.filter((node) => node !== modExport);\n } else if (declaration.type === 'VariableDeclaration') {\n const declarations = declaration.declarations;\n declarations.forEach((declaration) => {\n // @ts-expect-error - id should always have a name in this case\n if (!declaration.id || declaration.id.name !== 'handleError') {\n return;\n }\n foundHandleError = true;\n const userCode = declaration.init;\n const stringifiedUserCode = userCode ? generateCode(userCode).code : '';\n // @ts-expect-error - we can just place a string here, magicast will convert it to a node\n declaration.init = `Sentry.handleErrorWithSentry(${stringifiedUserCode})`;\n });\n }\n });\n\n if (!foundHandleError) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handleError = builders.functionCall(\n 'Sentry.handleErrorWithSentry',\n );\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction wrapHandle(mod: ProxifiedModule<any>): void {\n const modAst = mod.exports.$ast as Program;\n const namedExports = modAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n let foundHandle = false;\n\n namedExports.forEach((modExport) => {\n const declaration = modExport.declaration;\n if (!declaration) {\n return;\n }\n if (declaration.type === 'FunctionDeclaration') {\n if (!declaration.id || declaration.id.name !== 'handle') {\n return;\n }\n foundHandle = true;\n const userCode = generateCode(declaration).code;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handle = builders.raw(\n `sequence(Sentry.sentryHandle(), ${userCode.replace(\n 'handle',\n '_handle',\n )})`,\n );\n // because of an issue with magicast, we need to remove the original export\n modAst.body = modAst.body.filter((node) => node !== modExport);\n } else if (declaration.type === 'VariableDeclaration') {\n const declarations = declaration.declarations;\n declarations.forEach((declaration) => {\n if (\n !declaration.id ||\n declaration.id.type !== 'Identifier' ||\n (declaration.id.name && declaration.id.name !== 'handle')\n ) {\n return;\n }\n const userCode = declaration.init;\n const stringifiedUserCode = userCode ? generateCode(userCode).code : '';\n // @ts-expect-error - we can just place a string here, magicast will convert it to a node\n declaration.init = `sequence(Sentry.sentryHandle(), ${stringifiedUserCode})`;\n foundHandle = true;\n });\n }\n });\n\n if (!foundHandle) {\n // can't use builders.functionCall here because it doesn't yet\n // support member expressions (Sentry.sentryHandle()) in args\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handle = builders.raw('sequence(Sentry.sentryHandle())');\n }\n\n try {\n mod.imports.$add({\n from: '@sveltejs/kit/hooks',\n imported: 'sequence',\n local: 'sequence',\n });\n } catch (_) {\n // It's possible sequence is already imported. in this case, magicast throws but that's fine.\n }\n}\n\nexport async function loadSvelteConfig(): Promise<PartialSvelteConfig> {\n const configFilePath = path.join(process.cwd(), SVELTE_CONFIG_FILE);\n\n try {\n if (!fs.existsSync(configFilePath)) {\n return {};\n }\n\n const configUrl = url.pathToFileURL(configFilePath).href;\n const svelteConfigModule = (await import(configUrl)) as {\n default: PartialSvelteConfig;\n };\n\n return svelteConfigModule?.default || {};\n } catch (e: unknown) {\n clack.log.error(`Couldn't load ${SVELTE_CONFIG_FILE}.\nPlease make sure, you're running this wizard with Node 16 or newer`);\n clack.log.info(\n chalk.dim(\n typeof e === 'object' && e != null && 'toString' in e\n ? e.toString()\n : typeof e === 'string'\n ? e\n : 'Unknown error',\n ),\n );\n\n return {};\n }\n}\n\nasync function modifyViteConfig(\n viteConfigPath: string,\n projectInfo: ProjectInfo,\n): Promise<void> {\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath, 'utf-8')\n ).toString();\n\n const { org, project, url, selfHosted } = projectInfo;\n\n const prettyViteConfigFilename = chalk.cyan(path.basename(viteConfigPath));\n\n try {\n const viteModule = parseModule(viteConfigContent);\n\n if (hasSentryContent(viteModule.$ast as t.Program)) {\n clack.log.warn(\n `File ${prettyViteConfigFilename} already contains Sentry code.\nSkipping adding Sentry functionality to.`,\n );\n Sentry.setTag(`modified-vite-cfg`, 'fail');\n Sentry.setTag(`vite-cfg-fail-reason`, 'has-sentry-content');\n return;\n }\n\n await modifyAndRecordFail(\n () =>\n addVitePlugin(viteModule, {\n imported: 'sentrySvelteKit',\n from: '@sentry/sveltekit',\n constructor: 'sentrySvelteKit',\n options: {\n sourceMapsUploadOptions: {\n org,\n project,\n ...(selfHosted && { url }),\n },\n },\n index: 0,\n }),\n 'add-vite-plugin',\n 'vite-cfg',\n );\n\n await modifyAndRecordFail(\n async () => {\n const code = generateCode(viteModule.$ast).code;\n await fs.promises.writeFile(viteConfigPath, code);\n },\n 'write-file',\n 'vite-cfg',\n );\n } catch (e) {\n debug(e);\n await showFallbackViteCopyPasteSnippet(\n viteConfigPath,\n getViteConfigCodeSnippet(org, project, selfHosted, url),\n );\n Sentry.captureException('Sveltekit Vite Config Modification Fail');\n }\n\n clack.log.success(`Added Sentry code to ${prettyViteConfigFilename}`);\n Sentry.setTag(`modified-vite-cfg`, 'success');\n}\n\nasync function showFallbackViteCopyPasteSnippet(\n viteConfigPath: string,\n codeSnippet: string,\n) {\n const viteConfigFilename = path.basename(viteConfigPath);\n\n clack.log.warning(\n `Couldn't automatically modify your ${chalk.cyan(viteConfigFilename)}\n${chalk.dim(`This sometimes happens when we encounter more complex vite configs.\nIt may not seem like it but sometimes our magical powers are limited ;)`)}`,\n );\n\n clack.log.info(\"But don't worry - it's super easy to do this yourself!\");\n\n clack.log.step(\n `Add the following code to your ${chalk.cyan(viteConfigFilename)}:`,\n );\n\n // Intentionally logging to console here for easier copy/pasting\n // eslint-disable-next-line no-console\n console.log(codeSnippet);\n\n await abortIfCancelled(\n clack.select({\n message: 'Did you copy the snippet above?',\n options: [\n { label: 'Yes!', value: true, hint: \"Great, that's already it!\" },\n ],\n initialValue: true,\n }),\n );\n}\n\nconst getViteConfigCodeSnippet = (\n org: string,\n project: string,\n selfHosted: boolean,\n url: string,\n) =>\n chalk.gray(`\nimport { sveltekit } from '@sveltejs/kit/vite';\nimport { defineConfig } from 'vite';\n${chalk.greenBright(\"import { sentrySvelteKit } from '@sentry/sveltekit'\")}\n\nexport default defineConfig({\n plugins: [\n // Make sure \\`sentrySvelteKit\\` is registered before \\`sveltekit\\`\n ${chalk.greenBright(`sentrySvelteKit({\n sourceMapsUploadOptions: {\n org: '${org}',\n project: '${project}',${selfHosted ? `\\n url: '${url}',` : ''}\n }\n }),`)}\n sveltekit(),\n ]\n});\n`);\n\n/**\n * We want to insert the init call on top of the file but after all import statements\n */\nfunction getInitCallInsertionIndex(originalHooksModAST: Program): number {\n // We need to deep-copy here because reverse mutates in place\n const copiedBodyNodes = [...originalHooksModAST.body];\n const lastImportDeclaration = copiedBodyNodes\n .reverse()\n .find((node) => node.type === 'ImportDeclaration');\n\n const initCallInsertionIndex = lastImportDeclaration\n ? originalHooksModAST.body.indexOf(lastImportDeclaration) + 1\n : 0;\n return initCallInsertionIndex;\n}\n\n/**\n * Applies the @param modifyCallback and records Sentry tags if the call failed.\n * In case of a failure, a tag is set with @param reason as a fail reason\n * and the error is rethrown.\n */\nasync function modifyAndRecordFail<T>(\n modifyCallback: () => T | Promise<T>,\n reason: string,\n fileType: 'server-hooks' | 'client-hooks' | 'vite-cfg',\n): Promise<void> {\n try {\n await traceStep(`${fileType}-${reason}`, modifyCallback);\n } catch (e) {\n Sentry.setTag(`modified-${fileType}`, 'fail');\n Sentry.setTag(`${fileType}-mod-fail-reason`, reason);\n throw e;\n }\n}\n"]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export declare function getClientHooksTemplate(dsn: string, selectedFeatures: {
|
|
2
2
|
performance: boolean;
|
|
3
3
|
replay: boolean;
|
|
4
|
+
logs: boolean;
|
|
4
5
|
}): string;
|
|
5
6
|
export declare function getServerHooksTemplate(dsn: string, selectedFeatures: {
|
|
6
7
|
performance: boolean;
|
|
7
8
|
replay: boolean;
|
|
9
|
+
logs: boolean;
|
|
8
10
|
}): string;
|
|
9
11
|
/**
|
|
10
12
|
* +page.svelte with Sentry example
|
|
@@ -12,6 +12,11 @@ ${selectedFeatures.performance
|
|
|
12
12
|
tracesSampleRate: 1.0,
|
|
13
13
|
`
|
|
14
14
|
: ''}
|
|
15
|
+
${selectedFeatures.logs
|
|
16
|
+
? ` // Enable logs to be sent to Sentry
|
|
17
|
+
enableLogs: true,
|
|
18
|
+
`
|
|
19
|
+
: ''}
|
|
15
20
|
${selectedFeatures.replay
|
|
16
21
|
? ` // This sets the sample rate to be 10%. You may want this to be 100% while
|
|
17
22
|
// in development and sample at a lower rate in production
|
|
@@ -41,6 +46,11 @@ Sentry.init({
|
|
|
41
46
|
${selectedFeatures.performance
|
|
42
47
|
? `
|
|
43
48
|
tracesSampleRate: 1.0,
|
|
49
|
+
`
|
|
50
|
+
: ''}
|
|
51
|
+
${selectedFeatures.logs
|
|
52
|
+
? ` // Enable logs to be sent to Sentry
|
|
53
|
+
enableLogs: true,
|
|
44
54
|
`
|
|
45
55
|
: ''}
|
|
46
56
|
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/sveltekit/templates.ts"],"names":[],"mappings":";;;AAAA,SAAgB,sBAAsB,CACpC,GAAW,EACX,
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/sveltekit/templates.ts"],"names":[],"mappings":";;;AAAA,SAAgB,sBAAsB,CACpC,GAAW,EACX,gBAIC;IAED,OAAO;;;;UAIC,GAAG;EAEX,gBAAgB,CAAC,WAAW;QAC1B,CAAC,CAAC;;CAEL;QACG,CAAC,CAAC,EACN;EAEE,gBAAgB,CAAC,IAAI;QACnB,CAAC,CAAC;;CAEL;QACG,CAAC,CAAC,EACN;EAEE,gBAAgB,CAAC,MAAM;QACrB,CAAC,CAAC;;;;;;;;;uCASiC;QACnC,CAAC,CAAC,EACN;;;;;CAKC,CAAC;AACF,CAAC;AA9CD,wDA8CC;AAED,SAAgB,sBAAsB,CACpC,GAAW,EACX,gBAIC;IAED,OAAO;;;;;UAKC,GAAG;EAEX,gBAAgB,CAAC,WAAW;QAC1B,CAAC,CAAC;;CAEL;QACG,CAAC,CAAC,EACN;EAEE,gBAAgB,CAAC,IAAI;QACnB,CAAC,CAAC;;CAEL;QACG,CAAC,CAAC,EACN;;;;;;;;;;CAUC,CAAC;AACF,CAAC;AAtCD,wDAsCC;AAED;;GAEG;AACH,SAAgB,0BAA0B,CAAC,OAK1C;IACC,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU;QACvC,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,iBAAiB,OAAO,CAAC,OAAO,oBAAoB,OAAO,CAAC,SAAS,EAAE;QACvF,CAAC,CAAC,WAAW,OAAO,CAAC,OAAO,8BAA8B,OAAO,CAAC,SAAS,EAAE,CAAC;IAEhF,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iGAiDwF,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkK9G,CAAC;AACF,CAAC;AA9ND,gEA8NC;AAED,SAAgB,wBAAwB;IACtC,OAAO;;;;;;CAMR,CAAC;AACF,CAAC;AARD,4DAQC","sourcesContent":["export function getClientHooksTemplate(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n) {\n return `import { handleErrorWithSentry, replayIntegration } from \"@sentry/sveltekit\";\nimport * as Sentry from '@sentry/sveltekit';\n\nSentry.init({\n dsn: '${dsn}',\n${\n selectedFeatures.performance\n ? `\n tracesSampleRate: 1.0,\n`\n : ''\n}\n${\n selectedFeatures.logs\n ? ` // Enable logs to be sent to Sentry\n enableLogs: true,\n`\n : ''\n}\n${\n selectedFeatures.replay\n ? ` // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n\n // If the entire session is not sampled, use the below sample rate to sample\n // sessions when an error occurs.\n replaysOnErrorSampleRate: 1.0,\n\n // If you don't want to use Session Replay, just remove the line below:\n integrations: [replayIntegration()],`\n : ''\n}\n});\n\n// If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\nexport const handleError = handleErrorWithSentry();\n`;\n}\n\nexport function getServerHooksTemplate(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n replay: boolean;\n logs: boolean;\n },\n) {\n return `import { sequence } from \"@sveltejs/kit/hooks\";\nimport { handleErrorWithSentry, sentryHandle } from \"@sentry/sveltekit\";\nimport * as Sentry from '@sentry/sveltekit';\n\nSentry.init({\n dsn: '${dsn}',\n${\n selectedFeatures.performance\n ? `\n tracesSampleRate: 1.0,\n`\n : ''\n}\n${\n selectedFeatures.logs\n ? ` // Enable logs to be sent to Sentry\n enableLogs: true,\n`\n : ''\n}\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: import.meta.env.DEV,\n});\n\n// If you have custom handlers, make sure to place them after \\`sentryHandle()\\` in the \\`sequence\\` function.\nexport const handle = sequence(sentryHandle());\n\n// If you have a custom error handler, pass it to \\`handleErrorWithSentry\\`\nexport const handleError = handleErrorWithSentry();\n`;\n}\n\n/**\n * +page.svelte with Sentry example\n */\nexport function getSentryExampleSveltePage(options: {\n selfHosted: boolean;\n url: string;\n orgSlug: string;\n projectId: string;\n}) {\n const issuesPageLink = options.selfHosted\n ? `${options.url}organizations/${options.orgSlug}/issues/?project=${options.projectId}`\n : `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;\n\n return `<!--\nThis is just a very simple page with a button to throw an example error.\nFeel free to delete this file and the entire sentry route.\n-->\n\n<script>\n import * as Sentry from '@sentry/sveltekit';\n import { onMount } from 'svelte';\n \n // Svelte Runes (requires Svelte 5)\n // let hasSentError = $state(false);\n let hasSentError = false;\n let isConnected = true;\n\n onMount(async () => {\n const result = await Sentry.diagnoseSdkConnectivity();\n isConnected = result !== 'sentry-unreachable';\n });\n\n function getSentryData() {\n Sentry.startSpan(\n {\n name: 'Example Frontend Span',\n op: 'test'\n },\n async () => {\n const res = await fetch('/sentry-example-page');\n if (!res.ok) {\n hasSentError = true;\n throw new Error('Sentry Example Frontend Error');\n }\n }\n );\n }\n</script>\n\n<title>sentry-example-page</title>\n\n<div>\n <main>\n <div class=\"flex-spacer\"></div>\n <svg height=\"40\" width=\"40\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M21.85 2.995a3.698 3.698 0 0 1 1.353 1.354l16.303 28.278a3.703 3.703 0 0 1-1.354 5.053 3.694 3.694 0 0 1-1.848.496h-3.828a31.149 31.149 0 0 0 0-3.09h3.815a.61.61 0 0 0 .537-.917L20.523 5.893a.61.61 0 0 0-1.057 0l-3.739 6.494a28.948 28.948 0 0 1 9.63 10.453 28.988 28.988 0 0 1 3.499 13.78v1.542h-9.852v-1.544a19.106 19.106 0 0 0-2.182-8.85 19.08 19.08 0 0 0-6.032-6.829l-1.85 3.208a15.377 15.377 0 0 1 6.382 12.484v1.542H3.696A3.694 3.694 0 0 1 0 34.473c0-.648.17-1.286.494-1.849l2.33-4.074a8.562 8.562 0 0 1 2.689 1.536L3.158 34.17a.611.611 0 0 0 .538.917h8.448a12.481 12.481 0 0 0-6.037-9.09l-1.344-.772 4.908-8.545 1.344.77a22.16 22.16 0 0 1 7.705 7.444 22.193 22.193 0 0 1 3.316 10.193h3.699a25.892 25.892 0 0 0-3.811-12.033 25.856 25.856 0 0 0-9.046-8.796l-1.344-.772 5.269-9.136a3.698 3.698 0 0 1 3.2-1.849c.648 0 1.285.17 1.847.495Z\" fill=\"currentcolor\"/>\n </svg>\n <h1>\n sentry-example-page\n </h1>\n\n <p class=\"description\">\n Click the button below, and view the sample error on the Sentry <a target=\"_blank\" href=\"${issuesPageLink}\">Issues Page</a>. \n For more details about setting up Sentry, <a target=\"_blank\" href=\"https://docs.sentry.io/platforms/javascript/guides/sveltekit/\">read our docs</a>.\n </p>\n\n <button\n type=\"button\"\n onclick={getSentryData}\n disabled={!isConnected}\n >\n <span>\n Throw Sample Error\n </span>\n </button>\n\n {#if hasSentError}\n <p class=\"success\">\n Sample error was sent to Sentry.\n </p>\n {:else if !isConnected}\n <div class=\"connectivity-error\">\n <p>It looks like network requests to Sentry are being blocked, which will prevent errors from being captured. Try disabling your ad-blocker to complete the test.</p>\n </div>\n {:else}\n <div class=\"success_placeholder\"></div>\n {/if}\n <div class=\"flex-spacer\"></div>\n </main>\n</div>\n\n<style>\n :global(body) {\n margin: 0;\n\n @media (prefers-color-scheme: dark) {\n color: #ededed;\n background-color: #0a0a0a;\n }\n }\n\n main {\n display: flex;\n min-height: 100vh;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n box-sizing: border-box;\n gap: 16px;\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", sans-serif;\n }\n\n h1 {\n padding: 0px 4px;\n border-radius: 4px;\n background-color: rgba(24, 20, 35, 0.03);\n font-family: monospace;\n font-size: 20px;\n line-height: 1.2;\n }\n\n p {\n margin: 0;\n font-size: 20px;\n }\n\n a {\n color: #6341F0;\n text-decoration: underline;\n cursor: pointer;\n\n @media (prefers-color-scheme: dark) {\n color: #B3A1FF;\n }\n }\n\n button {\n border-radius: 8px;\n color: white;\n cursor: pointer;\n background-color: #553DB8;\n border: none;\n padding: 0;\n margin-top: 4px;\n\n & > span {\n display: inline-block;\n padding: 12px 16px;\n border-radius: inherit;\n font-size: 20px;\n font-weight: bold;\n line-height: 1;\n background-color: #7553FF;\n border: 1px solid #553DB8;\n transform: translateY(-4px);\n }\n\n &:hover > span {\n transform: translateY(-8px);\n }\n\n &:active > span {\n transform: translateY(0);\n }\n\n &:disabled {\n cursor: not-allowed;\n opacity: 0.6;\n\n & > span {\n transform: translateY(0);\n border: none;\n }\n }\n }\n\n .description {\n text-align: center;\n color: #6E6C75;\n max-width: 500px;\n line-height: 1.5;\n font-size: 20px;\n\n @media (prefers-color-scheme: dark) {\n color: #A49FB5;\n }\n }\n\n .flex-spacer {\n flex: 1;\n }\n\n .success {\n padding: 12px 16px;\n border-radius: 8px;\n font-size: 20px;\n line-height: 1;\n background-color: #00F261;\n border: 1px solid #00BF4D;\n color: #181423;\n }\n\n .success_placeholder {\n height: 46px;\n }\n\n .connectivity-error {\n padding: 12px 16px;\n background-color: #E50045;\n border-radius: 8px;\n width: 500px;\n color: #FFFFFF;\n border: 1px solid #A80033;\n text-align: center;\n margin: 0;\n }\n \n .connectivity-error a {\n color: #FFFFFF;\n text-decoration: underline;\n }\n</style>\n`;\n}\n\nexport function getSentryExampleApiRoute() {\n return `// This is just a very simple API route that throws an example error.\n// Feel free to delete this file and the entire sentry route.\n\nexport const GET = async () => {\n throw new Error(\"Sentry Example API Route Error\");\n};\n`;\n}\n"]}
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const WIZARD_VERSION = "
|
|
1
|
+
export declare const WIZARD_VERSION = "6.1.0";
|
package/dist/src/version.js
CHANGED
package/dist/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA,oCAAoC;AACpC,2CAA2C;;;AAE9B,QAAA,cAAc,GAAG,OAAO,CAAC","sourcesContent":["// DO NOT modify this file manually!\n// This is file is updated at release time.\n\nexport const WIZARD_VERSION = '
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA,oCAAoC;AACpC,2CAA2C;;;AAE9B,QAAA,cAAc,GAAG,OAAO,CAAC","sourcesContent":["// DO NOT modify this file manually!\n// This is file is updated at release time.\n\nexport const WIZARD_VERSION = '6.1.0';\n"]}
|