@astryxdesign/cli 0.7.14 → 0.7.15-canary.g061b2fa

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 (164) hide show
  1. package/README.md +63 -63
  2. package/api/build/_adapter.d.mts +4 -0
  3. package/api/build/_adapter.mjs +28 -2
  4. package/api/build/blocks/blocks.d.mts +10 -1
  5. package/api/build/blocks/blocks.mjs +84 -7
  6. package/api/build/build.mjs +6 -1
  7. package/api/build/tree.d.mts +4 -0
  8. package/api/build/tree.mjs +9 -2
  9. package/api/doctor/_adapter.d.mts +3 -1
  10. package/api/doctor/_adapter.mjs +14 -1
  11. package/api/doctor/_authoring-audit.d.mts +42 -0
  12. package/api/doctor/_authoring-audit.mjs +106 -0
  13. package/api/doctor/doctor.d.mts +7 -0
  14. package/api/doctor/doctor.mjs +24 -39
  15. package/api/doctor/theme-checks.mjs +56 -21
  16. package/api/integration/validate-integration.mjs +17 -3
  17. package/api/integration/validateIntegration.doc.mjs +1 -1
  18. package/api/search/_adapter.mjs +124 -3
  19. package/api/search/_candidate-score.mjs +63 -9
  20. package/api/search/_entries.d.mts +10 -0
  21. package/api/search/_entries.mjs +68 -1
  22. package/api/search/_gather-templates.d.mts +11 -0
  23. package/api/search/_gather-templates.mjs +22 -2
  24. package/api/search/_words.mjs +26 -6
  25. package/api/swizzle/copy/copy.mjs +1 -1
  26. package/api/theme/_adapter.d.mts +17 -1
  27. package/api/theme/_adapter.mjs +185 -40
  28. package/api/theme/build/build.d.mts +29 -1
  29. package/api/theme/build/build.mjs +426 -65
  30. package/api/theme/eject/eject.mjs +10 -6
  31. package/api/theme/targets/targets.d.mts +8 -0
  32. package/api/theme/targets/targets.mjs +24 -4
  33. package/api/theme/template/template.mjs +48 -2
  34. package/api/theme/theme.type.d.mts +8 -0
  35. package/api/theme/theme.type.mjs +5 -1
  36. package/api/theme/themeBuild.doc.mjs +7 -4
  37. package/api/theme/themeEject.doc.mjs +3 -3
  38. package/api/theme/themeRemove.doc.mjs +5 -2
  39. package/api/theme/themeTargets.doc.mjs +1 -1
  40. package/api/theme/themeTemplate.doc.mjs +2 -2
  41. package/api/theme/themeUse.doc.mjs +8 -2
  42. package/api/theme-edit/_adapter.d.mts +46 -3
  43. package/api/theme-edit/_adapter.mjs +372 -109
  44. package/api/theme-edit/_check.d.mts +6 -3
  45. package/api/theme-edit/_check.mjs +665 -87
  46. package/api/theme-edit/_color.mjs +4 -2
  47. package/api/theme-edit/_compiler.d.mts +2 -1
  48. package/api/theme-edit/_compiler.mjs +27 -13
  49. package/api/theme-edit/_context.d.mts +2 -1
  50. package/api/theme-edit/_context.mjs +47 -8
  51. package/api/theme-edit/_edit.d.mts +9 -3
  52. package/api/theme-edit/_edit.mjs +484 -66
  53. package/api/theme-edit/_how-commands.d.mts +33 -7
  54. package/api/theme-edit/_how-commands.mjs +57 -45
  55. package/api/theme-edit/_how-question.d.mts +4 -0
  56. package/api/theme-edit/_how-question.mjs +1004 -223
  57. package/api/theme-edit/_how.mjs +96 -9
  58. package/api/theme-edit/_palette.d.mts +38 -13
  59. package/api/theme-edit/_palette.mjs +620 -223
  60. package/api/theme-edit/_parts.mjs +63 -7
  61. package/api/theme-edit/_png.d.mts +4 -4
  62. package/api/theme-edit/_png.mjs +4 -2
  63. package/api/theme-edit/_preview-app.d.mts +6 -0
  64. package/api/theme-edit/_preview-app.mjs +1194 -207
  65. package/api/theme-edit/_preview.mjs +2 -2
  66. package/api/theme-edit/_project.d.mts +12 -1
  67. package/api/theme-edit/_project.mjs +37 -6
  68. package/api/theme-edit/_settings.d.mts +104 -33
  69. package/api/theme-edit/_settings.mjs +818 -118
  70. package/api/theme-edit/_tables.d.mts +7 -0
  71. package/api/theme-edit/_tables.mjs +61 -0
  72. package/api/theme-edit/theme-edit.type.d.mts +11 -1
  73. package/api/theme-edit/theme-edit.type.mjs +4 -3
  74. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  75. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  76. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  77. package/api/theme-edit/themeEditPreviewList.doc.mjs +1 -1
  78. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  79. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  80. package/api/upgrade/_adapter.d.mts +1 -0
  81. package/assets/codemods/run-codemod.mjs +61 -0
  82. package/assets/codemods/runner.mjs +5 -4
  83. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  84. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  85. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  86. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  87. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  88. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  89. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  90. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  91. package/assets/docs/tree/calendars.doc.mjs +1 -3
  92. package/assets/docs/tree/checks.doc.mjs +22 -1
  93. package/assets/docs.generated.json +2 -1
  94. package/assets/self-audit.generated.json +1 -0
  95. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  96. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  97. package/assets/templates/components.generated.json +1 -1
  98. package/authoring/integration/integration.doc.mjs +8 -0
  99. package/authoring/integration/schema.d.mts +8 -0
  100. package/authoring/integration/schema.mjs +1 -0
  101. package/authoring/integration/type.ts +9 -0
  102. package/clients/cli/bin/astryx.mjs +19 -15
  103. package/clients/cli/build-id.generated.json +1 -0
  104. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  105. package/clients/cli/commands/experimental/theme.mjs +178 -78
  106. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  107. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  108. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  109. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  110. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  111. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  112. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  113. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  114. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  115. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  116. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  117. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  118. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  119. package/clients/cli/commands/manifest.mjs +5 -2
  120. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  121. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  122. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  123. package/clients/cli/commands/theme.mjs +374 -42
  124. package/clients/cli/index.mjs +9 -3
  125. package/clients/cli/lib/manifest.mjs +37 -0
  126. package/clients/cli/lib/resolve-theme.mjs +2 -1
  127. package/clients/cli/manifest.generated.json +1 -0
  128. package/foundation/config/theme-state.d.mts +16 -0
  129. package/foundation/config/theme-state.mjs +84 -13
  130. package/foundation/discovery/module-exports.mjs +16 -2
  131. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  132. package/foundation/discovery/stored-self-audit.mjs +119 -0
  133. package/foundation/discovery/template-adapter.d.mts +48 -2
  134. package/foundation/discovery/template-adapter.mjs +51 -19
  135. package/foundation/discovery/template-needs.d.mts +19 -0
  136. package/foundation/discovery/template-needs.mjs +50 -16
  137. package/foundation/discovery/template-source-tree.d.mts +7 -0
  138. package/foundation/discovery/template-source-tree.mjs +15 -0
  139. package/foundation/discovery/theme-discovery.d.mts +2 -1
  140. package/foundation/discovery/theme-discovery.mjs +2 -8
  141. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  142. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  143. package/foundation/doc-compiler/import.mjs +22 -15
  144. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  145. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  146. package/foundation/env/private-dir.d.mts +17 -0
  147. package/foundation/env/private-dir.mjs +42 -0
  148. package/foundation/fs/gather-cache.d.mts +108 -0
  149. package/foundation/fs/gather-cache.mjs +741 -0
  150. package/foundation/fs/jiti-cache.d.mts +21 -0
  151. package/foundation/fs/jiti-cache.mjs +66 -0
  152. package/foundation/fs/module-loader.mjs +14 -3
  153. package/foundation/fs/read-record.d.mts +31 -1
  154. package/foundation/fs/read-record.mjs +100 -7
  155. package/foundation/integrations/integrations.d.mts +8 -0
  156. package/foundation/integrations/integrations.mjs +4 -0
  157. package/foundation/integrations/validate-contributions.d.mts +62 -1
  158. package/foundation/integrations/validate-contributions.mjs +476 -40
  159. package/foundation/release/cache.d.mts +11 -2
  160. package/foundation/release/cache.mjs +59 -10
  161. package/foundation/release/folder-lock.d.mts +21 -0
  162. package/foundation/release/folder-lock.mjs +171 -0
  163. package/foundation/response/response-types.doc.mjs +1 -1
  164. package/package.json +8 -6
