Skip to content
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
"license": "Apache-2.0",
"type": "module",
"bin": {
"jbctl": "dist/bin.sh"
"jbctl": "dist/bin.cjs"
},
"files": [
"dist/cli.js",
"dist/bin.sh"
"dist/bin.cjs"
],
"scripts": {
"start": "bun src/cli.ts",
"test": "bun test",
"build": "bun scripts/build.ts",
"build:all": "bun scripts/build.ts --all",
"build:npm": "bun build src/cli.ts --target node --outfile dist/cli.js && cp scripts/launcher.sh dist/bin.sh && chmod +x dist/bin.sh",
"build:npm": "bun scripts/build-npm.ts",
"prepublishOnly": "bun run build:npm"
},
"engines": {
Expand Down
21 changes: 21 additions & 0 deletions scripts/build-npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bun

import { chmodSync, copyFileSync, mkdirSync } from "node:fs";

const OUT_DIR = "dist";

async function main() {
mkdirSync(OUT_DIR, { recursive: true });

const build = Bun.spawn(
["bun", "build", "src/cli.ts", "--target", "node", "--outfile", "dist/cli.js"],
{ stdout: "inherit", stderr: "inherit" },
);
const exitCode = await build.exited;
if (exitCode !== 0) process.exit(exitCode);

copyFileSync("scripts/launcher.cjs", "dist/bin.cjs");
chmodSync("dist/bin.cjs", 0o755);
}

main();
17 changes: 17 additions & 0 deletions scripts/launcher.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const { existsSync } = require("node:fs");
const { join } = require("node:path");
const { pathToFileURL } = require("node:url");

const cliPath = join(__dirname, "cli.js");

if (!existsSync(cliPath)) {
console.error("jbctl is not built correctly: dist/cli.js is missing");
process.exit(1);
}

void import(pathToFileURL(cliPath).href).catch((importError) => {
console.error(`jbctl failed to launch: ${importError.message}`);
process.exit(1);
});
12 changes: 10 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import { ToolAdapter } from "./adapter.ts";
import { runCall } from "./commands/call.ts";
import {
getProjectLabel,
type IdeInstance,
discoverInstances,
projectPathMatches,
runDiscover,
} from "./commands/discover.ts";
import { runDoctor } from "./commands/doctor.ts";
Expand Down Expand Up @@ -49,7 +51,7 @@ async function resolveByProject(
): Promise<IdeInstance | undefined> {
// Fast path: match opened projects from config files
const matched = instances.filter((i) =>
i.openedProjects.some((p) => projectPath.startsWith(p)),
i.openedProjects.some((p) => projectPathMatches(projectPath, p)),
);
if (matched.length === 1) return matched[0];

Expand Down Expand Up @@ -159,7 +161,13 @@ async function main() {
detected = await resolveByProject(active, config.project);
if (!detected) {
const list = active
.map((i) => ` ${i.displayName} → ${i.endpoint}`)
.map((i) => {
const projects =
i.openedProjects.length > 0
? ` [${i.openedProjects.map((p) => getProjectLabel(p)).join(", ")}]`
: "";
return ` ${i.displayName}${projects} → ${i.endpoint}`;
})
.join("\n");
console.error(
`Error [CONNECTION_ERROR]: Multiple MCP-active IDEs found and none matched project "${config.project}". Specify --endpoint:\n${list}`,
Expand Down
Loading