UNPKG

@sentry/nextjs

Version:
74 lines (71 loc) 3.26 kB
import * as childProcess from 'child_process'; import * as fs from 'fs'; import * as path from 'path'; import { getTracingHooksDirectory } from '@sentry/server-utils/orchestrion/webpack'; function setUpBuildTimeVariables(userNextConfig, userSentryOptions, releaseName) { const assetPrefix = userNextConfig.assetPrefix || userNextConfig.basePath || ""; const basePath = userNextConfig.basePath ?? ""; const rewritesTunnelPath = userSentryOptions.tunnelRoute !== void 0 && userNextConfig.output !== "export" && typeof userSentryOptions.tunnelRoute === "string" ? `${basePath}${userSentryOptions.tunnelRoute}` : void 0; const buildTimeVariables = { // Make sure that if we have a windows path, the backslashes are interpreted as such (rather than as escape // characters) _sentryRewriteFramesDistDir: userNextConfig.distDir?.replace(/\\/g, "\\\\") || ".next", // Get the path part of `assetPrefix`, minus any trailing slash. (We use a placeholder for the origin if // `assetPrefix` doesn't include one. Since we only care about the path, it doesn't matter what it is.) _sentryRewriteFramesAssetPrefixPath: assetPrefix ? new URL(assetPrefix, "http://dogs.are.great").pathname.replace(/\/$/, "") : "" }; if (userNextConfig.assetPrefix) { buildTimeVariables._assetsPrefix = userNextConfig.assetPrefix; } if (userSentryOptions._experimental?.thirdPartyOriginStackFrames) { buildTimeVariables._experimentalThirdPartyOriginStackFrames = "true"; } if (rewritesTunnelPath) { buildTimeVariables._sentryRewritesTunnelPath = rewritesTunnelPath; } if (userSentryOptions._experimental?.useDiagnosticsChannelInjection) { buildTimeVariables._sentryUseDiagnosticsChannelInjection = "true"; buildTimeVariables._sentryOrchestrionTracingHooksDir = getTracingHooksDirectory(); } if (basePath) { buildTimeVariables._sentryBasePath = basePath; } if (userNextConfig.assetPrefix) { buildTimeVariables._sentryAssetPrefix = userNextConfig.assetPrefix; } if (userSentryOptions._experimental?.thirdPartyOriginStackFrames) { buildTimeVariables._experimentalThirdPartyOriginStackFrames = "true"; } if (releaseName) { buildTimeVariables._sentryRelease = releaseName; } if (typeof userNextConfig.env === "object") { userNextConfig.env = { ...buildTimeVariables, ...userNextConfig.env }; } else if (userNextConfig.env === void 0) { userNextConfig.env = buildTimeVariables; } } function getGitRevision() { let gitRevision; try { gitRevision = childProcess.execSync("git rev-parse HEAD", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim(); } catch { } return gitRevision; } function getInstrumentationClientFileContents() { const potentialInstrumentationClientFileLocations = [ ["src", "instrumentation-client.ts"], ["src", "instrumentation-client.js"], ["instrumentation-client.ts"], ["instrumentation-client.js"] ]; for (const pathSegments of potentialInstrumentationClientFileLocations) { try { return fs.readFileSync(path.join(process.cwd(), ...pathSegments), "utf-8"); } catch { } } } export { getGitRevision, getInstrumentationClientFileContents, setUpBuildTimeVariables }; //# sourceMappingURL=buildTime.js.map