build.js
// Bundles the plugin into .lmstudio/production.js, the file LM Studio runs, with the SDK and
// zod left to node_modules so they are shared with LM Studio's own copy. With --test, also
// bundles each test file into test-dist/.
const esbuild = require("esbuild");
const fs = require("fs");
const path = require("path");
async function run() {
const common = { bundle: true, platform: "node", target: "node20", format: "cjs", external: ["@lmstudio/sdk", "zod", "canvas", "path2d-polyfill"], logLevel: "warning" };
await esbuild.build({ ...common, entryPoints: [".lmstudio/entry.ts"], outfile: ".lmstudio/production.js" });
fs.writeFileSync("install-state.json", JSON.stringify({ by: "node-plugin-installer-v1", at: Date.now() }));
if (process.argv.includes("--test")) {
const tests = fs.readdirSync("test").filter((f) => f.endsWith(".test.ts"));
await esbuild.build({ ...common, entryPoints: tests.map((f) => path.join("test", f)), outdir: "test-dist" });
const files = tests.map((f) => path.join("test-dist", f.replace(/\.ts$/, ".js")));
const run = require("child_process").spawnSync(process.execPath, ["--test", ...files], { stdio: "inherit" });
process.exit(run.status ?? 1);
}
console.log("Built .lmstudio/production.js");
}
run().catch((e) => { console.error(e); process.exit(1); });
build.js
// Bundles the plugin into .lmstudio/production.js, the file LM Studio runs, with the SDK and
// zod left to node_modules so they are shared with LM Studio's own copy. With --test, also
// bundles each test file into test-dist/.
const esbuild = require("esbuild");
const fs = require("fs");
const path = require("path");
async function run() {
const common = { bundle: true, platform: "node", target: "node20", format: "cjs", external: ["@lmstudio/sdk", "zod", "canvas", "path2d-polyfill"], logLevel: "warning" };
await esbuild.build({ ...common, entryPoints: [".lmstudio/entry.ts"], outfile: ".lmstudio/production.js" });
fs.writeFileSync("install-state.json", JSON.stringify({ by: "node-plugin-installer-v1", at: Date.now() }));
if (process.argv.includes("--test")) {
const tests = fs.readdirSync("test").filter((f) => f.endsWith(".test.ts"));
await esbuild.build({ ...common, entryPoints: tests.map((f) => path.join("test", f)), outdir: "test-dist" });
const files = tests.map((f) => path.join("test-dist", f.replace(/\.ts$/, ".js")));
const run = require("child_process").spawnSync(process.execPath, ["--test", ...files], { stdio: "inherit" });
process.exit(run.status ?? 1);
}
console.log("Built .lmstudio/production.js");
}
run().catch((e) => { console.error(e); process.exit(1); });