emit CJS/ESM syntax in standalone mode based on AJV code options

Offen
#679 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

@jaideeppyne arbeitet bereits daran.

Seit 17.8.2026.

  • #872 von @jaideeppyne — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
42/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
javascript
Bereich
backend

Rechercherichtung

Beginne in lib/standalone.js bei der fest codierten require/module.exports-Logik und verfolge, wie serializerOptions den Standalone-Generator erreichen. Prüfe die AJV-Codeoptionen, insbesondere source und esm, und verifiziere, dass die generierte Standalone-Ausgabe der ausgewählten CJS- oder ESM-Syntax folgt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

feature request
Prerequisites
  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal

Use the AJV code option to decide if the standalone code generator would emit CJS (require/module) or ESM (import/export) instead of hardcoding require and module.exports as shown below in the standalone.js file

https://github.com/fastify/fast-json-stringify/blob/74c35c0ee4c2dd12cc8edf8acad4b2f46c0542bb/lib/standalone.js#L14-L23

Motivation

Typescript and ESM users will have to go through some build system configurations to resolve the require in ESM runtime headache during development. Especially that the StandaloneValidator from the @fastify/ajv-compiler package respects the ESM AJV option out of the box.

If we can leverage the serializerOptions, Fastify users in ESM envirmenment can easily use a standalone serializers with the AJV options

ajv: {
  code: { source: true, esm: true } 
}
Example

No response

Vorherrschende Sprache
JavaScript
Sterne
3.7k
Forks
245
Ø Merge
3 T. 5 Std.
Gemergte PRs (30 T.)
16

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus fastify/fast-json-stringify

Alle Issues in fastify/fast-json-stringify

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.