denoland / deploy_feedback

For reporting issues with Deno Deploy
https://deno.com/deploy
74 stars 5 forks source link

[Bug]: emitDecoratorMetadata not respected in Deno Deploy #633

Open cleverplatypus opened 6 months ago

cleverplatypus commented 6 months ago

Problem description

While experimentalDecorators setting in deno.json is now respected since https://github.com/denoland/deno/pull/22521 emitDecoratorMetadata is not. Unlike the former issue, it doesn't seem to be an issue with deno compile. In fact, compiled deno apps work as expected locally.

This issue makes decorator-based dependency injection not viable in deno apps in Deploy.

Steps to reproduce

deno.json

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true
    }
}

server.ts

import { Reflect } from 'https://deno.land/x/deno_reflect@v0.2.1/mod.ts';

export type ClassConstructor<T = unknown> = new (...args: any[]) => T;

function Annotation<T>() {
  return (_: ClassConstructor<T>): void => {};
}

class Custom {

}

@Annotation()
class Test {
  constructor(name: string, age: number, custom : Custom) {}
}

Deno.serve((_request: Request) => {
  const metadata = Reflect.getMetadata('design:paramtypes', Test);

  return new Response(metadata?.map((x: ClassConstructor) => x.name).join(', ') || 'No metadata. But it should output "String, Number, Custom"');
});

Expected behavior

Classes annotated with TC39 decorators should emit metadata that should be made available in design:paramtypes.

Environment

works in this environment

deno 1.41.1 (release, x86_64-apple-darwin) v8 12.1.285.27 typescript 5.3.3

doesn't work in

Deno Deploy (as of March 10th 2024)

Possible solution

No response

Additional context

No response

cleverplatypus commented 5 months ago

@bartlomieju No feedback yet?