@sentry/wizard 4.2.0 → 4.4.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/e2e-tests/tests/{nextjs.test.js → nextjs-14.test.js} +3 -3
  3. package/dist/e2e-tests/tests/nextjs-14.test.js.map +1 -0
  4. package/dist/e2e-tests/tests/nextjs-15.test.d.ts +1 -0
  5. package/dist/e2e-tests/tests/nextjs-15.test.js +123 -0
  6. package/dist/e2e-tests/tests/nextjs-15.test.js.map +1 -0
  7. package/dist/src/apple/apple-wizard.js +5 -1
  8. package/dist/src/apple/apple-wizard.js.map +1 -1
  9. package/dist/src/flutter/flutter-wizard.js +3 -1
  10. package/dist/src/flutter/flutter-wizard.js.map +1 -1
  11. package/dist/src/nextjs/nextjs-wizard.js +5 -4
  12. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  13. package/dist/src/nuxt/sdk-setup.js +1 -1
  14. package/dist/src/nuxt/sdk-setup.js.map +1 -1
  15. package/dist/src/react-native/javascript.d.ts +16 -0
  16. package/dist/src/react-native/javascript.js +141 -6
  17. package/dist/src/react-native/javascript.js.map +1 -1
  18. package/dist/src/react-native/react-native-wizard.js +1 -0
  19. package/dist/src/react-native/react-native-wizard.js.map +1 -1
  20. package/dist/src/remix/remix-wizard.js +1 -1
  21. package/dist/src/remix/remix-wizard.js.map +1 -1
  22. package/dist/src/sourcemaps/sourcemaps-wizard.d.ts +1 -0
  23. package/dist/src/sourcemaps/sourcemaps-wizard.js +14 -30
  24. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  25. package/dist/src/sourcemaps/utils/detect-tool.js +0 -2
  26. package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
  27. package/dist/src/sveltekit/sdk-setup.js +1 -1
  28. package/dist/src/sveltekit/sdk-setup.js.map +1 -1
  29. package/dist/src/version.d.ts +1 -1
  30. package/dist/src/version.js +1 -1
  31. package/dist/src/version.js.map +1 -1
  32. package/dist/test/react-native/javascript.test.js +406 -0
  33. package/dist/test/react-native/javascript.test.js.map +1 -1
  34. package/package.json +2 -2
  35. package/dist/e2e-tests/tests/nextjs.test.js.map +0 -1
  36. /package/dist/e2e-tests/tests/{nextjs.test.d.ts → nextjs-14.test.d.ts} +0 -0
