Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Allow to specify minifiedUrl directly #8

Open
wata727 opened this issue Apr 28, 2018 · 10 comments
Open

Feature request: Allow to specify minifiedUrl directly #8

wata727 opened this issue Apr 28, 2018 · 10 comments
Labels
backlog We hope to fix this feature/bug in the future feature request Request for a new feature

Comments

@wata727
Copy link

wata727 commented Apr 28, 2018

Hi team,

We are using Bugsnag in our React app built by webpack. In order to get more readable stacktrace, I'd like to upload source map when building it. However, it is deployed as a different file name from generated by webpack. (eg. app.js -> app.[digest].js)

Currently, minifiedUrl is automatically determined from publicUrl and file name, but I'd like to specify minifiedUrl directly with wildcards. For example:

const { BugsnagSourceMapUploaderPlugin } = require('webpack-bugsnag-plugins')

module.exports = {
  entry: './app.js',
  devtool: 'source-map',
  output: {
    path: __dirname,
    filename: './bundle.js',
    publicPath: 'https://your-app.xyz/assets/'
  },
  plugins: [].concat(
    // It's a good idea to only run this plugin when you're building a bundle
    // that will be released, rather than for every development build
    isDistEnv
      ? new BugsnagSourceMapUploaderPlugin({
          apiKey: 'YOUR_API_KEY',
          appVersion: '1.2.3',
          minifiedUrl: 'https://your-app.xyz/assets/bundle.*.js'
        })
      : []
  )
}

WDYT?

@bengourley
Copy link
Contributor

Hey @wata727.

I think the use case you describe works when a webpack build results in a single output file. However, it is very common for webpack to output multiple "chunks". In which case a single minifiedUrl would not be sufficient.

This isn't the first time the flexibility of this logic has come up though – and I have a suggestion as to how we could make it better. Currently the minifiedUrl is determined using this logic:

return {
source: compilation.assets[source].existsAt,
map: compilation.assets[map].existsAt,
url: resolve(
// ensure publicPath has a trailing slash
publicPath.replace(/[^/]$/, '$&/'),
source
).toString()

If there was a configuration option for BugsnagSourceMapUploaderPlugin that took those components as input and returned the URL, would this enable you to fix your issue? e.g.

new BugsnagSourceMapUploaderPlugin({
  apiKey: 'YOUR_API_KEY',
  appVersion: '1.2.3',
  getMinifiedUrl: (publicPath, localPath) => {

    // the current/default behaviour
    return url.resolve(publicPath.replace(/[^/]$/, '$&/'), source).toString()

    // your use-case?
    return url.resolve(
      publicPath.replace(/[^/]$/, '$&/'),
      source.replace(/\.js$/, '.*.js')
    ).toString()

    // or more simply! (N.B. this won't scale if your
    // webpack build starts outputting multiple chunks)
    return 'https://your-app.xyz/assets/bundle.*.js'

  }
})

@wata727
Copy link
Author

wata727 commented May 1, 2018

Thanks @bengourley

Yes, currently we have a single output file. Maybe the getMinifiedUrl would be helpful for us. However, I guess a [name] is better if it can work. For example:

new BugsnagSourceMapUploaderPlugin({
  apiKey: 'YOUR_API_KEY',
  appVersion: '1.2.3',
  minifiedUrl: 'https://your-app.xyz/assets/[name].*.js'
})

By the way, now we are using own ruby scripts to upload source map to Bugsnag. We'd love to switch this plugin If supports this feature and Webpack4 :)

@bengourley bengourley added the scheduled Work is starting on this feature/bug label Jun 26, 2018
@bengourley
Copy link
Contributor

Hi @wata727. I'm just picking this up again to see what we can do about it, and I'd like to understand how/why your assets on disk don't have the [hash] component but they do in the browser URL.

Can you share with me a basic example that illustrates the problem? Thanks.

@wata727
Copy link
Author

wata727 commented Jan 7, 2019

Hi @bengourley. Thanks for your attention.

For historical reasons, we are giving a hash digest to assets in a way different from Webpack. In a Ruby on Rails project, because of helper methods, asset management by Sprockets is mainstream, and we are struggling to coexist with Webpack.

For the above reasons, in our project, Webpack builds code and Sprockets gives hash digests to assets.

@snmaynard
Copy link

We use rails and webpack and use the https://github.com/danethurber/webpack-manifest-plugin plugin to generate a json hash that rails then uses in the same way as it uses the sprockets asset manifest file.

There are also alternatives (https://github.com/rupurt/webpack-sprockets-rails-manifest-plugin) to solving this issue.

@wata727
Copy link
Author

wata727 commented Jan 8, 2019

Thanks for your information. However, I thought that this option helps us before completing to migrate to these plugins...
Since it is a workaround to the last, it is not a very important request for me now. Feel free to close this issue if necessary.

@ybiquitous
Copy link

Hi @bengourley,

I really want the feature recently but this issue can be reopened?

I create a patch and try it on my company system but it works!
Here is my patch:

ybiquitous@3f79313

diff --git a/source-map-uploader-plugin.js b/source-map-uploader-plugin.js
index 6a70295..94ad1d6 100644
--- a/source-map-uploader-plugin.js
+++ b/source-map-uploader-plugin.js
@@ -20,6 +20,7 @@ class BugsnagSourceMapUploaderPlugin {
     this.overwrite = options.overwrite
     this.endpoint = options.endpoint
     this.ignoredBundleExtensions = options.ignoredBundleExtensions || [ '.css' ]
+    this.minifiedUrl = options.minifiedUrl
     this.validate()
   }
 
@@ -103,12 +104,16 @@ class BugsnagSourceMapUploaderPlugin {
     const opts = {
       apiKey: this.apiKey,
       appVersion: this.appVersion,
-      minifiedUrl: sm.url,
       minifiedFile: sm.source,
       sourceMap: sm.map
     }
     if (this.endpoint) opts.endpoint = this.endpoint
     if (this.overwrite) opts.overwrite = this.overwrite
+    if (typeof this.minifiedUrl === 'function') {
+      opts.minifiedUrl = this.minifiedUrl(sm.url)
+    } else {
+      opts.minifiedUrl = sm.url
+    }
     return opts
   }
 }

Of course, this patch is just a PoC and it seems that there must be a better way, but it works on my case at least.

I would be so happy if you could re-consider the issue. 🙏

@ybiquitous
Copy link

Sorry, I missed the usage. It is as follow:

new BugsnagSourceMapUploaderPlugin({
  apiKey: process.env.BUGSNAG_API_KEY,
  appVersion: process.env.BUGSNAG_APP_VERSION,
  overwrite: true,
  minifiedUrl: (url) => `http*://*foo-cdn.net/${url.replace(/^\/+/, '')}`,
})

@mattdyoung mattdyoung removed the scheduled Work is starting on this feature/bug label Jan 6, 2020
@mattdyoung mattdyoung reopened this Jan 6, 2020
@mattdyoung mattdyoung added backlog We hope to fix this feature/bug in the future feature request Request for a new feature labels Jan 6, 2020
@mattdyoung
Copy link
Contributor

Hi @ybiquitous

Now re-opened and we plan to take a fresh look at this when priorities allow.

@ybiquitous
Copy link

Thank you so much! I'm looking forward to good news 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog We hope to fix this feature/bug in the future feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

5 participants