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
18 changes: 9 additions & 9 deletions .github/architecture/repo-map.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<!-- AUTO-GENERATED by .github/scripts/generate-repo-map.mjs — run `pnpm map` to update. -->
# PolyCSS Repository Map

Tracked production code scanned across `packages/*/src`, `bench/`, and `website/src`: **465 files**, **98,571 lines**. Regenerate with `pnpm map`; verified in CI by `pnpm check:map`.
Tracked production code scanned across `packages/*/src`, `bench/`, and `website/src`: **488 files**, **98,910 lines**. Regenerate with `pnpm map`; verified in CI by `pnpm check:map`.

## 1. Packages & Entry Points

| Package | Visibility | Exports | Workspace deps | Src files | Src lines | Test files |
|---|---|---|---|---:|---:|---:|
| `packages/core` (`@layoutit/polycss-core`) | npm | `., ./three` | — | 99 | 27,290 | 58 |
| `packages/core` (`@layoutit/polycss-core`) | npm | `., ./three` | — | 104 | 27,402 | 58 |
| `packages/domformat` (`@layoutit/polycss-domformat`) | private | `., ./browser` | — | 36 | 13,165 | 0 |
| `packages/fonts` (`@layoutit/polycss-fonts`) | npm | `.` | `@layoutit/polycss-core` | 7 | 1,656 | 4 |
| `packages/morph` (`@layoutit/polycss-morph`) | npm | `., ./prepare` | `@layoutit/polycss`, `@layoutit/polycss-core` | 49 | 7,629 | 14 |
| `packages/polycss` (`@layoutit/polycss`) | npm | `., ./runtime, ./internal, ./elements, ./three` | `@layoutit/polycss-core` | 73 | 16,933 | 41 |
| `packages/polycss` (`@layoutit/polycss`) | npm | `., ./runtime, ./internal, ./elements, ./three` | `@layoutit/polycss-core` | 91 | 17,154 | 41 |
| `packages/react` (`@layoutit/polycss-react`) | npm | `., ./three` | `@layoutit/polycss`, `@layoutit/polycss-core` | 44 | 4,651 | 31 |
| `packages/skills` (`@layoutit/polycss-skills`) | npm | `.` | — | 1 | 415 | 1 |
| `packages/vue` (`@layoutit/polycss-vue`) | npm | `., ./three` | `@layoutit/polycss`, `@layoutit/polycss-core` | 42 | 4,437 | 29 |
Expand Down Expand Up @@ -45,8 +45,8 @@ Single source of truth: [`packages/workspace-aliases.mjs`](../../packages/worksp

| Fan-in | Lines | File |
|---:|---:|---|
| 113 | 528 | `packages/core/src/index.ts` |
| 87 | 248 | `packages/core/src/types.ts` |
| 123 | 528 | `packages/core/src/index.ts` |
| 92 | 248 | `packages/core/src/types.ts` |
| 38 | 301 | `packages/react/src/index.ts` |
| 33 | 119 | `website/src/components/types.ts` |
| 29 | 148 | `packages/polycss/src/runtime.ts` |
Expand All @@ -55,8 +55,8 @@ Single source of truth: [`packages/workspace-aliases.mjs`](../../packages/worksp
| 19 | 88 | `website/src/components/GalleryWorkbench/types.ts` |
| 17 | 49 | `packages/core/src/math/vec3.ts` |
| 17 | 385 | `packages/polycss/src/api/createPolyScene.ts` |
| 16 | 366 | `packages/core/src/atlas/types.ts` |
| 16 | 45 | `packages/polycss/src/render/textureAtlas.ts` |
| 13 | 121 | `packages/polycss/src/api/scene/internalTypes.ts` |

### Largest production source files

Expand All @@ -67,13 +67,13 @@ Single source of truth: [`packages/workspace-aliases.mjs`](../../packages/worksp
| 1,192 | `bench/visual-gate.mjs` |
| 1,178 | `packages/domformat/src/browser.ts` |
| 1,139 | `website/src/components/GalleryWorkbench/presets/presetFiles.ts` |
| 968 | `packages/polycss/src/snapshot/exportPolySceneSnapshot.ts` |
| 963 | `packages/core/src/atlas/plan.ts` |
| 912 | `bench/entries/lifecycle.tsx` |
| 910 | `website/src/components/GalleryWorkbench/GalleryWorkbench.tsx` |
| 885 | `packages/morph/src/contracts/validation.ts` |
| 860 | `packages/domformat/src/state/interaction.ts` |
| 840 | `packages/polycss/src/render/atlas/renderPolygons.ts` |
| 827 | `website/src/components/BuilderWorkbench/components/BuilderScene.tsx` |
| 825 | `website/src/components/GalleryWorkbench/hooks/useRouteSync.ts` |
| 801 | `packages/polycss/src/api/controls/gizmoEngine.ts` |

## 4. Core Render & Control Pipelines

Expand Down
290 changes: 290 additions & 0 deletions .github/scripts/check-doc-imports.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { WORKSPACE_SOURCE_ENTRIES } from "../../packages/workspace-aliases.mjs";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(__dirname, "..", "..");
const packagesRoot = path.join(repoRoot, "packages");

const PRIVATE_SUBPATHS = new Set(["@layoutit/polycss/internal"]);

function stripCommentsPreserveStrings(source) {
let out = "";
let i = 0;
while (i < source.length) {
const ch = source[i];
const next = source[i + 1];
if (ch === "\"" || ch === "'" || ch === "`") {
const quote = ch;
out += ch;
i += 1;
while (i < source.length) {
if (source[i] === "\\" && i + 1 < source.length) {
out += source[i] + source[i + 1];
i += 2;
continue;
}
out += source[i];
if (source[i] === quote) {
i += 1;
break;
}
i += 1;
}
continue;
}
if (ch === "/" && next === "/") {
i += 2;
while (i < source.length && source[i] !== "\n") i += 1;
continue;
}
if (ch === "/" && next === "*") {
i += 2;
while (i < source.length && !(source[i] === "*" && source[i + 1] === "/")) i += 1;
i += 2;
continue;
}
out += ch;
i += 1;
}
return out;
}

function resolveTsFile(baseFile, specifier) {
if (specifier.startsWith("@layoutit/")) {
const rel = WORKSPACE_SOURCE_ENTRIES[specifier];
return rel ? path.join(packagesRoot, rel) : null;
}
const base = path.resolve(path.dirname(baseFile), specifier.replace(/\.js$/, ""));
for (const candidate of [
`${base}.ts`,
`${base}.tsx`,
path.join(base, "index.ts"),
path.join(base, "index.tsx"),
]) {
if (fs.existsSync(candidate)) return candidate;
}
return null;
}

function parseModuleExports(filePath, visited = new Set()) {
const result = { values: new Set(), types: new Set() };
if (visited.has(filePath)) return result;
visited.add(filePath);

const stripped = stripCommentsPreserveStrings(fs.readFileSync(filePath, "utf8"));

// export { ... } / export type { ... }
for (const match of stripped.matchAll(/export\s+(type\s+)?\{([^}]*)\}/g)) {
const blockIsType = Boolean(match[1]);
for (const part of match[2].split(",")) {
const raw = part.trim();
if (!raw) continue;
const itemIsType = blockIsType || /^type\s+/.test(raw);
const cleaned = raw.replace(/^type\s+/, "");
const pieces = cleaned.split(/\s+as\s+/);
const exported = (pieces[1] ?? pieces[0]).trim();
if (!exported) continue;
if (itemIsType) result.types.add(exported);
else result.values.add(exported);
}
}

// export [declare] [async] function/const/let/var/class/enum
for (const match of stripped.matchAll(
/export\s+(?:declare\s+)?(?:async\s+)?(?:function|const|let|var|class|enum)\s+([A-Za-z_$][\w$]*)/g,
)) {
result.values.add(match[1]);
}

// export [declare] interface/type
for (const match of stripped.matchAll(
/export\s+(?:declare\s+)?(?:interface|type)\s+([A-Za-z_$][\w$]*)/g,
)) {
result.types.add(match[1]);
}

// export [type] * as ns from "..."
for (const match of stripped.matchAll(
/export\s+(type\s+)?\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s+["']([^"']+)["']/g,
)) {
if (match[1]) result.types.add(match[2]);
else result.values.add(match[2]);
}

// export [type] * from "..."
for (const match of stripped.matchAll(/export\s+(type\s+)?\*\s+from\s+["']([^"']+)["']/g)) {
const starIsType = Boolean(match[1]);
const target = resolveTsFile(filePath, match[2]);
if (!target || !fs.existsSync(target)) continue;
const nested = parseModuleExports(target, visited);
for (const name of nested.types) result.types.add(name);
for (const name of nested.values) {
if (starIsType) result.types.add(name);
else result.values.add(name);
}
}

return result;
}

function collectMarkdownFiles(dir, out = []) {
if (!fs.existsSync(dir)) return out;
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) collectMarkdownFiles(full, out);
else if (/\.(?:md|mdx)$/.test(entry.name)) out.push(full);
}
return out;
}

