floydspace / serverless-esbuild

💨 A Serverless framework plugin to bundle JavaScript and TypeScript with extremely fast esbuild
MIT License
453 stars 139 forks source link

Get `runtime` from the function level #471

Open duncanista opened 1 year ago

duncanista commented 1 year ago

Problem

Currently, you can only build for runtimes at the provider level.

provider:
  name: aws
  region: sa-east-1
  runtime: nodejs18.x

functions:
  hello-world:
    handler: index.handler

If I want to build multiple functions with different runtimes, I have to create another serverless.yml file, which is not convenient.

Proposed solution

I would like to build multiple functions with multiple runtimes. Getting the runtime from the function level.

provider:
  name: aws
  region: sa-east-1

functions:
  hello-world-node18:
    handler: index.handler
    runtime: nodejs18.x
   hello-world-node16:
    handler: index.handler
    runtime: nodejs16.x

Currently, this throws the following error:

Error:
AssertionError [ERR_ASSERTION]: not a supported runtime
    at new AssertionError (node:internal/assert/assertion_error:451:5)

Alternatives considered

Maybe also use the provider as a fallback?

Additional context

mklenbw commented 1 year ago

This issue is also affecting build with a different runtime as node or no runtime set at provider level.

The plugin throws a hard assertion if the runtime-provider is empty, although the functions have a valid runtime set.

It should be easy to solve.

@duncanista this should be considered a bug because it breaks deployments. The title is just missleading.

brettdh commented 1 year ago

Same for me; I want to use esbuild with just a single lambda. Most lambdas in my app are using a custom docker image (mostly Python).

davidworkman9 commented 1 year ago

I'm a few versions behind and was trying to upgrade. this use to work on v1.34.0. v1.35.0 seems to have broken this functionality.

andreas-wolf commented 9 months ago

Same problem here. esbuild is a dependency from another module. We don't use it directly since our provider runtime is python. V1.35.0 broke our build with assertIsSupportedRuntime(providerRuntime);