@sentry/wizard 6.11.0 → 6.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/dist/e2e-tests/tests/cloudflare-worker.test.js +5 -0
- package/dist/e2e-tests/tests/cloudflare-worker.test.js.map +1 -1
- package/dist/e2e-tests/tests/pnpm-workspace.test.js +2 -1
- package/dist/e2e-tests/tests/pnpm-workspace.test.js.map +1 -1
- package/dist/e2e-tests/tests/react-router-instrumentation-api.test.d.ts +1 -0
- package/dist/e2e-tests/tests/react-router-instrumentation-api.test.js +96 -0
- package/dist/e2e-tests/tests/react-router-instrumentation-api.test.js.map +1 -0
- package/dist/e2e-tests/tests/react-router.test.js +3 -1
- package/dist/e2e-tests/tests/react-router.test.js.map +1 -1
- package/dist/e2e-tests/tests/sveltekit-tracing.test.js +2 -1
- package/dist/e2e-tests/tests/sveltekit-tracing.test.js.map +1 -1
- package/dist/src/apple/code-tools.js +17 -3
- package/dist/src/apple/code-tools.js.map +1 -1
- package/dist/src/apple/configure-package-manager.js +18 -5
- package/dist/src/apple/configure-package-manager.js.map +1 -1
- package/dist/src/cloudflare/cloudflare-wizard.js +5 -0
- package/dist/src/cloudflare/cloudflare-wizard.js.map +1 -1
- package/dist/src/cloudflare/sdk-setup.d.ts +1 -0
- package/dist/src/cloudflare/sdk-setup.js.map +1 -1
- package/dist/src/cloudflare/templates.d.ts +1 -0
- package/dist/src/cloudflare/templates.js +7 -1
- package/dist/src/cloudflare/templates.js.map +1 -1
- package/dist/src/cloudflare/wrap-worker.d.ts +1 -0
- package/dist/src/cloudflare/wrap-worker.js +7 -0
- package/dist/src/cloudflare/wrap-worker.js.map +1 -1
- package/dist/src/react-native/expo.d.ts +6 -0
- package/dist/src/react-native/expo.js +27 -1
- package/dist/src/react-native/expo.js.map +1 -1
- package/dist/src/react-native/git.d.ts +5 -0
- package/dist/src/react-native/git.js +32 -1
- package/dist/src/react-native/git.js.map +1 -1
- package/dist/src/react-native/javascript.js +3 -1
- package/dist/src/react-native/javascript.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.js +12 -6
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/react-router/codemods/client.entry.d.ts +1 -1
- package/dist/src/react-router/codemods/client.entry.js +69 -12
- package/dist/src/react-router/codemods/client.entry.js.map +1 -1
- package/dist/src/react-router/codemods/react-router-config.js +1 -1
- package/dist/src/react-router/codemods/react-router-config.js.map +1 -1
- package/dist/src/react-router/codemods/root.js +1 -2
- package/dist/src/react-router/codemods/root.js.map +1 -1
- package/dist/src/react-router/codemods/server-entry.d.ts +1 -1
- package/dist/src/react-router/codemods/server-entry.js +39 -4
- package/dist/src/react-router/codemods/server-entry.js.map +1 -1
- package/dist/src/react-router/codemods/vite.js +46 -1
- package/dist/src/react-router/codemods/vite.js.map +1 -1
- package/dist/src/react-router/react-router-wizard.js +52 -5
- package/dist/src/react-router/react-router-wizard.js.map +1 -1
- package/dist/src/react-router/sdk-setup.d.ts +4 -2
- package/dist/src/react-router/sdk-setup.js +32 -5
- package/dist/src/react-router/sdk-setup.js.map +1 -1
- package/dist/src/react-router/templates.d.ts +2 -2
- package/dist/src/react-router/templates.js +72 -2
- package/dist/src/react-router/templates.js.map +1 -1
- package/dist/src/sourcemaps/tools/vite.js +1 -1
- package/dist/src/sourcemaps/tools/vite.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup/vite.js +1 -1
- package/dist/src/sveltekit/sdk-setup/vite.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +10 -0
- package/dist/src/utils/ast-utils.js +19 -1
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/test/apple/code-tools.test.js +78 -0
- package/dist/test/apple/code-tools.test.js.map +1 -1
- package/dist/test/apple/configure-package-manager.test.d.ts +1 -0
- package/dist/test/apple/configure-package-manager.test.js +161 -0
- package/dist/test/apple/configure-package-manager.test.js.map +1 -0
- package/dist/test/cloudflare/sdk-setup.test.js +20 -2
- package/dist/test/cloudflare/sdk-setup.test.js.map +1 -1
- package/dist/test/cloudflare/templates.test.js +54 -0
- package/dist/test/cloudflare/templates.test.js.map +1 -1
- package/dist/test/cloudflare/wrap-worker.test.js +74 -11
- package/dist/test/cloudflare/wrap-worker.test.js.map +1 -1
- package/dist/test/react-native/expo.test.js +140 -0
- package/dist/test/react-native/expo.test.js.map +1 -1
- package/dist/test/react-native/git.test.d.ts +1 -0
- package/dist/test/react-native/git.test.js +160 -0
- package/dist/test/react-native/git.test.js.map +1 -0
- package/dist/test/react-router/codemods/client-entry.test.js +29 -0
- package/dist/test/react-router/codemods/client-entry.test.js.map +1 -1
- package/dist/test/react-router/codemods/root.test.js +4 -0
- package/dist/test/react-router/codemods/root.test.js.map +1 -1
- package/dist/test/react-router/codemods/server-entry.test.js +70 -0
- package/dist/test/react-router/codemods/server-entry.test.js.map +1 -1
- package/dist/test/react-router/codemods/vite.test.js +89 -0
- package/dist/test/react-router/codemods/vite.test.js.map +1 -1
- package/dist/test/react-router/sdk-setup.test.js +62 -6
- package/dist/test/react-router/sdk-setup.test.js.map +1 -1
- package/dist/test/react-router/templates.test.js +50 -0
- package/dist/test/react-router/templates.test.js.map +1 -1
- package/dist/test/sourcemaps/tools/vite.test.js +12 -8
- package/dist/test/sourcemaps/tools/vite.test.js.map +1 -1
- package/dist/test/utils/ast-utils.test.js +22 -0
- package/dist/test/utils/ast-utils.test.js.map +1 -1
- package/package.json +2 -2
|
@@ -44,12 +44,25 @@ async function configurePackageManager({ projectDir, }) {
|
|
|
44
44
|
Sentry.setTag('cocoapod-exists', isCocoaPodsAvailable);
|
|
45
45
|
(0, debug_1.debug)(`CocoaPods is ${isCocoaPodsAvailable ? 'installed' : 'not installed'}`);
|
|
46
46
|
if (isCocoaPodsAvailable) {
|
|
47
|
-
|
|
48
|
-
// Otherwise, we can just use the Swift Package Manager.
|
|
47
|
+
prompts_1.default.log.warn('CocoaPods is being deprecated. No new updates will be released after June 2026.\nWe recommend migrating to Swift Package Manager (SPM).');
|
|
49
48
|
(0, debug_1.debug)('Asking user to choose a package manager');
|
|
50
|
-
const pm =
|
|
49
|
+
const pm = await (0, telemetry_1.traceStep)('Choose a package manager', () => (0, clack_1.abortIfCancelled)(prompts_1.default.select({
|
|
50
|
+
message: 'Which package manager would you like to use to add Sentry?',
|
|
51
|
+
options: [
|
|
52
|
+
{
|
|
53
|
+
value: 'SPM',
|
|
54
|
+
label: 'Swift Package Manager',
|
|
55
|
+
hint: 'Recommended',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
value: 'CocoaPods',
|
|
59
|
+
label: 'CocoaPods',
|
|
60
|
+
hint: 'Deprecated - no updates after June 2026',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
})));
|
|
51
64
|
(0, debug_1.debug)(`User chose package manager: ${chalk_1.default.cyan(pm)}`);
|
|
52
|
-
shouldUseSPM = pm === '
|
|
65
|
+
shouldUseSPM = pm === 'SPM';
|
|
53
66
|
if (!shouldUseSPM) {
|
|
54
67
|
(0, debug_1.debug)('Adding CocoaPods reference');
|
|
55
68
|
const podAdded = await (0, telemetry_1.traceStep)('Add CocoaPods reference', () => cocoapod.addCocoaPods(projectDir));
|
|
@@ -61,7 +74,7 @@ async function configurePackageManager({ projectDir, }) {
|
|
|
61
74
|
}
|
|
62
75
|
}
|
|
63
76
|
(0, debug_1.debug)(`Should use SPM: ${chalk_1.default.cyan(shouldUseSPM.toString())}`);
|
|
64
|
-
Sentry.setTag('package-manager', shouldUseSPM ? 'SPM' : '
|
|
77
|
+
Sentry.setTag('package-manager', shouldUseSPM ? 'SPM' : 'CocoaPods');
|
|
65
78
|
return { shouldUseSPM };
|
|
66
79
|
}
|
|
67
80
|
exports.configurePackageManager = configurePackageManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure-package-manager.js","sourceRoot":"","sources":["../../../src/apple/configure-package-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,qDAAuC;AACvC,kDAA0B;AAE1B,4CAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"configure-package-manager.js","sourceRoot":"","sources":["../../../src/apple/configure-package-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,qDAAuC;AACvC,kDAA0B;AAE1B,4CAAyC;AACzC,0CAAkD;AAClD,0CAAuC;AACvC,qDAAuC;AAEhC,KAAK,UAAU,uBAAuB,CAAC,EAC5C,UAAU,GAGX;IACC,IAAA,aAAK,EACH,+CAA+C,eAAK,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CACxE,CAAC;IAEF,8EAA8E;IAC9E,qDAAqD;IACrD,IAAI,YAAY,GAAG,IAAI,CAAC;IAExB,MAAM,oBAAoB,GAAG,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAC/D,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,CAAC;IACvD,IAAA,aAAK,EAAC,gBAAgB,oBAAoB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;IAE9E,IAAI,oBAAoB,EAAE;QACxB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,yIAAyI,CAC1I,CAAC;QAEF,IAAA,aAAK,EAAC,yCAAyC,CAAC,CAAC;QACjD,MAAM,EAAE,GAAwB,MAAM,IAAA,qBAAS,EAC7C,0BAA0B,EAC1B,GAAG,EAAE,CACH,IAAA,wBAAgB,EACd,iBAAK,CAAC,MAAM,CAAC;YACX,OAAO,EACL,4DAA4D;YAC9D,OAAO,EAAE;gBACP;oBACE,KAAK,EAAE,KAAK;oBACZ,KAAK,EAAE,uBAAuB;oBAC9B,IAAI,EAAE,aAAa;iBACpB;gBACD;oBACE,KAAK,EAAE,WAAW;oBAClB,KAAK,EAAE,WAAW;oBAClB,IAAI,EAAE,yCAAyC;iBAChD;aACF;SACF,CAAC,CACH,CACJ,CAAC;QACF,IAAA,aAAK,EAAC,+BAA+B,eAAK,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAEvD,YAAY,GAAG,EAAE,KAAK,KAAK,CAAC;QAE5B,IAAI,CAAC,YAAY,EAAE;YACjB,IAAA,aAAK,EAAC,4BAA4B,CAAC,CAAC;YACpC,MAAM,QAAQ,GAAG,MAAM,IAAA,qBAAS,EAAC,yBAAyB,EAAE,GAAG,EAAE,CAC/D,QAAQ,CAAC,YAAY,CAAC,UAAU,CAAC,CAClC,CAAC;YACF,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;YAC1C,IAAA,aAAK,EAAC,8BAA8B,eAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;YAEvE,IAAI,CAAC,QAAQ,EAAE;gBACb,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,yKAAyK,CAC1K,CAAC;aACH;SACF;KACF;IACD,IAAA,aAAK,EAAC,mBAAmB,eAAK,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IAChE,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAErE,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC;AApED,0DAoEC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport * as Sentry from '@sentry/node';\nimport chalk from 'chalk';\n\nimport { traceStep } from '../telemetry';\nimport { abortIfCancelled } from '../utils/clack';\nimport { debug } from '../utils/debug';\nimport * as cocoapod from './cocoapod';\n\nexport async function configurePackageManager({\n projectDir,\n}: {\n projectDir: string;\n}) {\n debug(\n `Checking if CocoaPods is installed at path: ${chalk.cyan(projectDir)}`,\n );\n\n // Xcode ships with the Swift Package Manager and potentially using CocoaPods.\n // We need to check if the user has CocoaPods set up.\n let shouldUseSPM = true;\n\n const isCocoaPodsAvailable = cocoapod.usesCocoaPod(projectDir);\n Sentry.setTag('cocoapod-exists', isCocoaPodsAvailable);\n debug(`CocoaPods is ${isCocoaPodsAvailable ? 'installed' : 'not installed'}`);\n\n if (isCocoaPodsAvailable) {\n clack.log.warn(\n 'CocoaPods is being deprecated. No new updates will be released after June 2026.\\nWe recommend migrating to Swift Package Manager (SPM).',\n );\n\n debug('Asking user to choose a package manager');\n const pm: 'SPM' | 'CocoaPods' = await traceStep(\n 'Choose a package manager',\n () =>\n abortIfCancelled(\n clack.select({\n message:\n 'Which package manager would you like to use to add Sentry?',\n options: [\n {\n value: 'SPM',\n label: 'Swift Package Manager',\n hint: 'Recommended',\n },\n {\n value: 'CocoaPods',\n label: 'CocoaPods',\n hint: 'Deprecated - no updates after June 2026',\n },\n ],\n }),\n ),\n );\n debug(`User chose package manager: ${chalk.cyan(pm)}`);\n\n shouldUseSPM = pm === 'SPM';\n\n if (!shouldUseSPM) {\n debug('Adding CocoaPods reference');\n const podAdded = await traceStep('Add CocoaPods reference', () =>\n cocoapod.addCocoaPods(projectDir),\n );\n Sentry.setTag('cocoapod-added', podAdded);\n debug(`CocoaPods reference added: ${chalk.cyan(podAdded.toString())}`);\n\n if (!podAdded) {\n clack.log.warn(\n \"Could not add Sentry pod to your Podfile. You'll have to add it manually.\\nPlease follow the instructions at https://docs.sentry.io/platforms/apple/guides/ios/#install\",\n );\n }\n }\n }\n debug(`Should use SPM: ${chalk.cyan(shouldUseSPM.toString())}`);\n Sentry.setTag('package-manager', shouldUseSPM ? 'SPM' : 'CocoaPods');\n\n return { shouldUseSPM };\n}\n"]}
|
|
@@ -58,6 +58,11 @@ async function runCloudflareWizardWithTelemetry(options) {
|
|
|
58
58
|
prompt: `Do you want to enable ${chalk_1.default.bold('Tracing')} to track the performance of your application?`,
|
|
59
59
|
enabledHint: 'recommended',
|
|
60
60
|
},
|
|
61
|
+
{
|
|
62
|
+
id: 'logs',
|
|
63
|
+
prompt: `Do you want to enable ${chalk_1.default.bold('Logs')} to send your application logs to Sentry?`,
|
|
64
|
+
enabledHint: 'recommended',
|
|
65
|
+
},
|
|
61
66
|
]);
|
|
62
67
|
await (0, telemetry_1.traceStep)('Create Sentry initialization', async () => {
|
|
63
68
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare-wizard.js","sourceRoot":"","sources":["../../../src/cloudflare/cloudflare-wizard.ts"],"names":[],"mappings":";;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAE1B,4CAAwD;AACxD,0CASwB;AACxB,0DAAwE;AACxE,wDAA4D;AAE5D,2CAAmD;AACnD,kGAA0F;AAC1F,8EAAyE;AACzE,8EAAyE;AACzE,0CAAuC;AACvC,0GAGyD;AAElD,KAAK,UAAU,mBAAmB,CACvC,OAAsB;IAEtB,OAAO,IAAA,yBAAa,EAClB;QACE,OAAO,EAAE,OAAO,CAAC,gBAAgB;QACjC,WAAW,EAAE,YAAY;QACzB,aAAa,EAAE,OAAO;KACvB,EACD,GAAG,EAAE,CAAC,gCAAgC,CAAC,OAAO,CAAC,CAChD,CAAC;AACJ,CAAC;AAXD,kDAWC;AAED,KAAK,UAAU,gCAAgC,CAC7C,OAAsB;IAEtB,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAE9D,IAAA,oBAAY,EAAC;QACX,UAAU,EAAE,0BAA0B;QACtC,SAAS;QACT,gBAAgB;KACjB,CAAC,CAAC;IAEH,MAAM,IAAA,yCAAiC,EAAC;QACtC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C,GAAG,EAAE,SAAS;KACf,CA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,GAAG,IAAA,sEAA+B,GAAE,CAAC;IAEnD,MAAM,IAAA,qBAAS,EAAC,iDAAiD,EAAE,GAAG,EAAE,CACtE,IAAA,6CAAoB,EAAC;QACnB,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,wDAAiB,EAAE,CAAC;QAChD,mBAAmB,EAAE,CAAC,YAAY,CAAC;QACnC,kBAAkB,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;QACzD,gBAAgB,EAAE;YAChB,OAAO,EAAE,qBAAqB;SAC/B;KACF,CAAC,CACH,CAAC;IAEF,MAAM,IAAA,8BAAsB,EAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;IAEjD,iFAAiF;IACjF,MAAM,IAAA,wCAA2B,EAC/B,eAAe,CAAC,YAAY,CAAC,IAAI,EACjC,eAAe,CAAC,IAAI,CACrB,CAAC;IAEF,iBAAK,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC;AACnC,CAAC;AAED,SAAgB,iBAAiB;IAC/B,OAAO;IACL,eAAK,CAAC,KAAK,CACX,sEAAsE,CACvE;;IAEC,eAAK,CAAC,GAAG,CAAC,aAAa,CAAC;IACxB,eAAK,CAAC,GAAG,CAAC,qDAAqD,CAAC;IAChE,eAAK,CAAC,GAAG,CAAC,kCAAkC,CAAC,IAAI,eAAK,CAAC,IAAI,CAC3D,iBAAiB,CAClB;IACC,eAAK,CAAC,GAAG,CAAC,gDAAgD,CAAC;;IAE3D,eAAK,CAAC,IAAI,CACV;iEAC6D,CAC9D;GACA,CAAC;AACJ,CAAC;AAlBD,8CAkBC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport { traceStep, withTelemetry } from '../telemetry';\nimport {\n confirmContinueIfNoOrDirtyGitRepo,\n ensurePackageIsInstalled,\n featureSelectionPrompt,\n getOrAskForProjectData,\n getPackageDotJson,\n installPackage,\n printWelcome,\n runPrettierIfInstalled,\n} from '../utils/clack';\nimport { offerProjectScopedMcpConfig } from '../utils/clack/mcp-config';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport type { WizardOptions } from '../utils/types';\nimport { createSentryInitFile } from './sdk-setup';\nimport { abortIfSpotlightNotSupported } from '../utils/abort-if-sportlight-not-supported';\nimport { ensureWranglerConfig } from './wrangler/ensure-wrangler-config';\nimport { updateWranglerConfig } from './wrangler/update-wrangler-config';\nimport { debug } from '../utils/debug';\nimport {\n defaultEntryPoint,\n getEntryPointFromWranglerConfig,\n} from './wrangler/get-entry-point-from-wrangler-config';\n\nexport async function runCloudflareWizard(\n options: WizardOptions,\n): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'cloudflare',\n wizardOptions: options,\n },\n () => runCloudflareWizardWithTelemetry(options),\n );\n}\n\nasync function runCloudflareWizardWithTelemetry(\n options: WizardOptions,\n): Promise<void> {\n const { promoCode, telemetryEnabled, forceInstall } = options;\n\n printWelcome({\n wizardName: 'Sentry Cloudflare Wizard',\n promoCode,\n telemetryEnabled,\n });\n\n await confirmContinueIfNoOrDirtyGitRepo({\n ignoreGitChanges: options.ignoreGitChanges,\n cwd: undefined,\n });\n\n const packageJson = await getPackageDotJson();\n\n await ensurePackageIsInstalled(packageJson, 'wrangler', 'Cloudflare');\n\n traceStep('Ensure Wrangler config', () => {\n ensureWranglerConfig();\n });\n\n const projectData = await getOrAskForProjectData(\n options,\n 'node-cloudflare-workers',\n );\n\n if (projectData.spotlight) {\n return abortIfSpotlightNotSupported('Cloudflare');\n }\n\n const { selectedProject } = projectData;\n\n await installPackage({\n packageName: '@sentry/cloudflare@^10',\n packageNameDisplayLabel: '@sentry/cloudflare',\n alreadyInstalled: hasPackageInstalled('@sentry/cloudflare', packageJson),\n forceInstall,\n });\n\n const selectedFeatures = await featureSelectionPrompt([\n {\n id: 'performance',\n prompt: `Do you want to enable ${chalk.bold(\n 'Tracing',\n )} to track the performance of your application?`,\n enabledHint: 'recommended',\n },\n ] as const);\n\n await traceStep('Create Sentry initialization', async () => {\n try {\n await createSentryInitFile(\n selectedProject.keys[0].dsn.public,\n selectedFeatures,\n );\n } catch (e) {\n clack.log.warn(\n 'Could not automatically set up Sentry initialization. Please set it up manually using instructions from https://docs.sentry.io/platforms/javascript/guides/cloudflare/',\n );\n debug(e);\n }\n });\n\n const mainFile = getEntryPointFromWranglerConfig();\n\n await traceStep('Update Wrangler config with Sentry requirements', () =>\n updateWranglerConfig({\n ...(mainFile ? {} : { main: defaultEntryPoint }),\n compatibility_flags: ['nodejs_als'],\n compatibility_date: new Date().toISOString().slice(0, 10),\n version_metadata: {\n binding: 'CF_VERSION_METADATA',\n },\n }),\n );\n\n await runPrettierIfInstalled({ cwd: undefined });\n\n // Offer optional project-scoped MCP config for Sentry with org and project scope\n await offerProjectScopedMcpConfig(\n selectedProject.organization.slug,\n selectedProject.slug,\n );\n\n clack.outro(buildOutroMessage());\n}\n\nexport function buildOutroMessage(): string {\n return `\n ${chalk.green(\n 'Sentry has been successfully configured for your Cloudflare project.',\n )}\n\n ${chalk.dim('Next steps:')}\n ${chalk.dim('1. Wrap your worker with Sentry as instructed above')}\n ${chalk.dim('2. Deploy your application with:')} ${chalk.cyan(\n 'wrangler deploy',\n )}\n ${chalk.dim('3. Trigger an error to test Sentry integration')}\n\n ${chalk.cyan(\n `To learn more about using Sentry with Cloudflare, visit:\n https://docs.sentry.io/platforms/javascript/guides/cloudflare/`,\n )}\n `;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cloudflare-wizard.js","sourceRoot":"","sources":["../../../src/cloudflare/cloudflare-wizard.ts"],"names":[],"mappings":";;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAE1B,4CAAwD;AACxD,0CASwB;AACxB,0DAAwE;AACxE,wDAA4D;AAE5D,2CAAmD;AACnD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C,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;IAEjD,iFAAiF;IACjF,MAAM,IAAA,wCAA2B,EAC/B,eAAe,CAAC,YAAY,CAAC,IAAI,EACjC,eAAe,CAAC,IAAI,CACrB,CAAC;IAEF,iBAAK,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC;AACnC,CAAC;AAED,SAAgB,iBAAiB;IAC/B,OAAO;IACL,eAAK,CAAC,KAAK,CACX,sEAAsE,CACvE;;IAEC,eAAK,CAAC,GAAG,CAAC,aAAa,CAAC;IACxB,eAAK,CAAC,GAAG,CAAC,qDAAqD,CAAC;IAChE,eAAK,CAAC,GAAG,CAAC,kCAAkC,CAAC,IAAI,eAAK,CAAC,IAAI,CAC3D,iBAAiB,CAClB;IACC,eAAK,CAAC,GAAG,CAAC,gDAAgD,CAAC;;IAE3D,eAAK,CAAC,IAAI,CACV;iEAC6D,CAC9D;GACA,CAAC;AACJ,CAAC;AAlBD,8CAkBC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\nimport { traceStep, withTelemetry } from '../telemetry';\nimport {\n confirmContinueIfNoOrDirtyGitRepo,\n ensurePackageIsInstalled,\n featureSelectionPrompt,\n getOrAskForProjectData,\n getPackageDotJson,\n installPackage,\n printWelcome,\n runPrettierIfInstalled,\n} from '../utils/clack';\nimport { offerProjectScopedMcpConfig } from '../utils/clack/mcp-config';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport type { WizardOptions } from '../utils/types';\nimport { createSentryInitFile } from './sdk-setup';\nimport { abortIfSpotlightNotSupported } from '../utils/abort-if-sportlight-not-supported';\nimport { ensureWranglerConfig } from './wrangler/ensure-wrangler-config';\nimport { updateWranglerConfig } from './wrangler/update-wrangler-config';\nimport { debug } from '../utils/debug';\nimport {\n defaultEntryPoint,\n getEntryPointFromWranglerConfig,\n} from './wrangler/get-entry-point-from-wrangler-config';\n\nexport async function runCloudflareWizard(\n options: WizardOptions,\n): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'cloudflare',\n wizardOptions: options,\n },\n () => runCloudflareWizardWithTelemetry(options),\n );\n}\n\nasync function runCloudflareWizardWithTelemetry(\n options: WizardOptions,\n): Promise<void> {\n const { promoCode, telemetryEnabled, forceInstall } = options;\n\n printWelcome({\n wizardName: 'Sentry Cloudflare Wizard',\n promoCode,\n telemetryEnabled,\n });\n\n await confirmContinueIfNoOrDirtyGitRepo({\n ignoreGitChanges: options.ignoreGitChanges,\n cwd: undefined,\n });\n\n const packageJson = await getPackageDotJson();\n\n await ensurePackageIsInstalled(packageJson, 'wrangler', 'Cloudflare');\n\n traceStep('Ensure Wrangler config', () => {\n ensureWranglerConfig();\n });\n\n const projectData = await getOrAskForProjectData(\n options,\n 'node-cloudflare-workers',\n );\n\n if (projectData.spotlight) {\n return abortIfSpotlightNotSupported('Cloudflare');\n }\n\n const { selectedProject } = projectData;\n\n await installPackage({\n packageName: '@sentry/cloudflare@^10',\n packageNameDisplayLabel: '@sentry/cloudflare',\n alreadyInstalled: hasPackageInstalled('@sentry/cloudflare', packageJson),\n forceInstall,\n });\n\n const selectedFeatures = await featureSelectionPrompt([\n {\n id: 'performance',\n prompt: `Do you want to enable ${chalk.bold(\n 'Tracing',\n )} to track the performance of your application?`,\n enabledHint: 'recommended',\n },\n {\n id: 'logs',\n prompt: `Do you want to enable ${chalk.bold(\n 'Logs',\n )} to send your application logs to Sentry?`,\n enabledHint: 'recommended',\n },\n ] as const);\n\n await traceStep('Create Sentry initialization', async () => {\n try {\n await createSentryInitFile(\n selectedProject.keys[0].dsn.public,\n selectedFeatures,\n );\n } catch (e) {\n clack.log.warn(\n 'Could not automatically set up Sentry initialization. Please set it up manually using instructions from https://docs.sentry.io/platforms/javascript/guides/cloudflare/',\n );\n debug(e);\n }\n });\n\n const mainFile = getEntryPointFromWranglerConfig();\n\n await traceStep('Update Wrangler config with Sentry requirements', () =>\n updateWranglerConfig({\n ...(mainFile ? {} : { main: defaultEntryPoint }),\n compatibility_flags: ['nodejs_als'],\n compatibility_date: new Date().toISOString().slice(0, 10),\n version_metadata: {\n binding: 'CF_VERSION_METADATA',\n },\n }),\n );\n\n await runPrettierIfInstalled({ cwd: undefined });\n\n // Offer optional project-scoped MCP config for Sentry with org and project scope\n await offerProjectScopedMcpConfig(\n selectedProject.organization.slug,\n selectedProject.slug,\n );\n\n clack.outro(buildOutroMessage());\n}\n\nexport function buildOutroMessage(): string {\n return `\n ${chalk.green(\n 'Sentry has been successfully configured for your Cloudflare project.',\n )}\n\n ${chalk.dim('Next steps:')}\n ${chalk.dim('1. Wrap your worker with Sentry as instructed above')}\n ${chalk.dim('2. Deploy your application with:')} ${chalk.cyan(\n 'wrangler deploy',\n )}\n ${chalk.dim('3. Trigger an error to test Sentry integration')}\n\n ${chalk.cyan(\n `To learn more about using Sentry with Cloudflare, visit:\n https://docs.sentry.io/platforms/javascript/guides/cloudflare/`,\n )}\n `;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-setup.js","sourceRoot":"","sources":["../../../src/cloudflare/sdk-setup.ts"],"names":[],"mappings":";;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,sDAAyB;AACzB,0DAA6B;AAC7B,2CAGqB;AACrB,0GAGyD;AACzD,+CAAqD;AAErD;;;GAGG;AACI,KAAK,UAAU,oBAAoB,CACxC,GAAW,EACX,
|
|
1
|
+
{"version":3,"file":"sdk-setup.js","sourceRoot":"","sources":["../../../src/cloudflare/sdk-setup.ts"],"names":[],"mappings":";;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,sDAAyB;AACzB,0DAA6B;AAC7B,2CAGqB;AACrB,0GAGyD;AACzD,+CAAqD;AAErD;;;GAGG;AACI,KAAK,UAAU,oBAAoB,CACxC,GAAW,EACX,gBAGC;IAED,MAAM,oBAAoB,GAAG,I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AAC,sCAAsC,CAAC,CAAC;YACvD,iBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;YAEvE,iBAAK,CAAC,IAAI,CACR,eAAK,CAAC,IAAI,CAAC,IAAA,uCAA2B,EAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAC/D,CAAC;SACH;QACD,OAAO;KACR;AACH,CAAC;AAzDD,oDAyDC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport {\n getCloudflareWorkerTemplate,\n getCloudflareWorkerTemplateWithHandler,\n} from './templates';\nimport {\n defaultEntryPoint,\n getEntryPointFromWranglerConfig,\n} from './wrangler/get-entry-point-from-wrangler-config';\nimport { wrapWorkerWithSentry } from './wrap-worker';\n\n/**\n * Creates or updates the main worker file with Sentry initialization.\n * Currently focused on Cloudflare Workers\n */\nexport async function createSentryInitFile(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n logs: boolean;\n },\n): Promise<void> {\n const entryPointFromConfig = getEntryPointFromWranglerConfig();\n\n if (!entryPointFromConfig) {\n clack.log.info(\n 'No entry point found in wrangler config, creating a new one.',\n );\n\n const cloudflareWorkerTemplate = getCloudflareWorkerTemplateWithHandler();\n\n await fs.promises.mkdir(\n path.join(process.cwd(), path.dirname(defaultEntryPoint)),\n {\n recursive: true,\n },\n );\n await fs.promises.writeFile(\n path.join(process.cwd(), defaultEntryPoint),\n cloudflareWorkerTemplate,\n { encoding: 'utf-8', flag: 'w' },\n );\n\n clack.log.success(`Created ${chalk.cyan(defaultEntryPoint)}.`);\n\n return;\n }\n\n const entryPointPath = path.join(process.cwd(), entryPointFromConfig);\n\n if (fs.existsSync(entryPointPath)) {\n clack.log.info(\n `Found existing entry point: ${chalk.cyan(entryPointFromConfig)}`,\n );\n\n try {\n await wrapWorkerWithSentry(entryPointPath, dsn, selectedFeatures);\n clack.log.success(\n `Wrapped ${chalk.cyan(\n entryPointFromConfig,\n )} with Sentry initialization.`,\n );\n } catch (error) {\n clack.log.warn('Failed to wrap worker automatically.');\n clack.log.step('Please wrap your handler with Sentry initialization:');\n\n clack.note(\n chalk.cyan(getCloudflareWorkerTemplate(dsn, selectedFeatures)),\n );\n }\n return;\n }\n}\n"]}
|
|
@@ -8,11 +8,17 @@ function getCloudflareWorkerTemplate(dsn, selectedFeatures) {
|
|
|
8
8
|
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
|
|
9
9
|
tracesSampleRate: 1,`;
|
|
10
10
|
}
|
|
11
|
+
let logsOptions = '';
|
|
12
|
+
if (selectedFeatures.logs) {
|
|
13
|
+
logsOptions = `
|
|
14
|
+
// Enable logs to be sent to Sentry
|
|
15
|
+
enableLogs: true,`;
|
|
16
|
+
}
|
|
11
17
|
return `import * as Sentry from '@sentry/cloudflare';
|
|
12
18
|
|
|
13
19
|
export default Sentry.withSentry(
|
|
14
20
|
(env) => ({
|
|
15
|
-
dsn: '${dsn}',${performanceOptions}
|
|
21
|
+
dsn: '${dsn}',${performanceOptions}${logsOptions}
|
|
16
22
|
}),
|
|
17
23
|
{
|
|
18
24
|
async fetch(request, env, ctx): Promise<Response> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/cloudflare/templates.ts"],"names":[],"mappings":";;;AAAA,SAAgB,2BAA2B,CACzC,GAAW,EACX,
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/cloudflare/templates.ts"],"names":[],"mappings":";;;AAAA,SAAgB,2BAA2B,CACzC,GAAW,EACX,gBAGC;IAED,IAAI,kBAAkB,GAAG,EAAE,CAAC;IAC5B,IAAI,gBAAgB,CAAC,WAAW,EAAE;QAChC,kBAAkB,GAAG;;uBAEF,CAAC;KACrB;IAED,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,gBAAgB,CAAC,IAAI,EAAE;QACzB,WAAW,GAAG;;oBAEE,CAAC;KAClB;IAED,OAAO;;;;UAIC,GAAG,KAAK,kBAAkB,GAAG,WAAW;;;;;;;;;CASjD,CAAC;AACF,CAAC;AAnCD,kEAmCC;AAED,SAAgB,sCAAsC;IACpD,OAAO;;;;;;;;;;;;;CAaR,CAAC;AACF,CAAC;AAfD,wFAeC","sourcesContent":["export function getCloudflareWorkerTemplate(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n logs: boolean;\n },\n): string {\n let performanceOptions = '';\n if (selectedFeatures.performance) {\n performanceOptions = `\n\t\t// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n\t\ttracesSampleRate: 1,`;\n }\n\n let logsOptions = '';\n if (selectedFeatures.logs) {\n logsOptions = `\n\t\t// Enable logs to be sent to Sentry\n\t\tenableLogs: true,`;\n }\n\n return `import * as Sentry from '@sentry/cloudflare';\n\nexport default Sentry.withSentry(\n\t(env) => ({\n\t\tdsn: '${dsn}',${performanceOptions}${logsOptions}\n\t}),\n\t{\n\t\tasync fetch(request, env, ctx): Promise<Response> {\n\t\t\t// Your worker logic here\n\t\t\treturn new Response('Hello World!');\n\t\t},\n\t} satisfies ExportedHandler<Env>,\n);\n`;\n}\n\nexport function getCloudflareWorkerTemplateWithHandler(): string {\n return `export default {\n\tasync fetch(request, env, ctx): Promise<Response> {\n\t\tconst url = new URL(request.url);\n\t\tswitch (url.pathname) {\n\t\t\tcase '/message':\n\t\t\t\treturn new Response('Hello, World!');\n\t\t\tcase '/random':\n\t\t\t\treturn new Response(crypto.randomUUID());\n\t\t\tdefault:\n\t\t\t\treturn new Response('Not Found', { status: 404 });\n\t\t}\n\t},\n} satisfies ExportedHandler<Env>;\n`;\n}\n"]}
|
|
@@ -103,6 +103,13 @@ function createSentryConfigFunction(dsn, selectedFeatures) {
|
|
|
103
103
|
];
|
|
104
104
|
configProperties.push(tracesSampleRateProperty);
|
|
105
105
|
}
|
|
106
|
+
if (selectedFeatures.logs) {
|
|
107
|
+
const enableLogsProperty = b.objectProperty(b.identifier('enableLogs'), b.booleanLiteral(true));
|
|
108
|
+
enableLogsProperty.comments = [
|
|
109
|
+
b.commentLine(' Enable logs to be sent to Sentry', true, false),
|
|
110
|
+
];
|
|
111
|
+
configProperties.push(enableLogsProperty);
|
|
112
|
+
}
|
|
106
113
|
const configObject = b.objectExpression(configProperties);
|
|
107
114
|
return b.arrowFunctionExpression([b.identifier('env')], configObject);
|
|
108
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap-worker.js","sourceRoot":"","sources":["../../../src/cloudflare/wrap-worker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,kFAAkF;AAClF,uCAA+C;AAC/C,+EAA+E;AAC/E,sDAAwC;AACxC,kDAAsD;AACtD,kDAA0B;AAG1B,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACI,KAAK,UAAU,oBAAoB,CACxC,cAAsB,EACtB,GAAW,EACX,
|
|
1
|
+
{"version":3,"file":"wrap-worker.js","sourceRoot":"","sources":["../../../src/cloudflare/wrap-worker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,kFAAkF;AAClF,uCAA+C;AAC/C,+EAA+E;AAC/E,sDAAwC;AACxC,kDAAsD;AACtD,kDAA0B;AAG1B,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACI,KAAK,UAAU,oBAAoB,CACxC,cAAsB,EACtB,GAAW,EACX,gBAGC;IAED,MAAM,SAAS,GAAG,MAAM,IAAA,mBAAQ,EAAC,cAAc,CAAC,CAAC;IAEjD,IAAI,IAAA,4BAAgB,EAAC,SAAS,CAAC,IAAiB,CAAC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CAAC,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAChC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CACpB,CAAC;QAEF,wBAAwB,CAAC,QAAQ,GAAG;YAClC,CAAC,CAAC,WAAW,CACX,mHAAmH,EACnH,IAAI,EACJ,KAAK,CACN;SACF,CAAC;QAEF,gBAAgB,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;KACjD;IAED,IAAI,gBAAgB,CAAC,IAAI,EAAE;QACzB,MAAM,kBAAkB,GAAG,CAAC,CAAC,cAAc,CACzC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,EAC1B,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CACvB,CAAC;QAEF,kBAAkB,CAAC,QAAQ,GAAG;YAC5B,CAAC,CAAC,WAAW,CAAC,mCAAmC,EAAE,IAAI,EAAE,KAAK,CAAC;SAChE,CAAC;QAEF,gBAAgB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;KAC3C;IAED,MAAM,YAAY,GAAG,CAAC,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IAE1D,OAAO,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import * as recast from 'recast';\nimport type { namedTypes as t } from 'ast-types';\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { loadFile, writeFile } from 'magicast';\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport { hasSentryContent } from '../utils/ast-utils';\nimport chalk from 'chalk';\nimport { ExpressionKind } from 'ast-types/lib/gen/kinds';\n\nconst b = recast.types.builders;\n\n/**\n * Wraps a Cloudflare Worker's default export with Sentry.withSentry()\n *\n * Before:\n * ```\n * export default {\n * async fetch(request, env, ctx) { ... }\n * } satisfies ExportedHandler<Env>;\n * ```\n *\n * After:\n * ```\n * import * as Sentry from '@sentry/cloudflare';\n *\n * export default Sentry.withSentry(\n * (env) => ({\n * dsn: 'your-dsn',\n * tracesSampleRate: 1,\n * }),\n * {\n * async fetch(request, env, ctx) { ... }\n * } satisfies ExportedHandler<Env>\n * );\n * ```\n *\n * @param workerFilePath - Path to the worker file to wrap\n * @param dsn - Sentry DSN for initialization\n * @param selectedFeatures - Feature flags for optional Sentry features\n */\nexport async function wrapWorkerWithSentry(\n workerFilePath: string,\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n logs: boolean;\n },\n): Promise<void> {\n const workerAst = await loadFile(workerFilePath);\n\n if (hasSentryContent(workerAst.$ast as t.Program)) {\n clack.log.warn(\n `Sentry is already configured in ${chalk.cyan(\n workerFilePath,\n )}. Skipping wrapping with Sentry.`,\n );\n return;\n }\n\n workerAst.imports.$add({\n from: '@sentry/cloudflare',\n imported: '*',\n local: 'Sentry',\n });\n\n recast.visit(workerAst.$ast, {\n visitExportDefaultDeclaration(path) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n const originalDeclaration = path.value.declaration as ExpressionKind;\n const sentryConfig = createSentryConfigFunction(dsn, selectedFeatures);\n const wrappedExport = b.callExpression(\n b.memberExpression(b.identifier('Sentry'), b.identifier('withSentry')),\n [sentryConfig, originalDeclaration],\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n path.value.declaration = wrappedExport;\n\n return false;\n },\n });\n\n await writeFile(workerAst.$ast, workerFilePath);\n}\n\n/**\n * Creates the Sentry config function: (env) => ({ dsn: '...', ... })\n */\nfunction createSentryConfigFunction(\n dsn: string,\n selectedFeatures: {\n performance: boolean;\n logs: boolean;\n },\n): t.ArrowFunctionExpression {\n const configProperties: t.ObjectProperty[] = [\n b.objectProperty(b.identifier('dsn'), b.stringLiteral(dsn)),\n ];\n\n if (selectedFeatures.performance) {\n const tracesSampleRateProperty = b.objectProperty(\n b.identifier('tracesSampleRate'),\n b.numericLiteral(1),\n );\n\n tracesSampleRateProperty.comments = [\n b.commentLine(\n ' Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.',\n true,\n false,\n ),\n ];\n\n configProperties.push(tracesSampleRateProperty);\n }\n\n if (selectedFeatures.logs) {\n const enableLogsProperty = b.objectProperty(\n b.identifier('enableLogs'),\n b.booleanLiteral(true),\n );\n\n enableLogsProperty.comments = [\n b.commentLine(' Enable logs to be sent to Sentry', true, false),\n ];\n\n configProperties.push(enableLogsProperty);\n }\n\n const configObject = b.objectExpression(configProperties);\n\n return b.arrowFunctionExpression([b.identifier('env')], configObject);\n}\n"]}
|
|
@@ -14,3 +14,9 @@ export declare function printSentryExpoMigrationOutro(): void;
|
|
|
14
14
|
export declare function patchExpoAppConfig(options: RNCliSetupConfigContent): Promise<void>;
|
|
15
15
|
export declare function addWithSentryToAppConfigJson(appConfigContent: string, options: RNCliSetupConfigContent): string | null;
|
|
16
16
|
export declare function getSentryAppConfigJsonCodeSnippet({ url, project, org, }: Omit<RNCliSetupConfigContent, 'authToken'>): string;
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the project is using Expo's Config Plugins (CNG)
|
|
19
|
+
* It checks by checking if the native folders are in gitignore or not
|
|
20
|
+
* If native folders are in gitignore then we can skip the native properties file step
|
|
21
|
+
*/
|
|
22
|
+
export declare const isExpoCNG: () => Promise<boolean>;
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getSentryAppConfigJsonCodeSnippet = exports.addWithSentryToAppConfigJson = exports.patchExpoAppConfig = exports.printSentryExpoMigrationOutro = exports.SENTRY_PLUGIN_FUNCTION_NAME = exports.DEPRECATED_SENTRY_EXPO_PLUGIN_NAME = exports.SENTRY_EXPO_PLUGIN_NAME = void 0;
|
|
29
|
+
exports.isExpoCNG = exports.getSentryAppConfigJsonCodeSnippet = exports.addWithSentryToAppConfigJson = exports.patchExpoAppConfig = exports.printSentryExpoMigrationOutro = exports.SENTRY_PLUGIN_FUNCTION_NAME = exports.DEPRECATED_SENTRY_EXPO_PLUGIN_NAME = exports.SENTRY_EXPO_PLUGIN_NAME = void 0;
|
|
30
30
|
// @ts-expect-error - clack is ESM and TS complains about that. It works though
|
|
31
31
|
const clack = __importStar(require("@clack/prompts"));
|
|
32
32
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -35,6 +35,7 @@ const os_1 = require("os");
|
|
|
35
35
|
const Sentry = __importStar(require("@sentry/node"));
|
|
36
36
|
const clack_1 = require("../utils/clack");
|
|
37
37
|
const telemetry_1 = require("../telemetry");
|
|
38
|
+
const git_1 = require("./git");
|
|
38
39
|
exports.SENTRY_EXPO_PLUGIN_NAME = '@sentry/react-native/expo';
|
|
39
40
|
exports.DEPRECATED_SENTRY_EXPO_PLUGIN_NAME = 'sentry-expo';
|
|
40
41
|
exports.SENTRY_PLUGIN_FUNCTION_NAME = 'withSentry';
|
|
@@ -155,4 +156,29 @@ exports.getSentryAppConfigJsonCodeSnippet = getSentryAppConfigJsonCodeSnippet;
|
|
|
155
156
|
function isPlainObject(what) {
|
|
156
157
|
return Object.prototype.toString.call(what) === '[object Object]';
|
|
157
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Checks if the project is using Expo's Config Plugins (CNG)
|
|
161
|
+
* It checks by checking if the native folders are in gitignore or not
|
|
162
|
+
* If native folders are in gitignore then we can skip the native properties file step
|
|
163
|
+
*/
|
|
164
|
+
const isExpoCNG = async () => {
|
|
165
|
+
const iOSExists = fs.existsSync('ios');
|
|
166
|
+
const androidExists = fs.existsSync('android');
|
|
167
|
+
const anyNativeFolderExists = iOSExists || androidExists;
|
|
168
|
+
if (!anyNativeFolderExists) {
|
|
169
|
+
// Definitely CNG and using prebuild steps
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const [isIosInGitIgnore, isAndroidInGitIgnore] = await Promise.all([
|
|
174
|
+
iOSExists ? (0, git_1.isFolderInGitignore)('ios') : Promise.resolve(true),
|
|
175
|
+
androidExists ? (0, git_1.isFolderInGitignore)('android') : Promise.resolve(true),
|
|
176
|
+
]);
|
|
177
|
+
return isIosInGitIgnore && isAndroidInGitIgnore;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
exports.isExpoCNG = isExpoCNG;
|
|
158
184
|
//# sourceMappingURL=expo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expo.js","sourceRoot":"","sources":["../../../src/react-native/expo.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,sDAAwC;AACxC,kDAA0B;AAC1B,uCAAyB;AACzB,2BAAyB;AAEzB,qDAAuC;AACvC,0CAA4E;AAE5E,4CAAyC;AAE5B,QAAA,uBAAuB,GAAG,2BAA2B,CAAC;AACtD,QAAA,kCAAkC,GAAG,aAAa,CAAC;AAEnD,QAAA,2BAA2B,GAAG,YAAY,CAAC;AAExD,MAAM,eAAe,GAAG,UAAU,CAAC;AAQnC,SAAgB,6BAA6B;IAC3C,KAAK,CAAC,KAAK,CACT,cAAc,eAAK,CAAC,IAAI,CACtB,aAAa,CACd,iFAAiF,eAAK,CAAC,IAAI,CAC1F,sEAAsE,CACvE,EAAE,CACJ,CAAC;AACJ,CAAC;AARD,sEAQC;AAED;;GAEG;AACI,KAAK,UAAU,kBAAkB,CAAC,OAAgC;IACvE,SAAS,gBAAgB;QACvB,OAAO,IAAA,iCAAyB,EAAC;YAC/B,QAAQ,EAAE,eAAe;YACzB,WAAW,EAAE,iCAAiC,CAAC,OAAO,CAAC;YACvD,IAAI,EAAE,kEAAkE;SACzE,CAAC,CAAC;IACL,CAAC;IAED,MAAM,mBAAmB,GAAG,EAAE,CAAC,UA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AExB,CAAC;;EAEL,CAAC,CAAC;IACF,CAAC,CAAC,CAAC;AACL,CAAC;AApBD,8EAoBC;AAED;;;GAGG;AACH,SAAS,aAAa,CAAC,IAAa;IAClC,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,iBAAiB,CAAC;AACpE,CAAC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as fs from 'fs';\nimport { EOL } from 'os';\n\nimport * as Sentry from '@sentry/node';\nimport { makeCodeSnippet, showCopyPasteInstructions } from '../utils/clack';\nimport { RNCliSetupConfigContent } from './react-native-wizard';\nimport { traceStep } from '../telemetry';\n\nexport const SENTRY_EXPO_PLUGIN_NAME = '@sentry/react-native/expo';\nexport const DEPRECATED_SENTRY_EXPO_PLUGIN_NAME = 'sentry-expo';\n\nexport const SENTRY_PLUGIN_FUNCTION_NAME = 'withSentry';\n\nconst APP_CONFIG_JSON = `app.json`;\n\nexport interface AppConfigJson {\n expo?: {\n plugins?: Array<[string, undefined | Record<string, unknown>]>;\n };\n}\n\nexport function printSentryExpoMigrationOutro(): void {\n clack.outro(\n `Deprecated ${chalk.cyan(\n 'sentry-expo',\n )} package installed in your dependencies. Please follow the migration guide at ${chalk.cyan(\n 'https://docs.sentry.io/platforms/react-native/migration/sentry-expo/',\n )}`,\n );\n}\n\n/**\n * Finds app.json in the project root and add Sentry Expo `withSentry` plugin.\n */\nexport async function patchExpoAppConfig(options: RNCliSetupConfigContent) {\n function showInstructions() {\n return showCopyPasteInstructions({\n filename: APP_CONFIG_JSON,\n codeSnippet: getSentryAppConfigJsonCodeSnippet(options),\n hint: 'This ensures auto upload of source maps during native app build.',\n });\n }\n\n const appConfigJsonExists = fs.existsSync(APP_CONFIG_JSON);\n\n Sentry.setTag(\n 'app-config-file-status',\n appConfigJsonExists ? 'found' : 'not-found',\n );\n if (!appConfigJsonExists) {\n return await showInstructions();\n }\n\n const patched = await patchAppConfigJson(APP_CONFIG_JSON, options);\n if (!patched) {\n Sentry.setTag('app-config-file-status', 'patch-error');\n clack.log.error(`Unable to patch ${chalk.cyan('app.config.json')}.`);\n return await showInstructions();\n }\n}\n\nasync function patchAppConfigJson(\n path: string,\n options: RNCliSetupConfigContent,\n): Promise<boolean> {\n const appConfigContent = (\n await fs.promises.readFile(path, { encoding: 'utf-8' })\n ).toString();\n const patchedContent = traceStep('app-config-json-patch', () =>\n addWithSentryToAppConfigJson(appConfigContent, options),\n );\n if (patchedContent === null) {\n return false;\n }\n\n try {\n await fs.promises.writeFile(path, patchedContent);\n } catch (error) {\n Sentry.setTag('app-config-file-status', 'json-write-error');\n clack.log.error(`Unable to write ${chalk.cyan('app.config.json')}.`);\n Sentry.captureException(`Unable to write 'app.config.json'.`);\n return false;\n }\n Sentry.setTag('app-config-file-status', 'json-write-success');\n clack.log.success(\n `Added Sentry Expo plugin to ${chalk.cyan('app.config.json')}.`,\n );\n return true;\n}\n\nexport function addWithSentryToAppConfigJson(\n appConfigContent: string,\n options: RNCliSetupConfigContent,\n): string | null {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const parsedAppConfig: AppConfigJson = JSON.parse(appConfigContent);\n const includesWithSentry =\n appConfigContent.includes(SENTRY_EXPO_PLUGIN_NAME) ||\n appConfigContent.includes(DEPRECATED_SENTRY_EXPO_PLUGIN_NAME);\n\n if (includesWithSentry) {\n Sentry.setTag('app-config-file-status', 'already-patched');\n clack.log.warn(\n `Your ${chalk.cyan(\n 'app.config.json',\n )} already includes the Sentry Expo plugin.`,\n );\n return null;\n }\n\n if (\n parsedAppConfig.expo !== undefined &&\n !isPlainObject(parsedAppConfig.expo)\n ) {\n Sentry.setTag('app-config-file-status', 'invalid-json');\n clack.log.error(\n `Unable to find expo in your ${chalk.cyan(\n 'app.config.json',\n )}. Make sure it has a valid format!`,\n );\n return null;\n }\n if (\n parsedAppConfig.expo &&\n parsedAppConfig.expo.plugins !== undefined &&\n !Array.isArray(parsedAppConfig.expo.plugins)\n ) {\n Sentry.setTag('app-config-file-status', 'invalid-json');\n clack.log.error(\n `Unable to find expo plugins in your ${chalk.cyan(\n 'app.config.json',\n )}. Make sure it has a valid format!`,\n );\n return null;\n }\n\n parsedAppConfig.expo = parsedAppConfig.expo ?? {};\n parsedAppConfig.expo.plugins = parsedAppConfig.expo.plugins ?? [];\n parsedAppConfig.expo.plugins.push([\n SENTRY_EXPO_PLUGIN_NAME,\n {\n url: options.url,\n project: options.project,\n organization: options.org,\n },\n ]);\n\n return JSON.stringify(parsedAppConfig, null, 2) + EOL;\n } catch (error) {\n Sentry.setTag('app-config-file-status', 'invalid-json');\n clack.log.error(\n `Unable to parse your ${chalk.cyan(\n 'app.config.json',\n )}. Make sure it has a valid format!`,\n );\n Sentry.captureException(`Error to parsing 'app.config.json'`);\n return null;\n }\n}\n\nexport function getSentryAppConfigJsonCodeSnippet({\n url,\n project,\n org,\n}: Omit<RNCliSetupConfigContent, 'authToken'>) {\n return makeCodeSnippet(true, (unchanged, plus, _minus) => {\n return unchanged(`{\n \"name\": \"my app\",\n \"plugins\": [\n ${plus(`[\n \"@sentry/react-native/expo\",\n {\n \"url\": \"${url}\",\n \"project\": \"${project}\",\n \"organization\": \"${org}\"\n }\n ]`)}\n ],\n}`);\n });\n}\n\n/**\n * Checks whether the given value is a plain object (as opposed to something like a class instance or a primitive).\n * vendored from @sentry/utils to avoid registering the dependency.\n */\nfunction isPlainObject(what: unknown): boolean {\n return Object.prototype.toString.call(what) === '[object Object]';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"expo.js","sourceRoot":"","sources":["../../../src/react-native/expo.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,sDAAwC;AACxC,kDAA0B;AAC1B,uCAAyB;AACzB,2BAAyB;AAEzB,qDAAuC;AACvC,0CAA4E;AAE5E,4CAAyC;AACzC,+BAA4C;AAE/B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AAG,CAAC;YACjE,SAAS,CAAC,CAAC,CAAC,IAAA,yBAAmB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;YAC9D,aAAa,CAAC,CAAC,CAAC,IAAA,yBAAmB,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;SACvE,CAAC,CAAC;QAEH,OAAO,gBAAgB,IAAI,oBAAoB,CAAC;KACjD;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC;AArBW,QAAA,SAAS,aAqBpB","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as fs from 'fs';\nimport { EOL } from 'os';\n\nimport * as Sentry from '@sentry/node';\nimport { makeCodeSnippet, showCopyPasteInstructions } from '../utils/clack';\nimport { RNCliSetupConfigContent } from './react-native-wizard';\nimport { traceStep } from '../telemetry';\nimport { isFolderInGitignore } from './git';\n\nexport const SENTRY_EXPO_PLUGIN_NAME = '@sentry/react-native/expo';\nexport const DEPRECATED_SENTRY_EXPO_PLUGIN_NAME = 'sentry-expo';\n\nexport const SENTRY_PLUGIN_FUNCTION_NAME = 'withSentry';\n\nconst APP_CONFIG_JSON = `app.json`;\n\nexport interface AppConfigJson {\n expo?: {\n plugins?: Array<[string, undefined | Record<string, unknown>]>;\n };\n}\n\nexport function printSentryExpoMigrationOutro(): void {\n clack.outro(\n `Deprecated ${chalk.cyan(\n 'sentry-expo',\n )} package installed in your dependencies. Please follow the migration guide at ${chalk.cyan(\n 'https://docs.sentry.io/platforms/react-native/migration/sentry-expo/',\n )}`,\n );\n}\n\n/**\n * Finds app.json in the project root and add Sentry Expo `withSentry` plugin.\n */\nexport async function patchExpoAppConfig(options: RNCliSetupConfigContent) {\n function showInstructions() {\n return showCopyPasteInstructions({\n filename: APP_CONFIG_JSON,\n codeSnippet: getSentryAppConfigJsonCodeSnippet(options),\n hint: 'This ensures auto upload of source maps during native app build.',\n });\n }\n\n const appConfigJsonExists = fs.existsSync(APP_CONFIG_JSON);\n\n Sentry.setTag(\n 'app-config-file-status',\n appConfigJsonExists ? 'found' : 'not-found',\n );\n if (!appConfigJsonExists) {\n return await showInstructions();\n }\n\n const patched = await patchAppConfigJson(APP_CONFIG_JSON, options);\n if (!patched) {\n Sentry.setTag('app-config-file-status', 'patch-error');\n clack.log.error(`Unable to patch ${chalk.cyan('app.config.json')}.`);\n return await showInstructions();\n }\n}\n\nasync function patchAppConfigJson(\n path: string,\n options: RNCliSetupConfigContent,\n): Promise<boolean> {\n const appConfigContent = (\n await fs.promises.readFile(path, { encoding: 'utf-8' })\n ).toString();\n const patchedContent = traceStep('app-config-json-patch', () =>\n addWithSentryToAppConfigJson(appConfigContent, options),\n );\n if (patchedContent === null) {\n return false;\n }\n\n try {\n await fs.promises.writeFile(path, patchedContent);\n } catch (error) {\n Sentry.setTag('app-config-file-status', 'json-write-error');\n clack.log.error(`Unable to write ${chalk.cyan('app.config.json')}.`);\n Sentry.captureException(`Unable to write 'app.config.json'.`);\n return false;\n }\n Sentry.setTag('app-config-file-status', 'json-write-success');\n clack.log.success(\n `Added Sentry Expo plugin to ${chalk.cyan('app.config.json')}.`,\n );\n return true;\n}\n\nexport function addWithSentryToAppConfigJson(\n appConfigContent: string,\n options: RNCliSetupConfigContent,\n): string | null {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const parsedAppConfig: AppConfigJson = JSON.parse(appConfigContent);\n const includesWithSentry =\n appConfigContent.includes(SENTRY_EXPO_PLUGIN_NAME) ||\n appConfigContent.includes(DEPRECATED_SENTRY_EXPO_PLUGIN_NAME);\n\n if (includesWithSentry) {\n Sentry.setTag('app-config-file-status', 'already-patched');\n clack.log.warn(\n `Your ${chalk.cyan(\n 'app.config.json',\n )} already includes the Sentry Expo plugin.`,\n );\n return null;\n }\n\n if (\n parsedAppConfig.expo !== undefined &&\n !isPlainObject(parsedAppConfig.expo)\n ) {\n Sentry.setTag('app-config-file-status', 'invalid-json');\n clack.log.error(\n `Unable to find expo in your ${chalk.cyan(\n 'app.config.json',\n )}. Make sure it has a valid format!`,\n );\n return null;\n }\n if (\n parsedAppConfig.expo &&\n parsedAppConfig.expo.plugins !== undefined &&\n !Array.isArray(parsedAppConfig.expo.plugins)\n ) {\n Sentry.setTag('app-config-file-status', 'invalid-json');\n clack.log.error(\n `Unable to find expo plugins in your ${chalk.cyan(\n 'app.config.json',\n )}. Make sure it has a valid format!`,\n );\n return null;\n }\n\n parsedAppConfig.expo = parsedAppConfig.expo ?? {};\n parsedAppConfig.expo.plugins = parsedAppConfig.expo.plugins ?? [];\n parsedAppConfig.expo.plugins.push([\n SENTRY_EXPO_PLUGIN_NAME,\n {\n url: options.url,\n project: options.project,\n organization: options.org,\n },\n ]);\n\n return JSON.stringify(parsedAppConfig, null, 2) + EOL;\n } catch (error) {\n Sentry.setTag('app-config-file-status', 'invalid-json');\n clack.log.error(\n `Unable to parse your ${chalk.cyan(\n 'app.config.json',\n )}. Make sure it has a valid format!`,\n );\n Sentry.captureException(`Error to parsing 'app.config.json'`);\n return null;\n }\n}\n\nexport function getSentryAppConfigJsonCodeSnippet({\n url,\n project,\n org,\n}: Omit<RNCliSetupConfigContent, 'authToken'>) {\n return makeCodeSnippet(true, (unchanged, plus, _minus) => {\n return unchanged(`{\n \"name\": \"my app\",\n \"plugins\": [\n ${plus(`[\n \"@sentry/react-native/expo\",\n {\n \"url\": \"${url}\",\n \"project\": \"${project}\",\n \"organization\": \"${org}\"\n }\n ]`)}\n ],\n}`);\n });\n}\n\n/**\n * Checks whether the given value is a plain object (as opposed to something like a class instance or a primitive).\n * vendored from @sentry/utils to avoid registering the dependency.\n */\nfunction isPlainObject(what: unknown): boolean {\n return Object.prototype.toString.call(what) === '[object Object]';\n}\n\n/**\n * Checks if the project is using Expo's Config Plugins (CNG)\n * It checks by checking if the native folders are in gitignore or not\n * If native folders are in gitignore then we can skip the native properties file step\n */\nexport const isExpoCNG = async (): Promise<boolean> => {\n const iOSExists = fs.existsSync('ios');\n const androidExists = fs.existsSync('android');\n\n const anyNativeFolderExists = iOSExists || androidExists;\n\n if (!anyNativeFolderExists) {\n // Definitely CNG and using prebuild steps\n return true;\n }\n\n try {\n const [isIosInGitIgnore, isAndroidInGitIgnore] = await Promise.all([\n iOSExists ? isFolderInGitignore('ios') : Promise.resolve(true), // If the folder doesn't exist, we can consider it as ignored\n androidExists ? isFolderInGitignore('android') : Promise.resolve(true),\n ]);\n\n return isIosInGitIgnore && isAndroidInGitIgnore;\n } catch (error) {\n return false;\n }\n};\n"]}
|
|
@@ -1 +1,6 @@
|
|
|
1
1
|
export declare function addToGitignore(filepath: string): Promise<boolean>;
|
|
2
|
+
/**
|
|
3
|
+
* Checks if gitignore file contains ios and android folders
|
|
4
|
+
* Processes line by line, ignoring comments and checking for exact patterns
|
|
5
|
+
*/
|
|
6
|
+
export declare const isFolderInGitignore: (folder: string) => Promise<boolean>;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.addToGitignore = void 0;
|
|
26
|
+
exports.isFolderInGitignore = exports.addToGitignore = void 0;
|
|
27
27
|
const fs = __importStar(require("fs"));
|
|
28
28
|
const GITIGNORE_FILENAME = '.gitignore';
|
|
29
29
|
async function addToGitignore(filepath) {
|
|
@@ -49,4 +49,35 @@ async function addToGitignore(filepath) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
exports.addToGitignore = addToGitignore;
|
|
52
|
+
/**
|
|
53
|
+
* Checks if gitignore file contains ios and android folders
|
|
54
|
+
* Processes line by line, ignoring comments and checking for exact patterns
|
|
55
|
+
*/
|
|
56
|
+
const isFolderInGitignore = async (folder) => {
|
|
57
|
+
try {
|
|
58
|
+
const content = await fs.promises.readFile(GITIGNORE_FILENAME, {
|
|
59
|
+
encoding: 'utf-8',
|
|
60
|
+
});
|
|
61
|
+
// Split by lines and normalize line endings
|
|
62
|
+
const lines = content.replace(/\r\n/g, '\n').split('\n');
|
|
63
|
+
return lines.some((line) => {
|
|
64
|
+
const lineWithoutComment = line.split('#')[0].trim();
|
|
65
|
+
if (!lineWithoutComment || !lineWithoutComment.includes(folder)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const patterns = [
|
|
69
|
+
folder,
|
|
70
|
+
`${folder}/`,
|
|
71
|
+
`${folder}/*`,
|
|
72
|
+
`/${folder}`,
|
|
73
|
+
`/${folder}/`, // Folder with leading and trailing slash: /ios/
|
|
74
|
+
];
|
|
75
|
+
return patterns.includes(lineWithoutComment);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.isFolderInGitignore = isFolderInGitignore;
|
|
52
83
|
//# sourceMappingURL=git.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src/react-native/git.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AAEzB,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAEjC,KAAK,UAAU,cAAc,CAAC,QAAgB;IACnD;;;;;;;;;;;;OAYG;IACH,IAAI;QACF,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,kBAAkB,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AApBD,wCAoBC","sourcesContent":["import * as fs from 'fs';\n\nconst GITIGNORE_FILENAME = '.gitignore';\n\nexport async function addToGitignore(filepath: string): Promise<boolean> {\n /**\n * Don't check whether the given file is ignored because:\n * 1. It's tricky to check it without git.\n * 2. Git might not be installed or accessible.\n * 3. It's convenient to use a module to interact with git, but it would\n * increase the size x2 approximately. Docs say to run the Wizard without\n * installing it, and duplicating the size would slow the set-up down.\n * 4. The Wizard is meant to be run once.\n * 5. A message is logged informing users it's been added to the gitignore.\n * 6. It will be added to the gitignore as many times as it runs - not a big\n * deal.\n * 7. It's straightforward to remove it from the gitignore.\n */\n try {\n await fs.promises.appendFile(GITIGNORE_FILENAME, `\\n${filepath}\\n`);\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src/react-native/git.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AAEzB,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAEjC,KAAK,UAAU,cAAc,CAAC,QAAgB;IACnD;;;;;;;;;;;;OAYG;IACH,IAAI;QACF,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,kBAAkB,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AApBD,wCAoBC;AAED;;;GAGG;AACI,MAAM,mBAAmB,GAAG,KAAK,EAAE,MAAc,EAAoB,EAAE;IAC5E,IAAI;QACF,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,EAAE;YAC7D,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAC;QAEH,4CAA4C;QAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEzD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACzB,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAErD,IAAI,CAAC,kBAAkB,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;gBAC/D,OAAO,KAAK,CAAC;aACd;YAED,MAAM,QAAQ,GAAG;gBACf,MAAM;gBACN,GAAG,MAAM,GAAG;gBACZ,GAAG,MAAM,IAAI;gBACb,IAAI,MAAM,EAAE;gBACZ,IAAI,MAAM,GAAG,EAAE,gDAAgD;aAChE,CAAC;YAEF,OAAO,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;KACJ;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC;AA7BW,QAAA,mBAAmB,uBA6B9B","sourcesContent":["import * as fs from 'fs';\n\nconst GITIGNORE_FILENAME = '.gitignore';\n\nexport async function addToGitignore(filepath: string): Promise<boolean> {\n /**\n * Don't check whether the given file is ignored because:\n * 1. It's tricky to check it without git.\n * 2. Git might not be installed or accessible.\n * 3. It's convenient to use a module to interact with git, but it would\n * increase the size x2 approximately. Docs say to run the Wizard without\n * installing it, and duplicating the size would slow the set-up down.\n * 4. The Wizard is meant to be run once.\n * 5. A message is logged informing users it's been added to the gitignore.\n * 6. It will be added to the gitignore as many times as it runs - not a big\n * deal.\n * 7. It's straightforward to remove it from the gitignore.\n */\n try {\n await fs.promises.appendFile(GITIGNORE_FILENAME, `\\n${filepath}\\n`);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Checks if gitignore file contains ios and android folders\n * Processes line by line, ignoring comments and checking for exact patterns\n */\nexport const isFolderInGitignore = async (folder: string): Promise<boolean> => {\n try {\n const content = await fs.promises.readFile(GITIGNORE_FILENAME, {\n encoding: 'utf-8',\n });\n\n // Split by lines and normalize line endings\n const lines = content.replace(/\\r\\n/g, '\\n').split('\\n');\n\n return lines.some((line) => {\n const lineWithoutComment = line.split('#')[0].trim();\n\n if (!lineWithoutComment || !lineWithoutComment.includes(folder)) {\n return false;\n }\n\n const patterns = [\n folder, // Exact match: ios\n `${folder}/`, // Folder with trailing slash: ios/\n `${folder}/*`, // Folder with wildcard: ios/*\n `/${folder}`, // Folder with leading slash: /ios\n `/${folder}/`, // Folder with leading and trailing slash: /ios/\n ];\n\n return patterns.includes(lineWithoutComment);\n });\n } catch {\n return false;\n }\n};\n"]}
|
|
@@ -39,6 +39,7 @@ const telemetry_1 = require("../telemetry");
|
|
|
39
39
|
const clack_1 = require("../utils/clack");
|
|
40
40
|
const glob_1 = require("./glob");
|
|
41
41
|
const react_native_wizard_1 = require("./react-native-wizard");
|
|
42
|
+
const ast_utils_1 = require("../utils/ast-utils");
|
|
42
43
|
// @ts-expect-error - magicast is ESM and TS complains about that. It works though
|
|
43
44
|
const magicast_1 = require("magicast");
|
|
44
45
|
const t = __importStar(require("@babel/types"));
|
|
@@ -173,7 +174,8 @@ async function wrapRootComponent() {
|
|
|
173
174
|
}
|
|
174
175
|
(0, telemetry_1.traceStep)('add-sentry-wrap', () => {
|
|
175
176
|
try {
|
|
176
|
-
|
|
177
|
+
const code = (0, ast_utils_1.preserveTrailingNewline)(js, (0, magicast_1.generateCode)(mod.$ast).code);
|
|
178
|
+
fs.writeFileSync(jsPath, code, 'utf-8');
|
|
177
179
|
prompts_1.default.log.success(`Added ${chalk_1.default.cyan('Sentry.wrap')} to ${chalk_1.default.cyan(jsRelativePath)}.`);
|
|
178
180
|
}
|
|
179
181
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.js","sourceRoot":"","sources":["../../../src/react-native/javascript.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8BAA8B;AAC9B,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,2CAA6B;AAC7B,iDAAmC;AACnC,uCAAyB;AACzB,qDAAuC;AAEvC,4CAAyC;AACzC,0CAA4E;AAC5E,iCAA6C;AAC7C,+DAAuD;AA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C,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* eslint-disable max-lines */\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as path from 'path';\nimport * as process from 'process';\nimport * as fs from 'fs';\nimport * as Sentry from '@sentry/node';\n\nimport { traceStep } from '../telemetry';\nimport { makeCodeSnippet, showCopyPasteInstructions } from '../utils/clack';\nimport { getFirstMatchedPath } from './glob';\nimport { RN_SDK_PACKAGE } from './react-native-wizard';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode, ProxifiedModule, parseModule } from 'magicast';\nimport * as t from '@babel/types';\n\nexport const sessionReplaySampleRate = 0.1;\nexport const sessionReplayOnErrorSampleRate = 1.0;\n\nexport async function addSentryInit({\n dsn,\n enableSessionReplay = false,\n enableFeedbackWidget = false,\n enableLogs = false,\n}: {\n dsn: string;\n enableSessionReplay?: boolean;\n enableFeedbackWidget?: boolean;\n enableLogs?: boolean;\n}) {\n const jsPath = getMainAppFilePath();\n Sentry.setTag('app-js-file-status', jsPath ? 'found' : 'not-found');\n if (!jsPath) {\n clack.log.warn(\n `Could not find main App file. Place the following code snippet close to the Apps Root component.`,\n );\n Sentry.captureException('Could not find main App file.');\n await showCopyPasteInstructions({\n filename: 'App.js or _layout.tsx',\n codeSnippet: getSentryInitColoredCodeSnippet(\n dsn,\n enableSessionReplay,\n enableFeedbackWidget,\n enableLogs,\n ),\n hint: 'This ensures the Sentry SDK is ready to capture errors.',\n });\n return;\n }\n const jsRelativePath = path.relative(process.cwd(), jsPath);\n\n const js = fs.readFileSync(jsPath, 'utf-8');\n const includesSentry = doesJsCodeIncludeSdkSentryImport(js, {\n sdkPackageName: RN_SDK_PACKAGE,\n });\n if (includesSentry) {\n Sentry.setTag('app-js-file-status', 'already-includes-sentry');\n clack.log.warn(\n `${chalk.cyan(\n jsRelativePath,\n )} already includes Sentry. We wont't add it again.`,\n );\n return;\n }\n\n traceStep('add-sentry-init', () => {\n const newContent = addSentryInitWithSdkImport(js, {\n dsn,\n enableSessionReplay,\n enableFeedbackWidget,\n enableLogs,\n });\n\n try {\n fs.writeFileSync(jsPath, newContent, 'utf-8');\n clack.log.success(\n `Added ${chalk.cyan('Sentry.init')} to ${chalk.cyan(jsRelativePath)}.`,\n );\n } catch (error) {\n clack.log.error(`Error while writing ${jsPath}`);\n Sentry.captureException('Error while writing app.js');\n }\n });\n\n Sentry.setTag('app-js-file-status', 'added-sentry-init');\n clack.log.success(\n chalk.green(`${chalk.cyan(jsRelativePath)} changes saved.`),\n );\n}\n\nexport function addSentryInitWithSdkImport(\n js: string,\n {\n dsn,\n enableSessionReplay = false,\n enableFeedbackWidget = false,\n enableLogs = false,\n }: {\n dsn: string;\n enableSessionReplay?: boolean;\n enableFeedbackWidget?: boolean;\n enableLogs?: boolean;\n },\n): string {\n return js.replace(\n /^([^]*)(import\\s+[^;]*?;$)/m,\n (match: string) => `${match}\n${getSentryInitPlainTextSnippet(\n dsn,\n enableSessionReplay,\n enableFeedbackWidget,\n enableLogs,\n)}`,\n );\n}\n\nexport function doesJsCodeIncludeSdkSentryImport(\n js: string,\n { sdkPackageName }: { sdkPackageName: string },\n): boolean {\n return !!js.match(sdkPackageName);\n}\n\nexport function getSentryInitColoredCodeSnippet(\n dsn: string,\n enableSessionReplay = false,\n enableFeedbackWidget = false,\n enableLogs = false,\n) {\n return makeCodeSnippet(true, (_unchanged, plus, _minus) => {\n return plus(\n getSentryInitPlainTextSnippet(\n dsn,\n enableSessionReplay,\n enableFeedbackWidget,\n enableLogs,\n ),\n );\n });\n}\n\nexport function getSentryInitPlainTextSnippet(\n dsn: string,\n enableSessionReplay = false,\n enableFeedbackWidget = false,\n enableLogs = false,\n) {\n return `import * as Sentry from '@sentry/react-native';\n\nSentry.init({\n dsn: '${dsn}',\n\n // Adds more context data to events (IP address, cookies, user, etc.)\n // For more information, visit: https://docs.sentry.io/platforms/react-native/data-management/data-collected/\n sendDefaultPii: true,\n\n // Enable Logs\n enableLogs: ${enableLogs ? 'true' : 'false'},\n${\n enableSessionReplay\n ? `\n // Configure Session Replay\n replaysSessionSampleRate: ${sessionReplaySampleRate},\n replaysOnErrorSampleRate: ${sessionReplayOnErrorSampleRate},\n`\n : ''\n}${getSentryIntegrationsPlainTextSnippet(\n enableSessionReplay,\n enableFeedbackWidget,\n )}\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: __DEV__,\n});`;\n}\n\nexport function getSentryIntegrationsPlainTextSnippet(\n enableSessionReplay = false,\n enableFeedbackWidget = false,\n) {\n if (!enableSessionReplay && !enableFeedbackWidget) {\n return '';\n }\n return ` integrations: [${\n enableSessionReplay ? 'Sentry.mobileReplayIntegration()' : ''\n }${enableSessionReplay && enableFeedbackWidget ? ', ' : ''}${\n enableFeedbackWidget ? 'Sentry.feedbackIntegration()' : ''\n }],\n`;\n}\n\nfunction getMainAppFilePath(): string | undefined {\n const prefixGlob = '{.,./src,./app}';\n const suffixGlob = '@(j|t|cj|mj)s?(x)';\n const universalGlob = `@(App|_layout).${suffixGlob}`;\n const jsFileGlob = `${prefixGlob}/+(${universalGlob})`;\n const jsPath = traceStep('find-app-js-file', () =>\n getFirstMatchedPath(jsFileGlob),\n );\n return jsPath;\n}\n\n/**\n * This step should be executed after `addSentryInit`\n */\nexport async function wrapRootComponent() {\n const showInstructions = () =>\n showCopyPasteInstructions({\n filename: 'App.js or _layout.tsx',\n codeSnippet: getSentryWrapColoredCodeSnippet(),\n });\n\n const jsPath = getMainAppFilePath();\n Sentry.setTag('app-js-file-status', jsPath ? 'found' : 'not-found');\n if (!jsPath) {\n clack.log.warn(\n `Could not find main App file. Please wrap your App's Root component.`,\n );\n await showInstructions();\n return;\n }\n\n const jsRelativePath = path.relative(process.cwd(), jsPath);\n\n const js = fs.readFileSync(jsPath, 'utf-8');\n\n const mod = parseModule(js);\n const result = checkAndWrapRootComponent(mod);\n\n if (result === SentryWrapResult.AlreadyWrapped) {\n Sentry.setTag('app-js-file-status', 'already-includes-sentry-wrap');\n clack.log.warn(\n `${chalk.cyan(\n jsRelativePath,\n )} already includes Sentry.wrap. We wont't add it again.`,\n );\n return;\n }\n\n if (result === SentryWrapResult.NotFound) {\n clack.log.warn(\n `Could not find your App's Root component. Please wrap your App's Root component manually.`,\n );\n await showInstructions();\n return;\n }\n\n traceStep('add-sentry-wrap', () => {\n try {\n fs.writeFileSync(jsPath, generateCode(mod.$ast).code, 'utf-8');\n clack.log.success(\n `Added ${chalk.cyan('Sentry.wrap')} to ${chalk.cyan(jsRelativePath)}.`,\n );\n } catch (error) {\n clack.log.error(`Error while writing ${jsPath}`);\n Sentry.captureException('Error while writing app.js');\n return;\n }\n });\n\n Sentry.setTag('app-js-file-status', 'added-sentry-wrap');\n clack.log.success(\n chalk.green(`${chalk.cyan(jsRelativePath)} changes saved.`),\n );\n}\n\nexport enum SentryWrapResult {\n NotFound = 'RootComponentNotFound',\n AlreadyWrapped = 'AlreadyWrapped',\n Success = 'Success',\n}\n\nexport function checkAndWrapRootComponent(\n mod: ProxifiedModule,\n): SentryWrapResult {\n if (doesContainSentryWrap(mod.$ast as t.Program)) {\n return SentryWrapResult.AlreadyWrapped;\n }\n\n const defaultExport = getDefaultExport(mod.$ast as t.Program);\n if (!defaultExport) {\n return SentryWrapResult.NotFound;\n }\n\n const wrappedConfig = wrapWithSentry(defaultExport);\n\n const replacedDefaultExport = replaceDefaultExport(\n mod.$ast as t.Program,\n wrappedConfig,\n );\n\n if (!replacedDefaultExport) {\n return SentryWrapResult.NotFound;\n }\n\n return SentryWrapResult.Success;\n}\n\nexport function getDefaultExport(\n program: t.Program,\n):\n | t.Identifier\n | t.CallExpression\n | t.ObjectExpression\n | t.FunctionDeclaration\n | t.ArrowFunctionExpression\n | t.ClassDeclaration\n | undefined {\n for (const node of program.body) {\n if (\n t.isExportDefaultDeclaration(node) &&\n (t.isIdentifier(node.declaration) ||\n t.isCallExpression(node.declaration) ||\n t.isObjectExpression(node.declaration) ||\n t.isFunctionDeclaration(node.declaration) ||\n t.isArrowFunctionExpression(node.declaration) ||\n t.isClassDeclaration(node.declaration))\n ) {\n Sentry.setTag('app-js-file-status', 'default-export');\n return node.declaration;\n }\n }\n\n Sentry.setTag('app-js-file-status', 'default-export-not-found');\n return undefined;\n}\n\nexport function wrapWithSentry(\n configObj:\n | t.Identifier\n | t.CallExpression\n | t.ObjectExpression\n | t.FunctionDeclaration\n | t.ArrowFunctionExpression\n | t.ClassDeclaration,\n): t.CallExpression {\n if (t.isFunctionDeclaration(configObj)) {\n return t.callExpression(\n t.memberExpression(t.identifier('Sentry'), t.identifier('wrap')),\n [\n t.functionExpression(\n configObj.id,\n configObj.params,\n configObj.body,\n configObj.generator,\n configObj.async,\n ),\n ],\n );\n }\n\n if (t.isArrowFunctionExpression(configObj)) {\n return t.callExpression(\n t.memberExpression(t.identifier('Sentry'), t.identifier('wrap')),\n [configObj],\n );\n }\n\n if (t.isClassDeclaration(configObj)) {\n return t.callExpression(\n t.memberExpression(t.identifier('Sentry'), t.identifier('wrap')),\n [\n t.classExpression(\n configObj.id,\n configObj.superClass,\n configObj.body,\n configObj.decorators,\n ),\n ],\n );\n }\n\n return t.callExpression(\n t.memberExpression(t.identifier('Sentry'), t.identifier('wrap')),\n [configObj],\n );\n}\n\nexport function replaceDefaultExport(\n program: t.Program,\n wrappedDefaultExport: t.CallExpression,\n): boolean {\n for (const node of program.body) {\n if (t.isExportDefaultDeclaration(node)) {\n node.declaration = wrappedDefaultExport;\n return true;\n }\n }\n return false;\n}\n\nexport function doesContainSentryWrap(program: t.Program): boolean {\n for (const node of program.body) {\n if (t.isExportDefaultDeclaration(node)) {\n const declaration = node.declaration;\n if (t.isCallExpression(declaration)) {\n const callExpr = declaration;\n if (t.isMemberExpression(callExpr.callee)) {\n const callee = callExpr.callee;\n if (\n t.isIdentifier(callee.object) &&\n callee.object.name === 'Sentry' &&\n t.isIdentifier(callee.property) &&\n callee.property.name === 'wrap'\n ) {\n return true;\n }\n }\n }\n }\n }\n return false;\n}\n\nfunction getSentryWrapColoredCodeSnippet() {\n return makeCodeSnippet(true, (_unchanged, plus, _minus) => {\n return plus(`import * as Sentry from '@sentry/react-native';\n\nexport default Sentry.wrap(App);`);\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"javascript.js","sourceRoot":"","sources":["../../../src/react-native/javascript.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8BAA8B;AAC9B,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,2CAA6B;AAC7B,iDAAmC;AACnC,uCAAyB;AACzB,qDAAuC;AAEvC,4CAAyC;AACzC,0CAA4E;AAC5E,iCAA6C;AAC7C,+DAAuD;AACvD,kDAA6D;AAE7D,kFAAkF;AAClF,uCAAsE;AACtE,gDAAkC;AAErB,QAAA,uBAAuB,GAAG,GAAG,CAAC;AAC9B,QAAA,8BAA8B,GAAG,GAAG,CAAC;AAE3C,KAAK,UAAU,aAAa,CAAC,EAClC,GAAG,EACH,mBAAmB,GAAG,KAAK,EAC3B,oBAAoB,GAAG,KAAK,EAC5B,UAAU,GAAG,KAAK,GAMnB;IACC,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;IACpC,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACpE,IAAI,CAAC,MAAM,EAAE;QACX,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,kGAAkG,CACnG,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,+BAA+B,CAAC,CAAC;QACzD,MAAM,IAAA,iCAAyB,EAAC;YAC9B,QAAQ,EAAE,uBAAuB;YACjC,WAAW,EAAE,+BAA+B,CAC1C,GAAG,EACH,mBAAmB,EACnB,oBAAoB,EACpB,UAAU,CACX;YACD,IAAI,EAAE,yDAAyD;SAChE,CAAC,CAAC;QACH,OAAO;KACR;IACD,MAAM,cAA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oBACzC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;oBAC/B,IACE,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC;wBAC7B,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ;wBAC/B,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC;wBAC/B,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,EAC/B;wBACA,OAAO,IAAI,CAAC;qBACb;iBACF;aACF;SACF;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AArBD,sDAqBC;AAED,SAAS,+BAA+B;IACtC,OAAO,IAAA,uBAAe,EAAC,IAAI,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;QACxD,OAAO,IAAI,CAAC;;iCAEiB,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* eslint-disable max-lines */\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as path from 'path';\nimport * as process from 'process';\nimport * as fs from 'fs';\nimport * as Sentry from '@sentry/node';\n\nimport { traceStep } from '../telemetry';\nimport { makeCodeSnippet, showCopyPasteInstructions } from '../utils/clack';\nimport { getFirstMatchedPath } from './glob';\nimport { RN_SDK_PACKAGE } from './react-native-wizard';\nimport { preserveTrailingNewline } from '../utils/ast-utils';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode, ProxifiedModule, parseModule } from 'magicast';\nimport * as t from '@babel/types';\n\nexport const sessionReplaySampleRate = 0.1;\nexport const sessionReplayOnErrorSampleRate = 1.0;\n\nexport async function addSentryInit({\n dsn,\n enableSessionReplay = false,\n enableFeedbackWidget = false,\n enableLogs = false,\n}: {\n dsn: string;\n enableSessionReplay?: boolean;\n enableFeedbackWidget?: boolean;\n enableLogs?: boolean;\n}) {\n const jsPath = getMainAppFilePath();\n Sentry.setTag('app-js-file-status', jsPath ? 'found' : 'not-found');\n if (!jsPath) {\n clack.log.warn(\n `Could not find main App file. Place the following code snippet close to the Apps Root component.`,\n );\n Sentry.captureException('Could not find main App file.');\n await showCopyPasteInstructions({\n filename: 'App.js or _layout.tsx',\n codeSnippet: getSentryInitColoredCodeSnippet(\n dsn,\n enableSessionReplay,\n enableFeedbackWidget,\n enableLogs,\n ),\n hint: 'This ensures the Sentry SDK is ready to capture errors.',\n });\n return;\n }\n const jsRelativePath = path.relative(process.cwd(), jsPath);\n\n const js = fs.readFileSync(jsPath, 'utf-8');\n const includesSentry = doesJsCodeIncludeSdkSentryImport(js, {\n sdkPackageName: RN_SDK_PACKAGE,\n });\n if (includesSentry) {\n Sentry.setTag('app-js-file-status', 'already-includes-sentry');\n clack.log.warn(\n `${chalk.cyan(\n jsRelativePath,\n )} already includes Sentry. We wont't add it again.`,\n );\n return;\n }\n\n traceStep('add-sentry-init', () => {\n const newContent = addSentryInitWithSdkImport(js, {\n dsn,\n enableSessionReplay,\n enableFeedbackWidget,\n enableLogs,\n });\n\n try {\n fs.writeFileSync(jsPath, newContent, 'utf-8');\n clack.log.success(\n `Added ${chalk.cyan('Sentry.init')} to ${chalk.cyan(jsRelativePath)}.`,\n );\n } catch (error) {\n clack.log.error(`Error while writing ${jsPath}`);\n Sentry.captureException('Error while writing app.js');\n }\n });\n\n Sentry.setTag('app-js-file-status', 'added-sentry-init');\n clack.log.success(\n chalk.green(`${chalk.cyan(jsRelativePath)} changes saved.`),\n );\n}\n\nexport function addSentryInitWithSdkImport(\n js: string,\n {\n dsn,\n enableSessionReplay = false,\n enableFeedbackWidget = false,\n enableLogs = false,\n }: {\n dsn: string;\n enableSessionReplay?: boolean;\n enableFeedbackWidget?: boolean;\n enableLogs?: boolean;\n },\n): string {\n return js.replace(\n /^([^]*)(import\\s+[^;]*?;$)/m,\n (match: string) => `${match}\n${getSentryInitPlainTextSnippet(\n dsn,\n enableSessionReplay,\n enableFeedbackWidget,\n enableLogs,\n)}`,\n );\n}\n\nexport function doesJsCodeIncludeSdkSentryImport(\n js: string,\n { sdkPackageName }: { sdkPackageName: string },\n): boolean {\n return !!js.match(sdkPackageName);\n}\n\nexport function getSentryInitColoredCodeSnippet(\n dsn: string,\n enableSessionReplay = false,\n enableFeedbackWidget = false,\n enableLogs = false,\n) {\n return makeCodeSnippet(true, (_unchanged, plus, _minus) => {\n return plus(\n getSentryInitPlainTextSnippet(\n dsn,\n enableSessionReplay,\n enableFeedbackWidget,\n enableLogs,\n ),\n );\n });\n}\n\nexport function getSentryInitPlainTextSnippet(\n dsn: string,\n enableSessionReplay = false,\n enableFeedbackWidget = false,\n enableLogs = false,\n) {\n return `import * as Sentry from '@sentry/react-native';\n\nSentry.init({\n dsn: '${dsn}',\n\n // Adds more context data to events (IP address, cookies, user, etc.)\n // For more information, visit: https://docs.sentry.io/platforms/react-native/data-management/data-collected/\n sendDefaultPii: true,\n\n // Enable Logs\n enableLogs: ${enableLogs ? 'true' : 'false'},\n${\n enableSessionReplay\n ? `\n // Configure Session Replay\n replaysSessionSampleRate: ${sessionReplaySampleRate},\n replaysOnErrorSampleRate: ${sessionReplayOnErrorSampleRate},\n`\n : ''\n}${getSentryIntegrationsPlainTextSnippet(\n enableSessionReplay,\n enableFeedbackWidget,\n )}\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: __DEV__,\n});`;\n}\n\nexport function getSentryIntegrationsPlainTextSnippet(\n enableSessionReplay = false,\n enableFeedbackWidget = false,\n) {\n if (!enableSessionReplay && !enableFeedbackWidget) {\n return '';\n }\n return ` integrations: [${\n enableSessionReplay ? 'Sentry.mobileReplayIntegration()' : ''\n }${enableSessionReplay && enableFeedbackWidget ? ', ' : ''}${\n enableFeedbackWidget ? 'Sentry.feedbackIntegration()' : ''\n }],\n`;\n}\n\nfunction getMainAppFilePath(): string | undefined {\n const prefixGlob = '{.,./src,./app}';\n const suffixGlob = '@(j|t|cj|mj)s?(x)';\n const universalGlob = `@(App|_layout).${suffixGlob}`;\n const jsFileGlob = `${prefixGlob}/+(${universalGlob})`;\n const jsPath = traceStep('find-app-js-file', () =>\n getFirstMatchedPath(jsFileGlob),\n );\n return jsPath;\n}\n\n/**\n * This step should be executed after `addSentryInit`\n */\nexport async function wrapRootComponent() {\n const showInstructions = () =>\n showCopyPasteInstructions({\n filename: 'App.js or _layout.tsx',\n codeSnippet: getSentryWrapColoredCodeSnippet(),\n });\n\n const jsPath = getMainAppFilePath();\n Sentry.setTag('app-js-file-status', jsPath ? 'found' : 'not-found');\n if (!jsPath) {\n clack.log.warn(\n `Could not find main App file. Please wrap your App's Root component.`,\n );\n await showInstructions();\n return;\n }\n\n const jsRelativePath = path.relative(process.cwd(), jsPath);\n\n const js = fs.readFileSync(jsPath, 'utf-8');\n\n const mod = parseModule(js);\n const result = checkAndWrapRootComponent(mod);\n\n if (result === SentryWrapResult.AlreadyWrapped) {\n Sentry.setTag('app-js-file-status', 'already-includes-sentry-wrap');\n clack.log.warn(\n `${chalk.cyan(\n jsRelativePath,\n )} already includes Sentry.wrap. We wont't add it again.`,\n );\n return;\n }\n\n if (result === SentryWrapResult.NotFound) {\n clack.log.warn(\n `Could not find your App's Root component. Please wrap your App's Root component manually.`,\n );\n await showInstructions();\n return;\n }\n\n traceStep('add-sentry-wrap', () => {\n try {\n const code = preserveTrailingNewline(js, generateCode(mod.$ast).code);\n fs.writeFileSync(jsPath, code, 'utf-8');\n clack.log.success(\n `Added ${chalk.cyan('Sentry.wrap')} to ${chalk.cyan(jsRelativePath)}.`,\n );\n } catch (error) {\n clack.log.error(`Error while writing ${jsPath}`);\n Sentry.captureException('Error while writing app.js');\n return;\n }\n });\n\n Sentry.setTag('app-js-file-status', 'added-sentry-wrap');\n clack.log.success(\n chalk.green(`${chalk.cyan(jsRelativePath)} changes saved.`),\n );\n}\n\nexport enum SentryWrapResult {\n NotFound = 'RootComponentNotFound',\n AlreadyWrapped = 'AlreadyWrapped',\n Success = 'Success',\n}\n\nexport function checkAndWrapRootComponent(\n mod: ProxifiedModule,\n): SentryWrapResult {\n if (doesContainSentryWrap(mod.$ast as t.Program)) {\n return SentryWrapResult.AlreadyWrapped;\n }\n\n const defaultExport = getDefaultExport(mod.$ast as t.Program);\n if (!defaultExport) {\n return SentryWrapResult.NotFound;\n }\n\n const wrappedConfig = wrapWithSentry(defaultExport);\n\n const replacedDefaultExport = replaceDefaultExport(\n mod.$ast as t.Program,\n wrappedConfig,\n );\n\n if (!replacedDefaultExport) {\n return SentryWrapResult.NotFound;\n }\n\n return SentryWrapResult.Success;\n}\n\nexport function getDefaultExport(\n program: t.Program,\n):\n | t.Identifier\n | t.CallExpression\n | t.ObjectExpression\n | t.FunctionDeclaration\n | t.ArrowFunctionExpression\n | t.ClassDeclaration\n | undefined {\n for (const node of program.body) {\n if (\n t.isExportDefaultDeclaration(node) &&\n (t.isIdentifier(node.declaration) ||\n t.isCallExpression(node.declaration) ||\n t.isObjectExpression(node.declaration) ||\n t.isFunctionDeclaration(node.declaration) ||\n t.isArrowFunctionExpression(node.declaration) ||\n t.isClassDeclaration(node.declaration))\n ) {\n Sentry.setTag('app-js-file-status', 'default-export');\n return node.declaration;\n }\n }\n\n Sentry.setTag('app-js-file-status', 'default-export-not-found');\n return undefined;\n}\n\nexport function wrapWithSentry(\n configObj:\n | t.Identifier\n | t.CallExpression\n | t.ObjectExpression\n | t.FunctionDeclaration\n | t.ArrowFunctionExpression\n | t.ClassDeclaration,\n): t.CallExpression {\n if (t.isFunctionDeclaration(configObj)) {\n return t.callExpression(\n t.memberExpression(t.identifier('Sentry'), t.identifier('wrap')),\n [\n t.functionExpression(\n configObj.id,\n configObj.params,\n configObj.body,\n configObj.generator,\n configObj.async,\n ),\n ],\n );\n }\n\n if (t.isArrowFunctionExpression(configObj)) {\n return t.callExpression(\n t.memberExpression(t.identifier('Sentry'), t.identifier('wrap')),\n [configObj],\n );\n }\n\n if (t.isClassDeclaration(configObj)) {\n return t.callExpression(\n t.memberExpression(t.identifier('Sentry'), t.identifier('wrap')),\n [\n t.classExpression(\n configObj.id,\n configObj.superClass,\n configObj.body,\n configObj.decorators,\n ),\n ],\n );\n }\n\n return t.callExpression(\n t.memberExpression(t.identifier('Sentry'), t.identifier('wrap')),\n [configObj],\n );\n}\n\nexport function replaceDefaultExport(\n program: t.Program,\n wrappedDefaultExport: t.CallExpression,\n): boolean {\n for (const node of program.body) {\n if (t.isExportDefaultDeclaration(node)) {\n node.declaration = wrappedDefaultExport;\n return true;\n }\n }\n return false;\n}\n\nexport function doesContainSentryWrap(program: t.Program): boolean {\n for (const node of program.body) {\n if (t.isExportDefaultDeclaration(node)) {\n const declaration = node.declaration;\n if (t.isCallExpression(declaration)) {\n const callExpr = declaration;\n if (t.isMemberExpression(callExpr.callee)) {\n const callee = callExpr.callee;\n if (\n t.isIdentifier(callee.object) &&\n callee.object.name === 'Sentry' &&\n t.isIdentifier(callee.property) &&\n callee.property.name === 'wrap'\n ) {\n return true;\n }\n }\n }\n }\n }\n return false;\n}\n\nfunction getSentryWrapColoredCodeSnippet() {\n return makeCodeSnippet(true, (_unchanged, plus, _minus) => {\n return plus(`import * as Sentry from '@sentry/react-native';\n\nexport default Sentry.wrap(App);`);\n });\n}\n"]}
|
|
@@ -185,13 +185,19 @@ Or setup using ${chalk_1.default.cyan('https://docs.sentry.io/platforms/react-na
|
|
|
185
185
|
else {
|
|
186
186
|
await (0, telemetry_1.traceStep)('patch-metro-config', metro_1.patchMetroWithSentryConfig);
|
|
187
187
|
}
|
|
188
|
-
if (
|
|
189
|
-
Sentry.setTag('
|
|
190
|
-
|
|
188
|
+
if (isExpo && (await (0, expo_1.isExpoCNG)())) {
|
|
189
|
+
Sentry.setTag('expo-cng', true);
|
|
190
|
+
prompts_1.default.log.info(`Detected Expo Continuous Native Generation (CNG) setup. Skipping native files patching.`);
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
192
|
+
else {
|
|
193
|
+
if (fs.existsSync('ios')) {
|
|
194
|
+
Sentry.setTag('patch-ios', true);
|
|
195
|
+
await (0, telemetry_1.traceStep)('patch-xcode-files', () => patchXcodeFiles(cliConfig));
|
|
196
|
+
}
|
|
197
|
+
if (fs.existsSync('android')) {
|
|
198
|
+
Sentry.setTag('patch-android', true);
|
|
199
|
+
await (0, telemetry_1.traceStep)('patch-android-files', () => patchAndroidFiles(cliConfig));
|
|
200
|
+
}
|
|
195
201
|
}
|
|
196
202
|
await (0, clack_1.runPrettierIfInstalled)({ cwd: undefined });
|
|
197
203
|
// Offer optional project-scoped MCP config for Sentry with org and project scope
|