docs, test: clarify how to hook a module sub-path using .cjs extension#89
Open
docs, test: clarify how to hook a module sub-path using .cjs extension#89
Conversation
david-luna
approved these changes
May 7, 2024
jsumners-nr
reviewed
May 8, 2024
Comment on lines
+7
to
+11
| // E.g., a Hook arg of `cjs-sub-module/foo` will **not** hook | ||
| // `./node_modules/cjs-sub-module/foo.cjs`. This is different compared to `.js` | ||
| // file extension usage. The difference is that Node.js's `require()` treats | ||
| // `.js` and `.cjs` differently. | ||
| // See https://nodejs.org/api/modules.html#file-modules |
Contributor
There was a problem hiding this comment.
I understand the reasoning, but it would make instrumenting modules very complicated. The end user API of require-in-the-middle is that the export of whatever targeted module is provided to the hook function. The (package.json).exports map complicates this as it can resolve the same export name to multiple extensions. In my view, the hook function shouldn't need to know about that detail. It should just receive the right thing.
trentm
commented
Jul 18, 2024
| the `modules` entry. E.g. `@langchain/core/dist/callbacks/manager.cjs` is | ||
| required to hook | ||
| `.../node_modules/@langchain/core/dist/callbacks/manager.cjs`. | ||
| This is because []`.cjs` is not handled specially by `require()` the way |
Contributor
Author
There was a problem hiding this comment.
Suggested change
| This is because []`.cjs` is not handled specially by `require()` the way | |
| This is because [`.cjs` is not handled specially by `require()` the way |
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.
Refs: #88 (comment)
Repeating part of that comment above: