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

feat(nextjs): Support distDir Next.js option #3990

Merged
merged 18 commits into from
Sep 22, 2021

Conversation

iker-barriocanal
Copy link
Contributor

Add support for setting custom build directories. Although this allows to custom that directory, source maps won't work; supporting them will come in a follow-up PR.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 22.26 KB (0%)
@sentry/browser - Webpack 23.23 KB (0%)
@sentry/react - Webpack 23.26 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 29.7 KB (-0.01% 🔽)

packages/nextjs/test/config.test.ts Outdated Show resolved Hide resolved
packages/nextjs/src/config/index.ts Outdated Show resolved Hide resolved
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.

Will look at the tests after this

nextProps: string[],
): Partial<SentryWebpackPluginOptions> {
// @ts-ignore '__spreadArray' import from tslib, ts(2343)
const propsToInclude = [...new Set(nextProps)];
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to do this, we know that nextProps will always be unique. I'd rather refer to the global rather than the function arg as well to make the intent as clear as possible.

If you want to enforce that they will be unique, write a test that just checks if SUPPORTED_NEXTJS_PROPERTIES is all unique.

Copy link
Member

Choose a reason for hiding this comment

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

Actually we could make SUPPORTED_NEXTJS_PROPERTIES a Set and then just iterate with https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we don't know whether they are unique, even if we make SUPPORTED_NEXTJS_PROPERTIES a Set. includeNextjsProps can be called from anywhere (even if it's only used in includeAllNextjsProps for now, but that's the point of generalizing after all) and with any array.

I've thought about two alternatives here: using a set as the argument type (which I think it's less convenient than using an array), and enforcing it with types (added a comment at the top of the file why this can't be accomplished). So decided this approach is the most suitable and added a test for duplicated keys.

Copy link
Member

Choose a reason for hiding this comment

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

We can possibly enforce it with the types, let chat about it.

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.

Good tests

@iker-barriocanal iker-barriocanal merged commit 27f8609 into master Sep 22, 2021
@iker-barriocanal iker-barriocanal deleted the iker/feat/nextjs-distdir branch September 22, 2021 09:09
lobsterkatie added a commit that referenced this pull request Oct 13, 2021
…s` integration (#4017)

This is a follow-up to #3990, which makes sure sourcemaps get uploaded from the correct spot when using the nextjs `distDir` option[1]. 

To make sure that the filenames  in stacktrace frames match the names of said sourcemaps, we use the `RewriteFrames` integration. Up until now, we've been hardcoding the replacement it should make, based on nextjs's default output directory. This makes it dynamic, by injecting code at build time which adds the relevant value into `global`, where it is accessible at runtime when we're instantiating the integration.

[1] https://nextjs.org/docs/api-reference/next.config.js/setting-a-custom-build-directory
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.

2 participants