Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kricsleo/unplugin-sentry

๐Ÿชœ All-in-one plugin for sentry, support webpack & vite & rollup & nuxt.
https://github.com/kricsleo/unplugin-sentry

plugin rollup sentry vite webpack

Last synced: 24 days ago
JSON representation

๐Ÿชœ All-in-one plugin for sentry, support webpack & vite & rollup & nuxt.

Awesome Lists containing this project

README

        

unplugin-sentry










All-in-one plugin for Sentry, supports webpack, vite, rollup, nuxt .ect.


It's used to upload sourcemap and release your project to Sentry ([What's Sentry?](https://sentry.io/welcome/)).

## Features

- ๐Ÿชœ Supports multiple bundlers and frameworks - including webpack, vite, rollup, nuxt and so on.
- โœจ Auto-detect configs depending on current environment - config as less as you need
- ๐Ÿงน Auto clean local soucemap files after upload (For security) - both `*.js.map` and `*.css.map`.
- ๐Ÿฌ Optional runtime provided - easy to init Sentry at runtime.

## Install

```bash
npm i unplugin-sentry -D
```

Vite

```ts
// vite.config.ts
import unpluginSentry from 'unplugin-sentry/vite'

export default defineConfig({
plugins: [
unpluginSentry({ /* options */ }),
],
})
```

Example: [`playground/vite`](./playground/vite)


Rollup

```ts
// rollup.config.js
import unpluginSentry from 'unplugin-sentry/rollup'

export default {
plugins: [
unpluginSentry({ /* options */ }),
],
}
```

Example: [`playground/rollup`](./playground/rollup)


Webpack

```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-sentry/webpack')({ /* options */ })
]
}
```

Example: [`playground/webpack`](./playground/webpack)

> This module works for Webpack >= 3


Nuxt

```ts
// nuxt.config.js
export default {
buildModules: [
['unplugin-sentry/nuxt', { /* options */ }],
],
}
```

Example: [`playground/nuxt`](./playground/nuxt)

> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)


Vue CLI

```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-sentry/webpack')({ /* options */ }),
],
},
}
```


esbuild

I don't use esbuild for now, so it haven't been tested in esbuild yet.
(You can have a try and tell me if it works ๐Ÿ‘‚. )


## Runtime Support

Besides uploading sourcemap to Sentry and other publishing works, this plugin also injects a virtual module named `virtual-unplugin-sentry-runtime` into your project.

It provides some useful meta info when initing Sentry at runtime. For example, when you call `Sentry.init({/** options **/})`, the `environment` and `release` options must match the one you use when uploading sourcemap. So that when debugging the issue in Sentry, the sourcemap can be correctly mapped.

```ts
import * as sentryMeta from 'virtual-unplugin-sentry-runtime'

console.log(sentryMeta)
// {
// ORG: string
// PROJECT: string
// ENV: string
// RELEASE: string
// DIST: string
// PUBLISH: boolean
// }
```

Need TS support for this runtime module? Just add the following config to your `tsconfig.json`.

```json
{
"compilerOptions": {
"types": ["unplugin-sentry/runtime"]
}
}
```

## Options

