ajv-validator / ajv-validator/ajv-cli

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

Aberta
#98 4 comentários 0 reações 0 responsáveis Ver no GitHub
compatibility
Linguagem predominante
TypeScript
Estrelas
316
Forks
77
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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?

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.