@sentry/wizard 3.24.1 → 3.25.1
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 +8 -0
- package/dist/package.json +1 -1
- package/dist/src/react-native/expo-env-file.d.ts +2 -0
- package/dist/src/react-native/expo-env-file.js +127 -0
- package/dist/src/react-native/expo-env-file.js.map +1 -0
- package/dist/src/react-native/expo-metro.d.ts +7 -0
- package/dist/src/react-native/expo-metro.js +236 -0
- package/dist/src/react-native/expo-metro.js.map +1 -0
- package/dist/src/react-native/expo.d.ts +16 -0
- package/dist/src/react-native/expo.js +195 -0
- package/dist/src/react-native/expo.js.map +1 -0
- package/dist/src/react-native/git.d.ts +1 -0
- package/dist/src/react-native/git.js +85 -0
- package/dist/src/react-native/git.js.map +1 -0
- package/dist/src/react-native/javascript.d.ts +3 -0
- package/dist/src/react-native/javascript.js +119 -1
- package/dist/src/react-native/javascript.js.map +1 -1
- package/dist/src/react-native/metro.d.ts +3 -0
- package/dist/src/react-native/metro.js +17 -15
- package/dist/src/react-native/metro.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.d.ts +12 -0
- package/dist/src/react-native/react-native-wizard.js +91 -78
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/react-native/xcode.js +14 -3
- package/dist/src/react-native/xcode.js.map +1 -1
- package/dist/src/remix/codemods/handle-error.js +35 -33
- package/dist/src/remix/codemods/handle-error.js.map +1 -1
- package/dist/src/remix/templates.d.ts +1 -1
- package/dist/src/remix/templates.js +1 -1
- package/dist/src/remix/templates.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +2 -1
- package/dist/src/utils/clack-utils.js +2 -2
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/test/react-native/expo-metro.test.d.ts +1 -0
- package/dist/test/react-native/expo-metro.test.js +26 -0
- package/dist/test/react-native/expo-metro.test.js.map +1 -0
- package/dist/test/react-native/expo.test.d.ts +1 -0
- package/dist/test/react-native/expo.test.js +57 -0
- package/dist/test/react-native/expo.test.js.map +1 -0
- package/dist/test/react-native/xcode.test.js +5 -0
- package/dist/test/react-native/xcode.test.js.map +1 -1
- package/package.json +1 -1
- package/src/react-native/expo-env-file.ts +55 -0
- package/src/react-native/expo-metro.ts +212 -0
- package/src/react-native/expo.ts +175 -0
- package/src/react-native/git.ts +25 -0
- package/src/react-native/javascript.ts +68 -1
- package/src/react-native/metro.ts +3 -3
- package/src/react-native/react-native-wizard.ts +72 -76
- package/src/react-native/xcode.ts +21 -5
- package/src/remix/codemods/handle-error.ts +57 -37
- package/src/remix/templates.ts +3 -3
- package/src/utils/clack-utils.ts +4 -4
- package/test/react-native/expo-metro.test.ts +81 -0
- package/test/react-native/expo.test.ts +86 -0
- package/test/react-native/xcode.test.ts +90 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expo.js","sourceRoot":"","sources":["../../../src/react-native/expo.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAC1B,qCAAyB;AACzB,yBAAyB;AAEzB,uCAA8C;AAC9C,mDAAuC;AACvC,oDAG8B;AAE9B,0CAAyC;AAE5B,QAAA,uBAAuB,GAAG,2BAA2B,CAAC;AACtD,QAAA,kCAAkC,GAAG,aAAa,CAAC;AAEnD,QAAA,2BAA2B,GAAG,YAAY,CAAC;AAExD,IAAM,eAAe,GAAG,UAAU,CAAC;AAQnC,SAAgB,6BAA6B;IAC3C,KAAK,CAAC,KAAK,CACT,qBAAc,eAAK,CAAC,IAAI,CACtB,aAAa,CACd,2FAAiF,eAAK,CAAC,IAAI,CAC1F,sEAAsE,CACvE,CAAE,CACJ,CAAC;AACJ,CAAC;AARD,sEAQC;AAED;;GAEG;AACH,SAAsB,kBAAkB,CAAC,OAAgC;;QACvE,SAAS,gBAAgB;YACvB,O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AAO,IAAI,CAAC;SACb;QAED,eAAe,CAAC,IAAI,GAAG,MAAA,eAAe,CAAC,IAAI,mCAAI,EAAE,CAAC;QAClD,eAAe,CAAC,IAAI,CAAC,OAAO,GAAG,MAAA,eAAe,CAAC,IAAI,CAAC,OAAO,mCAAI,EAAE,CAAC;QAClE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChC,+BAAuB;YACvB;gBACE,GAAG,EAAE,OAAO,CAAC,GAAG;gBAChB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,YAAY,EAAE,OAAO,CAAC,GAAG;aAC1B;SACF,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,QAAG,CAAC;KACvD;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,CAAC,MAAM,CAAC,wBAAwB,EAAE,cAAc,CAAC,CAAC;QACxD,KAAK,CAAC,GAAG,CAAC,KAAK,CACb,+BAAwB,eAAK,CAAC,IAAI,CAChC,iBAAiB,CAClB,uCAAoC,CACtC,CAAC;QACF,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AA1DD,oEA0DC;AAED,SAAgB,iCAAiC,CAAC,EAIL;QAH3C,GAAG,SAAA,EACH,OAAO,aAAA,EACP,GAAG,SAAA;IAEH,OAAO,IAAA,6BAAe,EAAC,IAAI,EAAE,UAAC,SAAS,EAAE,IAAI,EAAE,MAAM;QACnD,OAAO,SAAS,CAAC,4DAGf,IAAI,CAAC,+EAGO,GAAG,yCACC,OAAO,8CACF,GAAG,uBAExB,CAAC,cAEL,CAAC,CAAC;IACF,CAAC,CAAC,CAAC;AACL,CAAC;AApBD,8EAoBC","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as fs from 'fs';\nimport { EOL } from 'os';\n\nimport { isPlainObject } from '@sentry/utils';\nimport * as Sentry from '@sentry/node';\nimport {\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../utils/clack-utils';\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 APP_CONFIG_JSON,\n getSentryAppConfigJsonCodeSnippet(options),\n '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 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 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 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 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 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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function addToGitignore(filepath: string): Promise<boolean>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
exports.addToGitignore = void 0;
|
|
63
|
+
var fs = __importStar(require("fs"));
|
|
64
|
+
var GITIGNORE_FILENAME = '.gitignore';
|
|
65
|
+
function addToGitignore(filepath) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
+
var _a;
|
|
68
|
+
return __generator(this, function (_b) {
|
|
69
|
+
switch (_b.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
_b.trys.push([0, 2, , 3]);
|
|
72
|
+
return [4 /*yield*/, fs.promises.appendFile(GITIGNORE_FILENAME, "\n".concat(filepath, "\n"))];
|
|
73
|
+
case 1:
|
|
74
|
+
_b.sent();
|
|
75
|
+
return [2 /*return*/, true];
|
|
76
|
+
case 2:
|
|
77
|
+
_a = _b.sent();
|
|
78
|
+
return [2 /*return*/, false];
|
|
79
|
+
case 3: return [2 /*return*/];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
exports.addToGitignore = addToGitignore;
|
|
85
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src/react-native/git.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AAEzB,IAAM,kBAAkB,GAAG,YAAY,CAAC;AAExC,SAAsB,cAAc,CAAC,QAAgB;;;;;;;oBAejD,qBAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,kBAAkB,EAAE,YAAK,QAAQ,OAAI,CAAC,EAAA;;oBAAnE,SAAmE,CAAC;oBACpE,sBAAO,IAAI,EAAC;;;oBAEZ,sBAAO,KAAK,EAAC;;;;;CAEhB;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,7 +1,125 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
+
};
|
|
2
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSentryInitPlainTextSnippet = exports.getSentryInitColoredCodeSnippet = exports.doesJsCodeIncludeSdkSentryImport = exports.addSentryInitWithSdkImport = void 0;
|
|
65
|
+
exports.getSentryInitPlainTextSnippet = exports.getSentryInitColoredCodeSnippet = exports.doesJsCodeIncludeSdkSentryImport = exports.addSentryInitWithSdkImport = exports.addSentryInit = void 0;
|
|
66
|
+
/* eslint-disable max-lines */
|
|
67
|
+
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
68
|
+
var prompts_1 = __importDefault(require("@clack/prompts"));
|
|
69
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
70
|
+
var path = __importStar(require("path"));
|
|
71
|
+
var process = __importStar(require("process"));
|
|
72
|
+
var fs = __importStar(require("fs"));
|
|
73
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
74
|
+
var telemetry_1 = require("../telemetry");
|
|
4
75
|
var clack_utils_1 = require("../utils/clack-utils");
|
|
76
|
+
var glob_1 = require("./glob");
|
|
77
|
+
var react_native_wizard_1 = require("./react-native-wizard");
|
|
78
|
+
function addSentryInit(_a) {
|
|
79
|
+
var dsn = _a.dsn;
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
var prefixGlob, suffixGlob, universalGlob, jsFileGlob, jsPath, jsRelativePath, js, includesSentry;
|
|
82
|
+
return __generator(this, function (_b) {
|
|
83
|
+
switch (_b.label) {
|
|
84
|
+
case 0:
|
|
85
|
+
prefixGlob = '{.,./src,./app}';
|
|
86
|
+
suffixGlob = '@(j|t|cj|mj)s?(x)';
|
|
87
|
+
universalGlob = "@(App|_layout).".concat(suffixGlob);
|
|
88
|
+
jsFileGlob = "".concat(prefixGlob, "/+(").concat(universalGlob, ")");
|
|
89
|
+
jsPath = (0, telemetry_1.traceStep)('find-app-js-file', function () {
|
|
90
|
+
return (0, glob_1.getFirstMatchedPath)(jsFileGlob);
|
|
91
|
+
});
|
|
92
|
+
Sentry.setTag('app-js-file-status', jsPath ? 'found' : 'not-found');
|
|
93
|
+
if (!!jsPath) return [3 /*break*/, 2];
|
|
94
|
+
prompts_1.default.log.warn("Could not find main App file. Place the following code snippet close to the Apps Root component.");
|
|
95
|
+
return [4 /*yield*/, (0, clack_utils_1.showCopyPasteInstructions)('App.js or _layout.tsx', getSentryInitColoredCodeSnippet(dsn), 'This ensures the Sentry SDK is ready to capture errors.')];
|
|
96
|
+
case 1:
|
|
97
|
+
_b.sent();
|
|
98
|
+
return [2 /*return*/];
|
|
99
|
+
case 2:
|
|
100
|
+
jsRelativePath = path.relative(process.cwd(), jsPath);
|
|
101
|
+
js = fs.readFileSync(jsPath, 'utf-8');
|
|
102
|
+
includesSentry = doesJsCodeIncludeSdkSentryImport(js, {
|
|
103
|
+
sdkPackageName: react_native_wizard_1.RN_SDK_PACKAGE,
|
|
104
|
+
});
|
|
105
|
+
if (includesSentry) {
|
|
106
|
+
Sentry.setTag('app-js-file-status', 'already-includes-sentry');
|
|
107
|
+
prompts_1.default.log.warn("".concat(chalk_1.default.cyan(jsRelativePath), " already includes Sentry. We wont't add it again."));
|
|
108
|
+
return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
(0, telemetry_1.traceStep)('add-sentry-init', function () {
|
|
111
|
+
var newContent = addSentryInitWithSdkImport(js, { dsn: dsn });
|
|
112
|
+
prompts_1.default.log.success("Added ".concat(chalk_1.default.cyan('Sentry.init'), " to ").concat(chalk_1.default.cyan(jsRelativePath), "."));
|
|
113
|
+
fs.writeFileSync(jsPath, newContent, 'utf-8');
|
|
114
|
+
});
|
|
115
|
+
Sentry.setTag('app-js-file-status', 'added-sentry-init');
|
|
116
|
+
prompts_1.default.log.success(chalk_1.default.green("".concat(chalk_1.default.cyan(jsRelativePath), " changes saved.")));
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
exports.addSentryInit = addSentryInit;
|
|
5
123
|
function addSentryInitWithSdkImport(js, _a) {
|
|
6
124
|
var dsn = _a.dsn;
|
|
7
125
|
return js.replace(/^([^]*)(import\s+[^;]*?;$)/m, function (match) { return "".concat(match, "\n").concat(getSentryInitPlainTextSnippet(dsn)); });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.js","sourceRoot":"","sources":["../../../src/react-native/javascript.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"javascript.js","sourceRoot":"","sources":["../../../src/react-native/javascript.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AU,EAAE,IAAI,EAAE,MAAM;QACpD,OAAO,IAAI,CAAC,6BAA6B,CAAC,GAAG,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,0EAIC;AAED,SAAgB,6BAA6B,CAAC,GAAW;IACvD,OAAO,oFAGC,GAAG,2HAIT,CAAC;AACL,CAAC;AATD,sEASC","sourcesContent":["/* eslint-disable max-lines */\n// @ts-ignore - 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 {\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../utils/clack-utils';\nimport { getFirstMatchedPath } from './glob';\nimport { RN_SDK_PACKAGE } from './react-native-wizard';\n\nexport async function addSentryInit({ dsn }: { dsn: string }) {\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 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 'App.js or _layout.tsx',\n getSentryInitColoredCodeSnippet(dsn),\n '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, { dsn });\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 { dsn }: { dsn: string },\n): string {\n return js.replace(\n /^([^]*)(import\\s+[^;]*?;$)/m,\n (match: string) => `${match}\n${getSentryInitPlainTextSnippet(dsn)}`,\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(dsn: string) {\n return makeCodeSnippet(true, (_unchanged, plus, _minus) => {\n return plus(getSentryInitPlainTextSnippet(dsn));\n });\n}\n\nexport function getSentryInitPlainTextSnippet(dsn: string) {\n return `import * as Sentry from '@sentry/react-native';\n\nSentry.init({\n dsn: '${dsn}',\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // enableSpotlight: __DEV__,\n});`;\n}\n"]}
|
|
@@ -2,12 +2,15 @@ import { ProxifiedModule } from 'magicast';
|
|
|
2
2
|
import * as recast from 'recast';
|
|
3
3
|
import x = recast.types;
|
|
4
4
|
import t = x.namedTypes;
|
|
5
|
+
export declare const metroConfigPath = "metro.config.js";
|
|
5
6
|
export declare function patchMetroWithSentryConfig(): Promise<void>;
|
|
6
7
|
export declare function patchMetroWithSentryConfigInMemory(mod: ProxifiedModule, showInstructions: () => Promise<void>): Promise<boolean>;
|
|
7
8
|
export declare function patchMetroConfigWithSentrySerializer(): Promise<void>;
|
|
8
9
|
export declare function unPatchMetroConfig(): Promise<void>;
|
|
9
10
|
export declare function removeSentrySerializerFromMetroConfig(program: t.Program): boolean;
|
|
10
11
|
export declare function removeSentryRequire(program: t.Program): boolean;
|
|
12
|
+
export declare function parseMetroConfig(): Promise<ProxifiedModule>;
|
|
13
|
+
export declare function writeMetroConfig(mod: ProxifiedModule): Promise<boolean>;
|
|
11
14
|
export declare function addSentrySerializerToMetroConfig(configObj: t.ObjectExpression): boolean;
|
|
12
15
|
export declare function addSentrySerializerRequireToMetroConfig(program: t.Program): boolean;
|
|
13
16
|
export declare function addSentryMetroRequireToMetroConfig(program: t.Program): boolean;
|
|
@@ -62,7 +62,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
62
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
63
|
};
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.getModuleExportsAssignmentRight = exports.getMetroConfigObject = exports.addSentryMetroRequireToMetroConfig = exports.addSentrySerializerRequireToMetroConfig = exports.addSentrySerializerToMetroConfig = exports.removeSentryRequire = exports.removeSentrySerializerFromMetroConfig = exports.unPatchMetroConfig = exports.patchMetroConfigWithSentrySerializer = exports.patchMetroWithSentryConfigInMemory = exports.patchMetroWithSentryConfig = void 0;
|
|
65
|
+
exports.getModuleExportsAssignmentRight = exports.getMetroConfigObject = exports.addSentryMetroRequireToMetroConfig = exports.addSentrySerializerRequireToMetroConfig = exports.addSentrySerializerToMetroConfig = exports.writeMetroConfig = exports.parseMetroConfig = exports.removeSentryRequire = exports.removeSentrySerializerFromMetroConfig = exports.unPatchMetroConfig = exports.patchMetroConfigWithSentrySerializer = exports.patchMetroWithSentryConfigInMemory = exports.patchMetroWithSentryConfig = exports.metroConfigPath = void 0;
|
|
66
66
|
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
67
67
|
var clack = __importStar(require("@clack/prompts"));
|
|
68
68
|
// @ts-ignore - magicast is ESM and TS complains about that. It works though
|
|
@@ -74,7 +74,7 @@ var clack_utils_1 = require("../utils/clack-utils");
|
|
|
74
74
|
var recast = __importStar(require("recast"));
|
|
75
75
|
var chalk_1 = __importDefault(require("chalk"));
|
|
76
76
|
var b = recast.types.builders;
|
|
77
|
-
|
|
77
|
+
exports.metroConfigPath = 'metro.config.js';
|
|
78
78
|
function patchMetroWithSentryConfig() {
|
|
79
79
|
return __awaiter(this, void 0, void 0, function () {
|
|
80
80
|
var mod, showInstructions, success, saved;
|
|
@@ -84,7 +84,7 @@ function patchMetroWithSentryConfig() {
|
|
|
84
84
|
case 1:
|
|
85
85
|
mod = _a.sent();
|
|
86
86
|
showInstructions = function () {
|
|
87
|
-
return (0, clack_utils_1.showCopyPasteInstructions)(metroConfigPath, getMetroWithSentryConfigSnippet(true));
|
|
87
|
+
return (0, clack_utils_1.showCopyPasteInstructions)(exports.metroConfigPath, getMetroWithSentryConfigSnippet(true));
|
|
88
88
|
};
|
|
89
89
|
return [4 /*yield*/, patchMetroWithSentryConfigInMemory(mod, showInstructions)];
|
|
90
90
|
case 2:
|
|
@@ -96,10 +96,10 @@ function patchMetroWithSentryConfig() {
|
|
|
96
96
|
case 3:
|
|
97
97
|
saved = _a.sent();
|
|
98
98
|
if (!saved) return [3 /*break*/, 4];
|
|
99
|
-
clack.log.success(chalk_1.default.green("".concat(chalk_1.default.cyan(metroConfigPath), " changes saved.")));
|
|
99
|
+
clack.log.success(chalk_1.default.green("".concat(chalk_1.default.cyan(exports.metroConfigPath), " changes saved.")));
|
|
100
100
|
return [3 /*break*/, 6];
|
|
101
101
|
case 4:
|
|
102
|
-
clack.log.warn("Could not save changes to ".concat(chalk_1.default.cyan(metroConfigPath), ", please follow the manual steps."));
|
|
102
|
+
clack.log.warn("Could not save changes to ".concat(chalk_1.default.cyan(exports.metroConfigPath), ", please follow the manual steps."));
|
|
103
103
|
return [4 /*yield*/, showInstructions()];
|
|
104
104
|
case 5: return [2 /*return*/, _a.sent()];
|
|
105
105
|
case 6: return [2 /*return*/];
|
|
@@ -149,7 +149,7 @@ function patchMetroWithSentryConfigInMemory(mod, showInstructions) {
|
|
|
149
149
|
_a.sent();
|
|
150
150
|
return [2 /*return*/, false];
|
|
151
151
|
case 9:
|
|
152
|
-
clack.log.success("Added Sentry Metro plugin to ".concat(chalk_1.default.cyan(metroConfigPath), "."));
|
|
152
|
+
clack.log.success("Added Sentry Metro plugin to ".concat(chalk_1.default.cyan(exports.metroConfigPath), "."));
|
|
153
153
|
return [2 /*return*/, true];
|
|
154
154
|
}
|
|
155
155
|
});
|
|
@@ -165,7 +165,7 @@ function patchMetroConfigWithSentrySerializer() {
|
|
|
165
165
|
case 1:
|
|
166
166
|
mod = _a.sent();
|
|
167
167
|
showInstructions = function () {
|
|
168
|
-
return (0, clack_utils_1.showCopyPasteInstructions)(metroConfigPath, getMetroSentrySerializerSnippet(true));
|
|
168
|
+
return (0, clack_utils_1.showCopyPasteInstructions)(exports.metroConfigPath, getMetroSentrySerializerSnippet(true));
|
|
169
169
|
};
|
|
170
170
|
if (!(0, ast_utils_1.hasSentryContent)(mod.$ast)) return [3 /*break*/, 4];
|
|
171
171
|
return [4 /*yield*/, confirmPathMetroConfig()];
|
|
@@ -192,15 +192,15 @@ function patchMetroConfigWithSentrySerializer() {
|
|
|
192
192
|
return [4 /*yield*/, showInstructions()];
|
|
193
193
|
case 7: return [2 /*return*/, _a.sent()];
|
|
194
194
|
case 8:
|
|
195
|
-
clack.log.success("Added Sentry Metro plugin to ".concat(chalk_1.default.cyan(metroConfigPath), "."));
|
|
195
|
+
clack.log.success("Added Sentry Metro plugin to ".concat(chalk_1.default.cyan(exports.metroConfigPath), "."));
|
|
196
196
|
return [4 /*yield*/, writeMetroConfig(mod)];
|
|
197
197
|
case 9:
|
|
198
198
|
saved = _a.sent();
|
|
199
199
|
if (!saved) return [3 /*break*/, 10];
|
|
200
|
-
clack.log.success(chalk_1.default.green("".concat(chalk_1.default.cyan(metroConfigPath), " changes saved.")));
|
|
200
|
+
clack.log.success(chalk_1.default.green("".concat(chalk_1.default.cyan(exports.metroConfigPath), " changes saved.")));
|
|
201
201
|
return [3 /*break*/, 12];
|
|
202
202
|
case 10:
|
|
203
|
-
clack.log.warn("Could not save changes to ".concat(chalk_1.default.cyan(metroConfigPath), ", please follow the manual steps."));
|
|
203
|
+
clack.log.warn("Could not save changes to ".concat(chalk_1.default.cyan(exports.metroConfigPath), ", please follow the manual steps."));
|
|
204
204
|
return [4 /*yield*/, showInstructions()];
|
|
205
205
|
case 11: return [2 /*return*/, _a.sent()];
|
|
206
206
|
case 12: return [2 /*return*/];
|
|
@@ -224,11 +224,11 @@ function unPatchMetroConfig() {
|
|
|
224
224
|
case 2:
|
|
225
225
|
saved = _a.sent();
|
|
226
226
|
if (saved) {
|
|
227
|
-
clack.log.success("Removed Sentry Metro plugin from ".concat(chalk_1.default.cyan(metroConfigPath), "."));
|
|
227
|
+
clack.log.success("Removed Sentry Metro plugin from ".concat(chalk_1.default.cyan(exports.metroConfigPath), "."));
|
|
228
228
|
}
|
|
229
229
|
return [3 /*break*/, 4];
|
|
230
230
|
case 3:
|
|
231
|
-
clack.log.warn("No Sentry Metro plugin found in ".concat(chalk_1.default.cyan(metroConfigPath), "."));
|
|
231
|
+
clack.log.warn("No Sentry Metro plugin found in ".concat(chalk_1.default.cyan(exports.metroConfigPath), "."));
|
|
232
232
|
_a.label = 4;
|
|
233
233
|
case 4: return [2 /*return*/];
|
|
234
234
|
}
|
|
@@ -292,7 +292,7 @@ function parseMetroConfig() {
|
|
|
292
292
|
var metroConfigContent;
|
|
293
293
|
return __generator(this, function (_a) {
|
|
294
294
|
switch (_a.label) {
|
|
295
|
-
case 0: return [4 /*yield*/, fs.promises.readFile(metroConfigPath)];
|
|
295
|
+
case 0: return [4 /*yield*/, fs.promises.readFile(exports.metroConfigPath)];
|
|
296
296
|
case 1:
|
|
297
297
|
metroConfigContent = (_a.sent()).toString();
|
|
298
298
|
return [2 /*return*/, (0, magicast_1.parseModule)(metroConfigContent)];
|
|
@@ -300,6 +300,7 @@ function parseMetroConfig() {
|
|
|
300
300
|
});
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
|
+
exports.parseMetroConfig = parseMetroConfig;
|
|
303
304
|
function writeMetroConfig(mod) {
|
|
304
305
|
return __awaiter(this, void 0, void 0, function () {
|
|
305
306
|
var e_1;
|
|
@@ -307,19 +308,20 @@ function writeMetroConfig(mod) {
|
|
|
307
308
|
switch (_a.label) {
|
|
308
309
|
case 0:
|
|
309
310
|
_a.trys.push([0, 2, , 3]);
|
|
310
|
-
return [4 /*yield*/, (0, magicast_1.writeFile)(mod.$ast, metroConfigPath)];
|
|
311
|
+
return [4 /*yield*/, (0, magicast_1.writeFile)(mod.$ast, exports.metroConfigPath)];
|
|
311
312
|
case 1:
|
|
312
313
|
_a.sent();
|
|
313
314
|
return [3 /*break*/, 3];
|
|
314
315
|
case 2:
|
|
315
316
|
e_1 = _a.sent();
|
|
316
|
-
clack.log.error("Failed to write to ".concat(chalk_1.default.cyan(metroConfigPath), ": ").concat(JSON.stringify(e_1)));
|
|
317
|
+
clack.log.error("Failed to write to ".concat(chalk_1.default.cyan(exports.metroConfigPath), ": ").concat(JSON.stringify(e_1)));
|
|
317
318
|
return [2 /*return*/, false];
|
|
318
319
|
case 3: return [2 /*return*/, true];
|
|
319
320
|
}
|
|
320
321
|
});
|
|
321
322
|
});
|
|
322
323
|
}
|
|
324
|
+
exports.writeMetroConfig = writeMetroConfig;
|
|
323
325
|
function addSentrySerializerToMetroConfig(configObj) {
|
|
324
326
|
var serializerProp = getSerializerProp(configObj);
|
|
325
327
|
if ('invalid' === serializerProp) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metro.js","sourceRoot":"","sources":["../../../src/react-native/metro.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,4EAA4E;AAC5E,qCAAmE;AACnE,qCAAyB;AACzB,mDAAuC;AAEvC,gDAI4B;AAC5B,oDAI8B;AA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["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { ProxifiedModule, parseModule, writeFile } from 'magicast';\nimport * as fs from 'fs';\nimport * as Sentry from '@sentry/node';\n\nimport {\n getLastRequireIndex,\n hasSentryContent,\n removeRequire,\n} from '../utils/ast-utils';\nimport {\n abortIfCancelled,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../utils/clack-utils';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\nimport chalk from 'chalk';\n\nconst b = recast.types.builders;\n\nconst metroConfigPath = 'metro.config.js';\n\nexport async function patchMetroWithSentryConfig() {\n const mod = await parseMetroConfig();\n\n const showInstructions = () =>\n showCopyPasteInstructions(\n metroConfigPath,\n getMetroWithSentryConfigSnippet(true),\n );\n\n const success = await patchMetroWithSentryConfigInMemory(\n mod,\n showInstructions,\n );\n if (!success) {\n return;\n }\n\n const saved = await writeMetroConfig(mod);\n if (saved) {\n clack.log.success(\n chalk.green(`${chalk.cyan(metroConfigPath)} changes saved.`),\n );\n } else {\n clack.log.warn(\n `Could not save changes to ${chalk.cyan(\n metroConfigPath,\n )}, please follow the manual steps.`,\n );\n return await showInstructions();\n }\n}\n\nexport async function patchMetroWithSentryConfigInMemory(\n mod: ProxifiedModule,\n showInstructions: () => Promise<void>,\n): Promise<boolean> {\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await confirmPathMetroConfig();\n if (!shouldContinue) {\n await showInstructions();\n return false;\n }\n }\n\n const configExpression = getModuleExportsAssignmentRight(\n mod.$ast as t.Program,\n );\n if (!configExpression) {\n clack.log.warn(\n 'Could not find Metro config, please follow the manual steps.',\n );\n await showInstructions();\n return false;\n }\n\n const wrappedConfig = wrapWithSentryConfig(configExpression);\n\n const replacedModuleExportsRight = replaceModuleExportsRight(\n mod.$ast as t.Program,\n wrappedConfig,\n );\n if (!replacedModuleExportsRight) {\n clack.log.warn(\n 'Could not automatically wrap the config export, please follow the manual steps.',\n );\n await showInstructions();\n return false;\n }\n\n const addedSentryMetroImport = addSentryMetroRequireToMetroConfig(\n mod.$ast as t.Program,\n );\n if (!addedSentryMetroImport) {\n clack.log.warn(\n 'Could not add `@sentry/react-native/metro` import to Metro config, please follow the manual steps.',\n );\n await showInstructions();\n return false;\n }\n\n clack.log.success(\n `Added Sentry Metro plugin to ${chalk.cyan(metroConfigPath)}.`,\n );\n return true;\n}\n\nexport async function patchMetroConfigWithSentrySerializer() {\n const mod = await parseMetroConfig();\n\n const showInstructions = () =>\n showCopyPasteInstructions(\n metroConfigPath,\n getMetroSentrySerializerSnippet(true),\n );\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await confirmPathMetroConfig();\n if (!shouldContinue) {\n return await showInstructions();\n }\n }\n\n const configObj = getMetroConfigObject(mod.$ast as t.Program);\n if (!configObj) {\n clack.log.warn(\n 'Could not find Metro config object, please follow the manual steps.',\n );\n return showInstructions();\n }\n\n const addedSentrySerializer = addSentrySerializerToMetroConfig(configObj);\n if (!addedSentrySerializer) {\n clack.log.warn(\n 'Could not add Sentry serializer to Metro config, please follow the manual steps.',\n );\n return await showInstructions();\n }\n\n const addedSentrySerializerImport = addSentrySerializerRequireToMetroConfig(\n mod.$ast as t.Program,\n );\n if (!addedSentrySerializerImport) {\n clack.log.warn(\n 'Could not add Sentry serializer import to Metro config, please follow the manual steps.',\n );\n return await showInstructions();\n }\n\n clack.log.success(\n `Added Sentry Metro plugin to ${chalk.cyan(metroConfigPath)}.`,\n );\n\n const saved = await writeMetroConfig(mod);\n if (saved) {\n clack.log.success(\n chalk.green(`${chalk.cyan(metroConfigPath)} changes saved.`),\n );\n } else {\n clack.log.warn(\n `Could not save changes to ${chalk.cyan(\n metroConfigPath,\n )}, please follow the manual steps.`,\n );\n return await showInstructions();\n }\n}\n\nexport async function unPatchMetroConfig() {\n const mod = await parseMetroConfig();\n\n const removedAtLeastOneRequire = removeSentryRequire(mod.$ast as t.Program);\n const removedSerializerConfig = removeSentrySerializerFromMetroConfig(\n mod.$ast as t.Program,\n );\n\n if (removedAtLeastOneRequire || removedSerializerConfig) {\n const saved = await writeMetroConfig(mod);\n if (saved) {\n clack.log.success(\n `Removed Sentry Metro plugin from ${chalk.cyan(metroConfigPath)}.`,\n );\n }\n } else {\n clack.log.warn(\n `No Sentry Metro plugin found in ${chalk.cyan(metroConfigPath)}.`,\n );\n }\n}\n\nexport function removeSentrySerializerFromMetroConfig(\n program: t.Program,\n): boolean {\n const configObject = getMetroConfigObject(program);\n if (!configObject) {\n return false;\n }\n\n const serializerProp = getSerializerProp(configObject);\n if ('invalid' === serializerProp || 'undefined' === serializerProp) {\n return false;\n }\n\n const customSerializerProp = getCustomSerializerProp(serializerProp);\n if (\n 'invalid' === customSerializerProp ||\n 'undefined' === customSerializerProp\n ) {\n return false;\n }\n\n if (\n serializerProp.value.type === 'ObjectExpression' &&\n customSerializerProp.value.type === 'CallExpression' &&\n customSerializerProp.value.callee.type === 'Identifier' &&\n customSerializerProp.value.callee.name === 'createSentryMetroSerializer'\n ) {\n if (customSerializerProp.value.arguments.length === 0) {\n // FROM serializer: { customSerializer: createSentryMetroSerializer() }\n // TO serializer: {}\n let removed = false;\n serializerProp.value.properties = serializerProp.value.properties.filter(\n (p) => {\n if (\n p.type === 'ObjectProperty' &&\n p.key.type === 'Identifier' &&\n p.key.name === 'customSerializer'\n ) {\n removed = true;\n return false;\n }\n return true;\n },\n );\n\n if (removed) {\n return true;\n }\n } else {\n if (customSerializerProp.value.arguments[0].type !== 'SpreadElement') {\n // FROM serializer: { customSerializer: createSentryMetroSerializer(wrapperSerializer) }\n // TO serializer: { customSerializer: wrapperSerializer }\n customSerializerProp.value = customSerializerProp.value.arguments[0];\n return true;\n }\n }\n }\n\n return false;\n}\n\nexport function removeSentryRequire(program: t.Program): boolean {\n return removeRequire(program, '@sentry');\n}\n\nasync function parseMetroConfig(): Promise<ProxifiedModule> {\n const metroConfigContent = (\n await fs.promises.readFile(metroConfigPath)\n ).toString();\n\n return parseModule(metroConfigContent);\n}\n\nasync function writeMetroConfig(mod: ProxifiedModule): Promise<boolean> {\n try {\n await writeFile(mod.$ast, metroConfigPath);\n } catch (e) {\n clack.log.error(\n `Failed to write to ${chalk.cyan(metroConfigPath)}: ${JSON.stringify(e)}`,\n );\n return false;\n }\n return true;\n}\n\nexport function addSentrySerializerToMetroConfig(\n configObj: t.ObjectExpression,\n): boolean {\n const serializerProp = getSerializerProp(configObj);\n if ('invalid' === serializerProp) {\n return false;\n }\n\n // case 1: serializer property doesn't exist yet, so we can just add it\n if ('undefined' === serializerProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('serializer'),\n b.objectExpression([\n b.objectProperty(\n b.identifier('customSerializer'),\n b.callExpression(b.identifier('createSentryMetroSerializer'), []),\n ),\n ]),\n ),\n );\n return true;\n }\n\n const customSerializerProp = getCustomSerializerProp(serializerProp);\n // case 2: serializer.customSerializer property doesn't exist yet, so we just add it\n if (\n 'undefined' === customSerializerProp &&\n serializerProp.value.type === 'ObjectExpression'\n ) {\n serializerProp.value.properties.push(\n b.objectProperty(\n b.identifier('customSerializer'),\n b.callExpression(b.identifier('createSentryMetroSerializer'), []),\n ),\n );\n return true;\n }\n\n return false;\n}\n\nfunction getCustomSerializerProp(\n prop: t.ObjectProperty,\n): t.ObjectProperty | 'undefined' | 'invalid' {\n const customSerializerProp =\n prop.value.type === 'ObjectExpression' &&\n prop.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'customSerializer',\n );\n\n if (!customSerializerProp) {\n return 'undefined';\n }\n\n if (customSerializerProp.type === 'ObjectProperty') {\n return customSerializerProp;\n }\n\n return 'invalid';\n}\n\nfunction getSerializerProp(\n obj: t.ObjectExpression,\n): t.ObjectProperty | 'undefined' | 'invalid' {\n const serializerProp = obj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'serializer',\n );\n\n if (!serializerProp) {\n return 'undefined';\n }\n\n if (serializerProp.type === 'ObjectProperty') {\n return serializerProp;\n }\n\n return 'invalid';\n}\n\nexport function addSentrySerializerRequireToMetroConfig(\n program: t.Program,\n): boolean {\n const lastRequireIndex = getLastRequireIndex(program);\n const sentrySerializerRequire = createSentrySerializerRequire();\n const sentryImportIndex = lastRequireIndex + 1;\n if (sentryImportIndex < program.body.length) {\n // insert after last require\n program.body.splice(lastRequireIndex + 1, 0, sentrySerializerRequire);\n } else {\n // insert at the beginning\n program.body.unshift(sentrySerializerRequire);\n }\n return true;\n}\n\nexport function addSentryMetroRequireToMetroConfig(\n program: t.Program,\n): boolean {\n const lastRequireIndex = getLastRequireIndex(program);\n const sentryMetroRequire = createSentryMetroRequire();\n const sentryImportIndex = lastRequireIndex + 1;\n if (sentryImportIndex < program.body.length) {\n // insert after last require\n program.body.splice(lastRequireIndex + 1, 0, sentryMetroRequire);\n } else {\n // insert at the beginning\n program.body.unshift(sentryMetroRequire);\n }\n return true;\n}\n\nfunction wrapWithSentryConfig(\n configObj: t.Identifier | t.CallExpression | t.ObjectExpression,\n): t.CallExpression {\n return b.callExpression(b.identifier('withSentryConfig'), [configObj]);\n}\n\nfunction replaceModuleExportsRight(\n program: t.Program,\n wrappedConfig: t.CallExpression,\n): boolean {\n const moduleExports = getModuleExports(program);\n if (!moduleExports) {\n return false;\n }\n\n if (moduleExports.expression.type === 'AssignmentExpression') {\n moduleExports.expression.right = wrappedConfig;\n return true;\n }\n\n return false;\n}\n\n/**\n * Creates const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');\n */\nfunction createSentrySerializerRequire() {\n return b.variableDeclaration('const', [\n b.variableDeclarator(\n b.objectPattern([\n b.objectProperty.from({\n key: b.identifier('createSentryMetroSerializer'),\n value: b.identifier('createSentryMetroSerializer'),\n shorthand: true,\n }),\n ]),\n b.callExpression(b.identifier('require'), [\n b.literal('@sentry/react-native/dist/js/tools/sentryMetroSerializer'),\n ]),\n ),\n ]);\n}\n\n/**\n * Creates const {withSentryConfig} = require('@sentry/react-native/metro');\n */\nfunction createSentryMetroRequire() {\n return b.variableDeclaration('const', [\n b.variableDeclarator(\n b.objectPattern([\n b.objectProperty.from({\n key: b.identifier('withSentryConfig'),\n value: b.identifier('withSentryConfig'),\n shorthand: true,\n }),\n ]),\n b.callExpression(b.identifier('require'), [\n b.literal('@sentry/react-native/metro'),\n ]),\n ),\n ]);\n}\n\nasync function confirmPathMetroConfig() {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `Metro Config already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Metro plugin',\n value: true,\n },\n {\n label: 'No, show me instructions to manually add the plugin',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n if (!shouldContinue) {\n Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');\n }\n\n return shouldContinue;\n}\n\n/**\n * Returns value from `module.exports = value` or `const config = value`\n */\nexport function getMetroConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n // check config variable\n const configVariable = program.body.find((s) => {\n if (\n s.type === 'VariableDeclaration' &&\n s.declarations.length === 1 &&\n s.declarations[0].type === 'VariableDeclarator' &&\n s.declarations[0].id.type === 'Identifier' &&\n s.declarations[0].id.name === 'config'\n ) {\n return true;\n }\n return false;\n }) as t.VariableDeclaration | undefined;\n\n if (\n configVariable?.declarations[0].type === 'VariableDeclarator' &&\n configVariable?.declarations[0].init?.type === 'ObjectExpression'\n ) {\n Sentry.setTag('metro-config', 'config-variable');\n return configVariable.declarations[0].init;\n }\n\n return getModuleExportsObject(program);\n}\n\nfunction getModuleExportsObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n // check module.exports\n const moduleExports = getModuleExportsAssignmentRight(program);\n\n if (moduleExports?.type === 'ObjectExpression') {\n return moduleExports;\n }\n\n Sentry.setTag('metro-config', 'not-found');\n return undefined;\n}\n\nexport function getModuleExportsAssignmentRight(\n program: t.Program,\n): t.Identifier | t.CallExpression | t.ObjectExpression | undefined {\n // check module.exports\n const moduleExports = getModuleExports(program);\n\n if (\n moduleExports?.expression.type === 'AssignmentExpression' &&\n (moduleExports.expression.right.type === 'ObjectExpression' ||\n moduleExports.expression.right.type === 'CallExpression' ||\n moduleExports.expression.right.type === 'Identifier')\n ) {\n Sentry.setTag('metro-config', 'module-exports');\n return moduleExports?.expression.right;\n }\n\n Sentry.setTag('metro-config', 'not-found');\n return undefined;\n}\n\nfunction getModuleExports(\n program: t.Program,\n): t.ExpressionStatement | undefined {\n // find module.exports\n return program.body.find((s) => {\n if (\n s.type === 'ExpressionStatement' &&\n s.expression.type === 'AssignmentExpression' &&\n s.expression.left.type === 'MemberExpression' &&\n s.expression.left.object.type === 'Identifier' &&\n s.expression.left.object.name === 'module' &&\n s.expression.left.property.type === 'Identifier' &&\n s.expression.left.property.name === 'exports'\n ) {\n return true;\n }\n return false;\n }) as t.ExpressionStatement | undefined;\n}\n\nfunction getMetroSentrySerializerSnippet(colors: boolean) {\n return makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\";\n${plus(\n \"const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');\",\n)}\n\nconst config = {\n ${plus(`serializer: {\n customSerializer: createSentryMetroSerializer(),\n },`)}\n};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);\n`),\n );\n}\n\nfunction getMetroWithSentryConfigSnippet(colors: boolean) {\n return makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\";\n${plus(\"const {withSentryConfig} = require('@sentry/react-native/metro');\")}\n\nconst config = {};\n\nmodule.exports = ${plus(\n 'withSentryConfig(',\n )}mergeConfig(getDefaultConfig(__dirname), config)${plus(')')};\n`),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"metro.js","sourceRoot":"","sources":["../../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CAAC,MAAe;IACtD,OAAO,IAAA,6BAAe,EAAC,MAAM,EAAE,UAAC,SAAS,EAAE,IAAI,EAAE,CAAC;QAChD,OAAA,SAAS,CAAC,6FACZ,IAAI,CAAC,mEAAmE,CAAC,wDAIxD,IAAI,CACjB,mBAAmB,CACpB,6DAAmD,IAAI,CAAC,GAAG,CAAC,QAChE,CAAC;IARE,CAQF,CACC,CAAC;AACJ,CAAC","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { ProxifiedModule, parseModule, writeFile } from 'magicast';\nimport * as fs from 'fs';\nimport * as Sentry from '@sentry/node';\n\nimport {\n getLastRequireIndex,\n hasSentryContent,\n removeRequire,\n} from '../utils/ast-utils';\nimport {\n abortIfCancelled,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../utils/clack-utils';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\nimport chalk from 'chalk';\n\nconst b = recast.types.builders;\n\nexport const metroConfigPath = 'metro.config.js';\n\nexport async function patchMetroWithSentryConfig() {\n const mod = await parseMetroConfig();\n\n const showInstructions = () =>\n showCopyPasteInstructions(\n metroConfigPath,\n getMetroWithSentryConfigSnippet(true),\n );\n\n const success = await patchMetroWithSentryConfigInMemory(\n mod,\n showInstructions,\n );\n if (!success) {\n return;\n }\n\n const saved = await writeMetroConfig(mod);\n if (saved) {\n clack.log.success(\n chalk.green(`${chalk.cyan(metroConfigPath)} changes saved.`),\n );\n } else {\n clack.log.warn(\n `Could not save changes to ${chalk.cyan(\n metroConfigPath,\n )}, please follow the manual steps.`,\n );\n return await showInstructions();\n }\n}\n\nexport async function patchMetroWithSentryConfigInMemory(\n mod: ProxifiedModule,\n showInstructions: () => Promise<void>,\n): Promise<boolean> {\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await confirmPathMetroConfig();\n if (!shouldContinue) {\n await showInstructions();\n return false;\n }\n }\n\n const configExpression = getModuleExportsAssignmentRight(\n mod.$ast as t.Program,\n );\n if (!configExpression) {\n clack.log.warn(\n 'Could not find Metro config, please follow the manual steps.',\n );\n await showInstructions();\n return false;\n }\n\n const wrappedConfig = wrapWithSentryConfig(configExpression);\n\n const replacedModuleExportsRight = replaceModuleExportsRight(\n mod.$ast as t.Program,\n wrappedConfig,\n );\n if (!replacedModuleExportsRight) {\n clack.log.warn(\n 'Could not automatically wrap the config export, please follow the manual steps.',\n );\n await showInstructions();\n return false;\n }\n\n const addedSentryMetroImport = addSentryMetroRequireToMetroConfig(\n mod.$ast as t.Program,\n );\n if (!addedSentryMetroImport) {\n clack.log.warn(\n 'Could not add `@sentry/react-native/metro` import to Metro config, please follow the manual steps.',\n );\n await showInstructions();\n return false;\n }\n\n clack.log.success(\n `Added Sentry Metro plugin to ${chalk.cyan(metroConfigPath)}.`,\n );\n return true;\n}\n\nexport async function patchMetroConfigWithSentrySerializer() {\n const mod = await parseMetroConfig();\n\n const showInstructions = () =>\n showCopyPasteInstructions(\n metroConfigPath,\n getMetroSentrySerializerSnippet(true),\n );\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await confirmPathMetroConfig();\n if (!shouldContinue) {\n return await showInstructions();\n }\n }\n\n const configObj = getMetroConfigObject(mod.$ast as t.Program);\n if (!configObj) {\n clack.log.warn(\n 'Could not find Metro config object, please follow the manual steps.',\n );\n return showInstructions();\n }\n\n const addedSentrySerializer = addSentrySerializerToMetroConfig(configObj);\n if (!addedSentrySerializer) {\n clack.log.warn(\n 'Could not add Sentry serializer to Metro config, please follow the manual steps.',\n );\n return await showInstructions();\n }\n\n const addedSentrySerializerImport = addSentrySerializerRequireToMetroConfig(\n mod.$ast as t.Program,\n );\n if (!addedSentrySerializerImport) {\n clack.log.warn(\n 'Could not add Sentry serializer import to Metro config, please follow the manual steps.',\n );\n return await showInstructions();\n }\n\n clack.log.success(\n `Added Sentry Metro plugin to ${chalk.cyan(metroConfigPath)}.`,\n );\n\n const saved = await writeMetroConfig(mod);\n if (saved) {\n clack.log.success(\n chalk.green(`${chalk.cyan(metroConfigPath)} changes saved.`),\n );\n } else {\n clack.log.warn(\n `Could not save changes to ${chalk.cyan(\n metroConfigPath,\n )}, please follow the manual steps.`,\n );\n return await showInstructions();\n }\n}\n\nexport async function unPatchMetroConfig() {\n const mod = await parseMetroConfig();\n\n const removedAtLeastOneRequire = removeSentryRequire(mod.$ast as t.Program);\n const removedSerializerConfig = removeSentrySerializerFromMetroConfig(\n mod.$ast as t.Program,\n );\n\n if (removedAtLeastOneRequire || removedSerializerConfig) {\n const saved = await writeMetroConfig(mod);\n if (saved) {\n clack.log.success(\n `Removed Sentry Metro plugin from ${chalk.cyan(metroConfigPath)}.`,\n );\n }\n } else {\n clack.log.warn(\n `No Sentry Metro plugin found in ${chalk.cyan(metroConfigPath)}.`,\n );\n }\n}\n\nexport function removeSentrySerializerFromMetroConfig(\n program: t.Program,\n): boolean {\n const configObject = getMetroConfigObject(program);\n if (!configObject) {\n return false;\n }\n\n const serializerProp = getSerializerProp(configObject);\n if ('invalid' === serializerProp || 'undefined' === serializerProp) {\n return false;\n }\n\n const customSerializerProp = getCustomSerializerProp(serializerProp);\n if (\n 'invalid' === customSerializerProp ||\n 'undefined' === customSerializerProp\n ) {\n return false;\n }\n\n if (\n serializerProp.value.type === 'ObjectExpression' &&\n customSerializerProp.value.type === 'CallExpression' &&\n customSerializerProp.value.callee.type === 'Identifier' &&\n customSerializerProp.value.callee.name === 'createSentryMetroSerializer'\n ) {\n if (customSerializerProp.value.arguments.length === 0) {\n // FROM serializer: { customSerializer: createSentryMetroSerializer() }\n // TO serializer: {}\n let removed = false;\n serializerProp.value.properties = serializerProp.value.properties.filter(\n (p) => {\n if (\n p.type === 'ObjectProperty' &&\n p.key.type === 'Identifier' &&\n p.key.name === 'customSerializer'\n ) {\n removed = true;\n return false;\n }\n return true;\n },\n );\n\n if (removed) {\n return true;\n }\n } else {\n if (customSerializerProp.value.arguments[0].type !== 'SpreadElement') {\n // FROM serializer: { customSerializer: createSentryMetroSerializer(wrapperSerializer) }\n // TO serializer: { customSerializer: wrapperSerializer }\n customSerializerProp.value = customSerializerProp.value.arguments[0];\n return true;\n }\n }\n }\n\n return false;\n}\n\nexport function removeSentryRequire(program: t.Program): boolean {\n return removeRequire(program, '@sentry');\n}\n\nexport async function parseMetroConfig(): Promise<ProxifiedModule> {\n const metroConfigContent = (\n await fs.promises.readFile(metroConfigPath)\n ).toString();\n\n return parseModule(metroConfigContent);\n}\n\nexport async function writeMetroConfig(mod: ProxifiedModule): Promise<boolean> {\n try {\n await writeFile(mod.$ast, metroConfigPath);\n } catch (e) {\n clack.log.error(\n `Failed to write to ${chalk.cyan(metroConfigPath)}: ${JSON.stringify(e)}`,\n );\n return false;\n }\n return true;\n}\n\nexport function addSentrySerializerToMetroConfig(\n configObj: t.ObjectExpression,\n): boolean {\n const serializerProp = getSerializerProp(configObj);\n if ('invalid' === serializerProp) {\n return false;\n }\n\n // case 1: serializer property doesn't exist yet, so we can just add it\n if ('undefined' === serializerProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('serializer'),\n b.objectExpression([\n b.objectProperty(\n b.identifier('customSerializer'),\n b.callExpression(b.identifier('createSentryMetroSerializer'), []),\n ),\n ]),\n ),\n );\n return true;\n }\n\n const customSerializerProp = getCustomSerializerProp(serializerProp);\n // case 2: serializer.customSerializer property doesn't exist yet, so we just add it\n if (\n 'undefined' === customSerializerProp &&\n serializerProp.value.type === 'ObjectExpression'\n ) {\n serializerProp.value.properties.push(\n b.objectProperty(\n b.identifier('customSerializer'),\n b.callExpression(b.identifier('createSentryMetroSerializer'), []),\n ),\n );\n return true;\n }\n\n return false;\n}\n\nfunction getCustomSerializerProp(\n prop: t.ObjectProperty,\n): t.ObjectProperty | 'undefined' | 'invalid' {\n const customSerializerProp =\n prop.value.type === 'ObjectExpression' &&\n prop.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'customSerializer',\n );\n\n if (!customSerializerProp) {\n return 'undefined';\n }\n\n if (customSerializerProp.type === 'ObjectProperty') {\n return customSerializerProp;\n }\n\n return 'invalid';\n}\n\nfunction getSerializerProp(\n obj: t.ObjectExpression,\n): t.ObjectProperty | 'undefined' | 'invalid' {\n const serializerProp = obj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'serializer',\n );\n\n if (!serializerProp) {\n return 'undefined';\n }\n\n if (serializerProp.type === 'ObjectProperty') {\n return serializerProp;\n }\n\n return 'invalid';\n}\n\nexport function addSentrySerializerRequireToMetroConfig(\n program: t.Program,\n): boolean {\n const lastRequireIndex = getLastRequireIndex(program);\n const sentrySerializerRequire = createSentrySerializerRequire();\n const sentryImportIndex = lastRequireIndex + 1;\n if (sentryImportIndex < program.body.length) {\n // insert after last require\n program.body.splice(lastRequireIndex + 1, 0, sentrySerializerRequire);\n } else {\n // insert at the beginning\n program.body.unshift(sentrySerializerRequire);\n }\n return true;\n}\n\nexport function addSentryMetroRequireToMetroConfig(\n program: t.Program,\n): boolean {\n const lastRequireIndex = getLastRequireIndex(program);\n const sentryMetroRequire = createSentryMetroRequire();\n const sentryImportIndex = lastRequireIndex + 1;\n if (sentryImportIndex < program.body.length) {\n // insert after last require\n program.body.splice(lastRequireIndex + 1, 0, sentryMetroRequire);\n } else {\n // insert at the beginning\n program.body.unshift(sentryMetroRequire);\n }\n return true;\n}\n\nfunction wrapWithSentryConfig(\n configObj: t.Identifier | t.CallExpression | t.ObjectExpression,\n): t.CallExpression {\n return b.callExpression(b.identifier('withSentryConfig'), [configObj]);\n}\n\nfunction replaceModuleExportsRight(\n program: t.Program,\n wrappedConfig: t.CallExpression,\n): boolean {\n const moduleExports = getModuleExports(program);\n if (!moduleExports) {\n return false;\n }\n\n if (moduleExports.expression.type === 'AssignmentExpression') {\n moduleExports.expression.right = wrappedConfig;\n return true;\n }\n\n return false;\n}\n\n/**\n * Creates const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');\n */\nfunction createSentrySerializerRequire() {\n return b.variableDeclaration('const', [\n b.variableDeclarator(\n b.objectPattern([\n b.objectProperty.from({\n key: b.identifier('createSentryMetroSerializer'),\n value: b.identifier('createSentryMetroSerializer'),\n shorthand: true,\n }),\n ]),\n b.callExpression(b.identifier('require'), [\n b.literal('@sentry/react-native/dist/js/tools/sentryMetroSerializer'),\n ]),\n ),\n ]);\n}\n\n/**\n * Creates const {withSentryConfig} = require('@sentry/react-native/metro');\n */\nfunction createSentryMetroRequire() {\n return b.variableDeclaration('const', [\n b.variableDeclarator(\n b.objectPattern([\n b.objectProperty.from({\n key: b.identifier('withSentryConfig'),\n value: b.identifier('withSentryConfig'),\n shorthand: true,\n }),\n ]),\n b.callExpression(b.identifier('require'), [\n b.literal('@sentry/react-native/metro'),\n ]),\n ),\n ]);\n}\n\nasync function confirmPathMetroConfig() {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `Metro Config already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Metro plugin',\n value: true,\n },\n {\n label: 'No, show me instructions to manually add the plugin',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n if (!shouldContinue) {\n Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');\n }\n\n return shouldContinue;\n}\n\n/**\n * Returns value from `module.exports = value` or `const config = value`\n */\nexport function getMetroConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n // check config variable\n const configVariable = program.body.find((s) => {\n if (\n s.type === 'VariableDeclaration' &&\n s.declarations.length === 1 &&\n s.declarations[0].type === 'VariableDeclarator' &&\n s.declarations[0].id.type === 'Identifier' &&\n s.declarations[0].id.name === 'config'\n ) {\n return true;\n }\n return false;\n }) as t.VariableDeclaration | undefined;\n\n if (\n configVariable?.declarations[0].type === 'VariableDeclarator' &&\n configVariable?.declarations[0].init?.type === 'ObjectExpression'\n ) {\n Sentry.setTag('metro-config', 'config-variable');\n return configVariable.declarations[0].init;\n }\n\n return getModuleExportsObject(program);\n}\n\nfunction getModuleExportsObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n // check module.exports\n const moduleExports = getModuleExportsAssignmentRight(program);\n\n if (moduleExports?.type === 'ObjectExpression') {\n return moduleExports;\n }\n\n Sentry.setTag('metro-config', 'not-found');\n return undefined;\n}\n\nexport function getModuleExportsAssignmentRight(\n program: t.Program,\n): t.Identifier | t.CallExpression | t.ObjectExpression | undefined {\n // check module.exports\n const moduleExports = getModuleExports(program);\n\n if (\n moduleExports?.expression.type === 'AssignmentExpression' &&\n (moduleExports.expression.right.type === 'ObjectExpression' ||\n moduleExports.expression.right.type === 'CallExpression' ||\n moduleExports.expression.right.type === 'Identifier')\n ) {\n Sentry.setTag('metro-config', 'module-exports');\n return moduleExports?.expression.right;\n }\n\n Sentry.setTag('metro-config', 'not-found');\n return undefined;\n}\n\nfunction getModuleExports(\n program: t.Program,\n): t.ExpressionStatement | undefined {\n // find module.exports\n return program.body.find((s) => {\n if (\n s.type === 'ExpressionStatement' &&\n s.expression.type === 'AssignmentExpression' &&\n s.expression.left.type === 'MemberExpression' &&\n s.expression.left.object.type === 'Identifier' &&\n s.expression.left.object.name === 'module' &&\n s.expression.left.property.type === 'Identifier' &&\n s.expression.left.property.name === 'exports'\n ) {\n return true;\n }\n return false;\n }) as t.ExpressionStatement | undefined;\n}\n\nfunction getMetroSentrySerializerSnippet(colors: boolean) {\n return makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\";\n${plus(\n \"const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');\",\n)}\n\nconst config = {\n ${plus(`serializer: {\n customSerializer: createSentryMetroSerializer(),\n },`)}\n};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);\n`),\n );\n}\n\nfunction getMetroWithSentryConfigSnippet(colors: boolean) {\n return makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\";\n${plus(\"const {withSentryConfig} = require('@sentry/react-native/metro');\")}\n\nconst config = {};\n\nmodule.exports = ${plus(\n 'withSentryConfig(',\n )}mergeConfig(getDefaultConfig(__dirname), config)${plus(')')};\n`),\n );\n}\n"]}
|
|
@@ -4,8 +4,20 @@ export declare const RN_SDK_PACKAGE = "@sentry/react-native";
|
|
|
4
4
|
export declare const RN_PACKAGE = "react-native";
|
|
5
5
|
export declare const RN_HUMAN_NAME = "React Native";
|
|
6
6
|
export declare const SUPPORTED_RN_RANGE = ">=0.69.0";
|
|
7
|
+
export declare const SUPPORTED_EXPO_RANGE = ">=50.0.0";
|
|
8
|
+
/**
|
|
9
|
+
* The following SDK version ship with bundled Xcode scripts
|
|
10
|
+
* which simplifies the Xcode Build Phases setup.
|
|
11
|
+
*/
|
|
7
12
|
export declare const SDK_XCODE_SCRIPTS_SUPPORTED_SDK_RANGE = ">=5.11.0";
|
|
13
|
+
/**
|
|
14
|
+
* The following SDK version ship with Sentry Metro plugin
|
|
15
|
+
*/
|
|
8
16
|
export declare const SDK_SENTRY_METRO_PLUGIN_SUPPORTED_SDK_RANGE = ">=5.11.0";
|
|
17
|
+
/**
|
|
18
|
+
* The following SDK version ship with bundled Expo plugin
|
|
19
|
+
*/
|
|
20
|
+
export declare const SDK_EXPO_SUPPORTED_SDK_RANGE = ">=5.16.0";
|
|
9
21
|
export declare const SDK_SENTRY_METRO_WITH_SENTRY_CONFIG_SUPPORTED_SDK_RANGE = ">=5.17.0";
|
|
10
22
|
export type RNCliSetupConfigContent = Pick<Required<CliSetupConfigContent>, 'authToken' | 'org' | 'project' | 'url'>;
|
|
11
23
|
export declare function runReactNativeWizard(params: ReactNativeWizardOptions): Promise<void>;
|