Extends from [@sentry/cli - SentryCliOptions](https://github.com/getsentry/sentry-cli/blob/master/js/index.d.ts#L5).

| Prop | Type | Required | Default | Description |
|-----------------|-----------|----------|---------|------------------------------------------------------------------------------------------------------------------------|
| url | `string` | โŒ | `https://sentry.io/` | The URL of the Sentry instance you are connecting to.
This value will update `SENTRY_URL env variable. |
| org | `string` | โŒ | - | Organization slug.
This value will update `SENTRY_ORG` env variable. |
| project | `string` | โŒ | - | Project Project slug.
This value will update `SENTRY_PROJECT` env variable. |
| authToken | `string` | โŒ | - | Authentication token for API, interchangeable with apiKey.
This value will update `SENTRY_AUTH_TOKEN` env variable. |
| publish | `boolean` | โŒ | `false` | If publish project to Sentry.
Means to upload soucemap files and release the version to Sentry server.
You might want to turn it on only when deploying projects other than locally developing.
| release | `string` | โŒ | - | Release version.
Automatically generated from commit hash value if not provided. |
| shortRelease | `boolean` | โŒ | `true` | If use short commit hash for automatically generated release version. |
| cleanLocal | `boolean` | โŒ | `true` | If remove local sourcemap files (`*.js.map` & `*.css.map`) after the publish. |
| cleanArtifacts | `boolean` | โŒ | `false` | If remove previous artifacts in the same release. |
| sourcemap | [`SourcemapOptions`](#sourcemapoptions) | โŒ | - | Sourcemap options. |
| deploy | [`DeployOptions`](#deployoptions) | โŒ | - | Deploy options. |
| commits | [`CommitsOptions`](#commitsoptions) | โŒ | - | Commits options. |
| finalize | `boolean` | โŒ | `true` | If finalize a release after the publish. |
| silent | `boolean` | โŒ | `false` | If true, all logs are suppressed. |
| dryRun | `boolean` | โŒ | `false` | If attempts a dry run.
Usually used for debugging which mocks publishing. |
| configFile | `string` | โŒ | - | Path of Sentry config file. |

#### SourcemapOptions

Extends from [@sentry/cli - SentryCliUploadSourceMapsOptions](https://github.com/getsentry/sentry-cli/blob/master/js/index.d.ts#L64).

| Prop | Type | Required | Default | Description |
|----------------------|------------------|----------|-------------|----------------------------------------------------------------------------------------------------|
| include | `Array` | โŒ | -
Auto-detectd from current bundler(webpack, vite, rollup and so on). | One or more paths that Sentry CLI should scan recursively for sources.
It will upload all .map files and match associated .js files.
`type SourceMapsPathDescriptor = Omit & { paths: string[] }` |
| urlPrefix | `string` | โŒ | -
Auto-detectd from current bundler(webpack, vite, rollup and so on). | This sets an URL prefix at the beginning of all files.
This is also useful if your files are stored in a sub folder. **BUT REMEMBER TO START WITH `~/`.** eg: url-prefix `~/static/js`. |
| urlSuffix | `string` | โŒ | - | This sets an URL suffix at the end of all files.
Useful for appending query parameters. |
| ignore | `string[]` | โŒ | - | One or more paths to ignore during upload. Overrides entries in ignoreFile file. |
| ignoreFile | `string` \| `null` | โŒ | - | Path to a file containing list of files/directories to ignore.
Can point to .gitignore or anything with same format. |
| dist | `string` | โŒ | - | Unique identifier for the distribution, used to further segment your release.
Usually your build number.
| rewrite | `boolean` | โŒ | `true` | Enables rewriting of matching sourcemaps so that indexed maps are flattened and missing sources are inlined if possible. |
| sourceMapReference | `boolean` | โŒ | - | This prevents the automatic detection of sourcemap references. |
| stripPrefix | `string[]` | โŒ | - | When paired with the rewrite option this will remove a prefix from uploaded files.
For instance you can use this to remove a path that is build machine specific. |
| stripCommonPrefix | `boolean` | โŒ | - | When paired with the rewrite option this will add ~ to the stripPrefix array. |
| validate | `boolean` | โŒ | - | This attempts sourcemap validation before upload when rewriting is not enabled.
It will spot a variety of issues with source maps and cancel the upload if any are found.
This is not enabled by default as this can cause false positives. |
| ext | `string[]` | โŒ | - | This sets the file extensions to be considered. By default the following file extensions are processed: js, map, jsbundle and bundle. |

#### DeployOptions

Extends from [@sentry/cli - SentryCliNewDeployOptions](https://github.com/getsentry/sentry-cli/blob/master/js/index.d.ts#L126).

| Prop | Type | Required | Default | Description |
|-----------|-----------|----------|---------|-------------------------------------------------------------------------------------------------------------------|
| env | `string` | โŒ | -
Auto-detectd from current bundler(webpack, vite, rollup and so on) and use "process.env.NODE_ENV" as fallback. | Environment for this release. Values that make sense here would be `production` or `staging`. |
| started | `number` \| `string` | โŒ | - | Deployment start time in Unix timestamp (in seconds) or ISO 8601 format. |
| finished | `number` \| `string` | โŒ | - | Deployment finish time in Unix timestamp (in seconds) or ISO 8601 format. |
| time | `number` | โŒ | - | Deployment duration (in seconds). Can be used instead of started and finished. |
| name | `string` | โŒ | - | Human readable name for the deployment. |
| url | `string` | โŒ | - | URL that points to the deployment. |

#### CommitsOptions

Extends from [@sentry/cli - SentryCliCommitsOptions](https://github.com/getsentry/sentry-cli/blob/master/js/index.d.ts#L153).

| Prop | Type | Required | Default | Description |
|-----------------|-----------|----------|---------|--------------------------------------------------------------------------------------------------------------------|
| auto | `boolean` | โŒ | - | Automatically choose the associated commit (uses the current commit). Overrides other setCommit options. |
| repo | `string` | โŒ | - | The full repo name as defined in Sentry. Required if auto option is not true. |
| commit | `string` | โŒ | - | The current (last) commit in the release. Required if auto option is not true. |
| previousCommit | `string` | โŒ | - | The commit before the beginning of this release.
If omitted, this will default to the last commit of the previous release in Sentry.
If there was no previous release, the last 10 commits will be used. |
| ignoreMissing | `boolean` | โŒ | - | When the flag is set and the previous release commit was not found in the repository, will create a release.
with the default commits count(or the one specified with `--initial-depth`) instead of failing the command. |
| ignoreEmpty | `boolean` | โŒ | - | When the flag is set, command will not fail and just exit silently if no new commits for a given release are found.|

## License

[MIT](./LICENSE) License ยฉ 2021-Present [kricsleo](https://github.com/kricsleo)