function extractCodeBlocksFromMarkdown(markdown) {
const blocks = [];
for (const match of markdown.matchAll(/```[^\n]*\n([\s\S]*?)```/g)) {
blocks.push(match[1]);
}
return blocks;
}

function validateSnippetImports(relFile, snippet, exportMap, errors) {
const cleaned = stripCommentsPreserveStrings(snippet);

// Check static import declarations:
// import { ... } from "spec"
// import type { ... } from "spec"
// import * as ns from "spec"
// import Def from "spec"
// import Def, { ... } from "spec"
// import "spec"
const staticImportRe =
/(?:^|[\s;])import\s+(?:(type)\s+)?(?:(\*\s+as\s+[A-Za-z_$][\w$]*)|(\{[^}]*\})|([A-Za-z_$][\w$]*)(?:\s*,\s*(\{[^}]*\}|\*\s+as\s+[A-Za-z_$][\w$]*))?)\s+from\s+["'](@layoutit\/polycss[^"']*)["']|(?:^|[\s;])import\s+["'](@layoutit\/polycss[^"']*)["']/g;

for (const match of cleaned.matchAll(staticImportRe)) {
const isTypeImport = Boolean(match[1]);
const namedBlock = match[3] ?? (match[5]?.startsWith("{") ? match[5] : undefined);
const defaultIdent = match[4];
const spec = match[6] ?? match[7];

if (PRIVATE_SUBPATHS.has(spec)) {
errors.push(`${relFile}: imports private subpath "${spec}"`);
continue;
}
const allowed = exportMap[spec];
if (!allowed) {
errors.push(`${relFile}: unknown package specifier "${spec}"`);
continue;
}
if (defaultIdent) {
errors.push(`${relFile}: default import "${defaultIdent}" from "${spec}" (no default export)`);
}
if (namedBlock) {
const inner = namedBlock.slice(1, -1);
for (const part of inner.split(",")) {
const raw = part.trim();
if (!raw) continue;
const itemIsType = isTypeImport || /^type\s+/.test(raw);
const sym = raw.replace(/^type\s+/, "").split(/\s+as\s+/)[0].trim();
if (!sym) continue;
if (itemIsType) {
if (!allowed.values.has(sym) && !allowed.types.has(sym)) {
errors.push(`${relFile}: type "${sym}" is not exported by "${spec}"`);
}
} else if (!allowed.values.has(sym)) {
if (allowed.types.has(sym)) {
errors.push(`${relFile}: "${sym}" is a type-only export of "${spec}" (use "import type")`);
} else {
errors.push(`${relFile}: "${sym}" is not exported by "${spec}"`);
}
}
}
}
}

