ajv-validator / ajv-validator/ajv-formats

Take into account ajv `code.esm` option

未关闭
#68 1 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
TypeScript
星标
228
派生
42
PR 合并指标
30 天内没有已合并 PR

描述

**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**

```javascript
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**

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

**Output**

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

**What results did you expect?**

```javascript
// 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. (https://github.com/ajv-validator/ajv-formats/issues/65)

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。