-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathafterProductionBuild.ts
46 lines (42 loc) · 1.79 KB
/
afterProductionBuild.ts
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
import type { SentryBuildOptions } from './types';
import { getWebpackBuildFunctionCalled } from './util';
import { createSentryBuildPluginManager } from '@sentry/bundler-plugin-core';
import { getBuildPluginOptions } from './webpackPluginOptions';
import { glob } from 'glob';
/**
* A function to do Sentry stuff for the `afterProductionBuild` Next.js hook
*/
export async function handleAfterProductionBuild(
buildInfo: { distDir: string; releaseName: string | undefined },
sentryBuildOptions: SentryBuildOptions,
): Promise<void> {
// The handleAfterProductionBuild function is only relevant if we are using Turbopack instead of Webpack, meaning we noop if we detect that we did any webpack logic
if (getWebpackBuildFunctionCalled()) {
if (sentryBuildOptions.debug) {
// eslint-disable-next-line no-console
console.debug('[@sentry/nextjs] Not running afterProductionBuild logic because Webpack context was ran.');
}
return;
}
const sentryBuildPluginManager = createSentryBuildPluginManager(
getBuildPluginOptions(sentryBuildOptions, buildInfo.releaseName, 'after-production-build', buildInfo.distDir),
{
buildTool: 'turbopack',
loggerPrefix: '[@sentry/nextjs]',
},
);
const buildArtifactsPromise = glob(
['/**/*.js', '/**/*.mjs', '/**/*.cjs', '/**/*.js.map', '/**/*.mjs.map', '/**/*.cjs.map'].map(
q => `${q}?(\\?*)?(#*)`,
), // We want to allow query and hashes strings at the end of files
{
root: buildInfo.distDir,
absolute: true,
nodir: true,
},
);
await sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal();
await sentryBuildPluginManager.createRelease();
await sentryBuildPluginManager.uploadSourcemaps(await buildArtifactsPromise);
await sentryBuildPluginManager.deleteArtifacts();
}