sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.09k stars 126 forks source link

Function: nodejs.esbuild options are not getting applied #568

Open leon opened 2 weeks ago

leon commented 2 weeks ago

When supplying a custom esbuild config to Function it's not getting applied

const myFunction = new sst.aws.Function('MyFunction', {
  handler: 'src/main.handler',
  url: true,
  nodejs: {
    install: [
      '@nestjs/platform-express',
      '@nestjs/microservices*',
      '@nestjs/websockets*',
      '@fastify/static',
      '@fastify/view',
    ],
    esbuild: {
      plugins: [tscPlugin()],
    },
  },
})
leon commented 2 weeks ago

A potential problem I see is that we are unmarshalling esbuild from json. Does that mean that the plugin that is a javascript function won't get converted to go? https://github.com/sst/ion/blob/dev/pkg/runtime/node.go#L70

How does esbuild handle the conversion from javascript to go?

jayair commented 6 days ago

@leon I was following your messages in Discord, did you make some progress on this?

leon commented 6 days ago

No unfortunately not. Tried a couple of things but got stuck.

It's a bit complicated because of the typescript / go marshaling.

Hope someone else can look at it soon 🤓

thdxr commented 5 days ago

yeah this is quite tricky - we used to require you to pass in a path to a file that loaded the plugins, but don't really want to go back to that

we might not be able to support esbuild plugins

leon commented 5 days ago

A solution we could do is add a config Boolean to function called experimentalDecorators which in turn adds an esbuild plugin that compiles using typescript.

Only a couple of lines of code is needed.

What do you think? 🤔