Giter VIP home page Giter VIP logo

Comments (25)

simonc avatar simonc commented on May 13, 2024 8

For anyone new to esbuild and finding this page, @ffxsam's code works but you need to specify write: false in the options for args.outputFiles to be present.

# serverless.yml
custom:
  esbuild:
    plugins: plugins.js # file that contains the sourcemap-upload code
    sourcemap: external # using 'external' here as we only need the map files
    write: false

from serverless-esbuild.

rafael-lua avatar rafael-lua commented on May 13, 2024 5

@amitUpscale

I did, and it seems to have worked well for now.

For esbuild-serverless configuration, we have:

  esbuild:
    bundle: true
    minify: false
    sourcemap: external # we had to set this to external
    sourcesContent: true
    exclude: ['aws-sdk']
    target: 'node18'
    platform: 'node'
    plugins: esbuildPlugins.js # we declare an external plugin

And for the plugin file, we have:

const { sentryEsbuildPlugin } = require('@sentry/esbuild-plugin')

module.exports = [
  sentryEsbuildPlugin({
    org: 'my-org',
    project: 'the-sentry-project',
    authToken: process.env.SENTRY_AUTH_TOKEN,
    release: {
      name: process.env.APP_VERSION, // would be your release version
      finalize: process.env.SENTRY_RELEASE_FINALIZE === 'true', // we have CI for beta and prod. We only finalize on prod.
      dist: 'server',
    },
  }),
]

With that, just by running the serverless deploy command, sentry will take care of uploading the source files. We did it remix, and this is the way for us to send the server side source-maps.

from serverless-esbuild.

ffxsam avatar ffxsam commented on May 13, 2024 4

I've been working on it, and making good progress. So far, this will save out source maps to their own folder. The last part is to just have this execute sentry-cli to upload them.

const fs = require('fs');
const path = require('path');

