Skip to content

feat(resolver): allow exports field in require('../directory')#572

Merged
Boshen merged 1 commit intomainfrom
06-26-feat_resolver_allow_exports_field_in_require_._directory_
Jun 26, 2025
Merged

feat(resolver): allow exports field in require('../directory')#572
Boshen merged 1 commit intomainfrom
06-26-feat_resolver_allow_exports_field_in_require_._directory_

Conversation

@Boshen
Copy link
Copy Markdown
Member

@Boshen Boshen commented Jun 26, 2025

closes #571

This is not part of the spec but some vite projects rely on this behavior.

Opt-in by allowPackageExportsInDirectoryResolve: true.

See

Copy link
Copy Markdown
Member Author

Boshen commented Jun 26, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 26, 2025

Codecov Report

Attention: Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.71%. Comparing base (2d6973d) to head (e5ac66e).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/lib.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #572   +/-   ##
=======================================
  Coverage   93.71%   93.71%           
=======================================
  Files          14       14           
  Lines        2911     2928   +17     
=======================================
+ Hits         2728     2744   +16     
- Misses        183      184    +1     

☔ 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-hq
Copy link
Copy Markdown

codspeed-hq bot commented Jun 26, 2025

CodSpeed Performance Report

Merging #572 will not alter performance

Comparing 06-26-feat_resolver_allow_exports_field_in_require_.directory (e5ac66e) with main (2d6973d)

Summary

✅ 3 untouched benchmarks

@ljharb
Copy link
Copy Markdown

ljharb commented Jun 26, 2025

It's a really really bad idea to have nonstandard resolution; it's far better to break projects that rely on this behavior than to allow it by default.

Would you consider, at least, doing it via a config option, so that new users won't unwittingly rely on never-going-to-be-standard behavior?

@Boshen Boshen force-pushed the 06-26-feat_resolver_allow_exports_field_in_require_._directory_ branch from 7d1b0ad to 928d7cd Compare June 26, 2025 04:59
@JounQin
Copy link
Copy Markdown
Contributor

JounQin commented Jun 26, 2025

Would you consider, at least, doing it via a config option, so that new users won't unwittingly rely on never-going-to-be-standard behavior?

@ljharb I suppose you didn't read the codes, a new option allowPackageExportsInDirectoryResolve is added and default as false.

@ljharb
Copy link
Copy Markdown

ljharb commented Jun 26, 2025

Ah, I indeed didn't, and I'm glad to hear that :-)

closes #571

This is not part of the spec but some vite projects rely on this behavior.
See
* vitejs/vite#20252
* nodejs/node#58827
@Boshen Boshen force-pushed the 06-26-feat_resolver_allow_exports_field_in_require_._directory_ branch from 928d7cd to e5ac66e Compare June 26, 2025 05:02
@Boshen Boshen merged commit 05d6b5d into main Jun 26, 2025
18 checks passed
@Boshen Boshen deleted the 06-26-feat_resolver_allow_exports_field_in_require_._directory_ branch June 26, 2025 05:06
This was referenced Jun 26, 2025
shulaoda pushed a commit to shulaoda/oxc-resolver that referenced this pull request Mar 28, 2026
## 🤖 New release

* `oxc_resolver`: 8.0.0 -> 9.0.0 (⚠ API breaking changes)
* `oxc_napi_resolver`: 8.0.0

### ⚠ `oxc_resolver` breaking changes

```text
--- failure constructible_struct_adds_field: externally-constructible struct adds field ---

Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field ResolveOptions.modules in /tmp/.tmpTBvVad/oxc-resolver/src/options.rs:114

--- 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::module_directory in file /tmp/.tmpTBvVad/oxc-resolver/src/cache.rs:69
  trait method oxc_resolver::CachedPath::cached_node_modules in file /tmp/.tmpTBvVad/oxc-resolver/src/cache.rs:76
```

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

## `oxc_resolver`

<blockquote>

##
[9.0.0](oxc-project/oxc-resolver@oxc_resolver-v8.0.0...oxc_resolver-v9.0.0)
- 2025-05-09

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

