@sentry/wizard 4.8.0 → 5.0.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 +20 -0
- package/dist/e2e-tests/tests/angular-17.test.js +41 -41
- package/dist/e2e-tests/tests/angular-17.test.js.map +1 -1
- package/dist/e2e-tests/tests/angular-19.test.js +39 -39
- package/dist/e2e-tests/tests/angular-19.test.js.map +1 -1
- package/dist/e2e-tests/tests/expo.test.js +10 -2
- package/dist/e2e-tests/tests/expo.test.js.map +1 -1
- package/dist/e2e-tests/tests/react-native.test.js +38 -3
- package/dist/e2e-tests/tests/react-native.test.js.map +1 -1
- package/dist/e2e-tests/utils/index.js +14 -6
- package/dist/e2e-tests/utils/index.js.map +1 -1
- package/dist/lib/Helper/SentryCli.d.ts +0 -11
- package/dist/lib/Helper/SentryCli.js +0 -52
- package/dist/lib/Helper/SentryCli.js.map +1 -1
- package/dist/lib/Steps/Integrations/Cordova.js +13 -30
- package/dist/lib/Steps/Integrations/Cordova.js.map +1 -1
- package/dist/src/android/templates.js +2 -0
- package/dist/src/android/templates.js.map +1 -1
- package/dist/src/angular/angular-wizard.js +1 -1
- package/dist/src/angular/angular-wizard.js.map +1 -1
- package/dist/src/angular/sdk-setup.d.ts +1 -1
- package/dist/src/angular/sdk-setup.js +3 -3
- package/dist/src/angular/sdk-setup.js.map +1 -1
- package/dist/src/apple/code-tools.d.ts +4 -2
- package/dist/src/apple/code-tools.js +21 -11
- package/dist/src/apple/code-tools.js.map +1 -1
- package/dist/src/apple/inject-code-snippet.js +5 -3
- package/dist/src/apple/inject-code-snippet.js.map +1 -1
- package/dist/src/apple/macos-system-helper.d.ts +5 -0
- package/dist/src/apple/macos-system-helper.js +86 -0
- package/dist/src/apple/macos-system-helper.js.map +1 -0
- package/dist/src/apple/templates.js +10 -0
- package/dist/src/apple/templates.js.map +1 -1
- package/dist/src/apple/xcode-manager.d.ts +237 -11
- package/dist/src/apple/xcode-manager.js +736 -65
- package/dist/src/apple/xcode-manager.js.map +1 -1
- package/dist/src/apple/xcode-project-object-with-id.d.ts +5 -0
- package/dist/src/apple/xcode-project-object-with-id.js +3 -0
- package/dist/src/apple/xcode-project-object-with-id.js.map +1 -0
- package/dist/src/flutter/templates.js +7 -1
- package/dist/src/flutter/templates.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +1 -3
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nuxt/nuxt-wizard.js +1 -3
- package/dist/src/nuxt/nuxt-wizard.js.map +1 -1
- package/dist/src/react-native/expo-env-file.js +5 -0
- package/dist/src/react-native/expo-env-file.js.map +1 -1
- package/dist/src/react-native/expo-metro.js +18 -5
- package/dist/src/react-native/expo-metro.js.map +1 -1
- package/dist/src/react-native/expo.js +6 -0
- package/dist/src/react-native/expo.js.map +1 -1
- package/dist/src/react-native/glob.js +14 -4
- package/dist/src/react-native/glob.js.map +1 -1
- package/dist/src/react-native/gradle.d.ts +0 -1
- package/dist/src/react-native/gradle.js +15 -9
- package/dist/src/react-native/gradle.js.map +1 -1
- package/dist/src/react-native/javascript.d.ts +9 -4
- package/dist/src/react-native/javascript.js +44 -22
- package/dist/src/react-native/javascript.js.map +1 -1
- package/dist/src/react-native/metro.d.ts +1 -5
- package/dist/src/react-native/metro.js +18 -120
- package/dist/src/react-native/metro.js.map +1 -1
- package/dist/src/react-native/options.d.ts +1 -3
- package/dist/src/react-native/options.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.d.ts +1 -19
- package/dist/src/react-native/react-native-wizard.js +27 -101
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/react-native/xcode.d.ts +0 -7
- package/dist/src/react-native/xcode.js +15 -108
- package/dist/src/react-native/xcode.js.map +1 -1
- package/dist/src/remix/remix-wizard.js +1 -3
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/run.js +1 -4
- package/dist/src/run.js.map +1 -1
- package/dist/src/sourcemaps/utils/sdk-version.js +3 -0
- package/dist/src/sourcemaps/utils/sdk-version.js.map +1 -1
- package/dist/src/sveltekit/sveltekit-wizard.js +1 -3
- package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +0 -7
- package/dist/src/utils/ast-utils.js +1 -27
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/clack/index.d.ts +2 -12
- package/dist/src/utils/clack/index.js +8 -47
- package/dist/src/utils/clack/index.js.map +1 -1
- package/dist/src/utils/git.d.ts +11 -0
- package/dist/src/utils/git.js +69 -0
- package/dist/src/utils/git.js.map +1 -0
- package/dist/src/utils/sentrycli-utils.js +13 -4
- package/dist/src/utils/sentrycli-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 +54 -35
- package/dist/test/apple/code-tools.test.js.map +1 -1
- package/dist/test/apple/configure-sentry-cli.test.d.ts +1 -0
- package/dist/test/apple/configure-sentry-cli.test.js +131 -0
- package/dist/test/apple/configure-sentry-cli.test.js.map +1 -0
- package/dist/test/apple/macos-system-helper-mocked.test.d.ts +1 -0
- package/dist/test/apple/macos-system-helper-mocked.test.js +46 -0
- package/dist/test/apple/macos-system-helper-mocked.test.js.map +1 -0
- package/dist/test/apple/macos-system-helper.test.d.ts +1 -0
- package/dist/test/apple/macos-system-helper.test.js +88 -0
- package/dist/test/apple/macos-system-helper.test.js.map +1 -0
- package/dist/test/apple/templates.test.js +10 -0
- package/dist/test/apple/templates.test.js.map +1 -1
- package/dist/test/apple/xcode-manager.test.js +745 -379
- package/dist/test/apple/xcode-manager.test.js.map +1 -1
- package/dist/test/flutter/templates.test.js +9 -0
- package/dist/test/flutter/templates.test.js.map +1 -1
- package/dist/test/react-native/gradle.test.js +0 -119
- package/dist/test/react-native/gradle.test.js.map +1 -1
- package/dist/test/react-native/javascript.test.js +119 -0
- package/dist/test/react-native/javascript.test.js.map +1 -1
- package/dist/test/react-native/metro.test.js +0 -90
- package/dist/test/react-native/metro.test.js.map +1 -1
- package/dist/test/react-native/xcode.test.js +0 -81
- package/dist/test/react-native/xcode.test.js.map +1 -1
- package/dist/test/utils/git.test.d.ts +1 -0
- package/dist/test/utils/git.test.js +70 -0
- package/dist/test/utils/git.test.js.map +1 -0
- package/package.json +1 -1
- package/dist/src/react-native/uninstall.d.ts +0 -2
- package/dist/src/react-native/uninstall.js +0 -94
- package/dist/src/react-native/uninstall.js.map +0 -1
|
@@ -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,yCAA8C;AAC9C,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,UAAU,CAAC,eAAe,CAAC,CAA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EL,CAAC,CAAC;IACF,CAAC,CAAC,CAAC;AACL,CAAC;AApBD,8EAoBC","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 { isPlainObject } from '@sentry/utils';\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"]}
|
|
@@ -25,14 +25,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.getFirstMatchedPath = exports.APP_BUILD_GRADLE = exports.XCODE_PROJECT = void 0;
|
|
27
27
|
const glob = __importStar(require("glob"));
|
|
28
|
+
// @ts-expect-error - clack is ESM and TS complains about that. It works though
|
|
29
|
+
const clack = __importStar(require("@clack/prompts"));
|
|
30
|
+
const Sentry = __importStar(require("@sentry/node"));
|
|
28
31
|
exports.XCODE_PROJECT = 'ios/*.xcodeproj/project.pbxproj';
|
|
29
32
|
exports.APP_BUILD_GRADLE = '**/app/build.gradle';
|
|
30
33
|
const IGNORE_PATTERNS = ['node_modules/**', 'ios/Pods/**', '**/Pods/**'];
|
|
31
34
|
function getFirstMatchedPath(pattern) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
try {
|
|
36
|
+
const matches = glob.sync(pattern, {
|
|
37
|
+
ignore: IGNORE_PATTERNS,
|
|
38
|
+
});
|
|
39
|
+
return matches[0];
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
clack.log.error(`Error while matching path pattern "${pattern}"`);
|
|
43
|
+
Sentry.captureException(`Error while matching path pattern "${pattern}"`);
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
36
46
|
}
|
|
37
47
|
exports.getFirstMatchedPath = getFirstMatchedPath;
|
|
38
48
|
//# sourceMappingURL=glob.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/react-native/glob.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/react-native/glob.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+EAA+E;AAC/E,sDAAwC;AACxC,qDAAuC;AAE1B,QAAA,aAAa,GAAG,iCAAiC,CAAC;AAClD,QAAA,gBAAgB,GAAG,qBAAqB,CAAC;AAEtD,MAAM,eAAe,GAAG,CAAC,iBAAiB,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;AACzE,SAAgB,mBAAmB,CAAC,OAAe;IACjD,IAAI;QACF,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjC,MAAM,EAAE,eAAe;SACxB,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;KACnB;IAAC,OAAO,KAAK,EAAE;QACd,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,sCAAsC,OAAO,GAAG,CAAC,CAAC;QAClE,MAAM,CAAC,gBAAgB,CAAC,sCAAsC,OAAO,GAAG,CAAC,CAAC;QAC1E,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAZD,kDAYC","sourcesContent":["import * as glob from 'glob';\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport * as Sentry from '@sentry/node';\n\nexport const XCODE_PROJECT = 'ios/*.xcodeproj/project.pbxproj';\nexport const APP_BUILD_GRADLE = '**/app/build.gradle';\n\nconst IGNORE_PATTERNS = ['node_modules/**', 'ios/Pods/**', '**/Pods/**'];\nexport function getFirstMatchedPath(pattern: string): string | undefined {\n try {\n const matches = glob.sync(pattern, {\n ignore: IGNORE_PATTERNS,\n });\n\n return matches[0];\n } catch (error) {\n clack.log.error(`Error while matching path pattern \"${pattern}\"`);\n Sentry.captureException(`Error while matching path pattern \"${pattern}\"`);\n return undefined;\n }\n}\n"]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export declare function doesAppBuildGradleIncludeRNSentryGradlePlugin(content: string): boolean;
|
|
2
2
|
export declare function addRNSentryGradlePlugin(content: string): string;
|
|
3
|
-
export declare function removeRNSentryGradlePlugin(content: string): string;
|
|
4
3
|
export declare function writeAppBuildGradle(path: string, newContent: string): void;
|
|
@@ -23,8 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.writeAppBuildGradle = exports.
|
|
26
|
+
exports.writeAppBuildGradle = exports.addRNSentryGradlePlugin = exports.doesAppBuildGradleIncludeRNSentryGradlePlugin = void 0;
|
|
27
27
|
const fs = __importStar(require("fs"));
|
|
28
|
+
// @ts-expect-error - clack is ESM and TS complains about that. It works though
|
|
29
|
+
const clack = __importStar(require("@clack/prompts"));
|
|
30
|
+
const Sentry = __importStar(require("@sentry/node"));
|
|
28
31
|
const applyFrom = `apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle")`;
|
|
29
32
|
function doesAppBuildGradleIncludeRNSentryGradlePlugin(content) {
|
|
30
33
|
return content.includes('sentry.gradle');
|
|
@@ -34,16 +37,19 @@ function addRNSentryGradlePlugin(content) {
|
|
|
34
37
|
return content.replace(/^android {/m, (match) => `${applyFrom}\n${match}`);
|
|
35
38
|
}
|
|
36
39
|
exports.addRNSentryGradlePlugin = addRNSentryGradlePlugin;
|
|
37
|
-
function removeRNSentryGradlePlugin(content) {
|
|
38
|
-
return content.replace(/^\s*apply from:.*sentry\.gradle.*;?\s*?\r?\n/m, '');
|
|
39
|
-
}
|
|
40
|
-
exports.removeRNSentryGradlePlugin = removeRNSentryGradlePlugin;
|
|
41
40
|
function writeAppBuildGradle(path, newContent) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
try {
|
|
42
|
+
const currentContent = fs.readFileSync(path, 'utf-8');
|
|
43
|
+
if (newContent === currentContent) {
|
|
44
|
+
clack.log.info(`No changes to ${path}.`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
fs.writeFileSync(path, newContent, 'utf-8');
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
clack.log.error(`Error while writing ${path}`);
|
|
51
|
+
Sentry.captureException('Error while writing app/build.gradle');
|
|
45
52
|
}
|
|
46
|
-
fs.writeFileSync(path, newContent, 'utf-8');
|
|
47
53
|
}
|
|
48
54
|
exports.writeAppBuildGradle = writeAppBuildGradle;
|
|
49
55
|
//# sourceMappingURL=gradle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradle.js","sourceRoot":"","sources":["../../../src/react-native/gradle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;
|
|
1
|
+
{"version":3,"file":"gradle.js","sourceRoot":"","sources":["../../../src/react-native/gradle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,+EAA+E;AAC/E,sDAAwC;AACxC,qDAAuC;AAEvC,MAAM,SAAS,GAAG,6IAA6I,CAAC;AAEhK,SAAgB,6CAA6C,CAC3D,OAAe;IAEf,OAAO,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;AAC3C,CAAC;AAJD,sGAIC;AAED,SAAgB,uBAAuB,CAAC,OAAe;IACrD,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,SAAS,KAAK,KAAK,EAAE,CAAC,CAAC;AAC7E,CAAC;AAFD,0DAEC;AAED,SAAgB,mBAAmB,CAAC,IAAY,EAAE,UAAkB;IAClE,IAAI;QACF,MAAM,cAAc,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACtD,IAAI,UAAU,KAAK,cAAc,EAAE;YACjC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,IAAI,GAAG,CAAC,CAAC;YACzC,OAAO;SACR;QAED,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;KAC7C;IAAC,OAAO,KAAK,EAAE;QACd,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;QAC/C,MAAM,CAAC,gBAAgB,CAAC,sCAAsC,CAAC,CAAC;KACjE;AACH,CAAC;AAbD,kDAaC","sourcesContent":["import * as fs from 'fs';\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport * as Sentry from '@sentry/node';\n\nconst applyFrom = `apply from: new File([\"node\", \"--print\", \"require.resolve('@sentry/react-native/package.json')\"].execute().text.trim(), \"../sentry.gradle\")`;\n\nexport function doesAppBuildGradleIncludeRNSentryGradlePlugin(\n content: string,\n): boolean {\n return content.includes('sentry.gradle');\n}\n\nexport function addRNSentryGradlePlugin(content: string): string {\n return content.replace(/^android {/m, (match) => `${applyFrom}\\n${match}`);\n}\n\nexport function writeAppBuildGradle(path: string, newContent: string): void {\n try {\n const currentContent = fs.readFileSync(path, 'utf-8');\n if (newContent === currentContent) {\n clack.log.info(`No changes to ${path}.`);\n return;\n }\n\n fs.writeFileSync(path, newContent, 'utf-8');\n } catch (error) {\n clack.log.error(`Error while writing ${path}`);\n Sentry.captureException('Error while writing app/build.gradle');\n }\n}\n"]}
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { ProxifiedModule } from 'magicast';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
|
-
export declare
|
|
3
|
+
export declare const sessionReplaySampleRate = 0.1;
|
|
4
|
+
export declare const sessionReplayOnErrorSampleRate = 1;
|
|
5
|
+
export declare function addSentryInit({ dsn, enableSessionReplay, enableFeedbackWidget, }: {
|
|
4
6
|
dsn: string;
|
|
5
7
|
enableSessionReplay?: boolean;
|
|
8
|
+
enableFeedbackWidget?: boolean;
|
|
6
9
|
}): Promise<void>;
|
|
7
|
-
export declare function addSentryInitWithSdkImport(js: string, { dsn, enableSessionReplay, }: {
|
|
10
|
+
export declare function addSentryInitWithSdkImport(js: string, { dsn, enableSessionReplay, enableFeedbackWidget, }: {
|
|
8
11
|
dsn: string;
|
|
9
12
|
enableSessionReplay?: boolean;
|
|
13
|
+
enableFeedbackWidget?: boolean;
|
|
10
14
|
}): string;
|
|
11
15
|
export declare function doesJsCodeIncludeSdkSentryImport(js: string, { sdkPackageName }: {
|
|
12
16
|
sdkPackageName: string;
|
|
13
17
|
}): boolean;
|
|
14
|
-
export declare function getSentryInitColoredCodeSnippet(dsn: string, enableSessionReplay?: boolean): string;
|
|
15
|
-
export declare function getSentryInitPlainTextSnippet(dsn: string, enableSessionReplay?: boolean): string;
|
|
18
|
+
export declare function getSentryInitColoredCodeSnippet(dsn: string, enableSessionReplay?: boolean, enableFeedbackWidget?: boolean): string;
|
|
19
|
+
export declare function getSentryInitPlainTextSnippet(dsn: string, enableSessionReplay?: boolean, enableFeedbackWidget?: boolean): string;
|
|
20
|
+
export declare function getSentryIntegrationsPlainTextSnippet(enableSessionReplay?: boolean, enableFeedbackWidget?: boolean): string;
|
|
16
21
|
/**
|
|
17
22
|
* This step should be executed after `addSentryInit`
|
|
18
23
|
*/
|
|
@@ -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.doesContainSentryWrap = exports.replaceDefaultExport = exports.wrapWithSentry = exports.getDefaultExport = exports.checkAndWrapRootComponent = exports.SentryWrapResult = exports.wrapRootComponent = exports.getSentryInitPlainTextSnippet = exports.getSentryInitColoredCodeSnippet = exports.doesJsCodeIncludeSdkSentryImport = exports.addSentryInitWithSdkImport = exports.addSentryInit = void 0;
|
|
29
|
+
exports.doesContainSentryWrap = exports.replaceDefaultExport = exports.wrapWithSentry = exports.getDefaultExport = exports.checkAndWrapRootComponent = exports.SentryWrapResult = exports.wrapRootComponent = exports.getSentryIntegrationsPlainTextSnippet = exports.getSentryInitPlainTextSnippet = exports.getSentryInitColoredCodeSnippet = exports.doesJsCodeIncludeSdkSentryImport = exports.addSentryInitWithSdkImport = exports.addSentryInit = exports.sessionReplayOnErrorSampleRate = exports.sessionReplaySampleRate = void 0;
|
|
30
30
|
/* eslint-disable max-lines */
|
|
31
31
|
// @ts-expect-error - clack is ESM and TS complains about that. It works though
|
|
32
32
|
const prompts_1 = __importDefault(require("@clack/prompts"));
|
|
@@ -42,16 +42,17 @@ const react_native_wizard_1 = require("./react-native-wizard");
|
|
|
42
42
|
// @ts-expect-error - magicast is ESM and TS complains about that. It works though
|
|
43
43
|
const magicast_1 = require("magicast");
|
|
44
44
|
const t = __importStar(require("@babel/types"));
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
async function addSentryInit({ dsn, enableSessionReplay = false, }) {
|
|
45
|
+
exports.sessionReplaySampleRate = 0.1;
|
|
46
|
+
exports.sessionReplayOnErrorSampleRate = 1.0;
|
|
47
|
+
async function addSentryInit({ dsn, enableSessionReplay = false, enableFeedbackWidget = false, }) {
|
|
48
48
|
const jsPath = getMainAppFilePath();
|
|
49
49
|
Sentry.setTag('app-js-file-status', jsPath ? 'found' : 'not-found');
|
|
50
50
|
if (!jsPath) {
|
|
51
51
|
prompts_1.default.log.warn(`Could not find main App file. Place the following code snippet close to the Apps Root component.`);
|
|
52
|
+
Sentry.captureException('Could not find main App file.');
|
|
52
53
|
await (0, clack_1.showCopyPasteInstructions)({
|
|
53
54
|
filename: 'App.js or _layout.tsx',
|
|
54
|
-
codeSnippet: getSentryInitColoredCodeSnippet(dsn, enableSessionReplay),
|
|
55
|
+
codeSnippet: getSentryInitColoredCodeSnippet(dsn, enableSessionReplay, enableFeedbackWidget),
|
|
55
56
|
hint: 'This ensures the Sentry SDK is ready to capture errors.',
|
|
56
57
|
});
|
|
57
58
|
return;
|
|
@@ -66,55 +67,69 @@ async function addSentryInit({ dsn, enableSessionReplay = false, }) {
|
|
|
66
67
|
prompts_1.default.log.warn(`${chalk_1.default.cyan(jsRelativePath)} already includes Sentry. We wont't add it again.`);
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
|
-
if (enableSessionReplay) {
|
|
70
|
-
prompts_1.default.log.info(`Session Replay will be enabled with default settings (replaysSessionSampleRate: ${sessionReplaySampleRate}, replaysOnErrorSampleRate: ${sessionReplayOnErrorSampleRate}).`);
|
|
71
|
-
prompts_1.default.log.message('By default, all text content, images, and webviews will be masked for privacy. You can customize this in your code later.');
|
|
72
|
-
}
|
|
73
70
|
(0, telemetry_1.traceStep)('add-sentry-init', () => {
|
|
74
71
|
const newContent = addSentryInitWithSdkImport(js, {
|
|
75
72
|
dsn,
|
|
76
73
|
enableSessionReplay,
|
|
74
|
+
enableFeedbackWidget,
|
|
77
75
|
});
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
try {
|
|
77
|
+
fs.writeFileSync(jsPath, newContent, 'utf-8');
|
|
78
|
+
prompts_1.default.log.success(`Added ${chalk_1.default.cyan('Sentry.init')} to ${chalk_1.default.cyan(jsRelativePath)}.`);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
prompts_1.default.log.error(`Error while writing ${jsPath}`);
|
|
82
|
+
Sentry.captureException('Error while writing app.js');
|
|
83
|
+
}
|
|
80
84
|
});
|
|
81
85
|
Sentry.setTag('app-js-file-status', 'added-sentry-init');
|
|
82
86
|
prompts_1.default.log.success(chalk_1.default.green(`${chalk_1.default.cyan(jsRelativePath)} changes saved.`));
|
|
83
87
|
}
|
|
84
88
|
exports.addSentryInit = addSentryInit;
|
|
85
|
-
function addSentryInitWithSdkImport(js, { dsn, enableSessionReplay = false, }) {
|
|
89
|
+
function addSentryInitWithSdkImport(js, { dsn, enableSessionReplay = false, enableFeedbackWidget = false, }) {
|
|
86
90
|
return js.replace(/^([^]*)(import\s+[^;]*?;$)/m, (match) => `${match}
|
|
87
|
-
${getSentryInitPlainTextSnippet(dsn, enableSessionReplay)}`);
|
|
91
|
+
${getSentryInitPlainTextSnippet(dsn, enableSessionReplay, enableFeedbackWidget)}`);
|
|
88
92
|
}
|
|
89
93
|
exports.addSentryInitWithSdkImport = addSentryInitWithSdkImport;
|
|
90
94
|
function doesJsCodeIncludeSdkSentryImport(js, { sdkPackageName }) {
|
|
91
95
|
return !!js.match(sdkPackageName);
|
|
92
96
|
}
|
|
93
97
|
exports.doesJsCodeIncludeSdkSentryImport = doesJsCodeIncludeSdkSentryImport;
|
|
94
|
-
function getSentryInitColoredCodeSnippet(dsn, enableSessionReplay = false) {
|
|
98
|
+
function getSentryInitColoredCodeSnippet(dsn, enableSessionReplay = false, enableFeedbackWidget = false) {
|
|
95
99
|
return (0, clack_1.makeCodeSnippet)(true, (_unchanged, plus, _minus) => {
|
|
96
|
-
return plus(getSentryInitPlainTextSnippet(dsn, enableSessionReplay));
|
|
100
|
+
return plus(getSentryInitPlainTextSnippet(dsn, enableSessionReplay, enableFeedbackWidget));
|
|
97
101
|
});
|
|
98
102
|
}
|
|
99
103
|
exports.getSentryInitColoredCodeSnippet = getSentryInitColoredCodeSnippet;
|
|
100
|
-
function getSentryInitPlainTextSnippet(dsn, enableSessionReplay = false) {
|
|
104
|
+
function getSentryInitPlainTextSnippet(dsn, enableSessionReplay = false, enableFeedbackWidget = false) {
|
|
101
105
|
return `import * as Sentry from '@sentry/react-native';
|
|
102
106
|
|
|
103
107
|
Sentry.init({
|
|
104
108
|
dsn: '${dsn}',
|
|
109
|
+
|
|
110
|
+
// Adds more context data to events (IP address, cookies, user, etc.)
|
|
111
|
+
// For more information, visit: https://docs.sentry.io/platforms/react-native/data-management/data-collected/
|
|
112
|
+
sendDefaultPii: true,
|
|
105
113
|
${enableSessionReplay
|
|
106
114
|
? `
|
|
107
115
|
// Configure Session Replay
|
|
108
|
-
replaysSessionSampleRate: ${sessionReplaySampleRate},
|
|
109
|
-
replaysOnErrorSampleRate: ${sessionReplayOnErrorSampleRate},
|
|
110
|
-
integrations: [Sentry.mobileReplayIntegration()],
|
|
116
|
+
replaysSessionSampleRate: ${exports.sessionReplaySampleRate},
|
|
117
|
+
replaysOnErrorSampleRate: ${exports.sessionReplayOnErrorSampleRate},
|
|
111
118
|
`
|
|
112
|
-
: ''}
|
|
119
|
+
: ''}${getSentryIntegrationsPlainTextSnippet(enableSessionReplay, enableFeedbackWidget)}
|
|
113
120
|
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
|
|
114
121
|
// spotlight: __DEV__,
|
|
115
122
|
});`;
|
|
116
123
|
}
|
|
117
124
|
exports.getSentryInitPlainTextSnippet = getSentryInitPlainTextSnippet;
|
|
125
|
+
function getSentryIntegrationsPlainTextSnippet(enableSessionReplay = false, enableFeedbackWidget = false) {
|
|
126
|
+
if (!enableSessionReplay && !enableFeedbackWidget) {
|
|
127
|
+
return '';
|
|
128
|
+
}
|
|
129
|
+
return ` integrations: [${enableSessionReplay ? 'Sentry.mobileReplayIntegration()' : ''}${enableSessionReplay && enableFeedbackWidget ? ', ' : ''}${enableFeedbackWidget ? 'Sentry.feedbackIntegration()' : ''}],
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
132
|
+
exports.getSentryIntegrationsPlainTextSnippet = getSentryIntegrationsPlainTextSnippet;
|
|
118
133
|
function getMainAppFilePath() {
|
|
119
134
|
const prefixGlob = '{.,./src,./app}';
|
|
120
135
|
const suffixGlob = '@(j|t|cj|mj)s?(x)';
|
|
@@ -153,8 +168,15 @@ async function wrapRootComponent() {
|
|
|
153
168
|
return;
|
|
154
169
|
}
|
|
155
170
|
(0, telemetry_1.traceStep)('add-sentry-wrap', () => {
|
|
156
|
-
|
|
157
|
-
|
|
171
|
+
try {
|
|
172
|
+
fs.writeFileSync(jsPath, (0, magicast_1.generateCode)(mod.$ast).code, 'utf-8');
|
|
173
|
+
prompts_1.default.log.success(`Added ${chalk_1.default.cyan('Sentry.wrap')} to ${chalk_1.default.cyan(jsRelativePath)}.`);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
prompts_1.default.log.error(`Error while writing ${jsPath}`);
|
|
177
|
+
Sentry.captureException('Error while writing app.js');
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
158
180
|
});
|
|
159
181
|
Sentry.setTag('app-js-file-status', 'added-sentry-wrap');
|
|
160
182
|
prompts_1.default.log.success(chalk_1.default.green(`${chalk_1.default.cyan(jsRelativePath)} changes saved.`));
|
|
@@ -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;AAEvD,kFAAkF;AAClF,uCA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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';\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\nconst sessionReplaySampleRate = 0.1;\nconst sessionReplayOnErrorSampleRate = 1.0;\n\nexport async function addSentryInit({\n dsn,\n enableSessionReplay = false,\n}: {\n dsn: string;\n enableSessionReplay?: 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 await showCopyPasteInstructions({\n filename: 'App.js or _layout.tsx',\n codeSnippet: getSentryInitColoredCodeSnippet(dsn, enableSessionReplay),\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 if (enableSessionReplay) {\n clack.log.info(\n `Session Replay will be enabled with default settings (replaysSessionSampleRate: ${sessionReplaySampleRate}, replaysOnErrorSampleRate: ${sessionReplayOnErrorSampleRate}).`,\n );\n clack.log.message(\n 'By default, all text content, images, and webviews will be masked for privacy. You can customize this in your code later.',\n );\n }\n\n traceStep('add-sentry-init', () => {\n const newContent = addSentryInitWithSdkImport(js, {\n dsn,\n enableSessionReplay,\n });\n\n clack.log.success(\n `Added ${chalk.cyan('Sentry.init')} to ${chalk.cyan(jsRelativePath)}.`,\n );\n\n fs.writeFileSync(jsPath, newContent, 'utf-8');\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 }: { dsn: string; enableSessionReplay?: boolean },\n): string {\n return js.replace(\n /^([^]*)(import\\s+[^;]*?;$)/m,\n (match: string) => `${match}\n${getSentryInitPlainTextSnippet(dsn, enableSessionReplay)}`,\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) {\n return makeCodeSnippet(true, (_unchanged, plus, _minus) => {\n return plus(getSentryInitPlainTextSnippet(dsn, enableSessionReplay));\n });\n}\n\nexport function getSentryInitPlainTextSnippet(\n dsn: string,\n enableSessionReplay = false,\n) {\n return `import * as Sentry from '@sentry/react-native';\n\nSentry.init({\n dsn: '${dsn}',\n${\n enableSessionReplay\n ? `\n // Configure Session Replay\n replaysSessionSampleRate: ${sessionReplaySampleRate},\n replaysOnErrorSampleRate: ${sessionReplayOnErrorSampleRate},\n integrations: [Sentry.mobileReplayIntegration()],\n`\n : ''\n}\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // spotlight: __DEV__,\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 clack.log.success(\n `Added ${chalk.cyan('Sentry.wrap')} to ${chalk.cyan(jsRelativePath)}.`,\n );\n\n fs.writeFileSync(jsPath, generateCode(mod.$ast).code, 'utf-8');\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;AAEvD,kFAAkF;AAClF,uCAAsE;AACtE,gDAAkC;AAErB,QAAA,uBAAuB,GAAG,GAAG,CAAC;AAC9B,QAAA,8BAA8B,GAAG,GAAG,CAAC;AAE3C,KAAK,UAAU,aAAa,CAA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OAAkB;IACtD,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE;QAC/B,IAAI,CAAC,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE;YACtC,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;YACrC,IAAI,CAAC,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAAE;gBACnC,MAAM,QAAQ,GAAG,WAAW,CAAC;gBAC7B,IAAI,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;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';\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}: {\n dsn: string;\n enableSessionReplay?: boolean;\n enableFeedbackWidget?: 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 ),\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 });\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 }: {\n dsn: string;\n enableSessionReplay?: boolean;\n enableFeedbackWidget?: 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)}`,\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) {\n return makeCodeSnippet(true, (_unchanged, plus, _minus) => {\n return plus(\n getSentryInitPlainTextSnippet(\n dsn,\n enableSessionReplay,\n enableFeedbackWidget,\n ),\n );\n });\n}\n\nexport function getSentryInitPlainTextSnippet(\n dsn: string,\n enableSessionReplay = false,\n enableFeedbackWidget = 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 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"]}
|
|
@@ -5,11 +5,7 @@ import t = x.namedTypes;
|
|
|
5
5
|
export declare const metroConfigPath = "metro.config.js";
|
|
6
6
|
export declare function patchMetroWithSentryConfig(): Promise<void>;
|
|
7
7
|
export declare function patchMetroWithSentryConfigInMemory(mod: ProxifiedModule, showInstructions: () => Promise<void>): Promise<boolean>;
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function unPatchMetroConfig(): Promise<void>;
|
|
10
|
-
export declare function removeSentrySerializerFromMetroConfig(program: t.Program): boolean;
|
|
11
|
-
export declare function removeSentryRequire(program: t.Program): boolean;
|
|
12
|
-
export declare function parseMetroConfig(): Promise<ProxifiedModule>;
|
|
8
|
+
export declare function parseMetroConfig(): Promise<ProxifiedModule | undefined>;
|
|
13
9
|
export declare function writeMetroConfig(mod: ProxifiedModule): Promise<boolean>;
|
|
14
10
|
export declare function addSentrySerializerToMetroConfig(configObj: t.ObjectExpression): boolean;
|
|
15
11
|
export declare function addSentrySerializerRequireToMetroConfig(program: t.Program): 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.getModuleExportsAssignmentRight = exports.getMetroConfigObject = exports.addSentryMetroRequireToMetroConfig = exports.addSentrySerializerRequireToMetroConfig = exports.addSentrySerializerToMetroConfig = exports.writeMetroConfig = exports.parseMetroConfig = exports.
|
|
29
|
+
exports.getModuleExportsAssignmentRight = exports.getMetroConfigObject = exports.addSentryMetroRequireToMetroConfig = exports.addSentrySerializerRequireToMetroConfig = exports.addSentrySerializerToMetroConfig = exports.writeMetroConfig = exports.parseMetroConfig = exports.patchMetroWithSentryConfigInMemory = exports.patchMetroWithSentryConfig = exports.metroConfigPath = 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
|
// @ts-expect-error - magicast is ESM and TS complains about that. It works though
|
|
@@ -40,11 +40,15 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
40
40
|
const b = recast.types.builders;
|
|
41
41
|
exports.metroConfigPath = 'metro.config.js';
|
|
42
42
|
async function patchMetroWithSentryConfig() {
|
|
43
|
-
const mod = await parseMetroConfig();
|
|
44
43
|
const showInstructions = () => (0, clack_1.showCopyPasteInstructions)({
|
|
45
44
|
filename: exports.metroConfigPath,
|
|
46
45
|
codeSnippet: getMetroWithSentryConfigSnippet(true),
|
|
47
46
|
});
|
|
47
|
+
const mod = await parseMetroConfig();
|
|
48
|
+
if (!mod) {
|
|
49
|
+
clack.log.error(`Could read from file ${chalk_1.default.cyan(exports.metroConfigPath)}, please follow the manual steps.`);
|
|
50
|
+
return await showInstructions();
|
|
51
|
+
}
|
|
48
52
|
const success = await patchMetroWithSentryConfigInMemory(mod, showInstructions);
|
|
49
53
|
if (!success) {
|
|
50
54
|
return;
|
|
@@ -70,6 +74,7 @@ async function patchMetroWithSentryConfigInMemory(mod, showInstructions) {
|
|
|
70
74
|
const configExpression = getModuleExportsAssignmentRight(mod.$ast);
|
|
71
75
|
if (!configExpression) {
|
|
72
76
|
clack.log.warn('Could not find Metro config, please follow the manual steps.');
|
|
77
|
+
Sentry.captureException('Could not find Metro config.');
|
|
73
78
|
await showInstructions();
|
|
74
79
|
return false;
|
|
75
80
|
}
|
|
@@ -77,12 +82,14 @@ async function patchMetroWithSentryConfigInMemory(mod, showInstructions) {
|
|
|
77
82
|
const replacedModuleExportsRight = replaceModuleExportsRight(mod.$ast, wrappedConfig);
|
|
78
83
|
if (!replacedModuleExportsRight) {
|
|
79
84
|
clack.log.warn('Could not automatically wrap the config export, please follow the manual steps.');
|
|
85
|
+
Sentry.captureException('Could not automatically wrap the config export.');
|
|
80
86
|
await showInstructions();
|
|
81
87
|
return false;
|
|
82
88
|
}
|
|
83
89
|
const addedSentryMetroImport = addSentryMetroRequireToMetroConfig(mod.$ast);
|
|
84
90
|
if (!addedSentryMetroImport) {
|
|
85
91
|
clack.log.warn('Could not add `@sentry/react-native/metro` import to Metro config, please follow the manual steps.');
|
|
92
|
+
Sentry.captureException('Could not add `@sentry/react-native/metro` import to Metro config.');
|
|
86
93
|
await showInstructions();
|
|
87
94
|
return false;
|
|
88
95
|
}
|
|
@@ -90,113 +97,16 @@ async function patchMetroWithSentryConfigInMemory(mod, showInstructions) {
|
|
|
90
97
|
return true;
|
|
91
98
|
}
|
|
92
99
|
exports.patchMetroWithSentryConfigInMemory = patchMetroWithSentryConfigInMemory;
|
|
93
|
-
async function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
codeSnippet: getMetroSentrySerializerSnippet(true),
|
|
98
|
-
});
|
|
99
|
-
if ((0, ast_utils_1.hasSentryContent)(mod.$ast)) {
|
|
100
|
-
const shouldContinue = await confirmPathMetroConfig();
|
|
101
|
-
if (!shouldContinue) {
|
|
102
|
-
return await showInstructions();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const configObj = getMetroConfigObject(mod.$ast);
|
|
106
|
-
if (!configObj) {
|
|
107
|
-
clack.log.warn('Could not find Metro config object, please follow the manual steps.');
|
|
108
|
-
return showInstructions();
|
|
109
|
-
}
|
|
110
|
-
const addedSentrySerializer = addSentrySerializerToMetroConfig(configObj);
|
|
111
|
-
if (!addedSentrySerializer) {
|
|
112
|
-
clack.log.warn('Could not add Sentry serializer to Metro config, please follow the manual steps.');
|
|
113
|
-
return await showInstructions();
|
|
114
|
-
}
|
|
115
|
-
const addedSentrySerializerImport = addSentrySerializerRequireToMetroConfig(mod.$ast);
|
|
116
|
-
if (!addedSentrySerializerImport) {
|
|
117
|
-
clack.log.warn('Could not add Sentry serializer import to Metro config, please follow the manual steps.');
|
|
118
|
-
return await showInstructions();
|
|
119
|
-
}
|
|
120
|
-
clack.log.success(`Added Sentry Metro plugin to ${chalk_1.default.cyan(exports.metroConfigPath)}.`);
|
|
121
|
-
const saved = await writeMetroConfig(mod);
|
|
122
|
-
if (saved) {
|
|
123
|
-
clack.log.success(chalk_1.default.green(`${chalk_1.default.cyan(exports.metroConfigPath)} changes saved.`));
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
clack.log.warn(`Could not save changes to ${chalk_1.default.cyan(exports.metroConfigPath)}, please follow the manual steps.`);
|
|
127
|
-
return await showInstructions();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
exports.patchMetroConfigWithSentrySerializer = patchMetroConfigWithSentrySerializer;
|
|
131
|
-
async function unPatchMetroConfig() {
|
|
132
|
-
const mod = await parseMetroConfig();
|
|
133
|
-
const removedAtLeastOneRequire = removeSentryRequire(mod.$ast);
|
|
134
|
-
const removedSerializerConfig = removeSentrySerializerFromMetroConfig(mod.$ast);
|
|
135
|
-
if (removedAtLeastOneRequire || removedSerializerConfig) {
|
|
136
|
-
const saved = await writeMetroConfig(mod);
|
|
137
|
-
if (saved) {
|
|
138
|
-
clack.log.success(`Removed Sentry Metro plugin from ${chalk_1.default.cyan(exports.metroConfigPath)}.`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
clack.log.warn(`No Sentry Metro plugin found in ${chalk_1.default.cyan(exports.metroConfigPath)}.`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.unPatchMetroConfig = unPatchMetroConfig;
|
|
146
|
-
function removeSentrySerializerFromMetroConfig(program) {
|
|
147
|
-
const configObject = getMetroConfigObject(program);
|
|
148
|
-
if (!configObject) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
const serializerProp = getSerializerProp(configObject);
|
|
152
|
-
if ('invalid' === serializerProp || 'undefined' === serializerProp) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
const customSerializerProp = getCustomSerializerProp(serializerProp);
|
|
156
|
-
if ('invalid' === customSerializerProp ||
|
|
157
|
-
'undefined' === customSerializerProp) {
|
|
158
|
-
return false;
|
|
100
|
+
async function parseMetroConfig() {
|
|
101
|
+
try {
|
|
102
|
+
const metroConfigContent = (await fs.promises.readFile(exports.metroConfigPath)).toString();
|
|
103
|
+
return (0, magicast_1.parseModule)(metroConfigContent);
|
|
159
104
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (customSerializerProp.value.arguments.length === 0) {
|
|
165
|
-
// FROM serializer: { customSerializer: createSentryMetroSerializer() }
|
|
166
|
-
// TO serializer: {}
|
|
167
|
-
let removed = false;
|
|
168
|
-
serializerProp.value.properties = serializerProp.value.properties.filter((p) => {
|
|
169
|
-
if (p.type === 'ObjectProperty' &&
|
|
170
|
-
p.key.type === 'Identifier' &&
|
|
171
|
-
p.key.name === 'customSerializer') {
|
|
172
|
-
removed = true;
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
return true;
|
|
176
|
-
});
|
|
177
|
-
if (removed) {
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
if (customSerializerProp.value.arguments[0].type !== 'SpreadElement') {
|
|
183
|
-
// FROM serializer: { customSerializer: createSentryMetroSerializer(wrapperSerializer) }
|
|
184
|
-
// TO serializer: { customSerializer: wrapperSerializer }
|
|
185
|
-
customSerializerProp.value = customSerializerProp.value.arguments[0];
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
clack.log.error(`Could not read Metro config file ${chalk_1.default.cyan(exports.metroConfigPath)}`);
|
|
107
|
+
Sentry.captureException('Could not read Metro config file');
|
|
108
|
+
return undefined;
|
|
189
109
|
}
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
exports.removeSentrySerializerFromMetroConfig = removeSentrySerializerFromMetroConfig;
|
|
193
|
-
function removeSentryRequire(program) {
|
|
194
|
-
return (0, ast_utils_1.removeRequire)(program, '@sentry');
|
|
195
|
-
}
|
|
196
|
-
exports.removeSentryRequire = removeSentryRequire;
|
|
197
|
-
async function parseMetroConfig() {
|
|
198
|
-
const metroConfigContent = (await fs.promises.readFile(exports.metroConfigPath)).toString();
|
|
199
|
-
return (0, magicast_1.parseModule)(metroConfigContent);
|
|
200
110
|
}
|
|
201
111
|
exports.parseMetroConfig = parseMetroConfig;
|
|
202
112
|
async function writeMetroConfig(mod) {
|
|
@@ -205,6 +115,7 @@ async function writeMetroConfig(mod) {
|
|
|
205
115
|
}
|
|
206
116
|
catch (e) {
|
|
207
117
|
clack.log.error(`Failed to write to ${chalk_1.default.cyan(exports.metroConfigPath)}: ${JSON.stringify(e)}`);
|
|
118
|
+
Sentry.captureException('Failed to write to Metro config file');
|
|
208
119
|
return false;
|
|
209
120
|
}
|
|
210
121
|
return true;
|
|
@@ -410,19 +321,6 @@ function getModuleExports(program) {
|
|
|
410
321
|
return false;
|
|
411
322
|
});
|
|
412
323
|
}
|
|
413
|
-
function getMetroSentrySerializerSnippet(colors) {
|
|
414
|
-
return (0, clack_1.makeCodeSnippet)(colors, (unchanged, plus, _) => unchanged(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');";
|
|
415
|
-
${plus("const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');")}
|
|
416
|
-
|
|
417
|
-
const config = {
|
|
418
|
-
${plus(`serializer: {
|
|
419
|
-
customSerializer: createSentryMetroSerializer(),
|
|
420
|
-
},`)}
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
|
|
424
|
-
`));
|
|
425
|
-
}
|
|
426
324
|
function getMetroWithSentryConfigSnippet(colors) {
|
|
427
325
|
return (0, clack_1.makeCodeSnippet)(colors, (unchanged, plus, _) => unchanged(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');";
|
|
428
326
|
${plus("const {withSentryConfig} = require('@sentry/react-native/metro');")}
|