-
-
Notifications
You must be signed in to change notification settings - Fork 621
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): support JSR #2662
feat(jsr): support JSR #2662
Conversation
* feat(jsr): reduce slow types * fix: use allow function * chore: format code * chore: denoify
I think that JSR can instead npm registry, also it's not only for Deno. In the same way, we should not export only Deno adapter like serve-static middleware. I think that exporting all runtime adapter like current |
Thanks for the comment @nakasyou ! It makes sense. I'll do it now. |
@yusukebe are you going to publish dually to both npm and JSR? How are you planning on doing the build step? Context: I am myself maintaining a library for Telegram bots (https://github.com/grammyjs) and we're planning on switching over to JSR, as well, but we are not ready to ditch npm entirely. We are discussing several strategies at the moment in grammyjs/grammY#559 and I'm curious what your take on registry support is. (Side-note: there's actually a grammY-hono integration.) |
Hi @KnorpelSenf Yes. Both npm and JSR. Exactly, it's important to make the publishing steps. I've updated the description of this PR, please read it. |
Hey @nakasyou @usualoma @ryuapp @watany-dev and others! Please see this PR. We don't need a detailed review at first. I want to know if this approach is the right one. I would also like you to use the package @hono/do-not-use-this because it is already available. |
Great nice work! I am fine with this approach. |
Oh, one comment. I think I think it would be better to simply define it as a property in diff --git a/src/hono-base.ts b/src/hono-base.ts
index f15ee2fd..47e8a053 100644
--- a/src/hono-base.ts
+++ b/src/hono-base.ts
@@ -76,28 +76,22 @@ export type HonoOptions<E extends Env> = {
getPath?: GetPath<E>
}
-abstract class SuperClass<
- E extends Env = Env,
- S extends Schema = {},
- BasePath extends string = '/'
-> {
- // The implementations of these methods are fake.
- get: HandlerInterface<E, 'get', S, BasePath> = () => new Hono<any>()
- post: HandlerInterface<E, 'post', S, BasePath> = () => new Hono<any>()
- put: HandlerInterface<E, 'put', S, BasePath> = () => new Hono<any>()
- delete: HandlerInterface<E, 'delete', S, BasePath> = () => new Hono<any>()
- options: HandlerInterface<E, 'options', S, BasePath> = () => new Hono<any>()
- patch: HandlerInterface<E, 'patch', S, BasePath> = () => new Hono<any>()
- all: HandlerInterface<E, 'all', S, BasePath> = () => new Hono<any>()
- on: OnHandlerInterface<E, S, BasePath> = () => new Hono<any>()
- use: MiddlewareHandlerInterface<E, S, BasePath> = () => new Hono<any>()
-}
-
class Hono<
E extends Env = Env,
S extends Schema = {},
BasePath extends string = '/'
-> extends SuperClass<E, S, BasePath> {
+> {
+ // Theses methods are dynamically initialized in the constructor.
+ get!: HandlerInterface<E, 'get', S, BasePath>
+ post!: HandlerInterface<E, 'post', S, BasePath>
+ put!: HandlerInterface<E, 'put', S, BasePath>
+ delete!: HandlerInterface<E, 'delete', S, BasePath>
+ options!: HandlerInterface<E, 'options', S, BasePath>
+ patch!: HandlerInterface<E, 'patch', S, BasePath>
+ all!: HandlerInterface<E, 'all', S, BasePath>
+ on: OnHandlerInterface<E, S, BasePath>
+ use: MiddlewareHandlerInterface<E, S, BasePath>
+
/*
This class is like an abstract class and does not have a router.
To use it, inherit the class and implement router in the constructor.
@@ -111,8 +105,6 @@ class Hono<
routes: RouterRoute[] = []
constructor(options: HonoOptions<E> = {}) {
- super()
-
// Implementation of app.get(...handlers[]) or app.get(path, ...handlers[])
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE]
allMethods.forEach((method) => { |
The pkg naming |
I don't have any opinion, but in reference, Oak uses |
That's fair, and it is absolutely non-critical, just brought to attention. |
* feat(jsr): remove helper.ts and middleware.ts * fix: fix test
Thanks for the great results. |
Hi @yusukebe. Thanks for working on this! I also tried One thing I noticed is that the route context variable doesn't look typed correctly with The same variable looks typed more accurately when I import Hono from |
Hi @kt3k ! Thanks! In my environment, it is typed correctly: Maybe the cache or something makes it bad? |
Actually, I confirmed the same site as @kt3k , although I skipped it because I thought it was an issue dependent on my environment, since I could no longer reproduce it at hand. After adding one line, |
Oh, adding (BTW if I restart the language server from the command palette of VS Code (selecting |
Tested with |
I updated to |
Sounds true to me. If I check the script with |
The time has come. Let's land it! |
Publishing the RC version to JSR is a success! You can use {
"imports": {
"@hono/hono": "jsr:@hono/[email protected]"
}
}
import { Hono } from '@hono/hono'
const app = new Hono()
app.get('/', (c) => {
return c.text('Hello JSR!')
})
export default app |
Hello I'm trying to migrate from Denoland to JSR, here is my code (I publish the same code in Deno, Node.js and Cloudflare workers) import { env, getRuntimeKey } from 'hono/adapter'
import type { Context } from 'hono'
export function existInEnv(c: Context, key: string): boolean {
return key in env(c)
}
export function getEnv(c: Context, key: string): string {
if (key in env(c))
return env(c)[key] ?? ''
return ''
} The error i get: error: TS2345 [ERROR]: Argument of type 'import("https://jsr.io/@hono/hono/4.4.2/src/context.ts").Context<any, any, {}>' is not assignable to parameter of type 'import("file:///Users/martindonadieu/Documents/Projects.tmp/capgo/capgo-app/node_modules/.deno/[email protected]/node_modules/hono/dist/types/context.d.ts").Context<any, any, {}>'.
Property '#private' in type 'Context' refers to a different member that cannot be accessed from within type 'Context'.
return key in env(c)
^
at file:///Users/martindonadieu/Documents/Projects.tmp/capgo/capgo-app/supabase/functions/_backend/utils/utils.ts:100:21
TS2345 [ERROR]: Argument of type 'import("https://jsr.io/@hono/hono/4.4.2/src/context.ts").Context<any, any, {}>' is not assignable to parameter of type 'import("file:///Users/martindonadieu/Documents/Projects.tmp/capgo/capgo-app/node_modules/.deno/[email protected]/node_modules/hono/dist/types/context.d.ts").Context<any, any, {}>'.
if (key in env(c))
^
at file:///Users/martindonadieu/Documents/Projects.tmp/capgo/capgo-app/supabase/functions/_backend/utils/utils.ts:104:18
TS2345 [ERROR]: Argument of type 'import("https://jsr.io/@hono/hono/4.4.2/src/context.ts").Context<any, any, {}>' is not assignable to parameter of type 'import("file:///Users/martindonadieu/Documents/Projects.tmp/capgo/capgo-app/node_modules/.deno/[email protected]/node_modules/hono/dist/types/context.d.ts").Context<any, any, {}>'.
return env(c)[key] ?? ''
^
at file:///Users/martindonadieu/Documents/Projects.tmp/capgo/capgo-app/supabase/functions/_backend/utils/utils.ts:105:16
Found 3 errors. In the doc I see |
Hi @riderx
|
Thanks, sadly the problem is not related to Sentry package, so i changed it and still have the same problem. |
I made a branch if you want to look at it: https://github.com/Cap-go/capgo/tree/migrate_hono |
I updated my code example to be more precise |
I don't know why it will be so, but the there are two This mismatch causet the problem. I can't find a good way immediately but you can use full URL to solve it: import { env, getRuntimeKey } from 'jsr:@hono/[email protected]/adapter'
import type { SupabaseClient } from '@supabase/supabase-js'
import type { Context } from 'jsr:@hono/[email protected]'
import type { Database } from './supabase.types.ts' |
I don't think I can use the JSR prefix, since I'm deploying in 3 envs. ⛅️ wrangler 3.57.2 (update available 3.59.0)
-------------------------------------------------------
✘ [ERROR] Could not resolve "@hono/tiny"
cloudflare_workers/index.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/http-exception"
cloudflare_workers/index.ts:5:30:
5 │ import { HTTPException } from '@hono/http-exception'
╵ ~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "@hono/http-exception" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/plugins/channel_self.ts:5:21:
5 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/plugins/stats.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/plugins/updates.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/config.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/delete_failed_version.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/devices.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/download_link.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/log_as.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/plans.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/public_stats.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/stats.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/store_top.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/stripe_checkout.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/stripe_portal.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/private/upload_link.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/public/bundles.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/public/channel.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/public/devices.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/public/ok.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/clear_app_cache.ts:3:21:
3 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/clear_device_cache.ts:3:21:
3 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/cron_clear_versions.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/cron_email.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/cron_plan.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/cron_scrapper.ts:2:21:
2 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/cron_stats.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/logsnag_insights.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/on_app_create.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/on_channel_update.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/on_organization_create.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/on_user_create.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/on_user_delete.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/on_user_update.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/on_version_create.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/on_version_delete.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/on_version_update.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/tiny"
supabase/functions/_backend/triggers/stripe_event.ts:1:21:
1 │ import { Hono } from '@hono/tiny'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/tiny" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/utils/buffer"
supabase/functions/_backend/utils/hono.ts:1:32:
1 │ import { timingSafeEqual } from '@hono/utils/buffer'
╵ ~~~~~~~~~~~~~~~~~~~~
You can mark the path "@hono/utils/buffer" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/http-exception"
supabase/functions/_backend/utils/hono.ts:3:30:
3 │ import { HTTPException } from '@hono/http-exception'
╵ ~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "@hono/http-exception" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/cors"
supabase/functions/_backend/utils/hono.ts:4:21:
4 │ import { cors } from '@hono/cors'
╵ ~~~~~~~~~~~~
You can mark the path "@hono/cors" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/adapter"
supabase/functions/_backend/utils/pg.ts:6:30:
6 │ import { getRuntimeKey } from '@hono/adapter'
╵ ~~~~~~~~~~~~~~~
You can mark the path "@hono/adapter" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/adapter"
supabase/functions/_backend/utils/stats.ts:2:30:
2 │ import { getRuntimeKey } from '@hono/adapter'
╵ ~~~~~~~~~~~~~~~
You can mark the path "@hono/adapter" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Could not resolve "@hono/adapter"
supabase/functions/_backend/utils/utils.ts:1:35:
1 │ import { env, getRuntimeKey } from '@hono/adapter'
╵ ~~~~~~~~~~~~~~~
You can mark the path "@hono/adapter" as external to exclude it from the bundle, which will remove this error.
✘ [ERROR] Build failed with 45 errors:
cloudflare_workers/index.ts:1:21: ERROR: Could not resolve "@hono/tiny"
cloudflare_workers/index.ts:5:30: ERROR: Could not resolve "@hono/http-exception"
supabase/functions/_backend/plugins/channel_self.ts:5:21: ERROR: Could not resolve "@hono/tiny"
supabase/functions/_backend/plugins/stats.ts:1:21: ERROR: Could not resolve "@hono/tiny"
supabase/functions/_backend/plugins/updates.ts:1:21: ERROR: Could not resolve "@hono/tiny"
...
🪵 Logs were written to "/Users/martindonadieu/Library/Preferences/.wrangler/logs/wrangler-2024-06-05_02-03-22_577.log" Before the import where structured the same on all platforms, so I didn't have the issue |
@yusukebe thanks a lot I found my way to JSR, here was my required change: |
This PR will enable Hono to support the JSR.
We've done:
jsr-dry-run
command in CI to check if it's ready to publish JSR. 8b24707deno.json
. 7ac6306 And modified.JSX
be exported fromhono/jsx/jsx-runtime
notglobal
. 5bd2b71hono-base.ts
does not usedynamicClass
. b902590ExecutionContext
is not declared inglobal
. cf020c6deno_dist
anddenoify
completely. 0c776fadeno.json
exports./
,./jsx/jsx-runtime
,../middleware
, and./helper
deno.json
exports each helper, middleware, and adapter following @nakasyou's comment. 90892beUsage
Currently, we are uploading Hono as
@hono/do-not-use-this
on the JSR.You don't use it, but you can use it for experimental purposes.
We will support both npm and JSR
Though this PR will merged and Hono supports JSR, we don't stop supporting the npm. I'm thinking we can do it with the following publishing steps:
np
command on my local machine.Differences between npm package
It can't use
declare global
if it will be published in JSR. So you can't useContextVariableMap
. Instead, you can use theVariables
type exported from the middleware.Goodbye Denoify
We have to say Goodbye to Deonify if this PR is merged.
We were using it heavily to support publishing Hono on
deno.land/x
. But with this PR, it's not necessary because the--unstable-sloppy-imports
option can be used. I've removed thedeno_dist
directory completely.Thanks Denoify.
TODO
jsr.json
to prepare publishing.