- hash import does not need to load from node_modules
([oxc-project#501](oxc-project#501))

### <!-- 7 -->Chore

- add `--tsconfig` to example
([oxc-project#505](oxc-project#505))
- publish `oxc_napi_resolver`
([oxc-project#496](oxc-project#496))
</blockquote>

## `oxc_napi_resolver`

<blockquote>

##
[8.0.0](https://github.com/oxc-project/oxc-resolver/releases/tag/oxc_napi_resolver-v8.0.0)
- 2025-05-09

### <!-- 0 -->Features

- *(napi)* add mimalloc
([oxc-project#423](oxc-project#423))
- [**breaking**] Rust Edition 2024
([oxc-project#402](oxc-project#402))
- expose `package_json_path`
([oxc-project#376](oxc-project#376))
- *(napi)* expose module type info in ResolveResult
([oxc-project#223](oxc-project#223))
- *(napi)* add tracing via `OXC_LOG:DEBUG`
([oxc-project#202](oxc-project#202))
- *(napi)* add async API
([oxc-project#191](oxc-project#191))
- add `imports_fields` option
([oxc-project#138](oxc-project#138))
- add more builder functions for options
([oxc-project#110](oxc-project#110))
- *(napi)* support wasi target
([oxc-project#31](oxc-project#31))
- add file_dependencies and missing_dependencies API
([oxc-project#50](oxc-project#50))
- *(napi)* expose cloneWithOptions and clearCache methods
([oxc-project#40](oxc-project#40))
- *(napi)* update the doc and type for tsconfig references
([oxc-project#24](oxc-project#24))
- *(napi)* add options
([oxc-project#19](oxc-project#19))
- *(resolver)* add tracing-subscriber feature
([oxc-project#904](oxc-project#904))
- *(resolver)* tsconfig project references
([oxc-project#862](oxc-project#862))
- *(resolver)* add thiserror
([oxc-project#847](oxc-project#847))
- *(resolver)* implement nested alias field
([oxc-project#795](oxc-project#795))
- *(resolver)* implement tsconfig-paths
([oxc-project#750](oxc-project#750))
- *(resolver)* implement configurable `exports_fields` option
([oxc-project#733](oxc-project#733))
- *(resolver)* implement `main_fields`
- *(resolver)* implement resolveToContext
([oxc-project#694](oxc-project#694))
- *(resolver)* implement restrictions (path only)
([oxc-project#693](oxc-project#693))
- *(resolver)* implement fully specified
([oxc-project#687](oxc-project#687))
- *(resolver)* imports field
([oxc-project#681](oxc-project#681))
- *(resolver)* finish most of exports field
([oxc-project#674](oxc-project#674))
- *(resolver)* port the rest of the exports field tests
([oxc-project#659](oxc-project#659))
- *(resolver)* implement symlinks
([oxc-project#582](oxc-project#582))
- *(resolver)* complete query and fragment parsing
([oxc-project#579](oxc-project#579))
- *(resolver)* add preferRelative and preferAbsolute
([oxc-project#577](oxc-project#577))
- *(resolver)* implement roots
([oxc-project#576](oxc-project#576))
- *(resolver)* implement fallback
([oxc-project#572](oxc-project#572))
- *(resolver)* implement enforceExtension
([oxc-project#566](oxc-project#566))
- *(resolver)* implement descriptionFiles option
([oxc-project#565](oxc-project#565))
- *(resolver)* implement the basics of path alias
([oxc-project#564](oxc-project#564))
- *(resolver)* accept different file system implementations
([oxc-project#562](oxc-project#562))
- *(resolver)* implement browser field
([oxc-project#561](oxc-project#561))
- *(resolver)* implement scoped packages
([oxc-project#558](oxc-project#558))
- *(resolver)* port incorrect description file test
([oxc-project#557](oxc-project#557))
- *(resolver)* implement extension_alias
([oxc-project#556](oxc-project#556))
- *(resolver)* port resolve tests
([oxc-project#555](oxc-project#555))
- *(resolver)* resolve extensions
([oxc-project#549](oxc-project#549))
- *(resolver)* add resolver test fixtures
([oxc-project#542](oxc-project#542))

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

- hash import does not need to load from node_modules
([oxc-project#501](oxc-project#501))
- *(napi)* `new ResolverFactory()` options should be optional
([oxc-project#256](oxc-project#256))
- *(napi)* update buggy NAPI-RS versions
([oxc-project#225](oxc-project#225))
- canonicalize is not supported on wasi target
([oxc-project#124](oxc-project#124))
- resolve "browser" field when "exports" is present
([oxc-project#59](oxc-project#59))

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

- [**breaking**] remove `description_files` option
([oxc-project#488](oxc-project#488))
- [**breaking**] remove `modules` options
([oxc-project#484](oxc-project#484))
- vitest ([oxc-project#380](oxc-project#380))
- apply latest `cargo +nightly fmt`
([oxc-project#281](oxc-project#281))
- selectively parse package_json fields instead of parsing everything
([oxc-project#103](oxc-project#103))
- *(resolver)* clean up some code and tests
- *(resolver)* change internal funcs to non-pub by moving to unit tests
([oxc-project#682](oxc-project#682))

### <!-- 7 -->Chore

- publish `oxc_napi_resolver`
([oxc-project#496](oxc-project#496))
- *(napi)* make mimalloc optional to build
([oxc-project#495](oxc-project#495))
- *(README)* add wasm usage example
- *(README)* crates.io badge use recent downloads
- *(napi)* auto download wasm binding on webcontainer
([oxc-project#471](oxc-project#471))
- use root package.json for napi build
([oxc-project#469](oxc-project#469))
- *(deps)* update github-actions
([oxc-project#444](oxc-project#444))
- *(deps)* lock file maintenance npm packages
([oxc-project#436](oxc-project#436))
- bump napi
([oxc-project#404](oxc-project#404))
- *(deps)* lock file maintenance npm packages
([oxc-project#391](oxc-project#391))
- *(deps)* lock file maintenance rust crates
([oxc-project#390](oxc-project#390))
- *(README)* clarify Rust and node.js usages
- add dprint
([oxc-project#326](oxc-project#326))
- *(deps)* update napi-rs to 3.0.0-alpha
- `cargo upgrade` && `pnpm upgrade`
- *(deps)* update napi-rs to 3.0.0-alpha
- update napi changes
- *(deps)* update rust crate napi-derive to 3.0.0-alpha
- *(deps)* update rust crate napi to 3.0.0-alpha
- *(deps)* update napi-rs to 2.16.8
- *(napi)* make napi binary smaller with minimal tracing features
([oxc-project#213](oxc-project#213))
- *(napi)* remove tokio
([oxc-project#212](oxc-project#212))
- document directory is an absolute path for `resolve(directory,
specifier)`
([oxc-project#206](oxc-project#206))
- re-enable the wasi build
([oxc-project#193](oxc-project#193))
- use pnpm workspace
([oxc-project#182](oxc-project#182))
- *(deps)* update rust crates
([oxc-project#176](oxc-project#176))
- *(napi)* update NAPI-RS cli version and binding template
([oxc-project#111](oxc-project#111))
- update project github url
- *(deps)* update pnpm to v8.14.1
([oxc-project#52](oxc-project#52))
- *(deps)* update pnpm to v8.14.0
([oxc-project#48](oxc-project#48))
- *(deps)* update pnpm to v8.13.1
([oxc-project#42](oxc-project#42))
- remove FIXME comments
- *(napi)* align `*Fields` user options with enhanced-resolve
([oxc-project#35](oxc-project#35))
- *(deps)* update pnpm to v8.12.1
([oxc-project#21](oxc-project#21))
- add some doc for napi TsconfigOptions
([oxc-project#20](oxc-project#20))
- *(deps)* update pnpm to v8.12.0
([oxc-project#18](oxc-project#18))
- *(README)* adding debugging command from Rspack
- *(deps)* update pnpm to v8.11.0
([oxc-project#9](oxc-project#9))
- *(resolver)* remove tracing_subscriber
([#1362](https://github.com/oxc-project/oxc-resolver/pull/1362))
- *(resolver)* improve documentation
([oxc-project#591](oxc-project#591))

### <!-- 8 -->CI

- check for napi .d.index changes
([oxc-project#491](oxc-project#491))
- *(release-napi)* support `riscv64gc-unknown-linux-gnu` and
`s390x-unknown-linux-gnu`
([oxc-project#451](oxc-project#451))
</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.

Support non-standard "use exports field for directory resolution" behavior

3 participants