Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support wildcard * in alias plugin #388

Merged
merged 2 commits into from
Feb 19, 2025
Merged

feat: support wildcard * in alias plugin #388

merged 2 commits into from
Feb 19, 2025

Conversation

Boshen
Copy link
Member

@Boshen Boshen commented Feb 19, 2025

alias: {
    '@*': path.resolve(__dirname, 'src/*'), // maps `@something` to `path/to/something`
}

Ported from webpack/enhanced-resolve#439

Please note there is a small behaviour difference when compared to TypeScript's path alias resolve:

In TypeScript, when multiple patterns match a module specifier, the pattern with the longest matching prefix before any * token is used:

https://www.typescriptlang.org/docs/handbook/modules/reference.html#wildcard-substitutions

In enhanced-resolved's alias plugin, first matched alias key (in declaration order) wins.

closes #385
closes #386

```
alias: {
    '@*': path.resolve(__dirname, 'src/*'), // maps @something to path/to/something
}
```

Ported from webpack/enhanced-resolve#439

Please note there is a small behaviour difference when compared to
TypeScript's path alias resolve:

In TypeScript, when multiple patterns match a module specifier, the pattern with the longest matching prefix before any * token is used:

https://www.typescriptlang.org/docs/handbook/modules/reference.html#wildcard-substitutions

In enhanced-resolved's alias plugin, first match alias key (in declaration order) wins.

closes #385
closes #386
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.03%. Comparing base (1b0b122) to head (98bd74e).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #388      +/-   ##
==========================================
+ Coverage   95.00%   95.03%   +0.02%     
==========================================
  Files          13       13              
  Lines        2681     2697      +16     
==========================================
+ Hits         2547     2563      +16     
  Misses        134      134              

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

Copy link

codspeed-hq bot commented Feb 19, 2025

CodSpeed Performance Report

Merging #388 will degrade performances by 11.94%

Comparing alias-wildcard (98bd74e) with main (1b0b122)

Summary

❌ 3 regressions

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
resolver[multi-thread] 443.3 µs 477.4 µs -7.16%
resolver[resolve from symlinks] 51.7 ms 58.7 ms -11.94%
resolver[single-thread] 420.6 µs 446 µs -5.7%

@Boshen
Copy link
Member Author

Boshen commented Feb 19, 2025

Performance is expected to degrade due to the total number of aliases we have in our benchmark.
Every single key requires a check for *.

@Boshen Boshen merged commit cd992bf into main Feb 19, 2025
15 of 16 checks passed
@Boshen Boshen deleted the alias-wildcard branch February 19, 2025 04:48
@oxc-bot oxc-bot mentioned this pull request Feb 19, 2025
Boshen pushed a commit that referenced this pull request Feb 19, 2025
## 🤖 New release

* `oxc_resolver`: 4.1.0 -> 4.2.0 (✓ API compatible changes)

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

<blockquote>

##
[4.2.0](oxc_resolver-v4.1.0...oxc_resolver-v4.2.0)
- 2025-02-19

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

- support wildcard `*` in alias plugin (#388)
</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.

feat: alias wild cards
1 participant