An open source design system that's fully customizable and agent ready
TypeScript
fix(ci): detect new exports within modified directories (#391)
Cindy Zhange3c369fa2366
diff --git a/.github/scripts/analyze-pr.js b/.github/scripts/analyze-pr.jsindex 08b47d895b..8982e0bf91 100644--- a/.github/scripts/analyze-pr.js+++ b/.github/scripts/analyze-pr.js@@ -62,6 +62,28 @@ function componentExistsInBase(componentName) {}}+// Get exports from the base branch for a component (to detect new exports in modified dirs)+function getBaseExports(componentName) {+ try {+ const content = execSync(+ `git show ${baseBranch}:${CORE_SRC}/${componentName}/index.ts`,+ { encoding: 'utf8', stdio: 'pipe' }+ );+ const exportMatches = content.match(/export\s+{\s*([^}]+)\s*}/g) || [];+ const exports = [];+ for (const match of exportMatches) {+ const inner = match.replace(/export\s*{\s*/, '').replace(/\s*}/, '');+ exports.push(...inner.split(',').map(e => e.trim().split(' ')[0]));+ }+ if (content.includes('export default')) {+ exports.push('default');+ }+ return exports.filter(Boolean);+ } catch {+ return [];+ }+}+// Get file size in human readable formatfunction getFileSize(filePath) {try {@@ -401,6 +423,27 @@ function analyze() {componentStats[comp] = getComponentStats(comp);}+ // For modified directories, detect new exports (components that exist in HEAD+ // but not in the base branch). A directory like Layer/ may be "modified" but+ // contain brand-new exports like XDSPopover alongside existing ones.+ const newExports = [];+ for (const comp of modifiedComponents) {+ const headExports = componentStats[comp]?.exports || [];+ const baseExports = getBaseExports(comp);+ const added = headExports.filter(e => e.startsWith('XDS') && !baseExports.includes(e));+ newExports.push(...added);+ }++ // Also include all XDS exports from truly new directories+ for (const comp of newComponents) {+ const exports = componentStats[comp]?.exports || [];+ newExports.push(...exports.filter(e => e.startsWith('XDS')));+ }++ if (newExports.length > 0) {+ console.log(`New exports: ${newExports.join(', ')}`);+ }+// Build visual regression grep pattern from actual exported component names// (not directory names — e.g., Layer/ exports XDSPopover, XDSTooltip, etc.)const vrtComponents = [...new Set(@@ -411,6 +454,7 @@ function analyze() {const result = {newComponents,modifiedComponents,+ newExports,vrtComponents,componentStats,totalBundle: getTotalBundleStats(),diff --git a/.github/scripts/generate-pr-comment.js b/.github/scripts/generate-pr-comment.jsindex 7f75235f07..3f51e75c71 100644--- a/.github/scripts/generate-pr-comment.js+++ b/.github/scripts/generate-pr-comment.js@@ -98,7 +98,14 @@ if (analysis.modifiedComponents && analysis.modifiedComponents.length > 0) {const baseStats = analysis.baseComponentStats?.[comp] || {};const sbLink = getStorybookLink(storybookUrl, stats.storyTitle);const sbBadge = sbLink ? ` · ${extLink('View in Storybook', sbLink)}` : '';- componentSection += `<details>\n<summary><strong>${comp}</strong>${sbBadge}</summary>\n\n`;++ // Check if this modified directory has new exports+ const newExports = analysis.newExports || [];+ const compExports = stats.exports || [];+ const newInComp = compExports.filter(e => newExports.includes(e));+ const newBadge = newInComp.length > 0 ? ` · 🆕 ${newInComp.join(', ')}` : '';++ componentSection += `<details>\n<summary><strong>${comp}</strong>${sbBadge}${newBadge}</summary>\n\n`;componentSection += `| Metric | Before | After | Delta |\n|--------|--------|-------|-------|\n`;const esmDelta = stats.esmBytes && baseStats.esmBytes