@@ -24,8 +24,7 @@
24
24
  import * as fs from 'node:fs';
25
25
  import * as path from 'node:path';
26
26
  import {spawnSync} from 'node:child_process';
27
- import {builtinModules} from 'node:module';
28
- import {parse as parseModule} from '@babel/parser';
27
+ import {builtinModules, createRequire} from 'node:module';
29
28
  import {isValidSemver} from '../env/semver.mjs';
30
29
  import {findProjectCoreDir} from '../fs/paths.mjs';
31
30
  import {KNOWN_INTEGRATION_KEYS} from '../../authoring/integration/schema.mjs';
@@ -64,6 +63,18 @@ import {
64
63
  import {discoverIntegrationDocs} from '../discovery/docs-discovery.mjs';
65
64
  import {discoverIntegrationThemes} from '../discovery/theme-discovery.mjs';
66
65
 
66
+ const requireFromHere = createRequire(import.meta.url);
67
+
68
+ /**
69
+ * `@babel/parser`'s parse, loaded on first use: most commands that load the
70
+ * project's integrations never validate a contribution's source.
71
+ * @param {string} source
72
+ * @param {import('@babel/parser').ParserOptions} [options]
73
+ */
74
+ function parseModule(source, options) {
75
+ return requireFromHere('@babel/parser').parse(source, options);
76
+ }
77
+
67
78
  /**
68
79
  * @typedef {import('./issue').AstryxIntegrationIssue} Issue
69
80
  * @typedef {import('./integrations.mjs').LoadedIntegration} LoadedIntegration
@@ -1467,6 +1478,38 @@ function readModule(source, builtins) {
1467
1478
  return {server: found, assets};
1468
1479
  }
1469
1480
 
1481
+ /**
1482
+ * Whether npm packs one file (or, with `folder`, anything inside one
1483
+ * folder) of the package at `base`. `cache` holds what npm packs, asked at
1484
+ * most once per cache. With no `files` field and no ignore file on the
1485
+ * path, npm packs everything, so nothing is asked. Without npm's answer, a
1486
+ * path no `files` entry can reach is left out, and any other is unknown.
1487
+ * @param {string} base package root
1488
+ * @param {string} rel path relative to `base`, with forward slashes
1489
+ * @param {unknown} packedFiles package.json `files`
1490
+ * @param {{packed?: {paths: Set<string>} | {error: string}}} cache
1491
+ * @param {{folder?: boolean}} [options]
1492
+ * @returns {{packed: true} | {packed: false, by: 'npm' | 'files'} | {packed: 'unknown', error: string}}
1493
+ */
1494
+ function packState(base, rel, packedFiles, cache, {folder = false} = {}) {
1495
+ if (!Array.isArray(packedFiles) && ignoreFilesFor(base, rel).length === 0) {
1496
+ return {packed: true};
1497
+ }
1498
+ cache.packed ??= npmPackedPaths(base);
1499
+ const packed = cache.packed;
1500
+ if ('paths' in packed) {
1501
+ if (packed.paths.has(rel)) return {packed: true};
1502
+ if (folder && [...packed.paths].some(each => each.startsWith(`${rel}/`))) {
1503
+ return {packed: true};
1504
+ }
1505
+ return {packed: false, by: 'npm'};
1506
+ }
1507
+ if (Array.isArray(packedFiles) && outsideFiles(rel, packedFiles)) {
1508
+ return {packed: false, by: 'files'};
1509
+ }
1510
+ return {packed: 'unknown', error: packed.error};
1511
+ }
1512
+
1470
1513
  /**
1471
1514
  * What a package's examples need to work everywhere they are shown: template
1472
1515
  * lists, docs pages and catalog cards, which render each block alone from
@@ -1492,8 +1535,12 @@ function readModule(source, builtins) {
1492
1535
  * package (`npm pack --dry-run`). When npm cannot answer, an asset no
1493
1536
  * `files` entry can reach is still a note, and any other is returned in
1494
1537
  * `unchecked`.
1538
+ * It also returns `examples`, what the package-level listing note needs:
1539
+ * whether any block is a showcase, and, when none is, how many components
1540
+ * need an example (the exemptions above apply). It is absent when the
1541
+ * templates or components cannot be read, so no listing note is drawn.
1495
1542
  * @param {LoadedIntegration} integration
1496
- * @returns {Promise<{notes: Note[], unchecked: Array<{file: string, asset: string, reason: string}>}>}
1543
+ * @returns {Promise<{notes: Note[], unchecked: Array<{file: string, asset: string, reason: string}>, examples?: ExampleSummary}>}
1497
1544
  */
1498
1545
  export async function componentExamplesCheck(integration) {
1499
1546
  /** @type {Note[]} */
@@ -1531,8 +1578,8 @@ export async function componentExamplesCheck(integration) {
1531
1578
  } catch {
1532
1579
  packedFiles = undefined;
1533
1580
  }
1534
- /** @type {{paths: Set<string>} | {error: string} | undefined} what npm packs, read once */
1535
- let packed;
1581
+ /** @type {{packed?: {paths: Set<string>} | {error: string}}} what npm packs, read once */
1582
+ const npm = {};
1536
1583
  /** @type {Array<{file: string, asset: string, reason: string}>} */
1537
1584
  const unchecked = [];
1538
1585
  // A bare builtin name the package installs from npm (`buffer`, `events`)
@@ -1601,36 +1648,19 @@ export async function componentExamplesCheck(integration) {
1601
1648
  // A folder URL is packed when npm packs anything inside it.
1602
1649
  const isFolder = exists && fs.statSync(asset).isDirectory();
1603
1650
  if (exists) {
1604
- // With no `files` field npm packs everything but what an ignore file
1605
- // drops, in the package root or any folder down to the asset, so
1606
- // with no ignore file on that path there is nothing to ask.
1607
- if (
1608
- !Array.isArray(packedFiles) &&
1609
- ignoreFilesFor(base, assetRel).length === 0
1610
- ) {
1611
- continue;
1612
- }
1613
1651
  // What npm packs decides. Without npm's answer, an asset no entry
1614
1652
  // can reach is reported, and any other is listed as not checked.
1615
- packed ??= npmPackedPaths(base);
1616
- if ('paths' in packed) {
1617
- if (packed.paths.has(assetRel)) continue;
1618
- if (
1619
- isFolder &&
1620
- [...packed.paths].some(each => each.startsWith(`${assetRel}/`))
1621
- ) {
1622
- continue;
1623
- }
1624
- } else if (
1625
- !Array.isArray(packedFiles) ||
1626
- !outsideFiles(assetRel, packedFiles)
1627
- ) {
1653
+ const state = packState(base, assetRel, packedFiles, npm, {
1654
+ folder: isFolder,
1655
+ });
1656
+ if (state.packed === true) continue;
1657
+ if (state.packed === 'unknown') {
1628
1658
  unchecked.push({
1629
1659
  file: rel(template.filePath),
1630
1660
  asset: assetRel,
1631
1661
  reason: Array.isArray(packedFiles)
1632
- ? `${packed.error}, and a \`files\` entry may reach it`
1633
- : `${packed.error}, and ${ignoreFilesFor(base, assetRel).at(-1) ?? '.npmignore'} may drop it`,
1662
+ ? `${state.error}, and a \`files\` entry may reach it`
1663
+ : `${state.error}, and ${ignoreFilesFor(base, assetRel).at(-1) ?? '.npmignore'} may drop it`,
1634
1664
  });
1635
1665
  continue;
1636
1666
  }
@@ -1647,20 +1677,22 @@ export async function componentExamplesCheck(integration) {
1647
1677
  : negated != null && !outsideFiles(assetRel, packedFiles)
1648
1678
  ? `${rel(template.filePath)}: loads ${assetRel}, which the \`files\` entry "${negated}" leaves out of the package, so the template breaks once installed. Fix: drop or narrow "${negated}" so it no longer matches ${assetRel}, and confirm with \`npm pack --dry-run\`.`
1649
1679
  : Array.isArray(packedFiles) &&
1650
- (outsideFiles(assetRel, packedFiles) ||
1651
- !ignoreFilesFor(base, assetRel).some(file => file.includes('/')))
1652
- ? `${rel(template.filePath)}: loads ${assetRel}, which npm leaves out of the package by its \`files\` field, so the template breaks once installed. Fix: add "${folder}" to \`files\`, drop any \`!\` entry that excludes it, and confirm with \`npm pack --dry-run\`.`
1653
- : ignoreFix(
1654
- base,
1655
- rel(template.filePath),
1656
- assetRel,
1657
- Array.isArray(packedFiles),
1658
- ),
1680
+ (outsideFiles(assetRel, packedFiles) ||
1681
+ !ignoreFilesFor(base, assetRel).some(file =>
1682
+ file.includes('/'),
1683
+ ))
1684
+ ? `${rel(template.filePath)}: loads ${assetRel}, which npm leaves out of the package by its \`files\` field, so the template breaks once installed. Fix: add "${folder}" to \`files\`, drop any \`!\` entry that excludes it, and confirm with \`npm pack --dry-run\`.`
1685
+ : ignoreFix(
1686
+ base,
1687
+ rel(template.filePath),
1688
+ assetRel,
1689
+ Array.isArray(packedFiles),
1690
+ ),
1659
1691
  });
1660
1692
  }
1661
1693
  }
1662
1694
  if (!integration.components || rootProblem(integration.components)) {
1663
- return {notes, unchecked};
1695
+ return {notes, unchecked, examples: {needed: 0, showcase: shown.size > 0}};
1664
1696
  }
1665
1697
  /** @type {any[]} */
1666
1698
  let records;
@@ -1703,6 +1735,8 @@ export async function componentExamplesCheck(integration) {
1703
1735
  );
1704
1736
  if (owner) ownerOf.set(template, owner);
1705
1737
  }
1738
+ /** components that need an example and have none */
1739
+ let needed = 0;
1706
1740
  for (const record of records) {
1707
1741
  if (componentDiscovery.isIntegrationMember(record)) continue;
1708
1742
  if (shown.has(record.name)) continue;
@@ -1714,6 +1748,7 @@ export async function componentExamplesCheck(integration) {
1714
1748
  }
1715
1749
  if (doc?.hidden === true || doc?.isHiddenFromOverview === true) continue;
1716
1750
  if (doc?.category === 'Utility') continue;
1751
+ needed++;
1717
1752
  const name = record.name;
1718
1753
  const stem = `${name.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase()}-showcase`;
1719
1754
  // A block that already composes the component only needs the fields.
@@ -1809,7 +1844,7 @@ export async function componentExamplesCheck(integration) {
1809
1844
  ' A doc set to `hidden`, `isHiddenFromOverview` or category `Utility` needs no example.',
1810
1845
  });
1811
1846
  }
