1.1.0 โ€ข Published 1 year ago

unplugin-sentry v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

unplugin-sentry

NPM version License

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?).

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

npm i unplugin-sentry -D
// vite.config.ts
import unpluginSentry from 'unplugin-sentry/vite'

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

Example: playground/vite

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

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

Example: playground/rollup

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

Example: playground/webpack

This module works for Webpack >= 3

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

Example: playground/nuxt

This module works for both Nuxt 2 and Nuxt Vite

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

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.

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.

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

Options

Extends from @sentry/cli - SentryCliOptions.

PropTypeRequiredDefaultDescription
urlstringโŒhttps://sentry.io/The URL of the Sentry instance you are connecting to. This value will update `SENTRY_URL env variable.
orgstringโŒ-Organization slug. This value will update SENTRY_ORG env variable.
projectstringโŒ-Project Project slug. This value will update SENTRY_PROJECT env variable.
authTokenstringโŒ-Authentication token for API, interchangeable with apiKey. This value will update SENTRY_AUTH_TOKEN env variable.
publishbooleanโŒfalseIf 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.
releasestringโŒ-Release version. Automatically generated from commit hash value if not provided.
shortReleasebooleanโŒtrueIf use short commit hash for automatically generated release version.
cleanLocalbooleanโŒtrueIf remove local sourcemap files (*.js.map & *.css.map) after the publish.
cleanArtifactsbooleanโŒfalseIf remove previous artifacts in the same release.
sourcemapSourcemapOptionsโŒ-Sourcemap options.
deployDeployOptionsโŒ-Deploy options.
commitsCommitsOptionsโŒ-Commits options.
finalizebooleanโŒtrueIf finalize a release after the publish.
silentbooleanโŒfalseIf true, all logs are suppressed.
dryRunbooleanโŒfalseIf attempts a dry run. Usually used for debugging which mocks publishing.
configFilestringโŒ-Path of Sentry config file.

SourcemapOptions

Extends from @sentry/cli - SentryCliUploadSourceMapsOptions.

PropTypeRequiredDefaultDescription
includeArray<string \| SourceMapsPathDescriptor>โœ…- 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<SourcemapOptions, 'include'> & { paths: string[] }
urlPrefixstringโŒ- 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.
urlSuffixstringโŒ-This sets an URL suffix at the end of all files. Useful for appending query parameters.
ignorestring[]โŒ-One or more paths to ignore during upload. Overrides entries in ignoreFile file.
ignoreFilestring | nullโŒ-Path to a file containing list of files/directories to ignore. Can point to .gitignore or anything with same format.
diststringโŒ-Unique identifier for the distribution, used to further segment your release. Usually your build number.
rewritebooleanโŒtrueEnables rewriting of matching sourcemaps so that indexed maps are flattened and missing sources are inlined if possible.
sourceMapReferencebooleanโŒ-This prevents the automatic detection of sourcemap references.
stripPrefixstring[]โŒ-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.
stripCommonPrefixbooleanโŒ-When paired with the rewrite option this will add ~ to the stripPrefix array.
validatebooleanโŒ-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.
extstring[]โŒ-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.

PropTypeRequiredDefaultDescription
envstringโœ…- 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.
startednumber | stringโŒ-Deployment start time in Unix timestamp (in seconds) or ISO 8601 format.
finishednumber | stringโŒ-Deployment finish time in Unix timestamp (in seconds) or ISO 8601 format.
timenumberโŒ-Deployment duration (in seconds). Can be used instead of started and finished.
namestringโŒ-Human readable name for the deployment.
urlstringโŒ-URL that points to the deployment.

CommitsOptions

Extends from @sentry/cli - SentryCliCommitsOptions.

PropTypeRequiredDefaultDescription
autobooleanโŒ-Automatically choose the associated commit (uses the current commit). Overrides other setCommit options.
repostringโŒ-The full repo name as defined in Sentry. Required if auto option is not true.
commitstringโŒ-The current (last) commit in the release. Required if auto option is not true.
previousCommitstringโŒ-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.
ignoreMissingbooleanโŒ-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.
ignoreEmptybooleanโŒ-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 ยฉ 2021-Present kricsleo

1.0.2

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.5

1 year ago

0.0.4

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago