@sentry/wizard 5.0.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 (40) hide show
  1. package/CHANGELOG.md +5 -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/src/nextjs/nextjs-wizard.js +24 -10
  11. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  12. package/dist/src/nextjs/templates.d.ts +2 -0
  13. package/dist/src/nextjs/templates.js +47 -1
  14. package/dist/src/nextjs/templates.js.map +1 -1
  15. package/dist/src/nextjs/utils.d.ts +2 -0
  16. package/dist/src/nextjs/utils.js +42 -1
  17. package/dist/src/nextjs/utils.js.map +1 -1
  18. package/dist/src/sourcemaps/sourcemaps-wizard.js +14 -0
  19. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  20. package/dist/src/sourcemaps/tools/wrangler.d.ts +28 -0
  21. package/dist/src/sourcemaps/tools/wrangler.js +276 -0
  22. package/dist/src/sourcemaps/tools/wrangler.js.map +1 -0
  23. package/dist/src/sourcemaps/utils/detect-tool.d.ts +1 -1
  24. package/dist/src/sourcemaps/utils/detect-tool.js +1 -0
  25. package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
  26. package/dist/src/utils/clack/index.d.ts +9 -1
  27. package/dist/src/utils/clack/index.js +8 -1
  28. package/dist/src/utils/clack/index.js.map +1 -1
  29. package/dist/src/version.d.ts +1 -1
  30. package/dist/src/version.js +1 -1
  31. package/dist/src/version.js.map +1 -1
  32. package/dist/test/nextjs/templates.test.js +98 -0
  33. package/dist/test/nextjs/templates.test.js.map +1 -1
  34. package/dist/test/nextjs/utils.test.d.ts +1 -0
  35. package/dist/test/nextjs/utils.test.js +104 -0
  36. package/dist/test/nextjs/utils.test.js.map +1 -0
  37. package/dist/test/sourcemaps/tools/wrangler.test.d.ts +1 -0
  38. package/dist/test/sourcemaps/tools/wrangler.test.js +132 -0
  39. package/dist/test/sourcemaps/tools/wrangler.test.js.map +1 -0
  40. package/package.json +2 -1
@@ -48,6 +48,7 @@ const detect_tool_1 = require("./utils/detect-tool");
48
48
  const other_wizards_1 = require("./utils/other-wizards");
49
49
  const sdk_version_1 = require("./utils/sdk-version");
50
50
  const path_1 = require("path");
51
+ const wrangler_1 = require("./tools/wrangler");
51
52
  async function runSourcemapsWizard(options, preSelectedTool) {
52
53
  return (0, telemetry_1.withTelemetry)({
53
54
  enabled: options.telemetryEnabled,
@@ -106,6 +107,11 @@ You can turn this off by running the wizard with the '--disable-telemetry' flag.
106
107
  authToken,
107
108
  }, wizardOptionsWithPreSelectedProject, preSelectedTool));
108
109
  await (0, telemetry_1.traceStep)('ci-setup', () => setupCI(selectedTool, authToken, options.comingFrom));
110
+ if (!preSelectedTool) {
111
+ // running prettier is only necessary if the source maps wizard is the main flow
112
+ // skip it, if it's called from another wizard (e.g. angular)
113
+ await (0, clack_1.runPrettierIfInstalled)({ cwd: process.cwd() });
114
+ }
109
115
  if (!preSelectedTool) {
110
116
  await (0, telemetry_1.traceStep)('outro', () => printOutro(sentryUrl, selectedProject.organization.slug, selectedProject.id));
111
117
  }
@@ -124,6 +130,11 @@ async function askForUsedBundlerTool() {
124
130
  value: 'create-react-app',
125
131
  hint: 'Select this option if you set up your app with Create React App.',
126
132
  },
