next.js
444e04f7 - Turbopack: read package.json main and alias fields through typed projections (#100980)

Commit
1 hour ago
Turbopack: read package.json main and alias fields through typed projections (#100980) ## Summary When resolving into a package, the main fields (`main`, `module`, ...) and the alias field (`browser`) were read straight from the parsed `package.json`. Any edit to that file, such as to `scripts` or `dependencies`, therefore invalidated those resolutions. They now go through per-field tasks, like the `exports` and `imports` fields already do: - `package_json_string_field(path, field)` returns the field's string - `package_json_alias_field(path, field)` returns the alias entries as typed values: `false` means ignore, a string is a request to resolve instead, and anything else is kept as JSON text for the existing error Both tasks share a non-task helper for reading and projecting one field. Resolution still depends only on the small task results, so an edit to an unrelated field stops at them. Behavior is unchanged, including the "invalid alias field value" issue. ## Verification - New tests `test_package_json_string_field_invalidation` and `test_package_json_alias_field_invalidation`: an edit to `scripts` doesn't re-run a reader of `main` or `browser`, and a change to that field does - A temporary whole-`package.json` dependency makes the alias-field test fail, as expected - `cargo test -p turbopack-core --lib resolve::`: 78 passed on Linux - `cargo test -p turbopack-tests --test execution -- resolving`: 33 passed, including `alias_field`, `self_reference` and `exports_field_pattern` - `cargo check --workspace --tests`, `cargo clippy -p turbopack-core --tests`: clean - `cargo test -p turbopack-core --lib`: the 25 `resolve::` temp-dir tests that fail on macOS fail identically on the base branch; everything else passes <!-- NEXT_JS_LLM --> <!-- fleet 14d61f44-d6a1-4adf-839c-9584f32828c2 --> --------- Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Author
Parents
Loading