Proposal: optional module override resolver (file-level overrides without patching core) #16240
likeabas
started this conversation in
Feature Requests & Suggestions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Related: #12641 (this complements the hook/plugin idea there and follows up on my comment in that thread)
Problem
Forks that need to swap a module (a hook, a route, a component) currently have to patch core imports, e.g.
import … from '~/extensions/…'. Every swap touches upstream files, which causes merge conflicts on every sync. Hooks (#12641) cover additive behavior well, but they don't help when a whole module needs to be replaced or wrapped.Proposal
A small, opt-in resolver that works by convention:
With no
overrides/directory, behavior is identical to vanilla LibreChat.Resolve rules
~/…) are considered../,../) are never rewritten. This lets an override wrap the stock module via a relative import, without loops.overrides/are not redirected again..ts,.tsx,.js,/index).Implementation: one shared resolve function (
stockPath → overridePath | null) with thin adapters:resolveIdplugin (dev, build, HMR)api/)module.register/_resolveFilename, alongside the existing~aliasresolverpackages/*)Error handling: a broken override fails fast rather than silently falling back to stock. An optional
OVERRIDE_RESOLVE_DEBUG=1logs which modules were overridden.Known limitation: TypeScript
pathscan't express "if file exists", so "go to definition" on a stock import opens the stock file.Questions for maintainers
overrides/) or opt-in mechanism (env flag vs. always on)?We have a PoC in progress and are happy to implement and maintain it.
All reactions