@astryxdesign/cli 0.7.2-canary.6a3ff0f → 0.7.2-canary.6c792d8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +62 -62
  2. package/api/component/_adapter.d.mts +31 -0
  3. package/api/component/_adapter.mjs +116 -0
  4. package/api/component/component.mjs +60 -10
  5. package/api/component/doc-links.test.mjs +386 -0
  6. package/api/discover/_adapter.d.mts +119 -12
  7. package/api/discover/_adapter.mjs +449 -10
  8. package/api/discover/_adapter.test.mjs +599 -17
  9. package/api/discover/_catalog-view.d.mts +16 -5
  10. package/api/discover/_catalog-view.mjs +32 -8
  11. package/api/discover/detail/doc/doc.mjs +9 -1
  12. package/api/discover/discover.d.mts +11 -0
  13. package/api/discover/discover.doc.mjs +7 -6
  14. package/api/discover/discover.mjs +107 -19
  15. package/api/discover/discover.type.d.mts +18 -7
  16. package/api/discover/discover.type.mjs +15 -7
  17. package/api/discover/list/list.d.mts +4 -3
  18. package/api/discover/list/list.mjs +17 -10
  19. package/api/docs/_adapter.d.mts +63 -0
  20. package/api/docs/_adapter.mjs +309 -16
  21. package/api/docs/integration-tree.test.mjs +22 -0
  22. package/api/docs/list/list.mjs +12 -2
  23. package/api/doctor/theme-checks.test.mjs +136 -0
  24. package/api/integration/_adapter.d.mts +33 -0
  25. package/api/integration/_adapter.mjs +58 -0
  26. package/api/integration/authoring-checks.mjs +98 -3
  27. package/api/integration/authoring-checks.test.mjs +769 -0
  28. package/api/integration/authoring-checks.type.d.mts +134 -0
  29. package/api/integration/authoring-checks.type.mjs +60 -1
  30. package/api/integration/integrationComponentConflicts.doc.mjs +3 -1
  31. package/api/integration/integrationDocConflicts.doc.mjs +22 -5
  32. package/api/integration/pack-check.mjs +296 -7
  33. package/api/integration/pack-check.test.mjs +367 -0
  34. package/api/integration/validate-integration-fixes.test.mjs +67 -0
  35. package/api/integration/validate-integration.mjs +28 -3
  36. package/api/integration/validate-integration.test.mjs +77 -8
  37. package/api/integration/validateIntegration.doc.mjs +1 -1
  38. package/api/search/search.mjs +2 -1
  39. package/assets/discover/official-packages.json +367 -0
  40. package/assets/docs/author-a-theme.doc.mjs +2 -2
  41. package/assets/docs/browser-support.doc.mjs +1 -1
  42. package/assets/docs/styling-overview.doc.mjs +1 -1
  43. package/assets/docs/theme.doc.mjs +1 -1
  44. package/assets/docs/tree/add-a-topic.doc.mjs +3 -3
  45. package/assets/docs/tree/check-the-props.doc.mjs +7 -2
  46. package/assets/docs/tree/check-your-docs.doc.mjs +15 -3
  47. package/assets/docs/tree/checks.doc.mjs +5 -5
  48. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -7
  49. package/assets/docs/tree/document-the-theme.doc.mjs +2 -2
  50. package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
  51. package/assets/docs/tree/layout.doc.mjs +6 -6
  52. package/assets/docs/tree/migration-setup.doc.mjs +2 -2
  53. package/assets/docs/tree/publishing.doc.mjs +3 -3
  54. package/assets/docs/tree/quick-start.doc.mjs +2 -2
  55. package/assets/docs/tree/sections-and-placement.doc.mjs +2 -2
  56. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  57. package/assets/docs/tree/troubleshooting.doc.mjs +5 -5
  58. package/assets/docs/tree/upgrading.doc.mjs +1 -1
  59. package/authoring/discover/discover.doc.mjs +1 -1
  60. package/authoring/doctypes/component/component.doc.mjs +1 -1
  61. package/authoring/doctypes/component/type.ts +8 -0
  62. package/authoring/doctypes/hook/type.ts +4 -0
  63. package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
  64. package/clients/cli/commands/discover.doc.mjs +1 -1
  65. package/clients/cli/commands/discover.mjs +144 -93
  66. package/clients/cli/commands/discover.no-source.test.mjs +447 -33
  67. package/clients/cli/commands/discover.sources.test.mjs +20 -1
  68. package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -2
  69. package/clients/cli/commands/doctor-integration-docs.doc.mjs +19 -5
  70. package/clients/cli/commands/doctor-integration.test.mjs +48 -1
  71. package/clients/cli/commands/doctor.mjs +91 -5
  72. package/clients/cli/commands/integration-authoring.test.mjs +46 -0
  73. package/clients/cli/commands/integration-check.test.mjs +127 -0
  74. package/clients/cli/commands/integration.mjs +10 -4
  75. package/clients/cli/commands/json-contract.test.mjs +5 -1
  76. package/foundation/discovery/copied-passages.d.mts +216 -0
  77. package/foundation/discovery/copied-passages.mjs +720 -0
  78. package/foundation/discovery/copied-passages.test.mjs +124 -0
  79. package/foundation/discovery/doc-consistency.d.mts +34 -0
  80. package/foundation/discovery/doc-consistency.mjs +513 -0
  81. package/foundation/discovery/doc-consistency.test.mjs +347 -0
  82. package/foundation/discovery/doc-fluff.d.mts +112 -0
  83. package/foundation/discovery/doc-fluff.mjs +328 -0
  84. package/foundation/discovery/doc-fluff.test.mjs +142 -0
  85. package/foundation/discovery/doc-types.mjs +12 -5
  86. package/foundation/discovery/doc-types.test.mjs +46 -2
  87. package/foundation/discovery/docs-discovery.d.mts +7 -0
  88. package/foundation/discovery/docs-discovery.mjs +26 -2
  89. package/foundation/discovery/prop-drift.d.mts +25 -6
  90. package/foundation/discovery/prop-drift.mjs +171 -6
  91. package/foundation/discovery/prop-drift.test.mjs +65 -0
  92. package/foundation/discovery/stray-pointers.d.mts +52 -0
  93. package/foundation/discovery/stray-pointers.mjs +293 -0
  94. package/foundation/discovery/stray-pointers.test.mjs +86 -0
  95. package/foundation/doc-compiler/doc-loads.test.mjs +16 -0
  96. package/foundation/doc-compiler/links.d.mts +32 -0
  97. package/foundation/doc-compiler/links.mjs +163 -26
  98. package/foundation/doc-compiler/links.test.mjs +97 -4
  99. package/foundation/doc-compiler/tree.mjs +30 -1
  100. package/foundation/doc-compiler/tree.test.mjs +7 -0
  101. package/foundation/fs/module-loader.d.mts +2 -1
  102. package/foundation/fs/module-loader.mjs +60 -4
  103. package/foundation/fs/module-loader.test.mjs +194 -0
  104. package/foundation/integrations/contribution-inventory.d.mts +11 -0
  105. package/foundation/integrations/contribution-inventory.mjs +50 -2
  106. package/foundation/integrations/issue.ts +6 -0
  107. package/foundation/integrations/validate-contributions.mjs +30 -1
  108. package/foundation/response/response-types.doc.mjs +5 -5
  109. package/package.json +11 -11
