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

Take into account ajv code.esm option #68

Open
o-alexandrov opened this issue May 9, 2022 · 1 comment · May be fixed by #73
Open

Take into account ajv code.esm option #68

o-alexandrov opened this issue May 9, 2022 · 1 comment · May be fixed by #73
Labels
enhancement New feature or request

Comments

@o-alexandrov
Copy link

o-alexandrov commented May 9, 2022

What version of Ajv are you using? Does the issue happen if you use the latest version?

8.11.0 (currently latest)

Ajv options object

import Ajv from "ajv"
import standaloneCode from "ajv/dist/standalone"
import ajvFormats from "ajv-formats"

const ajv = new Ajv({
  code: { esm: true, source: true },
})
ajvFormats(ajv)

const output = standaloneCode(ajv, validate)

JSON Schema

{
  "type": "object",
  "properties": {
    "example": { "type": "number", "format": "int32" }
  },
  "$schema": "http://json-schema.org/draft-07/schema"
}

Output

// ...
const formats0 = require(`ajv-formats/dist/formats`).fullFormats.int32
// ...

What results did you expect?

// this is kinda awkward, but that's the only way to make it work as of now in pure ESM w/o post-processing
import { fullFormats } from "ajv-formats/dist/formats"
const { int32 } = fullFormats

Are you going to resolve the issue?
I've tried to look into it, but it seems to be coupled with many ajv packages, so please let me know your proposal.

I believe the resolution should be done in multiple steps:

  1. the import should be used instead of require (this issue)
  2. ajv-formats should export every function separately, not scoped within fullFormats, fastFormats, etc. (Export formats separately, without scoping #65)
@epoberezkin
Copy link
Member

ajv-formats should export every function separately, not scoped within fullFormats, fastFormats, etc.

I think it can still export these objects, they would be just rendered differently.

The solution is for ajv-formats to take code.esm option into account, moving this issue there...

@epoberezkin epoberezkin transferred this issue from ajv-validator/ajv May 13, 2022
@epoberezkin epoberezkin added enhancement New feature or request and removed bug report labels May 13, 2022
@epoberezkin epoberezkin changed the title Standalone. code.esm=true outputs require() for external modules Take into account ajv code.esm option May 13, 2022
@sethvincent sethvincent linked a pull request Sep 16, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

2 participants