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

implement require.extensions #18478

Merged
merged 8 commits into from
Mar 27, 2025
Merged

implement require.extensions #18478

merged 8 commits into from
Mar 27, 2025

Conversation

paperclover
Copy link
Member

@paperclover paperclover commented Mar 25, 2025

Closes #15795
Closes #15566
See BUN-11234
Closes BUN-11893
Closes BUN-11705
Closes Unitech/pm2#5964

  • require.extensions now contains the newly added extensions that Node 22-23 adds
  • require.extensions can be mutated to affect resolution and module loading
    • mutating any of these will add a slow-ish path to loading
    • mutating a built in extension will fire this slow path in more situations
    • assigning extensions['.js'], extensions['.json'], or another into a new extension will add a fast path
    • overwriting the entire extensions object isn't supported

@robobun
Copy link

robobun commented Mar 25, 2025

Updated 6:23 PM PT - Mar 26th, 2025

@paperclover, your commit 965794b5fceaaf7975f16cd01aa9b65dc03cd9f9 passed in Build #14033! 🎉


🧪   try this PR locally:

bunx bun-pr 18478

@paperclover
Copy link
Member Author

this will be rewritten to not use ProxyObject

@paperclover
Copy link
Member Author

the pr is reworked to not use a ProxyObject. instead of fixing issues in the direct calls, i have removed those implementations as i do not think it is important to support.

@paperclover paperclover marked this pull request as ready for review March 26, 2025 22:46
auto* name = propertyName.publicName();
if (!name->startsWith("."_s)) return;
BunString ext = Bun::toString(name);
uint32_t kind = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an enum

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i chose not to use an enum because it is used for a single parameter in one very specific function. the enum would have to be manually transcribed anyways, so it doesn't make it safer (until we get translate-c++)

const i = bun.strings.indexOfCharPos(basename, '.', next) orelse
return null;
next = i + 1;
if (i == 0) continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this i == 0 check be deleted? "foo/.bar" won't get a custom function if i'm understanding correctly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have had it hit. this is also a closer port to what node does here

@paperclover paperclover merged commit 70ddfb5 into main Mar 27, 2025
64 checks passed
@paperclover paperclover deleted the chloe/module6 branch March 27, 2025 21:58
Jarred-Sumner added a commit that referenced this pull request Mar 28, 2025
Jarred-Sumner added a commit that referenced this pull request Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants