-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathhandleRunAfterProductionCompile.ts
More file actions
59 lines (53 loc) · 2.09 KB
/
handleRunAfterProductionCompile.ts
File metadata and controls
59 lines (53 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import type { createSentryBuildPluginManager as createSentryBuildPluginManagerType } from '@sentry/bundler-plugin-core';
import { loadModule } from '@sentry/core';
import { getBuildPluginOptions } from './getBuildPluginOptions';
import type { SentryBuildOptions } from './types';
/**
* This function is called by Next.js after the production build is complete.
* It is used to upload sourcemaps to Sentry.
*/
export async function handleRunAfterProductionCompile(
{ releaseName, distDir, buildTool }: { releaseName?: string; distDir: string; buildTool: 'webpack' | 'turbopack' },
sentryBuildOptions: SentryBuildOptions,
): Promise<void> {
// We don't want to do anything for webpack at this point because the plugin already handles this
// TODO: Actually implement this for webpack as well
if (buildTool === 'webpack') {
return;
}
if (sentryBuildOptions.debug) {
// eslint-disable-next-line no-console
console.debug('[@sentry/nextjs] Running runAfterProductionCompile logic.');
}
const { createSentryBuildPluginManager } =
loadModule<{ createSentryBuildPluginManager: typeof createSentryBuildPluginManagerType }>(
'@sentry/bundler-plugin-core',
module,
) ?? {};
if (!createSentryBuildPluginManager) {
// eslint-disable-next-line no-console
console.warn(
'[@sentry/nextjs] Could not load build manager package. Will not run runAfterProductionCompile logic.',
);
return;
}
const sentryBuildPluginManager = createSentryBuildPluginManager(
getBuildPluginOptions({
sentryBuildOptions,
releaseName,
distDirAbsPath: distDir,
}),
{
buildTool,
loggerPrefix: '[@sentry/nextjs]',
},
);
await sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal();
await sentryBuildPluginManager.createRelease();
await sentryBuildPluginManager.injectDebugIds([distDir]);
await sentryBuildPluginManager.uploadSourcemaps([distDir], {
// We don't want to prepare the artifacts because we injected debug ids manually before
prepareArtifacts: false,
});
await sentryBuildPluginManager.deleteArtifacts();
}