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 for edge runtimes like cloudflare workers, vercel edge, deno etc #825

Open
cosbgn opened this issue Oct 24, 2023 · 7 comments
Open
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@cosbgn
Copy link

cosbgn commented Oct 24, 2023

As a feature request, it would be amazing if this library could work on cloudflare workers, deno, vercel-edge, netlify-edge and other edge runtimes.

These runtimes are gaining a lot of popularity lately, but unfortunately can't be used with this library. I guess this is also due to dependancies like ajv, but there are some edge ready alternatives like @cfworker/json-schema.

Thanks for considering it.

@erunion
Copy link
Member

erunion commented Oct 24, 2023

I would love to support Edge runtimes! Do you have a solid way of detecting a package that doesn't support it?

@erunion erunion added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers and removed good first issue Good for newcomers labels Oct 24, 2023
@cosbgn
Copy link
Author

cosbgn commented Oct 24, 2023

Not really, I think the easiest is just to use wrangler dev locally and see if an error comes up.

So far I've learned that:

  • Imports needs to be prefixed (e.g. import { Buffer } from 'node:buffer')
  • The nodejs_compat flag helps a lot, can easily be activated on cloudflare and active by default on vercel-edge
  • ajv doesn't work, but @cfworker/json-schema does
  • eval(), new Function(), setTimeout([string]), and setInterval([string]) can't be used.

@erunion
Copy link
Member

erunion commented Oct 24, 2023

Do you have an example code snippet for oas that's not working with wrangler dev? Would be helpful to see and debug. I know we only use ajv in oas/reducer, which isn't exported from any main export, and only really exists in this repository because it's used in https://github.com/readmeio/rdme

@cosbgn
Copy link
Author

cosbgn commented Oct 24, 2023

This is the started wrangler which fails on npm run start: https://github.com/cosbgn/oas-edge

@erunion
Copy link
Member

erunion commented Oct 24, 2023

Ah gotcha, so its failing on oas-normalize likely then. Moving that off ajv is going to be a lot of work because we'll have to move @readme/openapi-parser and then rewrite @readme/better-ajv-errors as well. 😓

@cosbgn
Copy link
Author

cosbgn commented Oct 24, 2023

oas-normalize would be great as well, but it's failing also without it, only with oas check the new commit without normalize: https://github.com/cosbgn/oas-edge/blob/main/src/index.js

@erunion
Copy link
Member

erunion commented Oct 24, 2023

Woof, ok I see now.

Screen Shot 2023-10-24 at 1 27 22 PM

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

No branches or pull requests

2 participants