// Dynamic import("@layoutit/polycss...")
for (const match of cleaned.matchAll(/\bimport\(\s*["'](@layoutit\/polycss[^"']*)["']\s*\)/g)) {
const spec = match[1];
if (PRIVATE_SUBPATHS.has(spec)) {
errors.push(`${relFile}: dynamic import of private subpath "${spec}"`);
} else if (!exportMap[spec]) {
errors.push(`${relFile}: dynamic import of unknown specifier "${spec}"`);
}
}
}

test("every @layoutit/polycss* import in READMEs, docs, landing tabs, and agent skill resolves against live barrels", () => {
const exportMap = {};
for (const [spec, rel] of Object.entries(WORKSPACE_SOURCE_ENTRIES)) {
if (PRIVATE_SUBPATHS.has(spec)) continue;
const abs = path.join(packagesRoot, rel);
assert.ok(fs.existsSync(abs), `missing barrel packages/${rel} for ${spec}`);
exportMap[spec] = parseModuleExports(abs);
}

const pkgReadmes = fs
.readdirSync(packagesRoot)
.filter((d) => d !== "domformat")
.map((d) => path.join(packagesRoot, d, "README.md"))
.filter((f) => fs.existsSync(f));

const docFiles = [
path.join(repoRoot, "README.md"),
...pkgReadmes,
...collectMarkdownFiles(path.join(repoRoot, "packages/skills/skill")),
...collectMarkdownFiles(path.join(repoRoot, "website/src/content/docs")),
].sort();

assert.ok(docFiles.length >= 25, `expected at least 25 doc/skill files, found ${docFiles.length}`);

const errors = [];
for (const absFile of docFiles) {
const relFile = path.relative(repoRoot, absFile);
const blocks = extractCodeBlocksFromMarkdown(fs.readFileSync(absFile, "utf8"));
for (const block of blocks) {
validateSnippetImports(relFile, block, exportMap, errors);
}
}

// Also check the landing page's embedded Vanilla/React/Vue code-tab examples.
const landingPath = path.join(repoRoot, "website/src/pages/index.astro");
if (fs.existsSync(landingPath)) {
const landingSrc = fs.readFileSync(landingPath, "utf8");
const relLanding = path.relative(repoRoot, landingPath);
for (const match of landingSrc.matchAll(/code:\s*`([\s\S]*?)`/g)) {
validateSnippetImports(relLanding, match[1], exportMap, errors);
}
}

assert.deepEqual(errors, []);
});

