nodejs / nodejs/node

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

Đang mở
#44,535 6 bình luận 12 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

esm feature request module never-stale
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

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).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với tài liệu Node.js được liên kết về package exports và imports, sau đó so sánh module resolve.exports được trích dẫn cùng các ví dụ liên quan. Xác định phạm vi của một triển khai độc lập ánh xạ một specifier và các điều kiện mà không truy cập hệ thống tệp; được xem là hoàn tất khi module được đề xuất bao quát exports và imports nhưng vẫn tách biệt khỏi việc phân giải đầy đủ require hoặc ESM.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, node.js
Lĩnh vực
developer-experience, tooling
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.