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

オープン
#679 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@jaideeppyne がすでに取り組んでいます。

2026年8月17日 から。

  • #872 @jaideeppyne による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript
領域
backend

調査の方向性

lib/standalone.js のハードコードされた require/module.exports ロジックから始め、serializerOptions が standalone ジェネレーターにどのように到達するかを追跡してください。AJV のコードオプション、特に source と esm を確認し、生成された standalone 出力が選択された CJS または ESM 構文に従っていることを検証してください。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
JavaScript
スター
3.7k
フォーク
245
平均マージ
3日 5時間
マージ済み PR(30日)
16

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fastify/fast-json-stringify のほかの issue

fastify/fast-json-stringify の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。