grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.04k stars 106 forks source link

feat: add `bun` web framework adapter #583

Closed SunsetTechuila closed 1 month ago

KnorpelSenf commented 2 months ago

There currently is no attempt at being compatible with bun. Bun seems to work for the core library, but bun's compatibility with Node is rather bad, and several grammY plugins currently crash when used with bun.

I am personally not interested in working on bun compatibility, and I'll leave it up to bun to improve their stability and Node compatibility. This means that if there are issues with bun compat, I will neither put any effort into this, nor am I going to spend time maintaining code that other people submit if its sole purpose is to work around issues in bun. Consequently, I would also reject such changes.

We have a few options here:

I am afraid that people will build up false expectations about bun compatibilty if we have this adapter. Do you think that people will start making demands if we merge this?

KnorpelSenf commented 2 months ago

There's another option: https://t.me/grammyjs/237897

SunsetTechuila commented 2 months ago

and several grammY plugins currently crash when used with bun.

Сould you tell which ones exactly? I can try to make them compatible

we can merge right away and simply ignore the fact that grammY only works sometimes on bun and if people use this adapter and then realise that compatibility is bad, then we can shrug and leave the problem up to them

Obviously a bad idea

we can wait

That would be ok

There's another option: https://t.me/grammyjs/237897 we can also ask to release it as a separate unofficial package

I'm not sure what exactly you're suggesting. To release something like grammyjs-with-bun-web-adapter npm package? Or to make it a plugin? As far as I understand, the second is not possible

SunsetTechuila commented 2 months ago

i have no idea how to import bun types, really non-trivial task

the only two ways (/// <reference types="npm:bun-types" /> and import "npm:bun-types") I've found result in error:

error: TS2349 [ERROR]: This expression is not callable.
  Not all constituents of type '(() => string | Uint8Array | AsyncIterable<Uint8Array> | ReadableStream<Uint8Array> | URLLike | ... 5 more ... | Promise<...>) | (ReadableStream<...> & Function)' are callable.
    Type 'ReadableStream<Uint8Array> & Function' has no call signatures.
            return new InputFile(await data()).toRaw();
                                       ~~~~
    at file:///E:/Repos/grammY/src/types.deno.ts:134:40
KnorpelSenf commented 2 months ago

@winstxnhdw has agreed to take care of the people who make demands.

The affected plugins are i18n and conversions, and you cannot fix their compat because it's caused by the build tooling. We need to switch to JSR instead, which will solve all of this, but until then, we can already provide this adapter.

Can you just copy the bun API types here, and rely on that?

winstxnhdw commented 2 months ago

Hi @SunsetTechuila, you can get the official bun types from https://www.npmjs.com/package/bun-types

winstxnhdw commented 2 months ago
error: TS2349 [ERROR]: This expression is not callable.
  Not all constituents of type '(() => string | Uint8Array | AsyncIterable<Uint8Array> | ReadableStream<Uint8Array> | URLLike | ... 5 more ... | Promise<...>) | (ReadableStream<...> & Function)' are callable.
    Type 'ReadableStream<Uint8Array> & Function' has no call signatures.
            return new InputFile(await data()).toRaw();
                                       ~~~~
    at file:///E:/Repos/grammY/src/types.deno.ts:134:40

You have to narrow down the types.

SunsetTechuila commented 2 months ago

You have to narrow down the types.

I doubt this is doable. I've tried everything

winstxnhdw commented 2 months ago

I don't see any problem when I do it though?

EDIT: Oh nvm I get it.