@@ -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,yEAAyE;AACzE,6DAAmC;AAGnC,4EAA4E;AAC5E,uCAAyE;AACzE,4EAA4E;AAC5E,8CAAiD;AACjD,2CAA6E;AAC7E,sDAI8B;AAC9B,0CAAuC;AACvC,kDAAgE;AAKhE,4CAAyC;AAEzC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAsBvC,KAAK,UAAU,2BAA2B,CAC/C,WAAwB,EACxB,YAAiC;IAEjC,MAAM,gBAAgB,GAAG,MAAM,IAAA,oCAAsB,EAAC;QACpD;YACE,EAAE,EAAE,aAAa;YACjB,MAAM,EAAE,yBAAyB,eAAK,CAAC,IAAI,CACzC,SAAS,CACV,gDAAgD;YACjD,WAAW,EAAE,aAAa;SAC3B;QACD;YACE,EAAE,EAAE,QAAQ;YACZ,MAAM,EAAE,yBAAyB,eAAK,CAAC,IAAI,CACzC,uBAAuB,CACxB,oEAAoE;YACrE,WAAW,EAAE,wCAAwC;SACtD;KACO,CAAC,CAAC;IAEZ,MAAM,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAE9E,uEAAuE;IACvE,MAAM,uBAAuB,GAAG,IAAA,oBAAQ,EAAC,eAAe,CAAC,CAAC;IAC1D,MAAM,uBAAuB,GAAG,IAAA,oBAAQ,EAA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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-ignore - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { builders, generateCode, loadFile, parseModule } from 'magicast';\n// @ts-ignore - 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-utils';\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 'Sentry 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-ignore - 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-ignore - 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-ignore - 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-ignore - 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 // @ts-ignore - id should always have a name in this case\n if (!declaration.id || declaration.id.name !== 'handle') {\n return;\n }\n const userCode = declaration.init;\n const stringifiedUserCode = userCode ? generateCode(userCode).code : '';\n // @ts-ignore - 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
+ {"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,yEAAyE;AACzE,6DAAmC;AAGnC,4EAA4E;AAC5E,uCAAyE;AACzE,4EAA4E;AAC5E,8CAAiD;AACjD,2CAA6E;AAC7E,sDAI8B;AAC9B,0CAAuC;AACvC,kDAAgE;AAKhE,4CAAyC;AAEzC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAsBvC,KAAK,UAAU,2BAA2B,CAC/C,WAAwB,EACxB,YAAiC;IAEjC,MAAM,gBAAgB,GAAG,MAAM,IAAA,oCAAsB,EAAC;QACpD;YACE,EAAE,EAAE,aAAa;YACjB,MAAM,EAAE,yBAAyB,eAAK,CAAC,IAAI,CACzC,SAAS,CACV,gDAAgD;YACjD,WAAW,EAAE,aAAa;SAC3B;QACD;YACE,EAAE,EAAE,QAAQ;YACZ,MAAM,EAAE,yBAAyB,eAAK,CAAC,IAAI,CACzC,gBAAgB,CACjB,oEAAoE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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-ignore - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { builders, generateCode, loadFile, parseModule } from 'magicast';\n// @ts-ignore - 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-utils';\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-ignore - 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-ignore - 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-ignore - 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-ignore - 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 // @ts-ignore - id should always have a name in this case\n if (!declaration.id || declaration.id.name !== 'handle') {\n return;\n }\n const userCode = declaration.init;\n const stringifiedUserCode = userCode ? generateCode(userCode).code : '';\n // @ts-ignore - 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 +1 @@
1
- export declare const WIZARD_VERSION = "4.2.0";
1
+ export declare const WIZARD_VERSION = "4.4.0";
@@ -3,5 +3,5 @@
3
3
  // This is file is updated at release time.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.WIZARD_VERSION = void 0;
6
- exports.WIZARD_VERSION = '4.2.0';
6
+ exports.WIZARD_VERSION = '4.4.0';
7
7
  //# sourceMappingURL=version.js.map
@@ -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 = '4.2.0';\n"]}
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 = '4.4.0';\n"]}
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const javascript_1 = require("../../src/react-native/javascript");
4
+ // @ts-ignore - magicast is ESM and TS complains about that. It works though
5
+ const magicast_1 = require("magicast");
4
6
  describe('react-native javascript', () => {
5
7
  describe('addSentryInitWithSdkImport', () => {
6
8
  it('adds sdk import and sentry init under last import in the file', () => {
@@ -109,5 +111,409 @@ export default App;`;
109
111
  })).toBe(false);
110
112
  });
111
113
  });
114
+ describe('addSentryWrap', () => {
115
+ it('wraps the root app component', () => {
116
+ const mod = (0, magicast_1.parseModule)(`import * as React from 'react';
117
+ import * as Sentry from '@sentry/react-native';
118
+
119
+ import { View } from 'react-native';
120
+
121
+ const App = () => {
122
+ return (
123
+ <View>
124
+ Test App
125
+ </View>
126
+ );
127
+ };
128
+
129
+ export default App;`);
130
+ const expectedOutput = `import * as React from 'react';
131
+ import * as Sentry from '@sentry/react-native';
132
+
133
+ import { View } from 'react-native';
134
+
135
+ const App = () => {
136
+ return (
137
+ <View>
138
+ Test App
139
+ </View>
140
+ );
141
+ };
142
+
143
+ export default Sentry.wrap(App);`;
144
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
145
+ expect(result).toBe(javascript_1.SentryWrapResult.Success);
146
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
147
+ });
148
+ it('wraps a wrapped root app component', () => {
149
+ const mod = (0, magicast_1.parseModule)(`import * as React from 'react';
150
+ import * as Sentry from '@sentry/react-native';
151
+
152
+ import { View } from 'react-native';
153
+
154
+ const App = () => {
155
+ return (
156
+ <View>
157
+ Test App
158
+ </View>
159
+ );
160
+ };
161
+
162
+ export default AnotheWrapper.wrap(App);`);
163
+ const expectedOutput = `import * as React from 'react';
164
+ import * as Sentry from '@sentry/react-native';
165
+
166
+ import { View } from 'react-native';
167
+
168
+ const App = () => {
169
+ return (
170
+ <View>
171
+ Test App
172
+ </View>
173
+ );
174
+ };
175
+
176
+ export default Sentry.wrap(AnotheWrapper.wrap(App));`;
177
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
178
+ expect(result).toBe(javascript_1.SentryWrapResult.Success);
179
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
180
+ });
181
+ it('wraps a root app named function', () => {
182
+ const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
183
+
184
+ export default function RootLayout() {
185
+ return (
186
+ <View>
187
+ Test App
188
+ </View>
189
+ );
190
+ }`);
191
+ const expectedOutput = `import * as Sentry from '@sentry/react-native';
192
+
193
+ export default Sentry.wrap(function RootLayout() {
194
+ return (
195
+ <View>
196
+ Test App
197
+ </View>
198
+ );
199
+ });`;
200
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
201
+ expect(result).toBe(javascript_1.SentryWrapResult.Success);
202
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
203
+ });
204
+ it('wraps a wrapped root app named function', () => {
205
+ const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
206
+
207
+ export default Another.wrapper(function RootLayout() {
208
+ return (
209
+ <View>
210
+ Test App
211
+ </View>
212
+ );
213
+ });`);
214
+ const expectedOutput = `import * as Sentry from '@sentry/react-native';
215
+
216
+ export default Sentry.wrap(Another.wrapper(function RootLayout() {
217
+ return (
218
+ <View>
219
+ Test App
220
+ </View>
221
+ );
222
+ }));`;
223
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
224
+ expect(result).toBe(javascript_1.SentryWrapResult.Success);
225
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
226
+ });
227
+ it('wraps a root app anonymous function', () => {
228
+ const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
229
+
230
+ export default () => {
231
+ return (
232
+ <View>
233
+ Test App
234
+ </View>
235
+ );
236
+ }`);
237
+ const expectedOutput = `import * as Sentry from '@sentry/react-native';
238
+
239
+ export default Sentry.wrap(() => {
240
+ return (
241
+ <View>
242
+ Test App
243
+ </View>
244
+ );
245
+ });`;
246
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
247
+ expect(result).toBe(javascript_1.SentryWrapResult.Success);
248
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
249
+ });
250
+ it('wraps a wrapped root app anonymous function', () => {
251
+ const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
252
+
253
+ export default Another.wrap(() => {
254
+ return (
255
+ <View>
256
+ Test App
257
+ </View>
258
+ );
259
+ });`);
260
+ const expectedOutput = `import * as Sentry from '@sentry/react-native';
261
+
262
+ export default Sentry.wrap(Another.wrap(() => {
263
+ return (
264
+ <View>
265
+ Test App
266
+ </View>
267
+ );
268
+ }));`;
269
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
270
+ expect(result).toBe(javascript_1.SentryWrapResult.Success);
271
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
272
+ });
273
+ it('wraps a complex root function', () => {
274
+ // This is the default export for a new Expo 52 project
275
+ const mod = (0, magicast_1.parseModule)(`import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
276
+ import { useFonts } from 'expo-font';
277
+ import { Stack } from 'expo-router';
278
+ import * as SplashScreen from 'expo-splash-screen';
279
+ import { StatusBar } from 'expo-status-bar';
280
+ import { useEffect } from 'react';
281
+ import 'react-native-reanimated';
282
+
283
+ import { useColorScheme } from '@/hooks/useColorScheme';
284
+ import * as Sentry from '@sentry/react-native';
285
+
286
+ Sentry.init({
287
+ dsn: 'https://sentry.io/123',
288
+
289
+ // uncomment the line below to enable Spotlight (https://spotlightjs.com)
290
+ // spotlight: __DEV__,
291
+ });
292
+
293
+ // Prevent the splash screen from auto-hiding before asset loading is complete.
294
+ SplashScreen.preventAutoHideAsync();
295
+
296
+ export default function RootLayout() {
297
+ const colorScheme = useColorScheme();
298
+ const [loaded] = useFonts({
299
+ SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
300
+ });
301
+
302
+ useEffect(() => {
303
+ if (loaded) {
304
+ SplashScreen.hideAsync();
305
+ }
306
+ }, [loaded]);
307
+
308
+ if (!loaded) {
309
+ return null;
310
+ }
311
+
312
+ return (
313
+ <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
314
+ <Stack>
315
+ <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
316
+ <Stack.Screen name="+not-found" />
317
+ </Stack>
318
+ <StatusBar style="auto" />
319
+ </ThemeProvider>
320
+ );
321
+ }
322
+ `);
323
+ const expectedOutput = `import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
324
+ import { useFonts } from 'expo-font';
325
+ import { Stack } from 'expo-router';
326
+ import * as SplashScreen from 'expo-splash-screen';
327
+ import { StatusBar } from 'expo-status-bar';
328
+ import { useEffect } from 'react';
329
+ import 'react-native-reanimated';
330
+
331
+ import { useColorScheme } from '@/hooks/useColorScheme';
332
+ import * as Sentry from '@sentry/react-native';
333
+
334
+ Sentry.init({
335
+ dsn: 'https://sentry.io/123',
336
+
337
+ // uncomment the line below to enable Spotlight (https://spotlightjs.com)
338
+ // spotlight: __DEV__,
339
+ });
340
+
341
+ // Prevent the splash screen from auto-hiding before asset loading is complete.
342
+ SplashScreen.preventAutoHideAsync();
343
+
344
+ export default Sentry.wrap(function RootLayout() {
345
+ const colorScheme = useColorScheme();
346
+ const [loaded] = useFonts({
347
+ SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
348
+ });
349
+
350
+ useEffect(() => {
351
+ if (loaded) {
352
+ SplashScreen.hideAsync();
353
+ }
354
+ }, [loaded]);
355
+
356
+ if (!loaded) {
357
+ return null;
358
+ }
359
+
360
+ return (
361
+ <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
362
+ <Stack>
363
+ <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
364
+ <Stack.Screen name="+not-found" />
365
+ </Stack>
366
+ <StatusBar style="auto" />
367
+ </ThemeProvider>
368
+ );
369
+ });`;
370
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
371
+ expect(result).toBe(javascript_1.SentryWrapResult.Success);
372
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
373
+ });
374
+ it('wraps a root app anonymous complex function', () => {
375
+ const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
376
+
377
+ export default () => {
378
+ const colorScheme = useColorScheme();
379
+ const [loaded] = useFonts({
380
+ SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
381
+ });
382
+
383
+ useEffect(() => {
384
+ if (loaded) {
385
+ SplashScreen.hideAsync();
386
+ }
387
+ }, [loaded]);
388
+
389
+ if (!loaded) {
390
+ return null;
391
+ }
392
+
393
+ return (
394
+ <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
395
+ <Stack>
396
+ <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
397
+ <Stack.Screen name="+not-found" />
398
+ </Stack>
399
+ <StatusBar style="auto" />
400
+ </ThemeProvider>
401
+ );
402
+ }`);
403
+ const expectedOutput = `import * as Sentry from '@sentry/react-native';
404
+
405
+ export default Sentry.wrap(() => {
406
+ const colorScheme = useColorScheme();
407
+ const [loaded] = useFonts({
408
+ SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
409
+ });
410
+
411
+ useEffect(() => {
412
+ if (loaded) {
413
+ SplashScreen.hideAsync();
414
+ }
415
+ }, [loaded]);
416
+
417
+ if (!loaded) {
418
+ return null;
419
+ }
420
+
421
+ return (
422
+ <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
423
+ <Stack>
424
+ <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
425
+ <Stack.Screen name="+not-found" />
426
+ </Stack>
427
+ <StatusBar style="auto" />
428
+ </ThemeProvider>
429
+ );
430
+ });`;
431
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
432
+ expect(result).toBe(javascript_1.SentryWrapResult.Success);
433
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
434
+ });
435
+ it('wraps a default class export', () => {
436
+ const mod = (0, magicast_1.parseModule)(`import * as Sentry from '@sentry/react-native';
437
+
438
+ export default class RootLayout extends React.Component {
439
+ render() {
440
+ return (
441
+ <View>
442
+ Test App
443
+ </View>
444
+ );
445
+ }
446
+ }`);
447
+ const expectedOutput = `import * as Sentry from '@sentry/react-native';
448
+
449
+ export default Sentry.wrap(class RootLayout extends React.Component {
450
+ render() {
451
+ return (
452
+ <View>
453
+ Test App
454
+ </View>
455
+ );
456
+ }
457
+ });`;
458
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
459
+ expect(result).toBe(javascript_1.SentryWrapResult.Success);
460
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(expectedOutput);
461
+ });
462
+ it('does not wrap a root app component if not found', () => {
463
+ const input = `import * as React from 'react';
464
+
465
+ import { View } from 'react-native';
466
+
467
+ const App = () => {
468
+ return (
469
+ <View>
470
+ Test App
471
+ </View>
472
+ );
473
+ };
474
+
475
+ export { App };`;
476
+ const mod = (0, magicast_1.parseModule)(input);
477
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
478
+ expect(result).toBe(javascript_1.SentryWrapResult.NotFound);
479
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(input);
480
+ });
481
+ it('does not wrap a root app component if already wrapped', () => {
482
+ const input = `import * as React from 'react';
483
+ import * as Sentry from '@sentry/react-native';
484
+
485
+ import { View } from 'react-native';
486
+
487
+ const App = () => {
488
+ return (
489
+ <View>
490
+ Test App
491
+ </View>
492
+ );
493
+ };
494
+
495
+ export default Sentry.wrap(App);`;
496
+ const mod = (0, magicast_1.parseModule)(input);
497
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
498
+ expect(result).toBe(javascript_1.SentryWrapResult.AlreadyWrapped);
499
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(input);
500
+ });
501
+ it('does not wrap the root app component in an empty file', () => {
502
+ const mod = (0, magicast_1.parseModule)(``);
503
+ const result = (0, javascript_1.checkAndWrapRootComponent)(mod);
504
+ expect(result).toBe(javascript_1.SentryWrapResult.NotFound);
505
+ expect((0, magicast_1.generateCode)(mod.$ast).code).toBe(``);
506
+ });
507
+ });
508
+ it('does detect Sentry.wrap if exists', () => {
509
+ const mod = (0, magicast_1.parseModule)(`export default Sentry.wrap(App);`);
510
+ const result = (0, javascript_1.doesContainSentryWrap)(mod.$ast);
511
+ expect(result).toBeTruthy();
512
+ });
513
+ it('does not detect Sentry.wrap if not present', () => {
514
+ const mod = (0, magicast_1.parseModule)(`export default App;`);
515
+ const result = (0, javascript_1.doesContainSentryWrap)(mod.$ast);
516
+ expect(result).toBeFalsy();
517
+ });
112
518
  });
113
519
  //# sourceMappingURL=javascript.test.js.map