Skip to content

Commit

Permalink
Add isCJS helper, update import-in-the-middle
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoessler committed Oct 2, 2024
1 parent a97cf6a commit cc43622
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion library/agent/hooks/wrapRequire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function wrapRequire() {
`Could not find the _resolveFilename function in node:module using Node.js version ${process.version}`
);
}

Check warning on line 37 in library/agent/hooks/wrapRequire.ts

View check run for this annotation

Codecov / codecov/patch

library/agent/hooks/wrapRequire.ts#L37

Added line #L37 was not covered by tests
// Prevent wrapping the require function multiple times
isRequireWrapped = true;
// Save the original require function
Expand Down Expand Up @@ -261,5 +262,5 @@ function patchPackage(this: mod, id: string, originalExports: unknown) {
* Returns the unwrapped require function.
*/
export function getOrignalRequire() {
return originalRequire || mod.prototype.require;
return originalRequire || mod.prototype?.require;
}
9 changes: 9 additions & 0 deletions library/helpers/isCJS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as mod from "module";

/**
* Check if executed in CommonJS environment.
* This will always be true if the library is normally used because it is a CommonJS library.
*/
export function isCJS(): boolean {

Check warning on line 7 in library/helpers/isCJS.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

exported declaration 'isCJS' not used within other modules
return mod.prototype !== undefined && mod.prototype.require !== undefined;
}
7 changes: 3 additions & 4 deletions library/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc43622

Please sign in to comment.