const envPlugin = {
  name: 'upload-sourcemaps',
  setup(build) {
    build.onEnd(args => {
      for (const file of args.outputFiles) {
        const { base, dir } = path.parse(file.path);

        if (/\.map$/.test(file.path)) {
          const funcDir = dir.replace(/.*\.build\//, '')

          fs.mkdirSync(`./.sourcemaps/${funcDir}`, { recursive: true });
          fs.writeFileSync(`./.sourcemaps/${funcDir}/${base}`, file.contents);

          continue;
        }


        fs.mkdirSync(dir, { recursive: true });
        fs.writeFileSync(file.path, file.contents);
      }
    });
  },
};

module.exports = [envPlugin];

from serverless-esbuild.

olup avatar olup commented on May 13, 2024 2

Or you could leave the source map where they are and feed the path to sentry cli. In any case, you should open a repo. I am sure many teams would be happy to have such a plugin for esbuild (in a serverless-esbuild project or other). Should we close this issue as it is not specifically linked to serverless-esbuild ?

from serverless-esbuild.

henriquecarv avatar henriquecarv commented on May 13, 2024 2

When combining this solution with typescript, has anybody experienced your stack trace referring to the minified/bundled .js file instead of its .ts file?

from serverless-esbuild.

olup avatar olup commented on May 13, 2024 1

Maybe more of a esbuild plugin to build ?

from serverless-esbuild.

ffxsam avatar ffxsam commented on May 13, 2024 1

Sure!

from serverless-esbuild.

atwoodjw avatar atwoodjw commented on May 13, 2024 1

The esbuild plugin automatically creates releases and upload source maps when bundling the app, but serverless-esbuild bundles in response to multiple serverless lifecycle hooks (e.g. package, deploy, invoke local, offline, etc.) While appropriate for package and deploy, I don't think we want the plugin creating releases and uploading source maps when invoking a function locally or running offline.

To be useful in the context of serverless-esbuild, I think we need a way to conditionally use the plugin based on serverless lifecycle hooks.

from serverless-esbuild.

cpcwood avatar cpcwood commented on May 13, 2024 1

Following @rafael-lua's comment 🙌🏻 I also managed to upload sourcemaps and remove them from the zip by specifying them in the sourcemaps.filesToDeleteAfterUpload option, e.g.

const { sentryEsbuildPlugin } = require('@sentry/esbuild-plugin')

module.exports = [
  sentryEsbuildPlugin({
    org: 'my-org',
    project: 'the-sentry-project',
    authToken: process.env.SENTRY_AUTH_TOKEN,
    sourcemaps: {
      assets: ['./.esbuild/.build/**/*'],
      filesToDeleteAfterUpload: ['./.esbuild/.build/**/*.js.map']
    }
  })
]

from serverless-esbuild.

ffxsam avatar ffxsam commented on May 13, 2024

@olup I was just looking into this, but since plugins are experimental, I couldn't find any documentation.

I looked through the source code a bit, and I didn't see any way for a plugin to see which files were saved as a result of the build process.

Correction: looks like if I set the write option to false, then my plugin gets a full array of files with their contents as Uint8Array objects. So, I'm thinking I might be able to filter this list and save the .map files in a separate folder, then spawn a sentry-cli process to upload the source maps. This could work!

Now I just need to figure out where to save the .js files so Serverless can find them & deploy them to AWS, and how/where to save the .map files.

from serverless-esbuild.

olup avatar olup commented on May 13, 2024

Thing is, packaging the js file is a bit involved and is partly the reason this lib exists. The code has been refined to cover many edge case. I wonder if there is a way to have an esbuild plugin that can work alongside normal operations of this lib.

from serverless-esbuild.

olup avatar olup commented on May 13, 2024

Maybe something around https://esbuild.github.io/plugins/#resolve-callbacks ? There is quite a bit of doc to fiddle around.

from serverless-esbuild.

ffxsam avatar ffxsam commented on May 13, 2024

Leaving the source maps where they're placed by esbuild would include them in the ZIP file that goes up to AWS, and that's not necessary.

I'll absolutely create a public repo for this once it's done!

from serverless-esbuild.

olup avatar olup commented on May 13, 2024

Hi there, can we close this as it will be handles by some esbuild plugin ?

from serverless-esbuild.

Steakeye avatar Steakeye commented on May 13, 2024

I'm converting a webpack build over to ESBuild and I've come across this exact requirement; does anyone know if a plugin has been released to handle this?

from serverless-esbuild.

floydspace avatar floydspace commented on May 13, 2024

hi @Steakeye, I don't this the plugin exists as npm package, you can try using the code snipped suggested by @ffxsam

from serverless-esbuild.

kopertop avatar kopertop commented on May 13, 2024

@ffxsam did you ever make a public plugin for this? this is still the top google search result for this issue so I think it would be helpful if there was a final resolution here.

from serverless-esbuild.

ffxsam avatar ffxsam commented on May 13, 2024

@kopertop I didn't post it officially anywhere, no. I've since moved to Serverless Stack, so I had to modify my plugin code a bit.

from serverless-esbuild.

atwoodjw avatar atwoodjw commented on May 13, 2024

@henriquecarv Yes. Did you ever figure this out?

from serverless-esbuild.

henriquecarv avatar henriquecarv commented on May 13, 2024

@atwoodjw I did not figure it out back then, so I stopped trying after a while. Might get back to it again sometime later :)

from serverless-esbuild.

epiphone avatar epiphone commented on May 13, 2024

Sentry now provides an esbuild plugin for uploading source maps: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/esbuild.

from serverless-esbuild.

walterholohan avatar walterholohan commented on May 13, 2024

@epiphone thank you for this, I will give it a go

from serverless-esbuild.

simonc avatar simonc commented on May 13, 2024

@walterholohan if you get it to work with serverless I'd be very interested in your config 😅

Merry xmas everyone 🎁🎄

from serverless-esbuild.

walterholohan avatar walterholohan commented on May 13, 2024

Hopefully @epiphone can provide his magic sauce on how he got it working

from serverless-esbuild.

 avatar commented on May 13, 2024

did anyone try out using Sentry with serverless-esbuild and sentry esbuild plugin

from serverless-esbuild.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.