ajv-validator / ajv-validator/ajv-cli

CLI compile - problem with CommonJS imports/exports and nonexistent require() paths

未关闭
#98 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
compatibility
主要语言
TypeScript
星标
316
派生
77
PR 合并指标
30 天内没有已合并 PR

描述

Hello!

In our project, we're using a typescript monorepo setup with a shared model.
The model interfaces are annotated with [YousefED/typescript-json-schema](https://github.com/YousefED/typescript-json-schema) to produce json schemas in build time. These schemas are later used on the API level, as well as complementary validation of the forms in an Angular frontend, using AJV. So far, so good.

We ran into a problem with Content Security Policy and unsafe-eval.
As a remedy, I'm trying to use AJV CLI to precompile validator functions. That, however, leads to a couple issues. It is generating some code, but there are caveats.

1. Generated validator files use CommonJS syntax for both imports and exports. Have there been any plans to support ES style imports/exports in these?
2. Looks like some of the generated require() style imports are trying to resolve nonexistent paths, resulting in errors. For example, validator generated from a schema with minlength:
`var func8 = require("ajv/dist/compile/ucs2length").default;`
In reality, there's no such file under ajv/dist/, but there's one under ajv/lib/
3. Other than that, it's misleading that "precompiled standalone validator functions" have an implicit dependency on AJV itself. Shouldn't it be possible to compile with a flag that includes the dependencies directly in the generated file? Or at least allow it to use ES-style imports rather than CommonJS?

贡献指南

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

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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