Proposal: Remove ESM/CJS duality from code samples in API docs
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
Since the introduction of ESM to Node.js core, we have been providing togglable ESM/CJS code examples in the API docs.
These examples differ only in the lines of code containing core imports, but the entire codeblocks need duplicating due to the limitations of the web renderer, leading to whole reams of duplicated cruft across /doc/api. The documentation space is extremely patchy as to which examples are just ESM, just CJS, or both. We occasionally get very kind contributors submitting PRs to double-up existing CJS-only code examples, but these are not good uses of reviewer time.
Almost invariably, it is incredibly obvious as to how to convert an ESM import from a builtin module into a CJS import, or vice versa.
I suggest that we:
- get rid of ```mjs and ```cjs blocks in favour of a single ```js block
- canonicalise ESM imports as the example paradigm of choice, unless a example is specifically demonstrating something CJS-specific
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
检查 /doc/api 下的示例,并盘点 mjs 和 cjs 代码块,记录明确展示 CommonJS 行为的情况。在将符合条件的示例整合到 js 代码块之前,与维护者确认范围以及默认使用 ESM 的约定。完成的标准是移除重复示例,同时确保 CJS 特有的演示仍然准确。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100