@sentry/wizard 3.10.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 +54 -7
- package/dist/lib/Constants.d.ts +1 -0
- package/dist/lib/Constants.js +5 -0
- package/dist/lib/Constants.js.map +1 -1
- package/dist/lib/Steps/ChooseIntegration.js +8 -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/ReactNative.js +3 -3
- package/dist/lib/Steps/Integrations/ReactNative.js.map +1 -1
- 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 +225 -0
- package/dist/src/android/android-wizard.js.map +1 -0
- package/dist/src/android/code-tools.d.ts +47 -0
- package/dist/src/android/code-tools.js +173 -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 +286 -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/remix-wizard.js +10 -20
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js +26 -13
- 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/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 +123 -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/sourcemaps/utils/detect-tool.d.ts +1 -1
- package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup.js +5 -5
- 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 +9 -5
- package/dist/src/utils/ast-utils.js +26 -11
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +74 -28
- package/dist/src/utils/clack-utils.js +427 -264
- 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/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/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/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/lib/Constants.ts +5 -0
- package/lib/Steps/ChooseIntegration.ts +7 -3
- package/lib/Steps/Integrations/Android.ts +23 -0
- package/lib/Steps/Integrations/ReactNative.ts +9 -3
- 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 +204 -0
- package/src/android/code-tools.ts +170 -0
- package/src/android/gradle.ts +250 -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/remix-wizard.ts +10 -15
- package/src/sourcemaps/sourcemaps-wizard.ts +19 -5
- package/src/sourcemaps/tools/nextjs.ts +2 -2
- package/src/sourcemaps/tools/sentry-cli.ts +8 -7
- package/src/sourcemaps/tools/vite.ts +143 -79
- package/src/sourcemaps/tools/webpack.ts +369 -30
- package/src/sourcemaps/utils/detect-tool.ts +2 -1
- package/src/sveltekit/sdk-setup.ts +10 -6
- package/src/sveltekit/sveltekit-wizard.ts +5 -14
- package/src/telemetry.ts +2 -0
- package/src/utils/ast-utils.ts +29 -11
- package/src/utils/clack-utils.ts +485 -283
- 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/android/code-tools.test.ts +49 -0
- package/test/sourcemaps/tools/vite.test.ts +149 -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/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
|
@@ -72,6 +72,7 @@ var fs = __importStar(require("fs"));
|
|
|
72
72
|
var clack_utils_1 = require("../../utils/clack-utils");
|
|
73
73
|
var package_json_1 = require("../../utils/package-json");
|
|
74
74
|
var telemetry_1 = require("../../telemetry");
|
|
75
|
+
var package_manager_1 = require("../../utils/package-manager");
|
|
75
76
|
var SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';
|
|
76
77
|
var addedToBuildCommand = false;
|
|
77
78
|
function configureSentryCLI(options, configureSourcemapGenerationFlow) {
|
|
@@ -157,7 +158,7 @@ function configureSentryCLI(options, configureSourcemapGenerationFlow) {
|
|
|
157
158
|
case 15:
|
|
158
159
|
prompts_1.default.log.info("No problem, just make sure to run this script ".concat(chalk_1.default.bold('after'), " building your application but ").concat(chalk_1.default.bold('before'), " deploying!"));
|
|
159
160
|
_b.label = 16;
|
|
160
|
-
case 16: return [4 /*yield*/, (0, clack_utils_1.
|
|
161
|
+
case 16: return [4 /*yield*/, (0, clack_utils_1.addSentryCliConfig)(options.authToken)];
|
|
161
162
|
case 17:
|
|
162
163
|
_b.sent();
|
|
163
164
|
return [2 /*return*/];
|
|
@@ -252,32 +253,34 @@ function askShouldAddToBuildCommand() {
|
|
|
252
253
|
* @param packageDotJson The package.json which will be modified.
|
|
253
254
|
*/
|
|
254
255
|
function addSentryCommandToBuildCommand(packageDotJson) {
|
|
256
|
+
var _a;
|
|
255
257
|
return __awaiter(this, void 0, void 0, function () {
|
|
256
|
-
var allNpmScripts,
|
|
257
|
-
return __generator(this, function (
|
|
258
|
-
switch (
|
|
258
|
+
var allNpmScripts, packageManager, packageManagerName, buildCommand, isProdBuildCommand, _b;
|
|
259
|
+
return __generator(this, function (_c) {
|
|
260
|
+
switch (_c.label) {
|
|
259
261
|
case 0:
|
|
260
262
|
// This usually shouldn't happen because earlier we added the
|
|
261
263
|
// SENTRY_NPM_SCRIPT_NAME script but just to be sure
|
|
262
264
|
packageDotJson.scripts = packageDotJson.scripts || {};
|
|
263
265
|
allNpmScripts = Object.keys(packageDotJson.scripts).filter(function (s) { return s !== SENTRY_NPM_SCRIPT_NAME; });
|
|
264
|
-
|
|
266
|
+
packageManager = (0, package_manager_1.detectPackageManger)();
|
|
267
|
+
packageManagerName = (_a = packageManager === null || packageManager === void 0 ? void 0 : packageManager.name) !== null && _a !== void 0 ? _a : 'npm';
|
|
265
268
|
buildCommand = typeof packageDotJson.scripts.build === 'string'
|
|
266
269
|
? 'build'
|
|
267
270
|
: allNpmScripts.find(function (s) { return s.toLocaleLowerCase().includes('build'); });
|
|
268
|
-
|
|
269
|
-
if (!
|
|
271
|
+
_b = !!buildCommand;
|
|
272
|
+
if (!_b) return [3 /*break*/, 2];
|
|
270
273
|
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.confirm({
|
|
271
|
-
message: "Is ".concat(chalk_1.default.cyan("".concat(
|
|
274
|
+
message: "Is ".concat(chalk_1.default.cyan("".concat(packageManagerName, " run ").concat(buildCommand)), " your production build command?"),
|
|
272
275
|
}))];
|
|
273
276
|
case 1:
|
|
274
|
-
|
|
275
|
-
|
|
277
|
+
_b = (_c.sent());
|
|
278
|
+
_c.label = 2;
|
|
276
279
|
case 2:
|
|
277
|
-
isProdBuildCommand =
|
|
280
|
+
isProdBuildCommand = _b;
|
|
278
281
|
if (!(allNpmScripts.length && (!buildCommand || !isProdBuildCommand))) return [3 /*break*/, 4];
|
|
279
282
|
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(prompts_1.default.select({
|
|
280
|
-
message: "Which ".concat(
|
|
283
|
+
message: "Which ".concat(packageManagerName, " command in your ").concat(chalk_1.default.cyan('package.json'), " builds your application for production?"),
|
|
281
284
|
options: allNpmScripts
|
|
282
285
|
.map(function (script) { return ({
|
|
283
286
|
label: script,
|
|
@@ -286,8 +289,8 @@ function addSentryCommandToBuildCommand(packageDotJson) {
|
|
|
286
289
|
.concat({ label: 'None of the above', value: 'none' }),
|
|
287
290
|
}))];
|
|
288
291
|
case 3:
|
|
289
|
-
buildCommand =
|
|
290
|
-
|
|
292
|
+
buildCommand = _c.sent();
|
|
293
|
+
_c.label = 4;
|
|
291
294
|
case 4:
|
|
292
295
|
if (!buildCommand || buildCommand === 'none') {
|
|
293
296
|
prompts_1.default.log.warn("We can only add the ".concat(chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME), " script to another `script` in your ").concat(chalk_1.default.cyan('package.json'), ".\nPlease add it manually to your prod build command."));
|
|
@@ -295,10 +298,10 @@ function addSentryCommandToBuildCommand(packageDotJson) {
|
|
|
295
298
|
}
|
|
296
299
|
packageDotJson.scripts[buildCommand
|
|
297
300
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
298
|
-
] = "".concat(packageDotJson.scripts[buildCommand], " && ").concat(
|
|
301
|
+
] = "".concat(packageDotJson.scripts[buildCommand], " && ").concat(packageManager, " run ").concat(SENTRY_NPM_SCRIPT_NAME);
|
|
299
302
|
return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), 'package.json'), JSON.stringify(packageDotJson, null, 2))];
|
|
300
303
|
case 5:
|
|
301
|
-
|
|
304
|
+
_c.sent();
|
|
302
305
|
addedToBuildCommand = true;
|
|
303
306
|
prompts_1.default.log.info("Added ".concat(chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME), " script to your ").concat(chalk_1.default.cyan(buildCommand), " command."));
|
|
304
307
|
return [2 /*return*/];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry-cli.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/sentry-cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,2DAAmC;AACnC,gDAA0B;AAC1B,mDAAuC;AACvC,yCAA6B;AAC7B,qCAAyB;AACzB,uDAMiC;AAGjC,yDAA+E;AAC/E,6CAA4C;AAE5C,IAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEnD,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC,SAAsB,kBAAkB,CACtC,OAA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,qBAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,EACxC,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CACxC,EAAA;;oBAHD,SAGC,CAAC;oBAEF,mBAAmB,GAAG,IAAI,CAAC;oBAE3B,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,gBAAS,eAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,6BAAmB,eAAK,CAAC,IAAI,CACtE,YAAY,CACb,cAAW,CACb,CAAC;;;;;CACH;AAED,SAAe,uCAAuC;;;;wBACpD,qBAAM,IAAA,8BAAgB,EACpB,iBAAK,CAAC,MAAM,CAAC;wBACX,OAAO,EAAE,iEAA0D,eAAK,CAAC,GAAG,CAC1E,uEAAuE,CACxE,CAAE;wBACH,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;wBACzD,YAAY,EAAE,IAAI;qBACnB,CAAC,CACH,EAAA;;oBARD,SAQC,CAAC;;;;;CACH","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as Sentry from '@sentry/node';\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport {\n abortIfCancelled,\n addSentryCliRc,\n detectPackageManager,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack-utils';\n\nimport { SourceMapUploadToolConfigurationOptions } from './types';\nimport { hasPackageInstalled, PackageDotJson } from '../../utils/package-json';\nimport { traceStep } from '../../telemetry';\n\nconst SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';\n\nlet addedToBuildCommand = false;\n\nexport async function configureSentryCLI(\n options: SourceMapUploadToolConfigurationOptions,\n configureSourcemapGenerationFlow: () => Promise<void> = defaultConfigureSourcemapGenerationFlow,\n): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n\n await installPackage({\n packageName: '@sentry/cli',\n alreadyInstalled: hasPackageInstalled('@sentry/cli', packageDotJson),\n });\n\n let validPath = false;\n let relativeArtifactPath;\n do {\n const rawArtifactPath = await abortIfCancelled(\n clack.text({\n message: 'Where are your build artifacts located?',\n placeholder: `.${path.sep}out`,\n validate(value) {\n if (!value) {\n return 'Please enter a path.';\n }\n },\n }),\n );\n\n if (path.isAbsolute(rawArtifactPath)) {\n relativeArtifactPath = path.relative(process.cwd(), rawArtifactPath);\n } else {\n relativeArtifactPath = rawArtifactPath;\n }\n\n try {\n await fs.promises.access(path.join(process.cwd(), relativeArtifactPath));\n validPath = true;\n } catch {\n validPath = await abortIfCancelled(\n clack.select({\n message: `We couldn't find artifacts at ${relativeArtifactPath}. Are you sure that this is the location that contains your build artifacts?`,\n options: [\n {\n label: 'No, let me verify.',\n value: false,\n },\n { label: 'Yes, I am sure!', value: true },\n ],\n initialValue: false,\n }),\n );\n }\n } while (!validPath);\n\n const relativePosixArtifactPath = relativeArtifactPath\n .split(path.sep)\n .join(path.posix.sep);\n\n await configureSourcemapGenerationFlow();\n\n await createAndAddNpmScript(\n packageDotJson,\n options,\n relativePosixArtifactPath,\n );\n\n if (await askShouldAddToBuildCommand()) {\n await traceStep('sentry-cli-add-to-build-cmd', () =>\n addSentryCommandToBuildCommand(packageDotJson),\n );\n } else {\n clack.log.info(\n `No problem, just make sure to run this script ${chalk.bold(\n 'after',\n )} building your application but ${chalk.bold('before')} deploying!`,\n );\n }\n\n await addSentryCliRc(options.authToken);\n}\n\nexport async function setupNpmScriptInCI(): Promise<void> {\n if (addedToBuildCommand) {\n // No need to tell users to add it manually to their CI\n // if the script is already added to the build command\n return;\n }\n\n const addedToCI = await abortIfCancelled(\n clack.select({\n message: `Add a step to your CI pipeline that runs the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script ${chalk.bold('right after')} building your application.`,\n options: [\n { label: 'I did, continue!', value: true },\n {\n label: \"I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `You need to run ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} after each build for source maps to work properly.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('added-ci-script', addedToCI);\n\n if (!addedToCI) {\n clack.log.info(\"Don't forget! :)\");\n }\n}\n\nasync function createAndAddNpmScript(\n packageDotJson: PackageDotJson,\n options: SourceMapUploadToolConfigurationOptions,\n relativePosixArtifactPath: string,\n): Promise<void> {\n const sentryCliNpmScript = `sentry-cli sourcemaps inject --org ${\n options.orgSlug\n } --project ${\n options.projectSlug\n } ${relativePosixArtifactPath} && sentry-cli${\n options.selfHosted ? ` --url ${options.url}` : ''\n } sourcemaps upload --org ${options.orgSlug} --project ${\n options.projectSlug\n } ${relativePosixArtifactPath}`;\n\n packageDotJson.scripts = packageDotJson.scripts || {};\n packageDotJson.scripts[SENTRY_NPM_SCRIPT_NAME] = sentryCliNpmScript;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n clack.log.info(\n `Added a ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n 'package.json',\n )}.`,\n );\n}\n\nasync function askShouldAddToBuildCommand(): Promise<boolean> {\n const shouldAddToBuildCommand = await abortIfCancelled(\n clack.select({\n message: `Do you want to automatically run the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script after each production build?`,\n options: [\n {\n label: 'Yes',\n value: true,\n hint: 'This will modify your prod build command',\n },\n { label: 'No', value: false },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('modify-build-command', shouldAddToBuildCommand);\n\n return shouldAddToBuildCommand;\n}\n\n/**\n * Add the sentry:sourcemaps command to the prod build command in the package.json\n * - Detect the user's build command\n * - Append the sentry:sourcemaps command to it\n *\n * @param packageDotJson The package.json which will be modified.\n */\nasync function addSentryCommandToBuildCommand(\n packageDotJson: PackageDotJson,\n): Promise<void> {\n // This usually shouldn't happen because earlier we added the\n // SENTRY_NPM_SCRIPT_NAME script but just to be sure\n packageDotJson.scripts = packageDotJson.scripts || {};\n\n const allNpmScripts = Object.keys(packageDotJson.scripts).filter(\n (s) => s !== SENTRY_NPM_SCRIPT_NAME,\n );\n\n const pacMan = detectPackageManager() || 'npm';\n\n // Heuristic to pre-select the build command:\n // Often, 'build' is the prod build command, so we favour it.\n // If it's not there, commands that include 'build' might be the prod build command.\n let buildCommand =\n typeof packageDotJson.scripts.build === 'string'\n ? 'build'\n : allNpmScripts.find((s) => s.toLocaleLowerCase().includes('build'));\n\n const isProdBuildCommand =\n !!buildCommand &&\n (await abortIfCancelled(\n clack.confirm({\n message: `Is ${chalk.cyan(\n `${pacMan} run ${buildCommand}`,\n )} your production build command?`,\n }),\n ));\n\n if (allNpmScripts.length && (!buildCommand || !isProdBuildCommand)) {\n buildCommand = await abortIfCancelled(\n clack.select({\n message: `Which ${pacMan} command in your ${chalk.cyan(\n 'package.json',\n )} builds your application for production?`,\n options: allNpmScripts\n .map((script) => ({\n label: script,\n value: script,\n }))\n .concat({ label: 'None of the above', value: 'none' }),\n }),\n );\n }\n\n if (!buildCommand || buildCommand === 'none') {\n clack.log.warn(\n `We can only add the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script to another \\`script\\` in your ${chalk.cyan('package.json')}.\nPlease add it manually to your prod build command.`,\n );\n return;\n }\n\n packageDotJson.scripts[\n buildCommand\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n ] = `${packageDotJson.scripts[buildCommand]} && ${pacMan} run ${SENTRY_NPM_SCRIPT_NAME}`;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n addedToBuildCommand = true;\n\n clack.log.info(\n `Added ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n buildCommand,\n )} command.`,\n );\n}\n\nasync function defaultConfigureSourcemapGenerationFlow(): Promise<void> {\n await abortIfCancelled(\n clack.select({\n message: `Verify that your build tool is generating source maps. ${chalk.dim(\n '(Your build output folder should contain .js.map files after a build)',\n )}`,\n options: [{ label: 'I checked. Continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sentry-cli.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/sentry-cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,2DAAmC;AACnC,gDAA0B;AAC1B,mDAAuC;AACvC,yCAA6B;AAC7B,qCAAyB;AACzB,uDAKiC;AAGjC,yDAA+E;AAC/E,6CAA4C;AAC5C,+DAAkE;AAElE,IAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEnD,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC,SAAsB,kBAAkB,CACtC,OAAgD,EAChD,gCAA+F;IAA/F,iDAAA,EAAA,0EAA+F;;;;;wBAExE,qBAAM,IAAA,+BAAiB,GAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAEhD,qBAAM,IAAA,4BAAc,EAAC;4BACnB,WAAW,EAAE,aAAa;4BAC1B,gBAAgB,EAAE,IAAA,kCAAmB,EAAC,aAAa,EAAE,cAAc,CAAC;yBACrE,CAAC,EAAA;;oBAHF,SAGE,CAAC;oBAEC,SAAS,GAAG,KAAK,CAAC;;wBAGI,qBAAM,IAAA,8BAAgB,EAC5C,iBAAK,CAAC,IAAI,CAAC;wBACT,OAAO,EAAE,yCAAyC;wBAClD,WAAW,EAAE,WAAI,IAAI,CAAC,GAAG,QAAK;wBAC9B,QAAQ,YAAC,KAAK;4BACZ,IAAI,CAAC,KAAK,EAAE;gCACV,OAAO,sBAAsB,CAAC;6BAC/B;wBACH,CAAC;qBACF,CAAC,CACH,EAAA;;oBAVK,eAAe,GAAG,SA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AAC,GAAG,CAC1E,uEAAuE,CACxE,CAAE;wBACH,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;wBACzD,YAAY,EAAE,IAAI;qBACnB,CAAC,CACH,EAAA;;oBARD,SAQC,CAAC;;;;;CACH","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as Sentry from '@sentry/node';\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport {\n abortIfCancelled,\n addSentryCliConfig,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack-utils';\n\nimport { SourceMapUploadToolConfigurationOptions } from './types';\nimport { hasPackageInstalled, PackageDotJson } from '../../utils/package-json';\nimport { traceStep } from '../../telemetry';\nimport { detectPackageManger } from '../../utils/package-manager';\n\nconst SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';\n\nlet addedToBuildCommand = false;\n\nexport async function configureSentryCLI(\n options: SourceMapUploadToolConfigurationOptions,\n configureSourcemapGenerationFlow: () => Promise<void> = defaultConfigureSourcemapGenerationFlow,\n): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n\n await installPackage({\n packageName: '@sentry/cli',\n alreadyInstalled: hasPackageInstalled('@sentry/cli', packageDotJson),\n });\n\n let validPath = false;\n let relativeArtifactPath;\n do {\n const rawArtifactPath = await abortIfCancelled(\n clack.text({\n message: 'Where are your build artifacts located?',\n placeholder: `.${path.sep}out`,\n validate(value) {\n if (!value) {\n return 'Please enter a path.';\n }\n },\n }),\n );\n\n if (path.isAbsolute(rawArtifactPath)) {\n relativeArtifactPath = path.relative(process.cwd(), rawArtifactPath);\n } else {\n relativeArtifactPath = rawArtifactPath;\n }\n\n try {\n await fs.promises.access(path.join(process.cwd(), relativeArtifactPath));\n validPath = true;\n } catch {\n validPath = await abortIfCancelled(\n clack.select({\n message: `We couldn't find artifacts at ${relativeArtifactPath}. Are you sure that this is the location that contains your build artifacts?`,\n options: [\n {\n label: 'No, let me verify.',\n value: false,\n },\n { label: 'Yes, I am sure!', value: true },\n ],\n initialValue: false,\n }),\n );\n }\n } while (!validPath);\n\n const relativePosixArtifactPath = relativeArtifactPath\n .split(path.sep)\n .join(path.posix.sep);\n\n await configureSourcemapGenerationFlow();\n\n await createAndAddNpmScript(\n packageDotJson,\n options,\n relativePosixArtifactPath,\n );\n\n if (await askShouldAddToBuildCommand()) {\n await traceStep('sentry-cli-add-to-build-cmd', () =>\n addSentryCommandToBuildCommand(packageDotJson),\n );\n } else {\n clack.log.info(\n `No problem, just make sure to run this script ${chalk.bold(\n 'after',\n )} building your application but ${chalk.bold('before')} deploying!`,\n );\n }\n\n await addSentryCliConfig(options.authToken);\n}\n\nexport async function setupNpmScriptInCI(): Promise<void> {\n if (addedToBuildCommand) {\n // No need to tell users to add it manually to their CI\n // if the script is already added to the build command\n return;\n }\n\n const addedToCI = await abortIfCancelled(\n clack.select({\n message: `Add a step to your CI pipeline that runs the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script ${chalk.bold('right after')} building your application.`,\n options: [\n { label: 'I did, continue!', value: true },\n {\n label: \"I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `You need to run ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} after each build for source maps to work properly.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('added-ci-script', addedToCI);\n\n if (!addedToCI) {\n clack.log.info(\"Don't forget! :)\");\n }\n}\n\nasync function createAndAddNpmScript(\n packageDotJson: PackageDotJson,\n options: SourceMapUploadToolConfigurationOptions,\n relativePosixArtifactPath: string,\n): Promise<void> {\n const sentryCliNpmScript = `sentry-cli sourcemaps inject --org ${\n options.orgSlug\n } --project ${\n options.projectSlug\n } ${relativePosixArtifactPath} && sentry-cli${\n options.selfHosted ? ` --url ${options.url}` : ''\n } sourcemaps upload --org ${options.orgSlug} --project ${\n options.projectSlug\n } ${relativePosixArtifactPath}`;\n\n packageDotJson.scripts = packageDotJson.scripts || {};\n packageDotJson.scripts[SENTRY_NPM_SCRIPT_NAME] = sentryCliNpmScript;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n clack.log.info(\n `Added a ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n 'package.json',\n )}.`,\n );\n}\n\nasync function askShouldAddToBuildCommand(): Promise<boolean> {\n const shouldAddToBuildCommand = await abortIfCancelled(\n clack.select({\n message: `Do you want to automatically run the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script after each production build?`,\n options: [\n {\n label: 'Yes',\n value: true,\n hint: 'This will modify your prod build command',\n },\n { label: 'No', value: false },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('modify-build-command', shouldAddToBuildCommand);\n\n return shouldAddToBuildCommand;\n}\n\n/**\n * Add the sentry:sourcemaps command to the prod build command in the package.json\n * - Detect the user's build command\n * - Append the sentry:sourcemaps command to it\n *\n * @param packageDotJson The package.json which will be modified.\n */\nasync function addSentryCommandToBuildCommand(\n packageDotJson: PackageDotJson,\n): Promise<void> {\n // This usually shouldn't happen because earlier we added the\n // SENTRY_NPM_SCRIPT_NAME script but just to be sure\n packageDotJson.scripts = packageDotJson.scripts || {};\n\n const allNpmScripts = Object.keys(packageDotJson.scripts).filter(\n (s) => s !== SENTRY_NPM_SCRIPT_NAME,\n );\n\n const packageManager = detectPackageManger();\n const packageManagerName = packageManager?.name ?? 'npm';\n\n // Heuristic to pre-select the build command:\n // Often, 'build' is the prod build command, so we favour it.\n // If it's not there, commands that include 'build' might be the prod build command.\n let buildCommand =\n typeof packageDotJson.scripts.build === 'string'\n ? 'build'\n : allNpmScripts.find((s) => s.toLocaleLowerCase().includes('build'));\n\n const isProdBuildCommand =\n !!buildCommand &&\n (await abortIfCancelled(\n clack.confirm({\n message: `Is ${chalk.cyan(\n `${packageManagerName} run ${buildCommand}`,\n )} your production build command?`,\n }),\n ));\n\n if (allNpmScripts.length && (!buildCommand || !isProdBuildCommand)) {\n buildCommand = await abortIfCancelled(\n clack.select({\n message: `Which ${packageManagerName} command in your ${chalk.cyan(\n 'package.json',\n )} builds your application for production?`,\n options: allNpmScripts\n .map((script) => ({\n label: script,\n value: script,\n }))\n .concat({ label: 'None of the above', value: 'none' }),\n }),\n );\n }\n\n if (!buildCommand || buildCommand === 'none') {\n clack.log.warn(\n `We can only add the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script to another \\`script\\` in your ${chalk.cyan('package.json')}.\nPlease add it manually to your prod build command.`,\n );\n return;\n }\n\n packageDotJson.scripts[\n buildCommand\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n ] = `${packageDotJson.scripts[buildCommand]} && ${packageManager} run ${SENTRY_NPM_SCRIPT_NAME}`;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n addedToBuildCommand = true;\n\n clack.log.info(\n `Added ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n buildCommand,\n )} command.`,\n );\n}\n\nasync function defaultConfigureSourcemapGenerationFlow(): Promise<void> {\n await abortIfCancelled(\n clack.select({\n message: `Verify that your build tool is generating source maps. ${chalk.dim(\n '(Your build output folder should contain .js.map files after a build)',\n )}`,\n options: [{ label: 'I checked. Continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n"]}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { SourceMapUploadToolConfigurationFunction } from './types';
|
|
1
|
+
import { SourceMapUploadToolConfigurationFunction, SourceMapUploadToolConfigurationOptions } from './types';
|
|
2
2
|
export declare const configureVitePlugin: SourceMapUploadToolConfigurationFunction;
|
|
3
|
+
export declare function addVitePluginToConfig(viteConfigPath: string, options: SourceMapUploadToolConfigurationOptions): Promise<boolean>;
|
|
@@ -73,13 +73,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
73
73
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
74
74
|
};
|
|
75
75
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
|
-
exports.configureVitePlugin = void 0;
|
|
76
|
+
exports.addVitePluginToConfig = exports.configureVitePlugin = void 0;
|
|
77
77
|
// @ts-ignore - clack is ESM and TS complains about that. It works though
|
|
78
|
-
var
|
|
78
|
+
var clack = __importStar(require("@clack/prompts"));
|
|
79
79
|
// @ts-ignore - magicast is ESM and TS complains about that. It works though
|
|
80
80
|
var magicast_1 = require("magicast");
|
|
81
81
|
// @ts-ignore - magicast is ESM and TS complains about that. It works though
|
|
82
82
|
var helpers_1 = require("magicast/helpers");
|
|
83
|
+
var recast = __importStar(require("recast"));
|
|
83
84
|
var Sentry = __importStar(require("@sentry/node"));
|
|
84
85
|
var chalk_1 = __importDefault(require("chalk"));
|
|
85
86
|
var clack_utils_1 = require("../../utils/clack-utils");
|
|
@@ -106,8 +107,9 @@ var getViteConfigContent = function (importStmt, generateSourceMapsOption, sentr
|
|
|
106
107
|
var configureVitePlugin = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
108
|
var _a, _b, _c, viteConfigPath, _d, successfullyAdded;
|
|
108
109
|
var _e;
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
var _f;
|
|
111
|
+
return __generator(this, function (_g) {
|
|
112
|
+
switch (_g.label) {
|
|
111
113
|
case 0:
|
|
112
114
|
_a = clack_utils_1.installPackage;
|
|
113
115
|
_e = {
|
|
@@ -116,73 +118,52 @@ var configureVitePlugin = function (options) { return __awaiter(void 0, void 0,
|
|
|
116
118
|
_b = package_json_1.hasPackageInstalled;
|
|
117
119
|
_c = ['@sentry/vite-plugin'];
|
|
118
120
|
return [4 /*yield*/, (0, clack_utils_1.getPackageDotJson)()];
|
|
119
|
-
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()])),
|
|
120
122
|
_e)])];
|
|
121
123
|
case 2:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return [
|
|
126
|
-
case 3:
|
|
127
|
-
_d = (_f.sent());
|
|
128
|
-
_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')];
|
|
129
129
|
case 4:
|
|
130
|
+
_d = (_g.sent());
|
|
131
|
+
_g.label = 5;
|
|
132
|
+
case 5:
|
|
130
133
|
viteConfigPath = _d;
|
|
131
134
|
successfullyAdded = false;
|
|
132
|
-
if (!viteConfigPath) return [3 /*break*/,
|
|
135
|
+
if (!viteConfigPath) return [3 /*break*/, 7];
|
|
133
136
|
return [4 /*yield*/, addVitePluginToConfig(viteConfigPath, options)];
|
|
134
|
-
case
|
|
135
|
-
successfullyAdded =
|
|
136
|
-
return [3 /*break*/,
|
|
137
|
-
case
|
|
138
|
-
case 7:
|
|
139
|
-
successfullyAdded = _f.sent();
|
|
140
|
-
_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/')];
|
|
141
141
|
case 8:
|
|
142
|
-
|
|
143
|
-
Sentry.setTag('
|
|
144
|
-
|
|
142
|
+
successfullyAdded = _g.sent();
|
|
143
|
+
Sentry.setTag('created-new-config', successfullyAdded ? 'success' : 'fail');
|
|
144
|
+
_g.label = 9;
|
|
145
145
|
case 9:
|
|
146
|
-
|
|
147
|
-
|
|
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];
|
|
148
150
|
case 10:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
case 11:
|
|
152
|
-
|
|
153
|
-
|
|
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();
|
|
154
159
|
return [2 /*return*/];
|
|
155
160
|
}
|
|
156
161
|
});
|
|
157
162
|
}); };
|
|
158
163
|
exports.configureVitePlugin = configureVitePlugin;
|
|
159
|
-
function createNewViteConfig(options) {
|
|
160
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
-
var e_1;
|
|
162
|
-
return __generator(this, function (_a) {
|
|
163
|
-
switch (_a.label) {
|
|
164
|
-
case 0:
|
|
165
|
-
_a.trys.push([0, 2, , 3]);
|
|
166
|
-
return [4 /*yield*/, fs.promises.writeFile('vite.config.js', getViteConfigSnippet(options, false))];
|
|
167
|
-
case 1:
|
|
168
|
-
_a.sent();
|
|
169
|
-
Sentry.setTag('created-new-config', 'success');
|
|
170
|
-
return [2 /*return*/, true];
|
|
171
|
-
case 2:
|
|
172
|
-
e_1 = _a.sent();
|
|
173
|
-
(0, debug_1.debug)(e_1);
|
|
174
|
-
Sentry.setTag('created-new-config', 'fail');
|
|
175
|
-
prompts_1.default.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."));
|
|
176
|
-
prompts_1.default.log.info(chalk_1.default.gray('More information about vite configs: https://vitejs.dev/config/'));
|
|
177
|
-
return [2 /*return*/, false];
|
|
178
|
-
case 3: return [2 /*return*/];
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
164
|
function addVitePluginToConfig(viteConfigPath, options) {
|
|
184
165
|
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
-
var prettyViteConfigFilename, viteConfigContent, mod, shouldContinue, org, project, selfHosted, url, code,
|
|
166
|
+
var prettyViteConfigFilename, viteConfigContent, mod, shouldContinue, enabledSourcemaps, org, project, selfHosted, url, code, e_1;
|
|
186
167
|
return __generator(this, function (_a) {
|
|
187
168
|
switch (_a.label) {
|
|
188
169
|
case 0:
|
|
@@ -192,8 +173,8 @@ function addVitePluginToConfig(viteConfigPath, options) {
|
|
|
192
173
|
case 1:
|
|
193
174
|
viteConfigContent = (_a.sent()).toString();
|
|
194
175
|
mod = (0, magicast_1.parseModule)(viteConfigContent);
|
|
195
|
-
if (!(0, ast_utils_1.hasSentryContent)(mod)) return [3 /*break*/, 3];
|
|
196
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(
|
|
176
|
+
if (!(0, ast_utils_1.hasSentryContent)(mod.$ast)) return [3 /*break*/, 3];
|
|
177
|
+
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
|
|
197
178
|
message: "".concat(prettyViteConfigFilename, " already contains Sentry-related code. Should the wizard modify it anyway?"),
|
|
198
179
|
options: [
|
|
199
180
|
{
|
|
@@ -215,6 +196,11 @@ function addVitePluginToConfig(viteConfigPath, options) {
|
|
|
215
196
|
}
|
|
216
197
|
_a.label = 3;
|
|
217
198
|
case 3:
|
|
199
|
+
enabledSourcemaps = enableSourcemapGeneration(mod.$ast);
|
|
200
|
+
if (!enabledSourcemaps) {
|
|
201
|
+
Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
|
|
202
|
+
return [2 /*return*/, false];
|
|
203
|
+
}
|
|
218
204
|
org = options.orgSlug, project = options.projectSlug, selfHosted = options.selfHosted, url = options.url;
|
|
219
205
|
(0, helpers_1.addVitePlugin)(mod, {
|
|
220
206
|
imported: 'sentryVitePlugin',
|
|
@@ -226,11 +212,11 @@ function addVitePluginToConfig(viteConfigPath, options) {
|
|
|
226
212
|
return [4 /*yield*/, fs.promises.writeFile(viteConfigPath, code)];
|
|
227
213
|
case 4:
|
|
228
214
|
_a.sent();
|
|
229
|
-
|
|
215
|
+
clack.log.success("Added the Sentry Vite plugin to ".concat(prettyViteConfigFilename, " and enabled source maps"));
|
|
230
216
|
return [2 /*return*/, true];
|
|
231
217
|
case 5:
|
|
232
|
-
|
|
233
|
-
(0, debug_1.debug)(
|
|
218
|
+
e_1 = _a.sent();
|
|
219
|
+
(0, debug_1.debug)(e_1);
|
|
234
220
|
Sentry.setTag('ast-mod-fail-reason', 'insertion-fail');
|
|
235
221
|
return [2 /*return*/, false];
|
|
236
222
|
case 6: return [2 /*return*/];
|
|
@@ -238,59 +224,85 @@ function addVitePluginToConfig(viteConfigPath, options) {
|
|
|
238
224
|
});
|
|
239
225
|
});
|
|
240
226
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)((0, prompts_1.select)({
|
|
251
|
-
message: 'Did you copy the snippet above?',
|
|
252
|
-
options: [{ label: 'Yes, continue!', value: true }],
|
|
253
|
-
initialValue: true,
|
|
254
|
-
}))];
|
|
255
|
-
case 1:
|
|
256
|
-
_a.sent();
|
|
257
|
-
return [2 /*return*/];
|
|
258
|
-
}
|
|
259
|
-
});
|
|
227
|
+
exports.addVitePluginToConfig = addVitePluginToConfig;
|
|
228
|
+
function enableSourcemapGeneration(program) {
|
|
229
|
+
var configObj = getViteConfigObject(program);
|
|
230
|
+
if (!configObj) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
var b = recast.types.builders;
|
|
234
|
+
var buildProp = configObj.properties.find(function (p) {
|
|
235
|
+
return p.key.type === 'Identifier' && p.key.name === 'build';
|
|
260
236
|
});
|
|
237
|
+
// case 1: build property doesn't exist yet, so we can just add it
|
|
238
|
+
if (!buildProp) {
|
|
239
|
+
configObj.properties.push(b.objectProperty(b.identifier('build'), b.objectExpression([
|
|
240
|
+
b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)),
|
|
241
|
+
])));
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
var isValidBuildProp = buildProp.type === 'ObjectProperty' &&
|
|
245
|
+
buildProp.value.type === 'ObjectExpression';
|
|
246
|
+
if (!isValidBuildProp) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
var sourceMapsProp = buildProp.value.type === 'ObjectExpression' &&
|
|
250
|
+
buildProp.value.properties.find(function (p) {
|
|
251
|
+
return p.key.type === 'Identifier' && p.key.name === 'sourcemap';
|
|
252
|
+
});
|
|
253
|
+
// case 2: build.sourcemap property doesn't exist yet, so we just add it
|
|
254
|
+
if (!sourceMapsProp && buildProp.value.type === 'ObjectExpression') {
|
|
255
|
+
buildProp.value.properties.push(b.objectProperty(b.identifier('sourcemap'), b.booleanLiteral(true)));
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
if (!sourceMapsProp || sourceMapsProp.type !== 'ObjectProperty') {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
// case 3: build.sourcemap property exists, and it's set to 'hidden'
|
|
262
|
+
if (sourceMapsProp.value.type === 'StringLiteral' &&
|
|
263
|
+
sourceMapsProp.value.value === 'hidden') {
|
|
264
|
+
// nothing to do for us
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
// case 4: build.sourcemap property exists, but it's not enabled, so we set it to true
|
|
268
|
+
// or it is already true in which case this is a noop
|
|
269
|
+
sourceMapsProp.value = b.booleanLiteral(true);
|
|
270
|
+
return true;
|
|
261
271
|
}
|
|
262
|
-
function
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
272
|
+
function getViteConfigObject(program) {
|
|
273
|
+
var defaultExport = program.body.find(function (s) { return s.type === 'ExportDefaultDeclaration'; });
|
|
274
|
+
if (!defaultExport) {
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
if (defaultExport.declaration.type === 'ObjectExpression') {
|
|
278
|
+
return defaultExport.declaration;
|
|
279
|
+
}
|
|
280
|
+
if (defaultExport.declaration.type === 'CallExpression' &&
|
|
281
|
+
defaultExport.declaration.arguments[0].type === 'ObjectExpression') {
|
|
282
|
+
return defaultExport.declaration.arguments[0];
|
|
283
|
+
}
|
|
284
|
+
if (defaultExport.declaration.type === 'Identifier') {
|
|
285
|
+
var configId = defaultExport.declaration.name;
|
|
286
|
+
return findConfigNode(configId, program);
|
|
287
|
+
}
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
function findConfigNode(configId, program) {
|
|
291
|
+
var _a;
|
|
292
|
+
for (var _i = 0, _b = program.body; _i < _b.length; _i++) {
|
|
293
|
+
var node = _b[_i];
|
|
294
|
+
if (node.type === 'VariableDeclaration') {
|
|
295
|
+
for (var _c = 0, _d = node.declarations; _c < _d.length; _c++) {
|
|
296
|
+
var declaration = _d[_c];
|
|
297
|
+
if (declaration.type === 'VariableDeclarator' &&
|
|
298
|
+
declaration.id.type === 'Identifier' &&
|
|
299
|
+
declaration.id.name === configId &&
|
|
300
|
+
((_a = declaration.init) === null || _a === void 0 ? void 0 : _a.type) === 'ObjectExpression') {
|
|
301
|
+
return declaration.init;
|
|
302
|
+
}
|
|
292
303
|
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return undefined;
|
|
295
307
|
}
|
|
296
308
|
//# sourceMappingURL=vite.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/vite.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,wDAA+C;AAC/C,4EAA4E;AAC5E,qCAAqD;AACrD,4EAA4E;AAC5E,4CAAiD;AAEjD,mDAAuC;AAEvC,gDAA0B;AAC1B,uDAKiC;AACjC,yDAA+D;AAM/D,mDAAyE;AAEzE,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,aA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EAAE;wBAClB,sBAAO,SAAS,EAAC;qBAClB;oBAEM,qBAAM,IAAA,8BAAgB,EAC3B,iBAAK,CAAC,IAAI,CAAC;4BACT,OAAO,EAAE,iDAAiD;4BAC1D,WAAW,EAAE,WAAI,IAAI,CAAC,GAAG,mBAAgB;4BACzC,QAAQ,EAAE,UAAC,KAAK;gCACd,IAAI,CAAC,KAAK,EAAE;oCACV,OAAO,sBAAsB,CAAC;iCAC/B;gCAED,IAAI;oCACF,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;iCACtB;gCAAC,WAAM;oCACN,OAAO,yCAAyC,CAAC;iCAClD;4BACH,CAAC;yBACF,CAAC,CACH,EAAA;wBAhBD,sBAAO,SAgBN,EAAC;;;;CACH","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport clack, { select } 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 * 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 { findScriptFile, 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 findScriptFile(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\nasync 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 { 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}`,\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 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"]}
|
|
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,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AE,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>;
|