ref: Modernize and streamline iitm/ritm for our usecase#2209
Open
Luca Forstner (lforst) wants to merge 4 commits into
Open
ref: Modernize and streamline iitm/ritm for our usecase#2209Luca Forstner (lforst) wants to merge 4 commits into
Luca Forstner (lforst) wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changed identifiers on various things for
import-in-the-middleso that we are less likely to conflict with the real one: Renamed URL marker from?iitmto?braintrust_iitmand also renamed global state identifier.Made it so that module patching is 100% explicit, meaning iitm/ritm only wraps modules passed to
new Hook([...]). We removed theinclude,exclude, orshouldIncludewhich make sense for the public package but not our forchetta.Changes some abysmal looking 2004-era-looking-ass to normal classes. Say what you will about classes but they are better than
Hook.prototype.unhook = function (this: HookInstance): void {We now have two ways to run IITM: The older way with
module.register()loader is async/off-thread, and the newermodule.registerHooks()is sync/in-process. Both need to store the next resolver int he pipeline so they can correctly resolve export * from ... while building wrapper modules. Previously they both shared onecachedResolvevariable - now we split the two intocachedAsyncResolveandcachedSyncResolveso the async path never accidentally calls a sync resolver, and vice versa.Made it so that when a package re-exports another CommonJS package from nested
node_moduleswe make sure we correctly patch it by usingprocess.cwd()instead ofimport.meta.url.Tests for everything