@sentry/nextjs
Version:
Official Sentry SDK for Next.js
192 lines (188 loc) • 8.48 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const diagnosticsChannelInjection = require('../diagnosticsChannelInjection.js');
const handleRunAfterProductionCompile = require('../handleRunAfterProductionCompile.js');
const constructTurbopackConfig = require('../turbopack/constructTurbopackConfig.js');
const util = require('../util.js');
const webpack = require('../webpack.js');
const constants = require('./constants.js');
function getBundlerInfo(nextJsVersion) {
const activeBundler = util.detectActiveBundler();
const isTurbopack = activeBundler === "turbopack";
const isWebpack = activeBundler === "webpack";
const isTurbopackSupported = util.supportsProductionCompileHook(nextJsVersion ?? "");
return { isTurbopack, isWebpack, isTurbopackSupported };
}
function maybeWarnAboutUnsupportedTurbopack(nextJsVersion, bundlerInfo) {
if (!bundlerInfo.isTurbopackSupported && bundlerInfo.isTurbopack) {
console.warn(
`[@sentry/nextjs] WARNING: You are using the Sentry SDK with Turbopack. The Sentry SDK is compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on ${nextJsVersion}. Please upgrade to a newer Next.js version to use the Sentry SDK with Turbopack.`
);
}
}
function maybeWarnAboutUnsupportedRunAfterProductionCompileHook(nextJsVersion, userSentryOptions, bundlerInfo) {
if (userSentryOptions.useRunAfterProductionCompileHook && !util.supportsProductionCompileHook(nextJsVersion ?? "") && bundlerInfo.isWebpack) {
console.warn(
"[@sentry/nextjs] The configured `useRunAfterProductionCompileHook` option is not compatible with your current Next.js version. This option is only supported on Next.js version 15.4.1 or later. Will not run source map and release management logic."
);
}
}
function maybeConstructTurbopackConfig(incomingUserNextConfigObject, userSentryOptions, routeManifest, nextJsVersion, bundlerInfo, vercelCronsConfigResult) {
if (!bundlerInfo.isTurbopack) {
return void 0;
}
const vercelCronsConfig = vercelCronsConfigResult.strategy === "spans" ? vercelCronsConfigResult.config : void 0;
return constructTurbopackConfig.constructTurbopackConfig({
userNextConfig: incomingUserNextConfigObject,
userSentryOptions,
routeManifest,
nextJsVersion,
vercelCronsConfig
});
}
function resolveUseRunAfterProductionCompileHookOption(userSentryOptions, bundlerInfo) {
return userSentryOptions.useRunAfterProductionCompileHook ?? (bundlerInfo.isTurbopack ? true : false);
}
function maybeSetUpRunAfterProductionCompileHook({
incomingUserNextConfigObject,
userSentryOptions,
releaseName,
nextJsVersion,
bundlerInfo,
turboPackConfig,
shouldUseRunAfterProductionCompileHook
}) {
if (!shouldUseRunAfterProductionCompileHook) {
return;
}
if (!util.supportsProductionCompileHook(nextJsVersion ?? "")) {
return;
}
if (incomingUserNextConfigObject?.compiler?.runAfterProductionCompile === void 0) {
incomingUserNextConfigObject.compiler ?? (incomingUserNextConfigObject.compiler = {});
incomingUserNextConfigObject.compiler.runAfterProductionCompile = async ({ distDir }) => {
await handleRunAfterProductionCompile.handleRunAfterProductionCompile(
{
releaseName,
distDir,
buildTool: bundlerInfo.isTurbopack ? "turbopack" : "webpack",
usesNativeDebugIds: bundlerInfo.isTurbopack ? turboPackConfig?.debugIds : void 0,
sriEnabled: !!incomingUserNextConfigObject.experimental?.sri
},
userSentryOptions
);
};
return;
}
if (typeof incomingUserNextConfigObject.compiler.runAfterProductionCompile === "function") {
incomingUserNextConfigObject.compiler.runAfterProductionCompile = new Proxy(
incomingUserNextConfigObject.compiler.runAfterProductionCompile,
{
async apply(target, thisArg, argArray) {
const { distDir } = argArray[0] ?? { distDir: ".next" };
await target.apply(thisArg, argArray);
await handleRunAfterProductionCompile.handleRunAfterProductionCompile(
{
releaseName,
distDir,
buildTool: bundlerInfo.isTurbopack ? "turbopack" : "webpack",
usesNativeDebugIds: bundlerInfo.isTurbopack ? turboPackConfig?.debugIds : void 0,
sriEnabled: !!incomingUserNextConfigObject.experimental?.sri
},
userSentryOptions
);
}
}
);
return;
}
console.warn(
"[@sentry/nextjs] The configured `compiler.runAfterProductionCompile` option is not a function. Will not run source map and release management logic."
);
}
function maybeEnableTurbopackSourcemaps(incomingUserNextConfigObject, userSentryOptions, bundlerInfo) {
if (!bundlerInfo.isTurbopackSupported || !bundlerInfo.isTurbopack || userSentryOptions.sourcemaps?.disable) {
return;
}
if (incomingUserNextConfigObject.productionBrowserSourceMaps !== void 0) {
return;
}
if (userSentryOptions.debug) {
console.log("[@sentry/nextjs] Automatically enabling browser source map generation for turbopack build.");
}
incomingUserNextConfigObject.productionBrowserSourceMaps = true;
if (userSentryOptions.sourcemaps?.deleteSourcemapsAfterUpload !== void 0) {
return;
}
if (userSentryOptions.debug) {
console.warn(
"[@sentry/nextjs] Source maps will be automatically deleted after being uploaded to Sentry. If you want to keep the source maps, set the `sourcemaps.deleteSourcemapsAfterUpload` option to false in `withSentryConfig()`. If you do not want to generate and upload sourcemaps at all, set the `sourcemaps.disable` option to true."
);
}
userSentryOptions.sourcemaps = {
...userSentryOptions.sourcemaps,
deleteSourcemapsAfterUpload: true
};
}
function getServerExternalPackagesPatch(incomingUserNextConfigObject, nextMajor, useDiagnosticsChannelInjection = false) {
const mergeExternals = (userProvided) => {
const defaults = useDiagnosticsChannelInjection ? diagnosticsChannelInjection.filterInstrumentedExternals(constants.DEFAULT_SERVER_EXTERNAL_PACKAGES, diagnosticsChannelInjection.BUNDLE_SAFE_INSTRUMENTED_PACKAGES) : constants.DEFAULT_SERVER_EXTERNAL_PACKAGES;
return [
...userProvided || [],
...defaults,
...useDiagnosticsChannelInjection ? diagnosticsChannelInjection.ORCHESTRION_RUNTIME_EXTERNAL_PACKAGES : []
];
};
if (nextMajor && nextMajor >= 15) {
return { serverExternalPackages: mergeExternals(incomingUserNextConfigObject.serverExternalPackages) };
}
return {
experimental: {
...incomingUserNextConfigObject.experimental,
serverComponentsExternalPackages: mergeExternals(
incomingUserNextConfigObject.experimental?.serverComponentsExternalPackages
)
}
};
}
function getWebpackPatch({
incomingUserNextConfigObject,
userSentryOptions,
releaseName,
routeManifest,
nextJsVersion,
shouldUseRunAfterProductionCompileHook,
bundlerInfo,
vercelCronsConfigResult
}) {
if (!bundlerInfo.isWebpack || userSentryOptions.webpack?.disableSentryConfig) {
return {};
}
return {
webpack: webpack.constructWebpackConfigFunction({
userNextConfig: incomingUserNextConfigObject,
userSentryOptions,
releaseName,
routeManifest,
nextJsVersion,
useRunAfterProductionCompileHook: shouldUseRunAfterProductionCompileHook,
vercelCronsConfigResult
})
};
}
function getTurbopackPatch(bundlerInfo, turboPackConfig) {
if (!bundlerInfo.isTurbopackSupported || !bundlerInfo.isTurbopack) {
return {};
}
return { turbopack: turboPackConfig };
}
exports.getBundlerInfo = getBundlerInfo;
exports.getServerExternalPackagesPatch = getServerExternalPackagesPatch;
exports.getTurbopackPatch = getTurbopackPatch;
exports.getWebpackPatch = getWebpackPatch;
exports.maybeConstructTurbopackConfig = maybeConstructTurbopackConfig;
exports.maybeEnableTurbopackSourcemaps = maybeEnableTurbopackSourcemaps;
exports.maybeSetUpRunAfterProductionCompileHook = maybeSetUpRunAfterProductionCompileHook;
exports.maybeWarnAboutUnsupportedRunAfterProductionCompileHook = maybeWarnAboutUnsupportedRunAfterProductionCompileHook;
exports.maybeWarnAboutUnsupportedTurbopack = maybeWarnAboutUnsupportedTurbopack;
exports.resolveUseRunAfterProductionCompileHookOption = resolveUseRunAfterProductionCompileHookOption;
//# sourceMappingURL=getFinalConfigObjectBundlerUtils.js.map