Skip to content

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

TypeScript

fix(cli): support hyphenated filenames in docs topic discovery (#1914)

nynexman4464f1baf67469d6
diff --git a/packages/cli/src/api/docs.mjs b/packages/cli/src/api/docs.mjs
index 2bf22d9f2c..c39e25c2a9 100644
--- a/packages/cli/src/api/docs.mjs
+++ b/packages/cli/src/api/docs.mjs
@@ -14,7 +14,7 @@ function discoverTopics() {
const topics = {};
if (!fs.existsSync(DOCS_DIR)) return topics;
for (const file of fs.readdirSync(DOCS_DIR)) {
- const match = file.match(/^(\w+)\.doc\.mjs$/);
+ const match = file.match(/^([\w-]+)\.doc\.mjs$/);
if (match) topics[match[1]] = path.join(DOCS_DIR, file);
}
return topics;
diff --git a/packages/cli/src/commands/docs.test.mjs b/packages/cli/src/commands/docs.test.mjs
index 284de82c41..ee3561c244 100644
--- a/packages/cli/src/commands/docs.test.mjs
+++ b/packages/cli/src/commands/docs.test.mjs
@@ -49,3 +49,32 @@ describe('registerDocs', () => {
expect(errorOutput).toContain('Unknown topic');
});
});
+
+describe('hyphenated doc filenames', () => {
+ it('lists hyphenated topics like cli-reference', async () => {
+ const program = createProgram();
+ await program.parseAsync(['node', 'xds', 'docs']);
+
+ const output = console.log.mock.calls.map(c => c[0]).join('\n');
+ expect(output).toContain('cli-reference');
+ expect(output).toContain('getting-started');
+ });
+
+ it('loads a hyphenated topic by name', async () => {
+ const program = createProgram();
+ await program.parseAsync(['node', 'xds', 'docs', 'cli-reference']);
+
+ const output = console.log.mock.calls.map(c => c[0]).join('\n');
+ // cli-reference doc should have real content, not an error
+ expect(output.length).toBeGreaterThan(0);
+ expect(console.error).not.toHaveBeenCalled();
+ });
+
+ it('returns docs.detail via API for hyphenated topic', async () => {
+ const {docs: docsApi} = await import('../api/docs.mjs');
+ const result = await docsApi('cli-reference');
+ expect(result.type).toBe('docs.detail');
+ expect(result.data).toBeDefined();
+ expect(result.data.description).toBeDefined();
+ });
+});