@sentry/wizard 3.22.3 → 3.23.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 +5 -0
- package/dist/package.json +1 -1
- package/dist/src/react-native/javascript.js +1 -1
- package/dist/src/react-native/javascript.js.map +1 -1
- package/dist/src/react-native/metro.d.ts +6 -1
- package/dist/src/react-native/metro.js +166 -17
- package/dist/src/react-native/metro.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.d.ts +1 -0
- package/dist/src/react-native/react-native-wizard.js +19 -20
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +1 -1
- package/dist/src/utils/ast-utils.js +2 -2
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/test/react-native/javascript.test.js +1 -1
- package/dist/test/react-native/javascript.test.js.map +1 -1
- package/dist/test/react-native/metro.test.js +115 -0
- package/dist/test/react-native/metro.test.js.map +1 -1
- package/package.json +1 -1
- package/src/react-native/javascript.ts +3 -0
- package/src/react-native/metro.ts +208 -18
- package/src/react-native/react-native-wizard.ts +24 -7
- package/src/utils/ast-utils.ts +2 -2
- package/test/react-native/javascript.test.ts +3 -0
- package/test/react-native/metro.test.ts +113 -0
package/CHANGELOG.md
CHANGED
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/wizard",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.23.0",
|
|
4
4
|
"homepage": "https://github.com/getsentry/sentry-wizard",
|
|
5
5
|
"repository": "https://github.com/getsentry/sentry-wizard",
|
|
6
6
|
"description": "Sentry wizard helping you to configure your project",
|
|
@@ -19,7 +19,7 @@ function getSentryInitColoredCodeSnippet(dsn) {
|
|
|
19
19
|
}
|
|
20
20
|
exports.getSentryInitColoredCodeSnippet = getSentryInitColoredCodeSnippet;
|
|
21
21
|
function getSentryInitPlainTextSnippet(dsn) {
|
|
22
|
-
return "import * as Sentry from '@sentry/react-native';\n\nSentry.init({\n dsn: '".concat(dsn, "',\n});");
|
|
22
|
+
return "import * as Sentry from '@sentry/react-native';\n\nSentry.init({\n dsn: '".concat(dsn, "',\n\n // uncomment the line below to enable Spotlight (https://spotlightjs.com)\n // enableSpotlight: __DEV__,\n});");
|
|
23
23
|
}
|
|
24
24
|
exports.getSentryInitPlainTextSnippet = getSentryInitPlainTextSnippet;
|
|
25
25
|
//# sourceMappingURL=javascript.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.js","sourceRoot":"","sources":["../../../src/react-native/javascript.ts"],"names":[],"mappings":";;;AAAA,oDAAuD;AAEvD,SAAgB,0BAA0B,CACxC,EAAU,EACV,EAAwB;QAAtB,GAAG,SAAA;IAEL,OAAO,EAAE,CAAC,OAAO,CACf,6BAA6B,EAC7B,UAAC,KAAa,IAAK,OAAA,UAAG,KAAK,eAC7B,6BAA6B,CAAC,GAAG,CAAC,CAAE,EADf,CACe,CACnC,CAAC;AACJ,CAAC;AATD,gEASC;AAED,SAAgB,gCAAgC,CAC9C,EAAU,EACV,EAA8C;QAA5C,cAAc,oBAAA;IAEhB,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AACpC,CAAC;AALD,4EAKC;AAED,SAAgB,+BAA+B,CAAC,GAAW;IACzD,OAAO,IAAA,6BAAe,EAAC,IAAI,EAAE,UAAC,UAAU,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,
|
|
1
|
+
{"version":3,"file":"javascript.js","sourceRoot":"","sources":["../../../src/react-native/javascript.ts"],"names":[],"mappings":";;;AAAA,oDAAuD;AAEvD,SAAgB,0BAA0B,CACxC,EAAU,EACV,EAAwB;QAAtB,GAAG,SAAA;IAEL,OAAO,EAAE,CAAC,OAAO,CACf,6BAA6B,EAC7B,UAAC,KAAa,IAAK,OAAA,UAAG,KAAK,eAC7B,6BAA6B,CAAC,GAAG,CAAC,CAAE,EADf,CACe,CACnC,CAAC;AACJ,CAAC;AATD,gEASC;AAED,SAAgB,gCAAgC,CAC9C,EAAU,EACV,EAA8C;QAA5C,cAAc,oBAAA;IAEhB,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AACpC,CAAC;AALD,4EAKC;AAED,SAAgB,+BAA+B,CAAC,GAAW;IACzD,OAAO,IAAA,6BAAe,EAAC,IAAI,EAAE,UAAC,UAAU,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":["import { makeCodeSnippet } from '../utils/clack-utils';\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"]}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import { ProxifiedModule } from 'magicast';
|
|
1
2
|
import * as recast from 'recast';
|
|
2
3
|
import x = recast.types;
|
|
3
4
|
import t = x.namedTypes;
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function patchMetroWithSentryConfig(): Promise<void>;
|
|
6
|
+
export declare function patchMetroWithSentryConfigInMemory(mod: ProxifiedModule, showInstructions: () => Promise<void>): Promise<boolean>;
|
|
7
|
+
export declare function patchMetroConfigWithSentrySerializer(): Promise<void>;
|
|
5
8
|
export declare function unPatchMetroConfig(): Promise<void>;
|
|
6
9
|
export declare function removeSentrySerializerFromMetroConfig(program: t.Program): boolean;
|
|
7
10
|
export declare function removeSentryRequire(program: t.Program): boolean;
|
|
8
11
|
export declare function addSentrySerializerToMetroConfig(configObj: t.ObjectExpression): boolean;
|
|
9
12
|
export declare function addSentrySerializerRequireToMetroConfig(program: t.Program): boolean;
|
|
13
|
+
export declare function addSentryMetroRequireToMetroConfig(program: t.Program): boolean;
|
|
10
14
|
/**
|
|
11
15
|
* Returns value from `module.exports = value` or `const config = value`
|
|
12
16
|
*/
|
|
13
17
|
export declare function getMetroConfigObject(program: t.Program): t.ObjectExpression | undefined;
|
|
18
|
+
export declare function getModuleExportsAssignmentRight(program: t.Program): t.Identifier | t.CallExpression | t.ObjectExpression | undefined;
|
|
@@ -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.getMetroConfigObject = exports.addSentrySerializerRequireToMetroConfig = exports.addSentrySerializerToMetroConfig = exports.removeSentryRequire = exports.removeSentrySerializerFromMetroConfig = exports.unPatchMetroConfig = exports.
|
|
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;
|
|
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
|
|
@@ -75,7 +75,88 @@ var recast = __importStar(require("recast"));
|
|
|
75
75
|
var chalk_1 = __importDefault(require("chalk"));
|
|
76
76
|
var b = recast.types.builders;
|
|
77
77
|
var metroConfigPath = 'metro.config.js';
|
|
78
|
-
function
|
|
78
|
+
function patchMetroWithSentryConfig() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
+
var mod, showInstructions, success, saved;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
83
|
+
case 0: return [4 /*yield*/, parseMetroConfig()];
|
|
84
|
+
case 1:
|
|
85
|
+
mod = _a.sent();
|
|
86
|
+
showInstructions = function () {
|
|
87
|
+
return (0, clack_utils_1.showCopyPasteInstructions)(metroConfigPath, getMetroWithSentryConfigSnippet(true));
|
|
88
|
+
};
|
|
89
|
+
return [4 /*yield*/, patchMetroWithSentryConfigInMemory(mod, showInstructions)];
|
|
90
|
+
case 2:
|
|
91
|
+
success = _a.sent();
|
|
92
|
+
if (!success) {
|
|
93
|
+
return [2 /*return*/];
|
|
94
|
+
}
|
|
95
|
+
return [4 /*yield*/, writeMetroConfig(mod)];
|
|
96
|
+
case 3:
|
|
97
|
+
saved = _a.sent();
|
|
98
|
+
if (!saved) return [3 /*break*/, 4];
|
|
99
|
+
clack.log.success(chalk_1.default.green("".concat(chalk_1.default.cyan(metroConfigPath), " changes saved.")));
|
|
100
|
+
return [3 /*break*/, 6];
|
|
101
|
+
case 4:
|
|
102
|
+
clack.log.warn("Could not save changes to ".concat(chalk_1.default.cyan(metroConfigPath), ", please follow the manual steps."));
|
|
103
|
+
return [4 /*yield*/, showInstructions()];
|
|
104
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
105
|
+
case 6: return [2 /*return*/];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
exports.patchMetroWithSentryConfig = patchMetroWithSentryConfig;
|
|
111
|
+
function patchMetroWithSentryConfigInMemory(mod, showInstructions) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
+
var shouldContinue, configExpression, wrappedConfig, replacedModuleExportsRight, addedSentryMetroImport;
|
|
114
|
+
return __generator(this, function (_a) {
|
|
115
|
+
switch (_a.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
if (!(0, ast_utils_1.hasSentryContent)(mod.$ast)) return [3 /*break*/, 3];
|
|
118
|
+
return [4 /*yield*/, confirmPathMetroConfig()];
|
|
119
|
+
case 1:
|
|
120
|
+
shouldContinue = _a.sent();
|
|
121
|
+
if (!!shouldContinue) return [3 /*break*/, 3];
|
|
122
|
+
return [4 /*yield*/, showInstructions()];
|
|
123
|
+
case 2:
|
|
124
|
+
_a.sent();
|
|
125
|
+
return [2 /*return*/, false];
|
|
126
|
+
case 3:
|
|
127
|
+
configExpression = getModuleExportsAssignmentRight(mod.$ast);
|
|
128
|
+
if (!!configExpression) return [3 /*break*/, 5];
|
|
129
|
+
clack.log.warn('Could not find Metro config, please follow the manual steps.');
|
|
130
|
+
return [4 /*yield*/, showInstructions()];
|
|
131
|
+
case 4:
|
|
132
|
+
_a.sent();
|
|
133
|
+
return [2 /*return*/, false];
|
|
134
|
+
case 5:
|
|
135
|
+
wrappedConfig = wrapWithSentryConfig(configExpression);
|
|
136
|
+
replacedModuleExportsRight = replaceModuleExportsRight(mod.$ast, wrappedConfig);
|
|
137
|
+
if (!!replacedModuleExportsRight) return [3 /*break*/, 7];
|
|
138
|
+
clack.log.warn('Could not automatically wrap the config export, please follow the manual steps.');
|
|
139
|
+
return [4 /*yield*/, showInstructions()];
|
|
140
|
+
case 6:
|
|
141
|
+
_a.sent();
|
|
142
|
+
return [2 /*return*/, false];
|
|
143
|
+
case 7:
|
|
144
|
+
addedSentryMetroImport = addSentryMetroRequireToMetroConfig(mod.$ast);
|
|
145
|
+
if (!!addedSentryMetroImport) return [3 /*break*/, 9];
|
|
146
|
+
clack.log.warn('Could not add `@sentry/react-native/metro` import to Metro config, please follow the manual steps.');
|
|
147
|
+
return [4 /*yield*/, showInstructions()];
|
|
148
|
+
case 8:
|
|
149
|
+
_a.sent();
|
|
150
|
+
return [2 /*return*/, false];
|
|
151
|
+
case 9:
|
|
152
|
+
clack.log.success("Added Sentry Metro plugin to ".concat(chalk_1.default.cyan(metroConfigPath), "."));
|
|
153
|
+
return [2 /*return*/, true];
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
exports.patchMetroWithSentryConfigInMemory = patchMetroWithSentryConfigInMemory;
|
|
159
|
+
function patchMetroConfigWithSentrySerializer() {
|
|
79
160
|
return __awaiter(this, void 0, void 0, function () {
|
|
80
161
|
var mod, showInstructions, shouldContinue, configObj, addedSentrySerializer, addedSentrySerializerImport, saved;
|
|
81
162
|
return __generator(this, function (_a) {
|
|
@@ -84,7 +165,7 @@ function patchMetroConfig() {
|
|
|
84
165
|
case 1:
|
|
85
166
|
mod = _a.sent();
|
|
86
167
|
showInstructions = function () {
|
|
87
|
-
return (0, clack_utils_1.showCopyPasteInstructions)(metroConfigPath,
|
|
168
|
+
return (0, clack_utils_1.showCopyPasteInstructions)(metroConfigPath, getMetroSentrySerializerSnippet(true));
|
|
88
169
|
};
|
|
89
170
|
if (!(0, ast_utils_1.hasSentryContent)(mod.$ast)) return [3 /*break*/, 4];
|
|
90
171
|
return [4 /*yield*/, confirmPathMetroConfig()];
|
|
@@ -127,7 +208,7 @@ function patchMetroConfig() {
|
|
|
127
208
|
});
|
|
128
209
|
});
|
|
129
210
|
}
|
|
130
|
-
exports.
|
|
211
|
+
exports.patchMetroConfigWithSentrySerializer = patchMetroConfigWithSentrySerializer;
|
|
131
212
|
function unPatchMetroConfig() {
|
|
132
213
|
return __awaiter(this, void 0, void 0, function () {
|
|
133
214
|
var mod, removedAtLeastOneRequire, removedSerializerConfig, saved;
|
|
@@ -295,12 +376,41 @@ function addSentrySerializerRequireToMetroConfig(program) {
|
|
|
295
376
|
program.body.splice(lastRequireIndex + 1, 0, sentrySerializerRequire);
|
|
296
377
|
}
|
|
297
378
|
else {
|
|
298
|
-
// insert at the
|
|
299
|
-
program.body.
|
|
379
|
+
// insert at the beginning
|
|
380
|
+
program.body.unshift(sentrySerializerRequire);
|
|
300
381
|
}
|
|
301
382
|
return true;
|
|
302
383
|
}
|
|
303
384
|
exports.addSentrySerializerRequireToMetroConfig = addSentrySerializerRequireToMetroConfig;
|
|
385
|
+
function addSentryMetroRequireToMetroConfig(program) {
|
|
386
|
+
var lastRequireIndex = (0, ast_utils_1.getLastRequireIndex)(program);
|
|
387
|
+
var sentryMetroRequire = createSentryMetroRequire();
|
|
388
|
+
var sentryImportIndex = lastRequireIndex + 1;
|
|
389
|
+
if (sentryImportIndex < program.body.length) {
|
|
390
|
+
// insert after last require
|
|
391
|
+
program.body.splice(lastRequireIndex + 1, 0, sentryMetroRequire);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
// insert at the beginning
|
|
395
|
+
program.body.unshift(sentryMetroRequire);
|
|
396
|
+
}
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
exports.addSentryMetroRequireToMetroConfig = addSentryMetroRequireToMetroConfig;
|
|
400
|
+
function wrapWithSentryConfig(configObj) {
|
|
401
|
+
return b.callExpression(b.identifier('withSentryConfig'), [configObj]);
|
|
402
|
+
}
|
|
403
|
+
function replaceModuleExportsRight(program, wrappedConfig) {
|
|
404
|
+
var moduleExports = getModuleExports(program);
|
|
405
|
+
if (!moduleExports) {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
if (moduleExports.expression.type === 'AssignmentExpression') {
|
|
409
|
+
moduleExports.expression.right = wrappedConfig;
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
304
414
|
/**
|
|
305
415
|
* Creates const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');
|
|
306
416
|
*/
|
|
@@ -317,6 +427,22 @@ function createSentrySerializerRequire() {
|
|
|
317
427
|
])),
|
|
318
428
|
]);
|
|
319
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* Creates const {withSentryConfig} = require('@sentry/react-native/metro');
|
|
432
|
+
*/
|
|
433
|
+
function createSentryMetroRequire() {
|
|
434
|
+
return b.variableDeclaration('const', [
|
|
435
|
+
b.variableDeclarator(b.objectPattern([
|
|
436
|
+
b.objectProperty.from({
|
|
437
|
+
key: b.identifier('withSentryConfig'),
|
|
438
|
+
value: b.identifier('withSentryConfig'),
|
|
439
|
+
shorthand: true,
|
|
440
|
+
}),
|
|
441
|
+
]), b.callExpression(b.identifier('require'), [
|
|
442
|
+
b.literal('@sentry/react-native/metro'),
|
|
443
|
+
])),
|
|
444
|
+
]);
|
|
445
|
+
}
|
|
320
446
|
function confirmPathMetroConfig() {
|
|
321
447
|
return __awaiter(this, void 0, void 0, function () {
|
|
322
448
|
var shouldContinue;
|
|
@@ -367,8 +493,35 @@ function getMetroConfigObject(program) {
|
|
|
367
493
|
Sentry.setTag('metro-config', 'config-variable');
|
|
368
494
|
return configVariable.declarations[0].init;
|
|
369
495
|
}
|
|
496
|
+
return getModuleExportsObject(program);
|
|
497
|
+
}
|
|
498
|
+
exports.getMetroConfigObject = getMetroConfigObject;
|
|
499
|
+
function getModuleExportsObject(program) {
|
|
500
|
+
// check module.exports
|
|
501
|
+
var moduleExports = getModuleExportsAssignmentRight(program);
|
|
502
|
+
if ((moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.type) === 'ObjectExpression') {
|
|
503
|
+
return moduleExports;
|
|
504
|
+
}
|
|
505
|
+
Sentry.setTag('metro-config', 'not-found');
|
|
506
|
+
return undefined;
|
|
507
|
+
}
|
|
508
|
+
function getModuleExportsAssignmentRight(program) {
|
|
370
509
|
// check module.exports
|
|
371
|
-
var moduleExports = program
|
|
510
|
+
var moduleExports = getModuleExports(program);
|
|
511
|
+
if ((moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.expression.type) === 'AssignmentExpression' &&
|
|
512
|
+
(moduleExports.expression.right.type === 'ObjectExpression' ||
|
|
513
|
+
moduleExports.expression.right.type === 'CallExpression' ||
|
|
514
|
+
moduleExports.expression.right.type === 'Identifier')) {
|
|
515
|
+
Sentry.setTag('metro-config', 'module-exports');
|
|
516
|
+
return moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.expression.right;
|
|
517
|
+
}
|
|
518
|
+
Sentry.setTag('metro-config', 'not-found');
|
|
519
|
+
return undefined;
|
|
520
|
+
}
|
|
521
|
+
exports.getModuleExportsAssignmentRight = getModuleExportsAssignmentRight;
|
|
522
|
+
function getModuleExports(program) {
|
|
523
|
+
// find module.exports
|
|
524
|
+
return program.body.find(function (s) {
|
|
372
525
|
if (s.type === 'ExpressionStatement' &&
|
|
373
526
|
s.expression.type === 'AssignmentExpression' &&
|
|
374
527
|
s.expression.left.type === 'MemberExpression' &&
|
|
@@ -380,19 +533,15 @@ function getMetroConfigObject(program) {
|
|
|
380
533
|
}
|
|
381
534
|
return false;
|
|
382
535
|
});
|
|
383
|
-
if ((moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.expression).right.type ===
|
|
384
|
-
'ObjectExpression') {
|
|
385
|
-
Sentry.setTag('metro-config', 'module-exports');
|
|
386
|
-
return (moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.expression)
|
|
387
|
-
.right;
|
|
388
|
-
}
|
|
389
|
-
Sentry.setTag('metro-config', 'not-found');
|
|
390
|
-
return undefined;
|
|
391
536
|
}
|
|
392
|
-
|
|
393
|
-
function getMetroConfigSnippet(colors) {
|
|
537
|
+
function getMetroSentrySerializerSnippet(colors) {
|
|
394
538
|
return (0, clack_utils_1.makeCodeSnippet)(colors, function (unchanged, plus, _) {
|
|
395
539
|
return unchanged("const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\";\n".concat(plus("const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');"), "\n\nconst config = {\n ").concat(plus("serializer: {\n customSerializer: createSentryMetroSerializer(),\n },"), "\n};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);\n"));
|
|
396
540
|
});
|
|
397
541
|
}
|
|
542
|
+
function getMetroWithSentryConfigSnippet(colors) {
|
|
543
|
+
return (0, clack_utils_1.makeCodeSnippet)(colors, function (unchanged, plus, _) {
|
|
544
|
+
return unchanged("const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\";\n".concat(plus("const {withSentryConfig} = require('@sentry/react-native/metro');"), "\n\nconst config = {};\n\nmodule.exports = ").concat(plus('withSentryConfig('), "mergeConfig(getDefaultConfig(__dirname), config)").concat(plus(')'), ";\n"));
|
|
545
|
+
});
|
|
546
|
+
}
|
|
398
547
|
//# sourceMappingURL=metro.js.map
|
|
@@ -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;AAE9B,6CAAiC;AAGjC,gDAA0B;AAE1B,IAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC,IAAM,eAAe,GAAG,iBAAiB,CAAC;AAE1C,SAA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O,IAAA,6BAAe,EAAC,MAAM,EAAE,UAAC,SAAS,EAAE,IAAI,EAAE,CAAC;QAChD,OAAA,SAAS,CAAC,6FACZ,IAAI,CACJ,4GAA4G,CAC7G,qCAGG,IAAI,CAAC,2EAEJ,CAAC,iFAIL,CAAC;IAZE,CAYF,CACC,CAAC;AACJ,CAAC","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { ProxifiedModule, parseModule, writeFile } from 'magicast';\nimport * as fs from 'fs';\nimport * as Sentry from '@sentry/node';\n\nimport {\n getLastRequireIndex,\n hasSentryContent,\n removeRequire,\n} from '../utils/ast-utils';\nimport {\n abortIfCancelled,\n makeCodeSnippet,\n showCopyPasteInstructions,\n} from '../utils/clack-utils';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\nimport chalk from 'chalk';\n\nconst b = recast.types.builders;\n\nconst metroConfigPath = 'metro.config.js';\n\nexport async function patchMetroConfig() {\n const mod = await parseMetroConfig();\n\n const showInstructions = () =>\n showCopyPasteInstructions(metroConfigPath, getMetroConfigSnippet(true));\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await confirmPathMetroConfig();\n if (!shouldContinue) {\n return await showInstructions();\n }\n }\n\n const configObj = getMetroConfigObject(mod.$ast as t.Program);\n if (!configObj) {\n clack.log.warn(\n 'Could not find Metro config object, please follow the manual steps.',\n );\n return showInstructions();\n }\n\n const addedSentrySerializer = addSentrySerializerToMetroConfig(configObj);\n if (!addedSentrySerializer) {\n clack.log.warn(\n 'Could not add Sentry serializer to Metro config, please follow the manual steps.',\n );\n return await showInstructions();\n }\n\n const addedSentrySerializerImport = addSentrySerializerRequireToMetroConfig(\n mod.$ast as t.Program,\n );\n if (!addedSentrySerializerImport) {\n clack.log.warn(\n 'Could not add Sentry serializer import to Metro config, please follow the manual steps.',\n );\n return await showInstructions();\n }\n\n clack.log.success(\n `Added Sentry Metro plugin to ${chalk.cyan(metroConfigPath)}.`,\n );\n\n const saved = await writeMetroConfig(mod);\n if (saved) {\n clack.log.success(\n chalk.green(`${chalk.cyan(metroConfigPath)} changes saved.`),\n );\n } else {\n clack.log.warn(\n `Could not save changes to ${chalk.cyan(\n metroConfigPath,\n )}, please follow the manual steps.`,\n );\n return await showInstructions();\n }\n}\n\nexport async function unPatchMetroConfig() {\n const mod = await parseMetroConfig();\n\n const removedAtLeastOneRequire = removeSentryRequire(mod.$ast as t.Program);\n const removedSerializerConfig = removeSentrySerializerFromMetroConfig(\n mod.$ast as t.Program,\n );\n\n if (removedAtLeastOneRequire || removedSerializerConfig) {\n const saved = await writeMetroConfig(mod);\n if (saved) {\n clack.log.success(\n `Removed Sentry Metro plugin from ${chalk.cyan(metroConfigPath)}.`,\n );\n }\n } else {\n clack.log.warn(\n `No Sentry Metro plugin found in ${chalk.cyan(metroConfigPath)}.`,\n );\n }\n}\n\nexport function removeSentrySerializerFromMetroConfig(\n program: t.Program,\n): boolean {\n const configObject = getMetroConfigObject(program);\n if (!configObject) {\n return false;\n }\n\n const serializerProp = getSerializerProp(configObject);\n if ('invalid' === serializerProp || 'undefined' === serializerProp) {\n return false;\n }\n\n const customSerializerProp = getCustomSerializerProp(serializerProp);\n if (\n 'invalid' === customSerializerProp ||\n 'undefined' === customSerializerProp\n ) {\n return false;\n }\n\n if (\n serializerProp.value.type === 'ObjectExpression' &&\n customSerializerProp.value.type === 'CallExpression' &&\n customSerializerProp.value.callee.type === 'Identifier' &&\n customSerializerProp.value.callee.name === 'createSentryMetroSerializer'\n ) {\n if (customSerializerProp.value.arguments.length === 0) {\n // FROM serializer: { customSerializer: createSentryMetroSerializer() }\n // TO serializer: {}\n let removed = false;\n serializerProp.value.properties = serializerProp.value.properties.filter(\n (p) => {\n if (\n p.type === 'ObjectProperty' &&\n p.key.type === 'Identifier' &&\n p.key.name === 'customSerializer'\n ) {\n removed = true;\n return false;\n }\n return true;\n },\n );\n\n if (removed) {\n return true;\n }\n } else {\n if (customSerializerProp.value.arguments[0].type !== 'SpreadElement') {\n // FROM serializer: { customSerializer: createSentryMetroSerializer(wrapperSerializer) }\n // TO serializer: { customSerializer: wrapperSerializer }\n customSerializerProp.value = customSerializerProp.value.arguments[0];\n return true;\n }\n }\n }\n\n return false;\n}\n\nexport function removeSentryRequire(program: t.Program): boolean {\n return removeRequire(program, '@sentry');\n}\n\nasync function parseMetroConfig(): Promise<ProxifiedModule> {\n const metroConfigContent = (\n await fs.promises.readFile(metroConfigPath)\n ).toString();\n\n return parseModule(metroConfigContent);\n}\n\nasync function writeMetroConfig(mod: ProxifiedModule): Promise<boolean> {\n try {\n await writeFile(mod.$ast, metroConfigPath);\n } catch (e) {\n clack.log.error(\n `Failed to write to ${chalk.cyan(metroConfigPath)}: ${JSON.stringify(e)}`,\n );\n return false;\n }\n return true;\n}\n\nexport function addSentrySerializerToMetroConfig(\n configObj: t.ObjectExpression,\n): boolean {\n const serializerProp = getSerializerProp(configObj);\n if ('invalid' === serializerProp) {\n return false;\n }\n\n // case 1: serializer property doesn't exist yet, so we can just add it\n if ('undefined' === serializerProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('serializer'),\n b.objectExpression([\n b.objectProperty(\n b.identifier('customSerializer'),\n b.callExpression(b.identifier('createSentryMetroSerializer'), []),\n ),\n ]),\n ),\n );\n return true;\n }\n\n const customSerializerProp = getCustomSerializerProp(serializerProp);\n // case 2: serializer.customSerializer property doesn't exist yet, so we just add it\n if (\n 'undefined' === customSerializerProp &&\n serializerProp.value.type === 'ObjectExpression'\n ) {\n serializerProp.value.properties.push(\n b.objectProperty(\n b.identifier('customSerializer'),\n b.callExpression(b.identifier('createSentryMetroSerializer'), []),\n ),\n );\n return true;\n }\n\n return false;\n}\n\nfunction getCustomSerializerProp(\n prop: t.ObjectProperty,\n): t.ObjectProperty | 'undefined' | 'invalid' {\n const customSerializerProp =\n prop.value.type === 'ObjectExpression' &&\n prop.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'customSerializer',\n );\n\n if (!customSerializerProp) {\n return 'undefined';\n }\n\n if (customSerializerProp.type === 'ObjectProperty') {\n return customSerializerProp;\n }\n\n return 'invalid';\n}\n\nfunction getSerializerProp(\n obj: t.ObjectExpression,\n): t.ObjectProperty | 'undefined' | 'invalid' {\n const serializerProp = obj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'serializer',\n );\n\n if (!serializerProp) {\n return 'undefined';\n }\n\n if (serializerProp.type === 'ObjectProperty') {\n return serializerProp;\n }\n\n return 'invalid';\n}\n\nexport function addSentrySerializerRequireToMetroConfig(\n program: t.Program,\n): boolean {\n const lastRequireIndex = getLastRequireIndex(program);\n const sentrySerializerRequire = createSentrySerializerRequire();\n const sentryImportIndex = lastRequireIndex + 1;\n if (sentryImportIndex < program.body.length) {\n // insert after last require\n program.body.splice(lastRequireIndex + 1, 0, sentrySerializerRequire);\n } else {\n // insert at the end\n program.body.push(sentrySerializerRequire);\n }\n return true;\n}\n\n/**\n * Creates const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');\n */\nfunction createSentrySerializerRequire() {\n return b.variableDeclaration('const', [\n b.variableDeclarator(\n b.objectPattern([\n b.objectProperty.from({\n key: b.identifier('createSentryMetroSerializer'),\n value: b.identifier('createSentryMetroSerializer'),\n shorthand: true,\n }),\n ]),\n b.callExpression(b.identifier('require'), [\n b.literal('@sentry/react-native/dist/js/tools/sentryMetroSerializer'),\n ]),\n ),\n ]);\n}\n\nasync function confirmPathMetroConfig() {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `Metro Config already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Metro plugin',\n value: true,\n },\n {\n label: 'No, show me instructions to manually add the plugin',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n if (!shouldContinue) {\n Sentry.setTag('ast-mod-fail-reason', 'has-sentry-content');\n }\n\n return shouldContinue;\n}\n\n/**\n * Returns value from `module.exports = value` or `const config = value`\n */\nexport function getMetroConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n // check config variable\n const configVariable = program.body.find((s) => {\n if (\n s.type === 'VariableDeclaration' &&\n s.declarations.length === 1 &&\n s.declarations[0].type === 'VariableDeclarator' &&\n s.declarations[0].id.type === 'Identifier' &&\n s.declarations[0].id.name === 'config'\n ) {\n return true;\n }\n return false;\n }) as t.VariableDeclaration | undefined;\n\n if (\n configVariable?.declarations[0].type === 'VariableDeclarator' &&\n configVariable?.declarations[0].init?.type === 'ObjectExpression'\n ) {\n Sentry.setTag('metro-config', 'config-variable');\n return configVariable.declarations[0].init;\n }\n\n // check module.exports\n const moduleExports = program.body.find((s) => {\n if (\n s.type === 'ExpressionStatement' &&\n s.expression.type === 'AssignmentExpression' &&\n s.expression.left.type === 'MemberExpression' &&\n s.expression.left.object.type === 'Identifier' &&\n s.expression.left.object.name === 'module' &&\n s.expression.left.property.type === 'Identifier' &&\n s.expression.left.property.name === 'exports'\n ) {\n return true;\n }\n return false;\n }) as t.ExpressionStatement | undefined;\n\n if (\n (moduleExports?.expression as t.AssignmentExpression).right.type ===\n 'ObjectExpression'\n ) {\n Sentry.setTag('metro-config', 'module-exports');\n return (moduleExports?.expression as t.AssignmentExpression)\n .right as t.ObjectExpression;\n }\n\n Sentry.setTag('metro-config', 'not-found');\n return undefined;\n}\n\nfunction getMetroConfigSnippet(colors: boolean) {\n return makeCodeSnippet(colors, (unchanged, plus, _) =>\n unchanged(`const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');\";\n${plus(\n \"const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');\",\n)}\n\nconst config = {\n ${plus(`serializer: {\n customSerializer: createSentryMetroSerializer(),\n },`)}\n};\n\nmodule.exports = mergeConfig(getDefaultConfig(__dirname), config);\n`),\n );\n}\n"]}
|
|
1
|
+
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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\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"]}
|
|
@@ -6,6 +6,7 @@ export declare const RN_HUMAN_NAME = "React Native";
|
|
|
6
6
|
export declare const SUPPORTED_RN_RANGE = ">=0.69.0";
|
|
7
7
|
export declare const SDK_XCODE_SCRIPTS_SUPPORTED_SDK_RANGE = ">=5.11.0";
|
|
8
8
|
export declare const SDK_SENTRY_METRO_PLUGIN_SUPPORTED_SDK_RANGE = ">=5.11.0";
|
|
9
|
+
export declare const SDK_SENTRY_METRO_WITH_SENTRY_CONFIG_SUPPORTED_SDK_RANGE = ">=5.17.0";
|
|
9
10
|
export type RNCliSetupConfigContent = Pick<Required<CliSetupConfigContent>, 'authToken' | 'org' | 'project' | 'url'>;
|
|
10
11
|
export declare function runReactNativeWizard(params: ReactNativeWizardOptions): Promise<void>;
|
|
11
12
|
export declare function runReactNativeWizardWithTelemetry(options: ReactNativeWizardOptions): Promise<void>;
|
|
@@ -73,7 +73,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
73
73
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
74
74
|
};
|
|
75
75
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
|
-
exports.runReactNativeWizardWithTelemetry = exports.runReactNativeWizard = exports.SDK_SENTRY_METRO_PLUGIN_SUPPORTED_SDK_RANGE = exports.SDK_XCODE_SCRIPTS_SUPPORTED_SDK_RANGE = exports.SUPPORTED_RN_RANGE = exports.RN_HUMAN_NAME = exports.RN_PACKAGE = exports.RN_SDK_PACKAGE = void 0;
|
|
76
|
+
exports.runReactNativeWizardWithTelemetry = exports.runReactNativeWizard = exports.SDK_SENTRY_METRO_WITH_SENTRY_CONFIG_SUPPORTED_SDK_RANGE = exports.SDK_SENTRY_METRO_PLUGIN_SUPPORTED_SDK_RANGE = exports.SDK_XCODE_SCRIPTS_SUPPORTED_SDK_RANGE = exports.SUPPORTED_RN_RANGE = exports.RN_HUMAN_NAME = exports.RN_PACKAGE = exports.RN_SDK_PACKAGE = void 0;
|
|
77
77
|
/* eslint-disable max-lines */
|
|
78
78
|
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
79
79
|
var prompts_1 = __importDefault(require("@clack/prompts"));
|
|
@@ -106,6 +106,8 @@ exports.SUPPORTED_RN_RANGE = '>=0.69.0';
|
|
|
106
106
|
exports.SDK_XCODE_SCRIPTS_SUPPORTED_SDK_RANGE = '>=5.11.0';
|
|
107
107
|
// The following SDK version ship with Sentry Metro plugin
|
|
108
108
|
exports.SDK_SENTRY_METRO_PLUGIN_SUPPORTED_SDK_RANGE = '>=5.11.0';
|
|
109
|
+
// The following SDK version shipped `withSentryConfig`
|
|
110
|
+
exports.SDK_SENTRY_METRO_WITH_SENTRY_CONFIG_SUPPORTED_SDK_RANGE = '>=5.17.0';
|
|
109
111
|
function runReactNativeWizard(params) {
|
|
110
112
|
return __awaiter(this, void 0, void 0, function () {
|
|
111
113
|
return __generator(this, function (_a) {
|
|
@@ -218,25 +220,22 @@ function runReactNativeWizardWithTelemetry(options) {
|
|
|
218
220
|
exports.runReactNativeWizardWithTelemetry = runReactNativeWizardWithTelemetry;
|
|
219
221
|
function addSentryToMetroConfig(_a) {
|
|
220
222
|
var sdkVersion = _a.sdkVersion;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
});
|
|
223
|
+
if (sdkVersion &&
|
|
224
|
+
(0, semver_1.fulfillsVersionRange)({
|
|
225
|
+
version: sdkVersion,
|
|
226
|
+
acceptableVersions: exports.SDK_SENTRY_METRO_WITH_SENTRY_CONFIG_SUPPORTED_SDK_RANGE,
|
|
227
|
+
canBeLatest: true,
|
|
228
|
+
})) {
|
|
229
|
+
return (0, metro_1.patchMetroWithSentryConfig)();
|
|
230
|
+
}
|
|
231
|
+
if (sdkVersion &&
|
|
232
|
+
(0, semver_1.fulfillsVersionRange)({
|
|
233
|
+
version: sdkVersion,
|
|
234
|
+
acceptableVersions: exports.SDK_SENTRY_METRO_PLUGIN_SUPPORTED_SDK_RANGE,
|
|
235
|
+
canBeLatest: true,
|
|
236
|
+
})) {
|
|
237
|
+
return (0, metro_1.patchMetroConfigWithSentrySerializer)();
|
|
238
|
+
}
|
|
240
239
|
}
|
|
241
240
|
function addSentryInit(_a) {
|
|
242
241
|
var dsn = _a.dsn;
|