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

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

Open
cleverplatypus opened this issue Mar 9, 2024 · 3 comments
Open

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

cleverplatypus opened this issue Mar 9, 2024 · 3 comments

Comments

@cleverplatypus
Copy link

Problem description

While experimentalDecorators setting in deno.json is now respected since denoland/deno#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/[email protected]/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
Copy link
Author

@bartlomieju No feedback yet?

@dirkluijk
Copy link

Not sure if this is any help, but I've been working on a new dependency injection library for JavaScript that does not rely on experimentalDecorators or emitDecoratorMetadata, but solely uses stage 3 class decorators that work fine with Deno.

Not trying to advertise (it's a non-profit open-source project anyway), but just to mention alternatives that work well on Bun.

@thomas3577
Copy link

Not sure if this is any help, but I've been working on a new dependency injection library for JavaScript that does not rely on experimentalDecorators or emitDecoratorMetadata, but solely uses stage 3 class decorators that work fine with Deno.

Not trying to advertise (it's a non-profit open-source project anyway), but just to mention alternatives that work well on Bun.

Oh, that looks very good. I'm going to try your library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants