Skip to content

fix: return the enclosing package.json if it is inside node_modules - #476

Merged
Boshen merged 1 commit into
mainfrom
fix-package-json-nested
Apr 29, 2025
Merged

Boshen merged 1 commit into
mainfrom
fix-package-json-nested

Conversation

@Boshen

@Boshen Boshen commented Apr 28, 2025 •

Copy link
Copy Markdown
Member

closes #396

A package may contain package.json inside its subdirectories, they must not participate in module resolution.

Example:

In the published vue package, it contains

vue/package.json
vue/server-renderer/package.json
vue/server-renderer/index.mjs

When requesting vue/server-renderer, it now esolves to vue/server-renderer/index.mjs with vue/package.json. It returned vue/server-renderer/package.json before this PR.

vue/server-renderer/package.json does not participate in module resolution according to the node.js module resolution algorithm so the returned package.json resolution should not be vue/server-renderer/package.json.


Note: There is an undefined behavior for resolving the sideEffects field.

vue/package.json (sideEffects: true)
vue/server-renderer/package.json (sideEffects: true)
vue/server-renderer/index.mjs

What should sideEffects return when requesting vue/server-renderer?

  • All current bundlers observe vue/server-renderer/package.json (sideEffects: true) -resolvers assume a package has only a root package.json so they just find the closes package.json starting from the end of the resolved path
  • But vue/server-renderer/package.json never participated in module resolution, why would we end up reading its sideEffects field?

@codecov

codecov Bot commented Apr 28, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.36%. Comparing base (3636638) to head (496ea5c).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #476      +/-   ##
==========================================
+ Coverage   95.31%   95.36%   +0.05%     
==========================================
  Files          13       13              
  Lines        2709     2739      +30     
==========================================
+ Hits         2582     2612      +30     
  Misses        127      127              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Apr 28, 2025 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #476 will not alter performance

Comparing fix-package-json-nested (496ea5c) with main (3636638)

Summary

✅ 3 untouched benchmarks

@Boshen
Boshen force-pushed the fix-package-json-nested branch from acb1f38 to deaeafb Compare April 28, 2025 16:35
@Boshen
Boshen requested a review from sapphi-red April 28, 2025 16:40
@Boshen

Boshen commented Apr 28, 2025

Copy link
Copy Markdown
Member Author

3 days and this is the best I can come up with, I don't like the solution but ... it kind of works?

@Boshen
Boshen force-pushed the fix-package-json-nested branch from deaeafb to 496ea5c Compare April 29, 2025 02:10
@Boshen

Boshen commented Apr 29, 2025

Copy link
Copy Markdown
Member Author

No breakage in Rolldown, merging.

@Boshen
Boshen merged commit 17123a2 into main Apr 29, 2025
@Boshen
Boshen deleted the fix-package-json-nested branch April 29, 2025 02:23
@oxc-bot oxc-bot mentioned this pull request Apr 29, 2025
Boshen pushed a commit that referenced this pull request Apr 29, 2025
## 🤖 New release

* `oxc_resolver`: 6.0.2 -> 7.0.0 (⚠ API breaking changes)

### ⚠ `oxc_resolver` breaking changes

```text
--- failure trait_method_added: pub trait method added ---

Description:
A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/trait_method_added.ron

Failed in:
  trait method oxc_resolver::CachedPath::node_modules in file /tmp/.tmpKIFAk9/oxc-resolver/src/cache.rs:65
```

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[7.0.0](oxc_resolver-v6.0.2...oxc_resolver-v7.0.0)
- 2025-04-29

### <!-- 1 -->Bug Fixes

- return the enclosing `package.json` if it is inside `node_modules`
([#476](#476))

### <!-- 4 -->Refactor

- add `Debug` to `FsCachedPath`
([#478](#478))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
@oxc-bot oxc-bot mentioned this pull request Apr 29, 2025
hanzo-dev pushed a commit to hanzoai/unrs-resolver that referenced this pull request Sep 9, 2026
## 🤖 New release

* `oxc_resolver`: 6.0.2 -> 7.0.0 (⚠ API breaking changes)

### ⚠ `oxc_resolver` breaking changes

```text
--- failure trait_method_added: pub trait method added ---

Description:
A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/trait_method_added.ron

Failed in:
  trait method oxc_resolver::CachedPath::node_modules in file /tmp/.tmpKIFAk9/oxc-resolver/src/cache.rs:65
```

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[7.0.0](oxc-project/oxc-resolver@oxc_resolver-v6.0.2...oxc_resolver-v7.0.0)
- 2025-04-29

### <!-- 1 -->Bug Fixes

- return the enclosing `package.json` if it is inside `node_modules`
([#476](oxc-project/oxc-resolver#476))

### <!-- 4 -->Refactor

- add `Debug` to `FsCachedPath`
([#478](oxc-project/oxc-resolver#478))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: not returning the correct package.json where the path is resolved from

1 participant