Skip to content

Commit

Permalink
Inject sentry client config with Nuxt addPluginTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
s1gr1d committed Jul 5, 2024
1 parent 306a2d2 commit 97180dd
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 68 deletions.
14 changes: 1 addition & 13 deletions packages/nuxt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,7 @@ Sentry.init({
});
```

### 4. Server-side setup

Add a `sentry.server.config.(js|ts)` file to the root of your project:

```javascript
import * as Sentry from '@sentry/nuxt';

Sentry.init({
dsn: env.DSN,
});
```

### 5. Vite Setup
### 4. Vite Setup

todo: add vite setup

Expand Down
1 change: 0 additions & 1 deletion packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@nuxt/kit": "^3.12.3",
"@sentry/browser": "8.15.0",
"@sentry/core": "8.15.0",
"@sentry/node": "8.15.0",
"@sentry/opentelemetry": "8.15.0",
"@sentry/types": "8.15.0",
"@sentry/utils": "8.15.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollu

export default makeNPMConfigVariants(
makeBaseNPMConfig({
entrypoints: ['src/index.server.ts', 'src/index.client.ts', 'src/client/index.ts', 'src/server/index.ts'],
entrypoints: ['src/index.client.ts', 'src/client/index.ts'],
}),
);
1 change: 0 additions & 1 deletion packages/nuxt/src/index.server.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/nuxt/src/index.types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
import type { Integration, Options, StackParser } from '@sentry/types';
import type * as clientSdk from './index.client';
import type * as serverSdk from './index.server';

// We export everything from both the client part of the SDK and from the server part. Some of the exports collide,
// which is not allowed, unless we re-export the colliding exports in this file - which we do below.
export * from './index.client';
export * from './index.server';

// re-export colliding types
export declare function init(options: Options | clientSdk.BrowserOptions | serverSdk.NodeOptions): void;
export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsIntegration;
export declare const contextLinesIntegration: typeof clientSdk.contextLinesIntegration;
export declare const getDefaultIntegrations: (options: Options) => Integration[];
export declare const defaultStackParser: StackParser;
export declare const continueTrace: typeof clientSdk.continueTrace;
export declare const metrics: typeof clientSdk.metrics & typeof serverSdk.metrics;
15 changes: 1 addition & 14 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,10 @@ export default defineNuxtModule<ModuleOptions>({

addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'), mode: 'client' });
}

const serverConfigFile = findDefaultSdkInitFile('server');

if (serverConfigFile) {
// Inject the server-side Sentry config file with a side effect import
addPluginTemplate({
mode: 'server',
filename: 'sentry-server-config.mjs',
getContents: () =>
`import "${buildDirResolver.resolve(`/${serverConfigFile}`)}"\n` +
'export default defineNuxtPlugin(() => {})',
});
}
},
});

function findDefaultSdkInitFile(type: 'server' | 'client'): string | undefined {
function findDefaultSdkInitFile(type: /* 'server' */ 'client'): string | undefined {
const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'];

const cwd = process.cwd();
Expand Down
3 changes: 0 additions & 3 deletions packages/nuxt/src/server/index.ts

This file was deleted.

19 changes: 0 additions & 19 deletions packages/nuxt/src/server/sdk.ts

This file was deleted.

0 comments on commit 97180dd

Please sign in to comment.