Skip to content

ref: Modernize and streamline iitm/ritm for our usecase#2209

Open
Luca Forstner (lforst) wants to merge 4 commits into
lforst/modernize-ir-itmfrom
lforst/streamline-iitm-ritm
Open

ref: Modernize and streamline iitm/ritm for our usecase#2209
Luca Forstner (lforst) wants to merge 4 commits into
lforst/modernize-ir-itmfrom
lforst/streamline-iitm-ritm

Conversation

@lforst

Copy link
Copy Markdown
Member
  • Changed identifiers on various things for import-in-the-middle so that we are less likely to conflict with the real one: Renamed URL marker from ?iitm to ?braintrust_iitm and 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 the include, exclude, or shouldInclude which 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 newer module.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 one cachedResolve variable - now we split the two into cachedAsyncResolve and cachedSyncResolve so 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_modules we make sure we correctly patch it by using process.cwd() instead of import.meta.url.

  • Tests for everything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant