-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e32aa4
commit 0988be0
Showing
5 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './server'; | ||
export * from './vite'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './sentrySolidStartVite'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Plugin } from 'vite'; | ||
import { makeSourceMapsVitePlugin } from './sourceMaps'; | ||
import type { SentrySolidStartPluginOptions } from './types'; | ||
|
||
/** | ||
* Various Sentry vite plugins to be used for SolidStart. | ||
*/ | ||
export const sentrySolidStartVite = (options: SentrySolidStartPluginOptions): Plugin[] => { | ||
const sentryPlugins: Plugin[] = []; | ||
|
||
if (process.env.NODE_ENV !== 'development') { | ||
if (options.sourceMapsUploadOptions?.enabled ?? true) { | ||
sentryPlugins.push(...makeSourceMapsVitePlugin(options)); | ||
} | ||
} | ||
|
||
return sentryPlugins; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { sentryVitePlugin } from '@sentry/vite-plugin'; | ||
import type { Plugin } from 'vite'; | ||
import type { SentrySolidStartPluginOptions } from './types'; | ||
|
||
/** | ||
* A Sentry plugin for SolidStart to enable source maps and use | ||
* @sentry/vite-plugin to automatically upload source maps to Sentry. | ||
* @param {SourceMapsOptions} options | ||
*/ | ||
export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions): Plugin[] { | ||
const { authToken, debug, org, project, sourceMapsUploadOptions } = options; | ||
return [ | ||
{ | ||
name: 'sentry-solidstart-source-maps', | ||
apply: 'build', | ||
enforce: 'post', | ||
config(config) { | ||
const sourceMapsPreviouslyNotEnabled = !config.build?.sourcemap; | ||
if (debug && sourceMapsPreviouslyNotEnabled) { | ||
// eslint-disable-next-line no-console | ||
console.log('[Sentry SolidStart Plugin] Enabling source map generation'); | ||
if (!sourceMapsUploadOptions?.filesToDeleteAfterUpload) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`[Sentry SolidStart PLugin] We recommend setting the \`sourceMapsUploadOptions.filesToDeleteAfterUpload\` option to clean up source maps after uploading. | ||
[Sentry SolidStart Plugin] Otherwise, source maps might be deployed to production, depending on your configuration`, | ||
); | ||
} | ||
} | ||
return { | ||
...config, | ||
build: { | ||
...config.build, | ||
sourcemap: true, | ||
}, | ||
}; | ||
}, | ||
}, | ||
...sentryVitePlugin({ | ||
org: org ?? process.env.SENTRY_ORG, | ||
project: project ?? process.env.SENTRY_PROJECT, | ||
authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN, | ||
telemetry: sourceMapsUploadOptions?.telemetry ?? true, | ||
sourcemaps: { | ||
filesToDeleteAfterUpload: sourceMapsUploadOptions?.filesToDeleteAfterUpload ?? undefined, | ||
...sourceMapsUploadOptions?.unstable_sentryVitePluginOptions?.sourcemaps, | ||
}, | ||
_metaOptions: { | ||
telemetry: { | ||
metaFramework: 'solidstart', | ||
}, | ||
}, | ||
debug: debug ?? false, | ||
...sourceMapsUploadOptions?.unstable_sentryVitePluginOptions, | ||
}), | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import type { SentryVitePluginOptions } from '@sentry/vite-plugin'; | ||
|
||
type SourceMapsOptions = { | ||
/** | ||
* If this flag is `true`, and an auth token is detected, the Sentry SDK will | ||
* automatically generate and upload source maps to Sentry during a production build. | ||
* | ||
* @default true | ||
*/ | ||
enabled?: boolean; | ||
|
||
/** | ||
* If this flag is `true`, the Sentry plugin will collect some telemetry data and send it to Sentry. | ||
* It will not collect any sensitive or user-specific data. | ||
* | ||
* @default true | ||
*/ | ||
telemetry?: boolean; | ||
|
||
/** | ||
* A glob or an array of globs that specifies the build artifacts that should be deleted after the artifact | ||
* upload to Sentry has been completed. | ||
* | ||
* @default [] - By default no files are deleted. | ||
* | ||
* The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob) | ||
*/ | ||
filesToDeleteAfterUpload?: string | Array<string>; | ||
|
||
/** | ||
* Options to further customize the Sentry Vite Plugin (@sentry/vite-plugin) behavior directly. | ||
* Options specified in this object take precedence over the options specified in | ||
* the `sourcemaps` and `release` objects. | ||
* | ||
* @see https://www.npmjs.com/package/@sentry/vite-plugin/v/2.22.2#options which lists all available options. | ||
* | ||
* Warning: Options within this object are subject to change at any time. | ||
* We DO NOT guarantee semantic versioning for these options, meaning breaking | ||
* changes can occur at any time within a major SDK version. | ||
* | ||
* Furthermore, some options are untested with SvelteKit specifically. Use with caution. | ||
*/ | ||
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>; | ||
}; | ||
|
||
/** | ||
* Build options for the Sentry module. These options are used during build-time by the Sentry SDK. | ||
*/ | ||
export type SentrySolidStartPluginOptions = { | ||
/** | ||
* The auth token to use when uploading source maps to Sentry. | ||
* | ||
* Instead of specifying this option, you can also set the `SENTRY_AUTH_TOKEN` environment variable. | ||
* | ||
* To create an auth token, follow this guide: | ||
* @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens | ||
*/ | ||
authToken?: string; | ||
|
||
/** | ||
* The organization slug of your Sentry organization. | ||
* Instead of specifying this option, you can also set the `SENTRY_ORG` environment variable. | ||
*/ | ||
org?: string; | ||
|
||
/** | ||
* The project slug of your Sentry project. | ||
* Instead of specifying this option, you can also set the `SENTRY_PROJECT` environment variable. | ||
*/ | ||
project?: string; | ||
|
||
/** | ||
* Options for the Sentry Vite plugin to customize the source maps upload process. | ||
*/ | ||
sourceMapsUploadOptions?: SourceMapsOptions; | ||
|
||
/** | ||
* Enable debug functionality of the SDK during build-time. | ||
* Enabling this will give you, for example logs about source maps. | ||
*/ | ||
debug?: boolean; | ||
}; |