@sentry/wizard 3.9.2 → 3.11.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 +58 -6
- package/dist/lib/Constants.d.ts +2 -0
- package/dist/lib/Constants.js +10 -0
- package/dist/lib/Constants.js.map +1 -1
- package/dist/lib/Steps/ChooseIntegration.js +15 -4
- package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
- package/dist/lib/Steps/Integrations/Android.d.ts +9 -0
- package/dist/lib/Steps/Integrations/Android.js +86 -0
- package/dist/lib/Steps/Integrations/Android.js.map +1 -0
- package/dist/lib/Steps/Integrations/Cordova.js +5 -1
- package/dist/lib/Steps/Integrations/Cordova.js.map +1 -1
- package/dist/lib/Steps/Integrations/ReactNative.js +3 -3
- package/dist/lib/Steps/Integrations/ReactNative.js.map +1 -1
- package/dist/lib/Steps/Integrations/Remix.d.ts +12 -0
- package/dist/lib/Steps/Integrations/Remix.js +98 -0
- package/dist/lib/Steps/Integrations/Remix.js.map +1 -0
- package/dist/lib/Steps/PromptForParameters.js +36 -3
- package/dist/lib/Steps/PromptForParameters.js.map +1 -1
- package/dist/lib/Steps/SentryProjectSelector.js +1 -1
- package/dist/lib/Steps/SentryProjectSelector.js.map +1 -1
- package/dist/package.json +4 -3
- package/dist/src/android/android-wizard.d.ts +2 -0
- package/dist/src/android/android-wizard.js +217 -0
- package/dist/src/android/android-wizard.js.map +1 -0
- package/dist/src/android/code-tools.d.ts +39 -0
- package/dist/src/android/code-tools.js +161 -0
- package/dist/src/android/code-tools.js.map +1 -0
- package/dist/src/android/gradle.d.ts +62 -0
- package/dist/src/android/gradle.js +281 -0
- package/dist/src/android/gradle.js.map +1 -0
- package/dist/src/android/manifest.d.ts +57 -0
- package/dist/src/android/manifest.js +183 -0
- package/dist/src/android/manifest.js.map +1 -0
- package/dist/src/android/templates.d.ts +11 -0
- package/dist/src/android/templates.js +34 -0
- package/dist/src/android/templates.js.map +1 -0
- package/dist/src/apple/apple-wizard.js +123 -64
- package/dist/src/apple/apple-wizard.js.map +1 -1
- package/dist/src/apple/cocoapod.js +4 -3
- package/dist/src/apple/cocoapod.js.map +1 -1
- package/dist/src/apple/code-tools.d.ts +1 -1
- package/dist/src/apple/code-tools.js +43 -19
- package/dist/src/apple/code-tools.js.map +1 -1
- package/dist/src/apple/fastlane.d.ts +1 -1
- package/dist/src/apple/fastlane.js +12 -6
- package/dist/src/apple/fastlane.js.map +1 -1
- package/dist/src/apple/templates.d.ts +2 -2
- package/dist/src/apple/templates.js +4 -4
- package/dist/src/apple/templates.js.map +1 -1
- package/dist/src/apple/xcode-manager.d.ts +19 -3
- package/dist/src/apple/xcode-manager.js +126 -24
- package/dist/src/apple/xcode-manager.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +49 -11
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.d.ts +2 -0
- package/dist/src/nextjs/templates.js +6 -2
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/remix/codemods/handle-error.d.ts +2 -0
- package/dist/src/remix/codemods/handle-error.js +70 -0
- package/dist/src/remix/codemods/handle-error.js.map +1 -0
- package/dist/src/remix/codemods/root-v1.d.ts +1 -0
- package/dist/src/remix/codemods/root-v1.js +133 -0
- package/dist/src/remix/codemods/root-v1.js.map +1 -0
- package/dist/src/remix/codemods/root-v2.d.ts +1 -0
- package/dist/src/remix/codemods/root-v2.js +134 -0
- package/dist/src/remix/codemods/root-v2.js.map +1 -0
- package/dist/src/remix/remix-wizard.d.ts +2 -0
- package/dist/src/remix/remix-wizard.js +196 -0
- package/dist/src/remix/remix-wizard.js.map +1 -0
- package/dist/src/remix/sdk-setup.d.ts +18 -0
- package/dist/src/remix/sdk-setup.js +293 -0
- package/dist/src/remix/sdk-setup.js.map +1 -0
- package/dist/src/remix/templates.d.ts +2 -0
- package/dist/src/remix/templates.js +6 -0
- package/dist/src/remix/templates.js.map +1 -0
- package/dist/src/remix/utils.d.ts +6 -0
- package/dist/src/remix/utils.js +55 -0
- package/dist/src/remix/utils.js.map +1 -0
- package/dist/src/sourcemaps/sourcemaps-wizard.js +49 -25
- package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
- package/dist/src/sourcemaps/tools/nextjs.js +1 -1
- package/dist/src/sourcemaps/tools/nextjs.js.map +1 -1
- package/dist/src/sourcemaps/tools/remix.d.ts +3 -0
- package/dist/src/sourcemaps/tools/remix.js +125 -0
- package/dist/src/sourcemaps/tools/remix.js.map +1 -0
- package/dist/src/sourcemaps/tools/sentry-cli.js +19 -16
- package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
- package/dist/src/sourcemaps/tools/vite.d.ts +2 -1
- package/dist/src/sourcemaps/tools/vite.js +99 -12
- package/dist/src/sourcemaps/tools/vite.js.map +1 -1
- package/dist/src/sourcemaps/utils/detect-tool.d.ts +1 -1
- package/dist/src/sourcemaps/utils/detect-tool.js +1 -0
- package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup.js +3 -3
- package/dist/src/sveltekit/sdk-setup.js.map +1 -1
- package/dist/src/sveltekit/sveltekit-wizard.js +34 -44
- package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
- package/dist/src/telemetry.js +1 -0
- package/dist/src/telemetry.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +2 -2
- package/dist/src/utils/ast-utils.js +7 -7
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +23 -28
- package/dist/src/utils/clack-utils.js +287 -244
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/package-manager.d.ts +10 -0
- package/dist/{lib/Helper/PackageManager.js → src/utils/package-manager.js} +42 -74
- package/dist/src/utils/package-manager.js.map +1 -0
- package/dist/src/utils/release-registry.d.ts +1 -0
- package/dist/src/utils/release-registry.js +68 -0
- package/dist/src/utils/release-registry.js.map +1 -0
- package/dist/src/utils/sentrycli-utils.d.ts +4 -0
- package/dist/src/utils/sentrycli-utils.js +41 -0
- package/dist/src/utils/sentrycli-utils.js.map +1 -0
- package/dist/test/sourcemaps/tools/vite.test.d.ts +1 -0
- package/dist/test/sourcemaps/tools/vite.test.js +132 -0
- package/dist/test/sourcemaps/tools/vite.test.js.map +1 -0
- package/lib/Constants.ts +10 -0
- package/lib/Steps/ChooseIntegration.ts +14 -3
- package/lib/Steps/Integrations/Android.ts +23 -0
- package/lib/Steps/Integrations/Cordova.ts +5 -1
- package/lib/Steps/Integrations/ReactNative.ts +9 -3
- package/lib/Steps/Integrations/Remix.ts +32 -0
- package/lib/Steps/PromptForParameters.ts +48 -3
- package/lib/Steps/SentryProjectSelector.ts +3 -1
- package/package.json +4 -3
- package/src/android/android-wizard.ts +196 -0
- package/src/android/code-tools.ts +156 -0
- package/src/android/gradle.ts +245 -0
- package/src/android/manifest.ts +180 -0
- package/src/android/templates.ts +88 -0
- package/src/apple/apple-wizard.ts +113 -35
- package/src/apple/cocoapod.ts +6 -3
- package/src/apple/code-tools.ts +46 -18
- package/src/apple/fastlane.ts +6 -12
- package/src/apple/templates.ts +2 -8
- package/src/apple/xcode-manager.ts +167 -25
- package/src/nextjs/nextjs-wizard.ts +72 -8
- package/src/nextjs/templates.ts +16 -2
- package/src/remix/codemods/handle-error.ts +67 -0
- package/src/remix/codemods/root-v1.ts +91 -0
- package/src/remix/codemods/root-v2.ts +84 -0
- package/src/remix/remix-wizard.ts +132 -0
- package/src/remix/sdk-setup.ts +300 -0
- package/src/remix/templates.ts +15 -0
- package/src/remix/utils.ts +41 -0
- package/src/sourcemaps/sourcemaps-wizard.ts +28 -5
- package/src/sourcemaps/tools/nextjs.ts +2 -2
- package/src/sourcemaps/tools/remix.ts +90 -0
- package/src/sourcemaps/tools/sentry-cli.ts +8 -7
- package/src/sourcemaps/tools/vite.ts +136 -6
- package/src/sourcemaps/utils/detect-tool.ts +4 -1
- package/src/sveltekit/sdk-setup.ts +4 -4
- package/src/sveltekit/sveltekit-wizard.ts +5 -14
- package/src/telemetry.ts +2 -0
- package/src/utils/ast-utils.ts +7 -5
- package/src/utils/clack-utils.ts +366 -258
- package/src/utils/package-manager.ts +61 -0
- package/src/utils/release-registry.ts +19 -0
- package/src/utils/sentrycli-utils.ts +22 -0
- package/test/sourcemaps/tools/vite.test.ts +149 -0
- package/dist/lib/Helper/PackageManager.d.ts +0 -22
- package/dist/lib/Helper/PackageManager.js.map +0 -1
- package/dist/src/utils/vendor/clack-custom-select.d.ts +0 -21
- package/dist/src/utils/vendor/clack-custom-select.js +0 -137
- package/dist/src/utils/vendor/clack-custom-select.js.map +0 -1
- package/lib/Helper/PackageManager.ts +0 -59
- package/src/utils/vendor/clack-custom-select.ts +0 -160
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.getNamespace = exports.addGradlePlugin = exports.selectAppFile = void 0;
|
|
66
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
67
|
+
var fs = __importStar(require("fs"));
|
|
68
|
+
var clack_utils_1 = require("../utils/clack-utils");
|
|
69
|
+
var templates_1 = require("./templates");
|
|
70
|
+
var bash = __importStar(require("../utils/bash"));
|
|
71
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
72
|
+
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
73
|
+
var clack = __importStar(require("@clack/prompts"));
|
|
74
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
75
|
+
var release_registry_1 = require("../utils/release-registry");
|
|
76
|
+
/**
|
|
77
|
+
* A Gradle project may contain multiple modules, some of them may be applications, some of them may be libraries.
|
|
78
|
+
* We are only interested in applications. For example:
|
|
79
|
+
*
|
|
80
|
+
* myproject/
|
|
81
|
+
* app/
|
|
82
|
+
* lib1/
|
|
83
|
+
* lib2/
|
|
84
|
+
* wearApp/
|
|
85
|
+
*
|
|
86
|
+
* In this case^ we are interested in app/ and wearApp/
|
|
87
|
+
*
|
|
88
|
+
* @param buildGradleFiles a list of build.gradle(.kts) paths that contain the com.android.application plugin
|
|
89
|
+
* @returns the selected project for setting up
|
|
90
|
+
*/
|
|
91
|
+
function selectAppFile(buildGradleFiles) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var appFiles, index, file, text, appFile_1, appFile;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
appFiles = [];
|
|
98
|
+
for (index = 0; index < buildGradleFiles.length; index++) {
|
|
99
|
+
file = buildGradleFiles[index];
|
|
100
|
+
text = fs.readFileSync(file, 'utf8');
|
|
101
|
+
if (/\(?["']com\.android\.application["']\)?(?!.*\S)/.test(text)) {
|
|
102
|
+
appFiles.push(file);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (!(appFiles.length === 0)) return [3 /*break*/, 2];
|
|
106
|
+
Sentry.setTag('custom-build-logic', true);
|
|
107
|
+
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.text({
|
|
108
|
+
message: "Unable to find your app's directory. \n Please enter the relative path to your app's build.gradle file from the root project (e.g. \"app/build.gradle.kts\")",
|
|
109
|
+
}))];
|
|
110
|
+
case 1:
|
|
111
|
+
appFile_1 = _a.sent();
|
|
112
|
+
return [2 /*return*/, appFile_1];
|
|
113
|
+
case 2:
|
|
114
|
+
if (!(appFiles.length === 1)) return [3 /*break*/, 3];
|
|
115
|
+
Sentry.setTag('multiple-projects', false);
|
|
116
|
+
appFile = appFiles[0];
|
|
117
|
+
return [3 /*break*/, 5];
|
|
118
|
+
case 3:
|
|
119
|
+
Sentry.setTag('multiple-projects', true);
|
|
120
|
+
return [4 /*yield*/, (0, clack_utils_1.askForItemSelection)(appFiles, 'Which project do you want to add Sentry to?')];
|
|
121
|
+
case 4:
|
|
122
|
+
appFile = (_a.sent()).value;
|
|
123
|
+
_a.label = 5;
|
|
124
|
+
case 5:
|
|
125
|
+
Sentry.setTag('custom-build-logic', false);
|
|
126
|
+
return [2 /*return*/, appFile];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
exports.selectAppFile = selectAppFile;
|
|
132
|
+
/**
|
|
133
|
+
* Patches a build.gradle(.kts) file that contains `com.android.application` plugin.
|
|
134
|
+
* There are multiple cases we have to handle here:
|
|
135
|
+
* - An existing `plugins {}` block:
|
|
136
|
+
* - We just have to add our plugin inside the block
|
|
137
|
+
* - No existing `plugins {}` block
|
|
138
|
+
* - We have to add the entire block in the beginning of the file, BUT *after imports*
|
|
139
|
+
*
|
|
140
|
+
* For example (2nd case):
|
|
141
|
+
*
|
|
142
|
+
* ```
|
|
143
|
+
* import net.ltgt.gradle.errorprone.errorprone
|
|
144
|
+
*
|
|
145
|
+
* // our plugins block goes here <--
|
|
146
|
+
* plugins {
|
|
147
|
+
* id("io.sentry.android.gradle") version "3.12.0"
|
|
148
|
+
* }
|
|
149
|
+
*
|
|
150
|
+
* apply(plugin = "com.android.application")
|
|
151
|
+
*
|
|
152
|
+
* android {
|
|
153
|
+
* ...
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* In the end we run `./gradlew` to verify the config is build-able and not broken.
|
|
158
|
+
*
|
|
159
|
+
* @param appFile the selected Gradle application project
|
|
160
|
+
* @returns true if successfully added Sentry Gradle config, false otherwise
|
|
161
|
+
*/
|
|
162
|
+
function addGradlePlugin(appFile, orgSlug, projectSlug) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
164
|
+
var gradleScript, pluginVersion, pluginsBlockMatch, newGradleScript, regex, importsMatch, insertIndex, insertIndex, buildSpinner, e_1;
|
|
165
|
+
return __generator(this, function (_a) {
|
|
166
|
+
switch (_a.label) {
|
|
167
|
+
case 0:
|
|
168
|
+
gradleScript = fs.readFileSync(appFile, 'utf8');
|
|
169
|
+
if (/\(?["']io\.sentry\.android\.gradle["']\)?/.test(gradleScript)) {
|
|
170
|
+
// sentry gradle plugin is already installed
|
|
171
|
+
clack.log.success(chalk_1.default.greenBright("".concat(chalk_1.default.bold('Sentry Gradle plugin'), " is already added to the project.")));
|
|
172
|
+
maybeAddSourceContextConfig(appFile, gradleScript, orgSlug, projectSlug);
|
|
173
|
+
return [2 /*return*/, true];
|
|
174
|
+
}
|
|
175
|
+
return [4 /*yield*/, (0, release_registry_1.fetchSdkVersion)('sentry.java.android.gradle-plugin')];
|
|
176
|
+
case 1:
|
|
177
|
+
pluginVersion = _a.sent();
|
|
178
|
+
pluginsBlockMatch = /plugins\s*{[^{}]*}/.exec(gradleScript);
|
|
179
|
+
if (!pluginsBlockMatch) {
|
|
180
|
+
regex = /import\s+[\w.]+/gm;
|
|
181
|
+
importsMatch = regex.exec(gradleScript);
|
|
182
|
+
insertIndex = 0;
|
|
183
|
+
while (importsMatch) {
|
|
184
|
+
insertIndex = importsMatch.index + importsMatch[0].length + 1;
|
|
185
|
+
importsMatch = regex.exec(gradleScript);
|
|
186
|
+
}
|
|
187
|
+
if (appFile.endsWith('.kts')) {
|
|
188
|
+
newGradleScript =
|
|
189
|
+
gradleScript.slice(0, insertIndex) +
|
|
190
|
+
(0, templates_1.pluginsBlockKts)(pluginVersion) +
|
|
191
|
+
gradleScript.slice(insertIndex);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
newGradleScript =
|
|
195
|
+
gradleScript.slice(0, insertIndex) +
|
|
196
|
+
(0, templates_1.pluginsBlock)(pluginVersion) +
|
|
197
|
+
gradleScript.slice(insertIndex);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
insertIndex = pluginsBlockMatch.index + pluginsBlockMatch[0].length - 1;
|
|
202
|
+
if (appFile.endsWith('.kts')) {
|
|
203
|
+
newGradleScript =
|
|
204
|
+
gradleScript.slice(0, insertIndex) +
|
|
205
|
+
(0, templates_1.pluginKts)(pluginVersion) +
|
|
206
|
+
gradleScript.slice(insertIndex);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
newGradleScript =
|
|
210
|
+
gradleScript.slice(0, insertIndex) +
|
|
211
|
+
(0, templates_1.plugin)(pluginVersion) +
|
|
212
|
+
gradleScript.slice(insertIndex);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
fs.writeFileSync(appFile, newGradleScript, 'utf8');
|
|
216
|
+
maybeAddSourceContextConfig(appFile, newGradleScript, orgSlug, projectSlug);
|
|
217
|
+
buildSpinner = clack.spinner();
|
|
218
|
+
buildSpinner.start('Running ./gradlew to verify changes (this may take a few minutes)...');
|
|
219
|
+
_a.label = 2;
|
|
220
|
+
case 2:
|
|
221
|
+
_a.trys.push([2, 4, , 5]);
|
|
222
|
+
return [4 /*yield*/, bash.execute('./gradlew')];
|
|
223
|
+
case 3:
|
|
224
|
+
_a.sent();
|
|
225
|
+
buildSpinner.stop(chalk_1.default.greenBright("".concat(chalk_1.default.bold('Sentry Gradle plugin'), " added to the project.")));
|
|
226
|
+
return [3 /*break*/, 5];
|
|
227
|
+
case 4:
|
|
228
|
+
e_1 = _a.sent();
|
|
229
|
+
buildSpinner.stop();
|
|
230
|
+
Sentry.captureException('Gradle Sync failed');
|
|
231
|
+
return [2 /*return*/, false];
|
|
232
|
+
case 5: return [2 /*return*/, true];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
exports.addGradlePlugin = addGradlePlugin;
|
|
238
|
+
/**
|
|
239
|
+
* Looks for the applications packageName (namespace) in the specified build.gradle(.kts) file.
|
|
240
|
+
*
|
|
241
|
+
* ```
|
|
242
|
+
* android {
|
|
243
|
+
* namespace 'my.package.name' <-- this is what we extract
|
|
244
|
+
*
|
|
245
|
+
* compileSdkVersion = 31
|
|
246
|
+
* ...
|
|
247
|
+
* }
|
|
248
|
+
* ```
|
|
249
|
+
* @param appFile
|
|
250
|
+
* @returns the packageName(namespace) of the app if available
|
|
251
|
+
*/
|
|
252
|
+
function getNamespace(appFile) {
|
|
253
|
+
var gradleScript = fs.readFileSync(appFile, 'utf8');
|
|
254
|
+
var namespaceMatch = /namespace\s*=?\s*['"]([^'"]+)['"]/i.exec(gradleScript);
|
|
255
|
+
if (!namespaceMatch || namespaceMatch.length <= 1) {
|
|
256
|
+
clack.log.warn('Unable to determine application package name.');
|
|
257
|
+
Sentry.captureException('No package name');
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
var namespace = namespaceMatch[1];
|
|
261
|
+
return namespace;
|
|
262
|
+
}
|
|
263
|
+
exports.getNamespace = getNamespace;
|
|
264
|
+
/**
|
|
265
|
+
* Adds source context configuration to the gradleScript if `sentry {}` block is not yet configured,
|
|
266
|
+
*
|
|
267
|
+
* @param appFile
|
|
268
|
+
* @param gradleScript
|
|
269
|
+
*/
|
|
270
|
+
function maybeAddSourceContextConfig(appFile, gradleScript, orgSlug, projectSlug) {
|
|
271
|
+
if (!/sentry\s*\{[^}]*\}/i.test(gradleScript)) {
|
|
272
|
+
// if no sentry {} block is configured, we add our own with source context enabled
|
|
273
|
+
if (appFile.endsWith('.kts')) {
|
|
274
|
+
fs.appendFileSync(appFile, (0, templates_1.sourceContextKts)(orgSlug, projectSlug), 'utf8');
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
fs.appendFileSync(appFile, (0, templates_1.sourceContext)(orgSlug, projectSlug), 'utf8');
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=gradle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gradle.js","sourceRoot":"","sources":["../../../src/android/gradle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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afe-assignment */\nimport * as fs from 'fs';\nimport { abortIfCancelled, askForItemSelection } from '../utils/clack-utils';\nimport {\n plugin,\n pluginKts,\n pluginsBlock,\n pluginsBlockKts,\n sourceContext,\n sourceContextKts,\n} from './templates';\nimport * as bash from '../utils/bash';\nimport * as Sentry from '@sentry/node';\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport { fetchSdkVersion } from '../utils/release-registry';\n\n/**\n * A Gradle project may contain multiple modules, some of them may be applications, some of them may be libraries.\n * We are only interested in applications. For example:\n *\n * myproject/\n * app/\n * lib1/\n * lib2/\n * wearApp/\n *\n * In this case^ we are interested in app/ and wearApp/\n *\n * @param buildGradleFiles a list of build.gradle(.kts) paths that contain the com.android.application plugin\n * @returns the selected project for setting up\n */\nexport async function selectAppFile(\n buildGradleFiles: string[],\n): Promise<string> {\n const appFiles = [];\n for (let index = 0; index < buildGradleFiles.length; index++) {\n const file = buildGradleFiles[index];\n const text = fs.readFileSync(file, 'utf8');\n if (/\\(?[\"']com\\.android\\.application[\"']\\)?(?!.*\\S)/.test(text)) {\n appFiles.push(file);\n }\n }\n\n if (appFiles.length === 0) {\n Sentry.setTag('custom-build-logic', true);\n const appFile = await abortIfCancelled(\n clack.text({\n message: `Unable to find your app's directory. \n Please enter the relative path to your app's build.gradle file from the root project (e.g. \"app/build.gradle.kts\")`,\n }),\n );\n return appFile;\n }\n\n let appFile;\n if (appFiles.length === 1) {\n Sentry.setTag('multiple-projects', false);\n appFile = appFiles[0];\n } else {\n Sentry.setTag('multiple-projects', true);\n appFile = (\n await askForItemSelection(\n appFiles,\n 'Which project do you want to add Sentry to?',\n )\n ).value;\n }\n Sentry.setTag('custom-build-logic', false);\n return appFile;\n}\n\n/**\n * Patches a build.gradle(.kts) file that contains `com.android.application` plugin.\n * There are multiple cases we have to handle here:\n * - An existing `plugins {}` block:\n * - We just have to add our plugin inside the block\n * - No existing `plugins {}` block\n * - We have to add the entire block in the beginning of the file, BUT *after imports*\n *\n * For example (2nd case):\n *\n * ```\n * import net.ltgt.gradle.errorprone.errorprone\n *\n * // our plugins block goes here <--\n * plugins {\n * id(\"io.sentry.android.gradle\") version \"3.12.0\"\n * }\n *\n * apply(plugin = \"com.android.application\")\n *\n * android {\n * ...\n * }\n * ```\n *\n * In the end we run `./gradlew` to verify the config is build-able and not broken.\n *\n * @param appFile the selected Gradle application project\n * @returns true if successfully added Sentry Gradle config, false otherwise\n */\nexport async function addGradlePlugin(\n appFile: string,\n orgSlug: string,\n projectSlug: string,\n): Promise<boolean> {\n const gradleScript = fs.readFileSync(appFile, 'utf8');\n\n if (/\\(?[\"']io\\.sentry\\.android\\.gradle[\"']\\)?/.test(gradleScript)) {\n // sentry gradle plugin is already installed\n clack.log.success(\n chalk.greenBright(\n `${chalk.bold(\n 'Sentry Gradle plugin',\n )} is already added to the project.`,\n ),\n );\n maybeAddSourceContextConfig(appFile, gradleScript, orgSlug, projectSlug);\n return true;\n }\n\n const pluginVersion = await fetchSdkVersion(\n 'sentry.java.android.gradle-plugin',\n );\n const pluginsBlockMatch = /plugins\\s*{[^{}]*}/.exec(gradleScript);\n let newGradleScript;\n if (!pluginsBlockMatch) {\n // no \"plugins {}\" block, we can just add our own after imports\n const regex = /import\\s+[\\w.]+/gm;\n let importsMatch = regex.exec(gradleScript);\n let insertIndex = 0;\n while (importsMatch) {\n insertIndex = importsMatch.index + importsMatch[0].length + 1;\n importsMatch = regex.exec(gradleScript);\n }\n\n if (appFile.endsWith('.kts')) {\n newGradleScript =\n gradleScript.slice(0, insertIndex) +\n pluginsBlockKts(pluginVersion) +\n gradleScript.slice(insertIndex);\n } else {\n newGradleScript =\n gradleScript.slice(0, insertIndex) +\n pluginsBlock(pluginVersion) +\n gradleScript.slice(insertIndex);\n }\n } else {\n const insertIndex =\n pluginsBlockMatch.index + pluginsBlockMatch[0].length - 1;\n if (appFile.endsWith('.kts')) {\n newGradleScript =\n gradleScript.slice(0, insertIndex) +\n pluginKts(pluginVersion) +\n gradleScript.slice(insertIndex);\n } else {\n newGradleScript =\n gradleScript.slice(0, insertIndex) +\n plugin(pluginVersion) +\n gradleScript.slice(insertIndex);\n }\n }\n fs.writeFileSync(appFile, newGradleScript, 'utf8');\n\n maybeAddSourceContextConfig(appFile, newGradleScript, orgSlug, projectSlug);\n\n const buildSpinner = clack.spinner();\n\n buildSpinner.start(\n 'Running ./gradlew to verify changes (this may take a few minutes)...',\n );\n\n try {\n await bash.execute('./gradlew');\n buildSpinner.stop(\n chalk.greenBright(\n `${chalk.bold('Sentry Gradle plugin')} added to the project.`,\n ),\n );\n } catch (e) {\n buildSpinner.stop();\n Sentry.captureException('Gradle Sync failed');\n return false;\n }\n\n return true;\n}\n\n/**\n * Looks for the applications packageName (namespace) in the specified build.gradle(.kts) file.\n *\n * ```\n * android {\n * namespace 'my.package.name' <-- this is what we extract\n *\n * compileSdkVersion = 31\n * ...\n * }\n * ```\n * @param appFile\n * @returns the packageName(namespace) of the app if available\n */\nexport function getNamespace(appFile: string): string | undefined {\n const gradleScript = fs.readFileSync(appFile, 'utf8');\n\n const namespaceMatch = /namespace\\s*=?\\s*['\"]([^'\"]+)['\"]/i.exec(\n gradleScript,\n );\n if (!namespaceMatch || namespaceMatch.length <= 1) {\n clack.log.warn('Unable to determine application package name.');\n Sentry.captureException('No package name');\n return undefined;\n }\n\n const namespace = namespaceMatch[1];\n return namespace;\n}\n\n/**\n * Adds source context configuration to the gradleScript if `sentry {}` block is not yet configured,\n *\n * @param appFile\n * @param gradleScript\n */\nfunction maybeAddSourceContextConfig(\n appFile: string,\n gradleScript: string,\n orgSlug: string,\n projectSlug: string,\n) {\n if (!/sentry\\s*\\{[^}]*\\}/i.test(gradleScript)) {\n // if no sentry {} block is configured, we add our own with source context enabled\n if (appFile.endsWith('.kts')) {\n fs.appendFileSync(\n appFile,\n sourceContextKts(orgSlug, projectSlug),\n 'utf8',\n );\n } else {\n fs.appendFileSync(appFile, sourceContext(orgSlug, projectSlug), 'utf8');\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Looks for the closing </application> tag in the manifest and adds the Sentry config after it.
|
|
3
|
+
*
|
|
4
|
+
* For example:
|
|
5
|
+
* ```xml
|
|
6
|
+
* <manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
7
|
+
* xmlns:tools="http://schemas.android.com/tools">
|
|
8
|
+
*
|
|
9
|
+
* <application>
|
|
10
|
+
* ...
|
|
11
|
+
* // this is what we add and more
|
|
12
|
+
* <meta-data android:name="io.sentry.dsn" android:value="__dsn__" />
|
|
13
|
+
* </application> <!-- we are looking for this one
|
|
14
|
+
* </manifest>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param manifestFile the path to the main AndroidManifest.xml file
|
|
18
|
+
* @param dsn
|
|
19
|
+
* @returns true if successfully patched the manifest, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
export declare function addManifestSnippet(manifestFile: string, dsn: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* There might be multiple <activity> in the manifest, as well as multiple <activity-alias> with category LAUNCHER,
|
|
24
|
+
* but only one main activity with action MAIN. We are looking for this one by parsing xml and walking it.
|
|
25
|
+
*
|
|
26
|
+
* In addition, older Android versions required to specify the packag name in the manifest,
|
|
27
|
+
* while the new ones - in the Gradle config. So we are just sanity checking if the package name
|
|
28
|
+
* is in the manifest and returning it as well.
|
|
29
|
+
*
|
|
30
|
+
* For example:
|
|
31
|
+
*
|
|
32
|
+
* ```xml
|
|
33
|
+
* <manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
34
|
+
* xmlns:tools="http://schemas.android.com/tools"
|
|
35
|
+
* package="com.example.sample">
|
|
36
|
+
*
|
|
37
|
+
* <application>
|
|
38
|
+
* <activity
|
|
39
|
+
* android:name="ui.MainActivity"
|
|
40
|
+
* ...other props>
|
|
41
|
+
* <intent-filter>
|
|
42
|
+
* <action android:name="android.intent.action.MAIN" /> <!-- we are looking for this one
|
|
43
|
+
*
|
|
44
|
+
* <category android:name="android.intent.category.LAUNCHER" />
|
|
45
|
+
* </intent-filter>
|
|
46
|
+
* </activity>
|
|
47
|
+
* </application>
|
|
48
|
+
* </manifest>
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param manifestFile path to the AndroidManifest.xml file
|
|
52
|
+
* @returns package name (if available in the manifest) + the main activity name
|
|
53
|
+
*/
|
|
54
|
+
export declare function getMainActivity(manifestFile: string): {
|
|
55
|
+
packageName?: string;
|
|
56
|
+
activityName?: string;
|
|
57
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getMainActivity = exports.addManifestSnippet = void 0;
|
|
30
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
31
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
32
|
+
var fs = __importStar(require("fs"));
|
|
33
|
+
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
34
|
+
var clack = __importStar(require("@clack/prompts"));
|
|
35
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
36
|
+
var templates_1 = require("./templates");
|
|
37
|
+
var xml_js_1 = __importDefault(require("xml-js"));
|
|
38
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
39
|
+
/**
|
|
40
|
+
* Looks for the closing </application> tag in the manifest and adds the Sentry config after it.
|
|
41
|
+
*
|
|
42
|
+
* For example:
|
|
43
|
+
* ```xml
|
|
44
|
+
* <manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
45
|
+
* xmlns:tools="http://schemas.android.com/tools">
|
|
46
|
+
*
|
|
47
|
+
* <application>
|
|
48
|
+
* ...
|
|
49
|
+
* // this is what we add and more
|
|
50
|
+
* <meta-data android:name="io.sentry.dsn" android:value="__dsn__" />
|
|
51
|
+
* </application> <!-- we are looking for this one
|
|
52
|
+
* </manifest>
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @param manifestFile the path to the main AndroidManifest.xml file
|
|
56
|
+
* @param dsn
|
|
57
|
+
* @returns true if successfully patched the manifest, false otherwise
|
|
58
|
+
*/
|
|
59
|
+
function addManifestSnippet(manifestFile, dsn) {
|
|
60
|
+
if (!fs.existsSync(manifestFile)) {
|
|
61
|
+
clack.log.warn('AndroidManifest.xml not found.');
|
|
62
|
+
Sentry.captureException('No AndroidManifest file');
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
var manifestContent = fs.readFileSync(manifestFile, 'utf8');
|
|
66
|
+
if (/android:name="io\.sentry[^"]*"/i.test(manifestContent)) {
|
|
67
|
+
// sentry is already configured
|
|
68
|
+
clack.log.success(chalk_1.default.greenBright('Sentry SDK is already configured.'));
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
var applicationMatch = /<\/application>/i.exec(manifestContent);
|
|
72
|
+
if (!applicationMatch) {
|
|
73
|
+
clack.log.warn('<application> tag not found within the manifest.');
|
|
74
|
+
Sentry.captureException('No <application> tag');
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
var insertionIndex = applicationMatch.index;
|
|
78
|
+
var newContent = manifestContent.slice(0, insertionIndex) +
|
|
79
|
+
(0, templates_1.manifest)(dsn) +
|
|
80
|
+
manifestContent.slice(insertionIndex);
|
|
81
|
+
fs.writeFileSync(manifestFile, newContent, 'utf8');
|
|
82
|
+
clack.log.success(chalk_1.default.greenBright("Updated ".concat(chalk_1.default.bold('AndroidManifest.xml'), " with the Sentry SDK configuration.")));
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
exports.addManifestSnippet = addManifestSnippet;
|
|
86
|
+
/**
|
|
87
|
+
* There might be multiple <activity> in the manifest, as well as multiple <activity-alias> with category LAUNCHER,
|
|
88
|
+
* but only one main activity with action MAIN. We are looking for this one by parsing xml and walking it.
|
|
89
|
+
*
|
|
90
|
+
* In addition, older Android versions required to specify the packag name in the manifest,
|
|
91
|
+
* while the new ones - in the Gradle config. So we are just sanity checking if the package name
|
|
92
|
+
* is in the manifest and returning it as well.
|
|
93
|
+
*
|
|
94
|
+
* For example:
|
|
95
|
+
*
|
|
96
|
+
* ```xml
|
|
97
|
+
* <manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
98
|
+
* xmlns:tools="http://schemas.android.com/tools"
|
|
99
|
+
* package="com.example.sample">
|
|
100
|
+
*
|
|
101
|
+
* <application>
|
|
102
|
+
* <activity
|
|
103
|
+
* android:name="ui.MainActivity"
|
|
104
|
+
* ...other props>
|
|
105
|
+
* <intent-filter>
|
|
106
|
+
* <action android:name="android.intent.action.MAIN" /> <!-- we are looking for this one
|
|
107
|
+
*
|
|
108
|
+
* <category android:name="android.intent.category.LAUNCHER" />
|
|
109
|
+
* </intent-filter>
|
|
110
|
+
* </activity>
|
|
111
|
+
* </application>
|
|
112
|
+
* </manifest>
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @param manifestFile path to the AndroidManifest.xml file
|
|
116
|
+
* @returns package name (if available in the manifest) + the main activity name
|
|
117
|
+
*/
|
|
118
|
+
function getMainActivity(manifestFile) {
|
|
119
|
+
var _a, _b, _c, _d;
|
|
120
|
+
if (!fs.existsSync(manifestFile)) {
|
|
121
|
+
clack.log.warn('AndroidManifest.xml not found.');
|
|
122
|
+
Sentry.captureException('No AndroidManifest file');
|
|
123
|
+
return {};
|
|
124
|
+
}
|
|
125
|
+
var manifestContent = fs.readFileSync(manifestFile, 'utf8');
|
|
126
|
+
var converted = xml_js_1.default.xml2js(manifestContent, {
|
|
127
|
+
compact: true,
|
|
128
|
+
});
|
|
129
|
+
var activities = (_b = (_a = converted.manifest) === null || _a === void 0 ? void 0 : _a.application) === null || _b === void 0 ? void 0 : _b.activity;
|
|
130
|
+
var packageName = (_d = (_c = converted.manifest) === null || _c === void 0 ? void 0 : _c._attributes) === null || _d === void 0 ? void 0 : _d['package'];
|
|
131
|
+
if (!activities) {
|
|
132
|
+
clack.log.warn('No activity found in AndroidManifest.');
|
|
133
|
+
Sentry.captureException('No Activity');
|
|
134
|
+
return {};
|
|
135
|
+
}
|
|
136
|
+
var mainActivity;
|
|
137
|
+
if (Array.isArray(activities)) {
|
|
138
|
+
var withIntentFilter = activities.filter(function (a) { return !!a['intent-filter']; });
|
|
139
|
+
mainActivity = withIntentFilter.find(function (a) { return isMainActivity(a); });
|
|
140
|
+
}
|
|
141
|
+
else if (isMainActivity(activities)) {
|
|
142
|
+
mainActivity = activities;
|
|
143
|
+
}
|
|
144
|
+
if (!mainActivity) {
|
|
145
|
+
clack.log.warn('No main activity found in AndroidManifest.');
|
|
146
|
+
Sentry.captureException('No Main Activity');
|
|
147
|
+
return {};
|
|
148
|
+
}
|
|
149
|
+
var attrs = mainActivity._attributes;
|
|
150
|
+
var activityName = attrs === null || attrs === void 0 ? void 0 : attrs['android:name'];
|
|
151
|
+
return { packageName: packageName, activityName: activityName };
|
|
152
|
+
}
|
|
153
|
+
exports.getMainActivity = getMainActivity;
|
|
154
|
+
function isMainActivity(activity) {
|
|
155
|
+
var intentFilters = activity['intent-filter'];
|
|
156
|
+
if (Array.isArray(intentFilters)) {
|
|
157
|
+
return intentFilters.some(function (i) {
|
|
158
|
+
var action = i.action;
|
|
159
|
+
return hasMainAction(action);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
var action = intentFilters.action;
|
|
164
|
+
return hasMainAction(action);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function hasMainAction(action) {
|
|
168
|
+
if (!action) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
function isMain(attrs) {
|
|
172
|
+
return (attrs === null || attrs === void 0 ? void 0 : attrs['android:name']) === 'android.intent.action.MAIN';
|
|
173
|
+
}
|
|
174
|
+
if (Array.isArray(action)) {
|
|
175
|
+
return action.some(function (c) {
|
|
176
|
+
return isMain(c._attributes);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
return isMain(action._attributes);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../../src/android/manifest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA+D;AAC/D,4DAA4D;AAC5D,qCAAyB;AACzB,yEAAyE;AACzE,oDA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AC,IAAI,CAAC,UAAC,CAAC;YACnB,OAAO,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;KACJ;SAAM;QACL,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;KACnC;AACH,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport * as fs from 'fs';\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport * as Sentry from '@sentry/node';\nimport { manifest } from './templates';\nimport xml, { Attributes, ElementCompact } from 'xml-js';\nimport chalk from 'chalk';\n\n/**\n * Looks for the closing </application> tag in the manifest and adds the Sentry config after it.\n *\n * For example:\n * ```xml\n * <manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n * xmlns:tools=\"http://schemas.android.com/tools\">\n *\n * <application>\n * ...\n * // this is what we add and more\n * <meta-data android:name=\"io.sentry.dsn\" android:value=\"__dsn__\" />\n * </application> <!-- we are looking for this one\n * </manifest>\n * ```\n *\n * @param manifestFile the path to the main AndroidManifest.xml file\n * @param dsn\n * @returns true if successfully patched the manifest, false otherwise\n */\nexport function addManifestSnippet(manifestFile: string, dsn: string): boolean {\n if (!fs.existsSync(manifestFile)) {\n clack.log.warn('AndroidManifest.xml not found.');\n Sentry.captureException('No AndroidManifest file');\n return false;\n }\n\n const manifestContent = fs.readFileSync(manifestFile, 'utf8');\n\n if (/android:name=\"io\\.sentry[^\"]*\"/i.test(manifestContent)) {\n // sentry is already configured\n clack.log.success(chalk.greenBright('Sentry SDK is already configured.'));\n return true;\n }\n\n const applicationMatch = /<\\/application>/i.exec(manifestContent);\n if (!applicationMatch) {\n clack.log.warn('<application> tag not found within the manifest.');\n Sentry.captureException('No <application> tag');\n return false;\n }\n\n const insertionIndex = applicationMatch.index;\n const newContent =\n manifestContent.slice(0, insertionIndex) +\n manifest(dsn) +\n manifestContent.slice(insertionIndex);\n fs.writeFileSync(manifestFile, newContent, 'utf8');\n\n clack.log.success(\n chalk.greenBright(\n `Updated ${chalk.bold(\n 'AndroidManifest.xml',\n )} with the Sentry SDK configuration.`,\n ),\n );\n\n return true;\n}\n\n/**\n * There might be multiple <activity> in the manifest, as well as multiple <activity-alias> with category LAUNCHER,\n * but only one main activity with action MAIN. We are looking for this one by parsing xml and walking it.\n *\n * In addition, older Android versions required to specify the packag name in the manifest,\n * while the new ones - in the Gradle config. So we are just sanity checking if the package name\n * is in the manifest and returning it as well.\n *\n * For example:\n *\n * ```xml\n * <manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n * xmlns:tools=\"http://schemas.android.com/tools\"\n * package=\"com.example.sample\">\n *\n * <application>\n * <activity\n * android:name=\"ui.MainActivity\"\n * ...other props>\n * <intent-filter>\n * <action android:name=\"android.intent.action.MAIN\" /> <!-- we are looking for this one\n *\n * <category android:name=\"android.intent.category.LAUNCHER\" />\n * </intent-filter>\n * </activity>\n * </application>\n * </manifest>\n * ```\n *\n * @param manifestFile path to the AndroidManifest.xml file\n * @returns package name (if available in the manifest) + the main activity name\n */\nexport function getMainActivity(manifestFile: string): {\n packageName?: string;\n activityName?: string;\n} {\n if (!fs.existsSync(manifestFile)) {\n clack.log.warn('AndroidManifest.xml not found.');\n Sentry.captureException('No AndroidManifest file');\n return {};\n }\n\n const manifestContent = fs.readFileSync(manifestFile, 'utf8');\n const converted: ElementCompact = xml.xml2js(manifestContent, {\n compact: true,\n });\n const activities: ElementCompact[] | ElementCompact | undefined =\n converted.manifest?.application?.activity;\n const packageName: string | undefined =\n converted.manifest?._attributes?.['package'];\n\n if (!activities) {\n clack.log.warn('No activity found in AndroidManifest.');\n Sentry.captureException('No Activity');\n return {};\n }\n\n let mainActivity;\n if (Array.isArray(activities)) {\n const withIntentFilter = activities.filter((a) => !!a['intent-filter']);\n mainActivity = withIntentFilter.find((a) => isMainActivity(a));\n } else if (isMainActivity(activities)) {\n mainActivity = activities;\n }\n\n if (!mainActivity) {\n clack.log.warn('No main activity found in AndroidManifest.');\n Sentry.captureException('No Main Activity');\n return {};\n }\n\n const attrs = mainActivity._attributes;\n const activityName = attrs?.['android:name'] as string | undefined;\n return { packageName: packageName, activityName: activityName };\n}\n\nfunction isMainActivity(activity: ElementCompact): boolean {\n const intentFilters: ElementCompact[] | ElementCompact =\n activity['intent-filter'];\n if (Array.isArray(intentFilters)) {\n return intentFilters.some((i) => {\n const action: ElementCompact[] | ElementCompact | undefined = i.action;\n return hasMainAction(action);\n });\n } else {\n const action: ElementCompact[] | ElementCompact | undefined =\n intentFilters.action;\n return hasMainAction(action);\n }\n}\n\nfunction hasMainAction(\n action: ElementCompact[] | ElementCompact | undefined,\n): boolean {\n if (!action) {\n return false;\n }\n\n function isMain(attrs?: Attributes): boolean {\n return attrs?.['android:name'] === 'android.intent.action.MAIN';\n }\n\n if (Array.isArray(action)) {\n return action.some((c) => {\n return isMain(c._attributes);\n });\n } else {\n return isMain(action._attributes);\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const pluginsBlock: (version?: string) => string;
|
|
2
|
+
export declare const pluginsBlockKts: (version?: string) => string;
|
|
3
|
+
export declare const plugin: (version?: string) => string;
|
|
4
|
+
export declare const pluginKts: (version?: string) => string;
|
|
5
|
+
export declare const manifest: (dsn: string) => string;
|
|
6
|
+
export declare const sentryImport = "import io.sentry.Sentry;\n";
|
|
7
|
+
export declare const sentryImportKt = "import io.sentry.Sentry\n";
|
|
8
|
+
export declare const testErrorSnippet = "\n // waiting for view to draw to better represent a captured error with a screenshot\n findViewById(android.R.id.content).getViewTreeObserver().addOnGlobalLayoutListener(() -> {\n try {\n throw new Exception(\"This app uses Sentry! :)\");\n } catch (Exception e) {\n Sentry.captureException(e);\n }\n });\n";
|
|
9
|
+
export declare const testErrorSnippetKt = "\n // waiting for view to draw to better represent a captured error with a screenshot\n findViewById<android.view.View>(android.R.id.content).viewTreeObserver.addOnGlobalLayoutListener {\n try {\n throw Exception(\"This app uses Sentry! :)\")\n } catch (e: Exception) {\n Sentry.captureException(e)\n }\n }\n";
|
|
10
|
+
export declare const sourceContext: (orgSlug: string, projectSlug: string) => string;
|
|
11
|
+
export declare const sourceContextKts: (orgSlug: string, projectSlug: string) => string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sourceContextKts = exports.sourceContext = exports.testErrorSnippetKt = exports.testErrorSnippet = exports.sentryImportKt = exports.sentryImport = exports.manifest = exports.pluginKts = exports.plugin = exports.pluginsBlockKts = exports.pluginsBlock = void 0;
|
|
4
|
+
var pluginsBlock = function (version) {
|
|
5
|
+
if (version === void 0) { version = '3.12.0'; }
|
|
6
|
+
return "\nplugins {\n id 'io.sentry.android.gradle' version '".concat(version, "'\n}\n\n");
|
|
7
|
+
};
|
|
8
|
+
exports.pluginsBlock = pluginsBlock;
|
|
9
|
+
var pluginsBlockKts = function (version) {
|
|
10
|
+
if (version === void 0) { version = '3.12.0'; }
|
|
11
|
+
return "\nplugins {\n id(\"io.sentry.android.gradle\") version \"".concat(version, "\"\n}\n\n");
|
|
12
|
+
};
|
|
13
|
+
exports.pluginsBlockKts = pluginsBlockKts;
|
|
14
|
+
var plugin = function (version) {
|
|
15
|
+
if (version === void 0) { version = '3.12.0'; }
|
|
16
|
+
return "\n id 'io.sentry.android.gradle' version '".concat(version, "'\n");
|
|
17
|
+
};
|
|
18
|
+
exports.plugin = plugin;
|
|
19
|
+
var pluginKts = function (version) {
|
|
20
|
+
if (version === void 0) { version = '3.12.0'; }
|
|
21
|
+
return "\n id(\"io.sentry.android.gradle\") version \"".concat(version, "\"\n");
|
|
22
|
+
};
|
|
23
|
+
exports.pluginKts = pluginKts;
|
|
24
|
+
var manifest = function (dsn) { return "\n <!-- Required: set your sentry.io project identifier (DSN) -->\n <meta-data android:name=\"io.sentry.dsn\" android:value=\"".concat(dsn, "\" />\n\n <!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->\n <meta-data android:name=\"io.sentry.traces.user-interaction.enable\" android:value=\"true\" />\n <!-- enable screenshot for crashes (could contain sensitive/PII data) -->\n <meta-data android:name=\"io.sentry.attach-screenshot\" android:value=\"true\" />\n <!-- enable view hierarchy for crashes -->\n <meta-data android:name=\"io.sentry.attach-view-hierarchy\" android:value=\"true\" />\n\n <!-- enable the performance API by setting a sample-rate, adjust in production env -->\n <meta-data android:name=\"io.sentry.traces.sample-rate\" android:value=\"1.0\" />\n <!-- enable profiling when starting transactions, adjust in production env -->\n <meta-data android:name=\"io.sentry.traces.profiling.sample-rate\" android:value=\"1.0\" />\n"); };
|
|
25
|
+
exports.manifest = manifest;
|
|
26
|
+
exports.sentryImport = "import io.sentry.Sentry;\n";
|
|
27
|
+
exports.sentryImportKt = "import io.sentry.Sentry\n";
|
|
28
|
+
exports.testErrorSnippet = "\n // waiting for view to draw to better represent a captured error with a screenshot\n findViewById(android.R.id.content).getViewTreeObserver().addOnGlobalLayoutListener(() -> {\n try {\n throw new Exception(\"This app uses Sentry! :)\");\n } catch (Exception e) {\n Sentry.captureException(e);\n }\n });\n";
|
|
29
|
+
exports.testErrorSnippetKt = "\n // waiting for view to draw to better represent a captured error with a screenshot\n findViewById<android.view.View>(android.R.id.content).viewTreeObserver.addOnGlobalLayoutListener {\n try {\n throw Exception(\"This app uses Sentry! :)\")\n } catch (e: Exception) {\n Sentry.captureException(e)\n }\n }\n";
|
|
30
|
+
var sourceContext = function (orgSlug, projectSlug) { return "\n\nsentry {\n org = \"".concat(orgSlug, "\"\n projectName = \"").concat(projectSlug, "\"\n\n // this will upload your source code to Sentry to show it as part of the stack traces\n // disable if you don't want to expose your sources\n includeSourceContext = true\n}\n"); };
|
|
31
|
+
exports.sourceContext = sourceContext;
|
|
32
|
+
var sourceContextKts = function (orgSlug, projectSlug) { return "\n\nsentry {\n org.set(\"".concat(orgSlug, "\")\n projectName.set(\"").concat(projectSlug, "\")\n\n // this will upload your source code to Sentry to show it as part of the stack traces\n // disable if you don't want to expose your sources\n includeSourceContext.set(true)\n}\n"); };
|
|
33
|
+
exports.sourceContextKts = sourceContextKts;
|
|
34
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/android/templates.ts"],"names":[],"mappings":";;;AAAO,IAAM,YAAY,GAAG,UAAC,OAAkB;IAAlB,wBAAA,EAAA,kBAAkB;IAAK,OAAA,kEAEP,OAAO,aAGnD;AALmD,CAKnD,CAAC;AALW,QAAA,YAAY,gBAKvB;AAEK,IAAM,eAAe,GAAG,UAAC,OAAkB;IAAlB,wBAAA,EAAA,kBAAkB;IAAK,OAAA,sEAET,OAAO,cAGpD;AALsD,CAKtD,CAAC;AALW,QAAA,eAAe,mBAK1B;AAEK,IAAM,MAAM,GAAG,UAAC,OAAkB;IAAlB,wBAAA,EAAA,kBAAkB;IAAK,OAAA,uDACD,OAAO,QACnD;AAF6C,CAE7C,CAAC;AAFW,QAAA,MAAM,UAEjB;AAEK,IAAM,SAAS,GAAG,UAAC,OAAkB;IAAlB,wBAAA,EAAA,kBAAkB;IAAK,OAAA,2DACH,OAAO,SACpD;AAFgD,CAEhD,CAAC;AAFW,QAAA,SAAS,aAEpB;AAEK,IAAM,QAAQ,GAAG,UAAC,GAAW,IAAK,OAAA,8IAEoB,GAAG,w2BAa/D,EAfwC,CAexC,CAAC;AAfW,QAAA,QAAQ,YAenB;AAEW,QAAA,YAAY,GAAG,4BAA4B,CAAC;AAE5C,QAAA,cAAc,GAAG,2BAA2B,CAAC;AAE7C,QAAA,gBAAgB,GAAG,2VAS/B,CAAC;AAEW,QAAA,kBAAkB,GAAG,4VASjC,CAAC;AAEK,IAAM,aAAa,GAAG,UAAC,OAAe,EAAE,WAAmB,IAAK,OAAA,oCAG1D,OAAO,qCACC,WAAW,mMAM/B,EAVsE,CAUtE,CAAC;AAVW,QAAA,aAAa,iBAUxB;AAEK,IAAM,gBAAgB,GAAG,UAAC,OAAe,EAAE,WAAmB,IAAK,OAAA,sCAG3D,OAAO,wCACC,WAAW,uMAMjC,EAVyE,CAUzE,CAAC;AAVW,QAAA,gBAAgB,oBAU3B","sourcesContent":["export const pluginsBlock = (version = '3.12.0') => `\nplugins {\n id 'io.sentry.android.gradle' version '${version}'\n}\n\n`;\n\nexport const pluginsBlockKts = (version = '3.12.0') => `\nplugins {\n id(\"io.sentry.android.gradle\") version \"${version}\"\n}\n\n`;\n\nexport const plugin = (version = '3.12.0') => `\n id 'io.sentry.android.gradle' version '${version}'\n`;\n\nexport const pluginKts = (version = '3.12.0') => `\n id(\"io.sentry.android.gradle\") version \"${version}\"\n`;\n\nexport const manifest = (dsn: string) => `\n <!-- Required: set your sentry.io project identifier (DSN) -->\n <meta-data android:name=\"io.sentry.dsn\" android:value=\"${dsn}\" />\n\n <!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->\n <meta-data android:name=\"io.sentry.traces.user-interaction.enable\" android:value=\"true\" />\n <!-- enable screenshot for crashes (could contain sensitive/PII data) -->\n <meta-data android:name=\"io.sentry.attach-screenshot\" android:value=\"true\" />\n <!-- enable view hierarchy for crashes -->\n <meta-data android:name=\"io.sentry.attach-view-hierarchy\" android:value=\"true\" />\n\n <!-- enable the performance API by setting a sample-rate, adjust in production env -->\n <meta-data android:name=\"io.sentry.traces.sample-rate\" android:value=\"1.0\" />\n <!-- enable profiling when starting transactions, adjust in production env -->\n <meta-data android:name=\"io.sentry.traces.profiling.sample-rate\" android:value=\"1.0\" />\n`;\n\nexport const sentryImport = `import io.sentry.Sentry;\\n`;\n\nexport const sentryImportKt = `import io.sentry.Sentry\\n`;\n\nexport const testErrorSnippet = `\n // waiting for view to draw to better represent a captured error with a screenshot\n findViewById(android.R.id.content).getViewTreeObserver().addOnGlobalLayoutListener(() -> {\n try {\n throw new Exception(\"This app uses Sentry! :)\");\n } catch (Exception e) {\n Sentry.captureException(e);\n }\n });\n`;\n\nexport const testErrorSnippetKt = `\n // waiting for view to draw to better represent a captured error with a screenshot\n findViewById<android.view.View>(android.R.id.content).viewTreeObserver.addOnGlobalLayoutListener {\n try {\n throw Exception(\"This app uses Sentry! :)\")\n } catch (e: Exception) {\n Sentry.captureException(e)\n }\n }\n`;\n\nexport const sourceContext = (orgSlug: string, projectSlug: string) => `\n\nsentry {\n org = \"${orgSlug}\"\n projectName = \"${projectSlug}\"\n\n // this will upload your source code to Sentry to show it as part of the stack traces\n // disable if you don't want to expose your sources\n includeSourceContext = true\n}\n`;\n\nexport const sourceContextKts = (orgSlug: string, projectSlug: string) => `\n\nsentry {\n org.set(\"${orgSlug}\")\n projectName.set(\"${projectSlug}\")\n\n // this will upload your source code to Sentry to show it as part of the stack traces\n // disable if you don't want to expose your sources\n includeSourceContext.set(true)\n}\n`;\n"]}
|