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
1 change: 1 addition & 0 deletions layouts.library.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"DrawerTrigger",
"Dropdown",
"Empty",
"FieldErrorMessage",
"FieldGroup",
"Fieldset",
"FieldsetActions",
Expand Down
26 changes: 26 additions & 0 deletions scripts/check-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ const layoutLibrary = JSON.parse(readFileSync("layouts.library.json", "utf8")) a
exports?: string[];
};
const layoutExports = new Set(layoutLibrary.exports ?? []);

// Add a name only when a PascalCase root value export intentionally is not a layout export.
const NOT_LAYOUT_EXPORTS = new Set<string>();

const rootValueExports = new Set<string>();
const rootSource = readFileSync("src/index.ts", "utf8");
for (const block of rootSource.matchAll(/export\s*\{([^}]*)\}\s*from/g)) {
if (/export\s+type\s*\{/.test(block[0])) continue;
for (const raw of block[1].split(",")) {
const specifier = raw.trim();
if (!specifier || specifier.startsWith("type ")) continue;
rootValueExports.add(specifier.split(/\s+as\s+/).pop() as string);
}
}

for (const name of rootValueExports) {
if (!/^[A-Z][a-z]/.test(name)) continue;
if (layoutExports.has(name) || NOT_LAYOUT_EXPORTS.has(name)) continue;
fail(
name,
"layouts-manifest",
`${name} is a root export but absent from layouts.library.json exports`,
"Structure",
);
}

for (const family of componentFamilies) {
if (!layoutExports.has(family.name)) {
fail(
Expand Down
10 changes: 10 additions & 0 deletions tests/components/form-exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ describe("form field-level components are exported from the root", () => {
expect(FIELD_LEVEL.filter((name) => !fromBarrel.has(name))).toEqual([]);
expect(FIELD_LEVEL.filter((name) => !fromRoot.has(name))).toEqual([]);
});

it("lists every field-level component in the layouts manifest", () => {
const manifest = JSON.parse(
readFileSync(join(import.meta.dir, "../../layouts.library.json"), "utf8"),
) as { exports?: string[] };
const layoutExports = new Set(manifest.exports ?? []);

// The solid-layouts compiler refuses the consumer import when an export is missing.
expect(FIELD_LEVEL.filter((name) => !layoutExports.has(name))).toEqual([]);
});
});
Loading