vite-plugin-sentry

0

Описание

Vite plugin acting as an interface to SentryCLI

Языки

  • TypeScript91,7%
  • JavaScript7,4%
  • Shell0,9%
README.md

Plugin for Vite ⚡️ to create releases and upload sourcemaps to Sentry

VersionLicense: MITcodecov

This plugin hooks into the Vite build step, to create a new release and upload source maps. It does not instrument error reporting in your app.

It's a port of official Sentry webpack plugin for Vite.

It's fully written on Typescript and there is some differences in configuration, described below, but we mostly follow @sentry/cli types.

Install

Configuration

If you using Typescript - you can use ViteSentryPluginOptions type for better configuration experience with autocomplete.

Example config:

Possible breaking change!

From version

1.2.0
we have changed default error handling. Now if Sentry report error while uploading sourcemaps - we crash whole build process instead of just print warning. This was done to prevent calling next to
&&
operator on uploading error.

You can enable legacy mode using

legacyErrorHandlingMode: true
in plugin config.

Wiki

Check project wiki on github to get more information.

Share config with Sentry client library

To correctly work with Sentry, you need to add a release to your project. Same about dist option: your uploaded sourcemaps and client sentry initialization must have same release/dist to make sentry correct recognize and bind sourcemaps to logged errors.

You can expose release and dist options used by vite-plugin-sentry into your application using Vite feature known as virtual module.

To do so, you need to add several lines:

TypeScript

To get type information for the virtual module or import meta env, you can add

vite-plugin-sentry/client
to your
types
array in tsconfig.json.

Also you can use

reference
in your typescript code like below:

Common how to:

Delete generated source maps after upload (#1)

UPD: From version 1.2.1 you can use new configuration option

cleanSourcemapsAfterUpload
to clean sourcemap files.

While i recommend to use CI, you can also use tools like rimraf in your npm scripts to drop any unnecessary files after build was complete:

Cannot install on Windows

This plugin relies on @sentry/cli tool, which requires VCRedist to be installed. Please check #8 for details.

List of available options

Here are the list of all plugin options:

Legend:

❌ - NOT required

⚠️ - NOT required in plugin config, but MUST be set (for example, using .sentryclirc file)

✅ - Required

OptionTypeRequiredDefault valueDescription
legacyErrorHandlingModebooleanfalseWhen
true
- all sentry uploading errors will be printed as warnings, build process will not be failed, vite will return exit code 0
cleanSourcemapsAfterUploadbooleanfalseDelete generated sourcemap files after complete
debugbooleanfalseShow debug messages during run
skipEnvironmentCheckbooleanfalseBy default plugin will be enabled only for production builds. Set this option to
true
to skip environment checks
dryRunbooleanfalseRun sentry in dry mode - will only prints all steps
urlstring'https://sentry.io/'The base URL of your Sentry instance.
authTokenstring⚠️''The authentication token to use for all communication with Sentry. Can be obtained from https://sentry.io/settings/account/api/auth-tokens/. Required scopes:
project:releases
(and
org:read
if
setCommits
option is used).
orgstring⚠️''The slug of the Sentry organization associated with the app.
projectstring⚠️''The slug of the Sentry project associated with the app.
vcsRemotestring'origin'The name of the remote in the version control system.
configFilestring''Path to sentry cli config file, as described in https://docs.sentry.io/product/cli/configuration/#configuration-file. By default, the config file is looked for upwards from the current path, and defaults from
~/.sentryclirc
are always loaded
releasestringUnique name for release. Defaults to sentry-cli releases propose version (requires access to GIT and root directory to be repo)
finalizebooleanfalseDetermines whether processed release should be automatically finalized after artifacts upload
silentbooleanfalseIf true, all sentry-cli logs are suppressed
deploySentryCliNewDeployOptionsSentry release deployment settings, see details below
sourceMapsSentryCliUploadSourceMapsOptionsSourcemaps settings, see details below
setCommitsSentryCliCommitsOptionsAdds commits to sentry, see details below

deploy settings

With

deploy
you can configure sentry cli to send deployment info. Here is a table of settings:

OptionTypeRequiredDescription
envstringEnvironment value for release. For example
production
startednumberUNIX timestamp for deployment start
finishednumberUNIX timestamp for deployment finish
timenumberDeployment duration in seconds. Can be used instead of
started
and
finished
.
namestringHuman-readable name for this deployment
urlstringURL that points to the deployment

sourceMaps settings

With

sourceMaps
you can configure how sourcemaps will be processed

OptionTypeRequiredDescription
includestring| string[]One or more paths that Sentry CLI should scan recursively for sources. It will upload all
.map
files and match associated
.js
files.
diststringUnique identifier for the distribution, used to further segment your release. Usually your build number
ignorestring[]Paths to ignore during upload. Overrides entries in
ignoreFile
file. If neither
ignoreFile
nor
ignore
is present, defaults to
['node_modules']
.
ignoreFilestringPath to a file containing list of files/directories to ignore. Can point to
.gitignore
or anything with the same format.
rewritebooleanEnables rewriting of matching source maps so that indexed maps are flattened and missing sources are inlined if possible. Defaults to
true
sourceMapReferencebooleanPrevents the automatic detection of sourcemap references. Defaults to
false
.
stripPrefixstring[]When paired with
rewrite
, will remove a prefix from uploaded filenames. Useful for removing a path that is build-machine-specific.
stripCommonPrefixbooleanWhen paired with
rewrite
, will add
~
to the
stripPrefix
array. Defaults to
false
validatebooleanWhen
true
, attempts source map validation before upload if rewriting is not enabled. It will spot a variety of issues with source maps and cancel the upload if any are found. Defaults to
false
to prevent false positives canceling upload.
urlPrefixstringURL prefix to add to the beginning of all filenames. Defaults to
~/
but you might want to set this to the full URL. This is also useful if your files are stored in a sub folder. eg:
url-prefix '~/static/js'
.
urlSuffixstringURL suffix to add to the end of all filenames. Useful for appending query parameters.
extstring[]The file extensions to be considered. By default the following file extensions are processed:
js
,
map
,
jsbundle
, and
bundle
.

setCommits settings

With

setCommits
you can configure

OptionTypeRequiredDescription
repostring
if auto === false
The full git repo name as defined in Sentry. Required if
auto
option is not
true
, otherwise optional.
commitstring
if auto === false
The current (most recent) commit in the release. Required if
auto
option is not
true
, otherwise optional.
previousCommitstringThe last commit of the previous release. Defaults to the most recent commit of the previous release in Sentry, or if no previous release is found, 10 commits back from
commit
.
autobooleanAutomatically set
commit
and
previousCommit
. Defaults
commit
to
HEAD
and
previousCommit
as described above. Overrides other options
ignoreMissingbooleanWhen 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.
ignoreEmptybooleanWhen the flag is set, command will not fail and just exit silently if no new commits for a given release have been found.

Tests

At the moment we got unit tests for plugin functions. You can run them by running

yarn test

Also there will appear e2e tests soon.

Author

👤 ikenfin

Thanks

Thank you to all contributors and users of this plugin. Knowing that so many people found this plugin helpful is really motivating me!

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator