Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions library/agent/hooks/onInspectionInterceptorResult.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable max-lines-per-function */
import { resolve } from "path";
import { cleanupStackTrace } from "../../helpers/cleanupStackTrace";
import { escapeHTML } from "../../helpers/escapeHTML";
import type { Agent } from "../Agent";
Expand All @@ -13,9 +11,10 @@ import {
} from "./InterceptorResult";
import type { PartialWrapPackageInfo } from "./WrapPackageInfo";
import { cleanError } from "../../helpers/cleanError";
import { getLibraryRoot } from "../../helpers/getLibraryRoot";

// Used for cleaning up the stack trace
const libraryRoot = resolve(__dirname, "../..");
const libraryRoot = getLibraryRoot();

export function onInspectionInterceptorResult(
context: ReturnType<typeof getContext>,
Expand Down
5 changes: 3 additions & 2 deletions library/helpers/getAgentVersion.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { resolve } from "path";
import { join } from "path";
import { getLibraryRoot } from "./getLibraryRoot";

export function getAgentVersion(): string {
try {
const json = require(resolve(__dirname, "../package.json"));
const json = require(join(getLibraryRoot(), "package.json"));

/* c8 ignore start */
if (!json.version) {
Expand Down
6 changes: 4 additions & 2 deletions library/helpers/getLibraryRoot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { resolve } from "path";
import { sep, resolve } from "path";

const libraryRoot = resolve(__dirname, "..");
const isBundled = !__filename.includes(`${sep}helpers${sep}getLibraryRoot`);

const libraryRoot = resolve(__dirname, isBundled ? "." : "..");

export function getLibraryRoot(): string {
return libraryRoot;
Expand Down
9 changes: 4 additions & 5 deletions library/helpers/isLibBundled.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { sep } from "path";

// Detect at runtime if the library is bundled inside an application
export function isLibBundled(): boolean {
// Replace Windows backslashes with forward slashes
const normalizedDirName = __dirname.replace(/\\/g, "/");

return (
!normalizedDirName.includes("node_modules/@aikidosec/firewall/helpers") &&
!normalizedDirName.includes("/build/helpers") // In case of e2e tests
!__dirname.includes(`node_modules${sep}@aikidosec${sep}firewall`) &&
!__dirname.includes(`firewall-node${sep}build`) // In case of e2e tests
);
}
Loading
Loading