Design review: per-project export-condition selection (PR #4351) — single-package motivation, Node-divergence semantics, alternatives

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

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

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, typescript
領域
build-system

調査の方向性

Read PR #4351 and issue #3566 first, then compare scriptc’s package export and imports resolution with Node’s condition ordering. Survey packages beyond rxjs and write down the proposed divergence rule, interactions with existing scriptc conditions, and failure behavior for missing targets. Done means the design questions in the issue have explicit decisions and a measurable win condition.

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

説明

Problem

PR #4351 proposes a new project-level setting, scriptc.packages.<name>.conditions, letting a project name the export condition scriptc compiles for a package. Architectural concerns before considering the implementation:

1. Single motivating package. The evidence base is one package: rxjs 7, whose root export map is { types, node: dist/cjs, require: dist/cjs, es2015: dist/esm, default: dist/esm5 }. Every motivation in the PR is rxjs-specific. There is no survey of how many published packages have the shape (ESM-preferred condition shadowed by an earlier node/require key) that actually break scriptc resolution today, and no explanation of why the existing scriptc condition (added in #3566) cannot be contributed upstream or shimmed via package overrides.

2. New config surface for a resolution-policy change. Today scriptc mirrors Node's resolution semantics: it selects the same file Node selects. The PR changes that default: when the setting is present, scriptc compiles a condition Node would not pick (es2015 over node). That is a semantic divergence between "what scriptc builds" and "what runs under Node" — precisely the divergence the compiler otherwise refuses (Node.js decides behavior; a compiled program must do what Node does). It needs a written position on when divergence is acceptable, how declaration types vs. compiled runtime stay consistent, and what happens when the chosen condition's build differs behaviorally from the CJS build Node loads (esm5 vs esm vs cjs are materially different artifacts).

3. Alternatives not evaluated.

  • Extend the existing scriptc condition mechanism (#3566): a package can already publish scriptc in its export map; why is per-package condition aliasing in project config preferable to documenting/automating the scriptc key (e.g. a patch/override step)?
  • Reuse Node's own --conditions: rejected in the PR because node precedes es2015 in key order, but a pnpm/patch-package override of the map, or upstream fix to the package, achieves the same without new config.
  • imports-map indirection or an explicit per-package override file (like TypeScript's paths) rather than a new condition-aliasing rule.

4. Spec-level questions. Interaction with imports conditions is mentioned but the semantics of aliasing inside imports (where node ordering matters differently) are not specified. Also unspecified: precedence when a package both publishes scriptc and the project names conditions, error behavior for unknown conditions at the far end (e.g. a package whose es2015 target directory does not exist), and Windows/path cases.

Proposal

Before merging #4351, decide the design:

  1. Either scope this to "packages that publish no compatible ESM condition" with documented criteria, or generalize it into a full package-override mechanism with one semantic story.
  2. Write the rule for when scriptc may resolve differently from Node, and what guarantees the compiled program still matches Node's runtime behavior (or document explicitly that it does not, and what the dual-run reporter should then do).
  3. Add a survey of real packages (beyond rxjs) whose resolution scriptc gets wrong today, with and without the feature, so the feature has a measurable win condition.
  4. Specify imports interaction, precedence with an existing scriptc key, and failure modes for missing targets.
主要言語
TypeScript
スター
6.7k
フォーク
229
平均マージ
14時間 29分
マージ済み PR(30日)
787

環境構築

はじめの一歩

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

vercel-labs/scriptc のほかの issue

vercel-labs/scriptc の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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