@sentry/wizard 4.9.0 → 5.1.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.
Files changed (72) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/e2e-tests/tests/cloudflare-wrangler-sourcemaps.test.d.ts +1 -0
  3. package/dist/e2e-tests/tests/cloudflare-wrangler-sourcemaps.test.js +91 -0
  4. package/dist/e2e-tests/tests/cloudflare-wrangler-sourcemaps.test.js.map +1 -0
  5. package/dist/e2e-tests/tests/nextjs-14.test.js +27 -0
  6. package/dist/e2e-tests/tests/nextjs-14.test.js.map +1 -1
  7. package/dist/e2e-tests/utils/index.d.ts +1 -0
  8. package/dist/e2e-tests/utils/index.js +23 -1
  9. package/dist/e2e-tests/utils/index.js.map +1 -1
  10. package/dist/lib/Steps/Integrations/Cordova.js +13 -30
  11. package/dist/lib/Steps/Integrations/Cordova.js.map +1 -1
  12. package/dist/src/nextjs/nextjs-wizard.js +24 -10
  13. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  14. package/dist/src/nextjs/templates.d.ts +2 -0
  15. package/dist/src/nextjs/templates.js +47 -1
  16. package/dist/src/nextjs/templates.js.map +1 -1
  17. package/dist/src/nextjs/utils.d.ts +2 -0
  18. package/dist/src/nextjs/utils.js +42 -1
  19. package/dist/src/nextjs/utils.js.map +1 -1
  20. package/dist/src/react-native/gradle.d.ts +0 -1
  21. package/dist/src/react-native/gradle.js +1 -5
  22. package/dist/src/react-native/gradle.js.map +1 -1
  23. package/dist/src/react-native/metro.d.ts +0 -4
  24. package/dist/src/react-native/metro.js +1 -129
  25. package/dist/src/react-native/metro.js.map +1 -1
  26. package/dist/src/react-native/options.d.ts +1 -3
  27. package/dist/src/react-native/options.js.map +1 -1
  28. package/dist/src/react-native/react-native-wizard.d.ts +1 -23
  29. package/dist/src/react-native/react-native-wizard.js +25 -127
  30. package/dist/src/react-native/react-native-wizard.js.map +1 -1
  31. package/dist/src/react-native/xcode.d.ts +0 -7
  32. package/dist/src/react-native/xcode.js +1 -109
  33. package/dist/src/react-native/xcode.js.map +1 -1
  34. package/dist/src/run.js +1 -4
  35. package/dist/src/run.js.map +1 -1
  36. package/dist/src/sourcemaps/sourcemaps-wizard.js +14 -0
  37. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  38. package/dist/src/sourcemaps/tools/wrangler.d.ts +28 -0
  39. package/dist/src/sourcemaps/tools/wrangler.js +276 -0
  40. package/dist/src/sourcemaps/tools/wrangler.js.map +1 -0
  41. package/dist/src/sourcemaps/utils/detect-tool.d.ts +1 -1
  42. package/dist/src/sourcemaps/utils/detect-tool.js +1 -0
  43. package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
  44. package/dist/src/sourcemaps/utils/sdk-version.js +3 -0
  45. package/dist/src/sourcemaps/utils/sdk-version.js.map +1 -1
  46. package/dist/src/utils/ast-utils.d.ts +0 -7
  47. package/dist/src/utils/ast-utils.js +1 -27
  48. package/dist/src/utils/ast-utils.js.map +1 -1
  49. package/dist/src/utils/clack/index.d.ts +9 -1
  50. package/dist/src/utils/clack/index.js +8 -1
  51. package/dist/src/utils/clack/index.js.map +1 -1
  52. package/dist/src/version.d.ts +1 -1
  53. package/dist/src/version.js +1 -1
  54. package/dist/src/version.js.map +1 -1
  55. package/dist/test/nextjs/templates.test.js +98 -0
  56. package/dist/test/nextjs/templates.test.js.map +1 -1
  57. package/dist/test/nextjs/utils.test.d.ts +1 -0
  58. package/dist/test/nextjs/utils.test.js +104 -0
  59. package/dist/test/nextjs/utils.test.js.map +1 -0
  60. package/dist/test/react-native/gradle.test.js +0 -119
  61. package/dist/test/react-native/gradle.test.js.map +1 -1
  62. package/dist/test/react-native/metro.test.js +0 -90
  63. package/dist/test/react-native/metro.test.js.map +1 -1
  64. package/dist/test/react-native/xcode.test.js +0 -81
  65. package/dist/test/react-native/xcode.test.js.map +1 -1
  66. package/dist/test/sourcemaps/tools/wrangler.test.d.ts +1 -0
  67. package/dist/test/sourcemaps/tools/wrangler.test.js +132 -0
  68. package/dist/test/sourcemaps/tools/wrangler.test.js.map +1 -0
  69. package/package.json +2 -1
  70. package/dist/src/react-native/uninstall.d.ts +0 -2
  71. package/dist/src/react-native/uninstall.js +0 -94
  72. package/dist/src/react-native/uninstall.js.map +0 -1
