Skip to content

Commit d3ed0eb

Browse files
committed
feat(publishRelease)!: upgrade to webpack-plugin v2
BREAKING CHANGE: See migration guide at https://sentry.nuxtjs.org/guide/migration
1 parent 3b57cfb commit d3ed0eb

10 files changed

Lines changed: 194 additions & 135 deletions

File tree

docs/content/en/configuration/options.md

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,17 @@ The `dsn` is the only option that is required to enable Sentry reporting.
158158
159159
<alert type="info">
160160
161-
`@sentry/webpack-plugin@1` package must be installed manually as a dev dependency to be able to publish releases.
161+
`@sentry/webpack-plugin@2` package must be installed manually as a dev dependency to be able to publish releases.
162162
163163
</alert>
164164
165-
- Type: `Boolean` or [`WebpackPluginOptions`](https://github.com/getsentry/sentry-webpack-plugin)
165+
- Type: `Boolean` or [`SentryWebpackPluginOptions`](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/packages/bundler-plugin-core/src/types.ts)
166166
- Default: `process.env.SENTRY_PUBLISH_RELEASE || false`
167-
- Enables Sentry releases for better debugging using source maps. Uses [@sentry/webpack-plugin](https://github.com/getsentry/sentry-webpack-plugin).
167+
- Enables Sentry releases for better debugging using source maps. Uses [@sentry/webpack-plugin](https://github.com/getsentry/sentry-javascript-bundler-plugins/).
168168
- Publishing releases requires the organization slug, project name and the Sentry authentication token to be provided. Those can be provided either via an object value or [environment variables or a properties file](https://docs.sentry.io/product/cli/configuration/#sentry-cli-working-with-projects). So for example, when using the object value, you'd set `authToken`, `org` and `project` options, and when using the environment variables you'd set `SENTRY_AUTH_TOKEN`, `SENTRY_ORG` and `SENTRY_PROJECT`.
169169
- It's recommended to pass an object value to this option rather than using the boolean `true`. When using the boolean, you have to provide all required options through other means mentioned above.
170170
- The releases are only published when this option is enabled and at the same time you are NOT running in development (`nuxt dev`) mode.
171-
- See https://docs.sentry.io/workflow/releases for more information. Note that the Sentry CLI options mentioned in the documentation typically have a [@sentry/webpack-plugin](https://github.com/getsentry/sentry-webpack-plugin) equivalent.
171+
- See https://docs.sentry.io/workflow/releases for more information. Note that the Sentry CLI options mentioned in the documentation typically have a [@sentry/webpack-plugin](https://github.com/getsentry/sentry-javascript-bundler-plugins/) equivalent.
172172

173173
Example configuration:
174174

@@ -179,50 +179,37 @@ sentry: {
179179
authToken: '<token>',
180180
org: 'MyCompany',
181181
project: 'my-project',
182-
// Attach commits to the release (requires that the build triggered within a git repository).
183-
setCommits: {
184-
auto: true
182+
release: {
183+
// Attach commits to the release (requires that the build triggered within a git repository).
184+
setCommits: {
185+
auto: true
186+
}
185187
}
186188
}
187189
}
188190
```
189191

190-
Note that the module sets the following defaults when publishing is enabled:
191-
192-
```js
193-
{
194-
include: [], // automatically set at publishing time to relevant paths for the bundles that were built
195-
ignore: [
196-
'node_modules',
197-
'.nuxt/dist/client/img'
198-
],
199-
configFile: '.sentryclirc',
200-
release: '', // defaults to the value of "config.release" which can either be set manually or is determined automatically through `@sentry/cli`
201-
}
202-
```
203-
204-
- Providing custom values for `include` or `ignore` will result in provided values getting appended to default values.
192+
- module by default includes all js/map assets generated during the build step.
205193

206194
### sourceMapStyle
207195

208196
- Type: `String`
209-
- Default: `source-map`
210-
- Only has effect when `publishRelease` is enabled
197+
- Default: `hidden-source-map`
198+
- Only has an effect when `publishRelease` is enabled
211199
- The type of source maps generated when publishing release to Sentry. See https://webpack.js.org/configuration/devtool for a list of available options
212-
- **Note**: Consider using `hidden-source-map` instead. For most people, that should be a better option but due to it being a breaking change, it won't be set as the default until next major release
213200

214201
### disableServerRelease
215202

216203
- Type: `Boolean`
217204
- Default: `process.env.SENTRY_DISABLE_SERVER_RELEASE || false`
218-
- Only has effect when `publishRelease` is enabled
205+
- Only has an effect when `publishRelease` is enabled
219206
- See https://docs.sentry.io/workflow/releases for more information
220207

221208
### disableClientRelease
222209

223210
- Type: `Boolean`
224211
- Default: `process.env.SENTRY_DISABLE_CLIENT_RELEASE || false`
225-
- Only has effect when `publishRelease` is enabled
212+
- Only has an effect when `publishRelease` is enabled
226213
- See https://docs.sentry.io/workflow/releases for more information
227214

228215
### clientIntegrations

docs/content/en/getting-started/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ In Typescript or type-checked JavaScript projects, add `@nuxtjs/sentry` to the `
6565

6666
<alert type="info">
6767

68-
The otherwise optional package `@sentry/webpack-plugin@1` has to be installed for types to be fully working.
68+
The otherwise optional package `@sentry/webpack-plugin@2` has to be installed for types to be fully working.
6969

7070
If not using the relevant functionality (`publishRelease` option is not enabled) then this package can be installed as dev-only dependency.
7171

docs/content/en/guide/migration.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ category: Guide
77

88
Follow this guide to upgrade from one major version to the other.
99

10+
## Upgrading from v7 to v8
11+
12+
Breaking changes only affect the `publishRelease` and the (related to `publishRelease`) `sourceMapStyle` option.
13+
14+
When using the `publishRelease` option, the `@sentry/webpack-plugin` package needs to be updated from version 1.x to 2.x.
15+
16+
The options supported by the `publishRelease` object have also changed slightly:
17+
- `configFile`, `dryRun`, `include`, `sourcemap` and `urlPrefix` options are no longer supported.
18+
- `setCommits` option moved to `release.setCommits`
19+
- `errorHandler` option signature has changed - see https://sentry.nuxtjs.org/guide/releases
20+
21+
The default value of the `sourceMapStyle` option has changed from `source-map` to `hidden-source-map` since the new version of the webpack plugin can handle source maps without having to reference them directly in the source files.
22+
23+
You can also check the [`@sentry/webpack-plugin` official migration guide](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/main/MIGRATION.md#upgrading-to-2x) for more information although not everything mentioned there applies to this module.
24+
1025
## Upgrading from v6 to v7
1126

1227
Sentry SDK dependencies updated from v6 to v7. Please read about breaking changes in Sentry SDK's [Upgrading from v6.x to v7.x](https://github.com/getsentry/sentry-javascript/blob/master/MIGRATION.md#upgrading-from-6x-to-7x) document.

docs/content/en/guide/releases.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ category: Guide
1414

1515
Follow the following steps to create and publish releases to Sentry.
1616

17-
1. Install the `@sentry/webpack-plugin@1` package as a dev dependency.
18-
2. Enable the [publishRelease](http://localhost:3000/configuration/options#publishrelease) option. Follow the link for mode detailed explanation of available options.
17+
1. Install the `@sentry/webpack-plugin@2` package as a dev dependency.
18+
2. Enable the [publishRelease](/configuration/options#publishrelease) option. Follow the link for mode detailed explanation of available options.
1919

2020
<alert type="info">
2121

@@ -32,8 +32,8 @@ On error during publishing, the build will be interrupted. If you would instead
3232
sentry: {
3333
publishRelease: {
3434
// other options...
35-
errorHandler(err, invokeErr, compilation) {
36-
compilation.warnings.push(`Sentry Release Error: ${err.message}`);
35+
errorHandler(error) {
36+
console.error(`Sentry Release Error: ${error.message}`);
3737
},
3838
},
3939
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"release": "release-it",
4545
"test": "yarn prepack && vitest run && yarn lint:fixture && yarn typecheck",
4646
"test:watch": "vitest",
47-
"typecheck": "tsc",
47+
"typecheck": "yarn dev:prepare && tsc",
4848
"coverage": "codecov"
4949
},
5050
"lint-staged": {
@@ -78,7 +78,7 @@
7878
"@nuxtjs/module-test-utils": "1.6.3",
7979
"@release-it/conventional-changelog": "7.0.0",
8080
"@sentry/profiling-node": "^1.1.2",
81-
"@sentry/webpack-plugin": "1.20.1",
81+
"@sentry/webpack-plugin": "2.7.1",
8282
"@size-limit/file": "^8.2.6",
8383
"@types/hash-sum": "1.0.0",
8484
"@types/lodash.mergewith": "4.6.7",

src/hooks.ts

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { fileURLToPath } from 'url'
2-
import { resolve, posix } from 'path'
2+
import { resolve } from 'path'
33
import { defu } from 'defu'
44
import type { ConsolaInstance } from 'consola'
55
import type { Configuration as WebpackConfig } from 'webpack'
6-
import type { SentryCliPluginOptions } from '@sentry/webpack-plugin'
6+
import type { SentryWebpackPluginOptions } from '@sentry/webpack-plugin'
77
import type { Options } from '@sentry/types'
88
import * as Sentry from '@sentry/node'
99
import { addPluginTemplate, addTemplate, addWebpackPlugin } from './kit-shim'
1010
import type { Nuxt } from './kit-shim'
1111
import type { ModuleConfiguration } from './types/configuration'
12-
import { clientSentryEnabled, serverSentryEnabled, envToBool, canInitialize } from './utils'
12+
import { clientSentryEnabled, serverSentryEnabled, canInitialize } from './utils'
1313
import { resolveRelease, ResolvedClientOptions, resolveClientOptions, ResolvedServerOptions, resolveServerOptions } from './options'
1414
import type { SentryHandlerProxy } from './options'
1515

@@ -62,77 +62,40 @@ export async function buildHook (nuxt: Nuxt, moduleOptions: ModuleConfiguration,
6262
}
6363
}
6464

65-
export async function webpackConfigHook (nuxt: Nuxt, webpackConfigs: WebpackConfig[], options: ModuleConfiguration & { publishRelease: SentryCliPluginOptions }, logger: ConsolaInstance): Promise<void> {
65+
export async function webpackConfigHook (nuxt: Nuxt, webpackConfigs: WebpackConfig[], options: ModuleConfiguration, logger: ConsolaInstance): Promise<void> {
6666
let WebpackPlugin: typeof import('@sentry/webpack-plugin')
6767
try {
6868
WebpackPlugin = await (import('@sentry/webpack-plugin').then(m => m.default || m))
6969
} catch {
7070
throw new Error('The "@sentry/webpack-plugin" package must be installed as a dev dependency to use the "publishRelease" option.')
7171
}
7272

73-
const publishRelease: SentryCliPluginOptions = defu({}, options.publishRelease)
74-
const nuxtOptions = nuxt.options
75-
76-
if (!publishRelease.urlPrefix) {
77-
// Set urlPrefix to match resources on the client. That's not technically correct for the server source maps, but it is what it is for now.
78-
if (typeof (nuxtOptions.router.base) === 'string' && typeof (nuxtOptions.build.publicPath) === 'string') {
79-
const publicPath = posix.join(nuxtOptions.router.base, nuxtOptions.build.publicPath)
80-
publishRelease.urlPrefix = publicPath.startsWith('/') ? `~${publicPath}` : publicPath
81-
}
82-
}
83-
84-
if (!Array.isArray(publishRelease.include)) {
85-
const { include } = publishRelease
86-
publishRelease.include = [...(include ? [include] : [])]
73+
const publishRelease: SentryWebpackPluginOptions = defu(options.publishRelease)
74+
if (!publishRelease.sourcemaps) {
75+
publishRelease.sourcemaps = {}
8776
}
88-
89-
const { buildDir } = nuxtOptions
90-
91-
if (!options.disableServerRelease) {
92-
publishRelease.include.push(`${buildDir}/dist/server`)
77+
if (!publishRelease.sourcemaps.ignore) {
78+
publishRelease.sourcemaps.ignore = []
9379
}
94-
if (!options.disableClientRelease) {
95-
publishRelease.include.push(`${buildDir}/dist/client`)
80+
if (!Array.isArray(publishRelease.sourcemaps.ignore)) {
81+
publishRelease.sourcemaps.ignore = [publishRelease.sourcemaps.ignore]
9682
}
97-
98-
publishRelease.release = options.config.release || publishRelease.release || await resolveRelease(options)
99-
10083
if (!publishRelease.release) {
101-
// We've already tried to determine "release" manually using Sentry CLI so to avoid webpack
102-
// plugin crashing, we'll just bail here.
103-
logger.warn('Sentry release will not be published because "config.release" was not set nor it ' +
104-
'was possible to determine it automatically from the repository')
105-
return
84+
publishRelease.release = {}
10685
}
107-
108-
const attachCommits = envToBool(process.env.SENTRY_AUTO_ATTACH_COMMITS)
109-
110-
if (attachCommits) {
111-
publishRelease.setCommits = publishRelease.setCommits || {}
112-
113-
const { setCommits } = publishRelease
114-
115-
if (setCommits.auto === undefined) {
116-
setCommits.auto = true
117-
}
118-
119-
const repo = process.env.SENTRY_RELEASE_REPO || ''
120-
121-
if (repo && setCommits.repo === undefined) {
122-
setCommits.repo = repo
123-
}
86+
publishRelease.release.name = publishRelease.release.name || options.config.release || await resolveRelease(options)
87+
if (!publishRelease.release.name) {
88+
// We've already tried to determine "release" manually using Sentry CLI so to avoid webpack plugin crashing, we'll just bail here.
89+
logger.warn('Sentry release will not be published because "config.release" or "publishRelease.release.name" was not set nor it ' +
90+
'was possible to determine it automatically from the repository.')
91+
return
12492
}
12593

12694
for (const config of webpackConfigs) {
12795
config.devtool = options.sourceMapStyle
96+
config.plugins = config.plugins || []
97+
config.plugins.push(WebpackPlugin.sentryWebpackPlugin(publishRelease))
12898
}
129-
130-
// Add WebpackPlugin to the last build config
131-
132-
const config = webpackConfigs[webpackConfigs.length - 1]
133-
134-
config.plugins = config.plugins || []
135-
config.plugins.push(new WebpackPlugin(publishRelease))
13699
}
137100

138101
export async function initializeServerSentry (nuxt: Nuxt, moduleOptions: ModuleConfiguration, sentryHandlerProxy: SentryHandlerProxy, logger: ConsolaInstance): Promise<void> {

src/module.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fileURLToPath } from 'url'
22
import { defu } from 'defu'
33
import { resolvePath } from 'mlly'
4-
import type { SentryCliPluginOptions } from '@sentry/webpack-plugin'
4+
import type { SentryWebpackPluginOptions } from '@sentry/webpack-plugin'
55
import { captureException, withScope } from '@sentry/node'
66
import type { Configuration as WebpackConfig } from 'webpack'
77
import { defineNuxtModule, isNuxt2, useLogger } from './kit-shim'
@@ -33,7 +33,7 @@ export default defineNuxtModule<ModuleConfiguration>({
3333
disableServerRelease: envToBool(process.env.SENTRY_DISABLE_SERVER_RELEASE) || false,
3434
disableClientRelease: envToBool(process.env.SENTRY_DISABLE_CLIENT_RELEASE) || false,
3535
logMockCalls: true,
36-
sourceMapStyle: 'source-map',
36+
sourceMapStyle: 'hidden-source-map',
3737
tracing: false,
3838
clientIntegrations: {
3939
ExtraErrorData: {},
@@ -56,17 +56,15 @@ export default defineNuxtModule<ModuleConfiguration>({
5656
requestHandlerConfig: {},
5757
}),
5858
async setup (options, nuxt) {
59-
const defaultsPublishRelease: SentryCliPluginOptions = {
60-
include: [],
61-
ignore: [
62-
'node_modules',
63-
'.nuxt/dist/client/img',
64-
],
65-
configFile: '.sentryclirc',
59+
const defaultsPublishRelease: SentryWebpackPluginOptions = {
60+
sourcemaps: {
61+
ignore: [
62+
'node_modules/**/*',
63+
],
64+
},
6665
}
6766

6867
if (options.publishRelease) {
69-
// @ts-expect-error Defu introduces "null" value in its merged types which cause error.
7068
options.publishRelease = defu(options.publishRelease, defaultsPublishRelease)
7169
}
7270

@@ -155,7 +153,7 @@ export default defineNuxtModule<ModuleConfiguration>({
155153
// Enable publishing of sourcemaps
156154
if (options.publishRelease && !options.disabled && !nuxt.options.dev) {
157155
if (isNuxt2()) {
158-
nuxt.hook('webpack:config', (webpackConfigs: WebpackConfig[]) => webpackConfigHook(nuxt, webpackConfigs, options as ModuleConfiguration & { publishRelease: SentryCliPluginOptions }, logger))
156+
nuxt.hook('webpack:config', (webpackConfigs: WebpackConfig[]) => webpackConfigHook(nuxt, webpackConfigs, options, logger))
159157
}
160158
}
161159
},

src/types/configuration.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Options as SentryOptions, IntegrationClass } from '@sentry/types'
33
import * as PluggableIntegrations from '@sentry/integrations'
44
import { BrowserTracing, Integrations as BrowserIntegrations, Replay, vueRouterInstrumentation } from '@sentry/vue'
55
import { Options as SentryVueOptions, TracingOptions as SentryVueTracingOptions } from '@sentry/vue/types/types'
6-
import { SentryCliPluginOptions } from '@sentry/webpack-plugin'
6+
import { SentryWebpackPluginOptions } from '@sentry/webpack-plugin'
77
import { Integrations as NodeIntegrations, NodeOptions, Handlers } from '@sentry/node'
88

99
type IntegrationsConfig<T extends Record<keyof T, IntegrationClass<unknown>>> = Partial<{
@@ -48,8 +48,8 @@ export interface ModuleConfiguration {
4848
initialize: boolean
4949
lazy: boolean | LazyConfiguration
5050
logMockCalls: boolean
51-
/** See available options at https://github.com/getsentry/sentry-webpack-plugin */
52-
publishRelease: boolean | Partial<SentryCliPluginOptions>
51+
/** See available options at https://docs.sentry.io/platforms/node/sourcemaps/uploading/webpack/ */
52+
publishRelease: boolean | SentryWebpackPluginOptions
5353
runtimeConfigKey: string
5454
serverConfig: NodeOptions | string
5555
serverIntegrations: ServerIntegrations

test/fixture/default/nuxt.config.cjs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ const config = {
3030
},
3131
customClientIntegrations: '~/config/custom-client-integrations.js',
3232
tracing: true,
33-
publishRelease: {
34-
authToken: 'fakeToken',
35-
org: 'MyCompany',
36-
project: 'TestProject',
37-
dryRun: true,
38-
},
3933
},
4034
}
4135

0 commit comments

Comments
 (0)