Skip to content

Commit 59b0bf6

Browse files
author
Luca Forstner
authored
fix(nextjs): Make Next.js types isomorphic (#6707)
1 parent e332ae1 commit 59b0bf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+124
-193
lines changed

.size-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = [
4646
},
4747
{
4848
name: '@sentry/nextjs Client - Webpack (gzipped + minified)',
49-
path: 'packages/nextjs/build/esm/index.client.js',
49+
path: 'packages/nextjs/build/esm/client/index.js',
5050
import: '{ init }',
5151
gzip: true,
5252
limit: '57 KB',

packages/nextjs/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"engines": {
1010
"node": ">=8"
1111
},
12-
"main": "build/cjs/index.server.js",
13-
"module": "build/esm/index.server.js",
14-
"browser": "build/esm/index.client.js",
15-
"types": "build/types/index.server.d.ts",
12+
"main": "build/cjs/index.js",
13+
"module": "build/esm/index.js",
14+
"browser": "build/esm/client/index.js",
15+
"types": "build/types/index.types.d.ts",
1616
"publishConfig": {
1717
"access": "public"
1818
},
@@ -31,7 +31,6 @@
3131
"tslib": "^1.9.3"
3232
},
3333
"devDependencies": {
34-
"@sentry/nextjs": "7.30.0",
3534
"@types/webpack": "^4.41.31",
3635
"eslint-plugin-react": "^7.31.11",
3736
"next": "10.1.3"
@@ -56,7 +55,7 @@
5655
"build:rollup:watch": "nodemon --ext ts --watch src scripts/buildRollup.ts",
5756
"build:types:watch": "tsc -p tsconfig.types.json --watch",
5857
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build",
59-
"circularDepCheck": "madge --circular src/index.client.ts && madge --circular --exclude 'config/types\\.ts' src/index.server.ts # see https://github.com/pahen/madge/issues/306",
58+
"circularDepCheck": "madge --circular src/index.ts && madge --circular src/client/index.ts && madge --circular src/index.types.ts",
6059
"clean": "rimraf build coverage sentry-nextjs-*.tgz",
6160
"fix": "run-s fix:eslint fix:prettier",
6261
"fix:eslint": "eslint . --format stylish --fix",

packages/nextjs/rollup.npm.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ export default [
55
makeBaseNPMConfig({
66
// We need to include `instrumentServer.ts` separately because it's only conditionally required, and so rollup
77
// doesn't automatically include it when calculating the module dependency tree.
8-
entrypoints: ['src/index.server.ts', 'src/index.client.ts', 'src/config/webpack.ts'],
8+
entrypoints: ['src/index.ts', 'src/client/index.ts', 'src/config/webpack.ts'],
99

1010
// prevent this internal nextjs code from ending up in our built package (this doesn't happen automatially because
1111
// the name doesn't match an SDK dependency)
12-
packageSpecificConfig: { external: ['next/router'] },
12+
packageSpecificConfig: { external: ['next/router', 'next/constants'] },
1313
}),
1414
),
1515
...makeNPMConfigVariants(

packages/nextjs/src/index.client.ts renamed to packages/nextjs/src/client/index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { RewriteFrames } from '@sentry/integrations';
2-
import { configureScope, init as reactInit, Integrations } from '@sentry/react';
2+
import { BrowserOptions, configureScope, init as reactInit, Integrations } from '@sentry/react';
33
import { BrowserTracing, defaultRequestInstrumentationOptions, hasTracingEnabled } from '@sentry/tracing';
44
import { EventProcessor } from '@sentry/types';
55

6-
import { nextRouterInstrumentation } from './performance/client';
7-
import { buildMetadata } from './utils/metadata';
8-
import { NextjsOptions } from './utils/nextjsOptions';
9-
import { applyTunnelRouteOption } from './utils/tunnelRoute';
10-
import { addOrUpdateIntegration } from './utils/userIntegrations';
6+
import { buildMetadata } from '../common/metadata';
7+
import { addOrUpdateIntegration } from '../common/userIntegrations';
8+
import { nextRouterInstrumentation } from './performance';
9+
import { applyTunnelRouteOption } from './tunnelRoute';
1110

1211
export * from '@sentry/react';
13-
export { nextRouterInstrumentation } from './performance/client';
14-
export { captureUnderscoreErrorException } from './utils/_error';
12+
export { nextRouterInstrumentation } from './performance';
13+
export { captureUnderscoreErrorException } from '../common/_error';
1514

1615
export { Integrations };
1716

@@ -35,7 +34,7 @@ const globalWithInjectedValues = global as typeof global & {
3534
};
3635

3736
/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
38-
export function init(options: NextjsOptions): void {
37+
export function init(options: BrowserOptions): void {
3938
applyTunnelRouteOption(options);
4039
buildMetadata(options, ['nextjs', 'react']);
4140
options.environment = options.environment || process.env.NODE_ENV;
@@ -52,7 +51,7 @@ export function init(options: NextjsOptions): void {
5251
});
5352
}
5453

55-
function addClientIntegrations(options: NextjsOptions): void {
54+
function addClientIntegrations(options: BrowserOptions): void {
5655
let integrations = options.integrations || [];
5756

5857
// This value is injected at build time, based on the output directory specified in the build config. Though a default

packages/nextjs/src/utils/tunnelRoute.ts renamed to packages/nextjs/src/client/tunnelRoute.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
import { BrowserOptions } from '@sentry/react';
12
import { dsnFromString, logger } from '@sentry/utils';
23

3-
import { NextjsOptions } from './nextjsOptions';
4-
54
const globalWithInjectedValues = global as typeof global & {
65
__sentryRewritesTunnelPath__?: string;
76
};
87

98
/**
109
* Applies the `tunnel` option to the Next.js SDK options based on `withSentryConfig`'s `tunnelRoute` option.
1110
*/
12-
export function applyTunnelRouteOption(options: NextjsOptions): void {
11+
export function applyTunnelRouteOption(options: BrowserOptions): void {
1312
const tunnelRouteOption = globalWithInjectedValues.__sentryRewritesTunnelPath__;
1413
if (tunnelRouteOption && options.dsn) {
1514
const dsnComponents = dsnFromString(options.dsn);

packages/nextjs/src/config/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type { SentryWebpackPluginOptions } from './types';
2+
export { withSentryConfig } from './withSentryConfig';

0 commit comments

Comments
 (0)