@sentry/wizard 3.24.0 → 3.25.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 (58) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/package.json +1 -1
  3. package/dist/src/nextjs/templates.js +1 -1
  4. package/dist/src/nextjs/templates.js.map +1 -1
  5. package/dist/src/react-native/expo-env-file.d.ts +2 -0
  6. package/dist/src/react-native/expo-env-file.js +127 -0
  7. package/dist/src/react-native/expo-env-file.js.map +1 -0
  8. package/dist/src/react-native/expo-metro.d.ts +7 -0
  9. package/dist/src/react-native/expo-metro.js +236 -0
  10. package/dist/src/react-native/expo-metro.js.map +1 -0
  11. package/dist/src/react-native/expo.d.ts +16 -0
  12. package/dist/src/react-native/expo.js +195 -0
  13. package/dist/src/react-native/expo.js.map +1 -0
  14. package/dist/src/react-native/git.d.ts +1 -0
  15. package/dist/src/react-native/git.js +85 -0
  16. package/dist/src/react-native/git.js.map +1 -0
  17. package/dist/src/react-native/javascript.d.ts +3 -0
  18. package/dist/src/react-native/javascript.js +119 -1
  19. package/dist/src/react-native/javascript.js.map +1 -1
  20. package/dist/src/react-native/metro.d.ts +3 -0
  21. package/dist/src/react-native/metro.js +17 -15
  22. package/dist/src/react-native/metro.js.map +1 -1
  23. package/dist/src/react-native/react-native-wizard.d.ts +12 -0
  24. package/dist/src/react-native/react-native-wizard.js +91 -78
  25. package/dist/src/react-native/react-native-wizard.js.map +1 -1
  26. package/dist/src/react-native/xcode.js +14 -3
  27. package/dist/src/react-native/xcode.js.map +1 -1
  28. package/dist/src/sourcemaps/sourcemaps-wizard.js +1 -1
  29. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  30. package/dist/src/utils/clack-utils.d.ts +2 -1
  31. package/dist/src/utils/clack-utils.js +2 -2
  32. package/dist/src/utils/clack-utils.js.map +1 -1
  33. package/dist/test/nextjs/templates.test.js +1 -1
  34. package/dist/test/nextjs/templates.test.js.map +1 -1
  35. package/dist/test/react-native/expo-metro.test.d.ts +1 -0
  36. package/dist/test/react-native/expo-metro.test.js +26 -0
  37. package/dist/test/react-native/expo-metro.test.js.map +1 -0
  38. package/dist/test/react-native/expo.test.d.ts +1 -0
  39. package/dist/test/react-native/expo.test.js +57 -0
  40. package/dist/test/react-native/expo.test.js.map +1 -0
  41. package/dist/test/react-native/xcode.test.js +5 -0
  42. package/dist/test/react-native/xcode.test.js.map +1 -1
  43. package/package.json +1 -1
  44. package/src/nextjs/templates.ts +1 -1
  45. package/src/react-native/expo-env-file.ts +55 -0
  46. package/src/react-native/expo-metro.ts +212 -0
  47. package/src/react-native/expo.ts +175 -0
  48. package/src/react-native/git.ts +25 -0
  49. package/src/react-native/javascript.ts +68 -1
  50. package/src/react-native/metro.ts +3 -3
  51. package/src/react-native/react-native-wizard.ts +72 -76
  52. package/src/react-native/xcode.ts +21 -5
  53. package/src/sourcemaps/sourcemaps-wizard.ts +1 -1
  54. package/src/utils/clack-utils.ts +4 -4
  55. package/test/nextjs/templates.test.ts +1 -1
  56. package/test/react-native/expo-metro.test.ts +81 -0
  57. package/test/react-native/expo.test.ts +86 -0
  58. package/test/react-native/xcode.test.ts +90 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.25.0
