Skip to content

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

TypeScript

fix(docsite): the production registry checks pages too and reports every item it leaves out on the job page (#9766)

Christopher Chedeauad50b86f5c62
diff --git a/apps/docsite/scripts/generate-data.mjs b/apps/docsite/scripts/generate-data.mjs
index 47a0e49461..4d13f0a5d3 100644
--- a/apps/docsite/scripts/generate-data.mjs
+++ b/apps/docsite/scripts/generate-data.mjs
@@ -77,7 +77,11 @@ import {
buildTypeDefinitionIndex,
collectPropTypeRefs,
} from '../src/lib/typeDefinitions.mjs';
-import {generateShadcnRegistryForTarget} from './generate-shadcn-registry.mjs';
+import {
+ generateShadcnRegistryForTarget,
+ registrySkipNotices,
+ reportRegistrySkips,
+} from './generate-shadcn-registry.mjs';
import {createPublishedImportJudge} from './published-exports.mjs';
import {
blockRegistryIdentity,
@@ -2722,20 +2726,7 @@ async function main() {
? createPublishedImportJudge(CONTENT_ROOT, packages)
: null,
});
- for (const skip of shadcnCounts.unpublishedImports) {
- console.log(
- ` ShadCN registry: not run until a release exports it: ${skip.block} ` +
- `imports ${skip.names.join(', ')} from ${skip.specifier}, which ` +
- `${skip.packageName}${skip.version ? ` ${skip.version}` : ''} does not export`,
- );
- }
- for (const kept of shadcnCounts.unreadImports) {
- console.log(
- ` ShadCN registry: could not read what ${kept.specifier} exports in ` +
- `${kept.packageName}${kept.version ? ` ${kept.version}` : ''}; ` +
- `kept ${kept.block}`,
- );
- }
+ reportRegistrySkips(registrySkipNotices(shadcnCounts));
checkShadcnRouteLock(shadcnCounts.contracts, {
allowSubset: DOCSITE_TARGET === 'latest',
});
diff --git a/apps/docsite/scripts/generate-shadcn-registry.mjs b/apps/docsite/scripts/generate-shadcn-registry.mjs
index ba86d2a145..d2f62562a1 100644
--- a/apps/docsite/scripts/generate-shadcn-registry.mjs
+++ b/apps/docsite/scripts/generate-shadcn-registry.mjs
@@ -651,63 +651,82 @@ export function buildShadcnRegistry({
const packageCatalog = new Map(packages.map(pkg => [pkg.name, pkg]));
const blockItems = [];
let skippedUnpublishedBlocks = 0;
- const unpublishedImports = [];
+ // Every item left out, with why, and every one kept unchecked, so a "not
+ // run" never reads as a pass.
+ const skippedItems = [];
const unreadImports = [];
+ function releaseOf(specifier) {
+ const pkg = packageCatalog.get(packageNameFromSpecifier(specifier));
+ return pkg == null
+ ? null
+ : {packageName: pkg.name, version: pkg.version ?? null};
+ }
+ // Whether every name an item imports from its own packages is published.
+ // A published subpath can lack a name a later release adds there, such as a
+ // new function; the item returns once a release exports it. An item whose
+ // own packages' declarations cannot be read stays, and the build names it.
+ function exportsPublished(kind, name, source) {
+ if (publishedImports == null) return true;
+ const {missing, unread} = missingPublishedImport(source, publishedImports);
+ if (missing != null) {
+ skippedItems.push({
+ kind,
+ name,
+ reason: 'export',
+ ...missing,
+ ...releaseOf(missing.specifier),
+ });
+ return false;
+ }
+ for (const specifier of unread) {
+ const release = releaseOf(specifier);
+ if (release != null) {
+ unreadImports.push({kind, name, specifier, ...release});
+ }
+ }
+ return true;
+ }
for (const block of blocks.map(withAuthoredSource)) {
// A released subpath can still lack a named component added after the last
// package release. Production blocks must satisfy both contracts: the
// imported subpath below and the published component snapshot here.
- if (
- skipBlocksWithUnavailableComponents &&
- block.componentsUsed?.some(
- componentName => !availableComponentNames.has(componentName),
- )
- ) {
+ const unavailable = skipBlocksWithUnavailableComponents
+ ? (block.componentsUsed ?? []).filter(
+ component => !availableComponentNames.has(component),
+ )
+ : [];
+ if (unavailable.length > 0) {
+ skippedItems.push({
+ kind: 'block',
+ name: block.dirName,
+ reason: 'component',
+ names: unavailable,
+ });
skippedUnpublishedBlocks++;
continue;
}
- const unpublishedComponentImport = readImportSpecifiers(
+ const undeclared = readImportSpecifiers(
block.source,
`${block.dirName}.tsx`,
).find(specifier => {
const pkg = packageCatalog.get(packageNameFromSpecifier(specifier));
return pkg != null && !packageExportsSpecifier(pkg, specifier);
});
- if (unpublishedComponentImport) {
+ if (undeclared != null) {
+ skippedItems.push({
+ kind: 'block',
+ name: block.dirName,
+ reason: 'subpath',
+ specifier: undeclared,
+ ...releaseOf(undeclared),
+ });
skippedUnpublishedBlocks++;
continue;
}
- // A published subpath can also lack a name a later release adds there,
- // such as a new function. The block returns once a release exports it.
- const {missing, unread} =
- publishedImports == null
- ? {missing: null, unread: []}
- : missingPublishedImport(block.source, publishedImports);
- if (missing != null) {
- const pkg = packageCatalog.get(
- packageNameFromSpecifier(missing.specifier),
- );
- unpublishedImports.push({
- block: block.dirName,
- ...missing,
- packageName: pkg?.name ?? packageNameFromSpecifier(missing.specifier),
- version: pkg?.version ?? null,
- });
+ if (!exportsPublished('block', block.dirName, block.source)) {
skippedUnpublishedBlocks++;
continue;
}
- // A block stays when its own packages' declarations cannot be read. The
- // build names it, so a broken check does not read as a pass.
- for (const specifier of unread) {
- const pkg = packageCatalog.get(packageNameFromSpecifier(specifier));
- if (pkg == null) continue;
- unreadImports.push({
- block: block.dirName,
- specifier,
- packageName: pkg.name,
- version: pkg.version ?? null,
- });
- }
try {
blockItems.push(
blockItem(
@@ -720,6 +739,12 @@ export function buildShadcnRegistry({
);
} catch (error) {
if (error instanceof UnpublishedAstryxDependencyError) {
+ skippedItems.push({
+ kind: 'block',
+ name: block.dirName,
+ reason: 'package',
+ packageName: error.packageName,
+ });
skippedUnpublishedBlocks++;
continue;
}
@@ -731,6 +756,10 @@ export function buildShadcnRegistry({
const pageItems = [];
let skippedUnpublishedPages = 0;
for (const template of templates.map(withAuthoredSource)) {
+ if (!exportsPublished('page', template.slug, template.source)) {
+ skippedUnpublishedPages++;
+ continue;
+ }
try {
pageItems.push(
pageItem(
@@ -743,6 +772,12 @@ export function buildShadcnRegistry({
);
} catch (error) {
if (error instanceof UnpublishedAstryxDependencyError) {
+ skippedItems.push({
+ kind: 'page',
+ name: template.slug,
+ reason: 'package',
+ packageName: error.packageName,
+ });
skippedUnpublishedPages++;
continue;
}
@@ -775,7 +810,7 @@ export function buildShadcnRegistry({
return {
registry,
items,
- unpublishedImports,
+ skippedItems,
unreadImports,
counts: {
components: componentItems.filter(
@@ -796,6 +831,84 @@ export function buildShadcnRegistry({
};
}
+function releaseText({packageName, version}) {
+ return version ? `${packageName} ${version}` : packageName;
+}
+
+const SKIP_NOTICES = {
+ component: skip =>
+ `uses ${skip.names.join(', ')}, which the published components do not include`,
+ subpath: skip =>
+ `imports ${skip.specifier}, a subpath ${releaseText(skip)} does not export`,
+ package: skip => `needs ${skip.packageName}, which has no published release`,
+ export: skip =>
+ `imports ${skip.names.join(', ')} from ${skip.specifier}, which ` +
+ `${releaseText(skip)} does not export`,
+};
+
+/** The order notices print in: GitHub's run page shows only the first ten. */
+const NOTICE_ORDER = ['export', 'unread', 'subpath', 'package', 'component'];
+
+/** One line per item the registry leaves out or keeps unchecked. */
+export function registrySkipNotices({skippedItems, unreadImports}) {
+ const lines = [
+ ...skippedItems.map(skip => ({
+ reason: skip.reason,
+ line:
+ `not run until a release has it: ${skip.kind} ${skip.name} ` +
+ SKIP_NOTICES[skip.reason](skip),
+ })),
+ ...unreadImports.map(kept => ({
+ reason: 'unread',
+ line:
+ `could not read what ${kept.specifier} exports in ` +
+ `${releaseText(kept)}; kept ${kept.kind} ${kept.name}`,
+ })),
+ ];
+ return lines
+ .sort(
+ (a, b) => NOTICE_ORDER.indexOf(a.reason) - NOTICE_ORDER.indexOf(b.reason),
+ )
+ .map(({line}) => line);
+}
+
+function workflowCommandText(text) {
+ return text
+ .replaceAll('%', '%25')
+ .replaceAll('\r', '%0D')
+ .replaceAll('\n', '%0A');
+}
+
+/**
+ * Prints each notice, and in GitHub Actions also as an annotation and a job
+ * summary list, so a "not run" never reads as a pass.
+ */
+export function reportRegistrySkips(
+ notices,
+ {env = process.env, log = console.log, appendFile = fs.appendFileSync} = {},
+) {
+ const heading = `${notices.length} not run or unchecked`;
+ if (notices.length > 0 && env.GITHUB_ACTIONS === 'true') {
+ log(
+ `::notice title=ShadCN registry::${heading}; the job summary lists them all`,
+ );
+ }
+ for (const notice of notices) {
+ log(` ShadCN registry: ${notice}`);
+ if (env.GITHUB_ACTIONS === 'true') {
+ log(`::notice title=ShadCN registry::${workflowCommandText(notice)}`);
+ }
+ }
+ if (notices.length > 0 && env.GITHUB_STEP_SUMMARY) {
+ appendFile(
+ env.GITHUB_STEP_SUMMARY,
+ `### ShadCN registry: ${heading}\n\n` +
+ notices.map(notice => `- ${notice}`).join('\n') +
+ '\n',
+ );
+ }
+}
+
function writeJson(filePath, value) {
fs.mkdirSync(path.dirname(filePath), {recursive: true});
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
@@ -848,7 +961,7 @@ export function generateShadcnRegistry({
}
return {
...result.counts,
- unpublishedImports: result.unpublishedImports,
+ skippedItems: result.skippedItems,
unreadImports: result.unreadImports,
itemNames: new Set(result.items.map(item => item.name)),
itemPaths: new Set(result.items.map(item => item.astryx.path)),
diff --git a/internal/shadcn-registry/generate-shadcn-registry.test.mjs b/internal/shadcn-registry/generate-shadcn-registry.test.mjs
index 70c3a36f61..b4040b234b 100644
--- a/internal/shadcn-registry/generate-shadcn-registry.test.mjs
+++ b/internal/shadcn-registry/generate-shadcn-registry.test.mjs
@@ -43,6 +43,8 @@ import {
buildShadcnRegistry,
generateShadcnRegistry,
generateShadcnRegistryForTarget,
+ registrySkipNotices,
+ reportRegistrySkips,
} from '../../apps/docsite/scripts/generate-shadcn-registry.mjs';
import {createPublishedImportJudge} from '../../apps/docsite/scripts/published-exports.mjs';
import {readImports} from '../../packages/cli/foundation/integrations/public-imports.mjs';
@@ -346,12 +348,22 @@ describe('buildShadcnRegistry', () => {
'export default function TimerShowcase() { return <Timer />; }\n',
});
- const {items, counts} = buildShadcnRegistry(input);
+ const {items, counts, skippedItems} = buildShadcnRegistry(input);
expect(items.map(item => item.name)).not.toContain(
'showcase-timer-default',
);
expect(counts.skippedUnpublishedBlocks).toBe(1);
+ expect(skippedItems).toEqual([
+ {
+ kind: 'block',
+ name: 'TimerShowcase',
+ reason: 'subpath',
+ specifier: '@astryxdesign/core/Timer',
+ packageName: '@astryxdesign/core',
+ version: '0.5.2',
+ },
+ ]);
});
it('skips a block that lazy-loads or re-exports an unpublished subpath', () => {
@@ -407,6 +419,14 @@ describe('buildShadcnRegistry', () => {
expect(result.total).toBe(3);
expect(result.skippedUnpublishedBlocks).toBe(1);
+ expect(result.skippedItems).toEqual([
+ {
+ kind: 'block',
+ name: 'ButtonFuture',
+ reason: 'component',
+ names: ['FutureButton'],
+ },
+ ]);
expect(
existsSync(path.join(outDir, 'showcases', 'button', 'future.json')),
).toBe(false);
@@ -431,13 +451,18 @@ describe('buildShadcnRegistry', () => {
"import {Button} from '@astryxdesign/core/Button';\n" +
'export default function ButtonAnimated() { createAnimator(null); return <Button label="Save" />; }\n',
});
- // The published release exports Button but not createAnimator.
- const publishedImports = statement =>
- statement.source.startsWith('@astryxdesign/core')
+ // The published root and Button subpath export Button but not
+ // createAnimator; this fake cannot tell for other subpaths.
+ const publishedImports = statement => {
+ if (!statement.source.startsWith('@astryxdesign/core'))
+ return undefined;
+ return statement.source === '@astryxdesign/core' ||
+ statement.source === '@astryxdesign/core/Button'
? statement.names
.map(binding => binding.imported)
.filter(name => name !== 'Button')
- : undefined;
+ : null;
+ };
const latest = generateShadcnRegistryForTarget({
target: 'latest',
@@ -454,9 +479,11 @@ describe('buildShadcnRegistry', () => {
expect(latest.total).toBe(3);
expect(latest.skippedUnpublishedBlocks).toBe(1);
- expect(latest.unpublishedImports).toEqual([
+ expect(latest.skippedItems).toEqual([
{
- block: 'ButtonAnimated',
+ kind: 'block',
+ name: 'ButtonAnimated',
+ reason: 'export',
specifier: '@astryxdesign/core',
names: ['createAnimator'],
packageName: '@astryxdesign/core',
@@ -469,7 +496,7 @@ describe('buildShadcnRegistry', () => {
),
).toBe(false);
expect(canary.total).toBe(4);
- expect(canary.unpublishedImports).toEqual([]);
+ expect(canary.skippedItems).toEqual([]);
expect(
existsSync(
path.join(root, 'canary', 'showcases', 'button', 'animated.json'),
@@ -491,6 +518,16 @@ describe('buildShadcnRegistry', () => {
path.join(dist, 'index.d.ts'),
'export declare const Button: unknown;\n',
);
+ // The page's Card subpath is declared and built.
+ mkdirSync(path.join(dist, 'Card'), {recursive: true});
+ writeFileSync(
+ path.join(dist, 'Card', 'index.js'),
+ 'export const Card = 1;\n',
+ );
+ writeFileSync(
+ path.join(dist, 'Card', 'index.d.ts'),
+ 'export declare const Card: unknown;\n',
+ );
const input = fixture();
input.blocks.push({
...input.blocks[0],
@@ -503,7 +540,14 @@ describe('buildShadcnRegistry', () => {
'export default function ButtonCounter() { const [n] = useState(0); return <Button label={String(n)} />; }\n',
});
const publishedImports = createPublishedImportJudge(root, [
- {...packages[1], packagePath: 'packages/core'},
+ {
+ ...packages[1],
+ packagePath: 'packages/core',
+ packageExports: {
+ ...packages[1].packageExports,
+ './Card': './dist/Card/index.js',
+ },
+ },
]);
const result = generateShadcnRegistryForTarget({
@@ -515,11 +559,12 @@ describe('buildShadcnRegistry', () => {
expect(result.total).toBe(4);
expect(result.skippedUnpublishedBlocks).toBe(0);
- expect(result.unpublishedImports).toEqual([]);
+ expect(result.skippedItems).toEqual([]);
// Only Astryx's own unread subpath is named; `react` stays silent.
expect(result.unreadImports).toEqual([
{
- block: 'ButtonShowcase',
+ kind: 'block',
+ name: 'ButtonShowcase',
specifier: '@astryxdesign/core/Button',
packageName: '@astryxdesign/core',
version: '0.5.2',
@@ -530,6 +575,154 @@ describe('buildShadcnRegistry', () => {
}
});
+ it('omits a production page that imports a name the published subpath lacks, and keeps it in preview', () => {
+ const root = mkdtempSync(
+ path.join(tmpdir(), 'astryx-shadcn-unpublished-page-'),
+ );
+ try {
+ const input = fixture();
+ input.templates.push({
+ ...input.templates[0],
+ slug: 'animated',
+ name: 'Animated',
+ source:
+ "import {createAnimator} from '@astryxdesign/core';\n" +
+ "import {Card} from '@astryxdesign/core/Card';\n" +
+ 'export default function Page() { createAnimator(null); return <Card />; }\n',
+ });
+ // The published release exports Button and Card, not createAnimator.
+ const publishedImports = statement =>
+ statement.source.startsWith('@astryxdesign/core')
+ ? statement.names
+ .map(binding => binding.imported)
+ .filter(name => name !== 'Button' && name !== 'Card')
+ : undefined;
+ // Both pages import the Card subpath, which this release declares.
+ const packages = input.packages.map(pkg =>
+ pkg.name === '@astryxdesign/core'
+ ? {
+ ...pkg,
+ packageExports: {
+ ...pkg.packageExports,
+ './Card': './dist/Card/index.js',
+ },
+ }
+ : pkg,
+ );
+
+ const latest = generateShadcnRegistryForTarget({
+ target: 'latest',
+ outDir: path.join(root, 'latest'),
+ publishedImports,
+ ...input,
+ packages,
+ });
+ const canary = generateShadcnRegistryForTarget({
+ target: 'canary',
+ outDir: path.join(root, 'canary'),
+ publishedImports,
+ ...input,
+ packages,
+ });
+
+ expect(latest.pages).toBe(1);
+ expect(latest.skippedUnpublishedPages).toBe(1);
+ expect(latest.skippedItems).toEqual([
+ {
+ kind: 'page',
+ name: 'animated',
+ reason: 'export',
+ specifier: '@astryxdesign/core',
+ names: ['createAnimator'],
+ packageName: '@astryxdesign/core',
+ version: '0.5.2',
+ },
+ ]);
+ expect(canary.pages).toBe(2);
+ expect(canary.skippedItems).toEqual([]);
+ } finally {
+ rmSync(root, {recursive: true, force: true});
+ }
+ });
+
+ it('reports every item the registry leaves out or keeps unchecked as lines, annotations and a job summary', () => {
+ const release = {packageName: '@astryxdesign/core', version: '0.7.6'};
+ const notices = registrySkipNotices({
+ skippedItems: [
+ {
+ kind: 'block',
+ name: 'AnimatorPlayingCardsVanilla',
+ reason: 'export',
+ specifier: '@astryxdesign/core',
+ names: ['createAnimator'],
+ ...release,
+ },
+ {
+ kind: 'block',
+ name: 'ButtonFuture',
+ reason: 'component',
+ names: ['FutureButton'],
+ },
+ {
+ kind: 'block',
+ name: 'TimerShowcase',
+ reason: 'subpath',
+ specifier: '@astryxdesign/core/Timer',
+ ...release,
+ },
+ {
+ kind: 'page',
+ name: 'chart',
+ reason: 'package',
+ packageName: '@astryxdesign/charts',
+ },
+ ],
+ unreadImports: [
+ {
+ kind: 'page',
+ name: 'dashboard',
+ specifier: '@astryxdesign/core/Card',
+ ...release,
+ },
+ ],
+ });
+ // A missing name and an unread subpath come first: the run page shows
+ // only the first ten annotations.
+ expect(notices).toEqual([
+ 'not run until a release has it: block AnimatorPlayingCardsVanilla imports createAnimator from @astryxdesign/core, which @astryxdesign/core 0.7.6 does not export',
+ 'could not read what @astryxdesign/core/Card exports in @astryxdesign/core 0.7.6; kept page dashboard',
+ 'not run until a release has it: block TimerShowcase imports @astryxdesign/core/Timer, a subpath @astryxdesign/core 0.7.6 does not export',
+ 'not run until a release has it: page chart needs @astryxdesign/charts, which has no published release',
+ 'not run until a release has it: block ButtonFuture uses FutureButton, which the published components do not include',
+ ]);
+
+ const local = [];
+ reportRegistrySkips(notices, {env: {}, log: line => local.push(line)});
+ expect(local).toEqual(
+ notices.map(notice => ` ShadCN registry: ${notice}`),
+ );
+
+ const logged = [];
+ const summary = [];
+ reportRegistrySkips(notices, {
+ env: {GITHUB_ACTIONS: 'true', GITHUB_STEP_SUMMARY: '/summary.md'},
+ log: line => logged.push(line),
+ appendFile: (file, text) => summary.push([file, text]),
+ });
+ expect(logged.filter(line => line.startsWith('::notice'))).toEqual([
+ '::notice title=ShadCN registry::5 not run or unchecked; the job summary lists them all',
+ ...notices.map(notice => `::notice title=ShadCN registry::${notice}`),
+ ]);
+ expect(summary).toEqual([
+ [
+ '/summary.md',
+ '### ShadCN registry: 5 not run or unchecked\n\n' +
+ notices.map(notice => `- ${notice}`).join('\n') +
+ '\n',
+ ],
+ ]);
+ });
+
it('judges an import against a published subpath with the CLI reader, re-exports included', () => {
const root = mkdtempSync(path.join(tmpdir(), 'astryx-published-exports-'));
try {