Skip to content
Merged
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 Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# introspection checks. Installs the published package and launches the stdio server.
FROM node:22-slim
RUN npm install -g @kyanitelabs/epoch
ENTRYPOINT ["epoch"]
ENTRYPOINT ["node", "/usr/local/lib/node_modules/@kyanitelabs/epoch/dist/index.js"]
18 changes: 16 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { realpathSync } from "node:fs";
import { pathToFileURL } from "node:url";
import { startMcpServer } from "./entries/mcp.js";
import { startHttpServer } from "./entries/http.js";
Expand Down Expand Up @@ -96,8 +97,21 @@ function main(): void {
});
}

const isEntrypoint = process.argv[1] !== undefined
&& import.meta.url === pathToFileURL(process.argv[1]).href;
function isCurrentFileEntrypoint(): boolean {
const entrypoint = process.argv[1];

if (!entrypoint) {
return false;
}

try {
return import.meta.url === pathToFileURL(realpathSync(entrypoint)).href;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve symlinked entrypoints when Node does

When the binary is invoked through npm's symlink with NODE_OPTIONS=--preserve-symlinks-main or node --preserve-symlinks-main, Node keeps import.meta.url pointed at the symlink while realpathSync(entrypoint) resolves it to dist/index.js, so this comparison returns false and main() never runs. This is a regression from the previous raw-path comparison for environments that preserve main-module symlinks; compare both the raw and realpath URLs, or realpath both sides, so the MCP server/CLI still starts in that mode.

Useful? React with 👍 / 👎.

} catch {
return import.meta.url === pathToFileURL(entrypoint).href;
}
}

const isEntrypoint = isCurrentFileEntrypoint();

if (isEntrypoint) {
main();
Expand Down