@@ -0,0 +1,28 @@
1
+ import type { SourceMapUploadToolConfigurationOptions } from './types';
2
+ /**
3
+ * only exported for testing
4
+ */
5
+ export declare const DIST_DIR: string;
6
+ export declare function configureWrangler(options: SourceMapUploadToolConfigurationOptions): Promise<void>;
7
+ /**
8
+ * only exported for testing
9
+ */
10
+ export declare function getSentryCliCommand(options: SourceMapUploadToolConfigurationOptions & {
11
+ outDir: string;
12
+ }): string;
13
+ /**
14
+ * Takes care of inserting the necessary arguments into the deploy command.
15
+ * Ensures that existing arguments and values are kept and that the
16
+ * wrangler deploy command is valid.
17
+ *
18
+ * only exported for testing
19
+ */
20
+ export declare function safeInsertArgsToWranglerDeployCommand(deployCommand: string, outDir: string): string | undefined;
21
+ /**
22
+ * only exported for testing
23
+ */
24
+ export declare function findOutDir(deployCommand: string): string;
25
+ /**
26
+ * Exported for testing
27
+ */
28
+ export declare function getWranglerDeployCommand(deployCommand: string): string | undefined;
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.getWranglerDeployCommand = exports.findOutDir = exports.safeInsertArgsToWranglerDeployCommand = exports.getSentryCliCommand = exports.configureWrangler = exports.DIST_DIR = void 0;
30
+ // @ts-expect-error - clack is ESM and TS complains about that. It works though
31
+ const clack = __importStar(require("@clack/prompts"));
32
+ const chalk_1 = __importDefault(require("chalk"));
33
+ const clack_1 = require("../../utils/clack");
34
+ const package_json_1 = require("../../utils/package-json");
35
+ const package_manager_1 = require("../../utils/package-manager");
36
+ const path_1 = __importDefault(require("path"));
37
+ const fs_1 = __importDefault(require("fs"));
38
+ const yargs_1 = __importDefault(require("yargs"));
39
+ const helpers_1 = require("yargs/helpers");
40
+ const SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';
41
+ /**
42
+ * only exported for testing
43
+ */
44
+ exports.DIST_DIR = path_1.default.join('.', 'dist');
45
+ async function configureWrangler(options) {
46
+ clack.note(chalk_1.default.whiteBright(`Configuring source maps upload with Cloudflare Wrangler requires the wizard to:
47
+ - Modify your deploy command to access source maps
48
+ - Set the SENTRY_RELEASE env var to identify source maps
49
+
50
+ Note: This setup may need additional configuration.
51
+ We recommend using Vite to build your worker instead, for an easier and more reliable setup.
52
+
53
+ Learn more about CloudFlare's Vite setup here:
54
+ ${chalk_1.default.underline(chalk_1.default.cyan('https://developers.cloudflare.com/workers/vite-plugin/get-started/'))}
55
+
56
+ You can switch to Vite and re-run this wizard later.
57
+ Otherwise, let's proceed with the Wrangler setup.`), 'Before we get started');
58
+ const proceed = await (0, clack_1.abortIfCancelled)(clack.confirm({
59
+ message: 'Do you want to proceed with the Wrangler setup?',
60
+ }));
61
+ if (!proceed) {
62
+ await (0, clack_1.abort)('Got it! You can switch to Vite and re-run this wizard later.', 0);
63
+ return;
64
+ }
65
+ await (0, clack_1.installPackage)({
66
+ packageName: '@sentry/cli',
67
+ alreadyInstalled: (0, package_json_1.hasPackageInstalled)('@sentry/cli', await (0, clack_1.getPackageDotJson)()),
68
+ devDependency: true,
69
+ });
70
+ if (!(await askContinueIfHasSentrySourcemapsScript())) {
71
+ return;
72
+ }
73
+ const deployCommand = await getDeployCommand();
74
+ if (!deployCommand) {
75
+ return;
76
+ }
77
+ const outDir = await getWranglerOutDir(deployCommand);
78
+ await createAndAddSentrySourcemapsScript({ ...options, outDir });
79
+ await writePostDeployCommand(deployCommand);
80
+ await modifyDeployCommand(deployCommand, outDir);
81
+ await (0, clack_1.addSentryCliConfig)({ authToken: options.authToken });
82
+ }
83
+ exports.configureWrangler = configureWrangler;
84
+ async function createAndAddSentrySourcemapsScript(options) {
85
+ const pkgJson = await (0, clack_1.getPackageDotJson)();
86
+ pkgJson.scripts = pkgJson.scripts ?? {};
87
+ pkgJson.scripts[SENTRY_NPM_SCRIPT_NAME] = getSentryCliCommand(options);
88
+ await fs_1.default.promises.writeFile(path_1.default.join(process.cwd(), 'package.json'), JSON.stringify(pkgJson, null, 2));
89
+ clack.log.success(`Added a ${chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk_1.default.cyan('package.json')}.`);
90
+ }
91
+ /**
92
+ * only exported for testing
93
+ */
94
+ function getSentryCliCommand(options) {
95
+ const sentryCliOptions = options.selfHosted ? ` --url ${options.url}` : '';
96
+ const orgAndProjectArgs = `--org=${options.orgSlug} --project=${options.projectSlug}`;
97
+ const stripPrefixPath = `${options.outDir}${path_1.default.sep}..`;
98
+ return [
99
+ '_SENTRY_RELEASE=$(sentry-cli releases propose-version)',
100
+ `sentry-cli${sentryCliOptions} releases new $_SENTRY_RELEASE ${orgAndProjectArgs}`,
101
+ `sentry-cli${sentryCliOptions} sourcemaps upload ${orgAndProjectArgs} --release=$_SENTRY_RELEASE --strip-prefix '${stripPrefixPath}' ${options.outDir}`,
102
+ ].join(' && ');
103
+ }
104
+ exports.getSentryCliCommand = getSentryCliCommand;
105
+ async function askContinueIfHasSentrySourcemapsScript() {
106
+ const pkgJson = await (0, clack_1.getPackageDotJson)();
107
+ pkgJson.scripts = pkgJson.scripts ?? {};
108
+ if (pkgJson.scripts[SENTRY_NPM_SCRIPT_NAME]) {
109
+ clack.log.warn(`The ${chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME)} script already exists in your ${chalk_1.default.cyan('package.json')}.
110
+ This likely means that you already ran this wizard once.
111
+ If things don't work yet, try overwriting the script and continue with the wizard.`);
112
+ const overwrite = await (0, clack_1.abortIfCancelled)(clack.select({
113
+ message: 'Do you want to overwrite it?',
114
+ options: [
115
+ { label: 'Yes', value: true, hint: 'Overwrite the existing script' },
116
+ { label: 'No', value: false, hint: 'This will exit the wizard' },
117
+ ],
118
+ }));
119
+ if (!overwrite) {
120
+ return false;
121
+ }
122
+ }
123
+ return true;
124
+ }
125
+ async function getDeployCommand() {
126
+ const pkgJson = await (0, clack_1.getPackageDotJson)();
127
+ const scripts = pkgJson.scripts ?? {};
128
+ let deployCommand = Object.keys(scripts).find((key) => /wrangler\s+deploy/.test(scripts[key] ?? ''));
129
+ const packageManager = await (0, clack_1.getPackageManager)(package_manager_1.NPM);
130
+ const isDeployCommand = !!deployCommand &&
131
+ (await (0, clack_1.abortIfCancelled)(clack.confirm({
132
+ message: `Is ${chalk_1.default.cyan(`${packageManager.runScriptCommand} ${deployCommand}`)} your build and deploy command?`,
133
+ })));
134
+ if (Object.keys(scripts).length && (!deployCommand || !isDeployCommand)) {
135
+ deployCommand = await (0, clack_1.abortIfCancelled)(clack.select({
136
+ message: `Which ${packageManager.name} command in your ${chalk_1.default.cyan('package.json')} builds your worker and deploys it?`,
137
+ options: Object.keys(scripts)
138
+ .map((script) => ({
139
+ label: script,
140
+ value: script,
141
+ }))
142
+ .concat({ label: 'None of the above', value: 'none' }),
143
+ }));
144
+ }
145
+ if (!deployCommand || deployCommand === 'none') {
146
+ clack.log.warn(`We can only add the ${chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME)} script to another \`script\` in your ${chalk_1.default.cyan('package.json')}.
147
+ Please add it manually to your prod build command.`);
148
+ return undefined;
149
+ }
150
+ return deployCommand;
151
+ }
152
+ async function writePostDeployCommand(deployCommand) {
153
+ const pkgJson = await (0, clack_1.getPackageDotJson)();
154
+ const packageManager = await (0, clack_1.getPackageManager)(package_manager_1.NPM);
155
+ pkgJson.scripts = pkgJson.scripts ?? {};
156
+ pkgJson.scripts[`post${deployCommand}`] = `${packageManager.runScriptCommand} ${SENTRY_NPM_SCRIPT_NAME}`;
157
+ await fs_1.default.promises.writeFile(path_1.default.join(process.cwd(), 'package.json'), JSON.stringify(pkgJson, null, 2));
158
+ clack.log.success(`Added a ${chalk_1.default.cyan(`post${deployCommand}`)} script to your ${chalk_1.default.cyan('package.json')}.`);
159
+ }
160
+ async function modifyDeployCommand(deployCommand, outDir) {
161
+ const pkgJson = await (0, clack_1.getPackageDotJson)();
162
+ pkgJson.scripts = pkgJson.scripts ?? {};
163
+ const oldDeployCommand = pkgJson.scripts[deployCommand];
164
+ if (!oldDeployCommand) {
165
+ clack.log.warn(`The ${chalk_1.default.cyan(deployCommand)} script doesn't seem to be part of your package.json scripts anymore. Cannot modify it. Please modify it manually:`);
166
+ await (0, clack_1.showCopyPasteInstructions)({
167
+ codeSnippet: `wrangler deploy --outdir ${outDir} --var SENTRY_RELEASE:$(sentry-cli releases propose-version) --upload-source-maps`,
168
+ filename: 'package.json',
169
+ });
170
+ return;
171
+ }
172
+ const newDeployCommand = safeInsertArgsToWranglerDeployCommand(oldDeployCommand, outDir);
173
+ if (!newDeployCommand) {
174
+ clack.log.warn(`The ${chalk_1.default.cyan(deployCommand)} script doesn't seem to be a valid ${chalk_1.default.cyan('wrangler deploy')} command. Cannot modify it. Please modify it manually:`);
175
+ await (0, clack_1.showCopyPasteInstructions)({
176
+ codeSnippet: oldDeployCommand,
177
+ filename: 'package.json',
178
+ });
179
+ return;
180
+ }
181
+ pkgJson.scripts[deployCommand] = newDeployCommand;
182
+ await fs_1.default.promises.writeFile(path_1.default.join(process.cwd(), 'package.json'), JSON.stringify(pkgJson, null, 2));
183
+ clack.log.success(`Modified your ${chalk_1.default.cyan(deployCommand)} script to enable uploading source maps.`);
184
+ }
185
+ /**
186
+ * Takes care of inserting the necessary arguments into the deploy command.
187
+ * Ensures that existing arguments and values are kept and that the
188
+ * wrangler deploy command is valid.
189
+ *
190
+ * only exported for testing
191
+ */
192
+ function safeInsertArgsToWranglerDeployCommand(deployCommand, outDir) {
193
+ // split deployCommand into individual bash commands (potentially separated by &&, ||, >> etc.)
194
+ const originalWranglerDeployCommand = getWranglerDeployCommand(deployCommand);
195
+ if (!originalWranglerDeployCommand) {
196
+ return undefined;
197
+ }
198
+ const existingArgs = originalWranglerDeployCommand
199
+ .split(' ')
200
+ .map((arg) => arg.trim())
201
+ .filter(Boolean);
202
+ const parsedArgs = (0, yargs_1.default)((0, helpers_1.hideBin)(existingArgs)).parse();
203
+ const newArgs = [];
204
+ if (!parsedArgs.outdir) {
205
+ newArgs.push('--outdir', outDir);
206
+ }
207
+ // Adding --upload-source-maps saves us from having to
208
+ // modify the `wrangler.toml` or `wrangler.jsonc` files.
209
+ // Not ideal because this forces source maps to be uploaded
210
+ // but we'll live with it for now.
211
+ if (!parsedArgs['upload-source-maps']) {
212
+ newArgs.push('--upload-source-maps');
213
+ }
214
+ // This is how we inject the SENTRY_RELEASE variable,
215
+ // which is picked up by the CloudFlare SDK.
216
+ // multiple --var arguments are allowed, so no need to check for existing --var arguments.
217
+ newArgs.push('--var', 'SENTRY_RELEASE:$(sentry-cli releases propose-version)');
218
+ return deployCommand
219
+ .replace(originalWranglerDeployCommand, `${originalWranglerDeployCommand} ${newArgs.join(' ')} `)
220
+ .trim();
221
+ }
222
+ exports.safeInsertArgsToWranglerDeployCommand = safeInsertArgsToWranglerDeployCommand;
223
+ /**
224
+ * Look up an already specified --outdir argument and return it if found.
225
+ * Otherwise, we defined `dist` as the default outdir.
226
+ */
227
+ async function getWranglerOutDir(deployScript) {
228
+ const pkgJson = await (0, clack_1.getPackageDotJson)();
229
+ const scripts = pkgJson.scripts ?? {};
230
+ const deployCommand = scripts[deployScript];
231
+ if (!deployCommand) {
232
+ return exports.DIST_DIR;
233
+ }
234
+ return findOutDir(deployCommand);
235
+ }
236
+ /**
237
+ * only exported for testing
238
+ */
239
+ function findOutDir(deployCommand) {
240
+ const args = getWranglerDeployCommand(deployCommand)
241
+ ?.split(' ')
242
+ .map((arg) => arg.trim());
243
+ if (!args) {
244
+ return exports.DIST_DIR;
245
+ }
246
+ const outDirArgIndex = args.findIndex((arg) => arg.startsWith('--outdir'));
247
+ if (outDirArgIndex === -1) {
248
+ return exports.DIST_DIR;
249
+ }
250
+ const outDirArg = args[outDirArgIndex];
251
+ if (outDirArg.startsWith('--outdir=')) {
252
+ return outDirArg.split('=')[1].trim().replace(/['"]/g, '');
253
+ }
254
+ const maybeOutDir = args[outDirArgIndex + 1];
255
+ if (maybeOutDir && !maybeOutDir.startsWith('--')) {
256
+ return maybeOutDir.replace(/['"]/g, '');
257
+ }
258
+ return exports.DIST_DIR;
259
+ }
260
+ exports.findOutDir = findOutDir;
261
+ /**
262
+ * Exported for testing
263
+ */
264
+ function getWranglerDeployCommand(deployCommand) {
265
+ const individualCommands = deployCommand.split(/&&|\|\||>>|>|<|\||;/);
266
+ const originalWranglerDeployCommand = individualCommands.find((cmd) => {
267
+ const argv = cmd
268
+ .split(' ')
269
+ .map((arg) => arg.trim())
270
+ .filter(Boolean);
271
+ return argv[0] === 'wrangler' && argv.includes('deploy');
272
+ });
273
+ return originalWranglerDeployCommand;
274
+ }
275
+ exports.getWranglerDeployCommand = getWranglerDeployCommand;
276
+ //# sourceMappingURL=wrangler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrangler.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/wrangler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,sDAAwC;AACxC,kDAA0B;AAC1B,6CAQ2B;AAC3B,2DAA+D;AAC/D,iEAAkD;AAElD,gDAAwB;AACxB,4CAAoB;AAEpB,kDAA0B;AAC1B,2CAAwC;AAExC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEnD;;GAEG;AACU,QAAA,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAExC,KAAK,UAAU,iBAAiB,CACrC,OAAgD;IAEhD,KAAK,CAAC,IAAI,CACR,eAAK,CAAC,WAAW,CACf;;;;;;;;EAQJ,eAAK,CAAC,SAAS,CACf,eAAK,CAAC,IAAI,CACR,oEAAoE,CACrE,CACF;;;kDAGiD,CAC7C,EACD,uBAAuB,CACxB,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,IAAA,wBAAgB,EACpC,KAAK,CAAC,OAAO,CAAC;QACZ,OAAO,EAAE,iDAAiD;KAC3D,CAAC,CACH,CAAC;IAEF,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAA,aAAK,EACT,8DAA8D,EAC9D,CAAC,CACF,CAAC;QACF,OAAO;KACR;IAED,MAAM,IAAA,sBAAc,EAAC;QACnB,WAAW,EAAE,aAAa;QAC1B,gBAAgB,EAAE,IAAA,kCAAmB,EACnC,aAAa,EACb,MAAM,IAAA,yBAAiB,GAAE,CAC1B;QACD,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,IAAI,CAAC,CAAC,MAAM,sCAAsC,EAAE,CAAC,EAAE;QACrD,OAAO;KACR;IAED,MAAM,aAAa,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAC/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AAC,QAAQ,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IACH,OAAO,6BAA6B,CAAC;AACvC,CAAC;AAZD,4DAYC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport {\n abort,\n abortIfCancelled,\n addSentryCliConfig,\n getPackageDotJson,\n getPackageManager,\n installPackage,\n showCopyPasteInstructions,\n} from '../../utils/clack';\nimport { hasPackageInstalled } from '../../utils/package-json';\nimport { NPM } from '../../utils/package-manager';\nimport type { SourceMapUploadToolConfigurationOptions } from './types';\nimport path from 'path';\nimport fs from 'fs';\n\nimport yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nconst SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';\n\n/**\n * only exported for testing\n */\nexport const DIST_DIR = path.join('.', 'dist');\n\nexport async function configureWrangler(\n options: SourceMapUploadToolConfigurationOptions,\n) {\n clack.note(\n chalk.whiteBright(\n `Configuring source maps upload with Cloudflare Wrangler requires the wizard to:\n- Modify your deploy command to access source maps\n- Set the SENTRY_RELEASE env var to identify source maps\n\nNote: This setup may need additional configuration. \nWe recommend using Vite to build your worker instead, for an easier and more reliable setup.\n\nLearn more about CloudFlare's Vite setup here:\n${chalk.underline(\n chalk.cyan(\n 'https://developers.cloudflare.com/workers/vite-plugin/get-started/',\n ),\n)}\n\nYou can switch to Vite and re-run this wizard later. \nOtherwise, let's proceed with the Wrangler setup.`,\n ),\n 'Before we get started',\n );\n\n const proceed = await abortIfCancelled(\n clack.confirm({\n message: 'Do you want to proceed with the Wrangler setup?',\n }),\n );\n\n if (!proceed) {\n await abort(\n 'Got it! You can switch to Vite and re-run this wizard later.',\n 0,\n );\n return;\n }\n\n await installPackage({\n packageName: '@sentry/cli',\n alreadyInstalled: hasPackageInstalled(\n '@sentry/cli',\n await getPackageDotJson(),\n ),\n devDependency: true,\n });\n\n if (!(await askContinueIfHasSentrySourcemapsScript())) {\n return;\n }\n\n const deployCommand = await getDeployCommand();\n if (!deployCommand) {\n return;\n }\n\n const outDir = await getWranglerOutDir(deployCommand);\n\n await createAndAddSentrySourcemapsScript({ ...options, outDir });\n\n await writePostDeployCommand(deployCommand);\n\n await modifyDeployCommand(deployCommand, outDir);\n\n await addSentryCliConfig({ authToken: options.authToken });\n}\n\nasync function createAndAddSentrySourcemapsScript(\n options: SourceMapUploadToolConfigurationOptions & { outDir: string },\n) {\n const pkgJson = await getPackageDotJson();\n pkgJson.scripts = pkgJson.scripts ?? {};\n pkgJson.scripts[SENTRY_NPM_SCRIPT_NAME] = getSentryCliCommand(options);\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(pkgJson, null, 2),\n );\n\n clack.log.success(\n `Added a ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n 'package.json',\n )}.`,\n );\n}\n\n/**\n * only exported for testing\n */\nexport function getSentryCliCommand(\n options: SourceMapUploadToolConfigurationOptions & { outDir: string },\n) {\n const sentryCliOptions = options.selfHosted ? ` --url ${options.url}` : '';\n const orgAndProjectArgs = `--org=${options.orgSlug} --project=${options.projectSlug}`;\n\n const stripPrefixPath = `${options.outDir}${path.sep}..`;\n\n return [\n '_SENTRY_RELEASE=$(sentry-cli releases propose-version)',\n `sentry-cli${sentryCliOptions} releases new $_SENTRY_RELEASE ${orgAndProjectArgs}`,\n `sentry-cli${sentryCliOptions} sourcemaps upload ${orgAndProjectArgs} --release=$_SENTRY_RELEASE --strip-prefix '${stripPrefixPath}' ${options.outDir}`,\n ].join(' && ');\n}\n\nasync function askContinueIfHasSentrySourcemapsScript(): Promise<boolean> {\n const pkgJson = await getPackageDotJson();\n\n pkgJson.scripts = pkgJson.scripts ?? {};\n\n if (pkgJson.scripts[SENTRY_NPM_SCRIPT_NAME]) {\n clack.log.warn(\n `The ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script already exists in your ${chalk.cyan('package.json')}.\nThis likely means that you already ran this wizard once.\nIf things don't work yet, try overwriting the script and continue with the wizard.`,\n );\n\n const overwrite = await abortIfCancelled(\n clack.select({\n message: 'Do you want to overwrite it?',\n options: [\n { label: 'Yes', value: true, hint: 'Overwrite the existing script' },\n { label: 'No', value: false, hint: 'This will exit the wizard' },\n ],\n }),\n );\n\n if (!overwrite) {\n return false;\n }\n }\n\n return true;\n}\n\nasync function getDeployCommand(): Promise<string | undefined> {\n const pkgJson = await getPackageDotJson();\n const scripts = pkgJson.scripts ?? {};\n\n let deployCommand = Object.keys(scripts).find((key) =>\n /wrangler\\s+deploy/.test(scripts[key] ?? ''),\n );\n\n const packageManager = await getPackageManager(NPM);\n const isDeployCommand =\n !!deployCommand &&\n (await abortIfCancelled(\n clack.confirm({\n message: `Is ${chalk.cyan(\n `${packageManager.runScriptCommand} ${deployCommand}`,\n )} your build and deploy command?`,\n }),\n ));\n\n if (Object.keys(scripts).length && (!deployCommand || !isDeployCommand)) {\n deployCommand = await abortIfCancelled(\n clack.select({\n message: `Which ${packageManager.name} command in your ${chalk.cyan(\n 'package.json',\n )} builds your worker and deploys it?`,\n options: Object.keys(scripts)\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 (!deployCommand || deployCommand === '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 undefined;\n }\n\n return deployCommand;\n}\n\nasync function writePostDeployCommand(deployCommand: string): Promise<void> {\n const pkgJson = await getPackageDotJson();\n const packageManager = await getPackageManager(NPM);\n pkgJson.scripts = pkgJson.scripts ?? {};\n pkgJson.scripts[\n `post${deployCommand}`\n ] = `${packageManager.runScriptCommand} ${SENTRY_NPM_SCRIPT_NAME}`;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(pkgJson, null, 2),\n );\n\n clack.log.success(\n `Added a ${chalk.cyan(`post${deployCommand}`)} script to your ${chalk.cyan(\n 'package.json',\n )}.`,\n );\n}\n\nasync function modifyDeployCommand(\n deployCommand: string,\n outDir: string,\n): Promise<void> {\n const pkgJson = await getPackageDotJson();\n pkgJson.scripts = pkgJson.scripts ?? {};\n const oldDeployCommand = pkgJson.scripts[deployCommand];\n\n if (!oldDeployCommand) {\n clack.log.warn(\n `The ${chalk.cyan(\n deployCommand,\n )} script doesn't seem to be part of your package.json scripts anymore. Cannot modify it. Please modify it manually:`,\n );\n\n await showCopyPasteInstructions({\n codeSnippet: `wrangler deploy --outdir ${outDir} --var SENTRY_RELEASE:$(sentry-cli releases propose-version) --upload-source-maps`,\n filename: 'package.json',\n });\n\n return;\n }\n\n const newDeployCommand = safeInsertArgsToWranglerDeployCommand(\n oldDeployCommand,\n outDir,\n );\n\n if (!newDeployCommand) {\n clack.log.warn(\n `The ${chalk.cyan(\n deployCommand,\n )} script doesn't seem to be a valid ${chalk.cyan(\n 'wrangler deploy',\n )} command. Cannot modify it. Please modify it manually:`,\n );\n\n await showCopyPasteInstructions({\n codeSnippet: oldDeployCommand,\n filename: 'package.json',\n });\n\n return;\n }\n\n pkgJson.scripts[deployCommand] = newDeployCommand;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(pkgJson, null, 2),\n );\n\n clack.log.success(\n `Modified your ${chalk.cyan(\n deployCommand,\n )} script to enable uploading source maps.`,\n );\n}\n\n/**\n * Takes care of inserting the necessary arguments into the deploy command.\n * Ensures that existing arguments and values are kept and that the\n * wrangler deploy command is valid.\n *\n * only exported for testing\n */\nexport function safeInsertArgsToWranglerDeployCommand(\n deployCommand: string,\n outDir: string,\n): string | undefined {\n // split deployCommand into individual bash commands (potentially separated by &&, ||, >> etc.)\n const originalWranglerDeployCommand = getWranglerDeployCommand(deployCommand);\n\n if (!originalWranglerDeployCommand) {\n return undefined;\n }\n\n const existingArgs = originalWranglerDeployCommand\n .split(' ')\n .map((arg) => arg.trim())\n .filter(Boolean);\n\n const parsedArgs = yargs(hideBin(existingArgs)).parse();\n\n const newArgs = [];\n\n if (!parsedArgs.outdir) {\n newArgs.push('--outdir', outDir);\n }\n\n // Adding --upload-source-maps saves us from having to\n // modify the `wrangler.toml` or `wrangler.jsonc` files.\n // Not ideal because this forces source maps to be uploaded\n // but we'll live with it for now.\n if (!parsedArgs['upload-source-maps']) {\n newArgs.push('--upload-source-maps');\n }\n\n // This is how we inject the SENTRY_RELEASE variable,\n // which is picked up by the CloudFlare SDK.\n // multiple --var arguments are allowed, so no need to check for existing --var arguments.\n newArgs.push(\n '--var',\n 'SENTRY_RELEASE:$(sentry-cli releases propose-version)',\n );\n\n return deployCommand\n .replace(\n originalWranglerDeployCommand,\n `${originalWranglerDeployCommand} ${newArgs.join(' ')} `,\n )\n .trim();\n}\n\n/**\n * Look up an already specified --outdir argument and return it if found.\n * Otherwise, we defined `dist` as the default outdir.\n */\nasync function getWranglerOutDir(deployScript: string): Promise<string> {\n const pkgJson = await getPackageDotJson();\n const scripts = pkgJson.scripts ?? {};\n const deployCommand = scripts[deployScript];\n\n if (!deployCommand) {\n return DIST_DIR;\n }\n\n return findOutDir(deployCommand);\n}\n\n/**\n * only exported for testing\n */\nexport function findOutDir(deployCommand: string): string {\n const args = getWranglerDeployCommand(deployCommand)\n ?.split(' ')\n .map((arg) => arg.trim());\n\n if (!args) {\n return DIST_DIR;\n }\n\n const outDirArgIndex = args.findIndex((arg) => arg.startsWith('--outdir'));\n if (outDirArgIndex === -1) {\n return DIST_DIR;\n }\n\n const outDirArg = args[outDirArgIndex];\n\n if (outDirArg.startsWith('--outdir=')) {\n return outDirArg.split('=')[1].trim().replace(/['\"]/g, '');\n }\n\n const maybeOutDir = args[outDirArgIndex + 1];\n\n if (maybeOutDir && !maybeOutDir.startsWith('--')) {\n return maybeOutDir.replace(/['\"]/g, '');\n }\n\n return DIST_DIR;\n}\n\n/**\n * Exported for testing\n */\nexport function getWranglerDeployCommand(deployCommand: string) {\n const individualCommands = deployCommand.split(/&&|\\|\\||>>|>|<|\\||;/);\n\n const originalWranglerDeployCommand = individualCommands.find((cmd) => {\n const argv = cmd\n .split(' ')\n .map((arg) => arg.trim())\n .filter(Boolean);\n\n return argv[0] === 'wrangler' && argv.includes('deploy');\n });\n return originalWranglerDeployCommand;\n}\n"]}
@@ -1,3 +1,3 @@
1
- export type SupportedTools = 'webpack' | 'vite' | 'rollup' | 'esbuild' | 'tsc' | 'sentry-cli' | 'create-react-app' | 'angular' | 'nextjs' | 'remix' | 'no-tool';
1
+ export type SupportedTools = 'webpack' | 'vite' | 'rollup' | 'esbuild' | 'tsc' | 'sentry-cli' | 'create-react-app' | 'angular' | 'nextjs' | 'remix' | 'wrangler' | 'no-tool';
2
2
  export declare const TOOL_PACKAGE_MAP: Record<string, SupportedTools>;
3
3
  export declare function detectUsedTool(): Promise<SupportedTools>;
@@ -10,6 +10,7 @@ const package_json_1 = require("../../utils/package-json");
10
10
  exports.TOOL_PACKAGE_MAP = {
11
11
  '@angular/core': 'angular',
12
12
  'create-react-app': 'create-react-app',
13
+ wrangler: 'wrangler',
13
14
  webpack: 'webpack',
14
15
  vite: 'vite',
15
16
  esbuild: 'esbuild',
@@ -1 +1 @@
1
- {"version":3,"file":"detect-tool.js","sourceRoot":"","sources":["../../../../src/sourcemaps/utils/detect-tool.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AACtD,2DAAwE;AAexE,oDAAoD;AACpD,kFAAkF;AAClF,sEAAsE;AACtE,YAAY;AACC,QAAA,gBAAgB,GAAmC;IAC9D,eAAe,EAAE,SAAS;IAC1B,kBAAkB,EAAE,kBAAkB;IACtC,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,KAAK;CAClB,CAAC;AAEK,KAAK,UAAU,cAAc;IAClC,MAAM,WAAW,GAAG,MAAM,IAAA,yBAAiB,GAAE,CAAC;IAE9C,MAAM,gBAAgB,GAAG,IAAA,2CAA4B,EACnD,MAAM,CAAC,IAAI,CAAC,wBAAgB,CAAC,EAC7B,WAAW,CACZ,CAAC;IAEF,IAAI,gBAAgB,EAAE;QACpB,OAAO,wBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;KAChD;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAbD,wCAaC","sourcesContent":["import { getPackageDotJson } from '../../utils/clack';\nimport { findInstalledPackageFromList } from '../../utils/package-json';\n\nexport type SupportedTools =\n | 'webpack'\n | 'vite'\n | 'rollup'\n | 'esbuild'\n | 'tsc'\n | 'sentry-cli'\n | 'create-react-app'\n | 'angular'\n | 'nextjs'\n | 'remix'\n | 'no-tool';\n\n// A map of package names pointing to the tool slug.\n// The order is important, because we want to detect the most specific tool first.\n// For instance, webpack needs to come before tsc because typescript c\n// Similarly\nexport const TOOL_PACKAGE_MAP: Record<string, SupportedTools> = {\n '@angular/core': 'angular',\n 'create-react-app': 'create-react-app',\n webpack: 'webpack',\n vite: 'vite',\n esbuild: 'esbuild',\n rollup: 'rollup',\n typescript: 'tsc',\n};\n\nexport async function detectUsedTool(): Promise<SupportedTools> {\n const packageJson = await getPackageDotJson();\n\n const foundToolPackage = findInstalledPackageFromList(\n Object.keys(TOOL_PACKAGE_MAP),\n packageJson,\n );\n\n if (foundToolPackage) {\n return TOOL_PACKAGE_MAP[foundToolPackage.name];\n }\n\n return 'sentry-cli';\n}\n"]}
1
+ {"version":3,"file":"detect-tool.js","sourceRoot":"","sources":["../../../../src/sourcemaps/utils/detect-tool.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AACtD,2DAAwE;AAgBxE,oDAAoD;AACpD,kFAAkF;AAClF,sEAAsE;AACtE,YAAY;AACC,QAAA,gBAAgB,GAAmC;IAC9D,eAAe,EAAE,SAAS;IAC1B,kBAAkB,EAAE,kBAAkB;IACtC,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,KAAK;CAClB,CAAC;AAEK,KAAK,UAAU,cAAc;IAClC,MAAM,WAAW,GAAG,MAAM,IAAA,yBAAiB,GAAE,CAAC;IAE9C,MAAM,gBAAgB,GAAG,IAAA,2CAA4B,EACnD,MAAM,CAAC,IAAI,CAAC,wBAAgB,CAAC,EAC7B,WAAW,CACZ,CAAC;IAEF,IAAI,gBAAgB,EAAE;QACpB,OAAO,wBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;KAChD;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAbD,wCAaC","sourcesContent":["import { getPackageDotJson } from '../../utils/clack';\nimport { findInstalledPackageFromList } from '../../utils/package-json';\n\nexport type SupportedTools =\n | 'webpack'\n | 'vite'\n | 'rollup'\n | 'esbuild'\n | 'tsc'\n | 'sentry-cli'\n | 'create-react-app'\n | 'angular'\n | 'nextjs'\n | 'remix'\n | 'wrangler'\n | 'no-tool';\n\n// A map of package names pointing to the tool slug.\n// The order is important, because we want to detect the most specific tool first.\n// For instance, webpack needs to come before tsc because typescript c\n// Similarly\nexport const TOOL_PACKAGE_MAP: Record<string, SupportedTools> = {\n '@angular/core': 'angular',\n 'create-react-app': 'create-react-app',\n wrangler: 'wrangler',\n webpack: 'webpack',\n vite: 'vite',\n esbuild: 'esbuild',\n rollup: 'rollup',\n typescript: 'tsc',\n};\n\nexport async function detectUsedTool(): Promise<SupportedTools> {\n const packageJson = await getPackageDotJson();\n\n const foundToolPackage = findInstalledPackageFromList(\n Object.keys(TOOL_PACKAGE_MAP),\n packageJson,\n );\n\n if (foundToolPackage) {\n return TOOL_PACKAGE_MAP[foundToolPackage.name];\n }\n\n return 'sentry-cli';\n}\n"]}
@@ -45,9 +45,11 @@ const SENTRY_SDK_PACKAGE_NAMES = [
45
45
  '@sentry/gatsby',
46
46
  '@sentry/nextjs',
47
47
  '@sentry/nuxt',
48
+ '@sentry/react-router',
48
49
  '@sentry/remix',
49
50
  '@sentry/solidstart',
50
51
  '@sentry/sveltekit',
52
+ '@sentry/tanstackstart-react',
51
53
  // Framework SDKs
52
54
  '@sentry/angular',
53
55
  '@sentry/angular-ivy',
@@ -63,6 +65,7 @@ const SENTRY_SDK_PACKAGE_NAMES = [
63
65
  '@sentry/serverless',
64
66
  // Base SDKs
65
67
  '@sentry/browser',
68
+ '@sentry/cloudflare',
66
69
  '@sentry/node',
67
70
  '@sentry/deno',
68
71
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"sdk-version.js","sourceRoot":"","sources":["../../../../src/sourcemaps/utils/sdk-version.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,mCAA+C;AAC/C,6CAI2B;AAE3B,qDAAuC;AACvC,2DAAwE;AAExE,MAAM,4BAA4B,GAAG,QAAQ,CAAC;AAE9C,+DAA+D;AAC/D,qEAAqE;AACrE,0EAA0E;AAC1E,qDAAqD;AACrD,MAAM,wBAAwB,GAAG;IAC/B,2DAA2D;IAC3D,eAAe;IACf,gBAAgB;IAChB,gBAAgB;IAChB,cAAc;IACd,eAAe;IACf,oBAAoB;IACpB,mBAAmB;IAEnB,iBAAiB;IACjB,iBAAiB;IACjB,qBAAqB;IACrB,wBAAwB;IACxB,aAAa;IACb,eAAe;IACf,iCAAiC;IACjC,gBAAgB;IAChB,eAAe;IACf,eAAe;IACf,gBAAgB;IAChB,aAAa;IACb,oBAAoB;IAEpB,YAAY;IACZ,iBAAiB;IACjB,cAAc;IACd,cAAc;CACf,CAAC;AAEF;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,kCAAkC;IACtD,MAAM,mBAAmB,GAAG,IAAA,2CAA4B,EACtD,wBAAwB,EACxB,MAAM,IAAA,yBAAiB,GAAE,CAC1B,CAAC;IAEF,UAAU;I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E,SAAS,CAAC,CAAC;IAChD,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,GAAG,eAAK,CAAC,MAAM,CACb,uDAAuD,gBAAgB,OAAO,0BAA0B,IAAI,CAC7G;;8DAEyD,eAAK,CAAC,IAAI,CAClE,4BAA4B,CAC7B;KACA,CACF,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport { minVersion, satisfies } from 'semver';\nimport {\n abortIfCancelled,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack';\n\nimport * as Sentry from '@sentry/node';\nimport { findInstalledPackageFromList } from '../../utils/package-json';\n\nconst MINIMUM_DEBUG_ID_SDK_VERSION = '7.47.0';\n\n// This array is orderd by the SDKs we want to check for first.\n// The reason is that some SDKs depend on others and some users might\n// have added the dependencies to their package.json. We want to make sure\n// that we actually detect the \"top-level\" SDK first.\nconst SENTRY_SDK_PACKAGE_NAMES = [\n // SDKs using other framework SDKs need to be checked first\n '@sentry/astro',\n '@sentry/gatsby',\n '@sentry/nextjs',\n '@sentry/nuxt',\n '@sentry/remix',\n '@sentry/solidstart',\n '@sentry/sveltekit',\n\n // Framework SDKs\n '@sentry/angular',\n '@sentry/angular-ivy',\n '@sentry/aws-serverless',\n '@sentry/bun',\n '@sentry/ember',\n '@sentry/google-cloud-serverless',\n '@sentry/nestjs',\n '@sentry/react',\n '@sentry/solid',\n '@sentry/svelte',\n '@sentry/vue',\n '@sentry/serverless',\n\n // Base SDKs\n '@sentry/browser',\n '@sentry/node',\n '@sentry/deno',\n];\n\n/**\n * Check for a minimum SDK version and prompt the user to upgrade if necessary.\n * We distinguish between 4 cases here:\n *\n * 1. Users didn't install any SDK yet\n * -> We tell them to install an SDK and then continue with the wizard\n * 2. Users installed an SDK in the range >=7.47.0\n * -> All good, no need to do anything!\n * 3. Users installed an SDK in the range >=7.0.0 <= 7.46.0\n * -> We ask if they want to auto-update to the latest version\n * 4. Users installed an SDK in the range <7.x\n * -> We tell users to manually upgrade (migrate between majors)\n */\nexport async function ensureMinimumSdkVersionIsInstalled(): Promise<void> {\n const installedSdkPackage = findInstalledPackageFromList(\n SENTRY_SDK_PACKAGE_NAMES,\n await getPackageDotJson(),\n );\n\n // Case 1:\n if (!installedSdkPackage) {\n return await handleNoSdkInstalled();\n }\n\n const { name: installedSdkName, version: installedSdkVersionOrRange } =\n installedSdkPackage;\n\n Sentry.setTag('installed-sdk', installedSdkName);\n\n const minInstalledVersion = getMinInstalledVersion(\n installedSdkVersionOrRange,\n installedSdkName,\n );\n\n if (!minInstalledVersion) {\n // This is handled in the getMinInstalledVersion function\n return;\n }\n\n const hasDebugIdCompatibleSdkVersion = satisfies(\n minInstalledVersion,\n `>=${MINIMUM_DEBUG_ID_SDK_VERSION}`,\n );\n\n // Case 2:\n if (hasDebugIdCompatibleSdkVersion) {\n Sentry.setTag('initial-sdk-version', '>=7.47.0');\n return;\n }\n\n const hasV7SdkVersion = satisfies(minInstalledVersion, '>=7.0.0');\n\n clack.log.warn(\n `${chalk.yellowBright(\n `It seems like you're using an outdated version (${installedSdkVersionOrRange}) of the ${chalk.bold(\n installedSdkName,\n )} SDK.`,\n )}\nUploading source maps is easiest with an SDK from version ${chalk.bold(\n MINIMUM_DEBUG_ID_SDK_VERSION,\n )} or newer. \n`,\n );\n\n // Case 3:\n if (hasV7SdkVersion) {\n await handleAutoUpdateSdk(installedSdkName);\n return;\n }\n\n // Case 4:\n await handleManuallyUpdateSdk(minInstalledVersion);\n}\n\nasync function handleManuallyUpdateSdk(minInstalledVersion: string) {\n Sentry.setTag(\n 'initial-sdk-version',\n `${satisfies(minInstalledVersion, '>=6.0.0') ? '6.x' : '<6.0.0'}`,\n );\n\n clack.log\n .info(`When upgrading from a version older than 7.0.0, make sure to follow the migration guide:\nhttps://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#upgrading-from-6x-to-7x\n`);\n\n const didUpdate = await abortIfCancelled(\n clack.select({\n message: 'Did you update your SDK to the latest version?',\n options: [\n {\n label: 'Yes!',\n value: true,\n },\n {\n label: \"No, I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `Remember to update your SDK to at least ${MINIMUM_DEBUG_ID_SDK_VERSION}.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag(\n 'resolved-sdk-status',\n didUpdate ? 'updated-manually' : 'update-later',\n );\n}\n\nasync function handleAutoUpdateSdk(packageName: string) {\n Sentry.setTag('initial-sdk-version', '>=7.0.0 <7.47.0');\n\n const shouldUpdate = await abortIfCancelled(\n clack.select({\n message:\n 'Do you want to automatically update your SDK to the latest version?',\n options: [\n {\n label: 'Yes!',\n value: true,\n hint: chalk.green('Recommended'),\n },\n {\n label: \"No, I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `Remember to update your SDK to at least ${MINIMUM_DEBUG_ID_SDK_VERSION}.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n if (shouldUpdate) {\n await installPackage({\n packageName,\n alreadyInstalled: true,\n askBeforeUpdating: false, // we already did this above\n });\n }\n\n Sentry.setTag(\n 'resolved-sdk-status',\n shouldUpdate ? 'updated-automatically' : 'update-later',\n );\n}\n\nasync function handleNoSdkInstalled(): Promise<void> {\n Sentry.setTag('initial-sdk-version', 'none');\n Sentry.setTag('installed-sdk', 'none');\n\n clack.log.warn(\n `${chalk.yellowBright(\n `It seems like you didn't yet install a Sentry SDK in your project.`,\n )}\nWe recommend setting up the SDK before continuing with the source maps wizard.\n\n${chalk.dim(`Take a look at our docs to get started:\nhttps://docs.sentry.io/`)}`,\n );\n\n const installedSDK = await abortIfCancelled(\n clack.select({\n message: 'Did you set up your Sentry SDK?',\n options: [\n { label: 'Yes, continue!', value: true },\n {\n label: \"I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n 'You need to set up an SDK before you can use Sentry',\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag(\n 'resolved-sdk-status',\n installedSDK ? 'installed-manually' : 'install-later',\n );\n}\n\nfunction getMinInstalledVersion(\n installedSdkVersionOrRange: string,\n installedSdkName: string,\n): string | undefined {\n try {\n // If `minVersion` is unable to parse the version it will throw an error\n // However, it will also return `null` if the parameter is undefined, which\n // we explicitly checked before but the typing doesn't know that.\n const minInstalledVersion = minVersion(installedSdkVersionOrRange)?.version;\n if (minInstalledVersion) {\n return minInstalledVersion;\n }\n } catch {\n // handling this, along with the `null` case below\n }\n\n Sentry.setTag('initial-sdk-version', 'unknown');\n clack.log.warn(\n `${chalk.yellow(\n `Could not parse the version of your installed SDK (\"${installedSdkName}\": \"${installedSdkVersionOrRange}\")`,\n )}\n\nPlease make sure that your Sentry SDK is updated to version ${chalk.bold(\n MINIMUM_DEBUG_ID_SDK_VERSION,\n )} or newer.\n `,\n );\n\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"sdk-version.js","sourceRoot":"","sources":["../../../../src/sourcemaps/utils/sdk-version.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,kDAA0B;AAC1B,mCAA+C;AAC/C,6CAI2B;AAE3B,qDAAuC;AACvC,2DAAwE;AAExE,MAAM,4BAA4B,GAAG,QAAQ,CAAC;AAE9C,+DAA+D;AAC/D,qEAAqE;AACrE,0EAA0E;AAC1E,qDAAqD;AACrD,MAAM,wBAAwB,GAAG;IAC/B,2DAA2D;IAC3D,eAAe;IACf,gBAAgB;IAChB,gBAAgB;IAChB,cAAc;IACd,sBAAsB;IACtB,eAAe;IACf,oBAAoB;IACpB,mBAAmB;IACnB,6BAA6B;IAE7B,iBAAiB;IACjB,iBAAiB;IACjB,qBAAqB;IACrB,wBAAwB;IACxB,aAAa;IACb,eAAe;IACf,iCAAiC;IACjC,gBAAgB;IAChB,eAAe;IACf,eAAe;IACf,gBAAgB;IAChB,aAAa;IACb,oBAAoB;IAEpB,YAAY;IACZ,iBAAi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ACjE,MAAM,mBAAmB,GAAG,IAAA,mBAAU,EAAC,0BAA0B,CAAC,EAAE,OAAO,CAAC;QAC5E,IAAI,mBAAmB,EAAE;YACvB,OAAO,mBAAmB,CAAC;SAC5B;KACF;IAAC,MAAM;QACN,kDAAkD;KACnD;IAED,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC;IAChD,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,GAAG,eAAK,CAAC,MAAM,CACb,uDAAuD,gBAAgB,OAAO,0BAA0B,IAAI,CAC7G;;8DAEyD,eAAK,CAAC,IAAI,CAClE,4BAA4B,CAC7B;KACA,CACF,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport { minVersion, satisfies } from 'semver';\nimport {\n abortIfCancelled,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack';\n\nimport * as Sentry from '@sentry/node';\nimport { findInstalledPackageFromList } from '../../utils/package-json';\n\nconst MINIMUM_DEBUG_ID_SDK_VERSION = '7.47.0';\n\n// This array is orderd by the SDKs we want to check for first.\n// The reason is that some SDKs depend on others and some users might\n// have added the dependencies to their package.json. We want to make sure\n// that we actually detect the \"top-level\" SDK first.\nconst SENTRY_SDK_PACKAGE_NAMES = [\n // SDKs using other framework SDKs need to be checked first\n '@sentry/astro',\n '@sentry/gatsby',\n '@sentry/nextjs',\n '@sentry/nuxt',\n '@sentry/react-router',\n '@sentry/remix',\n '@sentry/solidstart',\n '@sentry/sveltekit',\n '@sentry/tanstackstart-react',\n\n // Framework SDKs\n '@sentry/angular',\n '@sentry/angular-ivy',\n '@sentry/aws-serverless',\n '@sentry/bun',\n '@sentry/ember',\n '@sentry/google-cloud-serverless',\n '@sentry/nestjs',\n '@sentry/react',\n '@sentry/solid',\n '@sentry/svelte',\n '@sentry/vue',\n '@sentry/serverless',\n\n // Base SDKs\n '@sentry/browser',\n '@sentry/cloudflare',\n '@sentry/node',\n '@sentry/deno',\n];\n\n/**\n * Check for a minimum SDK version and prompt the user to upgrade if necessary.\n * We distinguish between 4 cases here:\n *\n * 1. Users didn't install any SDK yet\n * -> We tell them to install an SDK and then continue with the wizard\n * 2. Users installed an SDK in the range >=7.47.0\n * -> All good, no need to do anything!\n * 3. Users installed an SDK in the range >=7.0.0 <= 7.46.0\n * -> We ask if they want to auto-update to the latest version\n * 4. Users installed an SDK in the range <7.x\n * -> We tell users to manually upgrade (migrate between majors)\n */\nexport async function ensureMinimumSdkVersionIsInstalled(): Promise<void> {\n const installedSdkPackage = findInstalledPackageFromList(\n SENTRY_SDK_PACKAGE_NAMES,\n await getPackageDotJson(),\n );\n\n // Case 1:\n if (!installedSdkPackage) {\n return await handleNoSdkInstalled();\n }\n\n const { name: installedSdkName, version: installedSdkVersionOrRange } =\n installedSdkPackage;\n\n Sentry.setTag('installed-sdk', installedSdkName);\n\n const minInstalledVersion = getMinInstalledVersion(\n installedSdkVersionOrRange,\n installedSdkName,\n );\n\n if (!minInstalledVersion) {\n // This is handled in the getMinInstalledVersion function\n return;\n }\n\n const hasDebugIdCompatibleSdkVersion = satisfies(\n minInstalledVersion,\n `>=${MINIMUM_DEBUG_ID_SDK_VERSION}`,\n );\n\n // Case 2:\n if (hasDebugIdCompatibleSdkVersion) {\n Sentry.setTag('initial-sdk-version', '>=7.47.0');\n return;\n }\n\n const hasV7SdkVersion = satisfies(minInstalledVersion, '>=7.0.0');\n\n clack.log.warn(\n `${chalk.yellowBright(\n `It seems like you're using an outdated version (${installedSdkVersionOrRange}) of the ${chalk.bold(\n installedSdkName,\n )} SDK.`,\n )}\nUploading source maps is easiest with an SDK from version ${chalk.bold(\n MINIMUM_DEBUG_ID_SDK_VERSION,\n )} or newer. \n`,\n );\n\n // Case 3:\n if (hasV7SdkVersion) {\n await handleAutoUpdateSdk(installedSdkName);\n return;\n }\n\n // Case 4:\n await handleManuallyUpdateSdk(minInstalledVersion);\n}\n\nasync function handleManuallyUpdateSdk(minInstalledVersion: string) {\n Sentry.setTag(\n 'initial-sdk-version',\n `${satisfies(minInstalledVersion, '>=6.0.0') ? '6.x' : '<6.0.0'}`,\n );\n\n clack.log\n .info(`When upgrading from a version older than 7.0.0, make sure to follow the migration guide:\nhttps://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#upgrading-from-6x-to-7x\n`);\n\n const didUpdate = await abortIfCancelled(\n clack.select({\n message: 'Did you update your SDK to the latest version?',\n options: [\n {\n label: 'Yes!',\n value: true,\n },\n {\n label: \"No, I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `Remember to update your SDK to at least ${MINIMUM_DEBUG_ID_SDK_VERSION}.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag(\n 'resolved-sdk-status',\n didUpdate ? 'updated-manually' : 'update-later',\n );\n}\n\nasync function handleAutoUpdateSdk(packageName: string) {\n Sentry.setTag('initial-sdk-version', '>=7.0.0 <7.47.0');\n\n const shouldUpdate = await abortIfCancelled(\n clack.select({\n message:\n 'Do you want to automatically update your SDK to the latest version?',\n options: [\n {\n label: 'Yes!',\n value: true,\n hint: chalk.green('Recommended'),\n },\n {\n label: \"No, I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `Remember to update your SDK to at least ${MINIMUM_DEBUG_ID_SDK_VERSION}.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n if (shouldUpdate) {\n await installPackage({\n packageName,\n alreadyInstalled: true,\n askBeforeUpdating: false, // we already did this above\n });\n }\n\n Sentry.setTag(\n 'resolved-sdk-status',\n shouldUpdate ? 'updated-automatically' : 'update-later',\n );\n}\n\nasync function handleNoSdkInstalled(): Promise<void> {\n Sentry.setTag('initial-sdk-version', 'none');\n Sentry.setTag('installed-sdk', 'none');\n\n clack.log.warn(\n `${chalk.yellowBright(\n `It seems like you didn't yet install a Sentry SDK in your project.`,\n )}\nWe recommend setting up the SDK before continuing with the source maps wizard.\n\n${chalk.dim(`Take a look at our docs to get started:\nhttps://docs.sentry.io/`)}`,\n );\n\n const installedSDK = await abortIfCancelled(\n clack.select({\n message: 'Did you set up your Sentry SDK?',\n options: [\n { label: 'Yes, continue!', value: true },\n {\n label: \"I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n 'You need to set up an SDK before you can use Sentry',\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag(\n 'resolved-sdk-status',\n installedSDK ? 'installed-manually' : 'install-later',\n );\n}\n\nfunction getMinInstalledVersion(\n installedSdkVersionOrRange: string,\n installedSdkName: string,\n): string | undefined {\n try {\n // If `minVersion` is unable to parse the version it will throw an error\n // However, it will also return `null` if the parameter is undefined, which\n // we explicitly checked before but the typing doesn't know that.\n const minInstalledVersion = minVersion(installedSdkVersionOrRange)?.version;\n if (minInstalledVersion) {\n return minInstalledVersion;\n }\n } catch {\n // handling this, along with the `null` case below\n }\n\n Sentry.setTag('initial-sdk-version', 'unknown');\n clack.log.warn(\n `${chalk.yellow(\n `Could not parse the version of your installed SDK (\"${installedSdkName}\": \"${installedSdkVersionOrRange}\")`,\n )}\n\nPlease make sure that your Sentry SDK is updated to version ${chalk.bold(\n MINIMUM_DEBUG_ID_SDK_VERSION,\n )} or newer.\n `,\n );\n\n return undefined;\n}\n"]}
@@ -86,11 +86,4 @@ export declare function printJsonC(ast: t.Program): string;
86
86
  * @returns index of the last `const foo = require('bar');` statement or -1 if none was found.
87
87
  */
88
88
  export declare function getLastRequireIndex(program: t.Program): number;
89
- /**
90
- * Walks the statements and removes require statements which first argument includes the predicate.
91
- * Only removes top level require statements like `const foo = require('bar');`
92
- *
93
- * @returns True if any require statement was removed.
94
- */
95
- export declare function removeRequire(program: t.Program, predicate: string): boolean;
96
89
  export {};
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.removeRequire = exports.getLastRequireIndex = exports.printJsonC = exports.parseJsonC = exports.setOrUpdateObjectProperty = exports.getOrSetObjectProperty = exports.getObjectProperty = exports.hasSentryContent = exports.findFile = void 0;
26
+ exports.getLastRequireIndex = exports.printJsonC = exports.parseJsonC = exports.setOrUpdateObjectProperty = exports.getOrSetObjectProperty = exports.getObjectProperty = exports.hasSentryContent = exports.findFile = void 0;
27
27
  const fs = __importStar(require("fs"));
28
28
  const recast = __importStar(require("recast"));
29
29
  const b = recast.types.builders;
@@ -215,30 +215,4 @@ function getLastRequireIndex(program) {
215
215
  return lastRequireIdex;
216
216
  }
217
217
  exports.getLastRequireIndex = getLastRequireIndex;
218
- /**
219
- * Walks the statements and removes require statements which first argument includes the predicate.
220
- * Only removes top level require statements like `const foo = require('bar');`
221
- *
222
- * @returns True if any require statement was removed.
223
- */
224
- function removeRequire(program, predicate) {
225
- let removedAtLeastOne = false;
226
- program.body = program.body.filter((s) => {
227
- if (s.type === 'VariableDeclaration' &&
228
- s.declarations[0].type === 'VariableDeclarator' &&
229
- s.declarations[0].init !== null &&
230
- typeof s.declarations[0].init !== 'undefined' &&
231
- s.declarations[0].init.type === 'CallExpression' &&
232
- s.declarations[0].init.callee.type === 'Identifier' &&
233
- s.declarations[0].init.callee.name === 'require' &&
234
- s.declarations[0].init.arguments[0].type === 'StringLiteral' &&
235
- s.declarations[0].init.arguments[0].value.includes(predicate)) {
236
- removedAtLeastOne = true;
237
- return false;
238
- }
239
- return true;
240
- });
241
- return removedAtLeastOne;
242
- }
243
- exports.removeRequire = removeRequire;
244
218
  //# sourceMappingURL=ast-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ast-utils.js","sourceRoot":"","sources":["../../../src/utils/ast-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AAEzB,+CAAiC;AAIjC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;AAEhC;;;GAGG;AACH,SAAgB,QAAQ,CACtB,Q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CAAC,EAAE,EAAE;QACvC,IACE,CAAC,CAAC,IAAI,KAAK,qBAAqB;YAChC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,oBAAoB;YAC/C,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI;YAC/B,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW;YAC7C,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,gBAAgB;YAChD,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY;YACnD,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS;YAChD,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe;YAC5D,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAC7D;YACA,iBAAiB,GAAG,IAAI,CAAC;YACzB,OAAO,KAAK,CAAC;SACd;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AApBD,sCAoBC","sourcesContent":["import * as fs from 'fs';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\n\nconst b = recast.types.builders;\n\n/**\n * Checks if a file where we don't know its concrete file type yet exists\n * and returns the full path to the file with the correct file type.\n */\nexport function findFile(\n filePath: string,\n fileTypes: string[] = ['.js', '.ts', '.mjs', '.cjs'],\n): string | undefined {\n return fileTypes\n .map((type) => `${filePath}${type}`)\n .find((file) => fs.existsSync(file));\n}\n\n/**\n * checks for require('@sentry/*') syntax\n */\nexport function hasSentryContent(program: t.Program): boolean {\n let foundSentry: boolean | undefined = false;\n recast.visit(program, {\n visitStringLiteral(path) {\n foundSentry = foundSentry || path.node.value.startsWith('@sentry/');\n this.traverse(path);\n },\n visitLiteral(path) {\n foundSentry =\n foundSentry || path.node.value?.toString().startsWith('@sentry/');\n this.traverse(path);\n },\n });\n\n return !!foundSentry;\n}\n\n/**\n * Searches for a property of an ObjectExpression by name\n *\n * @param object the ObjectExpression to search in\n * @param name the name of the property to search for\n *\n * @returns the property if it exists\n */\nexport function getObjectProperty(\n object: t.ObjectExpression,\n name: string,\n): t.Property | undefined {\n return object.properties.find((p): p is t.Property => {\n const isObjectProp = p.type === 'Property' || p.type === 'ObjectProperty';\n\n if (!isObjectProp) {\n return false;\n }\n\n const hasMatchingLiteralKey =\n isObjectProp &&\n (p.key.type === 'Literal' || p.key.type === 'StringLiteral') &&\n p.key.value === name;\n\n if (hasMatchingLiteralKey) {\n return true;\n }\n\n // has matching identifier key\n return isObjectProp && p.key.type === 'Identifier' && p.key.name === name;\n });\n}\n\n/**\n * Attempts to find a property of an ObjectExpression by name. If it doesn't exist,\n * the property will be added to the ObjectExpression with the provided default value.\n *\n * @param object the parent object expression to search in\n * @param name the name of the property to search for\n * @param defaultValue the default value to set if the property doesn't exist\n *\n * @returns the\n */\nexport function getOrSetObjectProperty(\n object: t.ObjectExpression,\n name: string,\n defaultValue:\n | t.Literal\n | t.BooleanLiteral\n | t.StringLiteral\n | t.ObjectExpression,\n): t.Property {\n const existingProperty = getObjectProperty(object, name);\n\n if (existingProperty) {\n return existingProperty;\n }\n\n const newProperty = b.property.from({\n kind: 'init',\n key: b.stringLiteral(name),\n value: defaultValue,\n });\n\n object.properties.push(newProperty);\n\n return newProperty;\n}\n\n/**\n * Sets a property of an ObjectExpression if it exists, otherwise adds it\n * to the ObjectExpression. Optionally, a comment can be added to the\n * property.\n *\n * @param object the ObjectExpression to set the property on\n * @param name the name of the property to set\n * @param value the value of the property to set\n * @param comment (optional) a comment to add to the property\n */\nexport function setOrUpdateObjectProperty(\n object: t.ObjectExpression,\n name: string,\n value: t.Literal | t.BooleanLiteral | t.StringLiteral | t.ObjectExpression,\n comment?: string,\n) {\n const newComments =\n comment &&\n comment.split('\\n').map((c) => b.commentLine(` ${c}`, true, false));\n\n const existingProperty = getObjectProperty(object, name);\n\n if (existingProperty) {\n existingProperty.value = value;\n if (newComments) {\n existingProperty.comments = [\n ...(existingProperty?.comments || []),\n ...newComments,\n ];\n }\n } else {\n object.properties.push(\n b.objectProperty.from({\n key: b.stringLiteral(name),\n value,\n ...(newComments && {\n comments: newComments,\n }),\n }),\n );\n }\n}\n\ntype JsonCParseResult =\n | {\n jsonObject: t.ObjectExpression;\n ast: t.Program;\n }\n | {\n jsonObject: undefined;\n ast: undefined;\n };\n\n/**\n * Parses a JSON string with (potential) comments (JSON-C) and returns the JS AST\n * that can be walked and modified with recast like a normal JS AST.\n *\n * This is done by wrapping the JSON-C string in parentheses, thereby making it\n * a JS `Program` with an `ExpressionStatement` as its body. The expression is then\n * extracted from the AST and returned alongside the AST.\n *\n * To preserve as much original formatting as possible, the returned `ast`\n * property should be passed to {@link `printJsonC`} to get the JSON-C string back.\n *\n * If the input is not valid JSON-C, the result will be undefined.\n *\n * @see {@link JsonCParseResult}\n *\n * @param jsonString a JSON-C string\n *\n * @returns a {@link JsonCParseResult}, containing either the JSON-C object and the AST or undefined in both cases\n */\nexport function parseJsonC(jsonString: string): JsonCParseResult {\n try {\n const jsTsConfig = `(${jsonString})`;\n // no idea why recast returns any here, this is dumb :/\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const ast = recast.parse(jsTsConfig.toString()).program as t.Program;\n\n const jsonObject =\n (ast.body[0].type === 'ExpressionStatement' &&\n ast.body[0].expression.type === 'ObjectExpression' &&\n ast.body[0].expression) ||\n undefined;\n\n if (jsonObject) {\n return { jsonObject, ast };\n }\n } catch {\n /* empty */\n }\n return { jsonObject: undefined, ast: undefined };\n}\n\n/**\n * Takes the AST of a parsed JSON-C \"program\" and returns the JSON-C string without\n * any of the temporary JS wrapper code that was previously applied.\n *\n * Only use this in conjunction with {@link `parseJsonC`}\n *\n * @param ast the `ast` returned from {@link `parseJsonC`}\n *\n * @returns the JSON-C string\n */\nexport function printJsonC(ast: t.Program): string {\n const js = recast.print(ast).code;\n return js.substring(1, js.length - 1);\n}\n\n/**\n * Walks the program body and returns index of the last variable assignment initialized by require statement.\n * Only counts top level require statements.\n *\n * @returns index of the last `const foo = require('bar');` statement or -1 if none was found.\n */\nexport function getLastRequireIndex(program: t.Program): number {\n let lastRequireIdex = -1;\n program.body.forEach((s, i) => {\n if (\n s.type === 'VariableDeclaration' &&\n s.declarations[0].type === 'VariableDeclarator' &&\n s.declarations[0].init !== null &&\n typeof s.declarations[0].init !== 'undefined' &&\n s.declarations[0].init.type === 'CallExpression' &&\n s.declarations[0].init.callee.type === 'Identifier' &&\n s.declarations[0].init.callee.name === 'require'\n ) {\n lastRequireIdex = i;\n }\n });\n return lastRequireIdex;\n}\n\n/**\n * Walks the statements and removes require statements which first argument includes the predicate.\n * Only removes top level require statements like `const foo = require('bar');`\n *\n * @returns True if any require statement was removed.\n */\nexport function removeRequire(program: t.Program, predicate: string): boolean {\n let removedAtLeastOne = false;\n program.body = program.body.filter((s) => {\n if (\n s.type === 'VariableDeclaration' &&\n s.declarations[0].type === 'VariableDeclarator' &&\n s.declarations[0].init !== null &&\n typeof s.declarations[0].init !== 'undefined' &&\n s.declarations[0].init.type === 'CallExpression' &&\n s.declarations[0].init.callee.type === 'Identifier' &&\n s.declarations[0].init.callee.name === 'require' &&\n s.declarations[0].init.arguments[0].type === 'StringLiteral' &&\n s.declarations[0].init.arguments[0].value.includes(predicate)\n ) {\n removedAtLeastOne = true;\n return false;\n }\n return true;\n });\n return removedAtLeastOne;\n}\n"]}
1
+ {"version":3,"file":"ast-utils.js","sourceRoot":"","sources":["../../../src/utils/ast-utils.ts"],"names":[],"mappings":";;;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import * as fs from 'fs';\n\nimport * as recast from 'recast';\nimport x = recast.types;\nimport t = x.namedTypes;\n\nconst b = recast.types.builders;\n\n/**\n * Checks if a file where we don't know its concrete file type yet exists\n * and returns the full path to the file with the correct file type.\n */\nexport function findFile(\n filePath: string,\n fileTypes: string[] = ['.js', '.ts', '.mjs', '.cjs'],\n): string | undefined {\n return fileTypes\n .map((type) => `${filePath}${type}`)\n .find((file) => fs.existsSync(file));\n}\n\n/**\n * checks for require('@sentry/*') syntax\n */\nexport function hasSentryContent(program: t.Program): boolean {\n let foundSentry: boolean | undefined = false;\n recast.visit(program, {\n visitStringLiteral(path) {\n foundSentry = foundSentry || path.node.value.startsWith('@sentry/');\n this.traverse(path);\n },\n visitLiteral(path) {\n foundSentry =\n foundSentry || path.node.value?.toString().startsWith('@sentry/');\n this.traverse(path);\n },\n });\n\n return !!foundSentry;\n}\n\n/**\n * Searches for a property of an ObjectExpression by name\n *\n * @param object the ObjectExpression to search in\n * @param name the name of the property to search for\n *\n * @returns the property if it exists\n */\nexport function getObjectProperty(\n object: t.ObjectExpression,\n name: string,\n): t.Property | undefined {\n return object.properties.find((p): p is t.Property => {\n const isObjectProp = p.type === 'Property' || p.type === 'ObjectProperty';\n\n if (!isObjectProp) {\n return false;\n }\n\n const hasMatchingLiteralKey =\n isObjectProp &&\n (p.key.type === 'Literal' || p.key.type === 'StringLiteral') &&\n p.key.value === name;\n\n if (hasMatchingLiteralKey) {\n return true;\n }\n\n // has matching identifier key\n return isObjectProp && p.key.type === 'Identifier' && p.key.name === name;\n });\n}\n\n/**\n * Attempts to find a property of an ObjectExpression by name. If it doesn't exist,\n * the property will be added to the ObjectExpression with the provided default value.\n *\n * @param object the parent object expression to search in\n * @param name the name of the property to search for\n * @param defaultValue the default value to set if the property doesn't exist\n *\n * @returns the\n */\nexport function getOrSetObjectProperty(\n object: t.ObjectExpression,\n name: string,\n defaultValue:\n | t.Literal\n | t.BooleanLiteral\n | t.StringLiteral\n | t.ObjectExpression,\n): t.Property {\n const existingProperty = getObjectProperty(object, name);\n\n if (existingProperty) {\n return existingProperty;\n }\n\n const newProperty = b.property.from({\n kind: 'init',\n key: b.stringLiteral(name),\n value: defaultValue,\n });\n\n object.properties.push(newProperty);\n\n return newProperty;\n}\n\n/**\n * Sets a property of an ObjectExpression if it exists, otherwise adds it\n * to the ObjectExpression. Optionally, a comment can be added to the\n * property.\n *\n * @param object the ObjectExpression to set the property on\n * @param name the name of the property to set\n * @param value the value of the property to set\n * @param comment (optional) a comment to add to the property\n */\nexport function setOrUpdateObjectProperty(\n object: t.ObjectExpression,\n name: string,\n value: t.Literal | t.BooleanLiteral | t.StringLiteral | t.ObjectExpression,\n comment?: string,\n) {\n const newComments =\n comment &&\n comment.split('\\n').map((c) => b.commentLine(` ${c}`, true, false));\n\n const existingProperty = getObjectProperty(object, name);\n\n if (existingProperty) {\n existingProperty.value = value;\n if (newComments) {\n existingProperty.comments = [\n ...(existingProperty?.comments || []),\n ...newComments,\n ];\n }\n } else {\n object.properties.push(\n b.objectProperty.from({\n key: b.stringLiteral(name),\n value,\n ...(newComments && {\n comments: newComments,\n }),\n }),\n );\n }\n}\n\ntype JsonCParseResult =\n | {\n jsonObject: t.ObjectExpression;\n ast: t.Program;\n }\n | {\n jsonObject: undefined;\n ast: undefined;\n };\n\n/**\n * Parses a JSON string with (potential) comments (JSON-C) and returns the JS AST\n * that can be walked and modified with recast like a normal JS AST.\n *\n * This is done by wrapping the JSON-C string in parentheses, thereby making it\n * a JS `Program` with an `ExpressionStatement` as its body. The expression is then\n * extracted from the AST and returned alongside the AST.\n *\n * To preserve as much original formatting as possible, the returned `ast`\n * property should be passed to {@link `printJsonC`} to get the JSON-C string back.\n *\n * If the input is not valid JSON-C, the result will be undefined.\n *\n * @see {@link JsonCParseResult}\n *\n * @param jsonString a JSON-C string\n *\n * @returns a {@link JsonCParseResult}, containing either the JSON-C object and the AST or undefined in both cases\n */\nexport function parseJsonC(jsonString: string): JsonCParseResult {\n try {\n const jsTsConfig = `(${jsonString})`;\n // no idea why recast returns any here, this is dumb :/\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const ast = recast.parse(jsTsConfig.toString()).program as t.Program;\n\n const jsonObject =\n (ast.body[0].type === 'ExpressionStatement' &&\n ast.body[0].expression.type === 'ObjectExpression' &&\n ast.body[0].expression) ||\n undefined;\n\n if (jsonObject) {\n return { jsonObject, ast };\n }\n } catch {\n /* empty */\n }\n return { jsonObject: undefined, ast: undefined };\n}\n\n/**\n * Takes the AST of a parsed JSON-C \"program\" and returns the JSON-C string without\n * any of the temporary JS wrapper code that was previously applied.\n *\n * Only use this in conjunction with {@link `parseJsonC`}\n *\n * @param ast the `ast` returned from {@link `parseJsonC`}\n *\n * @returns the JSON-C string\n */\nexport function printJsonC(ast: t.Program): string {\n const js = recast.print(ast).code;\n return js.substring(1, js.length - 1);\n}\n\n/**\n * Walks the program body and returns index of the last variable assignment initialized by require statement.\n * Only counts top level require statements.\n *\n * @returns index of the last `const foo = require('bar');` statement or -1 if none was found.\n */\nexport function getLastRequireIndex(program: t.Program): number {\n let lastRequireIdex = -1;\n program.body.forEach((s, i) => {\n if (\n s.type === 'VariableDeclaration' &&\n s.declarations[0].type === 'VariableDeclarator' &&\n s.declarations[0].init !== null &&\n typeof s.declarations[0].init !== 'undefined' &&\n s.declarations[0].init.type === 'CallExpression' &&\n s.declarations[0].init.callee.type === 'Identifier' &&\n s.declarations[0].init.callee.name === 'require'\n ) {\n lastRequireIdex = i;\n }\n });\n return lastRequireIdex;\n}\n"]}
@@ -29,6 +29,12 @@ export interface CliSetupConfigContent {
29
29
  }
30
30
  export declare const rcCliSetupConfig: CliSetupConfig;
31
31
  export declare const propertiesCliSetupConfig: Required<CliSetupConfig>;
32
+ /**
33
+ * Aborts the wizard and sets the Sentry transaction status to `cancelled` or `aborted`.
34
+ *
35
+ * @param message The message to display to the user.
36
+ * @param status The status to set on the Sentry transaction. Defaults to `1`.
37
+ */
32
38
  export declare function abort(message?: string, status?: number): Promise<never>;
33
39
  export declare function abortIfCancelled<T>(input: T | Promise<T>): Promise<Exclude<T, symbol>>;
34
40
  export declare function printWelcome(options: {
@@ -69,6 +75,8 @@ type InstallPackageOptions = {
69
75
  packageManager?: PackageManager;
70
76
  /** Add force install flag to command to skip install precondition fails */
71
77
  forceInstall?: boolean;
78
+ /** Install as a dev dependency (@default: false) */
79
+ devDependency?: boolean;
72
80
  };
73
81
  /**
74
82
  * Installs or updates a package with the user's package manager.
@@ -76,7 +84,7 @@ type InstallPackageOptions = {
76
84
  * IMPORTANT: This function modifies the `package.json`! Be sure to re-read
77
85
  * it if you make additional modifications to it after calling this function!
78
86
  */
79
- export declare function installPackage({ packageName, alreadyInstalled, askBeforeUpdating, packageNameDisplayLabel, packageManager, forceInstall, }: InstallPackageOptions): Promise<{
87
+ export declare function installPackage({ packageName, alreadyInstalled, askBeforeUpdating, packageNameDisplayLabel, packageManager, forceInstall, devDependency, }: InstallPackageOptions): Promise<{
80
88
  packageManager?: PackageManager;
81
89
  }>;
82
90
  export declare function addSentryCliConfig({ authToken, org, project, url }: CliSetupConfigContent, setupConfig?: CliSetupConfig): Promise<void>;