@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61

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 (203) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/README.md +63 -63
  3. package/api/build/_adapter.d.mts +4 -0
  4. package/api/build/_adapter.mjs +28 -2
  5. package/api/build/blocks/blocks.d.mts +10 -1
  6. package/api/build/blocks/blocks.mjs +84 -7
  7. package/api/build/build.mjs +6 -1
  8. package/api/build/tree.d.mts +4 -0
  9. package/api/build/tree.mjs +9 -2
  10. package/api/doctor/_adapter.d.mts +3 -1
  11. package/api/doctor/_adapter.mjs +14 -1
  12. package/api/doctor/_authoring-audit.d.mts +42 -0
  13. package/api/doctor/_authoring-audit.mjs +106 -0
  14. package/api/doctor/doctor.d.mts +7 -0
  15. package/api/doctor/doctor.mjs +24 -39
  16. package/api/doctor/theme-checks.mjs +56 -21
  17. package/api/integration/add-helpers.mjs +5 -0
  18. package/api/integration/add-theme.mjs +15 -110
  19. package/api/integration/validate-integration.mjs +17 -3
  20. package/api/integration/validateIntegration.doc.mjs +1 -1
  21. package/api/search/_adapter.mjs +124 -3
  22. package/api/search/_candidate-score.mjs +63 -9
  23. package/api/search/_entries.d.mts +10 -0
  24. package/api/search/_entries.mjs +68 -1
  25. package/api/search/_gather-templates.d.mts +11 -0
  26. package/api/search/_gather-templates.mjs +22 -2
  27. package/api/search/_words.mjs +26 -6
  28. package/api/swizzle/copy/copy.mjs +1 -1
  29. package/api/theme/_adapter.d.mts +37 -5
  30. package/api/theme/_adapter.mjs +381 -57
  31. package/api/theme/_fork.d.mts +90 -0
  32. package/api/theme/_fork.mjs +246 -0
  33. package/api/theme/build/build.d.mts +40 -2
  34. package/api/theme/build/build.mjs +477 -66
  35. package/api/theme/eject/eject.mjs +36 -15
  36. package/api/theme/list/list.mjs +3 -6
  37. package/api/theme/palette/generate/generator.d.mts +13 -0
  38. package/api/theme/palette/generate/generator.mjs +32 -2
  39. package/api/theme/targets/targets.d.mts +8 -0
  40. package/api/theme/targets/targets.mjs +24 -4
  41. package/api/theme/template/template.mjs +48 -2
  42. package/api/theme/theme.type.d.mts +8 -0
  43. package/api/theme/theme.type.mjs +5 -1
  44. package/api/theme/themeBuild.doc.mjs +7 -4
  45. package/api/theme/themeEject.doc.mjs +3 -3
  46. package/api/theme/themeRemove.doc.mjs +5 -2
  47. package/api/theme/themeTargets.doc.mjs +1 -1
  48. package/api/theme/themeTemplate.doc.mjs +2 -2
  49. package/api/theme/themeUse.doc.mjs +8 -2
  50. package/api/theme-edit/_adapter.d.mts +46 -3
  51. package/api/theme-edit/_adapter.mjs +496 -112
  52. package/api/theme-edit/_catalog.d.mts +1 -6
  53. package/api/theme-edit/_catalog.mjs +5 -268
  54. package/api/theme-edit/_check.d.mts +9 -4
  55. package/api/theme-edit/_check.mjs +1232 -229
  56. package/api/theme-edit/_color.d.mts +19 -0
  57. package/api/theme-edit/_color.mjs +280 -34
  58. package/api/theme-edit/_compiler.d.mts +3 -1
  59. package/api/theme-edit/_compiler.mjs +52 -13
  60. package/api/theme-edit/_context.d.mts +4 -1
  61. package/api/theme-edit/_context.mjs +126 -13
  62. package/api/theme-edit/_css.d.mts +84 -0
  63. package/api/theme-edit/_css.mjs +700 -0
  64. package/api/theme-edit/_edit.d.mts +9 -3
  65. package/api/theme-edit/_edit.mjs +806 -103
  66. package/api/theme-edit/_how-commands.d.mts +38 -7
  67. package/api/theme-edit/_how-commands.mjs +64 -45
  68. package/api/theme-edit/_how-question.d.mts +33 -0
  69. package/api/theme-edit/_how-question.mjs +2553 -381
  70. package/api/theme-edit/_how.mjs +402 -31
  71. package/api/theme-edit/_overview.mjs +2 -7
  72. package/api/theme-edit/_palette.d.mts +60 -13
  73. package/api/theme-edit/_palette.mjs +826 -295
  74. package/api/theme-edit/_parts.d.mts +42 -10
  75. package/api/theme-edit/_parts.mjs +280 -69
  76. package/api/theme-edit/_png.d.mts +4 -4
  77. package/api/theme-edit/_png.mjs +4 -2
  78. package/api/theme-edit/_preview-app.d.mts +14 -0
  79. package/api/theme-edit/_preview-app.mjs +1675 -235
  80. package/api/theme-edit/_preview.d.mts +7 -16
  81. package/api/theme-edit/_preview.mjs +79 -86
  82. package/api/theme-edit/_project.d.mts +32 -2
  83. package/api/theme-edit/_project.mjs +80 -19
  84. package/api/theme-edit/_settings.d.mts +199 -52
  85. package/api/theme-edit/_settings.mjs +1422 -217
  86. package/api/theme-edit/_tables.d.mts +19 -6
  87. package/api/theme-edit/_tables.mjs +150 -92
  88. package/api/theme-edit/theme-edit.type.d.mts +20 -1
  89. package/api/theme-edit/theme-edit.type.mjs +6 -3
  90. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  91. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  92. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  93. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  94. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  95. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  96. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  97. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  98. package/api/upgrade/_adapter.d.mts +1 -0
  99. package/assets/codemods/run-codemod.mjs +61 -0
  100. package/assets/codemods/runner.mjs +5 -4
  101. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  102. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  103. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  104. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  105. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  106. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  107. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  108. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  109. package/assets/docs/tree/calendars.doc.mjs +1 -3
  110. package/assets/docs/tree/checks.doc.mjs +22 -1
  111. package/assets/docs/tree/publishing.doc.mjs +1 -0
  112. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  113. package/assets/docs.generated.json +2 -1
  114. package/assets/preview-app/next.config.mjs +7 -1
  115. package/assets/self-audit.generated.json +1 -0
  116. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  117. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  118. package/assets/templates/components.generated.json +1 -1
  119. package/authoring/integration/integration.doc.mjs +8 -0
  120. package/authoring/integration/schema.d.mts +8 -0
  121. package/authoring/integration/schema.mjs +1 -0
  122. package/authoring/integration/type.ts +9 -0
  123. package/clients/cli/bin/astryx.mjs +19 -15
  124. package/clients/cli/build-id.generated.json +1 -0
  125. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  126. package/clients/cli/commands/experimental/index.mjs +10 -10
  127. package/clients/cli/commands/experimental/theme.mjs +200 -81
  128. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  129. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  130. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  131. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  132. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  133. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  134. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  135. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  136. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  137. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  138. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  139. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  140. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  141. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  142. package/clients/cli/commands/integration.mjs +8 -0
  143. package/clients/cli/commands/manifest.mjs +5 -2
  144. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  145. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  146. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  147. package/clients/cli/commands/theme.mjs +439 -66
  148. package/clients/cli/index.mjs +27 -6
  149. package/clients/cli/lib/cli-error.mjs +118 -3
  150. package/clients/cli/lib/manifest.mjs +37 -0
  151. package/clients/cli/lib/resolve-theme.mjs +2 -1
  152. package/clients/cli/manifest.generated.json +1 -0
  153. package/foundation/config/project.mjs +34 -8
  154. package/foundation/config/theme-state.d.mts +16 -0
  155. package/foundation/config/theme-state.mjs +84 -13
  156. package/foundation/discovery/module-exports.mjs +16 -2
  157. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  158. package/foundation/discovery/stored-self-audit.mjs +119 -0
  159. package/foundation/discovery/template-adapter.d.mts +48 -2
  160. package/foundation/discovery/template-adapter.mjs +51 -19
  161. package/foundation/discovery/template-needs.d.mts +19 -0
  162. package/foundation/discovery/template-needs.mjs +50 -16
  163. package/foundation/discovery/template-source-tree.d.mts +7 -0
  164. package/foundation/discovery/template-source-tree.mjs +15 -0
  165. package/foundation/discovery/theme-discovery.d.mts +2 -1
  166. package/foundation/discovery/theme-discovery.mjs +16 -10
  167. package/foundation/discovery/theme-imports.d.mts +16 -0
  168. package/foundation/discovery/theme-imports.mjs +30 -2
  169. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  170. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  171. package/foundation/doc-compiler/import.mjs +22 -15
  172. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  173. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  174. package/foundation/env/private-dir.d.mts +17 -0
  175. package/foundation/env/private-dir.mjs +42 -0
  176. package/foundation/fs/gather-cache.d.mts +108 -0
  177. package/foundation/fs/gather-cache.mjs +783 -0
  178. package/foundation/fs/jiti-cache.d.mts +21 -0
  179. package/foundation/fs/jiti-cache.mjs +66 -0
  180. package/foundation/fs/module-loader.mjs +14 -3
  181. package/foundation/fs/read-record.d.mts +31 -1
  182. package/foundation/fs/read-record.mjs +100 -7
  183. package/foundation/integrations/autolink.d.mts +1 -24
  184. package/foundation/integrations/autolink.mjs +7 -60
  185. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  186. package/foundation/integrations/declared-dependencies.mjs +73 -0
  187. package/foundation/integrations/integrations.d.mts +8 -0
  188. package/foundation/integrations/integrations.mjs +4 -0
  189. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  190. package/foundation/integrations/may-have-integrations.mjs +47 -0
  191. package/foundation/integrations/validate-contributions.d.mts +62 -1
  192. package/foundation/integrations/validate-contributions.mjs +476 -40
  193. package/foundation/release/cache.d.mts +32 -4
  194. package/foundation/release/cache.mjs +105 -16
  195. package/foundation/release/folder-lock.d.mts +28 -0
  196. package/foundation/release/folder-lock.mjs +205 -0
  197. package/foundation/release/lock-lease.d.mts +2 -1
  198. package/foundation/release/lock-lease.mjs +7 -2
  199. package/foundation/response/error-codes.doc.mjs +1 -1
  200. package/foundation/response/response-types.doc.mjs +5 -5
  201. package/package.json +8 -6
  202. package/api/theme-edit/_css-properties.d.mts +0 -10
  203. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -124,8 +124,12 @@ export function negatedFilesEntry(rel: string, files: unknown): string | null;
