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

未关闭
#679 1 条评论 0 个 reaction 已指派 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 小时
30 天内合并 PR
16

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fastify/fast-json-stringify 的其他 Issue

查看 fastify/fast-json-stringify 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。