Skip to content

implement require.extensions - #18478

Merged
small-angel merged 8 commits into
mainfrom
chloe/module6
Mar 27, 2025
Merged

small-angel merged 8 commits into
mainfrom
chloe/module6

Conversation

@small-angel

@small-angel small-angel commented Mar 25, 2025 •

Copy link
Copy Markdown
Contributor

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

robobun commented Mar 25, 2025 •

Copy link
Copy Markdown
Collaborator
Updated 6:23 PM PT - Mar 26th, 2025

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


🧪   try this PR locally:

bunx bun-pr 18478

Comment thread src/js/builtins/CommonJS.ts Resolved
Comment thread src/js/builtins/CommonJS.ts Resolved
@small-angel

Copy link
Copy Markdown
Contributor Author

this will be rewritten to not use ProxyObject

@small-angel

Copy link
Copy Markdown
Contributor 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.

@small-angel
small-angel 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
Copy Markdown
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
Copy Markdown
Contributor 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++)

Comment thread src/bun.js/javascript.zig Resolved
Comment thread src/bun.js/module_loader.zig Resolved
Comment thread src/bun.js/module_loader.zig Resolved
Comment thread test/internal/ban-words.test.ts Resolved
const i = bun.strings.indexOfCharPos(basename, '.', next) orelse
return null;
next = i + 1;
if (i == 0) continue;

Copy link
Copy Markdown
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
Copy Markdown
Contributor 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

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