|
1 | 1 | import { fileURLToPath } from 'url' |
2 | | -import { resolve, posix } from 'path' |
| 2 | +import { resolve } from 'path' |
3 | 3 | import { defu } from 'defu' |
4 | 4 | import type { ConsolaInstance } from 'consola' |
5 | 5 | import type { Configuration as WebpackConfig } from 'webpack' |
6 | | -import type { SentryCliPluginOptions } from '@sentry/webpack-plugin' |
| 6 | +import type { SentryWebpackPluginOptions } from '@sentry/webpack-plugin' |
7 | 7 | import type { Options } from '@sentry/types' |
8 | 8 | import * as Sentry from '@sentry/node' |
9 | 9 | import { addPluginTemplate, addTemplate, addWebpackPlugin } from './kit-shim' |
10 | 10 | import type { Nuxt } from './kit-shim' |
11 | 11 | import type { ModuleConfiguration } from './types/configuration' |
12 | | -import { clientSentryEnabled, serverSentryEnabled, envToBool, canInitialize } from './utils' |
| 12 | +import { clientSentryEnabled, serverSentryEnabled, canInitialize } from './utils' |
13 | 13 | import { resolveRelease, ResolvedClientOptions, resolveClientOptions, ResolvedServerOptions, resolveServerOptions } from './options' |
14 | 14 | import type { SentryHandlerProxy } from './options' |
15 | 15 |
|
@@ -62,77 +62,40 @@ export async function buildHook (nuxt: Nuxt, moduleOptions: ModuleConfiguration, |
62 | 62 | } |
63 | 63 | } |
64 | 64 |
|
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> { |
66 | 66 | let WebpackPlugin: typeof import('@sentry/webpack-plugin') |
67 | 67 | try { |
68 | 68 | WebpackPlugin = await (import('@sentry/webpack-plugin').then(m => m.default || m)) |
69 | 69 | } catch { |
70 | 70 | throw new Error('The "@sentry/webpack-plugin" package must be installed as a dev dependency to use the "publishRelease" option.') |
71 | 71 | } |
72 | 72 |
|
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 = {} |
87 | 76 | } |
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 = [] |
93 | 79 | } |
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] |
96 | 82 | } |
97 | | - |
98 | | - publishRelease.release = options.config.release || publishRelease.release || await resolveRelease(options) |
99 | | - |
100 | 83 | 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 = {} |
106 | 85 | } |
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 |
124 | 92 | } |
125 | 93 |
|
126 | 94 | for (const config of webpackConfigs) { |
127 | 95 | config.devtool = options.sourceMapStyle |
| 96 | + config.plugins = config.plugins || [] |
| 97 | + config.plugins.push(WebpackPlugin.sentryWebpackPlugin(publishRelease)) |
128 | 98 | } |
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)) |
136 | 99 | } |
137 | 100 |
|
138 | 101 | export async function initializeServerSentry (nuxt: Nuxt, moduleOptions: ModuleConfiguration, sentryHandlerProxy: SentryHandlerProxy, logger: ConsolaInstance): Promise<void> { |
|
0 commit comments