Skip to content

Take into account ajv code.esm option #68

Open
@o-alexandrov

Description

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)

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions