ajv-validator / ajv-validator/ajv-cli

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

Aperta
#98 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub
compatibility
Lingua principale
TypeScript
Stelle
316
Fork
77
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.