Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(nextjs): Pre-disable-plugin-option config cleanup #3770

Merged
merged 8 commits into from
Jun 30, 2021

Conversation

lobsterkatie
Copy link
Member

This is a bunch of prep work pulled out of an upcoming PR, which will add the option to disable the SentryWebpackPlugin for both server and client builds.

The changes in this PR are mostly cosmetic, with the aim of making the code more readable. The only substantive changes are:

@github-actions
Copy link
Contributor

github-actions bot commented Jun 30, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 21.39 KB (0%)
@sentry/browser - Webpack 22.4 KB (0%)
@sentry/react - Webpack 22.44 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.89 KB (-0.01% 🔽)

...userNextConfig(phase, defaults),
webpack: newWebpackConfig,
});
return function(phase: string, defaults: { defaultConfig: { [key: string]: unknown } }): NextConfigObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: prefer an arrow function if we are just returning an anonymous func

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had one, then this return was getting visually muddied with the return inside the returned function, so I changed it to this, to make it clearer/easier to differentiate.

// if user has custom webpack config (which always takes the form of a function), run it so we have actual values to
// work with
if ('webpack' in userNextConfig && typeof userNextConfig.webpack === 'function') {
newConfig = userNextConfig.webpack(config, options);
newConfig = userNextConfig.webpack(newConfig, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be running storeServerConfigFileLocation after this logic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanna avoid doing let newConfig if possible

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be running storeServerConfigFileLocation after this logic?

Either way works. I was thinking of cloning as a first step to immediately get out of the way.

I just wanna avoid doing let newConfig if possible

Given that we don't know if we're going to reassign it or not, the only way around using 'let' would be to move the storeServerConfigFileLocation call (which is soon to disappear anyway) and then use a ternary, which IMHO would be harder to read than the if, since in this case the condition we're checking is kinda long.

Curiosity: Is it just out of a general principle that immutability > mutability that you want to avoid let, or is there some other reason?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just out of a general principle that immutability > mutability that you want to avoid

It's more specific to this instance. I made the comment because we are passing around config objects everywhere in this webpack logic, and I don't want someone to accidentally introduce a bug in future refactors or changes.

webpack: newWebpackConfig,
});
return function(phase: string, defaults: { defaultConfig: { [key: string]: unknown } }): NextConfigObject {
const materializedUserNextConfig = userNextConfig(phase, defaults);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case showing that we properly pass through phase?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more nit comments, not blockers though.

userSentryWebpackPluginOptions: Partial<SentryWebpackPluginOptions> = {},
): WebpackConfigFunction {
const newWebpackFunction = (config: WebpackConfigObject, options: BuildContext): WebpackConfigObject => {
// clone to avoid mutability issues
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm of the opinion that we can remove this comment, I think most readers should be aware of why we spread into a new object.

Suggested change
// clone to avoid mutability issues

@@ -34,6 +35,10 @@ const userNextConfig = {
};
const userSentryWebpackPluginConfig = { org: 'squirrelChasers', project: 'simulator', include: './thirdPartyMaps' };

/** mocks of the arguments passed to the result of `withSentryConfig` (when it's a function) */
const runtimePhase = 'puppy-phase-chew-everything-in-sight';
const defaultNextConfig = { nappingHoursPerDay: 20, oversizeFeet: true, shouldChaseTail: true };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we make this a more realistic config?

@@ -34,6 +35,10 @@ const userNextConfig = {
};
const userSentryWebpackPluginConfig = { org: 'squirrelChasers', project: 'simulator', include: './thirdPartyMaps' };

/** mocks of the arguments passed to the result of `withSentryConfig` (when it's a function) */
const runtimePhase = 'puppy-phase-chew-everything-in-sight';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we use a phase from next/constants that better reflects what this would be called with in real usage? As per phase docs in https://nextjs.org/docs/api-reference/next.config.js/introduction

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¯\(ツ)/¯ We can, if you think it's important. Since they're values which are merely passed from our function to the user's function, they can really be anything. I find writing (and reading) tests to be kinda uninteresting, so I try to have some fun with it.

Regardless, I'm going to merge this now, in the interest of moving on.

@lobsterkatie lobsterkatie enabled auto-merge (squash) June 30, 2021 20:08
@lobsterkatie lobsterkatie merged commit 2ee6fa8 into master Jun 30, 2021
@lobsterkatie lobsterkatie deleted the kmclb-pre-disable-plugin-option-cleanup branch June 30, 2021 20:09
@jsakas
Copy link

jsakas commented Jul 8, 2021

which will add the option to disable the SentryWebpackPlugin for both server and client builds.

@lobsterkatie any idea when this new version will be released? Not being able to disable this plugin is really slowing down our development server & workflow right now.

@kamilogorek
Copy link
Contributor

#nodeployfriday so most likely on monday :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants