@astryxdesign/cli 0.7.2-canary.405bb94 → 0.7.2-canary.411cbed

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 (31) hide show
  1. package/api/component/_adapter.d.mts +41 -1
  2. package/api/component/_adapter.mjs +93 -7
  3. package/api/component/component.mjs +22 -5
  4. package/api/component/integration-export-name.test.mjs +644 -0
  5. package/api/gap-report/gap-report.mjs +67 -4
  6. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  7. package/api/integration/add-contribution.mjs +7 -3
  8. package/api/integration/pack-check.mjs +51 -97
  9. package/api/integration/pack-check.test.mjs +359 -0
  10. package/api/search/search.d.mts +9 -0
  11. package/api/search/search.mjs +100 -13
  12. package/api/swizzle/copy/copy.mjs +28 -14
  13. package/assets/docs/tree/add-a-component.doc.mjs +10 -0
  14. package/assets/docs/tree/checks.doc.mjs +1 -1
  15. package/assets/docs/tree/component-family.doc.mjs +5 -1
  16. package/assets/docs/tree/component-imports.doc.mjs +8 -0
  17. package/assets/docs/tree/single-component.doc.mjs +1 -1
  18. package/assets/docs/tree/troubleshooting.doc.mjs +9 -1
  19. package/assets/docs/tree/versioning.doc.mjs +1 -0
  20. package/authoring/doctypes/component/component.doc.mjs +2 -2
  21. package/authoring/doctypes/component/type.ts +6 -3
  22. package/foundation/discovery/component-discovery.d.mts +160 -10
  23. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  24. package/foundation/discovery/component-discovery.mjs +658 -61
  25. package/foundation/discovery/component-replacement.mjs +18 -0
  26. package/foundation/discovery/component-replacement.test.mjs +40 -0
  27. package/foundation/discovery/module-exports.d.mts +27 -0
  28. package/foundation/discovery/module-exports.mjs +356 -31
  29. package/foundation/discovery/module-exports.test.mjs +172 -0
  30. package/foundation/integrations/contribution-inventory.mjs +6 -1
  31. package/package.json +9 -9
@@ -71,5 +71,15 @@ Declare component root ./components in astryx.integration.mjs.
71
71
  },
72
72
  ],
73
73
  },
74
+ {
75
+ id: 'document-an-existing-component',
76
+ title: 'Document a component you already have',
77
+ content: [
78
+ {
79
+ type: 'prose',
80
+ text: "To document a component your package already has, write its doc beside the source file and name the doc after that file, such as `acme-gallery.doc.mjs` beside `acme-gallery.tsx`. Set `name` to the export apps import, such as `name: 'AcmeGallery'`, and keep both files inside the components root that `astryx.integration.mjs` declares. The file does not have to be named after the component; {@link generic:component-imports} shows how apps then find it.",
81
+ },
82
+ ],
83
+ },
74
84
  ],
75
85
  };
@@ -105,7 +105,7 @@ export const docs = {
105
105
  'It runs `npm pack` the way `npm publish` would, including your `prepack` script.',
106
106
  'It checks that every contribution file is in the `.tgz` file. A root missing from `files` fails with `Add "templates" to "files" in package.json.`',
107
107
  'It lists the components, templates, themes, docs, and codemods the temporary app sees, and compares them with your source.',
108
- "It resolves each component's `import`, and each template's public import, the way Node does, and checks that the module exports the component, or a default export for a template.",
108
+ "It resolves each component's `import`, and each template's public import, the way Node does, and checks that the module exports the component under the name its doc documents, or a default export for a template. A type-only export does not count.",
109
109
  'For each theme, it rebuilds the source, compares the built module and production CSS with the authored outputs, and proves the module, CSS, and optional font CSS exports resolve from the packed package.',
110
110
  'It fails a package that needs an `@astryxdesign/cli` peer and lacks it: `>=0.6.6` for a template that sets `keywords`, and `>=0.6.4` for a template that sets `replaces`, a docs section, a placed guide, a doc section with an `id`, or a theme.',
111
111
  ],
@@ -95,7 +95,11 @@ export default {
95
95
  },
96
96
  {
97
97
  type: 'prose',
98
- text: 'The public module named by `import` must export every component or hook named by a full entry.',
98
+ text: "The public module named by `import` must export every component or hook named by a full entry. Apps then list, search and open each component in the family by its own name. A full entry the module does not export is not listed, and `integration verify` does not report it: check the family with `astryx component --list`. When `import` names output your pack lifecycle builds (such as `dist`), the members are listed once that output exists, and `integration verify` compares them as they are listed after the pack builds it.",
99
+ },
100
+ {
101
+ type: 'prose',
102
+ text: "A member's source is the `.tsx` file in the family doc's folder, or below it, that declares it: the one the family's own file or the module `import` names reaches, else the one in that folder that declares the name, as when `import` names built output. A member that only a bundle or a file outside that folder declares is still listed, with no source for `--source` or `swizzle`. A member is not listed when a doc's file or a Core name your package replaces already has its name. A member that shares a name with Core opens with `--package`.",
99
103
  },
100
104
  ],
101
105
  },
@@ -35,6 +35,14 @@ export const docs = {
35
35
  type: 'prose',
36
36
  text: 'Add writes the entry only when package.json already has an `exports` map, so start every package with `"exports": {}`.',
37
37
  },
38
+ {
39
+ type: 'prose',
40
+ text: 'A file does not have to be named after its component. When `Slides.tsx` exports `AcmeCarousel` and nothing named `Slides`, keep the doc beside it as `Slides.doc.mjs` and set its `name` to `AcmeCarousel`: apps list, search and open the component by that name, and `integration verify` checks that its import exports `AcmeCarousel`. A file that exports its own name keeps that name. A package that names its files in kebab case works the same way: `acme-gallery.doc.mjs` beside `acme-gallery.tsx` sets `name: \'AcmeGallery\'`.',
41
+ },
42
+ {
43
+ type: 'prose',
44
+ text: "The file name still opens the doc. A name that Core or another doc's file already has stays theirs, and so does a Core name your package replaces: with `Badge.doc.mjs` naming `AcmeBadge`, `astryx component Badge` opens Core's `Badge`, and `--package` with your package name reaches yours.",
45
+ },
38
46
  ],
39
47
  },
40
48
  {
@@ -56,7 +56,7 @@ export default {
56
56
  style: 'unordered',
57
57
  items: [
58
58
  'Keep `props` on the top-level doc. Private implementation helpers do not need entries.',
59
- 'Keep the doc beside the source and change both in the same pull request.',
59
+ 'Name the doc after the source file beside it, such as `AcmeCarousel.doc.mjs` beside `AcmeCarousel.tsx`, and change both in the same pull request.',
60
60
  'If the module later exposes several related public exports, adapt this doc with {@link generic:component-family}.',
61
61
  ],
62
62
  },
@@ -67,7 +67,7 @@ export const docs = {
67
67
  rows: [
68
68
  [
69
69
  '`component_export_missing`: `Component "AcmeCarousel" advertises import "@acme/astryx-widgets/components/AcmeCarousel", but that packed module does not export "AcmeCarousel".`',
70
- "package.json has no `exports` map, or the module does not export the name. Keep `export function AcmeCarousel`, and add the entry: `npm pkg set 'exports[./components/AcmeCarousel]=./components/AcmeCarousel.tsx'`.",
70
+ "package.json has no `exports` map, or the module does not export the name. Keep `export function AcmeCarousel`, and add the entry: `npm pkg set 'exports[./components/AcmeCarousel]=./components/AcmeCarousel.tsx'`. When the quoted name is a file name, such as `acme-carousel`, set the doc's `name` to the component the file exports. A type-only export does not count.",
71
71
  ],
72
72
  [
73
73
  '`template_export_missing`: `Template "acme-dashboard" public import "@acme/astryx-widgets/templates/acme-dashboard" does not have a default export.`',
@@ -125,6 +125,14 @@ export const docs = {
125
125
  type: 'table',
126
126
  headers: ['Symptom', 'Fix'],
127
127
  rows: [
128
+ [
129
+ '`Error: No component named "AcmeCarousel"` for a component your package documents.',
130
+ "Its doc still names its file. Set `name` to the export, such as `name: 'AcmeCarousel'` in `acme-carousel.doc.mjs`. A family member is listed only when the module its family doc imports exports it ({@link generic:component-family}).",
131
+ ],
132
+ [
133
+ '`npx astryx component Dialog` opens Core\'s `Dialog`, not yours.',
134
+ "A name that Core, a legacy docs package, or another package's file already has stays theirs. Run `npx astryx component Dialog --package @acme/astryx-widgets`, or give your component a name of its own.",
135
+ ],
128
136
  [
129
137
  '`Error: Template "dashboard" is ambiguous — narrow it with --type and/or --package.`',
130
138
  "Your template id matches a Core id. Rename it, such as `acme-dashboard`, or set `replaces: 'dashboard'` to take its place. `npx astryx doctor integration templates` warns about this before you publish.",
@@ -140,6 +140,7 @@ export const docs = {
140
140
  'Published 0.6.3 and earlier reject a template that sets `replaces` or `keywords`, drop that template, and hide every doc topic your package ships. Published 0.6.4 and 0.6.5 still drop a template that sets `keywords`.',
141
141
  'A stable CLI before 0.6.4 cannot read a docs section, a section `id`, or a theme folder that `integration add theme` writes. It can then hide every doc topic your package ships.',
142
142
  'Stable 0.6.3 still loads your components, but 0.6.0 cannot read the component docs that `integration add component` writes: `component AcmeCarousel` fails there.',
143
+ 'An app on an older CLI lists a component whose doc names another export of its file under the file name, and lists no family members, so `component AcmeCarousel` fails there.',
143
144
  ],
144
145
  },
145
146
  {
@@ -30,7 +30,7 @@ export const doc = {
30
30
  name: 'name',
31
31
  type: 'string',
32
32
  description:
33
- "Stable machine identity and directory name without the Astryx prefix, PascalCase. e.g. 'Button', 'TextInput', 'AppShell'. Change `displayName`, not `name`, to edit the visible label; registry URLs derive from this identity by default.",
33
+ "Stable machine identity and directory name without the Astryx prefix, PascalCase. e.g. 'Button', 'TextInput', 'AppShell'. For an integration component it is the export apps import: the doc sits beside the file that exports it, and when that file exports nothing under its own name, `name` may name the export it does have. Change `displayName`, not `name`, to edit the visible label; registry URLs derive from this identity by default.",
34
34
  required: true,
35
35
  },
36
36
  {
@@ -187,7 +187,7 @@ export const doc = {
187
187
  name: 'components',
188
188
  type: '(ComponentEntry | ComponentRef)[]',
189
189
  description:
190
- 'MultiComponentDoc variant (required there): one entry per public component/hook exported from the directory. Each entry is a full ComponentEntry (inline: name, displayName, description, props | params+returns) or a name-only ComponentRef pointing at a sibling {Name}.doc.mjs.',
190
+ 'MultiComponentDoc variant (required there): one entry per public component/hook exported from the directory. Each entry is a full ComponentEntry (inline: name, displayName, description, props | params+returns) or a name-only ComponentRef pointing at a sibling {Name}.doc.mjs. In an integration, each full entry the module named by `import` exports is a component under its own name.',
191
191
  },
192
192
  {
193
193
  name: 'subComponentOf',
@@ -33,9 +33,12 @@ export interface ComponentBaseDoc extends AuthoredDocGraphFields {
33
33
  type?: 'component';
34
34
  /**
35
35
  * Stable machine identity and directory name without the Astryx prefix,
36
- * PascalCase (for example `Button`, `Table`, or `AppShell`). Do not change
37
- * this to edit the visible label; use `displayName` for that. Registry URLs
38
- * derive from this value by default.
36
+ * PascalCase (for example `Button`, `Table`, or `AppShell`). For an
37
+ * integration component it is the export apps import: the doc sits beside
38
+ * the file that exports it, and when that file exports nothing under its own
39
+ * name, `name` may name the export it does have. Do not change this to edit
40
+ * the visible label; use `displayName` for that. Registry URLs derive from
41
+ * this value by default.
39
42
  */
40
43
  name: string;
41
44
  /** Human-readable display name with spaces between words, used by the
@@ -115,19 +115,81 @@ export function discoverExternalComponentsGrouped(docsDir: string): Record<strin
115
115
  * @returns {string | null}
116
116
  */
117
117
  export function findExternalComponentDoc(docsDir: string, name: string): string | null;
118
+ /** @param {string} docPath */
119
+ export function docStem(docPath: string): string;
120
+ /**
121
+ * Each family doc under an integration's components root that names an
122
+ * import, with the file the import resolves to: null when it resolves to none,
123
+ * such as build output that does not exist yet.
124
+ *
125
+ * @param {{name: string, components?: string, issuesUrl?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
126
+ * @returns {Array<{docPath: string, module: string | null}>}
127
+ */
128
+ export function familyImports(integration: {
129
+ name: string;
130
+ components?: string;
131
+ issuesUrl?: string;
132
+ __packageDir?: string;
133
+ __packageExports?: Record<string, unknown> | null;
134
+ }): Array<{
135
+ docPath: string;
136
+ module: string | null;
137
+ }>;
138
+ /**
139
+ * Whether a discovered integration record is a member its family doc lists,
140
+ * decided from the files, not from whether the doc loads.
141
+ *
142
+ * @param {{name: string, docPath: string|null}} record
143
+ * @returns {boolean}
144
+ */
145
+ export function isIntegrationMember(record: {
146
+ name: string;
147
+ docPath: string | null;
148
+ }): boolean;
149
+ /**
150
+ * The entry a family doc gives a member that discovery lists under its own
151
+ * name, or null when the record is the doc's own component or the loaded doc
152
+ * has no entry for it.
153
+ *
154
+ * @param {any} doc the doc loaded from `record.docPath`
155
+ * @param {{name: string, docPath: string|null}} record
156
+ * @returns {any}
157
+ */
158
+ export function integrationMemberEntry(doc: any, record: {
159
+ name: string;
160
+ docPath: string | null;
161
+ }): any;
162
+ /**
163
+ * Visit every component doc under an integration's components root, hidden
164
+ * ones included, in discovery order, with its stem.
165
+ * @param {string | undefined} componentsDir
166
+ * @param {(docPath: string, stem: string) => void} visit
167
+ */
168
+ export function forEachIntegrationDoc(componentsDir: string | undefined, visit: (docPath: string, stem: string) => void): void;
118
169
  /**
119
170
  * Discover ownership records for the components contributed by a single loaded
120
171
  * integration. Scans the integration's resolved `components` dir for same-stem
121
- * doc files and records each with owner package + issuesUrl + sourcePath.
172
+ * doc files and records each with owner package + issuesUrl + sourcePath. A doc
173
+ * that names a differently named export of its file is recorded under that
174
+ * export, and each family member it lists, under the member's name, unless the
175
+ * name is taken: every doc's file name (a hidden doc's too), a Core name a doc
176
+ * in the package replaces, and a name an earlier doc records.
122
177
  *
123
- * @param {{name: string, components?: string, issuesUrl?: string}} integration
178
+ * @param {{name: string, components?: string, issuesUrl?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
124
179
  * a single entry from `loadedIntegrations` (lib/integrations.mjs)
180
+ * @param {{documentedNames?: boolean}} [options] `documentedNames: false`
181
+ * records each doc under its file name alone, without reading the names
182
+ * docs document: for a caller that needs only what each doc says
125
183
  * @returns {Array<{name: string, package: string, docPath: string, sourcePath: string|null, issuesUrl: string|undefined, group: string|null}>}
126
184
  */
127
185
  export function discoverIntegrationComponents(integration: {
128
186
  name: string;
129
187
  components?: string;
130
188
  issuesUrl?: string;
189
+ __packageDir?: string;
190
+ __packageExports?: Record<string, unknown> | null;
191
+ }, { documentedNames }?: {
192
+ documentedNames?: boolean;
131
193
  }): Array<{
132
194
  name: string;
133
195
  package: string;
@@ -141,11 +203,16 @@ export function discoverIntegrationComponents(integration: {
141
203
  * Invalid metadata or a missing same-stem source removes only that component;
142
204
  * callers can report the returned errors while retaining valid siblings. A
143
205
  * component whose doc sets `replaces` carries the value as written; the
144
- * component replacement resolver decides what it means.
206
+ * component replacement resolver decides what it means. A family member is
207
+ * read through its family's doc: it never carries the family's `replaces`, and
208
+ * a family doc that fails to load is reported once. A doc that fails to load
209
+ * is reported under its file name: what it says cannot be trusted.
145
210
  *
146
211
  * @param {{name: string, components?: string, issuesUrl?: string}} integration
212
+ * @param {{documentedNames?: boolean}} [options] as for
213
+ * {@link discoverIntegrationComponents}
147
214
  * @returns {Promise<{
148
- * components: Array<{name: string, package: string, docPath: string, sourcePath: string, issuesUrl: string|undefined, group: string|null, replaces?: unknown}>,
215
+ * components: Array<{name: string, package: string, docPath: string, sourcePath: string|null, issuesUrl: string|undefined, group: string|null, replaces?: unknown}>,
149
216
  * discovered: Array<{name: string, package: string, docPath: string, sourcePath: string|null, issuesUrl: string|undefined, group: string|null}>,
150
217
  * errors: Array<{name: string, message: string}>,
151
218
  * }>}
@@ -154,12 +221,14 @@ export function discoverValidIntegrationComponents(integration: {
154
221
  name: string;
155
222
  components?: string;
156
223
  issuesUrl?: string;
224
+ }, options?: {
225
+ documentedNames?: boolean;
157
226
  }): Promise<{
158
227
  components: Array<{
159
228
  name: string;
160
229
  package: string;
161
230
  docPath: string;
162
- sourcePath: string;
231
+ sourcePath: string | null;
163
232
  issuesUrl: string | undefined;
164
233
  group: string | null;
165
234
  replaces?: unknown;
@@ -177,30 +246,103 @@ export function discoverValidIntegrationComponents(integration: {
177
246
  message: string;
178
247
  }>;
179
248
  }>;
249
+ /**
250
+ * How an owner holds a component name, which the owner rule
251
+ * ({@link unscopedComponentOwners}) reads: `core` when Core documents it;
252
+ * `file` when an integration doc named after its file is recorded under it;
253
+ * `doc` when only a doc records it: an export name, a member, or the file name
254
+ * of a doc recorded under another export.
255
+ * @typedef {'core' | 'file' | 'doc'} NameHold
256
+ */
257
+ /**
258
+ * How a discovered integration record holds its name.
259
+ * @param {{name: string, docPath: string|null}} record
260
+ * @returns {'file' | 'doc'}
261
+ */
262
+ export function integrationRecordHold(record: {
263
+ name: string;
264
+ docPath: string | null;
265
+ }): "file" | "doc";
266
+ /**
267
+ * The integration component a name finds, as discovery records it, and its
268
+ * hold: the same-stem doc first, then a doc that records the name as an export
269
+ * or a member.
270
+ *
271
+ * @param {{name?: string, components?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
272
+ * @param {string} name
273
+ * @returns {{docPath: string, sourcePath: string|null, hold: 'file' | 'doc'} | null}
274
+ */
275
+ export function findIntegrationComponent(integration: {
276
+ name?: string;
277
+ components?: string;
278
+ __packageDir?: string;
279
+ __packageExports?: Record<string, unknown> | null;
280
+ }, name: string): {
281
+ docPath: string;
282
+ sourcePath: string | null;
283
+ hold: "file" | "doc";
284
+ } | null;
285
+ /**
286
+ * The name discovery records a component doc under: the export its `name`
287
+ * documents when the doc is recorded under it, else the doc's file name.
288
+ *
289
+ * @param {{name?: string, components?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
290
+ * @param {string} docPath
291
+ * @returns {string}
292
+ */
293
+ export function recordedDocName(integration: {
294
+ name?: string;
295
+ components?: string;
296
+ __packageDir?: string;
297
+ __packageExports?: Record<string, unknown> | null;
298
+ }, docPath: string): string;
180
299
  /**
181
300
  * Find an integration component's doc file by name within a loaded
182
301
  * integration's resolved `components` dir. Honors the same-stem convention
183
- * (`{Name}.doc.{ts,mjs,js}`), preferring `.ts` → `.mjs` → `.js`.
302
+ * (`{Name}.doc.{ts,mjs,js}`), preferring `.ts` → `.mjs` → `.js`, and finds a
303
+ * doc that records the component under another name: a differently named
304
+ * export of its file, or a member its family doc lists.
184
305
  *
185
- * @param {{components?: string}} integration
306
+ * @param {{name?: string, components?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
186
307
  * @param {string} name bare component name (no `XDS`/`Astryx` prefix)
187
308
  * @returns {string|null}
188
309
  */
189
310
  export function findIntegrationComponentDoc(integration: {
311
+ name?: string;
190
312
  components?: string;
313
+ __packageDir?: string;
314
+ __packageExports?: Record<string, unknown> | null;
191
315
  }, name: string): string | null;
192
316
  /**
193
- * Find an integration component's swizzleable source file (`{Name}.tsx`) by
194
- * name within a loaded integration's resolved `components` dir. Returns null
317
+ * Find an integration component's swizzleable source file by name within a
318
+ * loaded integration's resolved `components` dir: the same-stem `{Name}.tsx`
319
+ * of its doc, or, for a family member, the file that declares it. Returns null
195
320
  * when the integration ships docs without source.
196
321
  *
197
- * @param {{components?: string}} integration
322
+ * @param {{name?: string, components?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
198
323
  * @param {string} name bare component name
199
324
  * @returns {string|null}
200
325
  */
201
326
  export function findIntegrationComponentSource(integration: {
327
+ name?: string;
202
328
  components?: string;
329
+ __packageDir?: string;
330
+ __packageExports?: Record<string, unknown> | null;
203
331
  }, name: string): string | null;
332
+ /**
333
+ * The owner rule: an owner that holds a name only because a doc records it
334
+ * (`hold: 'doc'`) yields to Core and to every file-named owner; `--package`
335
+ * still reaches it. Surfaces resolve a replacement first, then this rule, then
336
+ * which docs load.
337
+ *
338
+ * @template {{hold?: string}} T
339
+ * @param {T[]} owners each with its {@link NameHold}; an owner without one
340
+ * counts as Core's or file-named
341
+ * @returns {T[]}
342
+ */
343
+ export function unscopedComponentOwners<T extends {
344
+ hold?: string;
345
+ }>(owners: T[]): T[];
204
346
  /**
205
347
  * Build a flat list of ownership records for ALL discoverable components —
206
348
  * core (built-in) plus every loaded integration. This is the authoritative
@@ -229,3 +371,11 @@ export function discoverOwnedComponents(coreDir: string, loadedIntegrations?: Ar
229
371
  }>;
230
372
  /** The owner package name for built-in (core) components. */
231
373
  export const CORE_PACKAGE: import("../../authoring/index.js").ProviderId;
374
+ /**
375
+ * How an owner holds a component name, which the owner rule
376
+ * ({@link unscopedComponentOwners}) reads: `core` when Core documents it;
377
+ * `file` when an integration doc named after its file is recorded under it;
378
+ * `doc` when only a doc records it: an export name, a member, or the file name
379
+ * of a doc recorded under another export.
380
+ */
381
+ export type NameHold = "core" | "file" | "doc";