@sentry/wizard 3.11.0 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/package.json +1 -1
- package/dist/src/android/android-wizard.js +8 -0
- package/dist/src/android/android-wizard.js.map +1 -1
- package/dist/src/android/code-tools.d.ts +8 -0
- package/dist/src/android/code-tools.js +20 -8
- package/dist/src/android/code-tools.js.map +1 -1
- package/dist/src/android/gradle.js +6 -1
- package/dist/src/android/gradle.js.map +1 -1
- package/dist/src/sourcemaps/tools/vite.js +36 -111
- package/dist/src/sourcemaps/tools/vite.js.map +1 -1
- package/dist/src/sourcemaps/tools/webpack.d.ts +6 -1
- package/dist/src/sourcemaps/tools/webpack.js +290 -25
- package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup.js +2 -2
- package/dist/src/sveltekit/sdk-setup.js.map +1 -1
- package/dist/src/utils/ast-utils.d.ts +7 -3
- package/dist/src/utils/ast-utils.js +20 -5
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +52 -0
- package/dist/src/utils/clack-utils.js +169 -12
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/test/android/code-tools.test.d.ts +1 -0
- package/dist/test/android/code-tools.test.js +34 -0
- package/dist/test/android/code-tools.test.js.map +1 -0
- package/dist/test/sourcemaps/tools/webpack.test.d.ts +1 -0
- package/dist/test/sourcemaps/tools/webpack.test.js +179 -0
- package/dist/test/sourcemaps/tools/webpack.test.js.map +1 -0
- package/dist/test/utils/ast-utils.test.js +42 -7
- package/dist/test/utils/ast-utils.test.js.map +1 -1
- package/dist/test/utils/clack-utils.test.d.ts +1 -0
- package/dist/test/utils/clack-utils.test.js +200 -0
- package/dist/test/utils/clack-utils.test.js.map +1 -0
- package/package.json +1 -1
- package/src/android/android-wizard.ts +8 -0
- package/src/android/code-tools.ts +21 -7
- package/src/android/gradle.ts +6 -1
- package/src/sourcemaps/tools/vite.ts +22 -88
- package/src/sourcemaps/tools/webpack.ts +369 -30
- package/src/sveltekit/sdk-setup.ts +6 -2
- package/src/utils/ast-utils.ts +23 -7
- package/src/utils/clack-utils.ts +150 -2
- package/test/android/code-tools.test.ts +49 -0
- package/test/sourcemaps/tools/webpack.test.ts +303 -0
- package/test/utils/ast-utils.test.ts +28 -9
- package/test/utils/clack-utils.test.ts +142 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.12.0
|
|
4
|
+
|
|
5
|
+
- feat(sourcemaps): Automatically insert Sentry Webpack plugin (#432)
|
|
6
|
+
- fix(android): Add support for unusual import statements (#440)
|
|
7
|
+
- fix(wizard): Sort projects in project-selection step (#441)
|
|
8
|
+
- enh(android): Add more telemetry (#435)
|
|
9
|
+
|
|
3
10
|
## 3.11.0
|
|
4
11
|
|
|
5
12
|
- feat(android): Add wizard support for Android (#389)
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/wizard",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.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",
|
|
@@ -68,6 +68,7 @@ var fs = __importStar(require("fs"));
|
|
|
68
68
|
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
69
69
|
var clack = __importStar(require("@clack/prompts"));
|
|
70
70
|
var path = __importStar(require("path"));
|
|
71
|
+
var Sentry = __importStar(require("@sentry/node"));
|
|
71
72
|
var gradle = __importStar(require("./gradle"));
|
|
72
73
|
var manifest = __importStar(require("./manifest"));
|
|
73
74
|
var codetools = __importStar(require("./code-tools"));
|
|
@@ -122,6 +123,7 @@ function runAndroidWizardWithTelemetry(options) {
|
|
|
122
123
|
]);
|
|
123
124
|
if (!(!buildGradleFiles || buildGradleFiles.length === 0)) return [3 /*break*/, 3];
|
|
124
125
|
clack.log.error('No Gradle project found. Please run this command from the root of your project.');
|
|
126
|
+
Sentry.captureException('No Gradle project found');
|
|
125
127
|
return [4 /*yield*/, (0, clack_utils_1.abort)()];
|
|
126
128
|
case 2:
|
|
127
129
|
_b.sent();
|
|
@@ -144,6 +146,7 @@ function runAndroidWizardWithTelemetry(options) {
|
|
|
144
146
|
if (!pluginAdded) {
|
|
145
147
|
clack.log.warn("Could not add Sentry Gradle plugin to your app's build.gradle file. You'll have to add it manually.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#install");
|
|
146
148
|
}
|
|
149
|
+
Sentry.setTag('gradle-plugin-added', pluginAdded);
|
|
147
150
|
// ======== STEP 2. Configure Sentry SDK via AndroidManifest ============
|
|
148
151
|
clack.log.step("Configuring Sentry SDK via ".concat(chalk_1.default.cyan('AndroidManifest.xml')));
|
|
149
152
|
appDir = path.dirname(appFile);
|
|
@@ -154,6 +157,7 @@ function runAndroidWizardWithTelemetry(options) {
|
|
|
154
157
|
if (!manifestUpdated) {
|
|
155
158
|
clack.log.warn("Could not configure the Sentry SDK. You'll have to do it manually.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#configure");
|
|
156
159
|
}
|
|
160
|
+
Sentry.setTag('android-manifest-updated', manifestUpdated);
|
|
157
161
|
// ======== STEP 3. Patch Main Activity with a test error snippet ============
|
|
158
162
|
clack.log.step("Patching ".concat(chalk_1.default.bold('Main Activity'), " with a test error snippet."));
|
|
159
163
|
mainActivity = (0, telemetry_1.traceStep)('Find Main Activity', function () {
|
|
@@ -165,8 +169,11 @@ function runAndroidWizardWithTelemetry(options) {
|
|
|
165
169
|
packageName = gradle.getNamespace(appFile);
|
|
166
170
|
}
|
|
167
171
|
activityName = mainActivity.activityName;
|
|
172
|
+
Sentry.setTag('has-activity-name', !!activityName);
|
|
173
|
+
Sentry.setTag('has-package-name', !!packageName);
|
|
168
174
|
if (!activityName || !packageName) {
|
|
169
175
|
clack.log.warn("Could not find Activity with intent action MAIN. You'll have to manually verify the setup.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify");
|
|
176
|
+
Sentry.captureException('Could not find Main Activity');
|
|
170
177
|
}
|
|
171
178
|
else {
|
|
172
179
|
packageNameStable_1 = packageName;
|
|
@@ -179,6 +186,7 @@ function runAndroidWizardWithTelemetry(options) {
|
|
|
179
186
|
if (!activityPatched) {
|
|
180
187
|
clack.log.warn("Could not patch main activity. You'll have to manually verify the setup.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify");
|
|
181
188
|
}
|
|
189
|
+
Sentry.setTag('main-activity-patched', activityPatched);
|
|
182
190
|
}
|
|
183
191
|
// ======== STEP 4. Add sentry-cli config file ============
|
|
184
192
|
clack.log.step("Configuring ".concat(chalk_1.default.bold('proguard mappings upload'), " via the ").concat(chalk_1.default.cyan('sentry.properties'), " file."));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android-wizard.js","sourceRoot":"","sources":["../../../src/android/android-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA4D;AAC5D,qCAAyB;AACzB,yEAAyE;AACzE,oDAAwC;AACxC,yCAA6B;AAC7B,+CAAmC;AACnC,mDAAuC;AACvC,sDAA0C;AAC1C,oDAQ8B;AAE9B,0CAAwD;AACxD,gDAA0B;AAE1B,IAAM,6BAA6B,GAAmB;IACpD,QAAQ,EAAE,oCAAsB;IAChC,IAAI,EAAE,mBAAmB;IACzB,yBAAyB,YAAC,QAAgB;QACxC,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IACD,YAAY,YAAC,SAAiB;QAC5B,OAAO,qBAAc,SAAS,CAAE,CAAC;IACnC,CAAC;IACD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. It works though\nimport * as clack from '@clack/prompts';\nimport * as path from 'path';\nimport * as gradle from './gradle';\nimport * as manifest from './manifest';\nimport * as codetools from './code-tools';\nimport {\n CliSetupConfig,\n SENTRY_PROPERTIES_FILE,\n abort,\n addSentryCliConfig,\n confirmContinueEvenThoughNoGitRepo,\n getOrAskForProjectData,\n printWelcome,\n} from '../utils/clack-utils';\nimport { WizardOptions } from '../utils/types';\nimport { traceStep, withTelemetry } from '../telemetry';\nimport chalk from 'chalk';\n\nconst proguardMappingCliSetupConfig: CliSetupConfig = {\n filename: SENTRY_PROPERTIES_FILE,\n name: 'proguard mappings',\n likelyAlreadyHasAuthToken(contents: string): boolean {\n return !!contents.match(/auth\\.token=./g);\n },\n tokenContent(authToken: string): string {\n return `auth.token=${authToken}`;\n },\n likelyAlreadyHasOrgAndProject(contents: string): boolean {\n return !!(\n contents.match(/defaults\\.org=./g) &&\n contents.match(/defaults\\.project=./g)\n );\n },\n orgAndProjContent(org: string, project: string): string {\n return `defaults.org=${org}\\ndefaults.project=${project}`;\n },\n};\n\nexport async function runAndroidWizard(options: WizardOptions): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'android',\n },\n () => runAndroidWizardWithTelemetry(options),\n );\n}\n\nasync function runAndroidWizardWithTelemetry(\n options: WizardOptions,\n): Promise<void> {\n printWelcome({\n wizardName: 'Sentry Android Wizard',\n promoCode: options.promoCode,\n });\n\n await confirmContinueEvenThoughNoGitRepo();\n\n const projectDir = process.cwd();\n const buildGradleFiles = findFilesWithExtensions(projectDir, [\n '.gradle',\n 'gradle.kts',\n ]);\n\n if (!buildGradleFiles || buildGradleFiles.length === 0) {\n clack.log.error(\n 'No Gradle project found. Please run this command from the root of your project.',\n );\n await abort();\n return;\n }\n\n const appFile = await traceStep('Select App File', () =>\n gradle.selectAppFile(buildGradleFiles),\n );\n\n const { selectedProject, authToken } = await getOrAskForProjectData(\n options,\n 'android',\n );\n\n // ======== STEP 1. Add Sentry Gradle Plugin to build.gradle(.kts) ============\n clack.log.step(\n `Adding ${chalk.bold('Sentry Gradle plugin')} to your app's ${chalk.cyan(\n 'build.gradle',\n )} file.`,\n );\n const pluginAdded = await traceStep('Add Gradle Plugin', () =>\n gradle.addGradlePlugin(\n appFile,\n selectedProject.organization.slug,\n selectedProject.slug,\n ),\n );\n if (!pluginAdded) {\n clack.log.warn(\n \"Could not add Sentry Gradle plugin to your app's build.gradle file. You'll have to add it manually.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#install\",\n );\n }\n\n // ======== STEP 2. Configure Sentry SDK via AndroidManifest ============\n clack.log.step(\n `Configuring Sentry SDK via ${chalk.cyan('AndroidManifest.xml')}`,\n );\n const appDir = path.dirname(appFile);\n const manifestFile = path.join(appDir, 'src', 'main', 'AndroidManifest.xml');\n\n const manifestUpdated = traceStep('Update Android Manifest', () =>\n manifest.addManifestSnippet(\n manifestFile,\n selectedProject.keys[0].dsn.public,\n ),\n );\n if (!manifestUpdated) {\n clack.log.warn(\n \"Could not configure the Sentry SDK. You'll have to do it manually.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#configure\",\n );\n }\n\n // ======== STEP 3. Patch Main Activity with a test error snippet ============\n clack.log.step(\n `Patching ${chalk.bold('Main Activity')} with a test error snippet.`,\n );\n const mainActivity = traceStep('Find Main Activity', () =>\n manifest.getMainActivity(manifestFile),\n );\n let packageName = mainActivity.packageName;\n if (!packageName) {\n // if no package name in AndroidManifest, look into gradle script\n packageName = gradle.getNamespace(appFile);\n }\n const activityName = mainActivity.activityName;\n if (!activityName || !packageName) {\n clack.log.warn(\n \"Could not find Activity with intent action MAIN. You'll have to manually verify the setup.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify\",\n );\n } else {\n const packageNameStable = packageName;\n const activityFile = traceStep('Find Main Activity Source File', () =>\n codetools.findActivitySourceFile(appDir, packageNameStable, activityName),\n );\n\n const activityPatched = traceStep('Patch Main Activity', () =>\n codetools.patchMainActivity(activityFile),\n );\n if (!activityPatched) {\n clack.log.warn(\n \"Could not patch main activity. You'll have to manually verify the setup.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify\",\n );\n }\n }\n\n // ======== STEP 4. Add sentry-cli config file ============\n clack.log.step(\n `Configuring ${chalk.bold('proguard mappings upload')} via the ${chalk.cyan(\n 'sentry.properties',\n )} file.`,\n );\n await traceStep('Add SentryCli Config', () =>\n addSentryCliConfig(authToken, proguardMappingCliSetupConfig),\n );\n\n // ======== OUTRO ========\n clack.outro(`\n${chalk.greenBright('Successfully installed the Sentry Android SDK!')}\n\n${chalk.cyan(\n 'You can validate your setup by launching your application and checking Sentry issues page afterwards',\n)}\n\nCheck out the SDK documentation for further configuration:\nhttps://docs.sentry.io/platforms/android/\n `);\n}\n\n//find files with the given extension\nfunction findFilesWithExtensions(\n dir: string,\n extensions: string[],\n filesWithExtensions: string[] = [],\n): string[] {\n const cwd = process.cwd();\n const files = fs.readdirSync(dir, { withFileTypes: true });\n for (const file of files) {\n if (file.isDirectory()) {\n const childDir = path.join(dir, file.name);\n findFilesWithExtensions(childDir, extensions, filesWithExtensions);\n } else if (extensions.some((ext) => file.name.endsWith(ext))) {\n filesWithExtensions.push(path.relative(cwd, path.join(dir, file.name)));\n }\n }\n return filesWithExtensions;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"android-wizard.js","sourceRoot":"","sources":["../../../src/android/android-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA4D;AAC5D,qCAAyB;AACzB,yEAAyE;AACzE,oDAAwC;AACxC,yCAA6B;AAC7B,mDAAuC;AACvC,+CAAmC;AACnC,mDAAuC;AACvC,sDAA0C;AAC1C,oDAQ8B;AAE9B,0CAAwD;AACxD,gDAA0B;AAE1B,IAAM,6BAA6B,GAAmB;IACpD,QAAQ,EAAE,oCAAsB;IAChC,IAAI,EAAE,mBAAmB;IACzB,yBAAyB,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E,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3C,uBAAuB,CAAC,QAAQ,EAAE,UAAU,EAAE,mBAAmB,CAAC,CAAC;SACpE;aAAM,IAAI,UAAU,CAAC,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAvB,CAAuB,CAAC,EAAE;YAC5D,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACzE;;IANH,KAAmB,UAAK,EAAL,eAAK,EAAL,mBAAK,EAAL,IAAK;QAAnB,IAAM,IAAI,cAAA;gBAAJ,IAAI;KAOd;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["/* 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 path from 'path';\nimport * as Sentry from '@sentry/node';\nimport * as gradle from './gradle';\nimport * as manifest from './manifest';\nimport * as codetools from './code-tools';\nimport {\n CliSetupConfig,\n SENTRY_PROPERTIES_FILE,\n abort,\n addSentryCliConfig,\n confirmContinueEvenThoughNoGitRepo,\n getOrAskForProjectData,\n printWelcome,\n} from '../utils/clack-utils';\nimport { WizardOptions } from '../utils/types';\nimport { traceStep, withTelemetry } from '../telemetry';\nimport chalk from 'chalk';\n\nconst proguardMappingCliSetupConfig: CliSetupConfig = {\n filename: SENTRY_PROPERTIES_FILE,\n name: 'proguard mappings',\n likelyAlreadyHasAuthToken(contents: string): boolean {\n return !!contents.match(/auth\\.token=./g);\n },\n tokenContent(authToken: string): string {\n return `auth.token=${authToken}`;\n },\n likelyAlreadyHasOrgAndProject(contents: string): boolean {\n return !!(\n contents.match(/defaults\\.org=./g) &&\n contents.match(/defaults\\.project=./g)\n );\n },\n orgAndProjContent(org: string, project: string): string {\n return `defaults.org=${org}\\ndefaults.project=${project}`;\n },\n};\n\nexport async function runAndroidWizard(options: WizardOptions): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'android',\n },\n () => runAndroidWizardWithTelemetry(options),\n );\n}\n\nasync function runAndroidWizardWithTelemetry(\n options: WizardOptions,\n): Promise<void> {\n printWelcome({\n wizardName: 'Sentry Android Wizard',\n promoCode: options.promoCode,\n });\n\n await confirmContinueEvenThoughNoGitRepo();\n\n const projectDir = process.cwd();\n const buildGradleFiles = findFilesWithExtensions(projectDir, [\n '.gradle',\n 'gradle.kts',\n ]);\n\n if (!buildGradleFiles || buildGradleFiles.length === 0) {\n clack.log.error(\n 'No Gradle project found. Please run this command from the root of your project.',\n );\n Sentry.captureException('No Gradle project found');\n await abort();\n return;\n }\n\n const appFile = await traceStep('Select App File', () =>\n gradle.selectAppFile(buildGradleFiles),\n );\n\n const { selectedProject, authToken } = await getOrAskForProjectData(\n options,\n 'android',\n );\n\n // ======== STEP 1. Add Sentry Gradle Plugin to build.gradle(.kts) ============\n clack.log.step(\n `Adding ${chalk.bold('Sentry Gradle plugin')} to your app's ${chalk.cyan(\n 'build.gradle',\n )} file.`,\n );\n const pluginAdded = await traceStep('Add Gradle Plugin', () =>\n gradle.addGradlePlugin(\n appFile,\n selectedProject.organization.slug,\n selectedProject.slug,\n ),\n );\n if (!pluginAdded) {\n clack.log.warn(\n \"Could not add Sentry Gradle plugin to your app's build.gradle file. You'll have to add it manually.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#install\",\n );\n }\n Sentry.setTag('gradle-plugin-added', pluginAdded);\n\n // ======== STEP 2. Configure Sentry SDK via AndroidManifest ============\n clack.log.step(\n `Configuring Sentry SDK via ${chalk.cyan('AndroidManifest.xml')}`,\n );\n const appDir = path.dirname(appFile);\n const manifestFile = path.join(appDir, 'src', 'main', 'AndroidManifest.xml');\n\n const manifestUpdated = traceStep('Update Android Manifest', () =>\n manifest.addManifestSnippet(\n manifestFile,\n selectedProject.keys[0].dsn.public,\n ),\n );\n if (!manifestUpdated) {\n clack.log.warn(\n \"Could not configure the Sentry SDK. You'll have to do it manually.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#configure\",\n );\n }\n Sentry.setTag('android-manifest-updated', manifestUpdated);\n\n // ======== STEP 3. Patch Main Activity with a test error snippet ============\n clack.log.step(\n `Patching ${chalk.bold('Main Activity')} with a test error snippet.`,\n );\n const mainActivity = traceStep('Find Main Activity', () =>\n manifest.getMainActivity(manifestFile),\n );\n let packageName = mainActivity.packageName;\n if (!packageName) {\n // if no package name in AndroidManifest, look into gradle script\n packageName = gradle.getNamespace(appFile);\n }\n const activityName = mainActivity.activityName;\n Sentry.setTag('has-activity-name', !!activityName);\n Sentry.setTag('has-package-name', !!packageName);\n if (!activityName || !packageName) {\n clack.log.warn(\n \"Could not find Activity with intent action MAIN. You'll have to manually verify the setup.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify\",\n );\n Sentry.captureException('Could not find Main Activity');\n } else {\n const packageNameStable = packageName;\n const activityFile = traceStep('Find Main Activity Source File', () =>\n codetools.findActivitySourceFile(appDir, packageNameStable, activityName),\n );\n\n const activityPatched = traceStep('Patch Main Activity', () =>\n codetools.patchMainActivity(activityFile),\n );\n if (!activityPatched) {\n clack.log.warn(\n \"Could not patch main activity. You'll have to manually verify the setup.\\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify\",\n );\n }\n Sentry.setTag('main-activity-patched', activityPatched);\n }\n\n // ======== STEP 4. Add sentry-cli config file ============\n clack.log.step(\n `Configuring ${chalk.bold('proguard mappings upload')} via the ${chalk.cyan(\n 'sentry.properties',\n )} file.`,\n );\n await traceStep('Add SentryCli Config', () =>\n addSentryCliConfig(authToken, proguardMappingCliSetupConfig),\n );\n\n // ======== OUTRO ========\n clack.outro(`\n${chalk.greenBright('Successfully installed the Sentry Android SDK!')}\n\n${chalk.cyan(\n 'You can validate your setup by launching your application and checking Sentry issues page afterwards',\n)}\n\nCheck out the SDK documentation for further configuration:\nhttps://docs.sentry.io/platforms/android/\n `);\n}\n\n//find files with the given extension\nfunction findFilesWithExtensions(\n dir: string,\n extensions: string[],\n filesWithExtensions: string[] = [],\n): string[] {\n const cwd = process.cwd();\n const files = fs.readdirSync(dir, { withFileTypes: true });\n for (const file of files) {\n if (file.isDirectory()) {\n const childDir = path.join(dir, file.name);\n findFilesWithExtensions(childDir, extensions, filesWithExtensions);\n } else if (extensions.some((ext) => file.name.endsWith(ext))) {\n filesWithExtensions.push(path.relative(cwd, path.join(dir, file.name)));\n }\n }\n return filesWithExtensions;\n}\n"]}
|
|
@@ -37,3 +37,11 @@ export declare function findActivitySourceFile(appDir: string, packageName: stri
|
|
|
37
37
|
* @returns true if successfully patched, false otherwise
|
|
38
38
|
*/
|
|
39
39
|
export declare function patchMainActivity(activityFile: string | undefined): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the string index of the last import statement in the given code file.
|
|
42
|
+
* Works for both Java and Kotlin import statements.
|
|
43
|
+
*
|
|
44
|
+
* @param sourceCode
|
|
45
|
+
* @returns the insert index, or 0 if none found.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getLastImportLineLocation(sourceCode: string): number;
|
|
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.patchMainActivity = exports.findActivitySourceFile = void 0;
|
|
38
|
+
exports.getLastImportLineLocation = exports.patchMainActivity = exports.findActivitySourceFile = void 0;
|
|
39
39
|
var fs = __importStar(require("fs"));
|
|
40
40
|
var path = __importStar(require("path"));
|
|
41
41
|
var Sentry = __importStar(require("@sentry/node"));
|
|
@@ -114,13 +114,7 @@ function patchMainActivity(activityFile) {
|
|
|
114
114
|
clack.log.success(chalk_1.default.greenBright("".concat(chalk_1.default.bold('Main Activity'), " is already patched with test error snippet.")));
|
|
115
115
|
return true;
|
|
116
116
|
}
|
|
117
|
-
var
|
|
118
|
-
var importsMatch = importRegex.exec(activityContent);
|
|
119
|
-
var importIndex = 0;
|
|
120
|
-
while (importsMatch) {
|
|
121
|
-
importIndex = importsMatch.index + importsMatch[0].length + 1;
|
|
122
|
-
importsMatch = importRegex.exec(activityContent);
|
|
123
|
-
}
|
|
117
|
+
var importIndex = getLastImportLineLocation(activityContent);
|
|
124
118
|
var newActivityContent;
|
|
125
119
|
if (activityFile.endsWith('.kt')) {
|
|
126
120
|
newActivityContent =
|
|
@@ -158,4 +152,22 @@ function patchMainActivity(activityFile) {
|
|
|
158
152
|
return true;
|
|
159
153
|
}
|
|
160
154
|
exports.patchMainActivity = patchMainActivity;
|
|
155
|
+
/**
|
|
156
|
+
* Returns the string index of the last import statement in the given code file.
|
|
157
|
+
* Works for both Java and Kotlin import statements.
|
|
158
|
+
*
|
|
159
|
+
* @param sourceCode
|
|
160
|
+
* @returns the insert index, or 0 if none found.
|
|
161
|
+
*/
|
|
162
|
+
function getLastImportLineLocation(sourceCode) {
|
|
163
|
+
var importRegex = /import(?:\sstatic)?\s+[\w.*]+(?: as [\w.]+)?;?/gim;
|
|
164
|
+
var importsMatch = importRegex.exec(sourceCode);
|
|
165
|
+
var importIndex = 0;
|
|
166
|
+
while (importsMatch) {
|
|
167
|
+
importIndex = importsMatch.index + importsMatch[0].length + 1;
|
|
168
|
+
importsMatch = importRegex.exec(sourceCode);
|
|
169
|
+
}
|
|
170
|
+
return importIndex;
|
|
171
|
+
}
|
|
172
|
+
exports.getLastImportLineLocation = getLastImportLineLocation;
|
|
161
173
|
//# sourceMappingURL=code-tools.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-tools.js","sourceRoot":"","sources":["../../../src/android/code-tools.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qC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C,KAAK,CAAC,aAAa,CAAC,CAAC;KAC3C;IACD,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;IAE3D,KAAK,CAAC,GAAG,CAAC,OAAO,CACf,eAAK,CAAC,WAAW,CACf,kBAAW,eAAK,CAAC,IAAI,CACnB,eAAe,CAChB,yCAAsC,CACxC,CACF,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AAlED,8CAkEC;AAED;;;;;;GAMG;AACH,SAAgB,yBAAyB,CAAC,UAAkB;IAC1D,IAAM,WAAW,GAAG,mDAAmD,CAAC;IAExE,IAAI,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAChD,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,OAAO,YAAY,EAAE;QACnB,WAAW,GAAG,YAAY,CAAC,KAAK,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9D,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KAC7C;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAVD,8DAUC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\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 {\n sentryImport,\n sentryImportKt,\n testErrorSnippet,\n testErrorSnippetKt,\n} from './templates';\nimport { findFile } from '../utils/ast-utils';\n\n/**\n * Looks in src/main/java or src/main/kotlin for the specified {@link packageName} and\n * {@link activityName} by concatenating them. For example:\n *\n * src/\n * main/\n * java/ or kotlin/\n * my.package.name/\n * ui/\n * MainActivity.kt\n *\n * src/main/java can contain both .java and .kt sources, whilst src/main/kotlin only .kt\n *\n * @param appDir\n * @param packageName\n * @param activityName\n * @returns path to the Main Activity\n */\nexport function findActivitySourceFile(\n appDir: string,\n packageName: string,\n activityName: string,\n): string | undefined {\n const javaSrcDir = path.join(appDir, 'src', 'main', 'java');\n let possibleActivityPath;\n // if activity name starts with a dot, this means we need to concat packagename with it, otherwise\n // the package name is already specified in the activity name itself\n const packageNameParts = activityName.startsWith('.')\n ? packageName.split('.')\n : [];\n const activityNameParts = activityName.split('.');\n\n if (fs.existsSync(javaSrcDir)) {\n possibleActivityPath = findFile(\n path.join(javaSrcDir, ...packageNameParts, ...activityNameParts),\n ['.kt', '.java'],\n );\n }\n\n if (!possibleActivityPath || !fs.existsSync(possibleActivityPath)) {\n const kotlinSrcDir = path.join(appDir, 'src', 'main', 'kotlin');\n if (fs.existsSync(kotlinSrcDir)) {\n possibleActivityPath = findFile(\n path.join(kotlinSrcDir, ...packageNameParts, ...activityNameParts),\n ['.kt'],\n );\n }\n }\n return possibleActivityPath;\n}\n\n/**\n * Patches Main Activity with the test error code snippet by the specified path {@link activityFile}.\n * Finds activity's `onCreate` method, adds the snippet and necessary imports.\n *\n * ```kotlin\n * import something\n * import something.something\n * import io.sentry.Sentry <-- this is added by us\n *\n * override fun onCreate(savedInstanceState: Bundle?) {\n * super.onCreate(savedInstanceState)\n * // the snippet goes here <--\n * doSomething()\n * }\n * ```\n *\n * @param activityFile\n * @returns true if successfully patched, false otherwise\n */\nexport function patchMainActivity(activityFile: string | undefined): boolean {\n if (!activityFile || !fs.existsSync(activityFile)) {\n clack.log.warn('No main activity source file found in filesystem.');\n Sentry.captureException('No main activity source file');\n return false;\n }\n\n const activityContent = fs.readFileSync(activityFile, 'utf8');\n\n if (/import\\s+io\\.sentry\\.Sentry;?/i.test(activityContent)) {\n // sentry is already configured\n clack.log.success(\n chalk.greenBright(\n `${chalk.bold(\n 'Main Activity',\n )} is already patched with test error snippet.`,\n ),\n );\n return true;\n }\n\n const importIndex = getLastImportLineLocation(activityContent);\n\n let newActivityContent;\n if (activityFile.endsWith('.kt')) {\n newActivityContent =\n activityContent.slice(0, importIndex) +\n sentryImportKt +\n activityContent.slice(importIndex);\n } else {\n newActivityContent =\n activityContent.slice(0, importIndex) +\n sentryImport +\n activityContent.slice(importIndex);\n }\n\n const onCreateMatch = /super\\.onCreate\\(.*?\\);?/i.exec(newActivityContent);\n if (!onCreateMatch) {\n clack.log.warn('No onCreate method found in main activity.');\n Sentry.captureException('No onCreate method');\n return false;\n }\n\n const onCreateIndex = onCreateMatch.index + onCreateMatch[0].length;\n if (activityFile.endsWith('.kt')) {\n newActivityContent =\n newActivityContent.slice(0, onCreateIndex) +\n testErrorSnippetKt +\n newActivityContent.slice(onCreateIndex);\n } else {\n newActivityContent =\n newActivityContent.slice(0, onCreateIndex) +\n testErrorSnippet +\n newActivityContent.slice(onCreateIndex);\n }\n fs.writeFileSync(activityFile, newActivityContent, 'utf8');\n\n clack.log.success(\n chalk.greenBright(\n `Patched ${chalk.bold(\n 'Main Activity',\n )} with the Sentry test error snippet.`,\n ),\n );\n\n return true;\n}\n\n/**\n * Returns the string index of the last import statement in the given code file.\n * Works for both Java and Kotlin import statements.\n *\n * @param sourceCode\n * @returns the insert index, or 0 if none found.\n */\nexport function getLastImportLineLocation(sourceCode: string): number {\n const importRegex = /import(?:\\sstatic)?\\s+[\\w.*]+(?: as [\\w.]+)?;?/gim;\n\n let importsMatch = importRegex.exec(sourceCode);\n let importIndex = 0;\n while (importsMatch) {\n importIndex = importsMatch.index + importsMatch[0].length + 1;\n importsMatch = importRegex.exec(sourceCode);\n }\n return importIndex;\n}\n"]}
|
|
@@ -105,7 +105,12 @@ function selectAppFile(buildGradleFiles) {
|
|
|
105
105
|
if (!(appFiles.length === 0)) return [3 /*break*/, 2];
|
|
106
106
|
Sentry.setTag('custom-build-logic', true);
|
|
107
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
|
|
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",
|
|
109
|
+
placeholder: 'app/build.gradle.kts',
|
|
110
|
+
validate: function (value) {
|
|
111
|
+
if (!value.includes('.gradle') || !fs.existsSync(value))
|
|
112
|
+
return "Not a valid gradle file.";
|
|
113
|
+
},
|
|
109
114
|
}))];
|
|
110
115
|
case 1:
|
|
111
116
|
appFile_1 = _a.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradle.js","sourceRoot":"","sources":["../../../src/android/gradle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA4D;AAC5D,qCAAyB;AACzB,oDAA6E;AAC7E,yCAOqB;AACrB,kDAAsC;AACtC,mDAAuC;AACvC,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAC1B,8DAA4D;AAE5D;;;;;;;;;;;;;;GAcG;AACH,SAAsB,aAAa,CACjC,gBAA0B;;;;;;oBAEpB,QAAQ,GAAG,EAAE,CAAC;oBACpB,KAAS,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;wBACtD,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;wBAC/B,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;wBAC3C,IAAI,iDAAiD,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;4BAChE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;yBACrB;qBACF;yBAEG,CAAA,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAA,EAArB,wBAAqB;oBACvB,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;oBAC1B,qBAAM,IAAA,8BAAgB,EACpC,KAAK,CAAC,IAAI,CAAC;4BACT,OAAO,EAAE,qKAC0G;yBACpH,CAAC,CACH,EAAA;;oBALK,YAAU,SAKf;oBACD,sBAAO,SAAO,EAAC;;yBAIb,C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AAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YAC5B,EAAE,CAAC,cAAc,CACf,OAAO,EACP,IAAA,4BAAgB,EAAC,OAAO,EAAE,WAAW,CAAC,EACtC,MAAM,CACP,CAAC;SACH;aAAM;YACL,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,IAAA,yBAAa,EAAC,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC;SACzE;KACF;AACH,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-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"]}
|
|
1
|
+
{"version":3,"file":"gradle.js","sourceRoot":"","sources":["../../../src/android/gradle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA4D;AAC5D,qCAAyB;AACzB,oDAA6E;AAC7E,yCAOqB;AACrB,kDAAsC;AACtC,mDAAuC;AACvC,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAC1B,8DAA4D;AAE5D;;;;;;;;;;;;;;GAcG;AACH,SAAsB,aAAa,CACjC,gBAA0B;;;;;;oBAEpB,QAAQ,GAAG,EAAE,CAAC;oBACpB,KAAS,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;wBACtD,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;wBAC/B,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;wBAC3C,IAAI,iDAAiD,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;4BAChE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;yBACrB;qBACF;yBAEG,CAAA,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAA,EAArB,wBAAqB;oBACvB,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC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AC,CAAC;QAChE,MAAM,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;QAC3C,OAAO,SAAS,CAAC;KAClB;IAED,IAAM,SAAS,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;IACpC,OAAO,SAAS,CAAC;AACnB,CAAC;AAdD,oCAcC;AAED;;;;;GAKG;AACH,SAAS,2BAA2B,CAClC,OAAe,EACf,YAAoB,EACpB,OAAe,EACf,WAAmB;IAEnB,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE;QAC7C,kFAAkF;QAClF,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YAC5B,EAAE,CAAC,cAAc,CACf,OAAO,EACP,IAAA,4BAAgB,EAAC,OAAO,EAAE,WAAW,CAAC,EACtC,MAAM,CACP,CAAC;SACH;aAAM;YACL,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,IAAA,yBAAa,EAAC,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC;SACzE;KACF;AACH,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-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`,\n placeholder: 'app/build.gradle.kts',\n validate(value) {\n if (!value.includes('.gradle') || !fs.existsSync(value))\n return `Not a valid gradle file.`;\n },\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"]}
|
|
@@ -107,8 +107,9 @@ var getViteConfigContent = function (importStmt, generateSourceMapsOption, sentr
|
|
|
107
107
|
var configureVitePlugin = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
108
|
var _a, _b, _c, viteConfigPath, _d, successfullyAdded;
|
|
109
109
|
var _e;
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
var _f;
|
|
111
|
+
return __generator(this, function (_g) {
|
|
112
|
+
switch (_g.label) {
|
|
112
113
|
case 0:
|
|
113
114
|
_a = clack_utils_1.installPackage;
|
|
114
115
|
_e = {
|
|
@@ -117,73 +118,52 @@ var configureVitePlugin = function (options) { return __awaiter(void 0, void 0,
|
|
|
117
118
|
_b = package_json_1.hasPackageInstalled;
|
|
118
119
|
_c = ['@sentry/vite-plugin'];
|
|
119
120
|
return [4 /*yield*/, (0, clack_utils_1.getPackageDotJson)()];
|
|
120
|
-
case 1: return [4 /*yield*/, _a.apply(void 0, [(_e.alreadyInstalled = _b.apply(void 0, _c.concat([
|
|
121
|
+
case 1: return [4 /*yield*/, _a.apply(void 0, [(_e.alreadyInstalled = _b.apply(void 0, _c.concat([_g.sent()])),
|
|
121
122
|
_e)])];
|
|
122
123
|
case 2:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return [
|
|
127
|
-
case 3:
|
|
128
|
-
_d = (_f.sent());
|
|
129
|
-
_f.label = 4;
|
|
124
|
+
_g.sent();
|
|
125
|
+
if (!((_f = (0, ast_utils_1.findFile)(path.resolve(process.cwd(), 'vite.config'))) !== null && _f !== void 0)) return [3 /*break*/, 3];
|
|
126
|
+
_d = _f;
|
|
127
|
+
return [3 /*break*/, 5];
|
|
128
|
+
case 3: return [4 /*yield*/, (0, clack_utils_1.askForToolConfigPath)('Vite', 'vite.config.js')];
|
|
130
129
|
case 4:
|
|
130
|
+
_d = (_g.sent());
|
|
131
|
+
_g.label = 5;
|
|
132
|
+
case 5:
|
|
131
133
|
viteConfigPath = _d;
|
|
132
134
|
successfullyAdded = false;
|
|
133
|
-
if (!viteConfigPath) return [3 /*break*/,
|
|
135
|
+
if (!viteConfigPath) return [3 /*break*/, 7];
|
|
134
136
|
return [4 /*yield*/, addVitePluginToConfig(viteConfigPath, options)];
|
|
135
|
-
case
|
|
136
|
-
successfullyAdded =
|
|
137
|
-
return [3 /*break*/,
|
|
138
|
-
case
|
|
139
|
-
case 7:
|
|
140
|
-
successfullyAdded = _f.sent();
|
|
141
|
-
_f.label = 8;
|
|
137
|
+
case 6:
|
|
138
|
+
successfullyAdded = _g.sent();
|
|
139
|
+
return [3 /*break*/, 9];
|
|
140
|
+
case 7: return [4 /*yield*/, (0, clack_utils_1.createNewConfigFile)(path.join(process.cwd(), 'vite.config.js'), getViteConfigSnippet(options, false), 'More information about vite configs: https://vitejs.dev/config/')];
|
|
142
141
|
case 8:
|
|
143
|
-
|
|
144
|
-
Sentry.setTag('
|
|
145
|
-
|
|
142
|
+
successfullyAdded = _g.sent();
|
|
143
|
+
Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
|
|
144
|
+
_g.label = 9;
|
|
146
145
|
case 9:
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
if (!successfullyAdded) return [3 /*break*/, 10];
|
|
147
|
+
clack.log.info("We recommend checking the ".concat(viteConfigPath ? 'modified' : 'added', " file after the wizard finished to ensure it works with your build setup."));
|
|
148
|
+
Sentry.setTag('ast-mod', 'success');
|
|
149
|
+
return [3 /*break*/, 12];
|
|
149
150
|
case 10:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
case 11:
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
Sentry.setTag('ast-mod', 'fail');
|
|
152
|
+
return [4 /*yield*/, (0, clack_utils_1.showCopyPasteInstructions)(path.basename(viteConfigPath || 'vite.config.js'), getViteConfigSnippet(options, true))];
|
|
153
|
+
case 11:
|
|
154
|
+
_g.sent();
|
|
155
|
+
_g.label = 12;
|
|
156
|
+
case 12: return [4 /*yield*/, (0, clack_utils_1.addDotEnvSentryBuildPluginFile)(options.authToken)];
|
|
157
|
+
case 13:
|
|
158
|
+
_g.sent();
|
|
155
159
|
return [2 /*return*/];
|
|
156
160
|
}
|
|
157
161
|
});
|
|
158
162
|
}); };
|
|
159
163
|
exports.configureVitePlugin = configureVitePlugin;
|
|
160
|
-
function createNewViteConfig(options) {
|
|
161
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
-
var e_1;
|
|
163
|
-
return __generator(this, function (_a) {
|
|
164
|
-
switch (_a.label) {
|
|
165
|
-
case 0:
|
|
166
|
-
_a.trys.push([0, 2, , 3]);
|
|
167
|
-
return [4 /*yield*/, fs.promises.writeFile('vite.config.js', getViteConfigSnippet(options, false))];
|
|
168
|
-
case 1:
|
|
169
|
-
_a.sent();
|
|
170
|
-
Sentry.setTag('created-new-config', 'success');
|
|
171
|
-
return [2 /*return*/, true];
|
|
172
|
-
case 2:
|
|
173
|
-
e_1 = _a.sent();
|
|
174
|
-
(0, debug_1.debug)(e_1);
|
|
175
|
-
Sentry.setTag('created-new-config', 'fail');
|
|
176
|
-
clack.log.warn("Could not create a new ".concat(chalk_1.default.cyan('vite.config.js'), " file. Please create one manually and follow the instructions below."));
|
|
177
|
-
clack.log.info(chalk_1.default.gray('More information about vite configs: https://vitejs.dev/config/'));
|
|
178
|
-
return [2 /*return*/, false];
|
|
179
|
-
case 3: return [2 /*return*/];
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
164
|
function addVitePluginToConfig(viteConfigPath, options) {
|
|
185
165
|
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
-
var prettyViteConfigFilename, viteConfigContent, mod, shouldContinue, enabledSourcemaps, org, project, selfHosted, url, code,
|
|
166
|
+
var prettyViteConfigFilename, viteConfigContent, mod, shouldContinue, enabledSourcemaps, org, project, selfHosted, url, code, e_1;
|
|
187
167
|
return __generator(this, function (_a) {
|
|
188
168
|
switch (_a.label) {
|
|
189
169
|
case 0:
|
|
@@ -193,7 +173,7 @@ function addVitePluginToConfig(viteConfigPath, options) {
|
|
|
193
173
|
case 1:
|
|
194
174
|
viteConfigContent = (_a.sent()).toString();
|
|
195
175
|
mod = (0, magicast_1.parseModule)(viteConfigContent);
|
|
196
|
-
if (!(0, ast_utils_1.hasSentryContent)(mod)) return [3 /*break*/, 3];
|
|
176
|
+
if (!(0, ast_utils_1.hasSentryContent)(mod.$ast)) return [3 /*break*/, 3];
|
|
197
177
|
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
198
178
|
message: "".concat(prettyViteConfigFilename, " already contains Sentry-related code. Should the wizard modify it anyway?"),
|
|
199
179
|
options: [
|
|
@@ -235,8 +215,8 @@ function addVitePluginToConfig(viteConfigPath, options) {
|
|
|
235
215
|
clack.log.success("Added the Sentry Vite plugin to ".concat(prettyViteConfigFilename, " and enabled source maps"));
|
|
236
216
|
return [2 /*return*/, true];
|
|
237
217
|
case 5:
|
|
238
|
-
|
|
239
|
-
(0, debug_1.debug)(
|
|
218
|
+
e_1 = _a.sent();
|
|
219
|
+
(0, debug_1.debug)(e_1);
|
|
240
220
|
Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
|
|
241
221
|
return [2 /*return*/, false];
|
|
242
222
|
case 6: return [2 /*return*/];
|
|
@@ -245,61 +225,6 @@ function addVitePluginToConfig(viteConfigPath, options) {
|
|
|
245
225
|
});
|
|
246
226
|
}
|
|
247
227
|
exports.addVitePluginToConfig = addVitePluginToConfig;
|
|
248
|
-
function showCopyPasteInstructions(viteConfigFilename, options) {
|
|
249
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
250
|
-
return __generator(this, function (_a) {
|
|
251
|
-
switch (_a.label) {
|
|
252
|
-
case 0:
|
|
253
|
-
clack.log.step("Add the following code to your ".concat(chalk_1.default.cyan(viteConfigFilename), " file:"));
|
|
254
|
-
// Intentionally logging directly to console here so that the code can be copied/pasted directly
|
|
255
|
-
// eslint-disable-next-line no-console
|
|
256
|
-
console.log("\n".concat(getViteConfigSnippet(options, true)));
|
|
257
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
258
|
-
message: 'Did you copy the snippet above?',
|
|
259
|
-
options: [{ label: 'Yes, continue!', value: true }],
|
|
260
|
-
initialValue: true,
|
|
261
|
-
}))];
|
|
262
|
-
case 1:
|
|
263
|
-
_a.sent();
|
|
264
|
-
return [2 /*return*/];
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
function askForViteConfigPath() {
|
|
270
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
271
|
-
var hasViteConfig;
|
|
272
|
-
return __generator(this, function (_a) {
|
|
273
|
-
switch (_a.label) {
|
|
274
|
-
case 0: return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.confirm({
|
|
275
|
-
message: "Do you have a vite config file (e.g. ".concat(chalk_1.default.cyan('vite.config.js'), "?"),
|
|
276
|
-
initialValue: true,
|
|
277
|
-
}))];
|
|
278
|
-
case 1:
|
|
279
|
-
hasViteConfig = _a.sent();
|
|
280
|
-
if (!hasViteConfig) {
|
|
281
|
-
return [2 /*return*/, undefined];
|
|
282
|
-
}
|
|
283
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.text({
|
|
284
|
-
message: 'Please enter the path to your vite config file:',
|
|
285
|
-
placeholder: ".".concat(path.sep, "vite.config.js"),
|
|
286
|
-
validate: function (value) {
|
|
287
|
-
if (!value) {
|
|
288
|
-
return 'Please enter a path.';
|
|
289
|
-
}
|
|
290
|
-
try {
|
|
291
|
-
fs.accessSync(value);
|
|
292
|
-
}
|
|
293
|
-
catch (_a) {
|
|
294
|
-
return 'Could not access the file at this path.';
|
|
295
|
-
}
|
|
296
|
-
},
|
|
297
|
-
}))];
|
|
298
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
228
|
function enableSourcemapGeneration(program) {
|
|
304
229
|
var configObj = getViteConfigObject(program);
|
|
305
230
|
if (!configObj) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/vite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,4EAA4E;AAC5E,qCAAqD;AACrD,4EAA4E;AAC5E,4CAAiD;AAIjD,6CAAiC;AAEjC,mDAAuC;AAEvC,gDAA0B;AAC1B,uDAKiC;AACjC,y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WAAW,CAAC,IAAI,CAAC;QAChD,OAAO,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;KAC1C;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,cAAc,CACrB,QAAgB,EAChB,OAAkB;;IAElB,KAAmB,UAAY,EAAZ,KAAA,OAAO,CAAC,IAAI,EAAZ,cAAY,EAAZ,IAAY,EAAE;QAA5B,IAAM,IAAI,SAAA;QACb,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB,EAAE;YACvC,KAA0B,UAAiB,EAAjB,KAAA,IAAI,CAAC,YAAY,EAAjB,cAAiB,EAAjB,IAAiB,EAAE;gBAAxC,IAAM,WAAW,SAAA;gBACpB,IACE,WAAW,CAAC,IAAI,KAAK,oBAAoB;oBACzC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,YAAY;oBACpC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,QAAQ;oBAChC,CAAA,MAAA,WAAW,CAAC,IAAI,0CAAE,IAAI,MAAK,kBAAkB,EAC7C;oBACA,OAAO,WAAW,CAAC,IAAI,CAAC;iBACzB;aACF;SACF;KACF;IACD,OAAO,SAAS,CAAC;AACnB,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 { generateCode, parseModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\n\nimport type { namedTypes as t } from 'ast-types';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\n\nimport chalk from 'chalk';\nimport {\n abortIfCancelled,\n addDotEnvSentryBuildPluginFile,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack-utils';\nimport { hasPackageInstalled } from '../../utils/package-json';\n\nimport {\n SourceMapUploadToolConfigurationFunction,\n SourceMapUploadToolConfigurationOptions,\n} from './types';\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport { debug } from '../../utils/debug';\n\nconst getViteConfigSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) => {\n const rawImportStmt =\n 'import { sentryVitePlugin } from \"@sentry/vite-plugin\";';\n const rawGenerateSourceMapsOption =\n 'sourcemap: true, // Source map generation must be turned on';\n const rawSentryVitePluginFunction = `sentryVitePlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"${options.orgSlug}\",\n project: \"${options.projectSlug}\",${\n options.selfHosted ? `\\n url: \"${options.url}\",` : ''\n }\n }),`;\n\n const importStmt = colors ? chalk.greenBright(rawImportStmt) : rawImportStmt;\n const generateSourceMapsOption = colors\n ? chalk.greenBright(rawGenerateSourceMapsOption)\n : rawGenerateSourceMapsOption;\n const sentryVitePluginFunction = colors\n ? chalk.greenBright(rawSentryVitePluginFunction)\n : rawSentryVitePluginFunction;\n\n const code = getViteConfigContent(\n importStmt,\n generateSourceMapsOption,\n sentryVitePluginFunction,\n );\n return colors ? chalk.gray(code) : code;\n};\n\nconst getViteConfigContent = (\n importStmt: string,\n generateSourceMapsOption: string,\n sentryVitePluginFunction: string,\n) => `import { defineConfig } from \"vite\";\n${importStmt}\n\nexport default defineConfig({\n build: {\n ${generateSourceMapsOption}\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ${sentryVitePluginFunction}\n ],\n});\n`;\n\nexport const configureVitePlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/vite-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/vite-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const viteConfigPath =\n findFile(path.resolve(process.cwd(), 'vite.config')) ||\n (await askForViteConfigPath());\n\n let successfullyAdded = false;\n if (viteConfigPath) {\n successfullyAdded = await addVitePluginToConfig(viteConfigPath, options);\n } else {\n successfullyAdded = await createNewViteConfig(options);\n }\n\n if (successfullyAdded) {\n Sentry.setTag('ast-mod', 'success');\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n path.basename(viteConfigPath || 'vite.config.js'),\n options,\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\nasync function createNewViteConfig(\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n await fs.promises.writeFile(\n 'vite.config.js',\n getViteConfigSnippet(options, false),\n );\n Sentry.setTag('created-new-config', 'success');\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('created-new-config', 'fail');\n clack.log.warn(\n `Could not create a new ${chalk.cyan(\n 'vite.config.js',\n )} file. Please create one manually and follow the instructions below.`,\n );\n\n clack.log.info(\n chalk.gray(\n 'More information about vite configs: https://vitejs.dev/config/',\n ),\n );\n\n return false;\n }\n}\n\nexport async function addVitePluginToConfig(\n viteConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const prettyViteConfigFilename = chalk.cyan(path.basename(viteConfigPath));\n\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath)\n ).toString();\n\n const mod = parseModule(viteConfigContent);\n\n if (hasSentryContent(mod)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `${prettyViteConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Vite 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 return false;\n }\n }\n\n const enabledSourcemaps = enableSourcemapGeneration(mod.$ast as t.Program);\n if (!enabledSourcemaps) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const { orgSlug: org, projectSlug: project, selfHosted, url } = options;\n\n addVitePlugin(mod, {\n imported: 'sentryVitePlugin',\n from: '@sentry/vite-plugin',\n constructor: 'sentryVitePlugin',\n options: {\n org,\n project,\n ...(selfHosted && { url }),\n },\n });\n\n const code = generateCode(mod.$ast).code;\n\n await fs.promises.writeFile(viteConfigPath, code);\n\n clack.log.success(\n `Added the Sentry Vite plugin to ${prettyViteConfigFilename} and enabled source maps`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n\nasync function showCopyPasteInstructions(\n viteConfigFilename: string,\n options: SourceMapUploadToolConfigurationOptions,\n) {\n clack.log.step(\n `Add the following code to your ${chalk.cyan(viteConfigFilename)} file:`,\n );\n\n // Intentionally logging directly to console here so that the code can be copied/pasted directly\n // eslint-disable-next-line no-console\n console.log(`\\n${getViteConfigSnippet(options, true)}`);\n\n await abortIfCancelled(\n clack.select({\n message: 'Did you copy the snippet above?',\n options: [{ label: 'Yes, continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n\nasync function askForViteConfigPath(): Promise<string | undefined> {\n const hasViteConfig = await abortIfCancelled(\n clack.confirm({\n message: `Do you have a vite config file (e.g. ${chalk.cyan(\n 'vite.config.js',\n )}?`,\n initialValue: true,\n }),\n );\n\n if (!hasViteConfig) {\n return undefined;\n }\n\n return await abortIfCancelled(\n clack.text({\n message: 'Please enter the path to your vite config file:',\n placeholder: `.${path.sep}vite.config.js`,\n validate: (value) => {\n if (!value) {\n return 'Please enter a path.';\n }\n\n try {\n fs.accessSync(value);\n } catch {\n return 'Could not access the file at this path.';\n }\n },\n }),\n );\n}\n\nfunction enableSourcemapGeneration(program: t.Program): boolean {\n const configObj = getViteConfigObject(program);\n\n if (!configObj) {\n return false;\n }\n\n const b = recast.types.builders;\n\n const buildProp = configObj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'build',\n );\n\n // case 1: build property doesn't exist yet, so we can just add it\n if (!buildProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('build'),\n b.objectExpression([\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n ]),\n ),\n );\n return true;\n }\n\n const isValidBuildProp =\n buildProp.type === 'ObjectProperty' &&\n buildProp.value.type === 'ObjectExpression';\n\n if (!isValidBuildProp) {\n return false;\n }\n\n const sourceMapsProp =\n buildProp.value.type === 'ObjectExpression' &&\n buildProp.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'sourcemap',\n );\n\n // case 2: build.sourcemap property doesn't exist yet, so we just add it\n if (!sourceMapsProp && buildProp.value.type === 'ObjectExpression') {\n buildProp.value.properties.push(\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n );\n return true;\n }\n\n if (!sourceMapsProp || sourceMapsProp.type !== 'ObjectProperty') {\n return false;\n }\n\n // case 3: build.sourcemap property exists, and it's set to 'hidden'\n if (\n sourceMapsProp.value.type === 'StringLiteral' &&\n sourceMapsProp.value.value === 'hidden'\n ) {\n // nothing to do for us\n return true;\n }\n\n // case 4: build.sourcemap property exists, but it's not enabled, so we set it to true\n // or it is already true in which case this is a noop\n sourceMapsProp.value = b.booleanLiteral(true);\n return true;\n}\n\nfunction getViteConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n const defaultExport = program.body.find(\n (s) => s.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration;\n\n if (!defaultExport) {\n return undefined;\n }\n\n if (defaultExport.declaration.type === 'ObjectExpression') {\n return defaultExport.declaration;\n }\n\n if (\n defaultExport.declaration.type === 'CallExpression' &&\n defaultExport.declaration.arguments[0].type === 'ObjectExpression'\n ) {\n return defaultExport.declaration.arguments[0];\n }\n\n if (defaultExport.declaration.type === 'Identifier') {\n const configId = defaultExport.declaration.name;\n return findConfigNode(configId, program);\n }\n\n return undefined;\n}\n\nfunction findConfigNode(\n configId: string,\n program: t.Program,\n): t.ObjectExpression | undefined {\n for (const node of program.body) {\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n if (\n declaration.type === 'VariableDeclarator' &&\n declaration.id.type === 'Identifier' &&\n declaration.id.name === configId &&\n declaration.init?.type === 'ObjectExpression'\n ) {\n return declaration.init;\n }\n }\n }\n }\n return undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/vite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,4EAA4E;AAC5E,qCAAqD;AACrD,4EAA4E;AAC5E,4CAAiD;AAIjD,6CAAiC;AAEjC,mDAAuC;AAEvC,gDAA0B;AAC1B,uDAQiC;AACjC,yDAA+D;AAM/D,mDAAmE;AAEnE,yCAA6B;AAC7B,qCAAyB;AACzB,2CAA0C;AAE1C,IAAM,oBAAoB,GAAG,UAC3B,OAAgD,EAChD,MAAe;IAEf,IAAM,aAAa,GACjB,yDAAyD,CAAC;IAC5D,IAAM,2BAA2B,GAC/B,6DAA6D,CAAC;IAChE,IAAM,2BAA2B,GAAG,4FAExB,OAAO,CAAC,OAAO,mCACX,OAAO,CAAC,WAAW,gBACjC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,yBAAiB,OAAO,CAAC,GAAG,QAAI,CAAC,CAAC,CAAC,EAAE,cAEtD,CAAC;IAEP,IAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,eAAK,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IAC7E,IAAM,wBAAwB,GAAG,MAAM;QACrC,CAAC,CAAC,eAAK,CAAC,WAAW,CAAC,2BAA2B,CAAC;QAChD,CAAC,CAAC,2BAA2B,CAAC;IAChC,IAAM,wBAAwB,GAAG,MAAM;QACrC,CAAC,CAAC,eAAK,CAAC,WAAW,CAAC,2BAA2B,CAAC;QAChD,CAAC,CAAC,2BAA2B,CAAC;IAEhC,IAAM,IAAI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C,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,kBAAkB,EAClE;QACA,OAAO,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KAC/C;IAED,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,KAAK,YAAY,EAAE;QACnD,IAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC;QAChD,OAAO,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;KAC1C;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,cAAc,CACrB,QAAgB,EAChB,OAAkB;;IAElB,KAAmB,UAAY,EAAZ,KAAA,OAAO,CAAC,IAAI,EAAZ,cAAY,EAAZ,IAAY,EAAE;QAA5B,IAAM,IAAI,SAAA;QACb,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB,EAAE;YACvC,KAA0B,UAAiB,EAAjB,KAAA,IAAI,CAAC,YAAY,EAAjB,cAAiB,EAAjB,IAAiB,EAAE;gBAAxC,IAAM,WAAW,SAAA;gBACpB,IACE,WAAW,CAAC,IAAI,KAAK,oBAAoB;oBACzC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,YAAY;oBACpC,WAAW,CAAC,EAAE,CAAC,IAAI,KAAK,QAAQ;oBAChC,CAAA,MAAA,WAAW,CAAC,IAAI,0CAAE,IAAI,MAAK,kBAAkB,EAC7C;oBACA,OAAO,WAAW,CAAC,IAAI,CAAC;iBACzB;aACF;SACF;KACF;IACD,OAAO,SAAS,CAAC;AACnB,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 { generateCode, parseModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\n\nimport type { namedTypes as t } from 'ast-types';\n\nimport * as recast from 'recast';\n\nimport * as Sentry from '@sentry/node';\n\nimport chalk from 'chalk';\nimport {\n abortIfCancelled,\n addDotEnvSentryBuildPluginFile,\n askForToolConfigPath,\n createNewConfigFile,\n getPackageDotJson,\n installPackage,\n showCopyPasteInstructions,\n} from '../../utils/clack-utils';\nimport { hasPackageInstalled } from '../../utils/package-json';\n\nimport {\n SourceMapUploadToolConfigurationFunction,\n SourceMapUploadToolConfigurationOptions,\n} from './types';\nimport { findFile, hasSentryContent } from '../../utils/ast-utils';\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport { debug } from '../../utils/debug';\n\nconst getViteConfigSnippet = (\n options: SourceMapUploadToolConfigurationOptions,\n colors: boolean,\n) => {\n const rawImportStmt =\n 'import { sentryVitePlugin } from \"@sentry/vite-plugin\";';\n const rawGenerateSourceMapsOption =\n 'sourcemap: true, // Source map generation must be turned on';\n const rawSentryVitePluginFunction = `sentryVitePlugin({\n authToken: process.env.SENTRY_AUTH_TOKEN,\n org: \"${options.orgSlug}\",\n project: \"${options.projectSlug}\",${\n options.selfHosted ? `\\n url: \"${options.url}\",` : ''\n }\n }),`;\n\n const importStmt = colors ? chalk.greenBright(rawImportStmt) : rawImportStmt;\n const generateSourceMapsOption = colors\n ? chalk.greenBright(rawGenerateSourceMapsOption)\n : rawGenerateSourceMapsOption;\n const sentryVitePluginFunction = colors\n ? chalk.greenBright(rawSentryVitePluginFunction)\n : rawSentryVitePluginFunction;\n\n const code = getViteConfigContent(\n importStmt,\n generateSourceMapsOption,\n sentryVitePluginFunction,\n );\n return colors ? chalk.gray(code) : code;\n};\n\nconst getViteConfigContent = (\n importStmt: string,\n generateSourceMapsOption: string,\n sentryVitePluginFunction: string,\n) => `import { defineConfig } from \"vite\";\n${importStmt}\n\nexport default defineConfig({\n build: {\n ${generateSourceMapsOption}\n },\n plugins: [\n // Put the Sentry vite plugin after all other plugins\n ${sentryVitePluginFunction}\n ],\n});\n`;\n\nexport const configureVitePlugin: SourceMapUploadToolConfigurationFunction =\n async (options) => {\n await installPackage({\n packageName: '@sentry/vite-plugin',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/vite-plugin',\n await getPackageDotJson(),\n ),\n });\n\n const viteConfigPath =\n findFile(path.resolve(process.cwd(), 'vite.config')) ??\n (await askForToolConfigPath('Vite', 'vite.config.js'));\n\n let successfullyAdded = false;\n if (viteConfigPath) {\n successfullyAdded = await addVitePluginToConfig(viteConfigPath, options);\n } else {\n successfullyAdded = await createNewConfigFile(\n path.join(process.cwd(), 'vite.config.js'),\n getViteConfigSnippet(options, false),\n 'More information about vite configs: https://vitejs.dev/config/',\n );\n Sentry.setTag(\n 'created-new-config',\n successfullyAdded ? 'success' : 'fail',\n );\n }\n\n if (successfullyAdded) {\n clack.log.info(\n `We recommend checking the ${\n viteConfigPath ? 'modified' : 'added'\n } file after the wizard finished to ensure it works with your build setup.`,\n );\n\n Sentry.setTag('ast-mod', 'success');\n } else {\n Sentry.setTag('ast-mod', 'fail');\n await showCopyPasteInstructions(\n path.basename(viteConfigPath || 'vite.config.js'),\n getViteConfigSnippet(options, true),\n );\n }\n\n await addDotEnvSentryBuildPluginFile(options.authToken);\n };\n\nexport async function addVitePluginToConfig(\n viteConfigPath: string,\n options: SourceMapUploadToolConfigurationOptions,\n): Promise<boolean> {\n try {\n const prettyViteConfigFilename = chalk.cyan(path.basename(viteConfigPath));\n\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath)\n ).toString();\n\n const mod = parseModule(viteConfigContent);\n\n if (hasSentryContent(mod.$ast as t.Program)) {\n const shouldContinue = await abortIfCancelled(\n clack.select({\n message: `${prettyViteConfigFilename} already contains Sentry-related code. Should the wizard modify it anyway?`,\n options: [\n {\n label: 'Yes, add the Sentry Vite 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 return false;\n }\n }\n\n const enabledSourcemaps = enableSourcemapGeneration(mod.$ast as t.Program);\n if (!enabledSourcemaps) {\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n\n const { orgSlug: org, projectSlug: project, selfHosted, url } = options;\n\n addVitePlugin(mod, {\n imported: 'sentryVitePlugin',\n from: '@sentry/vite-plugin',\n constructor: 'sentryVitePlugin',\n options: {\n org,\n project,\n ...(selfHosted && { url }),\n },\n });\n\n const code = generateCode(mod.$ast).code;\n\n await fs.promises.writeFile(viteConfigPath, code);\n\n clack.log.success(\n `Added the Sentry Vite plugin to ${prettyViteConfigFilename} and enabled source maps`,\n );\n\n return true;\n } catch (e) {\n debug(e);\n Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');\n return false;\n }\n}\n\nfunction enableSourcemapGeneration(program: t.Program): boolean {\n const configObj = getViteConfigObject(program);\n\n if (!configObj) {\n return false;\n }\n\n const b = recast.types.builders;\n\n const buildProp = configObj.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'build',\n );\n\n // case 1: build property doesn't exist yet, so we can just add it\n if (!buildProp) {\n configObj.properties.push(\n b.objectProperty(\n b.identifier('build'),\n b.objectExpression([\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n ]),\n ),\n );\n return true;\n }\n\n const isValidBuildProp =\n buildProp.type === 'ObjectProperty' &&\n buildProp.value.type === 'ObjectExpression';\n\n if (!isValidBuildProp) {\n return false;\n }\n\n const sourceMapsProp =\n buildProp.value.type === 'ObjectExpression' &&\n buildProp.value.properties.find(\n (p: t.ObjectProperty) =>\n p.key.type === 'Identifier' && p.key.name === 'sourcemap',\n );\n\n // case 2: build.sourcemap property doesn't exist yet, so we just add it\n if (!sourceMapsProp && buildProp.value.type === 'ObjectExpression') {\n buildProp.value.properties.push(\n b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),\n );\n return true;\n }\n\n if (!sourceMapsProp || sourceMapsProp.type !== 'ObjectProperty') {\n return false;\n }\n\n // case 3: build.sourcemap property exists, and it's set to 'hidden'\n if (\n sourceMapsProp.value.type === 'StringLiteral' &&\n sourceMapsProp.value.value === 'hidden'\n ) {\n // nothing to do for us\n return true;\n }\n\n // case 4: build.sourcemap property exists, but it's not enabled, so we set it to true\n // or it is already true in which case this is a noop\n sourceMapsProp.value = b.booleanLiteral(true);\n return true;\n}\n\nfunction getViteConfigObject(\n program: t.Program,\n): t.ObjectExpression | undefined {\n const defaultExport = program.body.find(\n (s) => s.type === 'ExportDefaultDeclaration',\n ) as t.ExportDefaultDeclaration;\n\n if (!defaultExport) {\n return undefined;\n }\n\n if (defaultExport.declaration.type === 'ObjectExpression') {\n return defaultExport.declaration;\n }\n\n if (\n defaultExport.declaration.type === 'CallExpression' &&\n defaultExport.declaration.arguments[0].type === 'ObjectExpression'\n ) {\n return defaultExport.declaration.arguments[0];\n }\n\n if (defaultExport.declaration.type === 'Identifier') {\n const configId = defaultExport.declaration.name;\n return findConfigNode(configId, program);\n }\n\n return undefined;\n}\n\nfunction findConfigNode(\n configId: string,\n program: t.Program,\n): t.ObjectExpression | undefined {\n for (const node of program.body) {\n if (node.type === 'VariableDeclaration') {\n for (const declaration of node.declarations) {\n if (\n declaration.type === 'VariableDeclarator' &&\n declaration.id.type === 'Identifier' &&\n declaration.id.name === configId &&\n declaration.init?.type === 'ObjectExpression'\n ) {\n return declaration.init;\n }\n }\n }\n }\n return undefined;\n}\n"]}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import { SourceMapUploadToolConfigurationFunction } from './types';
|
|
1
|
+
import { SourceMapUploadToolConfigurationFunction, SourceMapUploadToolConfigurationOptions } from './types';
|
|
2
2
|
export declare const configureWebPackPlugin: SourceMapUploadToolConfigurationFunction;
|
|
3
|
+
/**
|
|
4
|
+
* Modifies a webpack config file to enable source map generation and add the Sentry webpack plugin
|
|
5
|
+
* exported only for testing
|
|
6
|
+
*/
|
|
7
|
+
export declare function modifyWebpackConfig(webpackConfigPath: string, options: SourceMapUploadToolConfigurationOptions): Promise<boolean>;
|