Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): let eve/next load under node -e (#4647)

roboeve[bot]66ed5f9c735c
diff --git a/.changeset/eve-next-node-eval.md b/.changeset/eve-next-node-eval.md
new file mode 100644
index 000000000..5bb06002e
--- /dev/null
+++ b/.changeset/eve-next-node-eval.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Importing `eve/next` from a `node -e` script, such as the loader `vercel dev` uses for `next.config.*`, no longer throws `ERR_INVALID_ARG_VALUE` for `"[eval]"`.
diff --git a/packages/eve/src/internal/application/package.scenario.test.ts b/packages/eve/src/internal/application/package.scenario.test.ts
new file mode 100644
index 000000000..72fa9bbe8
--- /dev/null
+++ b/packages/eve/src/internal/application/package.scenario.test.ts
@@ -0,0 +1,19 @@
+import { execFile } from "node:child_process";
+import { promisify } from "node:util";
+
+import { describe, expect, it } from "vitest";
+
+const run = promisify(execFile);
+
+describe("package module path", () => {
+ // `node -e` defines a global `__filename` of "[eval]", which ESM modules can see.
+ it("loads eve/next under node -e", async () => {
+ const entry = new URL("../../../dist/src/public/next/index.js", import.meta.url).href;
+ const { stdout } = await run(process.execPath, [
+ "-e",
+ `import(${JSON.stringify(entry)}).then((next) => console.log(typeof next.withEve))`,
+ ]);
+
+ expect(stdout.trim()).toBe("function");
+ });
+});
diff --git a/packages/eve/src/internal/application/package.ts b/packages/eve/src/internal/application/package.ts
index 22e9f690b..39c2336f9 100644
--- a/packages/eve/src/internal/application/package.ts
+++ b/packages/eve/src/internal/application/package.ts
@@ -1,6 +1,6 @@
import { existsSync, readFileSync, realpathSync } from "node:fs";
import { createRequire } from "node:module";
-import { basename, dirname, join } from "node:path";
+import { basename, dirname, isAbsolute, join } from "node:path";
import { fileURLToPath } from "node:url";
import { readStampedPackageVersion } from "#internal/application/stamped-package-version.js";
@@ -24,7 +24,8 @@ interface PackageLocation {
}
function resolveCurrentModulePath(): string {
- if (typeof __filename === "string") {
+ // In ESM this can read a global, such as the "[eval]" Node sets under `node -e`.
+ if (typeof __filename === "string" && isAbsolute(__filename)) {
return __filename;
}