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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ docs/superpowers/
# GitNexus local index
.gitnexus
.worktrees
bin/omniroute.mjs
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Smart AI Router with auto fallback — route to FREE & cheap models, zero downtime. Works with Cursor, Cline, Claude Desktop, Codex, and any OpenAI-compatible tool.",
"type": "module",
"bin": {
"omniroute": "bin/omniroute.ts",
"omniroute": "bin/omniroute.mjs",
"omniroute-reset-password": "bin/reset-password.mjs"
},
"files": [
Expand Down
18 changes: 18 additions & 0 deletions scripts/prepublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,24 @@ if (existsSync(mcpSrcFile)) {
}
}

// ── Step 8.7: Bundle CLI Entrypoint ──────────────────────────
const cliSrcFile = join(ROOT, "bin", "omniroute.ts");
const cliDestFile = join(ROOT, "bin", "omniroute.mjs");

if (existsSync(cliSrcFile)) {
console.log(" 🔨 Bundling CLI Entrypoint (TypeScript → JavaScript)...");
try {
execSync(
`npx esbuild bin/omniroute.ts --bundle --platform=node --packages=external --format=esm --outfile=bin/omniroute.mjs`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update pack-artifact allowlist for new CLI binary

This build step now writes bin/omniroute.mjs, but the pack policy still only allows/requires bin/omniroute.ts in scripts/pack-artifact-policy.ts (PACK_ARTIFACT_ROOT_ALLOWED_EXACT_PATHS and PACK_ARTIFACT_REQUIRED_PATHS). Because prepublishOnly runs build:cli before check:pack-artifact, the generated .mjs is treated as an unexpected artifact and the publish gate fails even when bundling succeeds.

Useful? React with 👍 / 👎.

{ cwd: ROOT, stdio: "inherit" }
);
execSync(`chmod +x bin/omniroute.mjs`, { cwd: ROOT });
console.log(" ✅ CLI Entrypoint bundled to bin/omniroute.mjs");
} catch (err: any) {
console.warn(" ⚠️ CLI bundle error:", err.message);

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 Fail prepublish when CLI bundling step errors

If esbuild (or chmod) fails here, the script only warns and continues, but package.json now points the omniroute bin to bin/omniroute.mjs. In that path, the release can proceed without a valid CLI entrypoint, producing an installed omniroute command that fails at runtime; this should be a hard failure or at least verify the output file exists before continuing.

Useful? React with 👍 / 👎.

}
Comment on lines +381 to +390

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The bundling of the CLI entrypoint is a critical build step for the package to function correctly. There are several issues with the current implementation:

  1. Error Handling: If esbuild fails, the script currently only logs a warning and continues. Since package.json now points to bin/omniroute.mjs, a failed bundle will result in a broken npm package being published. This should be a fatal error (process.exit(1)).
  2. Cross-platform Compatibility: execSync('chmod +x ...') will fail on Windows systems, breaking the build for developers on that platform. It should be wrapped in a platform check.
  3. Artifact Policy: The new bin/omniroute.mjs file must be added to PACK_ARTIFACT_ROOT_ALLOWED_EXACT_PATHS in scripts/pack-artifact-policy.ts, otherwise the check:pack-artifact validation (which runs during prepublishOnly) will fail.

Additionally, it is highly recommended to add esbuild to devDependencies in package.json to ensure build reproducibility and avoid the overhead/unreliability of npx downloading it during the build process.

  try {
    execSync(
      `npx esbuild bin/omniroute.ts --bundle --platform=node --packages=external --format=esm --outfile=bin/omniroute.mjs`,
      { cwd: ROOT, stdio: "inherit" }
    );
    if (process.platform !== "win32") {
      execSync(`chmod +x bin/omniroute.mjs`, { cwd: ROOT });
    }
    console.log("  ✅ CLI Entrypoint bundled to bin/omniroute.mjs");
  } catch (err: any) {
    console.error("  ❌ CLI bundle error:", err.message);
    process.exit(1);
  }

}

// ── Step 9: Copy shared utilities needed at runtime ────────
const sharedApiKey = join(ROOT, "src", "shared", "utils", "apiKey.js");
const sharedApiKeyDest = join(APP_DIR, "src", "shared", "utils");
Expand Down
Loading