1812
- return {notes, unchecked};
1847
+ return {notes, unchecked, examples: {needed, showcase: shown.size > 0}};
1813
1848
  }
1814
1849
 
1815
1850
  /**
@@ -2448,3 +2483,404 @@ async function allLoadedIntegrationIssues(loaded) {
2448
2483
  await runContributionChecks(loaded, issues);
2449
2484
  return issues;
2450
2485
  }
2486
+
2487
+ /**
2488
+ * Where the package declares the logo a catalog shows, and the field that
2489
+ * holds it for messages. The integration file's `logo` comes first; a
2490
+ * package.json `marketplace.logo` is also read when the integration file
2491
+ * has none, so a package that set it there keeps its logo.
2492
+ * @param {LoadedIntegration} integration
2493
+ * @param {any} pkg parsed package.json
2494
+ * @returns {{file: string, field: string, light: unknown, dark: unknown}}
2495
+ */
2496
+ function listingLogo(integration, pkg) {
2497
+ const manifestFile = integration.__manifestFile
2498
+ ? path.basename(integration.__manifestFile)
2499
+ : 'astryx.integration.mjs';
2500
+ const declared = integration.logo;
2501
+ if (declared && typeof declared === 'object') {
2502
+ return {
2503
+ file: manifestFile,
2504
+ field: 'logo',
2505
+ light: declared.light,
2506
+ dark: declared.dark,
2507
+ };
2508
+ }
2509
+ const legacy = pkg?.marketplace?.logo;
2510
+ if (legacy && typeof legacy === 'object') {
2511
+ return {
2512
+ file: 'package.json',
2513
+ field: 'marketplace.logo',
2514
+ light: legacy.light,
2515
+ dark: legacy.dark,
2516
+ };
2517
+ }
2518
+ return {file: manifestFile, field: 'logo', light: undefined, dark: undefined};
2519
+ }
2520
+
2521
+ /** The largest logo a catalog shows, in bytes. */
2522
+ const LOGO_MAX_BYTES = 512 * 1024;
2523
+
2524
+ /** SVG elements a logo may use: shapes, groups, paint servers and text alternatives. */
2525
+ const SVG_ELEMENTS = new Set([
2526
+ 'svg',
2527
+ 'g',
2528
+ 'defs',
2529
+ 'symbol',
2530
+ 'use',
2531
+ 'path',
2532
+ 'rect',
2533
+ 'circle',
2534
+ 'ellipse',
2535
+ 'line',
2536
+ 'polyline',
2537
+ 'polygon',
2538
+ 'lineargradient',
2539
+ 'radialgradient',
2540
+ 'stop',
2541
+ 'clippath',
2542
+ 'mask',
2543
+ 'title',
2544
+ 'desc',
2545
+ ]);
2546
+
2547
+ /** SVG attributes a logo may use: geometry, paint and labels, no events or styles. */
2548
+ const SVG_ATTRIBUTES = new Set([
2549
+ 'xmlns',
2550
+ 'xmlns:xlink',
2551
+ 'version',
2552
+ 'id',
2553
+ 'class',
2554
+ 'role',
2555
+ 'aria-label',
2556
+ 'aria-hidden',
2557
+ 'focusable',
2558
+ 'viewbox',
2559
+ 'preserveaspectratio',
2560
+ 'width',
2561
+ 'height',
2562
+ 'x',
2563
+ 'y',
2564
+ 'x1',
2565
+ 'y1',
2566
+ 'x2',
2567
+ 'y2',
2568
+ 'cx',
2569
+ 'cy',
2570
+ 'r',
2571
+ 'rx',
2572
+ 'ry',
2573
+ 'fx',
2574
+ 'fy',
2575
+ 'd',
2576
+ 'points',
2577
+ 'pathlength',
2578
+ 'transform',
2579
+ 'opacity',
2580
+ 'color',
2581
+ 'display',
2582
+ 'visibility',
2583
+ 'overflow',
2584
+ 'fill',
2585
+ 'fill-opacity',
2586
+ 'fill-rule',
2587
+ 'stroke',
2588
+ 'stroke-width',
2589
+ 'stroke-opacity',
2590
+ 'stroke-linecap',
2591
+ 'stroke-linejoin',
2592
+ 'stroke-miterlimit',
2593
+ 'stroke-dasharray',
2594
+ 'stroke-dashoffset',
2595
+ 'vector-effect',
2596
+ 'shape-rendering',
2597
+ 'clip-path',
2598
+ 'clip-rule',
2599
+ 'mask',
2600
+ 'offset',
2601
+ 'stop-color',
2602
+ 'stop-opacity',
2603
+ 'gradientunits',
2604
+ 'gradienttransform',
2605
+ 'spreadmethod',
2606
+ 'clippathunits',
2607
+ 'maskunits',
2608
+ 'maskcontentunits',
2609
+ 'href',
2610
+ 'xlink:href',
2611
+ ]);
2612
+
2613
+ const SVG_TAG =
2614
+ /^<(\/?)([A-Za-z][\w:.-]*)((?:\s+[^\s"'=<>/]+(?:\s*=\s*(?:"[^"]*"|'[^']*'))?)*)\s*(\/?)>/u;
2615
+ const SVG_ATTRIBUTE = /([^\s"'=<>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'))?/gu;
2616
+
2617
+ /**
2618
+ * Whether an attribute value stays inside the image: a reference is only to
2619
+ * an element of the same file (`#id`, `url(#id)`).
2620
+ * @param {string} name lower-case attribute name
2621
+ * @param {string} value
2622
+ * @returns {boolean}
2623
+ */
2624
+ function isLocalSvgValue(name, value) {
2625
+ // A character reference or a CSS escape could spell a reference the
2626
+ // tests below would miss.
2627
+ if (/[<>&\\]/u.test(value)) return false;
2628
+ if (name === 'xmlns') return value === 'http://www.w3.org/2000/svg';
2629
+ if (name === 'xmlns:xlink') return value === 'http://www.w3.org/1999/xlink';
2630
+ if (name === 'href' || name === 'xlink:href') {
2631
+ return /^#[\w.-]+$/u.test(value.trim());
2632
+ }
2633
+ if (name === 'mask' || name === 'clip-path') {
2634
+ return /^\s*(?:none|url\(\s*(["']?)#[\w.-]+\1\s*\))\s*$/iu.test(value);
2635
+ }
2636
+ if (name === 'fill' || name === 'stroke') {
2637
+ // A local paint server, then colors; the only functions are colors.
2638
+ const rest = value.replace(/url\(\s*(["']?)#[\w.-]+\1\s*\)/giu, '');
2639
+ return [...rest.matchAll(/([\w-]*)\s*\(/gu)].every(([, fn]) =>
2640
+ /^(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix|light-dark)$/iu.test(
2641
+ fn,
2642
+ ),
2643
+ );
2644
+ }
2645
+ return true;
2646
+ }
2647
+
2648
+ const XML_DECLARATION =
2649
+ /^<\?xml((?:\s+(?:version|encoding|standalone)\s*=\s*(?:"[\w.-]*"|'[\w.-]*'))*)\s*\?>/u;
2650
+
2651
+ /**
2652
+ * Whether `source` is an SVG drawn only with shapes: after an optional XML
2653
+ * declaration (only `version`, `encoding` and `standalone`, in UTF-8), every
2654
+ * element and attribute is on the allowlists above, every reference points
2655
+ * inside the file, no attribute value holds a character reference or a CSS
2656
+ * escape, and only `title` and `desc` hold text, and nothing else. Comments
2657
+ * are skipped where a tag could start; a doctype, CDATA or processing
2658
+ * instruction is refused.
2659
+ * @param {string} source
2660
+ * @returns {boolean}
2661
+ */
2662
+ function isShapesOnlySvg(source) {
2663
+ let rest = source.replace(/^\uFEFF/u, '').trim();
2664
+ if (rest.startsWith('<?')) {
2665
+ const declaration = XML_DECLARATION.exec(rest);
2666
+ if (declaration == null) return false;
2667
+ const encoding = /encoding\s*=\s*["']([^"']*)["']/u.exec(declaration[1]);
2668
+ if (encoding != null && encoding[1].toLowerCase() !== 'utf-8') return false;
2669
+ rest = rest.slice(declaration[0].length).trim();
2670
+ }
2671
+ /** @type {string[]} */
2672
+ const open = [];
2673
+ let rootClosed = false;
2674
+ while (rest.length > 0) {
2675
+ const inText = open.at(-1) === 'title' || open.at(-1) === 'desc';
2676
+ // `title` and `desc` hold text alone: no comment and no element.
2677
+ if (
2678
+ inText &&
2679
+ rest.startsWith('<') &&
2680
+ !rest.startsWith(`</${open.at(-1)}`)
2681
+ ) {
2682
+ return false;
2683
+ }
2684
+ // A comment is skipped only where a tag could start, so one opened
2685
+ // inside an attribute value cannot hide markup.
2686
+ // Its body may not start with `>` or `->` or hold `--`: an HTML parser
2687
+ // ends such a comment early, at `<!-->`, `<!--->` or `--!>`.
2688
+ if (rest.startsWith('<!--')) {
2689
+ const end = rest.indexOf('-->', 4);
2690
+ if (end === -1) return false;
2691
+ const body = rest.slice(4, end);
2692
+ if (
2693
+ body.startsWith('>') ||
2694
+ body.startsWith('->') ||
2695
+ body.includes('--')
2696
+ ) {
2697
+ return false;
2698
+ }
2699
+ rest = rest.slice(end + 3);
2700
+ continue;
2701
+ }
2702
+ if (rest.startsWith('<')) {
2703
+ const tag = SVG_TAG.exec(rest);
2704
+ if (tag == null || rootClosed) return false;
2705
+ const [whole, closing, rawName, attributes, selfClosing] = tag;
2706
+ const name = rawName.toLowerCase();
2707
+ if (!SVG_ELEMENTS.has(name)) return false;
2708
+ if (closing) {
2709
+ if (attributes.trim() !== '' || open.pop() !== name) return false;
2710
+ if (open.length === 0) rootClosed = true;
2711
+ } else {
2712
+ if (open.length === 0 && name !== 'svg') return false;
2713
+ for (const match of attributes.matchAll(SVG_ATTRIBUTE)) {
2714
+ const attribute = match[1].toLowerCase();
2715
+ if (!SVG_ATTRIBUTES.has(attribute)) return false;
2716
+ if (!isLocalSvgValue(attribute, match[2] ?? match[3] ?? '')) {
2717
+ return false;
2718
+ }
2719
+ }
2720
+ if (selfClosing) {
2721
+ if (open.length === 0) rootClosed = true;
2722
+ } else {
2723
+ open.push(name);
2724
+ }
2725
+ }
2726
+ rest = rest.slice(whole.length);
2727
+ continue;
2728
+ }
2729
+ const end = rest.indexOf('<');
2730
+ const text = end === -1 ? rest : rest.slice(0, end);
2731
+ const parent = open.at(-1);
2732
+ if (text.trim() !== '' && parent !== 'title' && parent !== 'desc') {
2733
+ return false;
2734
+ }
2735
+ rest = end === -1 ? '' : rest.slice(end);
2736
+ }
2737
+ return rootClosed && open.length === 0;
2738
+ }
2739
+
2740
+ /**
2741
+ * Whether these bytes are an image a catalog can show as a logo, in the
2742
+ * format the file's extension names: `.png`, `.jpg` or `.jpeg`, `.webp`, or
2743
+ * `.svg` drawn only with shapes; at most 512 KB. A file whose bytes claim
2744
+ * another format, or any other extension, is refused.
2745
+ * @param {Buffer} bytes
2746
+ * @param {string} file the image's path or name
2747
+ * @returns {boolean}
2748
+ */
2749
+ export function isListingImage(bytes, file) {
2750
+ if (bytes.length === 0 || bytes.length > LOGO_MAX_BYTES) return false;
2751
+ const png = [137, 80, 78, 71, 13, 10, 26, 10].every(
2752
+ (byte, index) => bytes[index] === byte,
2753
+ );
2754
+ const jpeg = bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255;
2755
+ const webp =
2756
+ bytes.subarray(0, 4).toString('latin1') === 'RIFF' &&
2757
+ bytes.subarray(8, 12).toString('latin1') === 'WEBP';
2758
+ switch (path.extname(file).toLowerCase()) {
2759
+ case '.png':
2760
+ return png;
2761
+ case '.jpg':
2762
+ case '.jpeg':
2763
+ return jpeg;
2764
+ case '.webp':
2765
+ return webp;
2766
+ case '.svg':
2767
+ return !png && !jpeg && !webp && isShapesOnlySvg(bytes.toString('utf8'));
2768
+ default:
2769
+ return false;
2770
+ }
2771
+ }
2772
+
2773
+ /**
2774
+ * What `componentExamplesCheck` found that the package-level note needs.
2775
+ * @typedef {object} ExampleSummary
2776
+ * @property {number} needed components that need an example and have none
2777
+ * @property {boolean} showcase whether any block template is a showcase
2778
+ */
2779
+
2780
+ /**
2781
+ * What a catalog needs to list the package well, as two information-only
2782
+ * notes that fail no check under any flag, each with its fix:
2783
+ * - `package_without_logo`: the integration file's `logo.light` (or, when
2784
+ * the integration file has no `logo`, package.json `marketplace.logo.light`)
2785
+ * names no image the package ships: missing, outside the package, not a
2786
+ * file, not a PNG, JPEG, WebP or shapes-only SVG of at most 512 KB, or left
2787
+ * out of the packed files. `dark`, when set, is checked the same way.
2788
+ * - `package_without_example`: from `examples`, the summary
2789
+ * `componentExamplesCheck` returns: the package has components that need
2790
+ * an example and no block template is a showcase. A package of themes,
2791
+ * docs, codemods or agent docs alone needs none.
2792
+ * A package of icon sets alone draws neither note. When npm cannot say
2793
+ * whether a logo is packed, it is returned in `unchecked`, listed with the
2794
+ * template assets npm could not place.
2795
+ * @param {LoadedIntegration} integration
2796
+ * @param {ExampleSummary} [examples]
2797
+ * @returns {{notes: Note[], unchecked: Array<{file: string, asset: string, reason: string}>}}
2798
+ */
2799
+ export function packageListingCheck(integration, examples) {
2800
+ /** @type {Note[]} */
2801
+ const notes = [];
2802
+ /** @type {Array<{file: string, asset: string, reason: string}>} */
2803
+ const unchecked = [];
2804
+ const base = integration.__packageDir;
2805
+ if (!base) return {notes, unchecked};
2806
+ /** @type {any} */
2807
+ let pkg;
2808
+ try {
2809
+ pkg = JSON.parse(fs.readFileSync(path.join(base, 'package.json'), 'utf8'));
2810
+ } catch {
2811
+ // package.json problems are reported by their own check.
2812
+ return {notes, unchecked};
2813
+ }
2814
+ // A package of icon sets alone is experimental; listing it is not.
2815
+ const stableRoots = [
2816
+ 'components',
2817
+ 'templates',
2818
+ 'themes',
2819
+ 'docs',
2820
+ 'codemods',
2821
+ 'agentDocs',
2822
+ ];
2823
+ if (!stableRoots.some(key => /** @type {any} */ (integration)[key])) {
2824
+ return {notes, unchecked};
2825
+ }
2826
+ const logo = listingLogo(integration, pkg);
2827
+ const fix = `Fix: add a square logo inside the package, such as \`marketplace/logo.svg\` (an SVG drawn only with shapes, or a PNG, JPEG or WebP, at most 512 KB), make sure \`files\` packs it, and set \`logo: {light: './marketplace/logo.svg'}\` in ${logo.file === 'package.json' ? 'the integration file' : logo.file}; add \`dark\` for a version drawn for dark backgrounds.`;
2828
+ /** @type {{packed?: {paths: Set<string>} | {error: string}}} */
2829
+ const npm = {};
2830
+ /**
2831
+ * Why the image at `value` cannot be shown, or null when it can (or when
2832
+ * only npm could tell, which adds it to `unchecked`).
2833
+ * @param {unknown} value
2834
+ * @param {string} field
2835
+ * @returns {string | null}
2836
+ */
2837
+ const problem = (value, field) => {
2838
+ const where = `${logo.file} \`${field}\``;
2839
+ if (typeof value !== 'string' || value.trim() === '') {
2840
+ return `${where} is ${value === undefined ? 'not set' : 'not a path'}`;
2841
+ }
2842
+ const rel = slash(path.normalize(value.trim())).replace(/^\.\//u, '');
2843
+ if (path.isAbsolute(value) || rel === '..' || rel.startsWith('../')) {
2844
+ return `${where} "${value}" points outside the package`;
2845
+ }
2846
+ const file = path.join(base, rel);
2847
+ if (!fs.existsSync(file) || !fs.statSync(file).isFile()) {
2848
+ return `${where} names ${rel}, which does not exist`;
2849
+ }
2850
+ if (!isListingImage(fs.readFileSync(file), rel)) {
2851
+ return `${where} names ${rel}, which is not a PNG, JPEG, WebP or shapes-only SVG of at most 512 KB whose contents match its extension`;
2852
+ }
2853
+ const state = packState(base, rel, pkg.files, npm);
2854
+ if (state.packed === true) return null;
2855
+ if (state.packed === 'unknown') {
2856
+ unchecked.push({file: logo.file, asset: rel, reason: state.error});
2857
+ return null;
2858
+ }
2859
+ return state.by === 'npm'
2860
+ ? `${where} names ${rel}, which npm leaves out of the package`
2861
+ : `${where} names ${rel}, which no \`files\` entry packs`;
2862
+ };
2863
+ const light = problem(logo.light, `${logo.field}.light`);
2864
+ if (light != null) {
2865
+ notes.push({
2866
+ code: 'package_without_logo',
2867
+ message: `${light}, so a catalog that lists this package shows no logo beside its name. ${fix}`,
2868
+ });
2869
+ } else if (logo.dark !== undefined) {
2870
+ const dark = problem(logo.dark, `${logo.field}.dark`);
2871
+ if (dark != null) {
2872
+ notes.push({
2873
+ code: 'package_without_logo',
2874
+ message: `${dark}, so on a dark background a catalog shows no logo for this package. Fix: point \`${logo.field}.dark\` at a packed image, or remove it to use the light logo everywhere.`,
2875
+ });
2876
+ }
2877
+ }
2878
+ if (examples != null && !examples.showcase && examples.needed > 0) {
2879
+ const {needed} = examples;
2880
+ notes.push({
2881
+ code: 'package_without_example',
2882
+ message: `The package contributes ${needed} component${needed === 1 ? '' : 's'} but no example block, so a catalog that lists it has nothing to preview. Fix: add a block template that renders one of them, with \`exampleFor: '<Component>'\` and \`isShowcase: true\` in its .doc.mjs; each \`component_without_example\` note gives the files to add.`,
2883
+ });
2884
+ }
2885
+ return {notes, unchecked};
2886
+ }
@@ -185,6 +185,12 @@ export function recentFailedInstall(version: string, cacheDir: string, now?: num
185
185
  failures: number;
186
186
  waitMs: number;
187
187
  } | null;
188
+ /**
189
+ * Is process `pid` on this computer still running?
190
+ * @param {number} pid
191
+ * @returns {boolean}
192
+ */
193
+ export function isAlive(pid: number): boolean;
188
194
  /**
189
195
  * Take a lock folder, or return false when another live run holds it. A lock
190
196
  * whose holder has gone, such as a run stopped with Ctrl-C or killed, is taken
@@ -224,17 +230,20 @@ export function isReleaseInstall(argv: string[], version: string, { node }?: {
224
230
  * since a recorded process id can name an unrelated process once the install
225
231
  * ended.
226
232
  * @param {string} lockDir a `.lock-<version>` folder
227
- * @param {{now?: number, procRoot?: string, factsOf?: (pid: number) => {argv: string[] | null, startedAt: number | null}}} [options]
233
+ * @param {{now?: number, procRoot?: string, factsOf?: (pid: number) => {argv: string[] | null, startedAt: number | null}, version?: string}} [options]
234
+ * `version` names the release when the folder's name does not (a lock
235
+ * moved aside).
228
236
  * the clock, the process table's folder, and the fact reader, for tests
229
237
  * @returns {'ended' | 'left'} whether a process group was ended
230
238
  */
231
- export function endRecordedInstall(lockDir: string, { now, procRoot, factsOf }?: {
239
+ export function endRecordedInstall(lockDir: string, { now, procRoot, factsOf, version: named }?: {
232
240
  now?: number;
233
241
  procRoot?: string;
234
242
  factsOf?: (pid: number) => {
235
243
  argv: string[] | null;
236
244
  startedAt: number | null;
237
245
  };
246
+ version?: string;
238
247
  }): "ended" | "left";
239
248
  /**
240
249
  * Why a release could not be made available.