Skip to content

Commit 0757e91

Browse files
committed
add template for wrapping data-fetching functions
1 parent 6dfa624 commit 0757e91

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/nextjs/rollup.npm.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ 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
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type {
2+
GetServerSideProps as GetServerSidePropsFunction,
3+
GetStaticPaths as GetStaticPathsFunction,
4+
GetStaticProps as GetStaticPropsFunction,
5+
} from 'next';
6+
7+
import type { withSentryGSPaths, withSentryGSProps, withSentryGSSP } from '../wrappers';
8+
9+
// TODO: Somehow the types for the imported SDK aren't recognized when it's imported using `require`, so for the moment,
10+
// we're faking it
11+
type SentrySDK = {
12+
withSentryGSSP: typeof withSentryGSSP;
13+
withSentryGSProps: typeof withSentryGSProps;
14+
withSentryGSPaths: typeof withSentryGSPaths;
15+
};
16+
17+
declare const _getServerSideProps: GetServerSidePropsFunction;
18+
declare const _getStaticProps: GetStaticPropsFunction;
19+
declare const _getStaticPaths: GetStaticPathsFunction;
20+
21+
// TODO: This is a require rather than an imoprt because for some reason, using `import` makes rollup silently refuse to
22+
// output a built version of this file.
23+
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-extraneous-dependencies
24+
const ServerSideSentryNextjsSDK = require('@sentry/nextjs');
25+
26+
export const getServerSideProps = (ServerSideSentryNextjsSDK as SentrySDK).withSentryGSSP(_getServerSideProps);
27+
export const getStaticProps = (ServerSideSentryNextjsSDK as SentrySDK).withSentryGSProps(_getStaticProps);
28+
export const getStaticPaths = (ServerSideSentryNextjsSDK as SentrySDK).withSentryGSPaths(_getStaticPaths);

0 commit comments

Comments
 (0)