@sentry/wizard 3.16.2 → 3.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.16.3
4
+
5
+ - fix(sourcemaps): Re-read package.json when modifying build command #493
6
+
3
7
  ## 3.16.2
4
8
 
5
9
  - fix(sourcemaps): Re-read package.json after CLI install (#489)
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/wizard",
3
- "version": "3.16.2",
3
+ "version": "3.16.3",
4
4
  "homepage": "https://github.com/getsentry/sentry-wizard",
5
5
  "repository": "https://github.com/getsentry/sentry-wizard",
6
6
  "description": "Sentry wizard helping you to configure your project",
@@ -1,5 +1,4 @@
1
1
  import { SourceMapUploadToolConfigurationOptions } from './types';
2
- import { PackageDotJson } from '../../utils/package-json';
3
2
  export declare function configureSentryCLI(options: SourceMapUploadToolConfigurationOptions, configureSourcemapGenerationFlow?: () => Promise<void>): Promise<void>;
4
3
  export declare function setupNpmScriptInCI(): Promise<void>;
5
4
  /**
@@ -9,4 +8,4 @@ export declare function setupNpmScriptInCI(): Promise<void>;
9
8
  *
10
9
  * @param packageDotJson The package.json which will be modified.
11
10
  */
12
- export declare function addSentryCommandToBuildCommand(packageDotJson: PackageDotJson): Promise<void>;
11
+ export declare function addSentryCommandToBuildCommand(): Promise<void>;
@@ -150,7 +150,7 @@ function configureSentryCLI(options, configureSourcemapGenerationFlow) {
150
150
  case 13:
151
151
  if (!_b.sent()) return [3 /*break*/, 15];
152
152
  return [4 /*yield*/, (0, telemetry_1.traceStep)('sentry-cli-add-to-build-cmd', function () {
153
- return addSentryCommandToBuildCommand(packageDotJson);
153
+ return addSentryCommandToBuildCommand();
154
154
  })];
155
155
  case 14:
156
156
  _b.sent();
@@ -255,13 +255,15 @@ function askShouldAddToBuildCommand() {
255
255
  *
256
256
  * @param packageDotJson The package.json which will be modified.
257
257
  */
258
- function addSentryCommandToBuildCommand(packageDotJson) {
258
+ function addSentryCommandToBuildCommand() {
259
259
  var _a;
260
260
  return __awaiter(this, void 0, void 0, function () {
261
- var allNpmScripts, packageManager, buildCommand, isProdBuildCommand, _b, oldCommand;
261
+ var packageDotJson, allNpmScripts, packageManager, buildCommand, isProdBuildCommand, _b, oldCommand;
262
262
  return __generator(this, function (_c) {
263
263
  switch (_c.label) {
264
- case 0:
264
+ case 0: return [4 /*yield*/, (0, clack_utils_1.getPackageDotJson)()];
265
+ case 1:
266
+ packageDotJson = _c.sent();
265
267
  // This usually shouldn't happen because earlier we added the
266
268
  // SENTRY_NPM_SCRIPT_NAME script but just to be sure
267
269
  packageDotJson.scripts = packageDotJson.scripts || {};
@@ -271,16 +273,16 @@ function addSentryCommandToBuildCommand(packageDotJson) {
271
273
  ? 'build'
272
274
  : allNpmScripts.find(function (s) { return s.toLocaleLowerCase().includes('build'); });
273
275
  _b = !!buildCommand;
274
- if (!_b) return [3 /*break*/, 2];
276
+ if (!_b) return [3 /*break*/, 3];
275
277
  return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.confirm({
276
278
  message: "Is ".concat(chalk_1.default.cyan("".concat(packageManager.runScriptCommand, " ").concat(buildCommand)), " your production build command?"),
277
279
  }))];
278
- case 1:
279
- _b = (_c.sent());
280
- _c.label = 2;
281
280
  case 2:
281
+ _b = (_c.sent());
282
+ _c.label = 3;
283
+ case 3:
282
284
  isProdBuildCommand = _b;
283
- if (!(allNpmScripts.length && (!buildCommand || !isProdBuildCommand))) return [3 /*break*/, 4];
285
+ if (!(allNpmScripts.length && (!buildCommand || !isProdBuildCommand))) return [3 /*break*/, 5];
284
286
  return [4 /*yield*/, (0, clack_utils_1.abortIfCancelled)(clack.select({
285
287
  message: "Which ".concat(packageManager.name, " command in your ").concat(chalk_1.default.cyan('package.json'), " builds your application for production?"),
286
288
  options: allNpmScripts
@@ -290,10 +292,10 @@ function addSentryCommandToBuildCommand(packageDotJson) {
290
292
  }); })
291
293
  .concat({ label: 'None of the above', value: 'none' }),
292
294
  }))];
293
- case 3:
294
- buildCommand = _c.sent();
295
- _c.label = 4;
296
295
  case 4:
296
+ buildCommand = _c.sent();
297
+ _c.label = 5;
298
+ case 5:
297
299
  if (!buildCommand || buildCommand === 'none') {
298
300
  clack.log.warn("We can only add the ".concat(chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME), " script to another `script` in your ").concat(chalk_1.default.cyan('package.json'), ".\nPlease add it manually to your prod build command."));
299
301
  return [2 /*return*/];
@@ -306,7 +308,7 @@ function addSentryCommandToBuildCommand(packageDotJson) {
306
308
  }
307
309
  packageDotJson.scripts[buildCommand] = "".concat(oldCommand, " && ").concat(packageManager.runScriptCommand, " ").concat(SENTRY_NPM_SCRIPT_NAME);
308
310
  return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), 'package.json'), JSON.stringify(packageDotJson, null, 2))];
309
- case 5:
311
+ case 6:
310
312
  _c.sent();
311
313
  addedToBuildCommand = true;
312
314
  clack.log.info("Added ".concat(chalk_1.default.cyan(SENTRY_NPM_SCRIPT_NAME), " script to your ").concat(chalk_1.default.cyan(buildCommand), " command."));
@@ -1 +1 @@
1
- {"version":3,"file":"sentry-cli.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/sentry-cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAC1B,mDAAuC;AACvC,yCAA6B;AAC7B,qCAAyB;AACzB,uDAKiC;AAGjC,yDAA+E;AAC/E,6CAA4C;AAC5C,+DAAuE;AAEvE,IAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEnD,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC,SAAsB,kBAAkB,CACtC,OAAgD,EAChD,gCAA+F;IAA/F,iDAAA,EAA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CAA2C;wBAC3C,KAAK,CAAC,GAAG,CAAC,IAAI,CACZ,WAAK,YAAY,2DAAyD,CAC3E,CAAC;wBACF,sBAAO;qBACR;oBAED,cAAc,CAAC,OAAO,CACpB,YAAY,CACb,GAAG,UAAG,UAAU,iBAAO,cAAc,CAAC,gBAAgB,cAAI,sBAAsB,CAAE,CAAC;oBAEpF,qBAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,EACxC,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CACxC,EAAA;;oBAHD,SAGC,CAAC;oBAEF,mBAAmB,GAAG,IAAI,CAAC;oBAE3B,KAAK,CAAC,GAAG,CAAC,IAAI,CACZ,gBAAS,eAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,6BAAmB,eAAK,CAAC,IAAI,CACtE,YAAY,CACb,cAAW,CACb,CAAC;;;;;CACH;AAlFD,wEAkFC;AAED,SAAe,uCAAuC;;;;wBACpD,qBAAM,IAAA,8BAAgB,EACpB,KAAK,CAAC,MAAM,CAAC;wBACX,OAAO,EAAE,iEAA0D,eAAK,CAAC,GAAG,CAC1E,uEAAuE,CACxE,CAAE;wBACH,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;wBACzD,YAAY,EAAE,IAAI;qBACnB,CAAC,CACH,EAAA;;oBARD,SAQC,CAAC;;;;;CACH","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as Sentry from '@sentry/node';\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport {\n abortIfCancelled,\n addSentryCliConfig,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack-utils';\n\nimport { SourceMapUploadToolConfigurationOptions } from './types';\nimport { hasPackageInstalled, PackageDotJson } from '../../utils/package-json';\nimport { traceStep } from '../../telemetry';\nimport { detectPackageManger, NPM } from '../../utils/package-manager';\n\nconst SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';\n\nlet addedToBuildCommand = false;\n\nexport async function configureSentryCLI(\n options: SourceMapUploadToolConfigurationOptions,\n configureSourcemapGenerationFlow: () => Promise<void> = defaultConfigureSourcemapGenerationFlow,\n): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n\n await installPackage({\n packageName: '@sentry/cli',\n alreadyInstalled: hasPackageInstalled('@sentry/cli', packageDotJson),\n });\n\n let validPath = false;\n let relativeArtifactPath;\n do {\n const rawArtifactPath = await abortIfCancelled(\n clack.text({\n message: 'Where are your build artifacts located?',\n placeholder: `.${path.sep}out`,\n validate(value) {\n if (!value) {\n return 'Please enter a path.';\n }\n },\n }),\n );\n\n if (path.isAbsolute(rawArtifactPath)) {\n relativeArtifactPath = path.relative(process.cwd(), rawArtifactPath);\n } else {\n relativeArtifactPath = rawArtifactPath;\n }\n\n try {\n await fs.promises.access(path.join(process.cwd(), relativeArtifactPath));\n validPath = true;\n } catch {\n validPath = await abortIfCancelled(\n clack.select({\n message: `We couldn't find artifacts at ${relativeArtifactPath}. Are you sure that this is the location that contains your build artifacts?`,\n options: [\n {\n label: 'No, let me verify.',\n value: false,\n },\n { label: 'Yes, I am sure!', value: true },\n ],\n initialValue: false,\n }),\n );\n }\n } while (!validPath);\n\n const relativePosixArtifactPath = relativeArtifactPath\n .split(path.sep)\n .join(path.posix.sep);\n\n await configureSourcemapGenerationFlow();\n\n await createAndAddNpmScript(options, relativePosixArtifactPath);\n\n if (await askShouldAddToBuildCommand()) {\n await traceStep('sentry-cli-add-to-build-cmd', () =>\n addSentryCommandToBuildCommand(packageDotJson),\n );\n } else {\n clack.log.info(\n `No problem, just make sure to run this script ${chalk.bold(\n 'after',\n )} building your application but ${chalk.bold('before')} deploying!`,\n );\n }\n\n await addSentryCliConfig({ authToken: options.authToken });\n}\n\nexport async function setupNpmScriptInCI(): Promise<void> {\n if (addedToBuildCommand) {\n // No need to tell users to add it manually to their CI\n // if the script is already added to the build command\n return;\n }\n\n const addedToCI = await abortIfCancelled(\n clack.select({\n message: `Add a step to your CI pipeline that runs the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script ${chalk.bold('right after')} building your application.`,\n options: [\n { label: 'I did, continue!', value: true },\n {\n label: \"I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `You need to run ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} after each build for source maps to work properly.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('added-ci-script', addedToCI);\n\n if (!addedToCI) {\n clack.log.info(\"Don't forget! :)\");\n }\n}\n\nasync function createAndAddNpmScript(\n options: SourceMapUploadToolConfigurationOptions,\n relativePosixArtifactPath: string,\n): Promise<void> {\n const sentryCliNpmScript = `sentry-cli sourcemaps inject --org ${\n options.orgSlug\n } --project ${\n options.projectSlug\n } ${relativePosixArtifactPath} && sentry-cli${\n options.selfHosted ? ` --url ${options.url}` : ''\n } sourcemaps upload --org ${options.orgSlug} --project ${\n options.projectSlug\n } ${relativePosixArtifactPath}`;\n\n const packageDotJson = await getPackageDotJson();\n\n packageDotJson.scripts = packageDotJson.scripts || {};\n packageDotJson.scripts[SENTRY_NPM_SCRIPT_NAME] = sentryCliNpmScript;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n clack.log.info(\n `Added a ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n 'package.json',\n )}.`,\n );\n}\n\nasync function askShouldAddToBuildCommand(): Promise<boolean> {\n const shouldAddToBuildCommand = await abortIfCancelled(\n clack.select({\n message: `Do you want to automatically run the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script after each production build?`,\n options: [\n {\n label: 'Yes',\n value: true,\n hint: 'This will modify your prod build command',\n },\n { label: 'No', value: false },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('modify-build-command', shouldAddToBuildCommand);\n\n return shouldAddToBuildCommand;\n}\n\n/**\n * Add the sentry:sourcemaps command to the prod build command in the package.json\n * - Detect the user's build command\n * - Append the sentry:sourcemaps command to it\n *\n * @param packageDotJson The package.json which will be modified.\n */\nexport async function addSentryCommandToBuildCommand(\n packageDotJson: PackageDotJson,\n): Promise<void> {\n // This usually shouldn't happen because earlier we added the\n // SENTRY_NPM_SCRIPT_NAME script but just to be sure\n packageDotJson.scripts = packageDotJson.scripts || {};\n\n const allNpmScripts = Object.keys(packageDotJson.scripts).filter(\n (s) => s !== SENTRY_NPM_SCRIPT_NAME,\n );\n\n const packageManager = detectPackageManger() ?? NPM;\n\n // Heuristic to pre-select the build command:\n // Often, 'build' is the prod build command, so we favour it.\n // If it's not there, commands that include 'build' might be the prod build command.\n let buildCommand =\n typeof packageDotJson.scripts.build === 'string'\n ? 'build'\n : allNpmScripts.find((s) => s.toLocaleLowerCase().includes('build'));\n\n const isProdBuildCommand =\n !!buildCommand &&\n (await abortIfCancelled(\n clack.confirm({\n message: `Is ${chalk.cyan(\n `${packageManager.runScriptCommand} ${buildCommand}`,\n )} your production build command?`,\n }),\n ));\n\n if (allNpmScripts.length && (!buildCommand || !isProdBuildCommand)) {\n buildCommand = await abortIfCancelled(\n clack.select({\n message: `Which ${packageManager.name} command in your ${chalk.cyan(\n 'package.json',\n )} builds your application for production?`,\n options: allNpmScripts\n .map((script) => ({\n label: script,\n value: script,\n }))\n .concat({ label: 'None of the above', value: 'none' }),\n }),\n );\n }\n\n if (!buildCommand || buildCommand === 'none') {\n clack.log.warn(\n `We can only add the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script to another \\`script\\` in your ${chalk.cyan('package.json')}.\nPlease add it manually to your prod build command.`,\n );\n return;\n }\n\n const oldCommand = packageDotJson.scripts[buildCommand];\n if (!oldCommand) {\n // very unlikely to happen but nevertheless\n clack.log.warn(\n `\\`${buildCommand}\\` doesn't seem to be part of your package.json scripts`,\n );\n return;\n }\n\n packageDotJson.scripts[\n buildCommand\n ] = `${oldCommand} && ${packageManager.runScriptCommand} ${SENTRY_NPM_SCRIPT_NAME}`;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n addedToBuildCommand = true;\n\n clack.log.info(\n `Added ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n buildCommand,\n )} command.`,\n );\n}\n\nasync function defaultConfigureSourcemapGenerationFlow(): Promise<void> {\n await abortIfCancelled(\n clack.select({\n message: `Verify that your build tool is generating source maps. ${chalk.dim(\n '(Your build output folder should contain .js.map files after a build)',\n )}`,\n options: [{ label: 'I checked. Continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n"]}
1
+ {"version":3,"file":"sentry-cli.js","sourceRoot":"","sources":["../../../../src/sourcemaps/tools/sentry-cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAyE;AACzE,oDAAwC;AACxC,gDAA0B;AAC1B,mDAAuC;AACvC,yCAA6B;AAC7B,qCAAyB;AACzB,uDAKiC;AAGjC,yDAA+D;AAC/D,6CAA4C;AAC5C,+DAAuE;AAEvE,IAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEnD,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC,SAAsB,kBAAkB,CACtC,OAAgD,EAChD,gCAA+F;IAA/F,iDAAA,EAAA,0EAA+F;;;;;wBAExE,qBAAM,IAAA,+BAAiB,GAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAEhD,qBAAM,IAAA,4BAAc,EAAC;4BACnB,WAAW,EAAE,aAAa;4BAC1B,gBAAgB,EAAE,IAAA,kCAAmB,EAAC,aAAa,EAAE,cAAc,CAAC;yBAC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c,CAAC,gBAAgB,cAAI,sBAAsB,CAAE,CAAC;oBAEpF,qBAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,EACxC,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CACxC,EAAA;;oBAHD,SAGC,CAAC;oBAEF,mBAAmB,GAAG,IAAI,CAAC;oBAE3B,KAAK,CAAC,GAAG,CAAC,IAAI,CACZ,gBAAS,eAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,6BAAmB,eAAK,CAAC,IAAI,CACtE,YAAY,CACb,cAAW,CACb,CAAC;;;;;CACH;AAjFD,wEAiFC;AAED,SAAe,uCAAuC;;;;wBACpD,qBAAM,IAAA,8BAAgB,EACpB,KAAK,CAAC,MAAM,CAAC;wBACX,OAAO,EAAE,iEAA0D,eAAK,CAAC,GAAG,CAC1E,uEAAuE,CACxE,CAAE;wBACH,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;wBACzD,YAAY,EAAE,IAAI;qBACnB,CAAC,CACH,EAAA;;oBARD,SAQC,CAAC;;;;;CACH","sourcesContent":["// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport * as clack from '@clack/prompts';\nimport chalk from 'chalk';\nimport * as Sentry from '@sentry/node';\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport {\n abortIfCancelled,\n addSentryCliConfig,\n getPackageDotJson,\n installPackage,\n} from '../../utils/clack-utils';\n\nimport { SourceMapUploadToolConfigurationOptions } from './types';\nimport { hasPackageInstalled } from '../../utils/package-json';\nimport { traceStep } from '../../telemetry';\nimport { detectPackageManger, NPM } from '../../utils/package-manager';\n\nconst SENTRY_NPM_SCRIPT_NAME = 'sentry:sourcemaps';\n\nlet addedToBuildCommand = false;\n\nexport async function configureSentryCLI(\n options: SourceMapUploadToolConfigurationOptions,\n configureSourcemapGenerationFlow: () => Promise<void> = defaultConfigureSourcemapGenerationFlow,\n): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n\n await installPackage({\n packageName: '@sentry/cli',\n alreadyInstalled: hasPackageInstalled('@sentry/cli', packageDotJson),\n });\n\n let validPath = false;\n let relativeArtifactPath;\n do {\n const rawArtifactPath = await abortIfCancelled(\n clack.text({\n message: 'Where are your build artifacts located?',\n placeholder: `.${path.sep}out`,\n validate(value) {\n if (!value) {\n return 'Please enter a path.';\n }\n },\n }),\n );\n\n if (path.isAbsolute(rawArtifactPath)) {\n relativeArtifactPath = path.relative(process.cwd(), rawArtifactPath);\n } else {\n relativeArtifactPath = rawArtifactPath;\n }\n\n try {\n await fs.promises.access(path.join(process.cwd(), relativeArtifactPath));\n validPath = true;\n } catch {\n validPath = await abortIfCancelled(\n clack.select({\n message: `We couldn't find artifacts at ${relativeArtifactPath}. Are you sure that this is the location that contains your build artifacts?`,\n options: [\n {\n label: 'No, let me verify.',\n value: false,\n },\n { label: 'Yes, I am sure!', value: true },\n ],\n initialValue: false,\n }),\n );\n }\n } while (!validPath);\n\n const relativePosixArtifactPath = relativeArtifactPath\n .split(path.sep)\n .join(path.posix.sep);\n\n await configureSourcemapGenerationFlow();\n\n await createAndAddNpmScript(options, relativePosixArtifactPath);\n\n if (await askShouldAddToBuildCommand()) {\n await traceStep('sentry-cli-add-to-build-cmd', () =>\n addSentryCommandToBuildCommand(),\n );\n } else {\n clack.log.info(\n `No problem, just make sure to run this script ${chalk.bold(\n 'after',\n )} building your application but ${chalk.bold('before')} deploying!`,\n );\n }\n\n await addSentryCliConfig({ authToken: options.authToken });\n}\n\nexport async function setupNpmScriptInCI(): Promise<void> {\n if (addedToBuildCommand) {\n // No need to tell users to add it manually to their CI\n // if the script is already added to the build command\n return;\n }\n\n const addedToCI = await abortIfCancelled(\n clack.select({\n message: `Add a step to your CI pipeline that runs the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script ${chalk.bold('right after')} building your application.`,\n options: [\n { label: 'I did, continue!', value: true },\n {\n label: \"I'll do it later...\",\n value: false,\n hint: chalk.yellow(\n `You need to run ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} after each build for source maps to work properly.`,\n ),\n },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('added-ci-script', addedToCI);\n\n if (!addedToCI) {\n clack.log.info(\"Don't forget! :)\");\n }\n}\n\nasync function createAndAddNpmScript(\n options: SourceMapUploadToolConfigurationOptions,\n relativePosixArtifactPath: string,\n): Promise<void> {\n const sentryCliNpmScript = `sentry-cli sourcemaps inject --org ${\n options.orgSlug\n } --project ${\n options.projectSlug\n } ${relativePosixArtifactPath} && sentry-cli${\n options.selfHosted ? ` --url ${options.url}` : ''\n } sourcemaps upload --org ${options.orgSlug} --project ${\n options.projectSlug\n } ${relativePosixArtifactPath}`;\n\n const packageDotJson = await getPackageDotJson();\n\n packageDotJson.scripts = packageDotJson.scripts || {};\n packageDotJson.scripts[SENTRY_NPM_SCRIPT_NAME] = sentryCliNpmScript;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n clack.log.info(\n `Added a ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n 'package.json',\n )}.`,\n );\n}\n\nasync function askShouldAddToBuildCommand(): Promise<boolean> {\n const shouldAddToBuildCommand = await abortIfCancelled(\n clack.select({\n message: `Do you want to automatically run the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script after each production build?`,\n options: [\n {\n label: 'Yes',\n value: true,\n hint: 'This will modify your prod build command',\n },\n { label: 'No', value: false },\n ],\n initialValue: true,\n }),\n );\n\n Sentry.setTag('modify-build-command', shouldAddToBuildCommand);\n\n return shouldAddToBuildCommand;\n}\n\n/**\n * Add the sentry:sourcemaps command to the prod build command in the package.json\n * - Detect the user's build command\n * - Append the sentry:sourcemaps command to it\n *\n * @param packageDotJson The package.json which will be modified.\n */\nexport async function addSentryCommandToBuildCommand(): Promise<void> {\n const packageDotJson = await getPackageDotJson();\n // This usually shouldn't happen because earlier we added the\n // SENTRY_NPM_SCRIPT_NAME script but just to be sure\n packageDotJson.scripts = packageDotJson.scripts || {};\n\n const allNpmScripts = Object.keys(packageDotJson.scripts).filter(\n (s) => s !== SENTRY_NPM_SCRIPT_NAME,\n );\n\n const packageManager = detectPackageManger() ?? NPM;\n\n // Heuristic to pre-select the build command:\n // Often, 'build' is the prod build command, so we favour it.\n // If it's not there, commands that include 'build' might be the prod build command.\n let buildCommand =\n typeof packageDotJson.scripts.build === 'string'\n ? 'build'\n : allNpmScripts.find((s) => s.toLocaleLowerCase().includes('build'));\n\n const isProdBuildCommand =\n !!buildCommand &&\n (await abortIfCancelled(\n clack.confirm({\n message: `Is ${chalk.cyan(\n `${packageManager.runScriptCommand} ${buildCommand}`,\n )} your production build command?`,\n }),\n ));\n\n if (allNpmScripts.length && (!buildCommand || !isProdBuildCommand)) {\n buildCommand = await abortIfCancelled(\n clack.select({\n message: `Which ${packageManager.name} command in your ${chalk.cyan(\n 'package.json',\n )} builds your application for production?`,\n options: allNpmScripts\n .map((script) => ({\n label: script,\n value: script,\n }))\n .concat({ label: 'None of the above', value: 'none' }),\n }),\n );\n }\n\n if (!buildCommand || buildCommand === 'none') {\n clack.log.warn(\n `We can only add the ${chalk.cyan(\n SENTRY_NPM_SCRIPT_NAME,\n )} script to another \\`script\\` in your ${chalk.cyan('package.json')}.\nPlease add it manually to your prod build command.`,\n );\n return;\n }\n\n const oldCommand = packageDotJson.scripts[buildCommand];\n if (!oldCommand) {\n // very unlikely to happen but nevertheless\n clack.log.warn(\n `\\`${buildCommand}\\` doesn't seem to be part of your package.json scripts`,\n );\n return;\n }\n\n packageDotJson.scripts[\n buildCommand\n ] = `${oldCommand} && ${packageManager.runScriptCommand} ${SENTRY_NPM_SCRIPT_NAME}`;\n\n await fs.promises.writeFile(\n path.join(process.cwd(), 'package.json'),\n JSON.stringify(packageDotJson, null, 2),\n );\n\n addedToBuildCommand = true;\n\n clack.log.info(\n `Added ${chalk.cyan(SENTRY_NPM_SCRIPT_NAME)} script to your ${chalk.cyan(\n buildCommand,\n )} command.`,\n );\n}\n\nasync function defaultConfigureSourcemapGenerationFlow(): Promise<void> {\n await abortIfCancelled(\n clack.select({\n message: `Verify that your build tool is generating source maps. ${chalk.dim(\n '(Your build output folder should contain .js.map files after a build)',\n )}`,\n options: [{ label: 'I checked. Continue!', value: true }],\n initialValue: true,\n }),\n );\n}\n"]}
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
14
  if (k2 === undefined) k2 = k;
4
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -75,6 +86,13 @@ jest.mock('@clack/prompts', function () {
75
86
  isCancel: jest.fn().mockReturnValue(false),
76
87
  };
77
88
  });
89
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
90
+ jest.mock('../../../src/utils/clack-utils', function () { return (__assign(__assign({}, jest.requireActual('../../../src/utils/clack-utils')), { getPackageDotJson: jest.fn().mockResolvedValue({
91
+ scripts: {
92
+ build: 'tsc',
93
+ },
94
+ version: '1.0.0',
95
+ }) })); });
78
96
  describe('addSentryCommandToBuildCommand', function () {
79
97
  afterEach(function () {
80
98
  jest.clearAllMocks();
@@ -87,20 +105,13 @@ describe('addSentryCommandToBuildCommand', function () {
87
105
  packageManagerHelpers.BUN,
88
106
  ],
89
107
  ])('adds the cli command to the script command (%s)', function (_, pacMan) { return __awaiter(void 0, void 0, void 0, function () {
90
- var packageJson;
91
108
  return __generator(this, function (_a) {
92
109
  switch (_a.label) {
93
110
  case 0:
94
111
  jest
95
112
  .spyOn(packageManagerHelpers, 'detectPackageManger')
96
113
  .mockReturnValue(pacMan);
97
- packageJson = {
98
- scripts: {
99
- build: 'tsc',
100
- },
101
- version: '1.0.0',
102
- };
103
- return [4 /*yield*/, (0, sentry_cli_1.addSentryCommandToBuildCommand)(packageJson)];
114
+ return [4 /*yield*/, (0, sentry_cli_1.addSentryCommandToBuildCommand)()];
104
115
  case 1:
105
116
  _a.sent();
106
117
  expect(writeFileSpy).toHaveBeenCalledWith(expect.stringContaining('package.json'), expect.stringContaining("tsc && ".concat(pacMan.runScriptCommand, " sentry:sourcemaps")));
@@ -1 +1 @@
1
- {"version":3,"file":"sentry-cli.test.js","sourceRoot":"","sources":["../../../../test/sourcemaps/tools/sentry-cli.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AAEzB,uEAA0F;AAE1F,wFAA4E;AAE5E,IAAM,YAAY,GAAG,IAAI;KACtB,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;KAC/B,kBAAkB,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,EAAE,EAAjB,CAAiB,CAAC,CAAC;AAE/C,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;IAC1B,OAAO;QACL,GAAG,EAAE;YACH,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;YACf,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;SACnB;QACD,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC;QAC1C,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC;KAC3C,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,gCAAgC,EAAE;IACzC,SAAS,CAAC;QACR,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,IAAI,CAAC;QACN;YACE,qBAAqB,CAAC,GAAG;YACzB,qBAAqB,CAAC,IAAI;YAC1B,qBAAqB,CAAC,IAAI;YAC1B,qBAAqB,CAAC,GAAG;SAC1B;KACF,CAAC,CAAC,iDAAiD,EAAE,UAAO,CAAC,EAAE,MAAM;;;;;oBACpE,IAAI;yBACD,KAAK,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;yBACnD,eAAe,CAAC,MAAM,CAAC,CAAC;oBACrB,WAAW,GAAG;wBAClB,OAAO,EAAE;4BACP,KAAK,EAAE,KAAK;yBACb;wBACD,OAAO,EAAE,OAAO;qBACjB,CAAC;oBACF,qBAAM,IAAA,2CAA8B,EAAC,WAAW,CAAC,EAAA;;oBAAjD,SAAiD,CAAC;oBAClD,MAAM,CAAC,YAAY,CAAC,CAAC,oBAAoB,CACvC,MAAM,CAAC,gBAAgB,CAAC,cAAc,CAAC,EACvC,MAAM,CAAC,gBAAgB,CACrB,iBAAU,MAAM,CAAC,gBAAgB,uBAAoB,CACtD,CACF,CAAC;;;;SACH,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as fs from 'fs';\n\nimport { addSentryCommandToBuildCommand } from '../../../src/sourcemaps/tools/sentry-cli';\n\nimport * as packageManagerHelpers from '../../../src/utils/package-manager';\n\nconst writeFileSpy = jest\n .spyOn(fs.promises, 'writeFile')\n .mockImplementation(() => Promise.resolve());\n\njest.mock('@clack/prompts', () => {\n return {\n log: {\n info: jest.fn(),\n success: jest.fn(),\n },\n confirm: jest.fn().mockResolvedValue(true),\n isCancel: jest.fn().mockReturnValue(false),\n };\n});\n\ndescribe('addSentryCommandToBuildCommand', () => {\n afterEach(() => {\n jest.clearAllMocks();\n });\n it.each([\n [\n packageManagerHelpers.NPM,\n packageManagerHelpers.PNPM,\n packageManagerHelpers.YARN,\n packageManagerHelpers.BUN,\n ],\n ])('adds the cli command to the script command (%s)', async (_, pacMan) => {\n jest\n .spyOn(packageManagerHelpers, 'detectPackageManger')\n .mockReturnValue(pacMan);\n const packageJson = {\n scripts: {\n build: 'tsc',\n },\n version: '1.0.0',\n };\n await addSentryCommandToBuildCommand(packageJson);\n expect(writeFileSpy).toHaveBeenCalledWith(\n expect.stringContaining('package.json'),\n expect.stringContaining(\n `tsc && ${pacMan.runScriptCommand} sentry:sourcemaps`,\n ),\n );\n });\n});\n"]}
1
+ {"version":3,"file":"sentry-cli.test.js","sourceRoot":"","sources":["../../../../test/sourcemaps/tools/sentry-cli.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AAEzB,uEAA0F;AAE1F,wFAA4E;AAE5E,IAAM,YAAY,GAAG,IAAI;KACtB,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;KAC/B,kBAAkB,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,EAAE,EAAjB,CAAiB,CAAC,CAAC;AAE/C,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;IAC1B,OAAO;QACL,GAAG,EAAE;YACH,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;YACf,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;SACnB;QACD,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC;QAC1C,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC;KAC3C,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,+DAA+D;AAC/D,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE,cAAM,OAAA,uBAC7C,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,KACvD,iBAAiB,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;QAC7C,OAAO,EAAE;YACP,KAAK,EAAE,KAAK;SACb;QACD,OAAO,EAAE,OAAO;KACjB,CAAC,IACF,EARgD,CAQhD,CAAC,CAAC;AAEJ,QAAQ,CAAC,gCAAgC,EAAE;IACzC,SAAS,CAAC;QACR,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,IAAI,CAAC;QACN;YACE,qBAAqB,CAAC,GAAG;YACzB,qBAAqB,CAAC,IAAI;YAC1B,qBAAqB,CAAC,IAAI;YAC1B,qBAAqB,CAAC,GAAG;SAC1B;KACF,CAAC,CAAC,iDAAiD,EAAE,UAAO,CAAC,EAAE,MAAM;;;;oBACpE,IAAI;yBACD,KAAK,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;yBACnD,eAAe,CAAC,MAAM,CAAC,CAAC;oBAC3B,qBAAM,IAAA,2CAA8B,GAAE,EAAA;;oBAAtC,SAAsC,CAAC;oBACvC,MAAM,CAAC,YAAY,CAAC,CAAC,oBAAoB,CACvC,MAAM,CAAC,gBAAgB,CAAC,cAAc,CAAC,EACvC,MAAM,CAAC,gBAAgB,CACrB,iBAAU,MAAM,CAAC,gBAAgB,uBAAoB,CACtD,CACF,CAAC;;;;SACH,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as fs from 'fs';\n\nimport { addSentryCommandToBuildCommand } from '../../../src/sourcemaps/tools/sentry-cli';\n\nimport * as packageManagerHelpers from '../../../src/utils/package-manager';\n\nconst writeFileSpy = jest\n .spyOn(fs.promises, 'writeFile')\n .mockImplementation(() => Promise.resolve());\n\njest.mock('@clack/prompts', () => {\n return {\n log: {\n info: jest.fn(),\n success: jest.fn(),\n },\n confirm: jest.fn().mockResolvedValue(true),\n isCancel: jest.fn().mockReturnValue(false),\n };\n});\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-return\njest.mock('../../../src/utils/clack-utils', () => ({\n ...jest.requireActual('../../../src/utils/clack-utils'),\n getPackageDotJson: jest.fn().mockResolvedValue({\n scripts: {\n build: 'tsc',\n },\n version: '1.0.0',\n }),\n}));\n\ndescribe('addSentryCommandToBuildCommand', () => {\n afterEach(() => {\n jest.clearAllMocks();\n });\n it.each([\n [\n packageManagerHelpers.NPM,\n packageManagerHelpers.PNPM,\n packageManagerHelpers.YARN,\n packageManagerHelpers.BUN,\n ],\n ])('adds the cli command to the script command (%s)', async (_, pacMan) => {\n jest\n .spyOn(packageManagerHelpers, 'detectPackageManger')\n .mockReturnValue(pacMan);\n await addSentryCommandToBuildCommand();\n expect(writeFileSpy).toHaveBeenCalledWith(\n expect.stringContaining('package.json'),\n expect.stringContaining(\n `tsc && ${pacMan.runScriptCommand} sentry:sourcemaps`,\n ),\n );\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/wizard",
3
- "version": "3.16.2",
3
+ "version": "3.16.3",
4
4
  "homepage": "https://github.com/getsentry/sentry-wizard",
5
5
  "repository": "https://github.com/getsentry/sentry-wizard",
6
6
  "description": "Sentry wizard helping you to configure your project",
@@ -12,7 +12,7 @@ import {
12
12
  } from '../../utils/clack-utils';
13
13
 
14
14
  import { SourceMapUploadToolConfigurationOptions } from './types';
15
- import { hasPackageInstalled, PackageDotJson } from '../../utils/package-json';
15
+ import { hasPackageInstalled } from '../../utils/package-json';
16
16
  import { traceStep } from '../../telemetry';
17
17
  import { detectPackageManger, NPM } from '../../utils/package-manager';
18
18
 
@@ -82,7 +82,7 @@ export async function configureSentryCLI(
82
82
 
83
83
  if (await askShouldAddToBuildCommand()) {
84
84
  await traceStep('sentry-cli-add-to-build-cmd', () =>
85
- addSentryCommandToBuildCommand(packageDotJson),
85
+ addSentryCommandToBuildCommand(),
86
86
  );
87
87
  } else {
88
88
  clack.log.info(
@@ -191,9 +191,8 @@ async function askShouldAddToBuildCommand(): Promise<boolean> {
191
191
  *
192
192
  * @param packageDotJson The package.json which will be modified.
193
193
  */
194
- export async function addSentryCommandToBuildCommand(
195
- packageDotJson: PackageDotJson,
196
- ): Promise<void> {
194
+ export async function addSentryCommandToBuildCommand(): Promise<void> {
195
+ const packageDotJson = await getPackageDotJson();
197
196
  // This usually shouldn't happen because earlier we added the
198
197
  // SENTRY_NPM_SCRIPT_NAME script but just to be sure
199
198
  packageDotJson.scripts = packageDotJson.scripts || {};
@@ -19,6 +19,17 @@ jest.mock('@clack/prompts', () => {
19
19
  };
20
20
  });
21
21
 
22
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
23
+ jest.mock('../../../src/utils/clack-utils', () => ({
24
+ ...jest.requireActual('../../../src/utils/clack-utils'),
25
+ getPackageDotJson: jest.fn().mockResolvedValue({
26
+ scripts: {
27
+ build: 'tsc',
28
+ },
29
+ version: '1.0.0',
30
+ }),
31
+ }));
32
+
22
33
  describe('addSentryCommandToBuildCommand', () => {
23
34
  afterEach(() => {
24
35
  jest.clearAllMocks();
@@ -34,13 +45,7 @@ describe('addSentryCommandToBuildCommand', () => {
34
45
  jest
35
46
  .spyOn(packageManagerHelpers, 'detectPackageManger')
36
47
  .mockReturnValue(pacMan);
37
- const packageJson = {
38
- scripts: {
39
- build: 'tsc',
40
- },
41
- version: '1.0.0',
42
- };
43
- await addSentryCommandToBuildCommand(packageJson);
48
+ await addSentryCommandToBuildCommand();
44
49
  expect(writeFileSpy).toHaveBeenCalledWith(
45
50
  expect.stringContaining('package.json'),
46
51
  expect.stringContaining(