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

Support ES Modules? #219

Closed
yusukebe opened this issue Mar 29, 2024 · 7 comments
Closed

Support ES Modules? #219

yusukebe opened this issue Mar 29, 2024 · 7 comments

Comments

@yusukebe
Copy link

Hi.

First, thank you very much for creating such a great product. We use Zod to OpenAPI in @hono/zod-openapi. It can only be archived if Zod to OpenAPI exists.

What I would like to know/suggest is supporting ES Modules. Currently, this only supports Common JS. However, some environments, such as Vitest, use only ES Modules and do not support Common JS. So the following problem occurred:

honojs/middleware#436

Would you happen to have any plans to support ES Modules? If so, it will be a great opportunity to work Zod to OpenAPI in more environments. Thanks!

@georgyangelov
Copy link
Collaborator

Hi @yusukebe,

We're definitely open to supporting ESM, however time we can put in the project is limited lately so I can't promise anything in terms of time.

Will you be ok to help on this? I believe it should be mostly splitting our tsconfig to tsconfig.cjs.json and tsconfig.esm.json, updating the build scripts and adding to the package.json. Plus some testing of course, and it would help that you have a reproduction case through your library. What do you think?

@danielkarso-pon
Copy link

I just added a PR for this: #220

I haven't tested it yet however.

@yusukebe
Copy link
Author

@georgyangelov Thank you for your response!

@danielkarso-pon So quick handling. Great!

@ducan-ne
Copy link

ducan-ne commented Apr 1, 2024

I encountered an issue while integrating the new Cloudflare Worker Vitest plugin. After hours of debugging, I noticed that openapi3-ts supports mjs, but @asteasolutions/zod-to-openapi (which import openapi3-ts) does not, makes vitest/cloudflare worker forces to use cjs, causing my test to fail. I hope to see this addressed in the next release.

@danielkarso-pon
Copy link

danielkarso-pon commented Apr 2, 2024

Fyi; if you want vitest fixed with Cloudflare worker and zod-to-openapi for now and not wait for the next release you can do this in your

package.json

"dependencies": {
    "zod-to-openapi": "github:danielkarso-pon/zod-to-openapi#multi-package"
  },
}
"overrides": {
  "@asteasolutions/zod-to-openapi": "$zod-to-openapi"
}

rm -rf node_modules && npm i

And in your vitest.config.ts

import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
import path from 'node:path';

export default defineWorkersConfig({
	test: {
		poolOptions: {
			workers: {
				wrangler: { configPath: './wrangler.toml' },
			},
		},
		server: {
			deps: {
				inline: ['@asteasolutions/zod-to-openapi'],
			}
		},
	},
	resolve: {
		alias: {
			'@/': new URL('./src/', import.meta.url).pathname,
			'@asteasolutions/zod-to-openapi': path.resolve(__dirname, 'node_modules/zod-to-openapi/dist/mjs/index.js'),
			'openapi3-ts/oas30': path.resolve(__dirname, 'node_modules/openapi3-ts/dist/oas30.mjs'),
		},
	}
});

@AGalabov
Copy link
Collaborator

AGalabov commented Apr 5, 2024

@yusukebe @ducan-ne @danielkarso-pon this should now be available as part of the v7.0.0 Release 🚀 .

@AGalabov AGalabov closed this as completed Apr 5, 2024
@yusukebe
Copy link
Author

yusukebe commented Apr 7, 2024

@danielkarso-pon @AGalabov

I've confirmed it works well! I'll release the new version of @hono/zod-openapi that includes the release. Thanks so much!

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

5 participants