@sentry/wizard 3.16.5 → 3.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/package.json +2 -2
- package/dist/src/apple/cocoapod.js +2 -0
- package/dist/src/apple/cocoapod.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +76 -21
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.d.ts +2 -0
- package/dist/src/nextjs/templates.js +15 -2
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/react-native/metro.d.ts +13 -0
- package/dist/src/react-native/metro.js +398 -0
- package/dist/src/react-native/metro.js.map +1 -0
- package/dist/src/react-native/react-native-wizard.d.ts +2 -0
- package/dist/src/react-native/react-native-wizard.js +139 -38
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/react-native/uninstall.js +4 -0
- package/dist/src/react-native/uninstall.js.map +1 -1
- package/dist/src/react-native/xcode.d.ts +7 -3
- package/dist/src/react-native/xcode.js +43 -11
- package/dist/src/react-native/xcode.js.map +1 -1
- package/dist/src/remix/remix-wizard.js +80 -37
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/remix/sdk-setup.d.ts +1 -0
- package/dist/src/remix/sdk-setup.js +21 -1
- package/dist/src/remix/sdk-setup.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +14 -0
- package/dist/src/utils/ast-utils.js +49 -1
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/test/react-native/metro.test.d.ts +1 -0
- package/dist/test/react-native/metro.test.js +125 -0
- package/dist/test/react-native/metro.test.js.map +1 -0
- package/dist/test/react-native/xcode.test.js +40 -2
- package/dist/test/react-native/xcode.test.js.map +1 -1
- package/package.json +2 -2
- package/src/apple/cocoapod.ts +2 -0
- package/src/nextjs/nextjs-wizard.ts +99 -19
- package/src/nextjs/templates.ts +77 -0
- package/src/react-native/metro.ts +409 -0
- package/src/react-native/react-native-wizard.ts +103 -7
- package/src/react-native/uninstall.ts +3 -0
- package/src/react-native/xcode.ts +70 -12
- package/src/remix/remix-wizard.ts +51 -15
- package/src/remix/sdk-setup.ts +31 -0
- package/src/utils/ast-utils.ts +52 -0
- package/test/react-native/metro.test.ts +283 -0
- package/test/react-native/xcode.test.ts +76 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/nextjs/templates.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA0B;AAE1B,SAAgB,qCAAqC,CACnD,OAAe,EACf,WAAmB,EACnB,UAAmB,EACnB,GAAW;IAEX,OAAO,kNAMG,OAAO,iCACH,WAAW,gBAAK,UAAU,CAAC,CAAC,CAAC,uBAAe,GAAG,OAAG,CAAC,CAAC,CAAC,EAAE,UACnE,CAAC;AACL,CAAC;AAfD,sFAeC;AAED,SAAgB,mCAAmC;IACjD,OAAO,usBAkBL,CAAC;AACL,CAAC;AApBD,kFAoBC;AAED,SAAgB,0BAA0B,CACxC,kCAA0C,EAC1C,0BAAkC;IAElC,OAAO,gMAOL,kCAAkC,kBAClC,0BAA0B,WAE7B,CAAC;AACF,CAAC;AAfD,gEAeC;AAED,SAAgB,0BAA0B,CACxC,kCAA0C,EAC1C,0BAAkC;IAElC,OAAO,mLAQL,kCAAkC,kBAClC,0BAA0B,WAE7B,CAAC;AACF,CAAC;AAhBD,gEAgBC;AAED,SAAgB,kCAAkC,CAChD,kCAA0C,EAC1C,0BAAkC;IAElC,OAAO,iJAOL,kCAAkC,kBAClC,0BAA0B,WAE7B,CAAC;AACF,CAAC;AAfD,gFAeC;AAED,SAAgB,uBAAuB,CACrC,GAAW,EACX,MAAoC;IAEpC,IAAI,MAAM,CAAC;IACX,IAAI,MAAM,KAAK,QAAQ,EAAE;QACvB,MAAM,GAAG,oNAEiD,CAAC;KAC5D;SAAM,IAAI,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,GAA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AAED,SAAgB,sCAAsC,CAAC,IAAa;IAClE,OAAO,qDAEL,IAAI,CAAC,CAAC,CAAC,gDAAgD,CAAC,CAAC,CAAC,EAAE,iBAG9D,eAAK,CAAC,GAAG,CACT,yEAAyE,CAC1E,4EAEG,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,+EAIlC,CAAC;AACF,CAAC;AAfD,wFAeC","sourcesContent":["import chalk from 'chalk';\n\nexport function getNextjsWebpackPluginOptionsTemplate(\n orgSlug: string,\n projectSlug: string,\n selfHosted: boolean,\n url: string,\n): string {\n return `{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n // Suppresses source map uploading logs during build\n silent: true,\n org: \"${orgSlug}\",\n project: \"${projectSlug}\",${selfHosted ? `\\n url: \"${url}\"` : ''}\n }`;\n}\n\nexport function getNextjsSentryBuildOptionsTemplate(): string {\n return `{\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 // Transpiles SDK to be compatible with IE11 (increases bundle size)\n transpileClientSDK: true,\n\n // Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)\n 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}\n\nexport function getNextjsConfigCjsTemplate(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: 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 ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigCjsAppendix(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: 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 ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigEsmCopyPasteSnippet(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: string,\n): string {\n return `\n\n// next.config.mjs\nimport { withSentryConfig } from \"@sentry/nextjs\";\n\nexport default withSentryConfig(\n yourNextConfig,\n ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\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 new Sentry.Replay({\n // Additional Replay configuration goes in here, for example:\n maskAllText: true,\n blockAllMedia: true,\n }),\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}\n});\n`;\n}\n\nexport function getSentryExamplePageContents(options: {\n selfHosted: boolean;\n url: string;\n orgSlug: string;\n projectId: string;\n useClient: boolean;\n}): string {\n const issuesPageLink = options.selfHosted\n ? `${options.url}organizations/${options.orgSlug}/issues/?project=${options.projectId}`\n : `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;\n\n return `${\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 const transaction = Sentry.startTransaction({\n name: \"Example Frontend Transaction\",\n });\n\n Sentry.configureScope((scope) => {\n scope.setSpan(transaction);\n });\n\n try {\n const res = await fetch(\"/api/sentry-example-api\");\n if (!res.ok) {\n throw new Error(\"Sentry Example Frontend Error\");\n }\n } finally {\n transaction.finish();\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"]}
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/nextjs/templates.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA0B;AAE1B,SAAgB,qCAAqC,CACnD,OAAe,EACf,WAAmB,EACnB,UAAmB,EACnB,GAAW;IAEX,OAAO,kNAMG,OAAO,iCACH,WAAW,gBAAK,UAAU,CAAC,CAAC,CAAC,uBAAe,GAAG,OAAG,CAAC,CAAC,CAAC,EAAE,UACnE,CAAC;AACL,CAAC;AAfD,sFAeC;AAED,SAAgB,mCAAmC;IACjD,OAAO,w7BAwBL,CAAC;AACL,CAAC;AA1BD,kFA0BC;AAED,SAAgB,0BAA0B,CACxC,kCAA0C,EAC1C,0BAAkC;IAElC,OAAO,gMAOL,kCAAkC,kBAClC,0BAA0B,WAE7B,CAAC;AACF,CAAC;AAfD,gEAeC;AAED,SAAgB,0BAA0B,CACxC,kCAA0C,EAC1C,0BAAkC;IAElC,OAAO,mLAQL,kCAAkC,kBAClC,0BAA0B,WAE7B,CAAC;AACF,CAAC;AAhBD,gEAgBC;AAED,SAAgB,kCAAkC,CAChD,kCAA0C,EAC1C,0BAAkC;IAElC,OAAO,iJAOL,kCAAkC,kBAClC,0BAA0B,WAE7B,CAAC;AACF,CAAC;AAfD,gFAeC;AAED,SAAgB,uBAAuB,CACrC,GAAW,EACX,MAAoC;IAEpC,IAAI,MAAM,CAAC;IACX,IAAI,MAAM,KAAK,QAAQ,EAAE;QACvB,MAAM,GAAG,oNAEiD,CAAC;KAC5D;SAAM,IAAI,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,GAAG,6NAEiD,CAAC;KAC5D;SAAM,IAAI,MAAM,KAAK,MAAM,EAAE;QAC5B,M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,CAAC,gDAAgD,CAAC,CAAC,CAAC,EAAE,iBAG9D,eAAK,CAAC,GAAG,CACT,yEAAyE,CAC1E,4EAEG,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,+EAIlC,CAAC;AACF,CAAC;AAfD,wFAeC;AAED,SAAgB,+BAA+B;IAC7C,OAAO,yWAmBR,CAAC;AACF,CAAC;AArBD,0EAqBC;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';\n\nexport function getNextjsWebpackPluginOptionsTemplate(\n orgSlug: string,\n projectSlug: string,\n selfHosted: boolean,\n url: string,\n): string {\n return `{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n // Suppresses source map uploading logs during build\n silent: true,\n org: \"${orgSlug}\",\n project: \"${projectSlug}\",${selfHosted ? `\\n url: \"${url}\"` : ''}\n }`;\n}\n\nexport function getNextjsSentryBuildOptionsTemplate(): string {\n return `{\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 // Transpiles SDK to be compatible with IE11 (increases bundle size)\n transpileClientSDK: true,\n\n // Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)\n 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.\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 sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: 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 ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigCjsAppendix(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: 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 ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigEsmCopyPasteSnippet(\n sentryWebpackPluginOptionsTemplate: string,\n sentryBuildOptionsTemplate: string,\n): string {\n return `\n\n// next.config.mjs\nimport { withSentryConfig } from \"@sentry/nextjs\";\n\nexport default withSentryConfig(\n yourNextConfig,\n ${sentryWebpackPluginOptionsTemplate},\n ${sentryBuildOptionsTemplate}\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 new Sentry.Replay({\n // Additional Replay configuration goes in here, for example:\n maskAllText: true,\n blockAllMedia: true,\n }),\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}\n});\n`;\n}\n\nexport function getSentryExamplePageContents(options: {\n selfHosted: boolean;\n url: string;\n orgSlug: string;\n projectId: string;\n useClient: boolean;\n}): string {\n const issuesPageLink = options.selfHosted\n ? `${options.url}organizations/${options.orgSlug}/issues/?project=${options.projectId}`\n : `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;\n\n return `${\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 const transaction = Sentry.startTransaction({\n name: \"Example Frontend Transaction\",\n });\n\n Sentry.configureScope((scope) => {\n scope.setSpan(transaction);\n });\n\n try {\n const res = await fetch(\"/api/sentry-example-api\");\n if (!res.ok) {\n throw new Error(\"Sentry Example Frontend Error\");\n }\n } finally {\n transaction.finish();\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 getSentryDefaultGlobalErrorPage() {\n return `\"use client\";\n\nimport * as Sentry from \"@sentry/nextjs\";\nimport Error 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 <Error />\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,13 @@
|
|
|
1
|
+
import * as recast from 'recast';
|
|
2
|
+
import x = recast.types;
|
|
3
|
+
import t = x.namedTypes;
|
|
4
|
+
export declare function patchMetroConfig(): Promise<void>;
|
|
5
|
+
export declare function unPatchMetroConfig(): Promise<void>;
|
|
6
|
+
export declare function removeSentrySerializerFromMetroConfig(program: t.Program): boolean;
|
|
7
|
+
export declare function removeSentryRequire(program: t.Program): boolean;
|
|
8
|
+
export declare function addSentrySerializerToMetroConfig(configObj: t.ObjectExpression): boolean;
|
|
9
|
+
export declare function addSentrySerializerRequireToMetroConfig(program: t.Program): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Returns value from `module.exports = value` or `const config = value`
|
|
12
|
+
*/
|
|
13
|
+
export declare function getMetroConfigObject(program: t.Program): t.ObjectExpression | undefined;
|
|
@@ -0,0 +1,398 @@
|
|
|
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.getMetroConfigObject = exports.addSentrySerializerRequireToMetroConfig = exports.addSentrySerializerToMetroConfig = exports.removeSentryRequire = exports.removeSentrySerializerFromMetroConfig = exports.unPatchMetroConfig = exports.patchMetroConfig = void 0;
|
|
66
|
+
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
67
|
+
var clack = __importStar(require("@clack/prompts"));
|
|
68
|
+
// @ts-ignore - magicast is ESM and TS complains about that. It works though
|
|
69
|
+
var magicast_1 = require("magicast");
|
|
70
|
+
var fs = __importStar(require("fs"));
|
|
71
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
72
|
+
var ast_utils_1 = require("../utils/ast-utils");
|
|
73
|
+
var clack_utils_1 = require("../utils/clack-utils");
|
|
74
|
+
var recast = __importStar(require("recast"));
|
|
75
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
76
|
+
var b = recast.types.builders;
|
|
77
|
+
var metroConfigPath = 'metro.config.js';
|
|
78
|
+
function patchMetroConfig() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
+
var mod, showInstructions, shouldContinue, configObj, addedSentrySerializer, addedSentrySerializerImport, saved;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
83
|
+
case 0: return [4 /*yield*/, parseMetroConfig()];
|
|
84
|
+
case 1:
|
|
85
|
+
mod = _a.sent();
|
|
86
|
+
showInstructions = function () {
|
|
87
|
+
return (0, clack_utils_1.showCopyPasteInstructions)(metroConfigPath, getMetroConfigSnippet(true));
|
|
88
|
+
};
|
|
89
|
+
if (!(0, ast_utils_1.hasSentryContent)(mod.$ast)) return [3 /*break*/, 4];
|
|
90
|
+
return [4 /*yield*/, confirmPathMetroConfig()];
|
|
91
|
+
case 2:
|
|
92
|
+
shouldContinue = _a.sent();
|
|
93
|
+
if (!!shouldContinue) return [3 /*break*/, 4];
|
|
94
|
+
return [4 /*yield*/, showInstructions()];
|
|
95
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
96
|
+
case 4:
|
|
97
|
+
configObj = getMetroConfigObject(mod.$ast);
|
|
98
|
+
if (!configObj) {
|
|
99
|
+
clack.log.warn('Could not find Metro config object, please follow the manual steps.');
|
|
100
|
+
return [2 /*return*/, showInstructions()];
|
|
101
|
+
}
|
|
102
|
+
addedSentrySerializer = addSentrySerializerToMetroConfig(configObj);
|
|
103
|
+
if (!!addedSentrySerializer) return [3 /*break*/, 6];
|
|
104
|
+
clack.log.warn('Could not add Sentry serializer to Metro config, please follow the manual steps.');
|
|
105
|
+
return [4 /*yield*/, showInstructions()];
|
|
106
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
107
|
+
case 6:
|
|
108
|
+
addedSentrySerializerImport = addSentrySerializerRequireToMetroConfig(mod.$ast);
|
|
109
|
+
if (!!addedSentrySerializerImport) return [3 /*break*/, 8];
|
|
110
|
+
clack.log.warn('Could not add Sentry serializer import to Metro config, please follow the manual steps.');
|
|
111
|
+
return [4 /*yield*/, showInstructions()];
|
|
112
|
+
case 7: return [2 /*return*/, _a.sent()];
|
|
113
|
+
case 8:
|
|
114
|
+
clack.log.success("Added Sentry Metro plugin to ".concat(chalk_1.default.cyan(metroConfigPath), "."));
|
|
115
|
+
return [4 /*yield*/, writeMetroConfig(mod)];
|
|
116
|
+
case 9:
|
|
117
|
+
saved = _a.sent();
|
|
118
|
+
if (!saved) return [3 /*break*/, 10];
|
|
119
|
+
clack.log.success(chalk_1.default.green("".concat(chalk_1.default.cyan(metroConfigPath), " changes saved.")));
|
|
120
|
+
return [3 /*break*/, 12];
|
|
121
|
+
case 10:
|
|
122
|
+
clack.log.warn("Could not save changes to ".concat(chalk_1.default.cyan(metroConfigPath), ", please follow the manual steps."));
|
|
123
|
+
return [4 /*yield*/, showInstructions()];
|
|
124
|
+
case 11: return [2 /*return*/, _a.sent()];
|
|
125
|
+
case 12: return [2 /*return*/];
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
exports.patchMetroConfig = patchMetroConfig;
|
|
131
|
+
function unPatchMetroConfig() {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
+
var mod, removedAtLeastOneRequire, removedSerializerConfig, saved;
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
switch (_a.label) {
|
|
136
|
+
case 0: return [4 /*yield*/, parseMetroConfig()];
|
|
137
|
+
case 1:
|
|
138
|
+
mod = _a.sent();
|
|
139
|
+
removedAtLeastOneRequire = removeSentryRequire(mod.$ast);
|
|
140
|
+
removedSerializerConfig = removeSentrySerializerFromMetroConfig(mod.$ast);
|
|
141
|
+
if (!(removedAtLeastOneRequire || removedSerializerConfig)) return [3 /*break*/, 3];
|
|
142
|
+
return [4 /*yield*/, writeMetroConfig(mod)];
|
|
143
|
+
case 2:
|
|
144
|
+
saved = _a.sent();
|
|
145
|
+
if (saved) {
|
|
146
|
+
clack.log.success("Removed Sentry Metro plugin from ".concat(chalk_1.default.cyan(metroConfigPath), "."));
|
|
147
|
+
}
|
|
148
|
+
return [3 /*break*/, 4];
|
|
149
|
+
case 3:
|
|
150
|
+
clack.log.warn("No Sentry Metro plugin found in ".concat(chalk_1.default.cyan(metroConfigPath), "."));
|
|
151
|
+
_a.label = 4;
|
|
152
|
+
case 4: return [2 /*return*/];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
exports.unPatchMetroConfig = unPatchMetroConfig;
|
|
158
|
+
function removeSentrySerializerFromMetroConfig(program) {
|
|
159
|
+
var configObject = getMetroConfigObject(program);
|
|
160
|
+
if (!configObject) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
var serializerProp = getSerializerProp(configObject);
|
|
164
|
+
if ('invalid' === serializerProp || 'undefined' === serializerProp) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
var customSerializerProp = getCustomSerializerProp(serializerProp);
|
|
168
|
+
if ('invalid' === customSerializerProp ||
|
|
169
|
+
'undefined' === customSerializerProp) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
if (serializerProp.value.type === 'ObjectExpression' &&
|
|
173
|
+
customSerializerProp.value.type === 'CallExpression' &&
|
|
174
|
+
customSerializerProp.value.callee.type === 'Identifier' &&
|
|
175
|
+
customSerializerProp.value.callee.name === 'createSentryMetroSerializer') {
|
|
176
|
+
if (customSerializerProp.value.arguments.length === 0) {
|
|
177
|
+
// FROM serializer: { customSerializer: createSentryMetroSerializer() }
|
|
178
|
+
// TO serializer: {}
|
|
179
|
+
var removed_1 = false;
|
|
180
|
+
serializerProp.value.properties = serializerProp.value.properties.filter(function (p) {
|
|
181
|
+
if (p.type === 'ObjectProperty' &&
|
|
182
|
+
p.key.type === 'Identifier' &&
|
|
183
|
+
p.key.name === 'customSerializer') {
|
|
184
|
+
removed_1 = true;
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
});
|
|
189
|
+
if (removed_1) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
if (customSerializerProp.value.arguments[0].type !== 'SpreadElement') {
|
|
195
|
+
// FROM serializer: { customSerializer: createSentryMetroSerializer(wrapperSerializer) }
|
|
196
|
+
// TO serializer: { customSerializer: wrapperSerializer }
|
|
197
|
+
customSerializerProp.value = customSerializerProp.value.arguments[0];
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
exports.removeSentrySerializerFromMetroConfig = removeSentrySerializerFromMetroConfig;
|
|
205
|
+
function removeSentryRequire(program) {
|
|
206
|
+
return (0, ast_utils_1.removeRequire)(program, '@sentry');
|
|
207
|
+
}
|
|
208
|
+
exports.removeSentryRequire = removeSentryRequire;
|
|
209
|
+
function parseMetroConfig() {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
+
var metroConfigContent;
|
|
212
|
+
return __generator(this, function (_a) {
|
|
213
|
+
switch (_a.label) {
|
|
214
|
+
case 0: return [4 /*yield*/, fs.promises.readFile(metroConfigPath)];
|
|
215
|
+
case 1:
|
|
216
|
+
metroConfigContent = (_a.sent()).toString();
|
|
217
|
+
return [2 /*return*/, (0, magicast_1.parseModule)(metroConfigContent)];
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
function writeMetroConfig(mod) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
224
|
+
var e_1;
|
|
225
|
+
return __generator(this, function (_a) {
|
|
226
|
+
switch (_a.label) {
|
|
227
|
+
case 0:
|
|
228
|
+
_a.trys.push([0, 2, , 3]);
|
|
229
|
+
return [4 /*yield*/, (0, magicast_1.writeFile)(mod.$ast, metroConfigPath)];
|
|
230
|
+
case 1:
|
|
231
|
+
_a.sent();
|
|
232
|
+
return [3 /*break*/, 3];
|
|
233
|
+
case 2:
|
|
234
|
+
e_1 = _a.sent();
|
|
235
|
+
clack.log.error("Failed to write to ".concat(chalk_1.default.cyan(metroConfigPath), ": ").concat(JSON.stringify(e_1)));
|
|
236
|
+
return [2 /*return*/, false];
|
|
237
|
+
case 3: return [2 /*return*/, true];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
function addSentrySerializerToMetroConfig(configObj) {
|
|
243
|
+
var serializerProp = getSerializerProp(configObj);
|
|
244
|
+
if ('invalid' === serializerProp) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
// case 1: serializer property doesn't exist yet, so we can just add it
|
|
248
|
+
if ('undefined' === serializerProp) {
|
|
249
|
+
configObj.properties.push(b.objectProperty(b.identifier('serializer'), b.objectExpression([
|
|
250
|
+
b.objectProperty(b.identifier('customSerializer'), b.callExpression(b.identifier('createSentryMetroSerializer'), [])),
|
|
251
|
+
])));
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
var customSerializerProp = getCustomSerializerProp(serializerProp);
|
|
255
|
+
// case 2: serializer.customSerializer property doesn't exist yet, so we just add it
|
|
256
|
+
if ('undefined' === customSerializerProp &&
|
|
257
|
+
serializerProp.value.type === 'ObjectExpression') {
|
|
258
|
+
serializerProp.value.properties.push(b.objectProperty(b.identifier('customSerializer'), b.callExpression(b.identifier('createSentryMetroSerializer'), [])));
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
exports.addSentrySerializerToMetroConfig = addSentrySerializerToMetroConfig;
|
|
264
|
+
function getCustomSerializerProp(prop) {
|
|
265
|
+
var customSerializerProp = prop.value.type === 'ObjectExpression' &&
|
|
266
|
+
prop.value.properties.find(function (p) {
|
|
267
|
+
return p.key.type === 'Identifier' && p.key.name === 'customSerializer';
|
|
268
|
+
});
|
|
269
|
+
if (!customSerializerProp) {
|
|
270
|
+
return 'undefined';
|
|
271
|
+
}
|
|
272
|
+
if (customSerializerProp.type === 'ObjectProperty') {
|
|
273
|
+
return customSerializerProp;
|
|
274
|
+
}
|
|
275
|
+
return 'invalid';
|
|
276
|
+
}
|
|
277
|
+
function getSerializerProp(obj) {
|
|
278
|
+
var serializerProp = obj.properties.find(function (p) {
|
|
279
|
+
return p.key.type === 'Identifier' && p.key.name === 'serializer';
|
|
280
|
+
});
|
|
281
|
+
if (!serializerProp) {
|
|
282
|
+
return 'undefined';
|
|
283
|
+
}
|
|
284
|
+
if (serializerProp.type === 'ObjectProperty') {
|
|
285
|
+
return serializerProp;
|
|
286
|
+
}
|
|
287
|
+
return 'invalid';
|
|
288
|
+
}
|
|
289
|
+
function addSentrySerializerRequireToMetroConfig(program) {
|
|
290
|
+
var lastRequireIndex = (0, ast_utils_1.getLastRequireIndex)(program);
|
|
291
|
+
var sentrySerializerRequire = createSentrySerializerRequire();
|
|
292
|
+
var sentryImportIndex = lastRequireIndex + 1;
|
|
293
|
+
if (sentryImportIndex < program.body.length) {
|
|
294
|
+
// insert after last require
|
|
295
|
+
program.body.splice(lastRequireIndex + 1, 0, sentrySerializerRequire);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
// insert at the end
|
|
299
|
+
program.body.push(sentrySerializerRequire);
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
exports.addSentrySerializerRequireToMetroConfig = addSentrySerializerRequireToMetroConfig;
|
|
304
|
+
/**
|
|
305
|
+
* Creates const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');
|
|
306
|
+
*/
|
|
307
|
+
function createSentrySerializerRequire() {
|
|
308
|
+
return b.variableDeclaration('const', [
|
|
309
|
+
b.variableDeclarator(b.objectPattern([
|
|
310
|
+
b.objectProperty.from({
|
|
311
|
+
key: b.identifier('createSentryMetroSerializer'),
|
|
312
|
+
value: b.identifier('createSentryMetroSerializer'),
|
|
313
|
+
shorthand: true,
|
|
314
|
+
}),
|
|
315
|
+
]), b.callExpression(b.identifier('require'), [
|
|
316
|
+
b.literal('@sentry/react-native/dist/js/tools/sentryMetroSerializer'),
|
|
317
|
+
])),
|
|
318
|
+
]);
|
|
319
|
+
}
|
|
320
|
+
function confirmPathMetroConfig() {
|
|
321
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
322
|
+
var shouldContinue;
|
|
323
|
+
return __generator(this, function (_a) {
|
|
324
|
+
switch (_a.label) {
|
|
325
|
+
case 0: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
326
|
+
message: "Metro Config already contains Sentry-related code. Should the wizard modify it anyway?",
|
|
327
|
+
options: [
|
|
328
|
+
{
|
|
329
|
+
label: 'Yes, add the Sentry Metro plugin',
|
|
330
|
+
value: true,
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
label: 'No, show me instructions to manually add the plugin',
|
|
334
|
+
value: false,
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
initialValue: true,
|
|
338
|
+
}))];
|
|
339
|
+
case 1:
|
|
340
|
+
shouldContinue = _a.sent();
|
|
341
|
+
if (!shouldContinue) {
|
|
342
|
+
Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');
|
|
343
|
+
}
|
|
344
|
+
return [2 /*return*/, shouldContinue];
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Returns value from `module.exports = value` or `const config = value`
|
|
351
|
+
*/
|
|
352
|
+
function getMetroConfigObject(program) {
|
|
353
|
+
var _a;
|
|
354
|
+
// check config variable
|
|
355
|
+
var configVariable = program.body.find(function (s) {
|
|
356
|
+
if (s.type === 'VariableDeclaration' &&
|
|
357
|
+
s.declarations.length === 1 &&
|
|
358
|
+
s.declarations[0].type === 'VariableDeclarator' &&
|
|
359
|
+
s.declarations[0].id.type === 'Identifier' &&
|
|
360
|
+
s.declarations[0].id.name === 'config') {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
return false;
|
|
364
|
+
});
|
|
365
|
+
if ((configVariable === null || configVariable === void 0 ? void 0 : configVariable.declarations[0].type) === 'VariableDeclarator' &&
|
|
366
|
+
((_a = configVariable === null || configVariable === void 0 ? void 0 : configVariable.declarations[0].init) === null || _a === void 0 ? void 0 : _a.type) === 'ObjectExpression') {
|
|
367
|
+
Sentry.setTag('metro-config', 'config-variable');
|
|
368
|
+
return configVariable.declarations[0].init;
|
|
369
|
+
}
|
|
370
|
+
// check module.exports
|
|
371
|
+
var moduleExports = program.body.find(function (s) {
|
|
372
|
+
if (s.type === 'ExpressionStatement' &&
|
|
373
|
+
s.expression.type === 'AssignmentExpression' &&
|
|
374
|
+
s.expression.left.type === 'MemberExpression' &&
|
|
375
|
+
s.expression.left.object.type === 'Identifier' &&
|
|
376
|
+
s.expression.left.object.name === 'module' &&
|
|
377
|
+
s.expression.left.property.type === 'Identifier' &&
|
|
378
|
+
s.expression.left.property.name === 'exports') {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
return false;
|
|
382
|
+
});
|
|
383
|
+
if ((moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.expression).right.type ===
|
|
384
|
+
'ObjectExpression') {
|
|
385
|
+
Sentry.setTag('metro-config', 'module-exports');
|
|
386
|
+
return (moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.expression)
|
|
387
|
+
.right;
|
|
388
|
+
}
|
|
389
|
+
Sentry.setTag('metro-config', 'not-found');
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
exports.getMetroConfigObject = getMetroConfigObject;
|
|
393
|
+
function getMetroConfigSnippet(colors) {
|
|
394
|
+
return (0, clack_utils_1.makeCodeSnippet)(colors, function (unchanged, plus, _) {
|
|
395
|
+
return unchanged("const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\";\n".concat(plus("const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');"), "\n\nconst config = {\n ").concat(plus("serializer: {\n customSerializer: createSentryMetroSerializer(),\n },"), "\n};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);\n"));
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
//# sourceMappingURL=metro.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metro.js","sourceRoot":"","sources":["../../../src/react-native/metro.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,4EAA4E;AAC5E,qCAAmE;AACnE,qCAAyB;AACzB,mDAAuC;AAEvC,gDAI4B;AAC5B,oDAI8B;AAE9B,6CAAiC;AAGjC,gDAA0B;AAE1B,IAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC,IAAM,eAAe,GAAG,iBAAiB,CAAC;AAE1C,SAAsB,gBAAgB;;;;;wBACxB,qBAAM,gBAAgB,EAAE,EAAA;;oBAA9B,GAA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AAC;QAChD,OAAA,SAAS,CAAC,6FACZ,IAAI,CACJ,4GAA4G,CAC7G,qCAGG,IAAI,CAAC,2EAEJ,CAAC,iFAIL,CAAC;IAZE,CAYF,CACC,CAAC;AACJ,CAAC","sourcesContent":["// @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, parseModule, writeFile } from 'magicast';\nimport * as fs from 'fs';\nimport * as Sentry from '@sentry/node';\n\nimport {\n getLastRequireIndex,\n hasSentryContent,\n removeRequire,\n} from '../utils/ast-utils';\nimport {\n abortIfCancelled,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../utils/clack-utils';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\nimport chalk from 'chalk';\n\nconst b = recast.types.builders;\n\nconst metroConfigPath = 'metro.config.js';\n\nexport async function patchMetroConfig() {\n const mod = await parseMetroConfig();\n\n const showInstructions = () =>\n showCopyPasteInstructions(metroConfigPath, getMetroConfigSnippet(true));\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await confirmPathMetroConfig();\n if (!shouldContinue) {\n return await showInstructions();\n }\n }\n\n const configObj = getMetroConfigObject(mod.$ast as t.Program);\n if (!configObj) {\n clack.log.warn(\n 'Could not find Metro config object, please follow the manual steps.',\n );\n return showInstructions();\n }\n\n const addedSentrySerializer = addSentrySerializerToMetroConfig(configObj);\n if (!addedSentrySerializer) {\n clack.log.warn(\n 'Could not add Sentry serializer to Metro config, please follow the manual steps.',\n );\n return await showInstructions();\n }\n\n const addedSentrySerializerImport = addSentrySerializerRequireToMetroConfig(\n mod.$ast as t.Program,\n );\n if (!addedSentrySerializerImport) {\n clack.log.warn(\n 'Could not add Sentry serializer import to Metro config, please follow the manual steps.',\n );\n return await showInstructions();\n }\n\n clack.log.success(\n `Added Sentry Metro plugin to ${chalk.cyan(metroConfigPath)}.`,\n );\n\n const saved = await writeMetroConfig(mod);\n if (saved) {\n clack.log.success(\n chalk.green(`${chalk.cyan(metroConfigPath)} changes saved.`),\n );\n } else {\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 async function unPatchMetroConfig() {\n const mod = await parseMetroConfig();\n\n const removedAtLeastOneRequire = removeSentryRequire(mod.$ast as t.Program);\n const removedSerializerConfig = removeSentrySerializerFromMetroConfig(\n mod.$ast as t.Program,\n );\n\n if (removedAtLeastOneRequire || removedSerializerConfig) {\n const saved = await writeMetroConfig(mod);\n if (saved) {\n clack.log.success(\n `Removed Sentry Metro plugin from ${chalk.cyan(metroConfigPath)}.`,\n );\n }\n } else {\n clack.log.warn(\n `No Sentry Metro plugin found in ${chalk.cyan(metroConfigPath)}.`,\n );\n }\n}\n\nexport function removeSentrySerializerFromMetroConfig(\n program: t.Program,\n): boolean {\n const configObject = getMetroConfigObject(program);\n if (!configObject) {\n return false;\n }\n\n const serializerProp = getSerializerProp(configObject);\n if ('invalid' === serializerProp || 'undefined' === serializerProp) {\n return false;\n }\n\n const customSerializerProp = getCustomSerializerProp(serializerProp);\n if (\n 'invalid' === customSerializerProp ||\n 'undefined' === customSerializerProp\n ) {\n return false;\n }\n\n if (\n serializerProp.value.type === 'ObjectExpression' &&\n customSerializerProp.value.type === 'CallExpression' &&\n customSerializerProp.value.callee.type === 'Identifier' &&\n customSerializerProp.value.callee.name === 'createSentryMetroSerializer'\n ) {\n if (customSerializerProp.value.arguments.length === 0) {\n // FROM serializer: { customSerializer: createSentryMetroSerializer() }\n // TO serializer: {}\n let removed = false;\n serializerProp.value.properties = serializerProp.value.properties.filter(\n (p) => {\n if (\n p.type === 'ObjectProperty' &&\n p.key.type === 'Identifier' &&\n p.key.name === 'customSerializer'\n ) {\n removed = true;\n return false;\n }\n return true;\n },\n );\n\n if (removed) {\n return true;\n }\n } else {\n if (customSerializerProp.value.arguments[0].type !== 'SpreadElement') {\n // FROM serializer: { customSerializer: createSentryMetroSerializer(wrapperSerializer) }\n // TO serializer: { customSerializer: wrapperSerializer }\n customSerializerProp.value = customSerializerProp.value.arguments[0];\n return true;\n }\n }\n }\n\n return false;\n}\n\nexport function removeSentryRequire(program: t.Program): boolean {\n return removeRequire(program, '@sentry');\n}\n\nasync function parseMetroConfig(): Promise<ProxifiedModule> {\n const metroConfigContent = (\n await fs.promises.readFile(metroConfigPath)\n ).toString();\n\n return parseModule(metroConfigContent);\n}\n\nasync function writeMetroConfig(mod: ProxifiedModule): Promise<boolean> {\n try {\n await writeFile(mod.$ast, metroConfigPath);\n } catch (e) {\n clack.log.error(\n `Failed to write to ${chalk.cyan(metroConfigPath)}: ${JSON.stringify(e)}`,\n );\n return false;\n }\n return true;\n}\n\nexport function addSentrySerializerToMetroConfig(\n configObj: t.ObjectExpression,\n): boolean {\n const serializerProp = getSerializerProp(configObj);\n if ('invalid' === serializerProp) {\n return false;\n }\n\n // case 1: serializer property doesn't exist yet, so we can just add it\n if ('undefined' === serializerProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('serializer'),\n b.objectExpression([\n b.objectProperty(\n b.identifier('customSerializer'),\n b.callExpression(b.identifier('createSentryMetroSerializer'), []),\n ),\n ]),\n ),\n );\n return true;\n }\n\n const customSerializerProp = getCustomSerializerProp(serializerProp);\n // case 2: serializer.customSerializer property doesn't exist yet, so we just add it\n if (\n 'undefined' === customSerializerProp &&\n serializerProp.value.type === 'ObjectExpression'\n ) {\n serializerProp.value.properties.push(\n b.objectProperty(\n b.identifier('customSerializer'),\n b.callExpression(b.identifier('createSentryMetroSerializer'), []),\n ),\n );\n return true;\n }\n\n return false;\n}\n\nfunction getCustomSerializerProp(\n prop: t.ObjectProperty,\n): t.ObjectProperty | 'undefined' | 'invalid' {\n const customSerializerProp =\n prop.value.type === 'ObjectExpression' &&\n prop.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'customSerializer',\n );\n\n if (!customSerializerProp) {\n return 'undefined';\n }\n\n if (customSerializerProp.type === 'ObjectProperty') {\n return customSerializerProp;\n }\n\n return 'invalid';\n}\n\nfunction getSerializerProp(\n obj: t.ObjectExpression,\n): t.ObjectProperty | 'undefined' | 'invalid' {\n const serializerProp = obj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'serializer',\n );\n\n if (!serializerProp) {\n return 'undefined';\n }\n\n if (serializerProp.type === 'ObjectProperty') {\n return serializerProp;\n }\n\n return 'invalid';\n}\n\nexport function addSentrySerializerRequireToMetroConfig(\n program: t.Program,\n): boolean {\n const lastRequireIndex = getLastRequireIndex(program);\n const sentrySerializerRequire = createSentrySerializerRequire();\n const sentryImportIndex = lastRequireIndex + 1;\n if (sentryImportIndex < program.body.length) {\n // insert after last require\n program.body.splice(lastRequireIndex + 1, 0, sentrySerializerRequire);\n } else {\n // insert at the end\n program.body.push(sentrySerializerRequire);\n }\n return true;\n}\n\n/**\n * Creates const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');\n */\nfunction createSentrySerializerRequire() {\n return b.variableDeclaration('const', [\n b.variableDeclarator(\n b.objectPattern([\n b.objectProperty.from({\n key: b.identifier('createSentryMetroSerializer'),\n value: b.identifier('createSentryMetroSerializer'),\n shorthand: true,\n }),\n ]),\n b.callExpression(b.identifier('require'), [\n b.literal('@sentry/react-native/dist/js/tools/sentryMetroSerializer'),\n ]),\n ),\n ]);\n}\n\nasync function confirmPathMetroConfig() {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `Metro Config already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Metro plugin',\n value: true,\n },\n {\n label: 'No, show me instructions to manually add the plugin',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n if (!shouldContinue) {\n Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');\n }\n\n return shouldContinue;\n}\n\n/**\n * Returns value from `module.exports = value` or `const config = value`\n */\nexport function getMetroConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n // check config variable\n const configVariable = program.body.find((s) => {\n if (\n s.type === 'VariableDeclaration' &&\n s.declarations.length === 1 &&\n s.declarations[0].type === 'VariableDeclarator' &&\n s.declarations[0].id.type === 'Identifier' &&\n s.declarations[0].id.name === 'config'\n ) {\n return true;\n }\n return false;\n }) as t.VariableDeclaration | undefined;\n\n if (\n configVariable?.declarations[0].type === 'VariableDeclarator' &&\n configVariable?.declarations[0].init?.type === 'ObjectExpression'\n ) {\n Sentry.setTag('metro-config', 'config-variable');\n return configVariable.declarations[0].init;\n }\n\n // check module.exports\n const moduleExports = program.body.find((s) => {\n if (\n s.type === 'ExpressionStatement' &&\n s.expression.type === 'AssignmentExpression' &&\n s.expression.left.type === 'MemberExpression' &&\n s.expression.left.object.type === 'Identifier' &&\n s.expression.left.object.name === 'module' &&\n s.expression.left.property.type === 'Identifier' &&\n s.expression.left.property.name === 'exports'\n ) {\n return true;\n }\n return false;\n }) as t.ExpressionStatement | undefined;\n\n if (\n (moduleExports?.expression as t.AssignmentExpression).right.type ===\n 'ObjectExpression'\n ) {\n Sentry.setTag('metro-config', 'module-exports');\n return (moduleExports?.expression as t.AssignmentExpression)\n .right as t.ObjectExpression;\n }\n\n Sentry.setTag('metro-config', 'not-found');\n return undefined;\n}\n\nfunction getMetroConfigSnippet(colors: boolean) {\n return makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\";\n${plus(\n \"const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');\",\n)}\n\nconst config = {\n ${plus(`serializer: {\n customSerializer: createSentryMetroSerializer(),\n },`)}\n};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);\n`),\n );\n}\n"]}
|
|
@@ -4,6 +4,8 @@ export declare const RN_SDK_PACKAGE = "@sentry/react-native";
|
|
|
4
4
|
export declare const RN_PACKAGE = "react-native";
|
|
5
5
|
export declare const RN_HUMAN_NAME = "React Native";
|
|
6
6
|
export declare const SUPPORTED_RN_RANGE = ">=0.69.0";
|
|
7
|
+
export declare const SDK_XCODE_SCRIPTS_SUPPORTED_SDK_RANGE = ">=5.11.0";
|
|
8
|
+
export declare const SDK_SENTRY_METRO_PLUGIN_SUPPORTED_SDK_RANGE = ">=5.11.0";
|
|
7
9
|
export type RNCliSetupConfigContent = Pick<Required<CliSetupConfigContent>, 'authToken' | 'org' | 'project' | 'url'>;
|
|
8
10
|
export declare function runReactNativeWizard(params: ReactNativeWizardOptions): Promise<void>;
|
|
9
11
|
export declare function runReactNativeWizardWithTelemetry(options: ReactNativeWizardOptions): Promise<void>;
|