4
+
5
+ - feat(react-native): Add support for Expo projects (#505)
6
+
7
+ ## 3.24.1
8
+
9
+ - fix(nextjs): Add trailing comma to `sentryUrl` option in `withSentryConfig` template (#601)
10
+
3
11
  ## 3.24.0
4
12
 
5
13
  - feat(remix): Switch to OTEL setup (#593)
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/wizard",
3
- "version": "3.24.0",
3
+ "version": "3.25.0",
4
4
  "homepage": "https://github.com/getsentry/sentry-wizard",
5
5
  "repository": "https://github.com/getsentry/sentry-wizard",
6
6
  "description": "Sentry wizard helping you to configure your project",
@@ -8,7 +8,7 @@ var chalk_1 = __importDefault(require("chalk"));
8
8
  var clack_utils_1 = require("../utils/clack-utils");
9
9
  function getWithSentryConfigOptionsTemplate(_a) {
10
10
  var orgSlug = _a.orgSlug, projectSlug = _a.projectSlug, selfHosted = _a.selfHosted, tunnelRoute = _a.tunnelRoute, sentryUrl = _a.sentryUrl;
11
- return "{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n org: \"".concat(orgSlug, "\",\n project: \"").concat(projectSlug, "\",").concat(selfHosted ? "\n sentryUrl: \"".concat(sentryUrl, "\"") : '', "\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // ").concat(tunnelRoute ? 'Route' : 'Uncomment to route', " browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n ").concat(tunnelRoute ? '' : '// ', "tunnelRoute: \"/monitoring\",\n\n // Hides source maps from generated client bundles\n hideSourceMaps: true,\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }");
11
+ return "{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n org: \"".concat(orgSlug, "\",\n project: \"").concat(projectSlug, "\",").concat(selfHosted ? "\n sentryUrl: \"".concat(sentryUrl, "\",") : '', "\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // ").concat(tunnelRoute ? 'Route' : 'Uncomment to route', " browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n ").concat(tunnelRoute ? '' : '// ', "tunnelRoute: \"/monitoring\",\n\n // Hides source maps from generated client bundles\n hideSourceMaps: true,\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }");
12
12
  }
13
13
  exports.getWithSentryConfigOptionsTemplate = getWithSentryConfigOptionsTemplate;
14
14
  function getNextjsConfigCjsTemplate(withSentryConfigOptionsTemplate) {
@@ -1 +1 @@
1
- {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/nextjs/templates.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA0B;AAC1B,oDAAuD;AAUvD,SAAgB,kCAAkC,CAAC,EAMzB;QALxB,OAAO,aAAA,EACP,WAAW,iBAAA,EACX,UAAU,gBAAA,EACV,WAAW,iBAAA,EACX,SAAS,eAAA;IAET,OAAO,qIAIG,OAAO,iCACH,WAAW,gBACvB,UAAU,CAAC,CAAC,CAAC,6BAAqB,SAAS,OAAG,CAAC,CAAC,CAAC,EAAE,0WAajD,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,qUAK5C,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,6gBAa1B,CAAC;AACL,CAAC;AA7CD,gFA6CC;AAED,SAAgB,0BAA0B,CACxC,+BAAuC;IAEvC,OAAO,gMAOL,+BAA+B,WAElC,CAAC;AACF,CAAC;AAbD,gEAaC;AAED,SAAgB,0BAA0B,CACxC,+BAAuC;IAEvC,OAAO,mLAQL,+BAA+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AK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,gCAErD,CAAC,QACH,CAAC,CAAC;IACF,CAAC,CAAC,CAAC;AACL,CAAC;AAlBD,wFAkBC;AAED,SAAgB,+BAA+B,CAAC,IAAa;IAC3D,OAAO,IAAI;QACT,CAAC,CAAC,wrBAsBJ;QACE,CAAC,CAAC,kpBAuBL,CAAC;AACF,CAAC;AAjDD,0EAiDC;AAED,SAAgB,8BAA8B,CAAC,IAAa;IAC1D,IAAI,IAAI,EAAE;QACR,OAAO,6BAET,eAAK,CAAC,KAAK,CAAC,2CAA2C,CAAC,eACxD,eAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC,eAC9C,eAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC,qDAEb,eAAK,CAAC,KAAK,CAC3C,6BAA6B,CAC9B,oBACD,eAAK,CAAC,KAAK,CAAC,wEAED,CAAC,kIAUf,CAAC;KACC;SAAM;QACL,OAAO,6BAET,eAAK,CAAC,KAAK,CAAC,2CAA2C,CAAC,eACxD,eAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC,eAC9C,eAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC,qDAEb,eAAK,CAAC,KAAK,CAAC,WAAW,CAAC,oBAC1D,eAAK,CAAC,KAAK,CAAC,wEAED,CAAC,kIAUf,CAAC;KACC;AACH,CAAC;AA9CD,wEA8CC","sourcesContent":["import chalk from 'chalk';\nimport { makeCodeSnippet } from '../utils/clack-utils';\n\ntype WithSentryConfigOptions = {\n orgSlug: string;\n projectSlug: string;\n selfHosted: boolean;\n sentryUrl: string;\n tunnelRoute: boolean;\n};\n\nexport function getWithSentryConfigOptionsTemplate({\n orgSlug,\n projectSlug,\n selfHosted,\n tunnelRoute,\n sentryUrl,\n}: WithSentryConfigOptions): string {\n return `{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n org: \"${orgSlug}\",\n project: \"${projectSlug}\",${\n selfHosted ? `\\n sentryUrl: \"${sentryUrl}\"` : ''\n }\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // ${\n tunnelRoute ? 'Route' : 'Uncomment to route'\n } browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n ${tunnelRoute ? '' : '// '}tunnelRoute: \"/monitoring\",\n\n // Hides source maps from generated client bundles\n hideSourceMaps: true,\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }`;\n}\n\nexport function getNextjsConfigCjsTemplate(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `const { withSentryConfig } = require(\"@sentry/nextjs\");\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {};\n\nmodule.exports = withSentryConfig(\n nextConfig,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigCjsAppendix(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `\n\n// Injected content via Sentry wizard below\n\nconst { withSentryConfig } = require(\"@sentry/nextjs\");\n\nmodule.exports = withSentryConfig(\n module.exports,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigEsmCopyPasteSnippet(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `\n\n// next.config.mjs\nimport { withSentryConfig } from \"@sentry/nextjs\";\n\nexport default withSentryConfig(\n yourNextConfig,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getSentryConfigContents(\n dsn: string,\n config: 'server' | 'client' | 'edge',\n): string {\n let primer;\n if (config === 'server') {\n primer = `// This file configures the initialization of Sentry on the server.\n// The config you add here will be used whenever the server handles a request.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'client') {\n primer = `// This file configures the initialization of Sentry on the client.\n// The config you add here will be used whenever a users loads a page in their browser.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'edge') {\n primer = `// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).\n// The config you add here will be used whenever one of the edge features is loaded.\n// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n }\n\n let additionalOptions = '';\n if (config === 'client') {\n additionalOptions = `\n\n replaysOnErrorSampleRate: 1.0,\n\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 // You can remove this option if you're not planning to use the Sentry Session Replay feature:\n integrations: [\n Sentry.replayIntegration({\n // Additional Replay configuration goes in here, for example:\n maskAllText: true,\n blockAllMedia: true,\n }),\n ],`;\n }\n\n let spotlightOption = '';\n if (config === 'server') {\n spotlightOption = `\n\n // Uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: process.env.NODE_ENV === 'development',\n `;\n }\n\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${primer}\n\nimport * as Sentry from \"@sentry/nextjs\";\n\nSentry.init({\n dsn: \"${dsn}\",\n\n // Adjust this value in production, or use tracesSampler for greater control\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,${additionalOptions}${spotlightOption}\n});\n`;\n}\n\nexport function getSentryExamplePageContents(options: {\n selfHosted: boolean;\n sentryUrl: string;\n orgSlug: string;\n projectId: string;\n useClient: boolean;\n}): string {\n const issuesPageLink = options.selfHosted\n ? `${options.sentryUrl}organizations/${options.orgSlug}/issues/?project=${options.projectId}`\n : `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;\n\n return `${\n options.useClient ? '\"use client\";\\n\\n' : ''\n }import Head from \"next/head\";\nimport * as Sentry from \"@sentry/nextjs\";\n\nexport default function Page() {\n return (\n <div>\n <Head>\n <title>Sentry Onboarding</title>\n <meta name=\"description\" content=\"Test Sentry for your Next.js app!\" />\n </Head>\n\n <main\n style={{\n minHeight: \"100vh\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: \"center\",\n }}\n >\n <h1 style={{ fontSize: \"4rem\", margin: \"14px 0\" }}>\n <svg\n style={{\n height: \"1em\",\n }}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 200 44\"\n >\n <path\n fill=\"currentColor\"\n d=\"M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z\"\n ></path>\n </svg>\n </h1>\n\n <p>Get started by sending us a sample error:</p>\n <button\n type=\"button\"\n style={{\n padding: \"12px\",\n cursor: \"pointer\",\n backgroundColor: \"#AD6CAA\",\n borderRadius: \"4px\",\n border: \"none\",\n color: \"white\",\n fontSize: \"14px\",\n margin: \"18px\",\n }}\n onClick={async () => {\n await Sentry.startSpan({\n name: 'Example Frontend Span',\n op: 'test'\n }, async () => {\n const res = await fetch(\"/api/sentry-example-api\");\n if (!res.ok) {\n throw new Error(\"Sentry Example Frontend Error\");\n }\n });\n }}\n >\n Throw error!\n </button>\n\n <p>\n Next, look for the error on the{\" \"}\n <a href=\"${issuesPageLink}\">Issues Page</a>.\n </p>\n <p style={{ marginTop: \"24px\" }}>\n For more information, see{\" \"}\n <a href=\"https://docs.sentry.io/platforms/javascript/guides/nextjs/\">\n https://docs.sentry.io/platforms/javascript/guides/nextjs/\n </a>\n </p>\n </main>\n </div>\n );\n}\n`;\n}\n\nexport function getSentryExampleApiRoute() {\n return `// A faulty API route to test Sentry's error monitoring\nexport default function handler(_req, res) {\n throw new Error(\"Sentry Example API Route Error\");\n res.status(200).json({ name: \"John Doe\" });\n}\n`;\n}\n\nexport function getSentryExampleAppDirApiRoute() {\n return `import { NextResponse } from \"next/server\";\n\nexport const dynamic = \"force-dynamic\";\n\n// A faulty API route to test Sentry's error monitoring\nexport function GET() {\n throw new Error(\"Sentry Example API Route Error\");\n return NextResponse.json({ data: \"Testing Sentry Error...\" });\n}\n`;\n}\n\nexport function getSentryDefaultUnderscoreErrorPage() {\n return `import * as Sentry from \"@sentry/nextjs\";\nimport Error from \"next/error\";\n\nconst CustomErrorComponent = (props) => {\n return <Error statusCode={props.statusCode} />;\n};\n\nCustomErrorComponent.getInitialProps = async (contextData) => {\n // In case this is running in a serverless function, await this in order to give Sentry\n // time to send the error before the lambda exits\n await Sentry.captureUnderscoreErrorException(contextData);\n\n // This will contain the status code of the response\n return Error.getInitialProps(contextData);\n};\n\nexport default CustomErrorComponent;\n`;\n}\n\nexport function getSimpleUnderscoreErrorCopyPasteSnippet() {\n return `\n${chalk.green(`import * as Sentry from '@sentry/nextjs';`)}\n\n${chalk.dim(\n '// Replace \"YourCustomErrorComponent\" with your custom error component!',\n)}\nYourCustomErrorComponent.getInitialProps = async (${chalk.green(\n `contextData`,\n )}) => {\n ${chalk.green('await Sentry.captureUnderscoreErrorException(contextData);')}\n\n ${chalk.dim('// ...other getInitialProps code')}\n};\n`;\n}\n\nexport function getFullUnderscoreErrorCopyPasteSnippet(isTs: boolean) {\n return `\nimport * as Sentry from '@sentry/nextjs';${\n isTs ? '\\nimport type { NextPageContext } from \"next\";' : ''\n }\n\n${chalk.dim(\n '// Replace \"YourCustomErrorComponent\" with your custom error component!',\n)}\nYourCustomErrorComponent.getInitialProps = async (contextData${\n isTs ? ': NextPageContext' : ''\n }) => {\n await Sentry.captureUnderscoreErrorException(contextData);\n};\n`;\n}\n\nexport function getInstrumentationHookContent(\n instrumentationHookLocation: 'src' | 'root',\n) {\n return `export async function register() {\n if (process.env.NEXT_RUNTIME === 'nodejs') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.server.config');\n }\n\n if (process.env.NEXT_RUNTIME === 'edge') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.edge.config');\n }\n}\n`;\n}\n\nexport function getInstrumentationHookCopyPasteSnippet(\n instrumentationHookLocation: 'src' | 'root',\n) {\n return makeCodeSnippet(true, (unchanged, plus) => {\n return unchanged(`export ${plus('async')} function register() {\n ${plus(`if (process.env.NEXT_RUNTIME === 'nodejs') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.server.config');\n }\n\n if (process.env.NEXT_RUNTIME === 'edge') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.edge.config');\n }`)}\n}`);\n });\n}\n\nexport function getSentryDefaultGlobalErrorPage(isTs: boolean) {\n return isTs\n ? `\"use client\";\n\nimport * as Sentry from \"@sentry/nextjs\";\nimport NextError from \"next/error\";\nimport { useEffect } from \"react\";\n\nexport default function GlobalError({ error }: { error: Error & { digest?: string } }) {\n useEffect(() => {\n Sentry.captureException(error);\n }, [error]);\n\n return (\n <html>\n <body>\n {/* \\`NextError\\` is the default Next.js error page component. Its type\n definition requires a \\`statusCode\\` prop. However, since the App Router\n does not expose status codes for errors, we simply pass 0 to render a\n generic error message. */}\n <NextError statusCode={0} />\n </body>\n </html>\n );\n}`\n : `\"use client\";\n\nimport * as Sentry from \"@sentry/nextjs\";\nimport NextError from \"next/error\";\nimport { useEffect } from \"react\";\n\nexport default function GlobalError({ error }) {\n useEffect(() => {\n Sentry.captureException(error);\n }, [error]);\n\n return (\n <html>\n <body>\n {/* \\`NextError\\` is the default Next.js error page component. Its type\n definition requires a \\`statusCode\\` prop. However, since the App Router\n does not expose status codes for errors, we simply pass 0 to render a\n generic error message. */}\n <NextError statusCode={0} />\n </body>\n </html>\n );\n}\n`;\n}\n\nexport function getGlobalErrorCopyPasteSnippet(isTs: boolean) {\n if (isTs) {\n return `\"use client\";\n\n${chalk.green('import * as Sentry from \"@sentry/nextjs\";')}\n${chalk.green('import Error from \"next/error\";')}\n${chalk.green('import { useEffect } from \"react\";')}\n\nexport default function GlobalError(${chalk.green(\n '{ error }: { error: Error }',\n )}) {\n ${chalk.green(`useEffect(() => {\n Sentry.captureException(error);\n }, [error]);`)}\n\n return (\n <html>\n <body>\n {/* Your Error component here... */}\n </body>\n </html>\n );\n}\n`;\n } else {\n return `\"use client\";\n\n${chalk.green('import * as Sentry from \"@sentry/nextjs\";')}\n${chalk.green('import Error from \"next/error\";')}\n${chalk.green('import { useEffect } from \"react\";')}\n\nexport default function GlobalError(${chalk.green('{ error }')}) {\n ${chalk.green(`useEffect(() => {\n Sentry.captureException(error);\n }, [error]);`)}\n\n return (\n <html>\n <body>\n {/* Your Error component here... */}\n </body>\n </html>\n );\n}\n`;\n }\n}\n"]}
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/nextjs/templates.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA0B;AAC1B,oDAAuD;AAUvD,SAAgB,kCAAkC,CAAC,EAMzB;QALxB,OAAO,aAAA,EACP,WAAW,iBAAA,EACX,UAAU,gBAAA,EACV,WAAW,iBAAA,EACX,SAAS,eAAA;IAET,OAAO,qIAIG,OAAO,iCACH,WAAW,gBACvB,UAAU,CAAC,CAAC,CAAC,6BAAqB,SAAS,QAAI,CAAC,CAAC,CAAC,EAAE,0WAalD,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,qUAK5C,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,6gBAa1B,CAAC;AACL,CAAC;AA7CD,gFA6CC;AAED,SAAgB,0BAA0B,CACxC,+BAAuC;IAEvC,OAAO,gMAOL,+BAA+B,WAElC,CAAC;AACF,CAAC;AAbD,gEAaC;AAED,SAAgB,0BAA0B,CACxC,+BAAuC;IAEvC,OAAO,mLAQL,+BAA+B,WAElC,CAAC;AACF,CAAC;AAdD,gEAcC;AAED,SAAgB,kCAAkC,CAChD,+BAAuC;IAEvC,OAAO,iJAOL,+BAA+B,WAElC,CAAC;AACF,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C;AAlBD,wFAkBC;AAED,SAAgB,+BAA+B,CAAC,IAAa;IAC3D,OAAO,IAAI;QACT,CAAC,CAAC,wrBAsBJ;QACE,CAAC,CAAC,kpBAuBL,CAAC;AACF,CAAC;AAjDD,0EAiDC;AAED,SAAgB,8BAA8B,CAAC,IAAa;IAC1D,IAAI,IAAI,EAAE;QACR,OAAO,6BAET,eAAK,CAAC,KAAK,CAAC,2CAA2C,CAAC,eACxD,eAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC,eAC9C,eAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC,qDAEb,eAAK,CAAC,KAAK,CAC3C,6BAA6B,CAC9B,oBACD,eAAK,CAAC,KAAK,CAAC,wEAED,CAAC,kIAUf,CAAC;KACC;SAAM;QACL,OAAO,6BAET,eAAK,CAAC,KAAK,CAAC,2CAA2C,CAAC,eACxD,eAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC,eAC9C,eAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC,qDAEb,eAAK,CAAC,KAAK,CAAC,WAAW,CAAC,oBAC1D,eAAK,CAAC,KAAK,CAAC,wEAED,CAAC,kIAUf,CAAC;KACC;AACH,CAAC;AA9CD,wEA8CC","sourcesContent":["import chalk from 'chalk';\nimport { makeCodeSnippet } from '../utils/clack-utils';\n\ntype WithSentryConfigOptions = {\n orgSlug: string;\n projectSlug: string;\n selfHosted: boolean;\n sentryUrl: string;\n tunnelRoute: boolean;\n};\n\nexport function getWithSentryConfigOptionsTemplate({\n orgSlug,\n projectSlug,\n selfHosted,\n tunnelRoute,\n sentryUrl,\n}: WithSentryConfigOptions): string {\n return `{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n org: \"${orgSlug}\",\n project: \"${projectSlug}\",${\n selfHosted ? `\\n sentryUrl: \"${sentryUrl}\",` : ''\n }\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,\n\n // ${\n tunnelRoute ? 'Route' : 'Uncomment to route'\n } browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n ${tunnelRoute ? '' : '// '}tunnelRoute: \"/monitoring\",\n\n // Hides source maps from generated client bundles\n hideSourceMaps: true,\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }`;\n}\n\nexport function getNextjsConfigCjsTemplate(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `const { withSentryConfig } = require(\"@sentry/nextjs\");\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {};\n\nmodule.exports = withSentryConfig(\n nextConfig,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigCjsAppendix(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `\n\n// Injected content via Sentry wizard below\n\nconst { withSentryConfig } = require(\"@sentry/nextjs\");\n\nmodule.exports = withSentryConfig(\n module.exports,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigEsmCopyPasteSnippet(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `\n\n// next.config.mjs\nimport { withSentryConfig } from \"@sentry/nextjs\";\n\nexport default withSentryConfig(\n yourNextConfig,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getSentryConfigContents(\n dsn: string,\n config: 'server' | 'client' | 'edge',\n): string {\n let primer;\n if (config === 'server') {\n primer = `// This file configures the initialization of Sentry on the server.\n// The config you add here will be used whenever the server handles a request.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'client') {\n primer = `// This file configures the initialization of Sentry on the client.\n// The config you add here will be used whenever a users loads a page in their browser.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'edge') {\n primer = `// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).\n// The config you add here will be used whenever one of the edge features is loaded.\n// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n }\n\n let additionalOptions = '';\n if (config === 'client') {\n additionalOptions = `\n\n replaysOnErrorSampleRate: 1.0,\n\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 // You can remove this option if you're not planning to use the Sentry Session Replay feature:\n integrations: [\n Sentry.replayIntegration({\n // Additional Replay configuration goes in here, for example:\n maskAllText: true,\n blockAllMedia: true,\n }),\n ],`;\n }\n\n let spotlightOption = '';\n if (config === 'server') {\n spotlightOption = `\n\n // Uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: process.env.NODE_ENV === 'development',\n `;\n }\n\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${primer}\n\nimport * as Sentry from \"@sentry/nextjs\";\n\nSentry.init({\n dsn: \"${dsn}\",\n\n // Adjust this value in production, or use tracesSampler for greater control\n tracesSampleRate: 1,\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,${additionalOptions}${spotlightOption}\n});\n`;\n}\n\nexport function getSentryExamplePageContents(options: {\n selfHosted: boolean;\n sentryUrl: string;\n orgSlug: string;\n projectId: string;\n useClient: boolean;\n}): string {\n const issuesPageLink = options.selfHosted\n ? `${options.sentryUrl}organizations/${options.orgSlug}/issues/?project=${options.projectId}`\n : `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;\n\n return `${\n options.useClient ? '\"use client\";\\n\\n' : ''\n }import Head from \"next/head\";\nimport * as Sentry from \"@sentry/nextjs\";\n\nexport default function Page() {\n return (\n <div>\n <Head>\n <title>Sentry Onboarding</title>\n <meta name=\"description\" content=\"Test Sentry for your Next.js app!\" />\n </Head>\n\n <main\n style={{\n minHeight: \"100vh\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: \"center\",\n }}\n >\n <h1 style={{ fontSize: \"4rem\", margin: \"14px 0\" }}>\n <svg\n style={{\n height: \"1em\",\n }}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 200 44\"\n >\n <path\n fill=\"currentColor\"\n d=\"M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z\"\n ></path>\n </svg>\n </h1>\n\n <p>Get started by sending us a sample error:</p>\n <button\n type=\"button\"\n style={{\n padding: \"12px\",\n cursor: \"pointer\",\n backgroundColor: \"#AD6CAA\",\n borderRadius: \"4px\",\n border: \"none\",\n color: \"white\",\n fontSize: \"14px\",\n margin: \"18px\",\n }}\n onClick={async () => {\n await Sentry.startSpan({\n name: 'Example Frontend Span',\n op: 'test'\n }, async () => {\n const res = await fetch(\"/api/sentry-example-api\");\n if (!res.ok) {\n throw new Error(\"Sentry Example Frontend Error\");\n }\n });\n }}\n >\n Throw error!\n </button>\n\n <p>\n Next, look for the error on the{\" \"}\n <a href=\"${issuesPageLink}\">Issues Page</a>.\n </p>\n <p style={{ marginTop: \"24px\" }}>\n For more information, see{\" \"}\n <a href=\"https://docs.sentry.io/platforms/javascript/guides/nextjs/\">\n https://docs.sentry.io/platforms/javascript/guides/nextjs/\n </a>\n </p>\n </main>\n </div>\n );\n}\n`;\n}\n\nexport function getSentryExampleApiRoute() {\n return `// A faulty API route to test Sentry's error monitoring\nexport default function handler(_req, res) {\n throw new Error(\"Sentry Example API Route Error\");\n res.status(200).json({ name: \"John Doe\" });\n}\n`;\n}\n\nexport function getSentryExampleAppDirApiRoute() {\n return `import { NextResponse } from \"next/server\";\n\nexport const dynamic = \"force-dynamic\";\n\n// A faulty API route to test Sentry's error monitoring\nexport function GET() {\n throw new Error(\"Sentry Example API Route Error\");\n return NextResponse.json({ data: \"Testing Sentry Error...\" });\n}\n`;\n}\n\nexport function getSentryDefaultUnderscoreErrorPage() {\n return `import * as Sentry from \"@sentry/nextjs\";\nimport Error from \"next/error\";\n\nconst CustomErrorComponent = (props) => {\n return <Error statusCode={props.statusCode} />;\n};\n\nCustomErrorComponent.getInitialProps = async (contextData) => {\n // In case this is running in a serverless function, await this in order to give Sentry\n // time to send the error before the lambda exits\n await Sentry.captureUnderscoreErrorException(contextData);\n\n // This will contain the status code of the response\n return Error.getInitialProps(contextData);\n};\n\nexport default CustomErrorComponent;\n`;\n}\n\nexport function getSimpleUnderscoreErrorCopyPasteSnippet() {\n return `\n${chalk.green(`import * as Sentry from '@sentry/nextjs';`)}\n\n${chalk.dim(\n '// Replace \"YourCustomErrorComponent\" with your custom error component!',\n)}\nYourCustomErrorComponent.getInitialProps = async (${chalk.green(\n `contextData`,\n )}) => {\n ${chalk.green('await Sentry.captureUnderscoreErrorException(contextData);')}\n\n ${chalk.dim('// ...other getInitialProps code')}\n};\n`;\n}\n\nexport function getFullUnderscoreErrorCopyPasteSnippet(isTs: boolean) {\n return `\nimport * as Sentry from '@sentry/nextjs';${\n isTs ? '\\nimport type { NextPageContext } from \"next\";' : ''\n }\n\n${chalk.dim(\n '// Replace \"YourCustomErrorComponent\" with your custom error component!',\n)}\nYourCustomErrorComponent.getInitialProps = async (contextData${\n isTs ? ': NextPageContext' : ''\n }) => {\n await Sentry.captureUnderscoreErrorException(contextData);\n};\n`;\n}\n\nexport function getInstrumentationHookContent(\n instrumentationHookLocation: 'src' | 'root',\n) {\n return `export async function register() {\n if (process.env.NEXT_RUNTIME === 'nodejs') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.server.config');\n }\n\n if (process.env.NEXT_RUNTIME === 'edge') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.edge.config');\n }\n}\n`;\n}\n\nexport function getInstrumentationHookCopyPasteSnippet(\n instrumentationHookLocation: 'src' | 'root',\n) {\n return makeCodeSnippet(true, (unchanged, plus) => {\n return unchanged(`export ${plus('async')} function register() {\n ${plus(`if (process.env.NEXT_RUNTIME === 'nodejs') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.server.config');\n }\n\n if (process.env.NEXT_RUNTIME === 'edge') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.edge.config');\n }`)}\n}`);\n });\n}\n\nexport function getSentryDefaultGlobalErrorPage(isTs: boolean) {\n return isTs\n ? `\"use client\";\n\nimport * as Sentry from \"@sentry/nextjs\";\nimport NextError from \"next/error\";\nimport { useEffect } from \"react\";\n\nexport default function GlobalError({ error }: { error: Error & { digest?: string } }) {\n useEffect(() => {\n Sentry.captureException(error);\n }, [error]);\n\n return (\n <html>\n <body>\n {/* \\`NextError\\` is the default Next.js error page component. Its type\n definition requires a \\`statusCode\\` prop. However, since the App Router\n does not expose status codes for errors, we simply pass 0 to render a\n generic error message. */}\n <NextError statusCode={0} />\n </body>\n </html>\n );\n}`\n : `\"use client\";\n\nimport * as Sentry from \"@sentry/nextjs\";\nimport NextError from \"next/error\";\nimport { useEffect } from \"react\";\n\nexport default function GlobalError({ error }) {\n useEffect(() => {\n Sentry.captureException(error);\n }, [error]);\n\n return (\n <html>\n <body>\n {/* \\`NextError\\` is the default Next.js error page component. Its type\n definition requires a \\`statusCode\\` prop. However, since the App Router\n does not expose status codes for errors, we simply pass 0 to render a\n generic error message. */}\n <NextError statusCode={0} />\n </body>\n </html>\n );\n}\n`;\n}\n\nexport function getGlobalErrorCopyPasteSnippet(isTs: boolean) {\n if (isTs) {\n return `\"use client\";\n\n${chalk.green('import * as Sentry from \"@sentry/nextjs\";')}\n${chalk.green('import Error from \"next/error\";')}\n${chalk.green('import { useEffect } from \"react\";')}\n\nexport default function GlobalError(${chalk.green(\n '{ error }: { error: Error }',\n )}) {\n ${chalk.green(`useEffect(() => {\n Sentry.captureException(error);\n }, [error]);`)}\n\n return (\n <html>\n <body>\n {/* Your Error component here... */}\n </body>\n </html>\n );\n}\n`;\n } else {\n return `\"use client\";\n\n${chalk.green('import * as Sentry from \"@sentry/nextjs\";')}\n${chalk.green('import Error from \"next/error\";')}\n${chalk.green('import { useEffect } from \"react\";')}\n\nexport default function GlobalError(${chalk.green('{ error }')}) {\n ${chalk.green(`useEffect(() => {\n Sentry.captureException(error);\n }, [error]);`)}\n\n return (\n <html>\n <body>\n {/* Your Error component here... */}\n </body>\n </html>\n );\n}\n`;\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { RNCliSetupConfigContent } from './react-native-wizard';
2
+ export declare function addExpoEnvLocal(options: RNCliSetupConfigContent): Promise<boolean>;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.addExpoEnvLocal = void 0;
66
+ // @ts-ignore - clack is ESM and TS complains about that. It works though
67
+ var clack = __importStar(require("@clack/prompts"));
68
+ var chalk_1 = __importDefault(require("chalk"));
69
+ var fs_1 = __importDefault(require("fs"));
70
+ var Sentry = __importStar(require("@sentry/node"));
71
+ var git_1 = require("./git");
72
+ var EXPO_ENV_LOCAL_FILE = '.env.local';
73
+ function addExpoEnvLocal(options) {
74
+ return __awaiter(this, void 0, void 0, function () {
75
+ var newContent, added, error_1, error_2;
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0:
79
+ newContent = "#DO NOT COMMIT THIS\nSENTRY_AUTH_TOKEN=".concat(options.authToken, "\n");
80
+ return [4 /*yield*/, (0, git_1.addToGitignore)(EXPO_ENV_LOCAL_FILE)];
81
+ case 1:
82
+ added = _a.sent();
83
+ if (added) {
84
+ clack.log.success("Added ".concat(chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE), " to .gitignore."));
85
+ }
86
+ else {
87
+ clack.log.error("Could not add ".concat(chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE), " to .gitignore, please add it to not commit your auth key."));
88
+ }
89
+ if (!!fs_1.default.existsSync(EXPO_ENV_LOCAL_FILE)) return [3 /*break*/, 5];
90
+ _a.label = 2;
91
+ case 2:
92
+ _a.trys.push([2, 4, , 5]);
93
+ return [4 /*yield*/, fs_1.default.promises.writeFile(EXPO_ENV_LOCAL_FILE, newContent)];
94
+ case 3:
95
+ _a.sent();
96
+ Sentry.setTag('expo-env-local', 'written');
97
+ clack.log.success("Written ".concat(chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE), "."));
98
+ return [2 /*return*/, true];
99
+ case 4:
100
+ error_1 = _a.sent();
101
+ Sentry.setTag('expo-env-local', 'write-error');
102
+ clack.log.error("Unable to write ".concat(chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE), "."));
103
+ return [2 /*return*/, false];
104
+ case 5:
105
+ Sentry.setTag('expo-env-local', 'exists');
106
+ clack.log.info("Updating existing ".concat(chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE), "."));
107
+ _a.label = 6;
108
+ case 6:
109
+ _a.trys.push([6, 8, , 9]);
110
+ return [4 /*yield*/, fs_1.default.promises.appendFile(EXPO_ENV_LOCAL_FILE, newContent)];
111
+ case 7:
112
+ _a.sent();
113
+ Sentry.setTag('expo-env-local', 'updated');
114
+ clack.log.success("Updated ".concat(chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE), "."));
115
+ return [2 /*return*/, true];
116
+ case 8:
117
+ error_2 = _a.sent();
118
+ Sentry.setTag('expo-env-local', 'update-error');
119
+ clack.log.error("Unable to update ".concat(chalk_1.default.cyan(EXPO_ENV_LOCAL_FILE), "."));
120
+ return [2 /*return*/, false];
121
+ case 9: return [2 /*return*/];
122
+ }
123
+ });
124
+ });
125
+ }
126
+ exports.addExpoEnvLocal = addExpoEnvLocal;
127
+ //# sourceMappingURL=expo-env-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expo-env-file.js","sourceRoot":"","sources":["../../../src/react-native/expo-env-file.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAC1B,0CAAoB;AACpB,mDAAuC;AAEvC,6BAAuC;AAEvC,IAAM,mBAAmB,GAAG,YAAY,CAAC;AAEzC,SAAsB,eAAe,CACnC,OAAgC;;;;;;oBAE1B,UAAU,GAAG,iDAA0C,OAAO,CAAC,SAAS,OAAI,CAAC;oBAErE,qBAAM,IAAA,oBAAc,EAAC,mBAAmB,CAAC,EAAA;;oBAAjD,KAAK,GAAG,SAAyC;oBACvD,IAA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kBAAW,eAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,MAAG,CAAC,CAAC;oBACjE,sBAAO,IAAI,EAAC;;;oBAEZ,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;oBAChD,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,2BAAoB,eAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,MAAG,CAAC,CAAC;oBACxE,sBAAO,KAAK,EAAC;;;;;CAEhB;AA5CD,0CA4CC","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport fs from 'fs';\nimport * as Sentry from '@sentry/node';\nimport { RNCliSetupConfigContent } from './react-native-wizard';\nimport { addToGitignore } from './git';\n\nconst EXPO_ENV_LOCAL_FILE = '.env.local';\n\nexport async function addExpoEnvLocal(\n options: RNCliSetupConfigContent,\n): Promise<boolean> {\n const newContent = `#DO NOT COMMIT THIS\\nSENTRY_AUTH_TOKEN=${options.authToken}\\n`;\n\n const added = await addToGitignore(EXPO_ENV_LOCAL_FILE);\n if (added) {\n clack.log.success(\n `Added ${chalk.cyan(EXPO_ENV_LOCAL_FILE)} to .gitignore.`,\n );\n } else {\n clack.log.error(\n `Could not add ${chalk.cyan(\n EXPO_ENV_LOCAL_FILE,\n )} to .gitignore, please add it to not commit your auth key.`,\n );\n }\n\n if (!fs.existsSync(EXPO_ENV_LOCAL_FILE)) {\n try {\n await fs.promises.writeFile(EXPO_ENV_LOCAL_FILE, newContent);\n Sentry.setTag('expo-env-local', 'written');\n clack.log.success(`Written ${chalk.cyan(EXPO_ENV_LOCAL_FILE)}.`);\n return true;\n } catch (error) {\n Sentry.setTag('expo-env-local', 'write-error');\n clack.log.error(`Unable to write ${chalk.cyan(EXPO_ENV_LOCAL_FILE)}.`);\n return false;\n }\n }\n\n Sentry.setTag('expo-env-local', 'exists');\n clack.log.info(`Updating existing ${chalk.cyan(EXPO_ENV_LOCAL_FILE)}.`);\n\n try {\n await fs.promises.appendFile(EXPO_ENV_LOCAL_FILE, newContent);\n Sentry.setTag('expo-env-local', 'updated');\n clack.log.success(`Updated ${chalk.cyan(EXPO_ENV_LOCAL_FILE)}.`);\n return true;\n } catch (error) {\n Sentry.setTag('expo-env-local', 'update-error');\n clack.log.error(`Unable to update ${chalk.cyan(EXPO_ENV_LOCAL_FILE)}.`);\n return false;\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import { ProxifiedModule } from 'magicast';
2
+ import * as recast from 'recast';
3
+ import x = recast.types;
4
+ import t = x.namedTypes;
5
+ export declare function addSentryToExpoMetroConfig(): Promise<void>;
6
+ export declare function patchMetroInMemory(mod: ProxifiedModule): boolean;
7
+ export declare function addSentryExpoConfigRequire(program: t.Program): void;
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.addSentryExpoConfigRequire = exports.patchMetroInMemory = exports.addSentryToExpoMetroConfig = void 0;
66
+ var fs = __importStar(require("fs"));
67
+ // @ts-ignore - clack is ESM and TS complains about that. It works though
68
+ var clack = __importStar(require("@clack/prompts"));
69
+ var chalk_1 = __importDefault(require("chalk"));
70
+ var Sentry = __importStar(require("@sentry/node"));
71
+ var ast_utils_1 = require("../utils/ast-utils");
72
+ var clack_utils_1 = require("../utils/clack-utils");
73
+ var metro_1 = require("./metro");
74
+ var recast = __importStar(require("recast"));
75
+ var b = recast.types.builders;
76
+ function addSentryToExpoMetroConfig() {
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ var success, mod, didPatch, saved;
79
+ return __generator(this, function (_a) {
80
+ switch (_a.label) {
81
+ case 0:
82
+ if (!!fs.existsSync(metro_1.metroConfigPath)) return [3 /*break*/, 4];
83
+ return [4 /*yield*/, createSentryExpoMetroConfig()];
84
+ case 1:
85
+ success = _a.sent();
86
+ if (!!success) return [3 /*break*/, 3];
87
+ Sentry.setTag('expo-metro-config', 'create-new-error');
88
+ return [4 /*yield*/, showInstructions()];
89
+ case 2: return [2 /*return*/, _a.sent()];
90
+ case 3:
91
+ Sentry.setTag('expo-metro-config', 'created-new');
92
+ return [2 /*return*/, undefined];
93
+ case 4: return [4 /*yield*/, (0, metro_1.parseMetroConfig)()];
94
+ case 5:
95
+ mod = _a.sent();
96
+ didPatch = false;
97
+ try {
98
+ didPatch = patchMetroInMemory(mod);
99
+ }
100
+ catch (e) {
101
+ // noop
102
+ }
103
+ if (!!didPatch) return [3 /*break*/, 7];
104
+ Sentry.setTag('expo-metro-config', 'patch-error');
105
+ clack.log.error("Could not patch ".concat(chalk_1.default.cyan(metro_1.metroConfigPath), " with Sentry configuration."));
106
+ return [4 /*yield*/, showInstructions()];
107
+ case 6: return [2 /*return*/, _a.sent()];
108
+ case 7: return [4 /*yield*/, (0, metro_1.writeMetroConfig)(mod)];
109
+ case 8:
110
+ saved = _a.sent();
111
+ if (!saved) return [3 /*break*/, 9];
112
+ Sentry.setTag('expo-metro-config', 'patch-saved');
113
+ clack.log.success(chalk_1.default.green("".concat(chalk_1.default.cyan(metro_1.metroConfigPath), " changes saved.")));
114
+ return [3 /*break*/, 11];
115
+ case 9:
116
+ Sentry.setTag('expo-metro-config', 'patch-save-error');
117
+ clack.log.warn("Could not save changes to ".concat(chalk_1.default.cyan(metro_1.metroConfigPath), ", please follow the manual steps."));
118
+ return [4 /*yield*/, showInstructions()];
119
+ case 10: return [2 /*return*/, _a.sent()];
120
+ case 11: return [2 /*return*/];
121
+ }
122
+ });
123
+ });
124
+ }
125
+ exports.addSentryToExpoMetroConfig = addSentryToExpoMetroConfig;
126
+ function patchMetroInMemory(mod) {
127
+ var ast = mod.$ast;
128
+ if ((0, ast_utils_1.hasSentryContent)(ast)) {
129
+ clack.log.warn("The ".concat(chalk_1.default.cyan(metro_1.metroConfigPath), " file already has Sentry configuration."));
130
+ return false;
131
+ }
132
+ var didReplaceDefaultConfigCall = false;
133
+ recast.visit(ast, {
134
+ visitVariableDeclaration: function (path) {
135
+ var node = path.node;
136
+ if (
137
+ // path is require("expo/metro-config")
138
+ // and only getDefaultConfig is being destructured
139
+ // then remove the entire declaration
140
+ node.declarations.length > 0 &&
141
+ node.declarations[0].type === 'VariableDeclarator' &&
142
+ node.declarations[0].init &&
143
+ node.declarations[0].init.type === 'CallExpression' &&
144
+ node.declarations[0].init.callee &&
145
+ node.declarations[0].init.callee.type === 'Identifier' &&
146
+ node.declarations[0].init.callee.name === 'require' &&
147
+ node.declarations[0].init.arguments[0].type === 'StringLiteral' &&
148
+ node.declarations[0].init.arguments[0].value === 'expo/metro-config' &&
149
+ node.declarations[0].id.type === 'ObjectPattern' &&
150
+ node.declarations[0].id.properties.length === 1 &&
151
+ node.declarations[0].id.properties[0].type === 'ObjectProperty' &&
152
+ node.declarations[0].id.properties[0].key.type === 'Identifier' &&
153
+ node.declarations[0].id.properties[0].key.name === 'getDefaultConfig') {
154
+ path.prune();
155
+ return false;
156
+ }
157
+ this.traverse(path);
158
+ },
159
+ visitCallExpression: function (path) {
160
+ var node = path.node;
161
+ if (
162
+ // path is getDefaultConfig
163
+ // then rename it to getSentryExpoConfig
164
+ node.callee.type === 'Identifier' &&
165
+ node.callee.name === 'getDefaultConfig') {
166
+ node.callee.name = 'getSentryExpoConfig';
167
+ didReplaceDefaultConfigCall = true;
168
+ return false;
169
+ }
170
+ this.traverse(path);
171
+ },
172
+ });
173
+ if (!didReplaceDefaultConfigCall) {
174
+ clack.log.warn("Could not find `getDefaultConfig` in ".concat(chalk_1.default.cyan(metro_1.metroConfigPath), "."));
175
+ return false;
176
+ }
177
+ addSentryExpoConfigRequire(ast);
178
+ return true;
179
+ }
180
+ exports.patchMetroInMemory = patchMetroInMemory;
181
+ function addSentryExpoConfigRequire(program) {
182
+ var lastRequireIndex = (0, ast_utils_1.getLastRequireIndex)(program);
183
+ var sentryExpoConfigRequire = createSentryExpoConfigRequire();
184
+ program.body.splice(lastRequireIndex + 1, 0, sentryExpoConfigRequire);
185
+ }
186
+ exports.addSentryExpoConfigRequire = addSentryExpoConfigRequire;
187
+ /**
188
+ * Creates const { getSentryExpoConfig } = require("@sentry/react-native/metro");
189
+ */
190
+ function createSentryExpoConfigRequire() {
191
+ return b.variableDeclaration('const', [
192
+ b.variableDeclarator(b.objectPattern([
193
+ b.objectProperty.from({
194
+ key: b.identifier('getSentryExpoConfig'),
195
+ value: b.identifier('getSentryExpoConfig'),
196
+ shorthand: true,
197
+ }),
198
+ ]), b.callExpression(b.identifier('require'), [
199
+ b.literal('@sentry/react-native/metro'),
200
+ ])),
201
+ ]);
202
+ }
203
+ function createSentryExpoMetroConfig() {
204
+ return __awaiter(this, void 0, void 0, function () {
205
+ var snippet, e_1;
206
+ return __generator(this, function (_a) {
207
+ switch (_a.label) {
208
+ case 0:
209
+ snippet = "const { getSentryExpoConfig } = require(\"@sentry/react-native/metro\");\n\nconst config = getSentryExpoConfig(__dirname);\n\nmodule.exports = config;\n";
210
+ _a.label = 1;
211
+ case 1:
212
+ _a.trys.push([1, 3, , 4]);
213
+ return [4 /*yield*/, fs.promises.writeFile(metro_1.metroConfigPath, snippet)];
214
+ case 2:
215
+ _a.sent();
216
+ return [3 /*break*/, 4];
217
+ case 3:
218
+ e_1 = _a.sent();
219
+ clack.log.error("Could not create ".concat(chalk_1.default.cyan(metro_1.metroConfigPath), " with Sentry configuration."));
220
+ return [2 /*return*/, false];
221
+ case 4:
222
+ clack.log.success("Created ".concat(chalk_1.default.cyan(metro_1.metroConfigPath), " with Sentry configuration."));
223
+ return [2 /*return*/, true];
224
+ }
225
+ });
226
+ });
227
+ }
228
+ function showInstructions() {
229
+ return (0, clack_utils_1.showCopyPasteInstructions)(metro_1.metroConfigPath, getMetroWithSentryExpoConfigSnippet(true));
230
+ }
231
+ function getMetroWithSentryExpoConfigSnippet(colors) {
232
+ return (0, clack_utils_1.makeCodeSnippet)(colors, function (unchanged, plus, minus) {
233
+ return unchanged("".concat(minus("// const { getDefaultConfig } = require(\"expo/metro-config\");"), "\n").concat(plus("const { getSentryExpoConfig } = require(\"@sentry/react-native/metro\");"), "\n\n").concat(minus("// const config = getDefaultConfig(__dirname);"), "\n").concat(plus("const config = getSentryExpoConfig(__dirname);"), "\n\nmodule.exports = config;"));
234
+ });
235
+ }
236
+ //# sourceMappingURL=expo-metro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expo-metro.js","sourceRoot":"","sources":["../../../src/react-native/expo-metro.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AAC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ACF,CAAC,CAAC;AACL,CAAC;AAED,SAAe,2BAA2B;;;;;;oBAClC,OAAO,GAAG,0JAKjB,CAAC;;;;oBAEE,qBAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,uBAAe,EAAE,OAAO,CAAC,EAAA;;oBAArD,SAAqD,CAAC;;;;oBAEtD,KAAK,CAAC,GAAG,CAAC,KAAK,CACb,2BAAoB,eAAK,CAAC,IAAI,CAC5B,uBAAe,CAChB,gCAA6B,CAC/B,CAAC;oBACF,sBAAO,KAAK,EAAC;;oBAEf,KAAK,CAAC,GAAG,CAAC,OAAO,CACf,kBAAW,eAAK,CAAC,IAAI,CAAC,uBAAe,CAAC,gCAA6B,CACpE,CAAC;oBACF,sBAAO,IAAI,EAAC;;;;CACb;AAED,SAAS,gBAAgB;IACvB,OAAO,IAAA,uCAAyB,EAC9B,uBAAe,EACf,mCAAmC,CAAC,IAAI,CAAC,CAC1C,CAAC;AACJ,CAAC;AAED,SAAS,mCAAmC,CAAC,MAAe;IAC1D,OAAO,IAAA,6BAAe,EAAC,MAAM,EAAE,UAAC,SAAS,EAAE,IAAI,EAAE,KAAK;QACpD,OAAA,SAAS,CAAC,UAAG,KAAK,CAChB,iEAA+D,CAChE,eACH,IAAI,CACJ,0EAAwE,CACzE,iBAEC,KAAK,CAAC,gDAAgD,CAAC,eACvD,IAAI,CAAC,gDAAgD,CAAC,iCAE/B,CAAC;IAVtB,CAUsB,CACvB,CAAC;AACJ,CAAC","sourcesContent":["import * as fs from 'fs';\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { ProxifiedModule } from 'magicast';\nimport chalk from 'chalk';\nimport * as Sentry from '@sentry/node';\n\nimport { getLastRequireIndex, hasSentryContent } from '../utils/ast-utils';\nimport {\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../utils/clack-utils';\n\nimport { metroConfigPath, parseMetroConfig, writeMetroConfig } from './metro';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\n\nconst b = recast.types.builders;\n\nexport async function addSentryToExpoMetroConfig() {\n if (!fs.existsSync(metroConfigPath)) {\n const success = await createSentryExpoMetroConfig();\n if (!success) {\n Sentry.setTag('expo-metro-config', 'create-new-error');\n return await showInstructions();\n }\n Sentry.setTag('expo-metro-config', 'created-new');\n return undefined;\n }\n\n const mod = await parseMetroConfig();\n\n let didPatch = false;\n try {\n didPatch = patchMetroInMemory(mod);\n } catch (e) {\n // noop\n }\n if (!didPatch) {\n Sentry.setTag('expo-metro-config', 'patch-error');\n clack.log.error(\n `Could not patch ${chalk.cyan(\n metroConfigPath,\n )} with Sentry configuration.`,\n );\n return await showInstructions();\n }\n\n const saved = await writeMetroConfig(mod);\n if (saved) {\n Sentry.setTag('expo-metro-config', 'patch-saved');\n clack.log.success(\n chalk.green(`${chalk.cyan(metroConfigPath)} changes saved.`),\n );\n } else {\n Sentry.setTag('expo-metro-config', 'patch-save-error');\n clack.log.warn(\n `Could not save changes to ${chalk.cyan(\n metroConfigPath,\n )}, please follow the manual steps.`,\n );\n return await showInstructions();\n }\n}\n\nexport function patchMetroInMemory(mod: ProxifiedModule): boolean {\n const ast = mod.$ast as t.Program;\n\n if (hasSentryContent(ast)) {\n clack.log.warn(\n `The ${chalk.cyan(\n metroConfigPath,\n )} file already has Sentry configuration.`,\n );\n return false;\n }\n\n let didReplaceDefaultConfigCall = false;\n\n recast.visit(ast, {\n visitVariableDeclaration(path) {\n const { node } = path;\n\n if (\n // path is require(\"expo/metro-config\")\n // and only getDefaultConfig is being destructured\n // then remove the entire declaration\n node.declarations.length > 0 &&\n node.declarations[0].type === 'VariableDeclarator' &&\n node.declarations[0].init &&\n node.declarations[0].init.type === 'CallExpression' &&\n node.declarations[0].init.callee &&\n node.declarations[0].init.callee.type === 'Identifier' &&\n node.declarations[0].init.callee.name === 'require' &&\n node.declarations[0].init.arguments[0].type === 'StringLiteral' &&\n node.declarations[0].init.arguments[0].value === 'expo/metro-config' &&\n node.declarations[0].id.type === 'ObjectPattern' &&\n node.declarations[0].id.properties.length === 1 &&\n node.declarations[0].id.properties[0].type === 'ObjectProperty' &&\n node.declarations[0].id.properties[0].key.type === 'Identifier' &&\n node.declarations[0].id.properties[0].key.name === 'getDefaultConfig'\n ) {\n path.prune();\n return false;\n }\n\n this.traverse(path);\n },\n\n visitCallExpression(path) {\n const { node } = path;\n if (\n // path is getDefaultConfig\n // then rename it to getSentryExpoConfig\n node.callee.type === 'Identifier' &&\n node.callee.name === 'getDefaultConfig'\n ) {\n node.callee.name = 'getSentryExpoConfig';\n didReplaceDefaultConfigCall = true;\n return false;\n }\n\n this.traverse(path);\n },\n });\n\n if (!didReplaceDefaultConfigCall) {\n clack.log.warn(\n `Could not find \\`getDefaultConfig\\` in ${chalk.cyan(metroConfigPath)}.`,\n );\n return false;\n }\n\n addSentryExpoConfigRequire(ast);\n\n return true;\n}\n\nexport function addSentryExpoConfigRequire(program: t.Program) {\n const lastRequireIndex = getLastRequireIndex(program);\n const sentryExpoConfigRequire = createSentryExpoConfigRequire();\n program.body.splice(lastRequireIndex + 1, 0, sentryExpoConfigRequire);\n}\n\n/**\n * Creates const { getSentryExpoConfig } = require(\"@sentry/react-native/metro\");\n */\nfunction createSentryExpoConfigRequire() {\n return b.variableDeclaration('const', [\n b.variableDeclarator(\n b.objectPattern([\n b.objectProperty.from({\n key: b.identifier('getSentryExpoConfig'),\n value: b.identifier('getSentryExpoConfig'),\n shorthand: true,\n }),\n ]),\n b.callExpression(b.identifier('require'), [\n b.literal('@sentry/react-native/metro'),\n ]),\n ),\n ]);\n}\n\nasync function createSentryExpoMetroConfig(): Promise<boolean> {\n const snippet = `const { getSentryExpoConfig } = require(\"@sentry/react-native/metro\");\n\nconst config = getSentryExpoConfig(__dirname);\n\nmodule.exports = config;\n`;\n try {\n await fs.promises.writeFile(metroConfigPath, snippet);\n } catch (e) {\n clack.log.error(\n `Could not create ${chalk.cyan(\n metroConfigPath,\n )} with Sentry configuration.`,\n );\n return false;\n }\n clack.log.success(\n `Created ${chalk.cyan(metroConfigPath)} with Sentry configuration.`,\n );\n return true;\n}\n\nfunction showInstructions() {\n return showCopyPasteInstructions(\n metroConfigPath,\n getMetroWithSentryExpoConfigSnippet(true),\n );\n}\n\nfunction getMetroWithSentryExpoConfigSnippet(colors: boolean): string {\n return makeCodeSnippet(colors, (unchanged, plus, minus) =>\n unchanged(`${minus(\n `// const { getDefaultConfig } = require(\"expo/metro-config\");`,\n )}\n${plus(\n `const { getSentryExpoConfig } = require(\"@sentry/react-native/metro\");`,\n)}\n\n${minus(`// const config = getDefaultConfig(__dirname);`)}\n${plus(`const config = getSentryExpoConfig(__dirname);`)}\n\nmodule.exports = config;`),\n );\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { RNCliSetupConfigContent } from './react-native-wizard';
2
+ export declare const SENTRY_EXPO_PLUGIN_NAME = "@sentry/react-native/expo";
3
+ export declare const DEPRECATED_SENTRY_EXPO_PLUGIN_NAME = "sentry-expo";
4
+ export declare const SENTRY_PLUGIN_FUNCTION_NAME = "withSentry";
5
+ export interface AppConfigJson {
6
+ expo?: {
7
+ plugins?: Array<[string, undefined | Record<string, unknown>]>;
8
+ };
9
+ }
10
+ export declare function printSentryExpoMigrationOutro(): void;
11
+ /**
12
+ * Finds app.json in the project root and add Sentry Expo `withSentry` plugin.
13
+ */
14
+ export declare function patchExpoAppConfig(options: RNCliSetupConfigContent): Promise<void>;
15
+ export declare function addWithSentryToAppConfigJson(appConfigContent: string, options: RNCliSetupConfigContent): string | null;
16
+ export declare function getSentryAppConfigJsonCodeSnippet({ url, project, org, }: Omit<RNCliSetupConfigContent, 'authToken'>): string;