133
+ {
134
+ label: 'Cloudflare Wrangler',
135
+ value: 'wrangler',
136
+ hint: "You're using `wrangler deploy` to build and deploy your Cloudflare Worker.",
137
+ },
127
138
  {
128
139
  label: 'Webpack',
129
140
  value: 'webpack',
@@ -184,6 +195,9 @@ async function startToolSetupFlow(selectedTool, options, wizardOptions, preSelec
184
195
  case 'create-react-app':
185
196
  await (0, sentry_cli_1.configureSentryCLI)(options, create_react_app_1.configureCRASourcemapGenerationFlow);
186
197
  break;
198
+ case 'wrangler':
199
+ await (0, wrangler_1.configureWrangler)(options);
200
+ break;
187
201
  case 'angular':
188
202
  await (0, sentry_cli_1.configureSentryCLI)({ ...options, defaultArtifactPath: `.${path_1.sep}dist` }, angular_1.configureAngularSourcemapGenerationFlow, preSelectedTool === 'angular');
189
203
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"sourcemaps-wizard.js","sourceRoot":"","sources":["../../../src/sourcemaps/sourcemaps-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,qDAAuC;AACvC,kDAA0B;AAE1B,4CAAwD;AACxD,0CASwB;AACxB,8DAA+C;AAE/C,sCAAiD;AACjD,+EAA0E;AAC1E,6CAA0E;AAC1E,+DAA+E;AAC/E,6CAAyD;AACzD,2CAAuD;AACvD,mDAA4E;AAC5E,qCAAkE;AAElE,uCAAmD;AACnD,6CAAyD;AAEzD,qDAAqD;AACrD,yDAAyF;AACzF,qDAAyE;AACzE,+BAA2B;AAEpB,KAAK,UAAU,mBAAmB,CACvC,OAAsB,EACtB,eAAgC;IAEhC,OAAO,IAAA,yBAAa,EAClB;QACE,OAAO,EAAE,OAAO,CAAC,gBAAgB;QACjC,WAAW,EAAE,YAAY;QACzB,aAAa,EAAE,OAAO;KACvB,EACD,GAAG,EAAE,CAAC,gCAAgC,CAAC,OAAO,EAAE,eAAe,CAAC,CACjE,CAAC;AACJ,CAAC;AAZD,kDAYC;AAED,KAAK,UAAU,gCAAgC,CAC7C,OAAsB,EACtB,eAAgC;IAEhC,IAAI,CAAC,eAAe,EAAE;QACpB,IAAA,oBAAY,EAAC;Y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pD,MAAM,cAAc,GAAG,IAAA,uBAAiB,EAAC,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IAEtE,MAAM,KAAK,GAAG,IAAA,yCAAkB,GAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IAEhD,iBAAK,CAAC,KAAK,CAAC,GAAG,eAAK,CAAC,KAAK,CAAC,mCAAmC,CAAC;;KAE5D,eAAK,CAAC,IAAI,CAAC;;kCAEkB,eAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC;QACvD,eAAK,CAAC,IAAI,CACV,GAAG,KAAK,qBAAqB,eAAK,CAAC,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,CACxE;QACC,eAAK,CAAC,IAAI,CACV,GAAG,KAAK,yDAAyD,CAClE;;QAEC,eAAK,CAAC,IAAI,CAAC,GAAG,KAAK,qCAAqC,CAAC;QACzD,eAAK,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,cAAc,EAAE,CAAC;;QAExC,eAAK,CAAC,IAAI,CACV,GAAG,KAAK,yDAAyD,CAClE;IACH,CAAC;KACA,eAAK,CAAC,GAAG,CACT;;;;yDAIoD,CACrD;CACH,CAAC,CAAC;AACH,CAAC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport * as Sentry from '@sentry/node';\nimport chalk from 'chalk';\n\nimport { traceStep, withTelemetry } from '../telemetry';\nimport {\n abort,\n abortIfCancelled,\n confirmContinueIfNoOrDirtyGitRepo,\n getOrAskForProjectData,\n getPackageManager,\n printWelcome,\n SENTRY_CLI_RC_FILE,\n SENTRY_DOT_ENV_FILE,\n} from '../utils/clack';\nimport { NPM } from '../utils/package-manager';\nimport type { WizardOptions } from '../utils/types';\nimport { getIssueStreamUrl } from '../utils/url';\nimport { isUnicodeSupported } from '../utils/vendor/is-unicorn-supported';\nimport { configureAngularSourcemapGenerationFlow } from './tools/angular';\nimport { configureCRASourcemapGenerationFlow } from './tools/create-react-app';\nimport { configureEsbuildPlugin } from './tools/esbuild';\nimport { configureRollupPlugin } from './tools/rollup';\nimport { configureSentryCLI, setupNpmScriptInCI } from './tools/sentry-cli';\nimport { configureTscSourcemapGenerationFlow } from './tools/tsc';\nimport type { SourceMapUploadToolConfigurationOptions } from './tools/types';\nimport { configureVitePlugin } from './tools/vite';\nimport { configureWebPackPlugin } from './tools/webpack';\nimport type { SupportedTools } from './utils/detect-tool';\nimport { detectUsedTool } from './utils/detect-tool';\nimport { checkIfMoreSuitableWizardExistsAndAskForRedirect } from './utils/other-wizards';\nimport { ensureMinimumSdkVersionIsInstalled } from './utils/sdk-version';\nimport { sep } from 'path';\n\nexport async function runSourcemapsWizard(\n options: WizardOptions,\n preSelectedTool?: SupportedTools,\n): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'sourcemaps',\n wizardOptions: options,\n },\n () => runSourcemapsWizardWithTelemetry(options, preSelectedTool),\n );\n}\n\nasync function runSourcemapsWizardWithTelemetry(\n options: WizardOptions,\n preSelectedTool?: SupportedTools,\n): Promise<void> {\n if (!preSelectedTool) {\n printWelcome({\n wizardName: 'Sentry Source Maps Upload Configuration Wizard',\n message: `This wizard will help you upload source maps to Sentry as part of your build.\nThank you for using Sentry :)${\n options.telemetryEnabled\n ? `\n\n(This setup wizard sends telemetry data and crash reports to Sentry.\nYou can turn this off by running the wizard with the '--disable-telemetry' flag.)`\n : ''\n }`,\n promoCode: options.promoCode,\n });\n }\n\n const moreSuitableWizard = await traceStep(\n 'check-framework-wizard',\n checkIfMoreSuitableWizardExistsAndAskForRedirect,\n );\n if (moreSuitableWizard) {\n await traceStep('run-framework-wizard', () => moreSuitableWizard(options));\n return;\n }\n\n if (!preSelectedTool) {\n await confirmContinueIfNoOrDirtyGitRepo({\n ignoreGitChanges: options.ignoreGitChanges,\n cwd: undefined,\n });\n }\n\n await traceStep('check-sdk-version', ensureMinimumSdkVersionIsInstalled);\n\n const { selfHosted, selectedProject, sentryUrl, authToken } =\n await getOrAskForProjectData(options);\n\n const wizardOptionsWithPreSelectedProject = {\n ...options,\n preSelectedProject: {\n project: selectedProject,\n authToken,\n selfHosted,\n },\n };\n\n const selectedTool =\n preSelectedTool || (await traceStep('select-tool', askForUsedBundlerTool));\n\n Sentry.setTag('selected-tool', selectedTool);\n\n if (selectedTool === 'no-tool') {\n clack.log.info(\n \"No Problem! But in this case, there's nothing to configure :)\",\n );\n await abort('Exiting, have a great day!', 0);\n return;\n }\n\n await traceStep('tool-setup', () =>\n startToolSetupFlow(\n selectedTool,\n {\n orgSlug: selectedProject.organization.slug,\n projectSlug: selectedProject.slug,\n selfHosted,\n url: sentryUrl,\n authToken,\n },\n wizardOptionsWithPreSelectedProject,\n preSelectedTool,\n ),\n );\n\n await traceStep('ci-setup', () =>\n setupCI(selectedTool, authToken, options.comingFrom),\n );\n\n if (!preSelectedTool) {\n await traceStep('outro', () =>\n printOutro(\n sentryUrl,\n selectedProject.organization.slug,\n selectedProject.id,\n ),\n );\n }\n}\n\nasync function askForUsedBundlerTool(): Promise<SupportedTools> {\n const selectedTool = await abortIfCancelled(\n clack.select({\n message: 'Which framework, bundler or build tool are you using?',\n options: [\n {\n label: 'Angular',\n value: 'angular',\n hint: 'Select this option if you are using Angular.',\n },\n {\n label: 'Create React App',\n value: 'create-react-app',\n hint: 'Select this option if you set up your app with Create React App.',\n },\n {\n label: 'Webpack',\n value: 'webpack',\n hint: 'Select this if you are using Webpack and you have access to your Webpack config.',\n },\n {\n label: 'Vite',\n value: 'vite',\n hint: 'Select this if you are using Vite and you have access to your Vite config.',\n },\n {\n label: 'esbuild',\n value: 'esbuild',\n hint: 'Select this if you are using esbuild and you have access to your esbuild config.',\n },\n {\n label: 'Rollup',\n value: 'rollup',\n hint: 'Select this if you are using Rollup and you have access to your Rollup config.',\n },\n {\n label: 'tsc',\n value: 'tsc',\n hint: 'Configure source maps when using tsc as build tool',\n },\n {\n label: 'I use another tool',\n value: 'sentry-cli',\n hint: 'This will configure source maps upload for you using sentry-cli',\n },\n {\n label: \"I don't minify, transpile or bundle my code\",\n value: 'no-tool',\n hint: 'This will exit the wizard',\n },\n ],\n initialValue: await detectUsedTool(),\n }),\n );\n\n return selectedTool;\n}\n\nasync function startToolSetupFlow(\n selectedTool: SupportedTools,\n options: SourceMapUploadToolConfigurationOptions,\n wizardOptions: WizardOptions,\n preSelectedTool?: SupportedTools,\n): Promise<void> {\n switch (selectedTool) {\n case 'webpack':\n await configureWebPackPlugin(options);\n break;\n case 'vite':\n await configureVitePlugin(options);\n break;\n case 'esbuild':\n await configureEsbuildPlugin(options);\n break;\n case 'rollup':\n await configureRollupPlugin(options);\n break;\n case 'tsc':\n await configureSentryCLI(options, configureTscSourcemapGenerationFlow);\n break;\n case 'create-react-app':\n await configureSentryCLI(options, configureCRASourcemapGenerationFlow);\n break;\n case 'angular':\n await configureSentryCLI(\n { ...options, defaultArtifactPath: `.${sep}dist` },\n configureAngularSourcemapGenerationFlow,\n preSelectedTool === 'angular',\n );\n break;\n default:\n await configureSentryCLI(options);\n break;\n }\n}\nexport async function setupCI(\n selectedTool: SupportedTools,\n authToken: string,\n comingFrom: WizardOptions['comingFrom'],\n) {\n if (comingFrom === 'vercel') {\n clack.log.info(\n 'Sentry Vercel integration is already configured. Skipping CI setup.',\n );\n Sentry.setTag('using-ci', true);\n } else {\n await traceStep('configure-ci', () => configureCI(selectedTool, authToken));\n }\n}\n\nexport async function configureCI(\n selectedTool: SupportedTools,\n authToken: string,\n): Promise<void> {\n const isUsingCI = await abortIfCancelled(\n clack.select({\n message: `Are you using a CI/CD tool to build and deploy your application?`,\n options: [\n {\n label: 'Yes',\n hint: 'I use a tool like GitHub Actions, GitLab, CircleCI, TravisCI, Jenkins, Vercel, ...',\n value: true,\n },\n {\n label: 'No',\n hint: 'I build and deploy my application manually',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('using-ci', isUsingCI);\n\n const isCliBasedFlowTool = [\n 'sentry-cli',\n 'tsc',\n 'angular',\n 'create-react-app',\n ].includes(selectedTool);\n\n const authTokenFile = isCliBasedFlowTool\n ? SENTRY_CLI_RC_FILE\n : SENTRY_DOT_ENV_FILE;\n\n if (!isUsingCI) {\n clack.log.info(\n `No Problem! Just make sure that the Sentry auth token from ${chalk.cyan(\n authTokenFile,\n )} is available whenever you build and deploy your app.`,\n );\n return;\n }\n\n if (isCliBasedFlowTool) {\n await traceStep('ci-npm-script-setup', setupNpmScriptInCI);\n }\n\n await traceStep('ci-auth-token-setup', () => setupAuthTokenInCI(authToken));\n}\n\nasync function setupAuthTokenInCI(authToken: string) {\n clack.log.step(\n 'Add the Sentry authentication token as an environment variable to your CI setup:',\n );\n\n // Intentially 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 chalk.greenBright(`\nSENTRY_AUTH_TOKEN=${authToken}\n`),\n );\n\n clack.log.warn(\n chalk.yellow('DO NOT commit this auth token to your repository!'),\n );\n\n const addedEnvVarToCI = await abortIfCancelled(\n clack.select({\n message: 'Did you configure CI as shown above?',\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 the auth token to upload source maps in CI',\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('added-env-var-to-ci', addedEnvVarToCI);\n\n if (!addedEnvVarToCI) {\n clack.log.info(\"Don't forget! :)\");\n }\n}\n\nasync function printOutro(\n url: string,\n orgSlug: string,\n projectId: string,\n): Promise<void> {\n const packageManager = await getPackageManager(NPM);\n\n const issueStreamUrl = getIssueStreamUrl({ url, orgSlug, projectId });\n\n const arrow = isUnicodeSupported() ? '→' : '->';\n\n clack.outro(`${chalk.green(\"That's it - everything is set up!\")}\n\n ${chalk.cyan(`Test and validate your setup locally with the following Steps:\n\n 1. Build your application in ${chalk.bold('production mode')}.\n ${chalk.gray(\n `${arrow} For example, run ${chalk.bold(packageManager.buildCommand)}.`,\n )}\n ${chalk.gray(\n `${arrow} You should see source map upload logs in your console.`,\n )}\n 2. Run your application and throw a test error.\n ${chalk.gray(`${arrow} The error should appear in Sentry:`)}\n ${chalk.gray(`${arrow} ${issueStreamUrl}`)}\n 3. Open the error in Sentry and verify that it's source-mapped.\n ${chalk.gray(\n `${arrow} The stack trace should show your original source code.`,\n )}\n `)}\n ${chalk.dim(\n `If you encounter any issues, please refer to the Troubleshooting Guide:\n https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js\n\n If the guide doesn't help or you encounter a bug, please let us know:\n https://github.com/getsentry/sentry-javascript/issues`,\n )}\n`);\n}\n"]}
1
+ {"version":3,"file":"sourcemaps-wizard.js","sourceRoot":"","sources":["../../../src/sourcemaps/sourcemaps-wizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAC/E,6DAAmC;AACnC,qDAAuC;AACvC,kDAA0B;AAE1B,4CAAwD;AACxD,0CAUwB;AACxB,8DAA+C;AAE/C,sCAAiD;AACjD,+EAA0E;AAC1E,6CAA0E;AAC1E,+DAA+E;AAC/E,6CAAyD;AACzD,2CAAuD;AACvD,mDAA4E;AAC5E,qCAAkE;AAElE,uCAAmD;AACnD,6CAAyD;AAEzD,qDAAqD;AACrD,yDAAyF;AACzF,qDAAyE;AACzE,+BAA2B;AAC3B,+CAAqD;AAE9C,KAAK,UAAU,mBAAmB,CACvC,OAAsB,EACtB,eAAgC;IAEhC,OAAO,IAAA,yBAAa,EAClB;QACE,OAAO,EAAE,OAAO,CAAC,gBAAgB;QACjC,WAAW,EAAE,YAAY;QACzB,aAAa,EAAE,OAAO;KACvB,EACD,GAAG,EAAE,CAAC,gCAAgC,CAAC,OAAO,EAAE,eAAe,CAAC,CACjE,CAAC;AACJ,CAAC;AAZD,kDAYC;AAED,KAAK,UAAU,gCAAgC,CAC7C,OAAsB,EACtB,eAAgC;IAEhC,IAAI,CAAC,eAAe,EAAE;QACpB,IAA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Y,EAAE,IAAI;KACnB,CAAC,CACH,CAAC;IAEF,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,eAAe,CAAC,CAAC;IAEtD,IAAI,CAAC,eAAe,EAAE;QACpB,iBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;KACpC;AACH,CAAC;AAED,KAAK,UAAU,UAAU,CACvB,GAAW,EACX,OAAe,EACf,SAAiB;IAEjB,MAAM,cAAc,GAAG,MAAM,IAAA,yBAAiB,EAAC,qBAAG,CAAC,CAAC;IAEpD,MAAM,cAAc,GAAG,IAAA,uBAAiB,EAAC,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IAEtE,MAAM,KAAK,GAAG,IAAA,yCAAkB,GAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IAEhD,iBAAK,CAAC,KAAK,CAAC,GAAG,eAAK,CAAC,KAAK,CAAC,mCAAmC,CAAC;;KAE5D,eAAK,CAAC,IAAI,CAAC;;kCAEkB,eAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC;QACvD,eAAK,CAAC,IAAI,CACV,GAAG,KAAK,qBAAqB,eAAK,CAAC,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,CACxE;QACC,eAAK,CAAC,IAAI,CACV,GAAG,KAAK,yDAAyD,CAClE;;QAEC,eAAK,CAAC,IAAI,CAAC,GAAG,KAAK,qCAAqC,CAAC;QACzD,eAAK,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,cAAc,EAAE,CAAC;;QAExC,eAAK,CAAC,IAAI,CACV,GAAG,KAAK,yDAAyD,CAClE;IACH,CAAC;KACA,eAAK,CAAC,GAAG,CACT;;;;yDAIoD,CACrD;CACH,CAAC,CAAC;AACH,CAAC","sourcesContent":["// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport * as Sentry from '@sentry/node';\nimport chalk from 'chalk';\n\nimport { traceStep, withTelemetry } from '../telemetry';\nimport {\n abort,\n abortIfCancelled,\n confirmContinueIfNoOrDirtyGitRepo,\n getOrAskForProjectData,\n getPackageManager,\n printWelcome,\n runPrettierIfInstalled,\n SENTRY_CLI_RC_FILE,\n SENTRY_DOT_ENV_FILE,\n} from '../utils/clack';\nimport { NPM } from '../utils/package-manager';\nimport type { WizardOptions } from '../utils/types';\nimport { getIssueStreamUrl } from '../utils/url';\nimport { isUnicodeSupported } from '../utils/vendor/is-unicorn-supported';\nimport { configureAngularSourcemapGenerationFlow } from './tools/angular';\nimport { configureCRASourcemapGenerationFlow } from './tools/create-react-app';\nimport { configureEsbuildPlugin } from './tools/esbuild';\nimport { configureRollupPlugin } from './tools/rollup';\nimport { configureSentryCLI, setupNpmScriptInCI } from './tools/sentry-cli';\nimport { configureTscSourcemapGenerationFlow } from './tools/tsc';\nimport type { SourceMapUploadToolConfigurationOptions } from './tools/types';\nimport { configureVitePlugin } from './tools/vite';\nimport { configureWebPackPlugin } from './tools/webpack';\nimport type { SupportedTools } from './utils/detect-tool';\nimport { detectUsedTool } from './utils/detect-tool';\nimport { checkIfMoreSuitableWizardExistsAndAskForRedirect } from './utils/other-wizards';\nimport { ensureMinimumSdkVersionIsInstalled } from './utils/sdk-version';\nimport { sep } from 'path';\nimport { configureWrangler } from './tools/wrangler';\n\nexport async function runSourcemapsWizard(\n options: WizardOptions,\n preSelectedTool?: SupportedTools,\n): Promise<void> {\n return withTelemetry(\n {\n enabled: options.telemetryEnabled,\n integration: 'sourcemaps',\n wizardOptions: options,\n },\n () => runSourcemapsWizardWithTelemetry(options, preSelectedTool),\n );\n}\n\nasync function runSourcemapsWizardWithTelemetry(\n options: WizardOptions,\n preSelectedTool?: SupportedTools,\n): Promise<void> {\n if (!preSelectedTool) {\n printWelcome({\n wizardName: 'Sentry Source Maps Upload Configuration Wizard',\n message: `This wizard will help you upload source maps to Sentry as part of your build.\nThank you for using Sentry :)${\n options.telemetryEnabled\n ? `\n\n(This setup wizard sends telemetry data and crash reports to Sentry.\nYou can turn this off by running the wizard with the '--disable-telemetry' flag.)`\n : ''\n }`,\n promoCode: options.promoCode,\n });\n }\n\n const moreSuitableWizard = await traceStep(\n 'check-framework-wizard',\n checkIfMoreSuitableWizardExistsAndAskForRedirect,\n );\n if (moreSuitableWizard) {\n await traceStep('run-framework-wizard', () => moreSuitableWizard(options));\n return;\n }\n\n if (!preSelectedTool) {\n await confirmContinueIfNoOrDirtyGitRepo({\n ignoreGitChanges: options.ignoreGitChanges,\n cwd: undefined,\n });\n }\n\n await traceStep('check-sdk-version', ensureMinimumSdkVersionIsInstalled);\n\n const { selfHosted, selectedProject, sentryUrl, authToken } =\n await getOrAskForProjectData(options);\n\n const wizardOptionsWithPreSelectedProject = {\n ...options,\n preSelectedProject: {\n project: selectedProject,\n authToken,\n selfHosted,\n },\n };\n\n const selectedTool =\n preSelectedTool || (await traceStep('select-tool', askForUsedBundlerTool));\n\n Sentry.setTag('selected-tool', selectedTool);\n\n if (selectedTool === 'no-tool') {\n clack.log.info(\n \"No Problem! But in this case, there's nothing to configure :)\",\n );\n await abort('Exiting, have a great day!', 0);\n return;\n }\n\n await traceStep('tool-setup', () =>\n startToolSetupFlow(\n selectedTool,\n {\n orgSlug: selectedProject.organization.slug,\n projectSlug: selectedProject.slug,\n selfHosted,\n url: sentryUrl,\n authToken,\n },\n wizardOptionsWithPreSelectedProject,\n preSelectedTool,\n ),\n );\n\n await traceStep('ci-setup', () =>\n setupCI(selectedTool, authToken, options.comingFrom),\n );\n\n if (!preSelectedTool) {\n // running prettier is only necessary if the source maps wizard is the main flow\n // skip it, if it's called from another wizard (e.g. angular)\n await runPrettierIfInstalled({ cwd: process.cwd() });\n }\n\n if (!preSelectedTool) {\n await traceStep('outro', () =>\n printOutro(\n sentryUrl,\n selectedProject.organization.slug,\n selectedProject.id,\n ),\n );\n }\n}\n\nasync function askForUsedBundlerTool(): Promise<SupportedTools> {\n const selectedTool = await abortIfCancelled(\n clack.select({\n message: 'Which framework, bundler or build tool are you using?',\n options: [\n {\n label: 'Angular',\n value: 'angular',\n hint: 'Select this option if you are using Angular.',\n },\n {\n label: 'Create React App',\n value: 'create-react-app',\n hint: 'Select this option if you set up your app with Create React App.',\n },\n {\n label: 'Cloudflare Wrangler',\n value: 'wrangler',\n hint: \"You're using `wrangler deploy` to build and deploy your Cloudflare Worker.\",\n },\n {\n label: 'Webpack',\n value: 'webpack',\n hint: 'Select this if you are using Webpack and you have access to your Webpack config.',\n },\n {\n label: 'Vite',\n value: 'vite',\n hint: 'Select this if you are using Vite and you have access to your Vite config.',\n },\n {\n label: 'esbuild',\n value: 'esbuild',\n hint: 'Select this if you are using esbuild and you have access to your esbuild config.',\n },\n {\n label: 'Rollup',\n value: 'rollup',\n hint: 'Select this if you are using Rollup and you have access to your Rollup config.',\n },\n {\n label: 'tsc',\n value: 'tsc',\n hint: 'Configure source maps when using tsc as build tool',\n },\n {\n label: 'I use another tool',\n value: 'sentry-cli',\n hint: 'This will configure source maps upload for you using sentry-cli',\n },\n {\n label: \"I don't minify, transpile or bundle my code\",\n value: 'no-tool',\n hint: 'This will exit the wizard',\n },\n ],\n initialValue: await detectUsedTool(),\n }),\n );\n\n return selectedTool;\n}\n\nasync function startToolSetupFlow(\n selectedTool: SupportedTools,\n options: SourceMapUploadToolConfigurationOptions,\n wizardOptions: WizardOptions,\n preSelectedTool?: SupportedTools,\n): Promise<void> {\n switch (selectedTool) {\n case 'webpack':\n await configureWebPackPlugin(options);\n break;\n case 'vite':\n await configureVitePlugin(options);\n break;\n case 'esbuild':\n await configureEsbuildPlugin(options);\n break;\n case 'rollup':\n await configureRollupPlugin(options);\n break;\n case 'tsc':\n await configureSentryCLI(options, configureTscSourcemapGenerationFlow);\n break;\n case 'create-react-app':\n await configureSentryCLI(options, configureCRASourcemapGenerationFlow);\n break;\n case 'wrangler':\n await configureWrangler(options);\n break;\n case 'angular':\n await configureSentryCLI(\n { ...options, defaultArtifactPath: `.${sep}dist` },\n configureAngularSourcemapGenerationFlow,\n preSelectedTool === 'angular',\n );\n break;\n default:\n await configureSentryCLI(options);\n break;\n }\n}\nexport async function setupCI(\n selectedTool: SupportedTools,\n authToken: string,\n comingFrom: WizardOptions['comingFrom'],\n) {\n if (comingFrom === 'vercel') {\n clack.log.info(\n 'Sentry Vercel integration is already configured. Skipping CI setup.',\n );\n Sentry.setTag('using-ci', true);\n } else {\n await traceStep('configure-ci', () => configureCI(selectedTool, authToken));\n }\n}\n\nexport async function configureCI(\n selectedTool: SupportedTools,\n authToken: string,\n): Promise<void> {\n const isUsingCI = await abortIfCancelled(\n clack.select({\n message: `Are you using a CI/CD tool to build and deploy your application?`,\n options: [\n {\n label: 'Yes',\n hint: 'I use a tool like GitHub Actions, GitLab, CircleCI, TravisCI, Jenkins, Vercel, ...',\n value: true,\n },\n {\n label: 'No',\n hint: 'I build and deploy my application manually',\n value: false,\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('using-ci', isUsingCI);\n\n const isCliBasedFlowTool = [\n 'sentry-cli',\n 'tsc',\n 'angular',\n 'create-react-app',\n ].includes(selectedTool);\n\n const authTokenFile = isCliBasedFlowTool\n ? SENTRY_CLI_RC_FILE\n : SENTRY_DOT_ENV_FILE;\n\n if (!isUsingCI) {\n clack.log.info(\n `No Problem! Just make sure that the Sentry auth token from ${chalk.cyan(\n authTokenFile,\n )} is available whenever you build and deploy your app.`,\n );\n return;\n }\n\n if (isCliBasedFlowTool) {\n await traceStep('ci-npm-script-setup', setupNpmScriptInCI);\n }\n\n await traceStep('ci-auth-token-setup', () => setupAuthTokenInCI(authToken));\n}\n\nasync function setupAuthTokenInCI(authToken: string) {\n clack.log.step(\n 'Add the Sentry authentication token as an environment variable to your CI setup:',\n );\n\n // Intentially 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 chalk.greenBright(`\nSENTRY_AUTH_TOKEN=${authToken}\n`),\n );\n\n clack.log.warn(\n chalk.yellow('DO NOT commit this auth token to your repository!'),\n );\n\n const addedEnvVarToCI = await abortIfCancelled(\n clack.select({\n message: 'Did you configure CI as shown above?',\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 the auth token to upload source maps in CI',\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('added-env-var-to-ci', addedEnvVarToCI);\n\n if (!addedEnvVarToCI) {\n clack.log.info(\"Don't forget! :)\");\n }\n}\n\nasync function printOutro(\n url: string,\n orgSlug: string,\n projectId: string,\n): Promise<void> {\n const packageManager = await getPackageManager(NPM);\n\n const issueStreamUrl = getIssueStreamUrl({ url, orgSlug, projectId });\n\n const arrow = isUnicodeSupported() ? '→' : '->';\n\n clack.outro(`${chalk.green(\"That's it - everything is set up!\")}\n\n ${chalk.cyan(`Test and validate your setup locally with the following Steps:\n\n 1. Build your application in ${chalk.bold('production mode')}.\n ${chalk.gray(\n `${arrow} For example, run ${chalk.bold(packageManager.buildCommand)}.`,\n )}\n ${chalk.gray(\n `${arrow} You should see source map upload logs in your console.`,\n )}\n 2. Run your application and throw a test error.\n ${chalk.gray(`${arrow} The error should appear in Sentry:`)}\n ${chalk.gray(`${arrow} ${issueStreamUrl}`)}\n 3. Open the error in Sentry and verify that it's source-mapped.\n ${chalk.gray(\n `${arrow} The stack trace should show your original source code.`,\n )}\n `)}\n ${chalk.dim(\n `If you encounter any issues, please refer to the Troubleshooting Guide:\n https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js\n\n If the guide doesn't help or you encounter a bug, please let us know:\n https://github.com/getsentry/sentry-javascript/issues`,\n )}\n`);\n}\n"]}
@@ -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,Q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,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;KAC5D;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;IAE7C,IAAI,WAAW,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAChD,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;KACzC;IAED,OAAO,gBAAQ,CAAC;AAClB,CAAC;AA3BD,gCA2BC;AAED;;GAEG;AACH,SAAgB,wBAAwB,CAAC,aAAqB;IAC5D,MAAM,kBAAkB,GAAG,aAAa,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAEtE,MAAM,6BAA6B,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QACpE,MAAM,IAAI,GAAG,GAAG;aACb,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;aACxB,MAAM,CAAC,OAAO,CAAC,CAAC;QAEnB,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,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"]}
@@ -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>;
@@ -93,6 +93,12 @@ exports.propertiesCliSetupConfig = {
93
93
  return `defaults.url=${url}`;
94
94
  },
95
95
  };
96
+ /**
97
+ * Aborts the wizard and sets the Sentry transaction status to `cancelled` or `aborted`.
98
+ *
99
+ * @param message The message to display to the user.
100
+ * @param status The status to set on the Sentry transaction. Defaults to `1`.
101
+ */
96
102
  async function abort(message, status) {
97
103
  clack.outro(message ?? 'Wizard setup cancelled.');
98
104
  const sentryHub = Sentry.getCurrentHub();
@@ -240,7 +246,7 @@ exports.confirmContinueIfPackageVersionNotSupported = confirmContinueIfPackageVe
240
246
  * IMPORTANT: This function modifies the `package.json`! Be sure to re-read
241
247
  * it if you make additional modifications to it after calling this function!
242
248
  */
243
- async function installPackage({ packageName, alreadyInstalled, askBeforeUpdating = true, packageNameDisplayLabel, packageManager, forceInstall = false, }) {
249
+ async function installPackage({ packageName, alreadyInstalled, askBeforeUpdating = true, packageNameDisplayLabel, packageManager, forceInstall = false, devDependency = false, }) {
244
250
  return (0, telemetry_1.traceStep)('install-package', async () => {
245
251
  if (alreadyInstalled && askBeforeUpdating) {
246
252
  const shouldUpdatePackage = await abortIfCancelled(clack.confirm({
@@ -257,6 +263,7 @@ async function installPackage({ packageName, alreadyInstalled, askBeforeUpdating
257
263
  await new Promise((resolve, reject) => {
258
264
  const installArgs = [
259
265
  pkgManager.installCommand,
266
+ ...(devDependency ? ['-D'] : []),
260
267
  pkgManager.registry
261
268
  ? `${pkgManager.registry}:${packageName}`
262
269
  : packageName,