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

feat: JSR compatibility #628

Open
wants to merge 6 commits into
base: v2
Choose a base branch
from
Open

feat: JSR compatibility #628

wants to merge 6 commits into from

Conversation

niusia-ua
Copy link
Member

With this PR, we are starting to work on migrating grammY and its ecosystem to the JSR registry.

Specifically, this PR resolves some of the type issues that arise due to JSR's restrictions.
Please review all changes carefully and test them on your bots.
In general, these changes shouldn't affect the logic of grammY, but it's worth making sure.

For example, the evaluation result has been improved from 47% to 76% (see screenshot).
Also, according to JSR, this should have improved the speed of code compilation.
The remaining scores are related to the package documentation.

This is just the beginning of the work.
In general, the migration to JSR should be fully completed with the release of grammY 2.0.
The second version will solve many of the existing problems, as well as move the code from a platform-specific approach to code compilation to capability-driven code behaviour.
This will allow us to fully rely on JSR to support multiple platforms.

You can test the build locally.
To do this, first run JSR on your machine as instructed.
Then publish the grammY package using JSR_URL=http://jsr.test deno publish.
The package will be available at http://jsr.test/@grammyjs/grammy, and the NPM build at http://npm.jsr.test/@jsr/grammyjs__grammy.
In the metafile of the NPM build, you can find a link to an archive that you can download and unzip to view its contents.
Such a build is suitable for publishing to NPM, except that it needs to be edited and repackaged a bit.

Screenshot from 2024-08-24 09-45-31

@niusia-ua niusia-ua added the enhancement New feature or request label Aug 25, 2024
@niusia-ua niusia-ua self-assigned this Aug 25, 2024
@niusia-ua
Copy link
Member Author

Should I add a --allow-env option to the deno task test?
I don't know why it is required.

@@ -1,4 +1,5 @@
import { type Update } from "../types.ts";
import { Buffer } from "node:buffer";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is forcing us to upgrade the @types/node version to the ^16.20.2.
Should we do it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are going to require at least Node 20, but probably rather an even more recent version. You can do this in the same PQ or it can also be done separately if you prefer.

Copy link
Member Author

@niusia-ua niusia-ua Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is enough to depend on Node.js v20 because its maintenance period will have ended in April 2026. It is a lot of time.

@KnorpelSenf KnorpelSenf changed the base branch from main to v2 August 25, 2024 16:18
@KnorpelSenf
Copy link
Member

Should I add a --allow-env option to the deno task test? I don't know why it is required.

It might be required we type-check certain code using type definitions defined in npm: deps?

import {
type ApiClientOptions,
type WebhookReplyEnvelope,
} from "./core/client.ts";
import type { ApiClientOptions, WebhookReplyEnvelope } from "./core/client.ts";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does JSR require us to have separate import statements?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a JSR requirement, but a Deno one.

@@ -965,7 +983,7 @@ export class Context implements RenamedUpdate {
text: string,
other?: Other<"sendMessage", "chat_id" | "text">,
signal?: AbortSignal,
) {
): Promise<ReturnType<ApiMethods["sendMessage"]>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should introduce and export a new type alias for this, but this can be done later. You can keep it this way for now.

@niusia-ua
Copy link
Member Author

It might be required we type-check certain code using type definitions defined in npm: deps?

It seems so. It works on the main branch.

@@ -119,6 +135,222 @@ function inputMessageMethods<R extends InlineQueryResult>(
};
}

interface InlineQueryResultBuilder {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of the redundancy by doing it via typeof and the existing const? I am not sure how well JSR does this yet

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand it. What type will we typeof?

@@ -36,6 +36,39 @@ type InlineQueryResultOptions<T, K extends keyof T> = Omit<
type OptionalKeys<T> = { [K in keyof T]-?: undefined extends T[K] ? K : never };
type OptionalFields<T> = Pick<T, OptionalKeys<T>[keyof T]>;

interface InputMessageMethods<R extends InlineQueryResult> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

getUpdates(
other?: Other<R, "getUpdates">,
signal?: AbortSignal,
): Promise<ReturnType<ApiMethods["getUpdates"]>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as for the context object (but it naturally has to be a different type)

@@ -2,7 +2,7 @@
export const isDeno = typeof Deno !== "undefined";

// === Export debug
import debug from "https://cdn.skypack.dev/[email protected]";
import debug from "npm:[email protected]";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: #630

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

Successfully merging this pull request may close these issues.

2 participants