From 838f3fa755b154411d97e87916bb18c6b0969b57 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Fri, 5 Jul 2024 13:31:45 +0200 Subject: [PATCH] Inject sentry client config with Nuxt addPluginTemplate --- packages/nuxt/README.md | 14 +------------- packages/nuxt/package.json | 1 - packages/nuxt/rollup.npm.config.mjs | 2 +- packages/nuxt/src/index.server.ts | 1 - packages/nuxt/src/index.types.ts | 16 ---------------- packages/nuxt/src/module.ts | 15 +-------------- packages/nuxt/src/server/index.ts | 3 --- packages/nuxt/src/server/sdk.ts | 19 ------------------- 8 files changed, 3 insertions(+), 68 deletions(-) delete mode 100644 packages/nuxt/src/index.server.ts delete mode 100644 packages/nuxt/src/server/index.ts delete mode 100644 packages/nuxt/src/server/sdk.ts diff --git a/packages/nuxt/README.md b/packages/nuxt/README.md index f329f569216d..7da84dd010f4 100644 --- a/packages/nuxt/README.md +++ b/packages/nuxt/README.md @@ -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 diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index 89e02a66479d..b6af634dd0d4 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -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", diff --git a/packages/nuxt/rollup.npm.config.mjs b/packages/nuxt/rollup.npm.config.mjs index a672e9e43eb3..e800fdbba474 100644 --- a/packages/nuxt/rollup.npm.config.mjs +++ b/packages/nuxt/rollup.npm.config.mjs @@ -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'], }), ); diff --git a/packages/nuxt/src/index.server.ts b/packages/nuxt/src/index.server.ts deleted file mode 100644 index 0ce5251aa327..000000000000 --- a/packages/nuxt/src/index.server.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './server'; diff --git a/packages/nuxt/src/index.types.ts b/packages/nuxt/src/index.types.ts index d1850eec18ec..768e7b586f6e 100644 --- a/packages/nuxt/src/index.types.ts +++ b/packages/nuxt/src/index.types.ts @@ -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; diff --git a/packages/nuxt/src/module.ts b/packages/nuxt/src/module.ts index b4b5a2d9d7ea..69465568a960 100644 --- a/packages/nuxt/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -32,23 +32,10 @@ export default defineNuxtModule({ 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(); diff --git a/packages/nuxt/src/server/index.ts b/packages/nuxt/src/server/index.ts deleted file mode 100644 index 6ac8d97b4241..000000000000 --- a/packages/nuxt/src/server/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from '@sentry/node'; - -export { init } from './sdk'; diff --git a/packages/nuxt/src/server/sdk.ts b/packages/nuxt/src/server/sdk.ts deleted file mode 100644 index 4faae8e6ef1a..000000000000 --- a/packages/nuxt/src/server/sdk.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { applySdkMetadata } from '@sentry/core'; -import { init as initNode } from '@sentry/node'; -import type { Client } from '@sentry/types'; -import type { SentryNuxtOptions } from '../common/types'; - -/** - * Initializes the server-side of the Nuxt SDK - * - * @param options Configuration options for the SDK. - */ -export function init(options: SentryNuxtOptions): Client | undefined { - const sentryOptions = { - ...options, - }; - - applySdkMetadata(sentryOptions, 'nuxt', ['nuxt', 'node']); - - return initNode(sentryOptions); -}