ajv-validator / ajv-validator/ajv-cli

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

Abierto
#98 4 comentarios 0 reacciones 0 asignados Ver en GitHub
compatibility
Lenguaje dominante
TypeScript
Estrellas
316
Forks
77
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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?

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.