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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"scripts": {
"typecheck": "bun --filter '*' typecheck",
"test": "bun test",
"build": "bun --filter '*' build"
"build": "bun --filter '*' build",
"postinstall": "bun --filter '@loreai/gateway' build"
},
"devDependencies": {
"@types/bun": "^1.2.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"build": "bun run script/build.ts",
"bundle": "bun run script/bundle.ts",
"build:binary": "bun run script/build.ts --binary",
"start": "bun run src/index.ts",
"prepare": "node -e \"var f=require('fs'),p='dist/index.bun.js';if(!f.existsSync(p)){f.mkdirSync('dist',{recursive:true});f.writeFileSync(p,'export * from \\\"../src/index.ts\\\";\\n')}\""
"start": "bun run src/index.ts"
},
"dependencies": {
"p-limit": "7"
Expand Down
30 changes: 26 additions & 4 deletions packages/gateway/script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,32 @@ const { values: flags } = parseArgs({
// ---------------------------------------------------------------------------

async function buildLibrary() {
// No-op: the npm package is built by `bun run bundle` (script/bundle.ts)
// which produces the self-contained CJS bundle (dist/index.cjs + dist/bin.cjs).
// This function exists only so `bun run build` (workspace-wide) doesn't fail.
console.log("⏭ @loreai/gateway: use `bun run bundle` for npm build");
// Create lightweight dev shims so workspace consumers can resolve
// the "bun" export condition without running the full `bun run bundle`.
// Real bundle builds (bundle.ts) wipe dist/ first, so these shims
// never interfere with production artifacts.
mkdirSync(distDir, { recursive: true });

const shims: Array<[string, string]> = [
["index.bun.js", 'export * from "../src/index.ts";\n'],
["embedding-worker.js", 'export * from "../../core/src/embedding-worker.ts";\n'],
];

for (const [filename, content] of shims) {
const filePath = join(distDir, filename);
if (existsSync(filePath)) {
// Don't overwrite real bundle output (minified, large files).
const existing = readFileSync(filePath, "utf8");
if (!existing.startsWith("export *")) {
console.log(` ${filename}: skipped (real bundle exists)`);
continue;
}
}
writeFileSync(filePath, content);
console.log(` ${filename}: dev shim created`);
}

console.log("✓ @loreai/gateway: dev shims ready (use `bun run bundle` for npm build)");
}

// ---------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion packages/gateway/test/bundle-exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import { fileURLToPath } from "node:url";
const packageDir = join(fileURLToPath(import.meta.url), "..", "..");
const distDir = join(packageDir, "dist");
const pkgJson = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8"));
const hasBundle = existsSync(join(distDir, "index.cjs")) && existsSync(join(distDir, "index.bun.js"));
const hasBunBundle = existsSync(join(distDir, "index.bun.js")) &&
!readFileSync(join(distDir, "index.bun.js"), "utf8").startsWith("export *");
const hasBundle = existsSync(join(distDir, "index.cjs")) && hasBunBundle;

describe.skipIf(!hasBundle)("bundle exports", () => {
// -------------------------------------------------------------------------
Expand Down
Loading