Skip to content

Support Windows #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
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
26 changes: 26 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,29 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
slug: AikidoSec/firewall-node
test-windows:
runs-on: windows-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Add local.aikido.io to hosts file
run: |
Add-Content -Path "C:\Windows\System32\drivers\etc\hosts" -Value "127.0.0.1 local.aikido.io"
- run: npm run install-lib-only
- run: npm run build
- run: npm run test:ci
- name: Upload coverage
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5
with:
files: ./library/.tap/report/lcov.info
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
slug: AikidoSec/firewall-node
3 changes: 3 additions & 0 deletions library/agent/hooks/VersionedPackage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { toWinPathIfWin } from "../../helpers/toWinPathIfWin";
import { RequireInterceptor } from "./RequireInterceptor";

export class VersionedPackage {
Expand Down Expand Up @@ -49,6 +50,8 @@ export class VersionedPackage {
relativePath = relativePath.slice(2);
}

relativePath = toWinPathIfWin(relativePath);

this.requireFileInterceptors.set(relativePath, interceptor);

return this;
Expand Down
17 changes: 11 additions & 6 deletions library/agent/hooks/getModuleInfoFromPath.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import * as t from "tap";
import { getModuleInfoFromPath } from "./getModuleInfoFromPath";
import { toWinPathIfWin as toWin } from "../../helpers/toWinPathIfWin";

t.test("it works", async (t) => {
t.same(
getModuleInfoFromPath(
"/Users/aikido/Projects/sec/node_modules/mysql/lib/Connection.js"
toWin("/Users/aikido/Projects/sec/node_modules/mysql/lib/Connection.js")
),
{
name: "mysql",
base: "/Users/aikido/Projects/sec/node_modules/mysql",
path: "lib/Connection.js",
base: toWin("/Users/aikido/Projects/sec/node_modules/mysql"),
path: toWin("lib/Connection.js"),
}
);
});

t.test("it works with scoped package", async (t) => {
t.same(
getModuleInfoFromPath(
"/Users/aikido/Projects/sec/node_modules/@google-cloud/functions-framework/build/src/logger.js"
toWin(
"/Users/aikido/Projects/sec/node_modules/@google-cloud/functions-framework/build/src/logger.js"
)
),
{
name: "@google-cloud/functions-framework",
base: "/Users/aikido/Projects/sec/node_modules/@google-cloud/functions-framework",
path: "build/src/logger.js",
base: toWin(
"/Users/aikido/Projects/sec/node_modules/@google-cloud/functions-framework"
),
path: toWin("build/src/logger.js"),
}
);
});
Expand Down
76 changes: 41 additions & 35 deletions library/agent/hooks/isMainJsFile.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
import * as t from "tap";
import { isMainJsFile } from "./isMainJsFile";
import type { PackageJson } from "type-fest";
import { sep } from "path";
import { isWindows } from "../../helpers/isWindows";

const basePackageJson: PackageJson = {
name: "aikido-module",
version: "1.0.0",
main: "./index.js",
};

const base = isWindows
? "C:\\Users\\abc\\proj\\node_modules\\aikido-module"
: "/home/user/proj/node_modules/aikido-module";

t.test("package.json main: is main file", async (t) => {
t.ok(
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "./index.js",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.js",
`${base}${sep}index.js`,
basePackageJson
)
);
t.ok(
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.js",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.js",
`${base}${sep}index.js`,
basePackageJson
)
);
Expand All @@ -39,11 +45,11 @@ t.test("package.json main: is main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "test.js",
},
"aikido-module",
"/home/user/proj/node_modules/aikido-module/test.js",
`${base}${sep}test.js`,
basePackageJson
)
);
Expand All @@ -53,11 +59,11 @@ t.test("package.json main: is main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.js",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.js",
`${base}${sep}index.js`,
// @ts-expect-error main can not be undefined in types
{
...basePackageJson,
Expand All @@ -72,11 +78,11 @@ t.test("package.json main: is not main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "test.js",
},
"abc",
"/home/user/proj/node_modules/aikido-module/test.js",
`${base}${sep}test.js`,
basePackageJson
)
);
Expand All @@ -86,11 +92,11 @@ t.test("package.json main: is not main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.js",
},
"abc",
"/home/user/proj/node_modules/aikido-module/test.js",
`${base}${sep}test.js`,
// @ts-expect-error main can not be undefined in types
{
...basePackageJson,
Expand All @@ -105,11 +111,11 @@ t.test("package.json exports: is main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.cjs",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.cjs",
`${base}${sep}index.cjs`,
// @ts-expect-error Merge
{
...basePackageJson,
Expand All @@ -121,11 +127,11 @@ t.test("package.json exports: is main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.cjs",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.cjs",
`${base}${sep}index.cjs`,
// @ts-expect-error Merge
{
...basePackageJson,
Expand All @@ -137,11 +143,11 @@ t.test("package.json exports: is main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "./test/index.cjs",
},
"abc",
"/home/user/proj/node_modules/aikido-module/test/index.cjs",
`${base}${sep}test${sep}index.cjs`,
// @ts-expect-error Merge
{
...basePackageJson,
Expand All @@ -153,11 +159,11 @@ t.test("package.json exports: is main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "./test/index.cjs",
},
"abc",
"/home/user/proj/node_modules/aikido-module/test/index.cjs",
`${base}${sep}test${sep}index.cjs`,
// @ts-expect-error Merge
{
...basePackageJson,
Expand All @@ -169,11 +175,11 @@ t.test("package.json exports: is main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.cjs",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.cjs",
`${base}${sep}index.cjs`,
// @ts-expect-error Merge
{
...basePackageJson,
Expand All @@ -191,11 +197,11 @@ t.test("package.json exports: is main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.cjs",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.cjs",
`${base}${sep}index.cjs`,
// @ts-expect-error Merge
{
...basePackageJson,
Expand All @@ -216,11 +222,11 @@ t.test("package.json exports: is main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.cjs",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.cjs",
`${base}${sep}index.cjs`,
// @ts-expect-error Merge
{
...basePackageJson,
Expand All @@ -244,11 +250,11 @@ t.test("package.json exports: is not main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.cjs",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.cjs",
`${base}${sep}index.cjs`,
// @ts-expect-error Merge
{
...basePackageJson,
Expand All @@ -260,7 +266,7 @@ t.test("package.json exports: is not main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "./test/index2.cjs",
},
"abc",
Expand All @@ -276,7 +282,7 @@ t.test("package.json exports: is not main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "./test/index.cjs",
},
"abc",
Expand All @@ -292,7 +298,7 @@ t.test("package.json exports: is not main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "./test/index.cjs",
},
"abc",
Expand All @@ -308,11 +314,11 @@ t.test("package.json exports: is not main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.cjs",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.cjs",
`${base}${sep}index.cjs`,
// @ts-expect-error Merge
{
...basePackageJson,
Expand All @@ -330,11 +336,11 @@ t.test("package.json exports: is not main file", async (t) => {
isMainJsFile(
{
name: "aikido-module",
base: "/home/user/proj/node_modules/aikido-module",
base: base,
path: "index.cjs",
},
"abc",
"/home/user/proj/node_modules/aikido-module/index.cjs",
`${base}${sep}index.cjs`,
// @ts-expect-error Merge
{
...basePackageJson,
Expand Down
9 changes: 5 additions & 4 deletions library/agent/hooks/wrapRequire.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "./wrapRequire";
import { Package } from "./Package";
import { BuiltinModule } from "./BuiltinModule";
import { sep } from "path";

t.test("Wrap require does not throw an error", async (t) => {
wrapRequire();
Expand All @@ -26,8 +27,8 @@ t.test("Can wrap external package", async (t) => {
exports._test = "aikido";
t.same(pkgInfo.name, "sqlite3");
t.same(pkgInfo.type, "external");
t.ok(pkgInfo.path?.base.endsWith("node_modules/sqlite3"));
t.same(pkgInfo.path?.relative, "lib/sqlite3.js");
t.ok(pkgInfo.path?.base.endsWith(`node_modules${sep}sqlite3`));
t.same(pkgInfo.path?.relative, `lib${sep}sqlite3.js`);
});
setPackagesToPatch([pkg]);

Expand Down Expand Up @@ -56,8 +57,8 @@ t.test("Can wrap file of external package", async (t) => {
exports._test = "aikido";
t.same(pkgInfo.name, "hono");
t.same(pkgInfo.type, "external");
t.ok(pkgInfo.path?.base.endsWith("node_modules/hono"));
t.same(pkgInfo.path?.relative, "dist/cjs/hono-base.js");
t.ok(pkgInfo.path?.base.endsWith(`node_modules${sep}hono`));
t.same(pkgInfo.path?.relative, `dist${sep}cjs${sep}hono-base.js`);
});
setPackagesToPatch([pkg]);

Expand Down
4 changes: 1 addition & 3 deletions library/helpers/isWindows.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export function isWindows() {
return process.platform === "win32";
}
export const isWindows = process.platform === "win32";
1 change: 1 addition & 0 deletions library/helpers/isWindowsCi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isWindowsCi = process.platform === "win32" && process.env.CI;
Loading
Loading