foobar
foobar•2w ago

Jsr, esm, x and external ref

Hi, I want to migrate most of my import to jsr to simplify code. I use Hono and 3rd party middleware on Deno. I import them with esm / deno.land Is there a better way to link dependencies with hono (or library with dependencies) ? My actual settings
"imports": {
"@/": "./",
"@scalar/hono-api-reference": "npm:@scalar/hono-api-reference",
"hono": "jsr:@hono/hono@^4.4.8",
// For hono swagger
"hono/swagger-ui": "https://esm.sh/@hono/swagger-ui@0.2.2?external=hono&target=es2022",
"hono/zod-validator": "https://esm.sh/@hono/zod-validator@0.2.1?external=hono,zod&target=es2022",
"hono/zod-openapi": "https://esm.sh/@hono/zod-openapi@0.11.1?external=hono,zod,hono/zod-validator&target=es2022",
"zod": "https://deno.land/x/zod@v3.23.8/mod.ts"
}
"imports": {
"@/": "./",
"@scalar/hono-api-reference": "npm:@scalar/hono-api-reference",
"hono": "jsr:@hono/hono@^4.4.8",
// For hono swagger
"hono/swagger-ui": "https://esm.sh/@hono/swagger-ui@0.2.2?external=hono&target=es2022",
"hono/zod-validator": "https://esm.sh/@hono/zod-validator@0.2.1?external=hono,zod&target=es2022",
"hono/zod-openapi": "https://esm.sh/@hono/zod-openapi@0.11.1?external=hono,zod,hono/zod-validator&target=es2022",
"zod": "https://deno.land/x/zod@v3.23.8/mod.ts"
}
5 Replies
Deno AI Helper
Deno AI Helper•2w ago
The documentation indicates that Deno has introduced the JavaScript Registry (JSR), which is a TypeScript-first, ESM-only module registry designed for the entire JavaScript ecosystem. JSR modules can be used from Deno and npm-based projects, and it's free and open source. This suggests that migrating your imports to JSR could indeed simplify your code by providing a more unified and streamlined way to manage dependencies. For your current settings, you're already using JSR for importing hono, which is great. However, for other dependencies like hono/swagger-ui, hono/zod-validator, and hono/zod-openapi, you're using esm.sh with query parameters to handle external dependencies and target environments. To further simplify your imports and potentially improve compatibility and performance, you could look for these packages on JSR and use them directly if they are available. This would allow you to take full advantage of JSR's benefits and possibly reduce the complexity of your import URLs. Here's an example of what your imports might look like if you were able to find all your dependencies on JSR:
"imports": {
"@/": "./",
"@scalar/hono-api-reference": "npm:@scalar/hono-api-reference",
"hono": "jsr:@hono/hono@^4.4.8",
// Assuming these packages are available on JSR
"hono/swagger-ui": "jsr:@hono/swagger-ui@0.2.2",
"hono/zod-validator": "jsr:@hono/zod-validator@0.2.1",
"hono/zod-openapi": "jsr:@hono/zod-openapi@0.11.1",
"zod": "jsr:zod@v3.23.8"
}
"imports": {
"@/": "./",
"@scalar/hono-api-reference": "npm:@scalar/hono-api-reference",
"hono": "jsr:@hono/hono@^4.4.8",
// Assuming these packages are available on JSR
"hono/swagger-ui": "jsr:@hono/swagger-ui@0.2.2",
"hono/zod-validator": "jsr:@hono/zod-validator@0.2.1",
"hono/zod-openapi": "jsr:@hono/zod-openapi@0.11.1",
"zod": "jsr:zod@v3.23.8"
}
Please note that the above example assumes that the packages are available on JSR, which you would need to verify. If they are not available, you may continue using esm.sh or deno.land as you currently are. Remember to check the JSR or the respective package documentation for the
Doctor 🤖
Doctor 🤖•2w ago
{
"hono": "npm:hono",
"@hono/swagger-ui": "npm:@hono/swagger-ui",
"@hono/zod-openapi": "npm:@hono/zod-openapi",
"@hono/zod-validator": "npm:@hono/zod-validator",
"@scalar/hono-api-reference": "npm:@scalar/hono-api-reference",
"zod": "npm:zod"
}
{
"hono": "npm:hono",
"@hono/swagger-ui": "npm:@hono/swagger-ui",
"@hono/zod-openapi": "npm:@hono/zod-openapi",
"@hono/zod-validator": "npm:@hono/zod-validator",
"@scalar/hono-api-reference": "npm:@scalar/hono-api-reference",
"zod": "npm:zod"
}
This example lacks the versions.
foobar
foobar•2w ago
I have the error message that zod-openapi is looking for export '@hono/hono@4.4.8'. How to link them with npm ?
Doctor 🤖
Doctor 🤖•2w ago
Sounds like it might be a bug as you shouldn't need to import a dependency's dependencies. Maybe want to open an issue on GitHub