mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +03:00
Completes the contributor profile: #12198 stopped OmniRoute from assembling the standalone bundle, but Next was still asked to emit one. Making output: "standalone" conditional on OMNIROUTE_BUILD_PROFILE=contributor removes the standalone tracing pass itself, which is where the remaining time went. Default builds are unaffected — the flag is read from the env at config load and is false everywhere except the contributor profile, so tests/unit/next-config.test.ts still observes output === "standalone" (18/18 green across contributor-build-script, next-config and build-profile-stubs). Reconciled on merge: CONTRIBUTING.md and scripts/build/backendOnlyPages.mjs already carried this stack's earlier steps on the tip, so both took the tip's side; only the next.config.mjs conditional and its test are this step's delta. Thanks @rafacpti23 for splitting this into four reviewable steps — it made the whole stack easy to reason about.
61 lines
2.6 KiB
JavaScript
61 lines
2.6 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import {
|
|
isContributorBuild,
|
|
stubContributorInstrumentation,
|
|
} from "../../../scripts/build/backendOnlyPages.mjs";
|
|
|
|
const nextConfigSource = fs.readFileSync(path.join(process.cwd(), "next.config.mjs"), "utf8");
|
|
|
|
const packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), "package.json"), "utf8"));
|
|
|
|
test("contributor build profile selects the webpack fallback", () => {
|
|
assert.match(packageJson.scripts["build:contributor"], /OMNIROUTE_USE_TURBOPACK=0/);
|
|
});
|
|
|
|
test("contributor build profile skips standalone packaging", () => {
|
|
assert.equal(isContributorBuild({ OMNIROUTE_BUILD_PROFILE: "contributor" }), true);
|
|
assert.equal(isContributorBuild({ OMNIROUTE_BUILD_PROFILE: "backend" }), false);
|
|
});
|
|
|
|
test("contributor instrumentation stubs are reversible", async () => {
|
|
const fs = await import("node:fs/promises");
|
|
const os = await import("node:os");
|
|
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "omniroute-contributor-"));
|
|
const instrumentationDir = path.join(tempRoot, "src");
|
|
await fs.mkdir(instrumentationDir, { recursive: true });
|
|
const files = ["instrumentation.ts", "instrumentation-node.ts"];
|
|
const originals = new Map();
|
|
for (const file of files) {
|
|
const target = path.join(instrumentationDir, file);
|
|
const source = `export async function ${file === "instrumentation.ts" ? "register" : "registerNodejs"}() { return "original"; }`;
|
|
originals.set(target, source);
|
|
await fs.writeFile(target, source);
|
|
}
|
|
const stubbed = stubContributorInstrumentation(tempRoot, { warn() {} });
|
|
assert.equal(stubbed.length, 2);
|
|
// Each stub must declare the symbol its own file really exports — instrumentation.ts
|
|
// owns Next's register(), instrumentation-node.ts owns registerNodejs().
|
|
assert.match(
|
|
await fs.readFile(path.join(instrumentationDir, "instrumentation.ts"), "utf8"),
|
|
/export async function register\(\) \{\}/
|
|
);
|
|
assert.match(
|
|
await fs.readFile(path.join(instrumentationDir, "instrumentation-node.ts"), "utf8"),
|
|
/export async function registerNodejs\(\) \{\}/
|
|
);
|
|
for (const entry of stubbed) await fs.writeFile(entry.file, entry.original);
|
|
for (const [target, source] of originals) assert.equal(await fs.readFile(target, "utf8"), source);
|
|
await fs.rm(tempRoot, { recursive: true, force: true });
|
|
});
|
|
|
|
test("contributor profile disables standalone output while default keeps it", () => {
|
|
assert.match(nextConfigSource, /isContributorBuild/);
|
|
assert.match(
|
|
nextConfigSource,
|
|
/\.\.\.\(isContributorBuild \? \{\} : \{ output: "standalone" \}\)/
|
|
);
|
|
});
|