mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 23:47:33 +00:00
* perf(packages): ship npm packages without source maps and guard their size in CI No package or consumer reads the published source maps, so they are no longer built. The CLI copies only the studio app it serves instead of the whole studio dist. verify:packed-manifests now holds every published package to a size budget that ratchets down, and CI rejects pull requests that add a large binary outside LFS. * fix(ci): large-binary check reads every filename and fails on git errors * ci: run only Build when a skill bundled into the CLI changes * fix(ci): size guards also catch type changes, odd file names, unreadable blobs and bad budgets * fix(ci): large-binary check reads blobs by id and skips submodules * fix(ci): exempt only exact registry copies under docs/public/catalog * test(ci): cover the staged catalog-copy exemption; drop the local-only override hint in CI * fix(ci): producer budget follows its slimmed package; size checks name their real cause
228 lines
7.7 KiB
JavaScript
228 lines
7.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { execFileSync } from "node:child_process";
|
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join } from "node:path";
|
|
import { describe, it } from "node:test";
|
|
import {
|
|
listPackedExportContracts,
|
|
listPackageSizeIssues,
|
|
listPackedJavaScriptImportIssues,
|
|
packageExportSpecifier,
|
|
renderBrowserConsumer,
|
|
verifyCliLicense,
|
|
} from "./verify-packed-manifests.mjs";
|
|
|
|
describe("packed manifest verifier", () => {
|
|
it("passes a package inside its size budget", () => {
|
|
const budget = { packed: 1000, unpacked: 4000 };
|
|
assert.deepEqual(listPackageSizeIssues("pkg", { packed: 950, unpacked: 3900 }, budget), []);
|
|
});
|
|
|
|
it("fails a package over its size budget", () => {
|
|
const issues = listPackageSizeIssues(
|
|
"pkg",
|
|
{ packed: 1001, unpacked: 3900 },
|
|
{ packed: 1000, unpacked: 4000 },
|
|
);
|
|
assert.equal(issues.length, 1);
|
|
assert.match(issues[0], /pkg packed size 1001 bytes is over its budget of 1000/);
|
|
});
|
|
|
|
it("makes a budget follow a package down once it shrinks", () => {
|
|
const issues = listPackageSizeIssues(
|
|
"pkg",
|
|
{ packed: 500, unpacked: 3900 },
|
|
{ packed: 1000, unpacked: 4000 },
|
|
);
|
|
assert.equal(issues.length, 1);
|
|
assert.match(issues[0], /lower it to 525/);
|
|
});
|
|
|
|
it("fails a malformed budget instead of skipping the metric", () => {
|
|
const sizes = { packed: 100, unpacked: 400 };
|
|
for (const budget of [{}, { paked: 100, unpacked: 400 }, { packed: "NaN", unpacked: 400 }]) {
|
|
assert.match(listPackageSizeIssues("pkg", sizes, budget).join("\n"), /invalid packed budget/);
|
|
}
|
|
});
|
|
|
|
it("asks for a budget for a new published package", () => {
|
|
assert.match(
|
|
listPackageSizeIssues("pkg", { packed: 100, unpacked: 400 }, undefined)[0],
|
|
/"pkg": \{ "packed": 105, "unpacked": 420 \}/,
|
|
);
|
|
});
|
|
|
|
it("requires the CLI package and tarball to declare Apache-2.0", () => {
|
|
assert.throws(
|
|
() => verifyCliLicense("packages/cli", {}, {}),
|
|
/packages\/cli must declare license Apache-2\.0/,
|
|
);
|
|
assert.throws(
|
|
() => verifyCliLicense("packages/cli", { license: "Apache-2.0" }, { license: "UNLICENSED" }),
|
|
/packages\/cli packed manifest must preserve license Apache-2\.0/,
|
|
);
|
|
assert.doesNotThrow(() =>
|
|
verifyCliLicense("packages/cli", { license: "Apache-2.0" }, { license: "Apache-2.0" }),
|
|
);
|
|
});
|
|
|
|
it("keeps every browser package live even when it declares sideEffects false", () => {
|
|
const consumer = renderBrowserConsumer(["@hyperframes/parsers", "@hyperframes/lint/browser"]);
|
|
|
|
assert.match(consumer, /import \* as packedBrowserModule0 from "@hyperframes\/parsers";/);
|
|
assert.match(consumer, /import \* as packedBrowserModule1 from "@hyperframes\/lint\/browser";/);
|
|
assert.match(consumer, /packedBrowserModules\.map\(\(module\) => Object\.keys\(module\)\)/);
|
|
assert.doesNotMatch(consumer, /import "@hyperframes\/parsers"/);
|
|
});
|
|
|
|
it("derives consumer specifiers from the packed export map", () => {
|
|
assert.equal(packageExportSpecifier("@hyperframes/sdk", "."), "@hyperframes/sdk");
|
|
assert.equal(
|
|
packageExportSpecifier("@hyperframes/sdk", "./adapters/fs"),
|
|
"@hyperframes/sdk/adapters/fs",
|
|
);
|
|
assert.deepEqual(
|
|
listPackedExportContracts([
|
|
{
|
|
packedPackage: {
|
|
name: "@hyperframes/example",
|
|
exports: {
|
|
".": { import: "./dist/index.js", types: "./dist/index.d.ts" },
|
|
"./runtime": "./dist/runtime.js",
|
|
},
|
|
},
|
|
},
|
|
]),
|
|
[
|
|
{
|
|
specifier: "@hyperframes/example",
|
|
typechecked: true,
|
|
environments: ["browser", "node"],
|
|
},
|
|
{
|
|
specifier: "@hyperframes/example/runtime",
|
|
typechecked: false,
|
|
environments: ["browser", "node"],
|
|
},
|
|
],
|
|
);
|
|
});
|
|
|
|
it("uses descriptor environments to separate Node and browser promises", () => {
|
|
assert.deepEqual(
|
|
listPackedExportContracts([
|
|
{
|
|
packedPackage: {
|
|
name: "@hyperframes/example",
|
|
exports: { ".": { import: "./dist/index.js", types: "./dist/index.d.ts" } },
|
|
},
|
|
descriptor: {
|
|
subpaths: {
|
|
".": { environments: ["browser"] },
|
|
},
|
|
},
|
|
},
|
|
]),
|
|
[
|
|
{
|
|
specifier: "@hyperframes/example",
|
|
typechecked: true,
|
|
environments: ["browser"],
|
|
},
|
|
],
|
|
);
|
|
});
|
|
|
|
function withPackedFiles(files, packedFiles, callback) {
|
|
const dir = mkdtempSync(join(tmpdir(), "hyperframes-pack-test-"));
|
|
try {
|
|
const packageDir = join(dir, "package");
|
|
mkdirSync(packageDir, { recursive: true });
|
|
for (const [file, source] of Object.entries(files)) {
|
|
mkdirSync(dirname(join(packageDir, file)), { recursive: true });
|
|
writeFileSync(join(packageDir, file), source, "utf8");
|
|
}
|
|
|
|
const tarball = join(dir, "package.tgz");
|
|
execFileSync("tar", ["-czf", tarball, "-C", dir, "package"]);
|
|
callback(tarball, new Set(packedFiles));
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
}
|
|
|
|
it("passes explicit relative JavaScript imports whose target is packed", () => {
|
|
withPackedFiles(
|
|
{
|
|
"dist/index.js": 'import { runtime } from "./generated/runtime-inline.js";\n',
|
|
"dist/generated/runtime-inline.js": "export const runtime = 'ok';\n",
|
|
},
|
|
["dist/index.js", "dist/generated/runtime-inline.js"],
|
|
(tarball, packedFiles) => {
|
|
assert.deepEqual(listPackedJavaScriptImportIssues(tarball, packedFiles), []);
|
|
},
|
|
);
|
|
});
|
|
|
|
it("reports explicit relative JavaScript imports whose target is missing from the tarball", () => {
|
|
withPackedFiles(
|
|
{
|
|
"dist/index.js": 'import { runtime } from "./generated/runtime-inline.js";\n',
|
|
},
|
|
["dist/index.js"],
|
|
(tarball, packedFiles) => {
|
|
assert.deepEqual(listPackedJavaScriptImportIssues(tarball, packedFiles), [
|
|
"dist/index.js:1 imports missing ./generated/runtime-inline.js",
|
|
]);
|
|
},
|
|
);
|
|
});
|
|
|
|
it("checks export-from, dynamic import, require, and mjs/cjs files", () => {
|
|
withPackedFiles(
|
|
{
|
|
"dist/index.js": 'export * from "./generated/exports.js";\n',
|
|
"dist/dynamic.mjs": 'await import("./generated/dynamic.js");\n',
|
|
"dist/require.cjs": 'require("./generated/require.js");\n',
|
|
},
|
|
["dist/index.js", "dist/dynamic.mjs", "dist/require.cjs"],
|
|
(tarball, packedFiles) => {
|
|
assert.deepEqual(listPackedJavaScriptImportIssues(tarball, packedFiles), [
|
|
"dist/index.js:1 imports missing ./generated/exports.js",
|
|
"dist/dynamic.mjs:1 imports missing ./generated/dynamic.js",
|
|
"dist/require.cjs:1 imports missing ./generated/require.js",
|
|
]);
|
|
},
|
|
);
|
|
});
|
|
|
|
it("reports extensionless relative imports", () => {
|
|
withPackedFiles(
|
|
{
|
|
"dist/index.js": 'export {\n runtime\n} from "./generated/runtime-inline";\n',
|
|
},
|
|
["dist/index.js"],
|
|
(tarball, packedFiles) => {
|
|
assert.deepEqual(listPackedJavaScriptImportIssues(tarball, packedFiles), [
|
|
"dist/index.js:1 imports ./generated/runtime-inline",
|
|
]);
|
|
},
|
|
);
|
|
});
|
|
|
|
it("reports side-effect imports whose target is missing from the tarball", () => {
|
|
withPackedFiles(
|
|
{
|
|
"index.js": 'import "./missing.js";\n',
|
|
},
|
|
["index.js"],
|
|
(tarball, packedFiles) => {
|
|
assert.deepEqual(listPackedJavaScriptImportIssues(tarball, packedFiles), [
|
|
"index.js:1 imports missing ./missing.js",
|
|
]);
|
|
},
|
|
);
|
|
});
|
|
});
|