mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-04 11:01:16 +01:00
perf(scripts): emit a server module beside the runtime bundle entry (#16765)
The runtime bundle now also has a server entry point, dist-runtime/server.mjs: the bundled dist/index.js without the argv shim. index.mjs loads it, so importing server.mjs loads the server code without starting it, and a compile cache warmed from it covers exactly the files a boot loads. bundleRuntime reports it as serverModule. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
c9669a6c22
commit
27709a99b1
2 files changed
+20
-2
No files matched your search
@@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
|
||||
import { mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
@@ -84,6 +85,18 @@ describe("bundleRuntime", () => {
|
||||
expect(output.entryDir).toBe(path.join(root, "server", "dist"));
|
||||
});
|
||||
|
||||
it("emits a server module that loads without starting the server", async () => {
|
||||
const outdir = path.join(root, "server", "dist-runtime");
|
||||
const summary = await bundleRuntime({ entry: path.join(root, "server", "dist", "index.js"), outdir });
|
||||
expect(summary.serverModule).toBe(path.join(outdir, "server.mjs"));
|
||||
const probe = path.join(root, "server", "probe.mjs");
|
||||
write(probe, `await import(${JSON.stringify(pathToFileURL(summary.serverModule).href)});\nconsole.log("loaded");\n`);
|
||||
const loaded = await execFileAsync(process.execPath, [probe], { cwd: path.join(root, "server"), timeout: 30_000 });
|
||||
expect(loaded.stdout.trim()).toBe("loaded");
|
||||
const started = await execFileAsync(process.execPath, [summary.outfile], { cwd: path.join(root, "server"), timeout: 30_000 });
|
||||
expect(JSON.parse(started.stdout).late).toBe(43);
|
||||
});
|
||||
|
||||
it("leaves the server's own dependencies to runtime resolution", async () => {
|
||||
const outdir = path.join(root, "server", "dist-runtime");
|
||||
const summary = await bundleRuntime({ entry: path.join(root, "server", "dist", "index.js"), outdir });
|
||||
|
||||
Reference in new issue
Block a user