124
124
  * package (`npm pack --dry-run`). When npm cannot answer, an asset no
125
125
  * `files` entry can reach is still a note, and any other is returned in
126
126
  * `unchecked`.
127
+ * It also returns `examples`, what the package-level listing note needs:
128
+ * whether any block is a showcase, and, when none is, how many components
129
+ * need an example (the exemptions above apply). It is absent when the
130
+ * templates or components cannot be read, so no listing note is drawn.
127
131
  * @param {LoadedIntegration} integration
128
- * @returns {Promise<{notes: Note[], unchecked: Array<{file: string, asset: string, reason: string}>}>}
132
+ * @returns {Promise<{notes: Note[], unchecked: Array<{file: string, asset: string, reason: string}>, examples?: ExampleSummary}>}
129
133
  */
130
134
  export function componentExamplesCheck(integration: LoadedIntegration): Promise<{
131
135
  notes: Note[];
@@ -134,6 +138,7 @@ export function componentExamplesCheck(integration: LoadedIntegration): Promise<
134
138
  asset: string;
135
139
  reason: string;
136
140
  }>;
141
+ examples?: ExampleSummary;
137
142
  }>;
138
143
  /**
139
144
  * The component doc names the check could not judge, shaped like the doc type
@@ -192,6 +197,49 @@ export function validateLoadedIntegrationListed(loaded: LoadedIntegration): Prom
192
197
  issues: Issue[];
193
198
  listed: Issue[];
194
199
  }>;
200
+ /**
201
+ * Whether these bytes are an image a catalog can show as a logo, in the
202
+ * format the file's extension names: `.png`, `.jpg` or `.jpeg`, `.webp`, or
203
+ * `.svg` drawn only with shapes; at most 512 KB. A file whose bytes claim
204
+ * another format, or any other extension, is refused.
205
+ * @param {Buffer} bytes
206
+ * @param {string} file the image's path or name
207
+ * @returns {boolean}
208
+ */
209
+ export function isListingImage(bytes: Buffer, file: string): boolean;
210
+ /**
211
+ * What `componentExamplesCheck` found that the package-level note needs.
212
+ * @typedef {object} ExampleSummary
213
+ * @property {number} needed components that need an example and have none
214
+ * @property {boolean} showcase whether any block template is a showcase
215
+ */
216
+ /**
217
+ * What a catalog needs to list the package well, as two information-only
218
+ * notes that fail no check under any flag, each with its fix:
219
+ * - `package_without_logo`: the integration file's `logo.light` (or, when
220
+ * the integration file has no `logo`, package.json `marketplace.logo.light`)
221
+ * names no image the package ships: missing, outside the package, not a
222
+ * file, not a PNG, JPEG, WebP or shapes-only SVG of at most 512 KB, or left
223
+ * out of the packed files. `dark`, when set, is checked the same way.
224
+ * - `package_without_example`: from `examples`, the summary
225
+ * `componentExamplesCheck` returns: the package has components that need
226
+ * an example and no block template is a showcase. A package of themes,
227
+ * docs, codemods or agent docs alone needs none.
228
+ * A package of icon sets alone draws neither note. When npm cannot say
229
+ * whether a logo is packed, it is returned in `unchecked`, listed with the
230
+ * template assets npm could not place.
231
+ * @param {LoadedIntegration} integration
232
+ * @param {ExampleSummary} [examples]
233
+ * @returns {{notes: Note[], unchecked: Array<{file: string, asset: string, reason: string}>}}
234
+ */
235
+ export function packageListingCheck(integration: LoadedIntegration, examples?: ExampleSummary): {
236
+ notes: Note[];
237
+ unchecked: Array<{
238
+ file: string;
239
+ asset: string;
240
+ reason: string;
241
+ }>;
242
+ };
195
243
  /**
196
244
  * @typedef {import('./issue').AstryxIntegrationIssue} Issue
197
245
  * @typedef {import('./integrations.mjs').LoadedIntegration} LoadedIntegration
@@ -210,5 +258,18 @@ export type Note = {
210
258
  code: string;
211
259
  message: string;
212
260
  };
261
+ /**
262
+ * What `componentExamplesCheck` found that the package-level note needs.
263
+ */
264
+ export type ExampleSummary = {
265
+ /**
266
+ * components that need an example and have none
267
+ */
268
+ needed: number;
269
+ /**
270
+ * whether any block template is a showcase
271
+ */
272
+ showcase: boolean;
273
+ };
213
274
  export type Issue = import("./issue").AstryxIntegrationIssue;
214
275
  export type LoadedIntegration = import("./integrations.mjs").LoadedIntegration;
@@ -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
+ }