Skip to content

Commit

Permalink
fix: released client sourcemaps don't have correct prefix (no /_nuxt/) (
Browse files Browse the repository at this point in the history
#155)

In c71d848 I've broken release of
client source maps by not setting `config.devtool = 'source-map'` for
the client build. I've missed the condition that returns early on client
build.

In 8e3e4d1 I've also attempted to
configure urlPrefix separately for client and server but I've missed
the fact that client and server source maps were not uploaded
separately but there was only one upload on building server (which
builds second). So the prefix that was actually used was the server
one.

Fix by going to previous logic of setting urlPrefix once (at the expense
of it being incorrect on the server). To fix that properly, we would
need to make two separate releases but that is non-trivial since
releasing can include source maps (client, server) and potentially also
commits. So the fix would have to be fairly elaborate to only release
client in one pass and potentially everything else on server build
(assuming there will be one).
  • Loading branch information
rchl authored Feb 14, 2020
1 parent d8546a5 commit 2c8bc83
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,37 @@ export default function SentryModule (moduleOptions) {
options.serverConfig = deepMerge.all([options.config, options.serverConfig])
options.clientConfig = deepMerge.all([options.config, options.clientConfig])

if (typeof options.webpackConfig.include === 'string') {
options.webpackConfig.include = [options.webpackConfig.include]
}

const { buildDir } = this.options
if (options.publishRelease) {
// 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.
const publicPath = join(this.options.router.base, this.options.build.publicPath)
options.webpackConfig.urlPrefix = publicPath.startsWith('/') ? `~${publicPath}` : publicPath

if (typeof options.webpackConfig.include === 'string') {
options.webpackConfig.include = [options.webpackConfig.include]
}

if (!options.disableServerRelease) {
options.webpackConfig.include.push(`${buildDir}/dist/server`)
}
if (!options.disableClientRelease) {
options.webpackConfig.include.push(`${buildDir}/dist/client`)
}
const { buildDir } = this.options

if (options.config.release && !options.webpackConfig.release) {
options.webpackConfig.release = options.config.release
}
if (!options.disableServerRelease) {
options.webpackConfig.include.push(`${buildDir}/dist/server`)
}
if (!options.disableClientRelease) {
options.webpackConfig.include.push(`${buildDir}/dist/client`)
}

if (options.attachCommits) {
options.webpackConfig.setCommits = {
auto: true
if (options.config.release && !options.webpackConfig.release) {
options.webpackConfig.release = options.config.release
}

if (options.repo) {
options.webpackConfig.setCommits.repo = options.repo
if (options.attachCommits) {
options.webpackConfig.setCommits = {
auto: true
}

if (options.repo) {
options.webpackConfig.setCommits.repo = options.repo
}
}
}

Expand Down Expand Up @@ -156,15 +163,13 @@ export default function SentryModule (moduleOptions) {

// Enable publishing of sourcemaps
if (!options.disabled) {
const { base } = this.options.router
const { publicPath } = this.options.build
const clientUrl = join(base, publicPath)
const clientUrlPrefix = clientUrl.startsWith('/') ? `~${clientUrl}` : clientUrl

this.extendBuild((config, { isClient, isModern, isDev }) => {
if (!options.publishRelease || isDev) {
return
}

config.devtool = 'source-map'

// when not in spa mode upload only at server build
if (isClient && this.options.mode !== 'spa') {
return
Expand All @@ -174,10 +179,6 @@ export default function SentryModule (moduleOptions) {
return
}

config.devtool = 'source-map'

options.webpackConfig.urlPrefix = isClient ? clientUrlPrefix : '~/'

config.plugins.push(new WebpackPlugin(options.webpackConfig))
logger.info('Enabling uploading of release sourcemaps to Sentry')
})
Expand Down

0 comments on commit 2c8bc83

Please sign in to comment.