|
1 | 1 | /* eslint-disable max-lines */
|
2 |
| -import { getSentryRelease } from '@sentry/node'; |
| 2 | +import { deepReadDirSync, getSentryRelease } from '@sentry/node'; |
3 | 3 | import { arrayify, dropUndefinedKeys, escapeStringForRegex, logger, stringMatchesSomePattern } from '@sentry/utils';
|
4 | 4 | import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin';
|
5 | 5 | import * as chalk from 'chalk';
|
6 | 6 | import * as fs from 'fs';
|
7 | 7 | import * as path from 'path';
|
| 8 | +import { WebpackPluginInstance } from 'webpack'; |
8 | 9 |
|
9 | 10 | import {
|
10 | 11 | BuildContext,
|
@@ -100,6 +101,28 @@ export function constructWebpackConfigFunction(
|
100 | 101 | ],
|
101 | 102 | });
|
102 | 103 | }
|
| 104 | + |
| 105 | + // Prevent `@vercel/nft` (which nextjs uses to determine which files are needed when packaging up a lambda) from |
| 106 | + // including any of our build-time code or dependencies. (Otherwise it'll include files like this one and even the |
| 107 | + // entirety of rollup and sucrase.) |
| 108 | + const nftPlugin = newConfig.plugins?.find((plugin: WebpackPluginInstance) => { |
| 109 | + const proto = Object.getPrototypeOf(plugin) as WebpackPluginInstance; |
| 110 | + return proto.constructor.name === 'TraceEntryPointsPlugin'; |
| 111 | + }) as WebpackPluginInstance & { excludeFiles: string[] }; |
| 112 | + if (nftPlugin) { |
| 113 | + const nextjsPackageRoot = path.dirname(require.resolve('@sentry/nextjs')); |
| 114 | + const nextjsPackageConfigDir = path.join(nextjsPackageRoot, 'config'); |
| 115 | + const excludedNextjsPackageFiles = deepReadDirSync(nextjsPackageConfigDir).map(file => |
| 116 | + path.join(nextjsPackageConfigDir, file), |
| 117 | + ); |
| 118 | + |
| 119 | + nftPlugin.excludeFiles.push(...excludedNextjsPackageFiles); |
| 120 | + } else { |
| 121 | + __DEBUG_BUILD__ && |
| 122 | + logger.warn( |
| 123 | + 'Unable to exclude Sentry build-time helpers from nft files. Could not find `TraceEntryPointsPlugin`.', |
| 124 | + ); |
| 125 | + } |
103 | 126 | }
|
104 | 127 |
|
105 | 128 | // The SDK uses syntax (ES6 and ES6+ features like object spread) which isn't supported by older browsers. For users
|
|
0 commit comments