test("validateSnippetImports catches type-as-value imports, default imports, bad subpaths, and /internal leaks", () => {
const mockExportMap = {
"@layoutit/polycss": { values: new Set(["createPolyScene"]), types: new Set(["Polygon"]) },
"@layoutit/polycss/three": { values: new Set(["mountPolyThreeScene"]), types: new Set() },
};
const errors = [];
validateSnippetImports(
"doc.md",
[
'import { Polygon } from "@layoutit/polycss";',
'import type { Polygon } from "@layoutit/polycss";',
'import Poly from "@layoutit/polycss";',
'import { applyThreeOrthographicCameraProps } from "@layoutit/polycss/three";',
'import { foo } from "@layoutit/polycss/internal";',
'import "@layoutit/polycss/element";',
'const m = await import("@layoutit/polycss/bogus");',
].join("\n"),
mockExportMap,
errors,
);
assert.equal(errors.length, 6);
assert.ok(errors.some((e) => e.includes('type-only export of "@layoutit/polycss"')));
assert.ok(errors.some((e) => e.includes('default import "Poly"')));
assert.ok(errors.some((e) => e.includes('"applyThreeOrthographicCameraProps" is not exported')));
assert.ok(errors.some((e) => e.includes('private subpath "@layoutit/polycss/internal"')));
assert.ok(errors.some((e) => e.includes('unknown package specifier "@layoutit/polycss/element"')));
assert.ok(errors.some((e) => e.includes('dynamic import of unknown specifier "@layoutit/polycss/bogus"')));
});
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/LayoutitStudio/polycss.git"
"url": "git+https://github.com/layoutit/polycss.git"
},
"bugs": {
"url": "https://github.com/LayoutitStudio/polycss/issues"
"url": "https://github.com/layoutit/polycss/issues"
},
"homepage": "https://github.com/LayoutitStudio/polycss#readme",
"homepage": "https://github.com/layoutit/polycss#readme",
"scripts": {
"build": "pnpm -r --if-present build",
"build:packages": "pnpm --filter './packages/*' -r build",
Expand All @@ -36,16 +36,17 @@
"check:packs": "node .github/scripts/check-packs.mjs",
"check:ir": "node --test bench/renderer-ir-conformance.test.mjs",
"typecheck": "pnpm --filter './packages/*' -r --if-present typecheck",
"typecheck:website": "pnpm --filter @layoutit/polycss-website typecheck",
"test:scripts": "node --test .github/scripts/*.test.mjs bench/visual-gate.test.mjs bench/perf-gate.test.mjs bench/lifecycle-gate.test.mjs",
"check:guards": "pnpm test:scripts && pnpm check:readmes && pnpm check:skill && pnpm check:map && pnpm check:boundaries && pnpm check:mirrors --require-base && pnpm check:exports",
"verify": "pnpm check:guards && pnpm test && pnpm build:packages && pnpm typecheck && pnpm check:ir && pnpm check:packs && pnpm bench:build && pnpm --filter './examples/*' -r build",
"verify": "pnpm check:guards && pnpm test && pnpm build:packages && pnpm typecheck && pnpm typecheck:website && pnpm check:ir && pnpm check:packs && pnpm bench:build && pnpm --filter './examples/*' -r build",
"publish:all": "pnpm sync:readmes && pnpm --filter './packages/*' --filter '!@layoutit/polycss-domformat' -r publish --access public",
"dev:website": "pnpm --filter @layoutit/polycss-website dev",
"gallery:domformat": "pnpm --filter @layoutit/polycss-website generate:domformat",
"gallery:domformat:prove": "pnpm --filter @layoutit/polycss-website prove:domformat",
"gallery:domformat:verify": "pnpm --filter @layoutit/polycss-website verify:domformat",
"gallery:domformat:verify:fresh": "pnpm --filter @layoutit/polycss-website verify:domformat:fresh",
"build:website": "pnpm --filter @layoutit/polycss-website build",
"build:website": "pnpm typecheck:website && pnpm --filter @layoutit/polycss-website build",
"bench:build": "node bench/build.mjs",
"bench:serve": "node bench/perf-serve.mjs --port 4400",
"bench:perf": "node bench/build.mjs && node bench/perf-bench.mjs",
Expand Down
Loading
Loading