@@ -213,6 +213,7 @@ function writePackage({
213
213
  themeExports = false,
214
214
  npmignore,
215
215
  components = false,
216
+ templates = false,
216
217
  scripts,
217
218
  } = {}) {
218
219
  const pkg = {name, version};
@@ -272,6 +273,14 @@ export default {type: 'theme', name: 'ocean', displayName: 'Ocean', description:
272
273
  'export default function Card() { return null; }\n',
273
274
  );
274
275
  }
276
+ if (templates) {
277
+ const root = path.join(tmpDir, 'templates');
278
+ fs.mkdirSync(root, {recursive: true});
279
+ fs.writeFileSync(
280
+ path.join(root, 'stray.tsx'),
281
+ 'export default function Stray() { return null; }\n',
282
+ );
283
+ }
275
284
  if (npmignore) {
276
285
  fs.writeFileSync(path.join(tmpDir, '.npmignore'), npmignore);
277
286
  }
@@ -303,6 +312,347 @@ function runCliVerify() {
303
312
  };
304
313
  }
305
314
 
315
+ /**
316
+ * Give the built ocean theme a font stylesheet and an entry module that loads
317
+ * the theme's own styles, and export them the way such a package does.
318
+ * @param {string} entry
319
+ * @param {string} [file] the entry's file name in `entries/`
320
+ */
321
+ function writeOwnStylesEntry(entry, file = 'ocean.mjs') {
322
+ fs.writeFileSync(
323
+ path.join(tmpDir, 'themes', 'ocean', 'ocean.fonts.css'),
324
+ "@font-face { font-family: 'Ocean Sans'; src: local('Ocean Sans'); }\n",
325
+ );
326
+ fs.mkdirSync(path.join(tmpDir, 'entries'), {recursive: true});
327
+ fs.writeFileSync(path.join(tmpDir, 'entries', file), entry);
328
+ const packageFile = path.join(tmpDir, 'package.json');
329
+ const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf-8'));
330
+ pkg.files = ['astryx.integration.mjs', 'themes', 'entries'];
331
+ pkg.exports = {
332
+ './themes/ocean': `./entries/${file}`,
333
+ './themes/ocean.css': './themes/ocean/ocean.css',
334
+ './themes/ocean.fonts.css': './themes/ocean/ocean.fonts.css',
335
+ };
336
+ fs.writeFileSync(packageFile, `${JSON.stringify(pkg, null, 2)}\n`);
337
+ }
338
+
339
+ /**
340
+ * Rename the ocean theme to deep-sea, keeping its `ocean` slug, and build it,
341
+ * so its outputs are named after the theme: `deep-sea.css` and `deep-sea.js`,
342
+ * which exports `deepSeaTheme`.
343
+ */
344
+ function writeRenamedOcean() {
345
+ writePackage({files: ['astryx.integration.mjs', 'themes', 'entries']});
346
+ fs.writeFileSync(
347
+ path.join(tmpDir, 'themes', 'ocean', 'oceanTheme.ts'),
348
+ "import {defineTheme} from '@astryxdesign/core/theme';\n\nexport const oceanTheme = defineTheme({name: 'deep-sea'});\n",
349
+ );
350
+ const built = spawnSync(
351
+ process.execPath,
352
+ [
353
+ path.join(process.cwd(), 'packages/cli/clients/cli/bin/astryx.mjs'),
354
+ 'theme',
355
+ 'build',
356
+ 'themes/ocean/oceanTheme.ts',
357
+ ],
358
+ {cwd: tmpDir, encoding: 'utf-8', timeout: 30_000},
359
+ );
360
+ if (built.status !== 0) {
361
+ throw new Error(`Could not build the theme fixture: ${built.stderr}`);
362
+ }
363
+ }
364
+
365
+ /**
366
+ * Give the ocean theme an icon registry and build it, so its built module
367
+ * also exports `oceanIcons`.
368
+ */
369
+ function writeOceanWithIcons() {
370
+ writePackage({files: ['astryx.integration.mjs', 'themes', 'entries']});
371
+ const themeDir = path.join(tmpDir, 'themes', 'ocean');
372
+ fs.writeFileSync(
373
+ path.join(themeDir, 'icons.js'),
374
+ 'export const oceanIcons = {};\n',
375
+ );
376
+ fs.writeFileSync(
377
+ path.join(themeDir, 'oceanTheme.ts'),
378
+ "import {defineTheme} from '@astryxdesign/core/theme';\nimport {oceanIcons} from './icons';\n\nexport const oceanTheme = defineTheme({name: 'ocean', icons: oceanIcons});\n",
379
+ );
380
+ const built = spawnSync(
381
+ process.execPath,
382
+ [
383
+ path.join(process.cwd(), 'packages/cli/clients/cli/bin/astryx.mjs'),
384
+ 'theme',
385
+ 'build',
386
+ 'themes/ocean/oceanTheme.ts',
387
+ ],
388
+ {cwd: tmpDir, encoding: 'utf-8', timeout: 30_000},
389
+ );
390
+ if (built.status !== 0) {
391
+ throw new Error(`Could not build the theme fixture: ${built.stderr}`);
392
+ }
393
+ }
394
+
395
+ // An entry like one whose import is the whole integration: it loads the
396
+ // theme's fonts and stylesheet, by relative path and through the package's
397
+ // own exports, and re-exports the built theme.
398
+ const OWN_STYLES_ENTRY = `// Copyright (c) Acme.
399
+
400
+ import '../themes/ocean/ocean.fonts.css';
401
+ import '@acme/widgets/themes/ocean.css';
402
+
403
+ export {oceanTheme} from '../themes/ocean/ocean.js';
404
+ `;
405
+
406
+ describe('a theme module that loads its own styles', () => {
407
+ it('passes an entry that imports the theme stylesheet and fonts and re-exports the built module', async () => {
408
+ writePackage({themeExports: true});
409
+ writeOwnStylesEntry(OWN_STYLES_ENTRY);
410
+
411
+ const result = await integrationPackCheck({cwd: tmpDir});
412
+
413
+ expect(result.data.issues).toEqual([]);
414
+ expect(result.data.packable).toBe(true);
415
+ const cli = runCliVerify();
416
+ expect(cli.status, cli.stderr).toBe(0);
417
+ expect(cli.receipt?.data.issues).toEqual([]);
418
+ });
419
+
420
+ it('passes an entry that imports its fonts through the package exports and re-exports everything', async () => {
421
+ writePackage({themeExports: true});
422
+ writeOwnStylesEntry(
423
+ "import '@acme/widgets/themes/ocean.fonts.css';\nimport '../themes/ocean/ocean.css';\nexport * from '../themes/ocean/ocean.js';\n",
424
+ );
425
+
426
+ const result = await integrationPackCheck({cwd: tmpDir});
427
+
428
+ expect(result.data.issues).toEqual([]);
429
+ expect(result.data.packable).toBe(true);
430
+ });
431
+
432
+ it.each([
433
+ [
434
+ 'also imports another stylesheet',
435
+ `${OWN_STYLES_ENTRY}import './other.css';\n`,
436
+ "./other.css is not the theme's own stylesheet or font stylesheet",
437
+ ],
438
+ [
439
+ 'also imports a script',
440
+ `import './setup.mjs';\n${OWN_STYLES_ENTRY}`,
441
+ "./setup.mjs is not the theme's own stylesheet or font stylesheet",
442
+ ],
443
+ [
444
+ 'runs code',
445
+ `${OWN_STYLES_ENTRY}console.log('ocean');\n`,
446
+ 'line 7 is neither a stylesheet import nor the re-export',
447
+ ],
448
+ [
449
+ 'exports another value',
450
+ `${OWN_STYLES_ENTRY}export const extra = 1;\n`,
451
+ 'line 7 is neither a stylesheet import nor the re-export',
452
+ ],
453
+ [
454
+ 'renames the theme it re-exports',
455
+ "import '../themes/ocean/ocean.css';\nexport {oceanTheme, oceanTheme as theme} from '../themes/ocean/ocean.js';\n",
456
+ 'it re-exports names other than oceanTheme',
457
+ ],
458
+ [
459
+ 'binds the stylesheet it imports',
460
+ "import styles from '../themes/ocean/ocean.css';\nexport {oceanTheme} from '../themes/ocean/ocean.js';\n",
461
+ 'its import of ../themes/ocean/ocean.css is not a side-effect import',
462
+ ],
463
+ [
464
+ 'imports the stylesheet as a CSS module script',
465
+ "import '../themes/ocean/ocean.css' with {type: 'css'};\nexport {oceanTheme} from '../themes/ocean/ocean.js';\n",
466
+ 'its import of ../themes/ocean/ocean.css is not a side-effect import',
467
+ ],
468
+ [
469
+ 're-exports another name',
470
+ "import '../themes/ocean/ocean.css';\nexport {oceanTheme, missing} from '../themes/ocean/ocean.js';\n",
471
+ 'it re-exports names other than oceanTheme',
472
+ ],
473
+ [
474
+ 're-exports a copy that is not a .js module',
475
+ "import '../themes/ocean/ocean.css';\nexport {oceanTheme} from './copy.cjs';\n",
476
+ 'its re-export from ./copy.cjs does not name a .js module',
477
+ ],
478
+ [
479
+ 'has a directive',
480
+ `'use client';\n${OWN_STYLES_ENTRY}`,
481
+ 'it has a directive',
482
+ ],
483
+ [
484
+ 're-exports twice',
485
+ `${OWN_STYLES_ENTRY}export * from '../themes/ocean/ocean.js';\n`,
486
+ 'it has more than one re-export',
487
+ ],
488
+ ])('fails an entry that %s', async (_label, entry, reason) => {
489
+ writePackage({themeExports: true});
490
+ writeOwnStylesEntry(entry);
491
+ fs.writeFileSync(path.join(tmpDir, 'entries', 'other.css'), '.x {}\n');
492
+ fs.writeFileSync(path.join(tmpDir, 'entries', 'setup.mjs'), 'export {};\n');
493
+ fs.copyFileSync(
494
+ path.join(tmpDir, 'themes', 'ocean', 'ocean.js'),
495
+ path.join(tmpDir, 'entries', 'copy.cjs'),
496
+ );
497
+
498
+ const result = await integrationPackCheck({cwd: tmpDir});
499
+
500
+ expect(result.data.packable).toBe(false);
501
+ expect(result.data.issues).toEqual([
502
+ {
503
+ code: 'theme_module_stale',
504
+ severity: 'error',
505
+ message: `Theme "ocean" module is not the module \`astryx theme build themes/ocean/oceanTheme.ts\` writes and does not only wrap it: ${reason}. A module that wraps the built module may only import the theme's own stylesheet and font stylesheet for their side effects and re-export from the built module either everything or only its theme, as oceanTheme.`,
506
+ },
507
+ ]);
508
+ });
509
+
510
+ it('fails an entry whose re-exported module drifts from source', async () => {
511
+ writePackage({themeExports: true});
512
+ writeOwnStylesEntry(OWN_STYLES_ENTRY);
513
+ fs.appendFileSync(
514
+ path.join(tmpDir, 'themes', 'ocean', 'ocean.js'),
515
+ '// stale module\n',
516
+ );
517
+
518
+ const result = await integrationPackCheck({cwd: tmpDir});
519
+
520
+ expect(result.data.packable).toBe(false);
521
+ expect(result.data.issues).toEqual([
522
+ {
523
+ code: 'theme_module_stale',
524
+ severity: 'error',
525
+ message:
526
+ 'Theme "ocean" module re-exports ../themes/ocean/ocean.js, which does not match themes/ocean/oceanTheme.ts. Run `astryx theme build themes/ocean/oceanTheme.ts` before packing.',
527
+ },
528
+ ]);
529
+ });
530
+
531
+ it('does not accept a TypeScript entry', async () => {
532
+ writePackage({themeExports: true});
533
+ writeOwnStylesEntry(OWN_STYLES_ENTRY, 'ocean.ts');
534
+
535
+ const result = await integrationPackCheck({cwd: tmpDir});
536
+
537
+ expect(result.data.packable).toBe(false);
538
+ expect(result.data.issues).toEqual([
539
+ {
540
+ code: 'theme_module_stale',
541
+ severity: 'error',
542
+ message:
543
+ 'Theme "ocean" module does not match themes/ocean/oceanTheme.ts. Run `astryx theme build themes/ocean/oceanTheme.ts` before packing.',
544
+ },
545
+ ]);
546
+ });
547
+
548
+ it('does not accept an entry that re-exports itself', async () => {
549
+ writePackage({themeExports: true});
550
+ writeOwnStylesEntry(
551
+ "import '../themes/ocean/ocean.css';\nexport * from './ocean.js';\n",
552
+ 'ocean.js',
553
+ );
554
+
555
+ const result = await integrationPackCheck({cwd: tmpDir});
556
+
557
+ expect(result.data.packable).toBe(false);
558
+ expect(result.data.issues).toContainEqual(
559
+ expect.objectContaining({
560
+ code: 'theme_import_unresolvable',
561
+ message: expect.stringContaining('does not export "oceanTheme"'),
562
+ }),
563
+ );
564
+ });
565
+
566
+ it('passes an entry for a theme whose own name differs from its slug', async () => {
567
+ writeRenamedOcean();
568
+ writeOwnStylesEntry(
569
+ "import '../themes/ocean/deep-sea.css';\nexport {deepSeaTheme as oceanTheme} from '../themes/ocean/deep-sea.js';\n",
570
+ );
571
+ setThemeExports({
572
+ './themes/ocean': './entries/ocean.mjs',
573
+ './themes/ocean.css': './themes/ocean/deep-sea.css',
574
+ });
575
+
576
+ const result = await integrationPackCheck({cwd: tmpDir});
577
+
578
+ expect(result.data.issues).toEqual([]);
579
+ expect(result.data.packable).toBe(true);
580
+ const cli = runCliVerify();
581
+ expect(cli.status, cli.stderr).toBe(0);
582
+ });
583
+
584
+ it('compares a partial export set with the module named after the theme', async () => {
585
+ writeRenamedOcean();
586
+ setThemeExports({'./themes/ocean': './themes/ocean/deep-sea.js'});
587
+
588
+ const result = await integrationPackCheck({cwd: tmpDir});
589
+
590
+ expect(result.data.packable).toBe(true);
591
+ expect(result.data.issues.map(issue => issue.code)).toEqual([
592
+ 'theme_exports_incomplete',
593
+ ]);
594
+ });
595
+
596
+ it('passes an entry that re-exports only the theme from a built module that also exports its icons', async () => {
597
+ writeOceanWithIcons();
598
+ writeOwnStylesEntry(OWN_STYLES_ENTRY);
599
+
600
+ const result = await integrationPackCheck({cwd: tmpDir});
601
+
602
+ expect(result.data.issues).toEqual([]);
603
+ expect(result.data.packable).toBe(true);
604
+ });
605
+
606
+ it('fails an entry that gives the built icons the theme export name', async () => {
607
+ writeOceanWithIcons();
608
+ writeOwnStylesEntry(
609
+ "import '../themes/ocean/ocean.css';\nexport {oceanIcons as oceanTheme} from '../themes/ocean/ocean.js';\n",
610
+ );
611
+
612
+ const result = await integrationPackCheck({cwd: tmpDir});
613
+
614
+ expect(result.data.packable).toBe(false);
615
+ expect(result.data.issues).toEqual([
616
+ expect.objectContaining({
617
+ code: 'theme_module_stale',
618
+ message: expect.stringContaining(
619
+ 'it re-exports oceanIcons, which is not the built theme',
620
+ ),
621
+ }),
622
+ ]);
623
+ });
624
+
625
+ it('fails when packing changes the module an entry re-exports', async () => {
626
+ const prepack = [
627
+ "const fs=require('fs')",
628
+ "fs.copyFileSync('themes/ocean/ocean.js','.ocean.js.orig')",
629
+ "fs.appendFileSync('themes/ocean/ocean.js','// packed\\n')",
630
+ ].join(';');
631
+ const postpack =
632
+ "require('fs').renameSync('.ocean.js.orig','themes/ocean/ocean.js')";
633
+ writePackage({
634
+ themeExports: true,
635
+ scripts: {
636
+ prepack: `node -e "${prepack}"`,
637
+ postpack: `node -e "${postpack}"`,
638
+ },
639
+ });
640
+ writeOwnStylesEntry(OWN_STYLES_ENTRY);
641
+
642
+ const result = await integrationPackCheck({cwd: tmpDir});
643
+
644
+ expect(result.data.packable).toBe(false);
645
+ expect(result.data.issues).toEqual([
646
+ {
647
+ code: 'packed_theme_module_changed',
648
+ severity: 'error',
649
+ message:
650
+ 'Theme "ocean" module changed during packing. Keep the built output unchanged in the tarball.',
651
+ },
652
+ ]);
653
+ });
654
+ });
655
+
306
656
  describe('integrationPackCheck', () => {
307
657
  it('returns packable:true for a valid integration with themes', async () => {
308
658
  writePackage({files: ['astryx.integration.mjs', 'themes']});
@@ -1558,6 +1908,23 @@ describe('integrationPackCheck', () => {
1558
1908
  expect(sourceWarnings[0].message).toContain('Card.tsx');
1559
1909
  });
1560
1910
 
1911
+ it('reports template sources without metadata as warnings', async () => {
1912
+ writePackage({
1913
+ manifest:
1914
+ "export default {themes: './themes', templates: './templates'};\n",
1915
+ files: ['astryx.integration.mjs', 'themes', 'templates'],
1916
+ templates: true,
1917
+ });
1918
+ const result = await integrationPackCheck({cwd: tmpDir});
1919
+
1920
+ const sourceWarnings = result.data.issues.filter(
1921
+ issue => issue.code === 'source_without_template_doc',
1922
+ );
1923
+ expect(sourceWarnings).toHaveLength(1);
1924
+ expect(sourceWarnings[0].severity).toBe('warning');
1925
+ expect(sourceWarnings[0].message).toContain('stray.tsx');
1926
+ });
1927
+
1561
1928
  it('cleans up its scratch consumer when npm pack fails', async () => {
1562
1929
  writePackage({
1563
1930
  files: ['astryx.integration.mjs', 'themes'],
@@ -37,6 +37,8 @@ const componentDoc = name =>
37
37
  `export default {type: 'component', name: '${name}', displayName: '${name}', usage: {description: '${name}.'}, props: []};\n`;
38
38
  /** @param {string} name */
39
39
  const componentSource = name => `export function ${name}() { return null; }\n`;
40
+ const templateSource = name =>
41
+ `export default function ${name}() { return null; }\n`;
40
42
  /** @param {string} name */
41
43
  const topic = name =>
42
44
  `export default ${JSON.stringify({
@@ -1131,6 +1133,71 @@ describe('source_without_component_doc fixes hold when followed', () => {
1131
1133
  });
1132
1134
  });
1133
1135
 
1136
+ describe('source_without_template_doc fixes hold when followed', () => {
1137
+ it('adds the named doc, which resolves the warning', async () => {
1138
+ const dir = writePackage({
1139
+ [MANIFEST]: manifest({templates: './templates'}),
1140
+ 'templates/hero.tsx': templateSource('Hero'),
1141
+ 'templates/hero.test.tsx': templateSource('HeroTest'),
1142
+ });
1143
+
1144
+ const message = only(await issuesOf(dir), 'source_without_template_doc');
1145
+ expect(message).toBe(
1146
+ "Template source \"hero.tsx\" has no same-stem metadata file hero.doc.mjs, so `astryx template` never lists it. Fix: add hero.doc.mjs beside it with type: 'page' or 'block'; `astryx docs authoring integration-template-doc` lists its fields. If it is not a template, move it out of the templates root.",
1147
+ );
1148
+
1149
+ const fixed = follow(dir, {
1150
+ write: {
1151
+ 'templates/hero.doc.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
1152
+ },
1153
+ });
1154
+ expect(await issuesOf(fixed)).toEqual([]);
1155
+ });
1156
+
1157
+ it('checks a dotted template id, but no test, spec or story file', async () => {
1158
+ const dir = writePackage({
1159
+ [MANIFEST]: manifest({templates: './templates'}),
1160
+ 'templates/landing.page.tsx': templateSource('LandingPage'),
1161
+ 'templates/hero.test.tsx': templateSource('HeroTest'),
1162
+ 'templates/hero.spec.tsx': templateSource('HeroSpec'),
1163
+ 'templates/hero.stories.tsx': templateSource('HeroStories'),
1164
+ });
1165
+
1166
+ const message = only(await issuesOf(dir), 'source_without_template_doc');
1167
+ expect(message).toContain(
1168
+ 'Template source "landing.page.tsx" has no same-stem metadata file landing.page.doc.mjs',
1169
+ );
1170
+
1171
+ const fixed = follow(dir, {
1172
+ write: {
1173
+ 'templates/landing.page.doc.mjs': `export default {type: 'page', name: 'landing.page', displayName: 'Landing'};\n`,
1174
+ },
1175
+ });
1176
+ expect(await issuesOf(fixed)).toEqual([]);
1177
+ });
1178
+
1179
+ it('never flags a helper in a subfolder of the templates root', async () => {
1180
+ const dir = writePackage({
1181
+ [MANIFEST]: manifest({templates: './templates'}),
1182
+ 'templates/hero.doc.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
1183
+ 'templates/hero.tsx': templateSource('Hero'),
1184
+ 'templates/hero/HeroCard.tsx': templateSource('HeroCard'),
1185
+ });
1186
+
1187
+ expect(await issuesOf(dir)).toEqual([]);
1188
+ });
1189
+
1190
+ it('accepts a released .template.mjs spec as the metadata', async () => {
1191
+ const dir = writePackage({
1192
+ [MANIFEST]: manifest({templates: './templates'}),
1193
+ 'templates/hero.tsx': templateSource('Hero'),
1194
+ 'templates/hero.template.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
1195
+ });
1196
+
1197
+ expect(await issuesOf(dir)).toEqual([]);
1198
+ });
1199
+ });
1200
+
1134
1201
  describe('codemod fixes hold when followed', () => {
1135
1202
  it('moves a stray codemod into a version folder, and renames a mis-named one', async () => {
1136
1203
  const dir = writePackage({
@@ -35,6 +35,7 @@ import * as fs from 'node:fs';
35
35
  import * as path from 'node:path';
36
36
  import {assertWithin} from '../../foundation/fs/path-safety.mjs';
37
37
  import {integrationDocTypes} from '../docs/_adapter.mjs';
38
+ import {integrationDocConsistency} from '../../foundation/discovery/doc-consistency.mjs';
38
39
  import {
39
40
  THEME_SLUG_RE,
40
41
  unreadThemeFolders,
@@ -332,6 +333,22 @@ async function validateAtPackageDir(
332
333
  issues.push(...(await validateLoadedIntegration(loaded)));
333
334
  if (loaded.themes && !rootProblem(loaded.themes))
334
335
  issues.push(...unreadThemeFolderIssues(packageDir, loaded));
336
+ // What the docs say that no reader serves: a prop listed twice, an
337
+ // overlay's text for a prop the doc lacks, an empty or unreachable section,
338
+ // and an overlay of no topic.
339
+ issues.push(
340
+ ...(await integrationDocConsistency(
341
+ {
342
+ components:
343
+ loaded.components && !rootProblem(loaded.components)
344
+ ? loaded.components
345
+ : undefined,
346
+ docs:
347
+ loaded.docs && !rootProblem(loaded.docs) ? loaded.docs : undefined,
348
+ },
349
+ packageDir,
350
+ )),
351
+ );
335
352
  if (scanUnreachable) {
336
353
  issues.push(
337
354
  ...(await findUnreachableContributionIssues(packageDir, loaded)),
@@ -476,9 +493,17 @@ export async function validateIntegration(pkg, options = {}) {
476
493
  validated: result.found,
477
494
  name: result.found ? (result.name ?? null) : null,
478
495
  version: result.found ? (result.version ?? null) : null,
479
- issues: result.reason === 'no_package_json'
480
- ? [{code: 'no_package', severity: 'error', message: 'No package.json found. Run this command inside a package directory.'}]
481
- : result.issues,
496
+ issues:
497
+ result.reason === 'no_package_json'
498
+ ? [
499
+ {
500
+ code: 'no_package',
501
+ severity: 'error',
502
+ message:
503
+ 'No package.json found. Run this command inside a package directory.',
504
+ },
505
+ ]
506
+ : result.issues,
482
507
  ...(docTypes ? {docTypes} : {}),
483
508
  },
484
509
  };
@@ -80,6 +80,28 @@ describe('validate-integration API', () => {
80
80
  expect(errors).toBe(0);
81
81
  });
82
82
 
83
+ it('warns, with a fix and the file, on docs no reader can serve', async () => {
84
+ const pkgDir = path.join(tmpDir, 'pkg');
85
+ writePackage(pkgDir, {
86
+ manifest: `export default { docs: './docs' };\n`,
87
+ });
88
+ fs.mkdirSync(path.join(pkgDir, 'docs'), {recursive: true});
89
+ fs.writeFileSync(
90
+ path.join(pkgDir, 'docs', 'ghost.doc.zh.mjs'),
91
+ "export default {title: 'ghost'};\n",
92
+ );
93
+
94
+ const result = await validateLocalIntegration(pkgDir);
95
+
96
+ expect(byCode(result.issues, 'orphan_doc_overlay')).toEqual([
97
+ expect.objectContaining({
98
+ severity: 'warning',
99
+ file: 'docs/ghost.doc.zh.mjs',
100
+ fix: expect.stringContaining('Delete docs/ghost.doc.zh.mjs'),
101
+ }),
102
+ ]);
103
+ });
104
+
83
105
  it('reports an unknown manifest key as a warning, and still loads the rest', async () => {
84
106
  // The manifest used to be parsed with a strict schema, so a single unknown
85
107
  // key failed the parse — and an integration whose manifest fails to parse
@@ -321,6 +343,36 @@ export default {type: 'theme', name: 'ocean', displayName: 'Ocean', description:
321
343
  );
322
344
  });
323
345
 
346
+ it('warns when a template source has no same-stem metadata, skipping test files', async () => {
347
+ const pkgDir = path.join(tmpDir, 'pkg');
348
+ writePackage(pkgDir, {
349
+ manifest: `export default { templates: './templates' };\n`,
350
+ });
351
+ fs.mkdirSync(path.join(pkgDir, 'templates'));
352
+ fs.writeFileSync(
353
+ path.join(pkgDir, 'templates', 'stray.tsx'),
354
+ 'export default function Stray() { return null; }\n',
355
+ );
356
+ fs.writeFileSync(
357
+ path.join(pkgDir, 'templates', 'stray.test.tsx'),
358
+ "import {it} from 'vitest';\nit('renders', () => {});\n",
359
+ );
360
+
361
+ const result = await validateLocalIntegration(pkgDir);
362
+
363
+ const warnings = byCode(result.issues, 'source_without_template_doc');
364
+ expect(warnings).toEqual([
365
+ expect.objectContaining({
366
+ severity: 'warning',
367
+ message: expect.stringContaining('"stray.tsx"'),
368
+ }),
369
+ ]);
370
+ expect(warnings[0].message).not.toContain('stray.test.tsx');
371
+ expect(warnings[0].message).toContain(
372
+ "Fix: add stray.doc.mjs beside it with type: 'page' or 'block'",
373
+ );
374
+ });
375
+
324
376
  it('reports codemods outside semver folders and invalid folder names', async () => {
325
377
  const pkgDir = path.join(tmpDir, 'pkg');
326
378
  writePackage(pkgDir, {
@@ -593,7 +645,10 @@ describe('integration diagnostics are read-only', () => {
593
645
  'components/Orphan.doc.mjs',
594
646
  "export default {type: 'component', name: 'Orphan', props: []};\n",
595
647
  );
596
- write('templates/dash.doc.mjs', "export default {type: 'page', name: 'Dash'};\n");
648
+ write(
649
+ 'templates/dash.doc.mjs',
650
+ "export default {type: 'page', name: 'Dash'};\n",
651
+ );
597
652
  write(
598
653
  'docs/theme.doc.mjs',
599
654
  "export default {type: 'generic', name: 'theme', title: 'Theme', description: 'x', sections: [{title: 'A', content: [{type: 'prose', text: 'x'}]}]};\n",
@@ -614,7 +669,9 @@ describe('integration diagnostics are read-only', () => {
614
669
  path.join(consumer, 'package.json'),
615
670
  JSON.stringify({name: 'consumer'}),
616
671
  );
617
- writeDiagnosedPackage(path.join(consumer, 'node_modules', '@acme', 'widgets'));
672
+ writeDiagnosedPackage(
673
+ path.join(consumer, 'node_modules', '@acme', 'widgets'),
674
+ );
618
675
  const before = {pkg: snapshot(pkgDir), consumer: snapshot(consumer)};
619
676
 
620
677
  const local = await validateIntegration(undefined, {cwd: pkgDir});
@@ -631,9 +688,13 @@ describe('integration diagnostics are read-only', () => {
631
688
  }
632
689
 
633
690
  expect(summarizeIssues(local.data.issues).errors).toBeGreaterThan(0);
634
- expect(byCode(local.data.issues, 'unreachable_contribution')).toHaveLength(1);
691
+ expect(byCode(local.data.issues, 'unreachable_contribution')).toHaveLength(
692
+ 1,
693
+ );
635
694
  expect(summarizeIssues(installed.data.issues).errors).toBeGreaterThan(0);
636
- expect({pkg: snapshot(pkgDir), consumer: snapshot(consumer)}).toEqual(before);
695
+ expect({pkg: snapshot(pkgDir), consumer: snapshot(consumer)}).toEqual(
696
+ before,
697
+ );
637
698
  });
638
699
  });
639
700
 
@@ -655,7 +716,9 @@ describe('validated separates "checked and clean" from "never checked"', () => {
655
716
  expect(validate.data.issues).toEqual([]);
656
717
 
657
718
  const templates = await integrationTemplateConflicts(undefined, {cwd: dir});
658
- const components = await integrationComponentConflicts(undefined, {cwd: dir});
719
+ const components = await integrationComponentConflicts(undefined, {
720
+ cwd: dir,
721
+ });
659
722
  const docs = await integrationDocConflicts(undefined, {cwd: dir});
660
723
  expect(templates.data.validated).toBe(false);
661
724
  expect(components.data.validated).toBe(false);
@@ -671,7 +734,9 @@ describe('validated separates "checked and clean" from "never checked"', () => {
671
734
  expect(validate.data.name).toBe('@acme/widgets');
672
735
 
673
736
  const templates = await integrationTemplateConflicts(undefined, {cwd: dir});
674
- const components = await integrationComponentConflicts(undefined, {cwd: dir});
737
+ const components = await integrationComponentConflicts(undefined, {
738
+ cwd: dir,
739
+ });
675
740
  const docs = await integrationDocConflicts(undefined, {cwd: dir});
676
741
  expect(templates.data.validated).toBe(true);
677
742
  expect(components.data.validated).toBe(true);
@@ -743,8 +808,12 @@ describe('unreadable folders are reported, never fatal', () => {
743
808
  expect(
744
809
  byCode(result.issues, 'unreadable_root').map(issue => issue.message),
745
810
  ).toEqual([
746
- expect.stringMatching(/^Declared codemods root cannot be read \(EACCES\)/),
747
- expect.stringMatching(/^Declared themes root cannot be read \(EACCES\)/),
811
+ expect.stringMatching(
812
+ /^Declared codemods root cannot be read \(EACCES\)/,
813
+ ),
814
+ expect.stringMatching(
815
+ /^Declared themes root cannot be read \(EACCES\)/,
816
+ ),
748
817
  ]);
749
818
  },
750
819
  );
@@ -62,7 +62,7 @@ export const doc = {
62
62
  {
63
63
  type: 'integration.validate',
64
64
  description:
65
- 'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked.',
65
+ 'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked.',
66
66
  },
67
67
  ],
68
68
  examples: [