fix(packages): resolve npm bin entrypoint detection (#567)
Fix npm/global bin entrypoint detection for CLI and MCP server by normalizing real entry paths, including symlinked invocations.
This commit is contained in:
1 parent
2face7394b
commit
c58e85bec5
7 files changed
+127
-4
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import test from "node:test";
|
||||
import { isMainModule } from "../src/entrypoint.js";
|
||||
|
||||
test("matches a module invoked through its real file path", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "dbx-entrypoint-"));
|
||||
try {
|
||||
const entry = join(dir, "cli.js");
|
||||
await writeFile(entry, "", "utf-8");
|
||||
|
||||
assert.equal(isMainModule(pathToFileURL(entry).href, entry), true);
|
||||
} finally {
|
||||
await rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("matches a module invoked through an npm-style symlink", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "dbx-entrypoint-"));
|
||||
try {
|
||||
const entry = join(dir, "dist", "cli.js");
|
||||
const bin = join(dir, "dbx");
|
||||
await mkdir(join(dir, "dist"));
|
||||
await writeFile(entry, "", "utf-8");
|
||||
await symlink(entry, bin);
|
||||
|
||||
assert.equal(isMainModule(pathToFileURL(entry).href, bin), true);
|
||||
} finally {
|
||||
await rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("does not match a different entry file", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "dbx-entrypoint-"));
|
||||
try {
|
||||
const entry = join(dir, "cli.js");
|
||||
const other = join(dir, "other.js");
|
||||
await writeFile(entry, "", "utf-8");
|
||||
await writeFile(other, "", "utf-8");
|
||||
|
||||
assert.equal(isMainModule(pathToFileURL(entry).href, other), false);
|
||||
} finally {
|
||||
await rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user