@@ -8,14 +8,14 @@ type PlainObject<T = any> = { [key: string]: T };
88
99// Man are these types hard to name well. "Entry" = an item in some collection of items, but in our case, one of the
1010// things we're worried about here is property (entry) in an object called... entry. So henceforth, the specific
11- // proptery we're modifying is going to be known as an EntryProperty, or EP for short .
11+ // property we're modifying is going to be known as an EntryProperty.
1212
1313// The function which is ultimately going to be exported from `next.config.js` under the name `webpack`
1414type WebpackExport = ( config : WebpackConfig , options : WebpackOptions ) => WebpackConfig ;
15- // type WebpackExport = (config: WebpackConfig, options: WebpackOptions) => Promise<WebpackConfig>;
1615
1716// The two arguments passed to the exported `webpack` function, as well as the thing it returns
1817type WebpackConfig = { devtool : string ; plugins : PlainObject [ ] ; entry : EntryProperty } ;
18+ // TODO use real webpack types
1919type WebpackOptions = { dev : boolean ; isServer : boolean } ;
2020
2121// For our purposes, the value for `entry` is either an object, or a function which returns such an object
@@ -27,7 +27,6 @@ type EntryProperty = (() => Promise<EntryPropertyObject>) | EntryPropertyObject;
2727type EntryPropertyObject = PlainObject < string | Array < string > | EntryPointObject > ;
2828type EntryPointObject = { import : string | Array < string > } ;
2929
30- // const injectSentry = async (origEntryProperty: EntryProperty, isServer: boolean): Promise<EntryPropertyObject> => {
3130const injectSentry = async ( origEntryProperty : EntryProperty , isServer : boolean ) : Promise < EntryProperty > => {
3231 // Out of the box, nextjs uses the `() => Promise<EntryPropertyObject>)` flavor of EntryProperty, where the returned
3332 // object has string arrays for values. But because we don't know whether someone else has come along before us and
@@ -77,7 +76,8 @@ const injectSentry = async (origEntryProperty: EntryProperty, isServer: boolean)
7776
7877 newEntryProperty [ injectionPoint ] = injectedInto ;
7978
80- // TODO: hack made necessary because promises are currently kicking my butt
79+ // TODO: hack made necessary because the async-ness of this function turns our object back into a promise, meaning the
80+ // internal `next` code which should do this doesn't
8181 if ( 'main.js' in newEntryProperty ) {
8282 delete newEntryProperty [ 'main.js' ] ;
8383 }
@@ -115,19 +115,17 @@ export function withSentryConfig(
115115 . map ( key => key in Object . keys ( providedWebpackPluginOptions ) ) ;
116116 if ( webpackPluginOptionOverrides . length > 0 ) {
117117 logger . warn (
118- '[next-plugin-sentry ] You are overriding the following automatically-set SentryWebpackPlugin config options:\n' +
118+ '[Sentry ] You are overriding the following automatically-set SentryWebpackPlugin config options:\n' +
119119 `\t${ webpackPluginOptionOverrides . toString ( ) } ,\n` +
120120 "which has the possibility of breaking source map upload and application. This is only a good idea if you know what you're doing." ,
121121 ) ;
122122 }
123123
124- // const newWebpackExport = async (config: WebpackConfig, options: WebpackOptions): Promise<WebpackConfig> => {
125124 const newWebpackExport = ( config : WebpackConfig , options : WebpackOptions ) : WebpackConfig => {
126125 let newConfig = config ;
127126
128127 if ( typeof providedExports . webpack === 'function' ) {
129128 newConfig = providedExports . webpack ( config , options ) ;
130- // newConfig = await providedExports.webpack(config, options);
131129 }
132130
133131 // Ensure quality source maps in production. (Source maps aren't uploaded in dev, and besides, Next doesn't let you
@@ -140,8 +138,6 @@ export function withSentryConfig(
140138 // Inject user config files (`sentry.client.confg.js` and `sentry.server.config.js`), which is where `Sentry.init()`
141139 // is called. By adding them here, we ensure that they're bundled by webpack as part of both server code and client code.
142140 newConfig . entry = ( injectSentry ( newConfig . entry , options . isServer ) as unknown ) as EntryProperty ;
143- // newConfig.entry = await injectSentry(newConfig.entry, options.isServer);
144- // newConfig.entry = async () => injectSentry(newConfig.entry, options.isServer);
145141
146142 // Add the Sentry plugin, which uploads source maps to Sentry when not in dev
147143 newConfig . plugins . push (
0 commit comments