Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Download build artifacts
uses: actions/download-artifact@v5
with:
name: firewall-node-library-${{ github.sha }}
name: firewall-node-library-${{ github.sha }}-original-structure

- name: Install dependencies for benchmarks
run: npm run install-benchmarks-only
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
run: bash ./.github/workflows/utils/install-wasm-pack.sh

- name: Install dependencies (library only)
run: npm run install-lib-only
run: node --run install-lib-only

- name: Build complete library
run: npm run build
run: node --run build

- name: Upload build artifacts
uses: actions/upload-artifact@v5
Expand All @@ -59,3 +59,19 @@ jobs:
build/
library/internals/
library/agent/hooks/instrumentation/wasm/

- name: Build but keep structure
run: node --run build
env:
BUILD_KEEP_STRUCTURE: "true"

- name: Upload build artifacts (keep structure)
uses: actions/upload-artifact@v5
with:
name: firewall-node-library-${{ github.sha }}-original-structure
if-no-files-found: error
retention-days: 7
path: |
build/
library/internals/
library/agent/hooks/instrumentation/wasm/
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
13 changes: 8 additions & 5 deletions library/helpers/isLibBundled.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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${sep}`) &&
// In case of e2e tests where we import from build folder directly
!(
__dirname.endsWith(`${sep}build${sep}helpers`) ||
__dirname.endsWith(`${sep}build`)
)
);
}
Loading