Skip to content

Commit 7ea5bd6

Browse files
committed
add template for wrapping data-fetching functions
1 parent 0570b7c commit 7ea5bd6

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

packages/nextjs/rollup.npm.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@ export default [
1414
),
1515
...makeNPMConfigVariants(
1616
makeBaseNPMConfig({
17-
entrypoints: ['src/config/templates/prefixLoaderTemplate.ts'],
17+
entrypoints: [
18+
'src/config/templates/prefixLoaderTemplate.ts',
19+
'src/config/templates/dataFetchersLoaderTemplate.ts',
20+
],
1821

1922
packageSpecificConfig: {
2023
output: {
21-
// preserve the original file structure (i.e., so that everything is still relative to `src`)
24+
// Preserve the original file structure (i.e., so that everything is still relative to `src`). (Not entirely
25+
// clear why this is necessary here and not for other entrypoints in this file.)
2226
entryFileNames: 'config/templates/[name].js',
2327

2428
// this is going to be add-on code, so it doesn't need the trappings of a full module (and in fact actively
2529
// shouldn't have them, lest they muck with the module to which we're adding it)
2630
sourcemap: false,
2731
esModule: false,
2832
},
33+
external: ['@sentry/nextjs'],
2934
},
3035
}),
3136
),
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type {
2+
GetServerSideProps as GetServerSidePropsFunction,
3+
GetStaticPaths as GetStaticPathsFunction,
4+
GetStaticProps as GetStaticPropsFunction,
5+
} from 'next';
6+
7+
declare const _getServerSideProps: GetServerSidePropsFunction;
8+
declare const _getStaticProps: GetStaticPropsFunction;
9+
declare const _getStaticPaths: GetStaticPathsFunction;
10+
11+
// We import the SDK under a purposefully clunky name, to lessen to near zero the chances of a name collision in case
12+
// the user has also imported Sentry for some reason. (In the future, we could check for such a collision using the AST,
13+
// but this is a lot simpler.)
14+
//
15+
// TODO: This import line is here because it needs to be in the injected code, but it also would (ideally)
16+
// let us take advantage of typechecking, via the linter (both eslint and the TS linter), using intellisense, and when
17+
// building. Solving for all five simultaneously seems to be tricky, however, because of the circular dependency. This
18+
// is one of a number of possible compromise options, which seems to hit everything except eslint linting and
19+
// typechecking via `tsc`. (TS linting and intellisense both work, though, so we do get at least some type safety.) See
20+
// https://github.com/getsentry/sentry-javascript/pull/5503#discussion_r936827996 for more details.
21+
//
22+
// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unresolved
23+
import * as ServerSideSentryNextjsSDK from '@sentry/nextjs';
24+
25+
export const getServerSideProps = ServerSideSentryNextjsSDK.withSentryGSSP(_getServerSideProps);
26+
export const getStaticProps = ServerSideSentryNextjsSDK.withSentryGSProps(_getStaticProps);
27+
export const getStaticPaths = ServerSideSentryNextjsSDK.withSentryGSPaths(_getStaticPaths);

packages/nextjs/tsconfig.types.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"extends": "./tsconfig.json",
33

4+
"exclude": ["src/config/templates/*"],
5+
46
"compilerOptions": {
57
"declaration": true,
68
"declarationMap": true,

0 commit comments

Comments
 (0)