Skip to content

Commit 7c23a0c

Browse files
author
Luca Forstner
committed
feat(nextjs): Use afterProductionBuild to upload sourcemaps and do release management
1 parent 267ebe0 commit 7c23a0c

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { getWebpackBuildFunctionCalled } from './util';
2+
3+
/**
4+
* TODO
5+
*/
6+
export async function afterProductionBuild(buildInfo: { distDir: string }, options: { debug: boolean }): Promise<void> {
7+
// The afterProductionBuild function is only relevant if we are using Turbopack instead of Webpack, meaning we noop if we detect that we did any webpack logic
8+
if (getWebpackBuildFunctionCalled()) {
9+
if (options.debug) {
10+
// eslint-disable-next-line no-console
11+
console.debug('[@sentry/nextjs] Not running afterProductionBuild logic because Webpack context was ran.');
12+
}
13+
return;
14+
}
15+
16+
// Create release? Maybe before this hook? Add release info like env, commits etc.
17+
// Finalize release?
18+
// Upload everything in distDir (consider org, project, authToken, sentryUrl)
19+
// Delete sourcemaps after upload?
20+
// Emit telemetry?
21+
}

packages/nextjs/src/config/util.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { GLOBAL_OBJ } from '@sentry/core';
12
import * as fs from 'fs';
23
import { sync as resolveSync } from 'resolve';
34

@@ -27,3 +28,21 @@ function resolveNextjsPackageJson(): string | undefined {
2728
return undefined;
2829
}
2930
}
31+
32+
/**
33+
* TODO
34+
*/
35+
export function setWebpackBuildFunctionCalled(): void {
36+
// Let the rest of the execution context know that we are using Webpack to build.
37+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
38+
(GLOBAL_OBJ as any)._sentryWebpackBuildFunctionCalled = true;
39+
}
40+
41+
/**
42+
* TODO
43+
*/
44+
export function getWebpackBuildFunctionCalled(): boolean {
45+
// Let the rest of the execution context know that we are using Webpack to build.
46+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
47+
return !!(GLOBAL_OBJ as any)._sentryWebpackBuildFunctionCalled;
48+
}

packages/nextjs/src/config/webpack.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import * as fs from 'fs';
55
import * as path from 'path';
6-
import { escapeStringForRegex, loadModule, logger, parseSemver } from '@sentry/core';
6+
import { GLOBAL_OBJ, escapeStringForRegex, loadModule, logger, parseSemver } from '@sentry/core';
77
import * as chalk from 'chalk';
88
import { sync as resolveSync } from 'resolve';
99

@@ -22,7 +22,7 @@ import type {
2222
WebpackEntryProperty,
2323
} from './types';
2424
import { getWebpackPluginOptions } from './webpackPluginOptions';
25-
import { getNextjsVersion } from './util';
25+
import { getNextjsVersion, setWebpackBuildFunctionCalled } from './util';
2626

2727
// Next.js runs webpack 3 times, once for the client, the server, and for edge. Because we don't want to print certain
2828
// warnings 3 times, we keep track of them here.
@@ -52,6 +52,8 @@ export function constructWebpackConfigFunction(
5252
incomingConfig: WebpackConfigObject,
5353
buildContext: BuildContext,
5454
): WebpackConfigObject {
55+
setWebpackBuildFunctionCalled();
56+
5557
const { isServer, dev: isDev, dir: projectDir } = buildContext;
5658
const runtime = isServer ? (buildContext.nextRuntime === 'edge' ? 'edge' : 'server') : 'client';
5759
// Default page extensions per https://github.com/vercel/next.js/blob/f1dbc9260d48c7995f6c52f8fbcc65f08e627992/packages/next/server/config-shared.ts#L161

0 commit comments

Comments
 (0)