Skip to content

Commit 87a3f37

Browse files
fix(build): exclude filtered require.context modules (#2736)
* fix(build): exclude filtered require.context modules require.context regexps previously filtered only the runtime map after a broad eager glob had imported every file. This evaluated and bundled excluded modules, including from client components. Resolve and filter context entries during the transform so only accepted files become static dependencies. Keep context directories watched so create and delete events can update the generated module set. * test: update require-context unit tests for static-import transform * fix(build): harden require.context enumeration and bindings Replace fs.glob (withFileTypes needs Node 22.2, engines allow >=22) with a readdir walk that follows directory symlinks like webpack and guards cycles via realpath, and grow the generated import binding prefix past any identifier already present in the source. * fix(build): scope symlink cycle guard to the recursion path A global realpath set deduplicated distinct symlink aliases of the same directory; track realpaths only along the current recursion path so aliases keep their own context keys while cycles still terminate. * fix(build): stat directory entries with unknown dirent types Filesystems without dirent type info (NFS, SMB, FUSE) report entries that are neither file nor directory; fall back to stat for any unknown type instead of only symlinks, and skip unresolvable ENOENT/ELOOP entries. * fix(build): make require.context deterministic and dev-invalidation complete Assign import binding indices after sorting so readdir order cannot change bundle bytes; invalidate recursive contexts on any membership event since a directory create/delete can change matching descendants without matching the file regexp; and drop watched-context entries for updated modules so importers that lose their last require.context call stop invalidating. --------- Co-authored-by: James <james@eli.cx>
1 parent b3a82e5 commit 87a3f37

6 files changed

Lines changed: 345 additions & 77 deletions

File tree

0 commit comments

Comments
 (0)