Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

Add guardrails for repo checks (#2103)

David Petersenfbe059473502
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 7ab3f51038..f1687095dd 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -50,9 +50,9 @@ jobs:
if: steps.scope.outputs.docsite_only != 'true'
run: rm -rf .eslintcache node_modules/.cache
- - name: Check SYNC comments
+ - name: Check repository guardrails
if: steps.scope.outputs.docsite_only != 'true'
- run: node scripts/check-sync.js
+ run: yarn check:repo
- name: Run ESLint
if: steps.scope.outputs.docsite_only != 'true'
diff --git a/.husky/pre-commit b/.husky/pre-commit
index 2312dc587f..f8d6f2fe6c 100755
--- a/.husky/pre-commit
+++ b/.husky/pre-commit
@@ -1 +1,2 @@
npx lint-staged
+yarn check:repo
diff --git a/package.json b/package.json
index 58c0a86b75..e79a463f13 100644
--- a/package.json
+++ b/package.json
@@ -15,8 +15,11 @@
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest --coverage",
- "lint": "eslint .",
- "lint:strict": "XDS_STRICT_LINT=1 eslint .",
+ "check:package-boundaries": "node scripts/check-package-boundaries.js",
+ "check:repo": "yarn check:sync && yarn check:package-boundaries",
+ "check:sync": "node scripts/check-sync.js",
+ "lint": "yarn check:repo && eslint .",
+ "lint:strict": "yarn check:repo && XDS_STRICT_LINT=1 eslint .",
"storybook": "yarn workspace @xds/storybook dev",
"storybook:build": "yarn workspace @xds/storybook build",
"docs": "yarn workspace @xds/docs dev",
diff --git a/packages/core/src/Table/XDSTable.perf.test.tsx b/packages/core/src/Table/XDSTable.perf.test.tsx
index c4c9da3c29..09054e9d23 100644
--- a/packages/core/src/Table/XDSTable.perf.test.tsx
+++ b/packages/core/src/Table/XDSTable.perf.test.tsx
@@ -39,6 +39,8 @@ const testColumns: XDSTableColumn<TestRow>[] = [
{key: 'value', header: 'Value'},
];
+const ciBudgetMultiplier = process.env.CI === 'true' ? 1.5 : 1;
+
// =============================================================================
// Test: Table doesn't re-render when unrelated state changes
// =============================================================================
@@ -451,8 +453,9 @@ describe('XDSTable render performance', () => {
const renderTime = endTime - startTime;
console.log(`500 rows initial render: ${renderTime.toFixed(2)}ms`);
- // Should render within 500ms
- expect(renderTime).toBeLessThan(500);
+ // CI runners vary more than local machines, so keep the local budget
+ // strict while allowing headroom for shared-runner noise.
+ expect(renderTime).toBeLessThan(500 * ciBudgetMultiplier);
});
it('should measure update performance', async () => {
diff --git a/scripts/check-package-boundaries.js b/scripts/check-package-boundaries.js
new file mode 100644
index 0000000000..19ec0fb321
--- /dev/null
+++ b/scripts/check-package-boundaries.js
@@ -0,0 +1,77 @@
+#!/usr/bin/env node
+
+/**
+ * Package Boundary Check
+ *
+ * Keeps package-specific APIs out of the core package. Core should expose
+ * primitive XDS building blocks; shell/common wrappers belong in their owning
+ * package so consumers do not get parallel implementations.
+ */
+
+const fs = require('fs');
+const path = require('path');
+
+const ROOT = path.resolve(__dirname, '..');
+const CORE_SRC = path.join(ROOT, 'packages/core/src');
+
+const violations = [];
+
+function walk(dir) {
+ for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
+ const fullPath = path.join(dir, entry.name);
+ if (entry.isDirectory()) {
+ walk(fullPath);
+ continue;
+ }
+
+ if (!/\.(ts|tsx)$/.test(entry.name)) {
+ continue;
+ }
+
+ checkFile(fullPath);
+ }
+}
+
+function checkFile(filePath) {
+ const relPath = path.relative(ROOT, filePath);
+ const basename = path.basename(filePath);
+
+ if (/^XDSCommon[A-Z]/.test(basename)) {
+ violations.push({
+ file: relPath,
+ message: 'XDSCommon* files belong in the common package, not @xds/core.',
+ });
+ }
+
+ const content = fs.readFileSync(filePath, 'utf8');
+ const lines = content.split('\n');
+ lines.forEach((line, index) => {
+ if (
+ /^\s*export\s+(?:declare\s+)?(?:class|const|function|interface|type)\s+XDSCommon[A-Z]/.test(
+ line,
+ )
+ ) {
+ violations.push({
+ file: `${relPath}:${index + 1}`,
+ message:
+ 'Exported XDSCommon* APIs belong in the common package, not @xds/core.',
+ });
+ }
+ });
+}
+
+walk(CORE_SRC);
+
+if (violations.length === 0) {
+ console.log('Package boundaries are clean.');
+ process.exit(0);
+}
+
+console.log(`Found ${violations.length} package boundary violation(s):\n`);
+for (const violation of violations) {
+ console.log(` ${violation.file}: ${violation.message}`);
+}
+console.log(
+ '\nMove common shell integrations to their owning package or update the existing wrapper there.',
+);
+process.exit(1);