Skip to content

Commit 89f5e79

Browse files
author
Luca Forstner
committed
Explain target module name
1 parent 9fb471d commit 89f5e79

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

packages/nextjs/rollup.npm.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default [
2929
// make it so Rollup calms down about the fact that we're combining default and named exports
3030
exports: 'named',
3131
},
32-
external: ['@sentry/nextjs', '__SENTRY_WRAPEE__.cjs'],
32+
external: ['@sentry/nextjs', '__SENTRY_WRAPPING_TARGET__'],
3333
},
3434
}),
3535
),

packages/nextjs/src/config/loaders/proxyLoader.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import { rollup } from 'rollup';
77

88
import { LoaderThis } from './types';
99

10+
// Just a simple placeholder to make referencing module consistent
1011
const SENTRY_WRAPPER_MODULE_NAME = 'sentry-wrapper-module';
11-
const WRAPPING_TARGET_MODULE_NAME = '__SENTRY_WRAPEE__.cjs';
12+
13+
// needs to end in .cjs in order for the `commonjs` plugin to pick it up - unfortunately the plugin has no option to
14+
// make this work in combination with the`virtual` plugin
15+
const WRAPPING_TARGET_MODULE_NAME = '__SENTRY_WRAPPING_TARGET__.cjs';
1216

1317
type LoaderOptions = {
1418
pagesDir: string;
@@ -59,6 +63,9 @@ export default async function proxyLoader(this: LoaderThis<LoaderOptions>, userC
5963
// Inject the route and the path to the file we're wrapping into the template
6064
templateCode = templateCode.replace(/__ROUTE__/g, parameterizedRoute.replace(/\\/g, '\\\\'));
6165

66+
// Replace the import path of the wrapping target in the template with a path that the `wrapUserCode` function will understand.
67+
templateCode = templateCode.replace(/__SENTRY_WRAPPING_TARGET__/g, WRAPPING_TARGET_MODULE_NAME);
68+
6269
// Run the proxy module code through Rollup, in order to split the `export * from '<wrapped file>'` out into
6370
// individual exports (which nextjs seems to require).
6471
try {

packages/nextjs/src/config/templates/apiWrapperTemplate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// @ts-ignore See above
1010
// eslint-disable-next-line import/no-unresolved
11-
import * as origModule from '__SENTRY_WRAPEE__.cjs';
11+
import * as origModule from '__SENTRY_WRAPPING_TARGET__';
1212
import * as Sentry from '@sentry/nextjs';
1313
import type { PageConfig } from 'next';
1414

@@ -73,4 +73,4 @@ export default exportedHandler;
7373
// not include anything whose name matchs something we've explicitly exported above.
7474
// @ts-ignore See above
7575
// eslint-disable-next-line import/no-unresolved
76-
export * from '__SENTRY_WRAPEE__.cjs';
76+
export * from '__SENTRY_WRAPPING_TARGET__';

packages/nextjs/src/config/templates/pageWrapperTemplate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// @ts-ignore See above
1010
// eslint-disable-next-line import/no-unresolved
11-
import * as wrapee from '__SENTRY_WRAPEE__.cjs';
11+
import * as wrapee from '__SENTRY_WRAPPING_TARGET__';
1212
import * as Sentry from '@sentry/nextjs';
1313
import type { GetServerSideProps, GetStaticProps, NextPage as NextPageComponent } from 'next';
1414

@@ -53,4 +53,4 @@ export default pageComponent;
5353
// not include anything whose name matchs something we've explicitly exported above.
5454
// @ts-ignore See above
5555
// eslint-disable-next-line import/no-unresolved
56-
export * from '__SENTRY_WRAPEE__.cjs';
56+
export * from '__SENTRY_WRAPPING_TARGET__';

0 commit comments

Comments
 (0)