Skip to content

Commit ef8e974

Browse files
committed
feat(nuxt): Base boilerplate for nuxt
1 parent 424937f commit ef8e974

File tree

13 files changed

+3898
-143
lines changed

13 files changed

+3898
-143
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"packages/integration-shims",
6363
"packages/nextjs",
6464
"packages/node",
65+
"packages/nuxt",
6566
"packages/opentelemetry",
6667
"packages/profiling-node",
6768
"packages/react",

packages/nuxt/.eslintrc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
node: true,
5+
},
6+
overrides: [
7+
{
8+
files: ['vite.config.ts'],
9+
parserOptions: {
10+
project: ['tsconfig.test.json'],
11+
},
12+
},
13+
{
14+
files: ['src/vite/**', 'src/server/**'],
15+
rules: {
16+
'@sentry-internal/sdk/no-optional-chaining': 'off',
17+
},
18+
},
19+
],
20+
extends: ['../../.eslintrc.js'],
21+
};

packages/nuxt/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-2024 Functional Software, Inc. dba Sentry
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/nuxt/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<p align="center">
2+
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
3+
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
4+
</a>
5+
</p>
6+
7+
# Official Sentry SDK for Nuxt (EXPERIMENTAL)
8+
9+
[![npm version](https://img.shields.io/npm/v/@sentry/nuxt.svg)](https://www.npmjs.com/package/@sentry/nuxt)
10+
[![npm dm](https://img.shields.io/npm/dm/@sentry/nuxt.svg)](https://www.npmjs.com/package/@sentry/nuxt)
11+
[![npm dt](https://img.shields.io/npm/dt/@sentry/nuxt.svg)](https://www.npmjs.com/package/@sentry/nuxt)
12+
13+
**This SDK is under active development and not yet published!**
14+
15+
## Links
16+
17+
todo: link official SDK docs
18+
19+
- [Official SDK Docs](https://docs.sentry.io/platforms/javascript/)
20+
21+
## Compatibility
22+
23+
The minimum supported version of Nuxt is `3.0.0`.
24+
25+
## General
26+
27+
This package is a wrapper around `@sentry/node` for the server and `@sentry/vue` for the client side, with added
28+
functionality related to Nuxt.
29+
30+
## Automatic Setup
31+
32+
todo: add wizard instructions
33+
34+
Take a look at the sections below if you want to customize your SDK configuration.
35+
36+
## Manual Setup
37+
38+
If the setup through the wizard doesn't work for you, you can also set up the SDK manually.
39+
40+
### 1. Prerequesits & Installation
41+
42+
1. Install the Sentry Nuxt SDK:
43+
44+
```bash
45+
# Using npm
46+
npm install @sentry/nuxt
47+
48+
# Using yarn
49+
yarn add @sentry/nuxt
50+
```
51+
52+
### 2. Client-side Setup
53+
54+
The Sentry Nuxt SDK is based on [Nuxt Modules](https://nuxt.com/docs/api/kit/modules).
55+
56+
1. Add `@sentry/nuxt` to the modules section of `nuxt.config.ts`:
57+
58+
```javascript
59+
// nuxt.config.ts
60+
export default defineNuxtConfig({
61+
modules: ['@sentry/nuxt'],
62+
runtimeConfig: {
63+
public: {
64+
sentry: {
65+
dsn: env.DSN,
66+
// Additional config
67+
},
68+
},
69+
},
70+
});
71+
```
72+
73+
### 3. Server-side Setup
74+
75+
todo: add server-side setup
76+
77+
### 4. Vite Setup
78+
79+
todo: add vite setup
80+
81+
---
82+
83+
## Uploading Source Maps
84+
85+
todo: add source maps instructions

packages/nuxt/package.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "@sentry/nuxt",
3+
"version": "8.10.0",
4+
"description": "Official Sentry SDK for Nuxt (EXPERIMENTAL)",
5+
"private": true,
6+
"repository": "git://github.com/getsentry/sentry-javascript.git",
7+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/nuxt",
8+
"author": "Sentry",
9+
"license": "MIT",
10+
"engines": {
11+
"node": ">=16"
12+
},
13+
"files": [
14+
"build"
15+
],
16+
"main": "build/module.cjs",
17+
"module": "build/module.mjs",
18+
"types": "build/types.d.ts",
19+
"exports": {
20+
".": {
21+
"types": "./build/types.d.ts",
22+
"import": "./build/module.mjs",
23+
"require": "./build/module.cjs"
24+
},
25+
"./package.json": "./package.json"
26+
},
27+
"publishConfig": {
28+
"access": "public"
29+
},
30+
"peerDependencies": {
31+
"nuxt": "3.x"
32+
},
33+
"dependencies": {
34+
"@sentry/core": "8.10.0",
35+
"@sentry/node": "8.10.0",
36+
"@sentry/opentelemetry": "8.10.0",
37+
"@sentry/types": "8.10.0",
38+
"@sentry/utils": "8.10.0",
39+
"@sentry/vite-plugin": "2.18.0",
40+
"@sentry/vue": "8.9.2",
41+
"@nuxt/kit": "^3.12.2"
42+
},
43+
"devDependencies": {
44+
"@babel/types": "7.20.7",
45+
"@nuxt/module-builder": "0.8.0",
46+
"nuxt": "^3.12.2",
47+
"vite": "^5.0.10"
48+
},
49+
"scripts": {
50+
"build": "run-p build:transpile build:types",
51+
"build:dev": "yarn build",
52+
"build:transpile": "nuxt-module-build build --outDir build",
53+
"build:types": "tsc -p tsconfig.types.json",
54+
"build:watch": "run-p build:transpile:watch build:types:watch",
55+
"build:dev:watch": "yarn build:watch",
56+
"build:transpile:watch": "nuxt-module-build build --outDir build --watch",
57+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
58+
"build:tarball": "nuxt-module-build build && npm pack ./build",
59+
"circularDepCheck": "madge --circular src/index.client.ts && madge --circular src/index.server.ts && madge --circular src/index.types.ts",
60+
"clean": "rimraf build coverage sentry-nuxt-*.tgz",
61+
"fix": "eslint . --format stylish --fix",
62+
"lint": "eslint . --format stylish",
63+
"test": "yarn test:unit",
64+
"test:unit": "vitest run",
65+
"test:watch": "vitest --watch",
66+
"yalc:publish": "ts-node ../../scripts/prepack.ts && yalc publish build --push --sig"
67+
},
68+
"volta": {
69+
"extends": "../../package.json"
70+
}
71+
}

packages/nuxt/src/module/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { type Resolver, addPlugin, createResolver, defineNuxtModule } from '@nuxt/kit';
2+
import type * as Sentry from '@sentry/vue';
3+
4+
export type ModuleOptions = Parameters<typeof Sentry.init>[0] & object;
5+
6+
export default defineNuxtModule<ModuleOptions>({
7+
meta: {
8+
name: '@sentry/nuxt',
9+
configKey: 'sentry',
10+
compatibility: {
11+
nuxt: '^3.0.0',
12+
},
13+
},
14+
// Default configuration options of the Nuxt module
15+
defaults: {},
16+
setup(_moduleOptions, _nuxt) {
17+
// Ignore because of `import.meta.url`
18+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
19+
// @ts-ignore
20+
const resolver: Resolver = createResolver(import.meta.url);
21+
22+
if (resolver) {
23+
// Ignore because `.resolve` is a valid method of `Resolver`, but because of ts-ignore above, `Resolver` is recognized as any
24+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
25+
addPlugin(resolver.resolve('runtime/client/plugin.js'));
26+
}
27+
},
28+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { applySdkMetadata } from '@sentry/core';
2+
import * as Sentry from '@sentry/vue';
3+
import { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app';
4+
5+
export default defineNuxtPlugin(nuxtApp => {
6+
const config = useRuntimeConfig();
7+
8+
// eslint-disable-next-line no-console
9+
console.log('Plugin initialized');
10+
11+
const sentryConfig = config.public.sentry || {};
12+
13+
applySdkMetadata(sentryConfig, 'nuxt', ['nuxt', 'vue']);
14+
15+
Sentry.init({
16+
...sentryConfig,
17+
app: nuxtApp.vueApp,
18+
});
19+
});

packages/nuxt/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
4+
"include": ["src/**/*"],
5+
6+
"compilerOptions": {
7+
// package-specific options
8+
}
9+
}

packages/nuxt/tsconfig.test.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"include": ["test/**/*", "vite.config.ts"],
5+
6+
"compilerOptions": {
7+
// should include all types from `./tsconfig.json` plus types for all test frameworks used
8+
"types": ["node", "vitest/globals"]
9+
}
10+
}

packages/nuxt/tsconfig.types.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
4+
"compilerOptions": {
5+
"declaration": true,
6+
"declarationMap": true,
7+
"emitDeclarationOnly": true,
8+
"outDir": "build/types"
9+
}
10+
}

0 commit comments

Comments
 (0)