Skip to content

Commit c44aab0

Browse files
committed
fix packaged node runtime module resolution
1 parent f13e3cb commit c44aab0

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

packaging.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Deno.test("built npm package loads in node through the published ESM entrypoint"
5050
dependencies?: Record<string, string>;
5151
devDependencies?: Record<string, string>;
5252
};
53+
const builtConfig = await Deno.readTextFile(
54+
join(workspacePath, "dist/esm/src/config.js"),
55+
);
5356
assertEquals(
5457
builtPackage.dependencies?.cosmiconfig,
5558
"^9.0.0",
@@ -60,6 +63,11 @@ Deno.test("built npm package loads in node through the published ESM entrypoint"
6063
"string",
6164
"generated npm package must declare Node typings for dnt typecheck",
6265
);
66+
assertEquals(
67+
builtConfig.includes("import-meta-ponyfill-esmodule"),
68+
false,
69+
"generated config loader should not depend on DNT import-meta ponyfill",
70+
);
6371

6472
const tempDir = await Deno.makeTempDir();
6573
try {

src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os from "node:os";
22
import { createRequire } from "node:module";
33
import { join } from "node:path";
4+
import process from "node:process";
45
import { redactEndpointUserInfo } from "./services/endpoint-redaction.ts";
56
import { notifyPluginWarning } from "./services/opencode-warning.ts";
67
import type { GraphitiConfig, RawGraphitiConfig } from "./types/index.ts";
@@ -60,7 +61,9 @@ export interface ConfigExplorerAdapter {
6061

6162
type ConfigExplorerFactory = () => ConfigExplorerAdapter;
6263

63-
const nodeRequire = createRequire(import.meta.url);
64+
const nodeRequire = createRequire(
65+
join(process.cwd(), "graphiti.config.runtime.cjs"),
66+
);
6467

6568
const isRecord = (value: unknown): value is Record<string, unknown> =>
6669
!!value && typeof value === "object" && !Array.isArray(value);

src/services/connection-manager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { createRequire } from "node:module";
2+
import { join } from "node:path";
23
import { pathToFileURL } from "node:url";
4+
import process from "node:process";
35
import manifest from "../../deno.json" with { type: "json" };
46
import { isAbortError } from "../utils.ts";
57
import { redactEndpointUserInfo } from "./endpoint-redaction.ts";
@@ -26,7 +28,9 @@ type McpRuntimeModules = {
2628
StreamableHTTPClientTransport: McpTransportConstructor;
2729
};
2830

29-
const nodeRequire = createRequire(import.meta.url);
31+
const nodeRequire = createRequire(
32+
pathToFileURL(join(process.cwd(), "graphiti.runtime.cjs")).href,
33+
);
3034
let mcpRuntimeModulesPromise: Promise<McpRuntimeModules> | null = null;
3135

3236
const importResolvedModule = async <T>(specifier: string): Promise<T> => {

0 commit comments

Comments
 (0)