Skip to content

Commit cc43622

Browse files
committed
Add isCJS helper, update import-in-the-middle
1 parent a97cf6a commit cc43622

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

library/agent/hooks/wrapRequire.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export function wrapRequire() {
3434
`Could not find the _resolveFilename function in node:module using Node.js version ${process.version}`
3535
);
3636
}
37+
3738
// Prevent wrapping the require function multiple times
3839
isRequireWrapped = true;
3940
// Save the original require function
@@ -261,5 +262,5 @@ function patchPackage(this: mod, id: string, originalExports: unknown) {
261262
* Returns the unwrapped require function.
262263
*/
263264
export function getOrignalRequire() {
264-
return originalRequire || mod.prototype.require;
265+
return originalRequire || mod.prototype?.require;
265266
}

library/helpers/isCJS.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as mod from "module";
2+
3+
/**
4+
* Check if executed in CommonJS environment.
5+
* This will always be true if the library is normally used because it is a CommonJS library.
6+
*/
7+
export function isCJS(): boolean {
8+
return mod.prototype !== undefined && mod.prototype.require !== undefined;
9+
}

library/package-lock.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)