nodejs / nodejs/node

Publish `exports` and `imports` implementations as separate module(s)

未关闭
#44,535 6 条评论 12 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

esm feature request module never-stale
主要语言
JavaScript
星标
122k
派生
37.3k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

What is the problem this feature will solve?

Projects implementing support for module resolution have to add support for the quite advanced exports and imports fields in package.json.

https://nodejs.org/api/packages.html#exports
https://nodejs.org/api/packages.html#imports

Examples of projects that have done this are Webpack, TypeScript, Jest (only exports, not imports), Yarn and probably more. AFAIK neither Rollup, Parcel or Metro (to name some bundlers) have support.

What is the feature you are proposing to solve the problem?

If the algorithm Node uses internally was published as a separate module, I hope (and believe) more projects would be able to add support more readily, and that ecosystem compatibility would improve as a result.

I think part of the reason is the complexity in supporting the algorithm needed, particularly with subpath exports, wildcards and conditionals. E.g. https://github.com/browserify/resolve/issues/222 is stuck, and https://github.com/facebook/jest/issues/9771 took a long time.

Prior art for externalizing parts of Node publishing cjs-module-lexer separately, which means Jest could implement the same feature as node itself when importing CJS from ESM (via vm API).


Note that this is not a request for the full require or ESM resolution algorithm. This is solely a request for "given this exports/imports, this specifier and these conditions, what path does it map to" - no FS access/lookups at all. API similar to https://github.com/lukeed/resolve.exports makes sense to me.

What alternatives have you considered?

Jest (and Yarn) currently use https://github.com/lukeed/resolve.exports to avoid having to implement all the resolution. It currently does not support imports (https://github.com/lukeed/resolve.exports/issues/14).

贡献指南

打开贡献指南

从这里开始

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

调研方向

先从链接的 Node.js package exports 和 imports 文档开始,然后对照所引用的 resolve.exports 模块及相关示例。确定一个无需访问文件系统、用于映射 specifier 和 conditions 的独立实现的范围;完成的标准是,所提议的模块覆盖 exports 和 imports,同时仍与完整的 require 或 ESM 解析保持分离。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
developer-experience, tooling
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

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