|
2 | 2 | import { getSentryRelease } from '@sentry/node';
|
3 | 3 | import { dropUndefinedKeys, escapeStringForRegex, logger } from '@sentry/utils';
|
4 | 4 | import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin';
|
| 5 | +import * as chalk from 'chalk'; |
5 | 6 | import * as fs from 'fs';
|
6 | 7 | import * as path from 'path';
|
7 | 8 |
|
@@ -138,9 +139,14 @@ export function constructWebpackConfigFunction(
|
138 | 139 | // TODO Handle possibility that user is using `SourceMapDevToolPlugin` (see
|
139 | 140 | // https://webpack.js.org/plugins/source-map-dev-tool-plugin/)
|
140 | 141 |
|
| 142 | + // TODO (v9 or v10, maybe): Remove this |
| 143 | + handleSourcemapHidingOptionWarning(userSentryOptions, isServer); |
| 144 | + |
141 | 145 | // Next doesn't let you change `devtool` in dev even if you want to, so don't bother trying - see
|
142 | 146 | // https://github.com/vercel/next.js/blob/master/errors/improper-devtool.md
|
143 | 147 | if (!isDev) {
|
| 148 | + // TODO (v8): Default `hideSourceMaps` to `true` |
| 149 | + |
144 | 150 | // `hidden-source-map` produces the same sourcemaps as `source-map`, but doesn't include the `sourceMappingURL`
|
145 | 151 | // comment at the bottom. For folks who aren't publicly hosting their sourcemaps, this is helpful because then
|
146 | 152 | // the browser won't look for them and throw errors into the console when it can't find them. Because this is a
|
@@ -494,3 +500,51 @@ function shouldEnableWebpackPlugin(buildContext: BuildContext, userSentryOptions
|
494 | 500 | // We've passed all of the tests!
|
495 | 501 | return true;
|
496 | 502 | }
|
| 503 | + |
| 504 | +/** Handle warning messages about `hideSourceMaps` option. Can be removed in v9 or v10 (or whenever we consider that |
| 505 | + * enough people will have upgraded the SDK that the warning about the default in v8 - currently commented out - is |
| 506 | + * overkill). */ |
| 507 | +function handleSourcemapHidingOptionWarning(userSentryOptions: UserSentryOptions, isServer: boolean): void { |
| 508 | + // This is nextjs's own logging formatting, vendored since it's not exported. See |
| 509 | + // https://github.com/vercel/next.js/blob/c3ceeb03abb1b262032bd96457e224497d3bbcef/packages/next/build/output/log.ts#L3-L11 |
| 510 | + // and |
| 511 | + // https://github.com/vercel/next.js/blob/de7aa2d6e486c40b8be95a1327639cbed75a8782/packages/next/lib/eslint/runLintCheck.ts#L321-L323. |
| 512 | + const codeFormat = (str: string): string => chalk.bold.cyan(str); |
| 513 | + |
| 514 | + const _warningPrefix_ = `${chalk.yellow('warn')} -`; |
| 515 | + const _sentryNextjs_ = codeFormat('@sentry/nextjs'); |
| 516 | + const _hideSourceMaps_ = codeFormat('hideSourceMaps'); |
| 517 | + const _true_ = codeFormat('true'); |
| 518 | + const _false_ = codeFormat('false'); |
| 519 | + const _sentry_ = codeFormat('sentry'); |
| 520 | + const _nextConfigJS_ = codeFormat('next.config.js'); |
| 521 | + |
| 522 | + if (isServer && userSentryOptions.hideSourceMaps === undefined) { |
| 523 | + // eslint-disable-next-line no-console |
| 524 | + console.warn( |
| 525 | + `\n${_warningPrefix_} In order to be able to deminify errors, ${_sentryNextjs_} creates sourcemaps and uploads ` + |
| 526 | + 'them to the Sentry server. Depending on your deployment setup, this means your original code may be visible ' + |
| 527 | + `in browser devtools in production. To prevent this, set ${_hideSourceMaps_} to ${_true_} in the ${_sentry_} ` + |
| 528 | + `options in your ${_nextConfigJS_}. To disable this warning without changing sourcemap behavior, set ` + |
| 529 | + `${_hideSourceMaps_} to ${_false_}. (In ${_sentryNextjs_} version 8.0.0 and beyond, this option will default ` + |
| 530 | + `to ${_true_}.) See https://webpack.js.org/configuration/devtool/ and ` + |
| 531 | + 'https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-hidden-source-map for more ' + |
| 532 | + 'information.\n', |
| 533 | + ); |
| 534 | + } |
| 535 | + |
| 536 | + // TODO (v8): Remove the check above in favor of the one below |
| 537 | + |
| 538 | + // const infoPrefix = `${chalk.cyan('info')} -`; |
| 539 | + // |
| 540 | + // if (isServer && userSentryOptions.hideSourceMaps === true) { |
| 541 | + // // eslint-disable-next-line no-console |
| 542 | + // console.log( |
| 543 | + // `\n${infoPrefix} Starting in ${_sentryNextjs_} version 8.0.0, ${_hideSourceMaps_} defaults to ${_true_}, and ` + |
| 544 | + // `thus can be removed from the ${_sentry_} options in ${_nextConfigJS_}. See ` + |
| 545 | + // 'https://webpack.js.org/configuration/devtool/ and ' + |
| 546 | + // 'https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#use-hidden-source-map for more ' + |
| 547 | + // 'information.\n', |
| 548 | + // ); |
| 549 | + // } |
| 550 | +} |
0 commit comments