@astryxdesign/cli 0.7.8-canary.ffd29c5 → 0.7.9-canary.0200dfe

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 (134) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +1 -1
  3. package/api/component/__fixtures__/resolutions/modules.txt +2 -2
  4. package/api/discover/_adapter.d.mts +1 -1
  5. package/api/docs/_adapter.d.mts +8 -2
  6. package/api/docs/_adapter.mjs +10 -4
  7. package/api/docs/detail/section/section.d.mts +5 -2
  8. package/api/docs/detail/section/section.mjs +6 -2
  9. package/api/docs/docs.mjs +7 -1
  10. package/api/doctor/_adapter.d.mts +6 -2
  11. package/api/doctor/_adapter.mjs +5 -3
  12. package/api/doctor/built-checks.d.mts +9 -4
  13. package/api/doctor/built-checks.mjs +15 -10
  14. package/api/search/_adapter.d.mts +3 -1
  15. package/api/search/_adapter.mjs +12 -2
  16. package/api/search/_candidate-score.d.mts +4 -1
  17. package/api/search/_candidate-score.mjs +46 -28
  18. package/api/search/_gather-components.mjs +5 -0
  19. package/api/search/_gather-templates.mjs +31 -6
  20. package/api/search/_lexical.d.mts +14 -0
  21. package/api/search/_lexical.mjs +4 -0
  22. package/api/search/_main-searcher.mjs +1 -1
  23. package/api/search/_result.d.mts +6 -5
  24. package/api/search/_result.mjs +1 -0
  25. package/api/search/_words.d.mts +44 -7
  26. package/api/search/_words.mjs +113 -21
  27. package/api/search/search.d.mts +4 -2
  28. package/api/search/search.doc.mjs +1 -1
  29. package/api/search/search.mjs +9 -8
  30. package/api/search/search.type.d.mts +4 -0
  31. package/api/search/search.type.mjs +1 -0
  32. package/api/swizzle/_adapter.d.mts +10 -0
  33. package/api/swizzle/_adapter.mjs +24 -1
  34. package/api/swizzle/copy/copy.mjs +9 -4
  35. package/api/theme/build/build.d.mts +26 -1
  36. package/api/theme/build/build.mjs +71 -20
  37. package/api/theme/build/core-interception.d.mts +2 -1
  38. package/api/theme/build/core-interception.mjs +23 -5
  39. package/assets/codemods/registry.mjs +1 -0
  40. package/assets/codemods/transforms/next/index.mjs +1 -11
  41. package/assets/codemods/transforms/v0.7.8/index.mjs +20 -0
  42. package/assets/discover/official-packages.json +4 -0
  43. package/assets/docs/browser-support.doc.mjs +27 -1
  44. package/assets/docs/tree/calendar-systems.doc.mjs +146 -0
  45. package/assets/docs/tree/calendars.doc.mjs +46 -0
  46. package/assets/docs/tree/i18n-calendars.doc.mjs +51 -0
  47. package/assets/docs/tree/internationalization.doc.mjs +3 -3
  48. package/assets/docs/tree/tokens-color.doc.mjs +1 -1
  49. package/assets/templates/blocks/components/Hooks/useClickableContainerHookUsage.doc.mjs +14 -0
  50. package/assets/templates/blocks/components/Hooks/useClickableContainerHookUsage.tsx +67 -0
  51. package/assets/templates/blocks/components/Hooks/useClipboardHookUsage.doc.mjs +14 -0
  52. package/assets/templates/blocks/components/Hooks/useClipboardHookUsage.tsx +35 -0
  53. package/assets/templates/blocks/components/Hooks/useImageModeHookUsage.doc.mjs +14 -0
  54. package/assets/templates/blocks/components/Hooks/useImageModeHookUsage.tsx +55 -0
  55. package/assets/templates/blocks/components/Hooks/useTreeFocusHookUsage.doc.mjs +15 -0
  56. package/assets/templates/blocks/components/Hooks/useTreeFocusHookUsage.tsx +98 -0
  57. package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +19 -0
  58. package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +68 -0
  59. package/assets/templates/blocks/components/InfoTip/InfoTipMetricDefinitions.doc.mjs +14 -0
  60. package/assets/templates/blocks/components/InfoTip/InfoTipMetricDefinitions.tsx +46 -0
  61. package/assets/templates/blocks/components/InfoTip/InfoTipPermissionNotes.doc.mjs +14 -0
  62. package/assets/templates/blocks/components/InfoTip/InfoTipPermissionNotes.tsx +41 -0
  63. package/assets/templates/blocks/components/InfoTip/InfoTipShowcase.doc.mjs +13 -0
  64. package/assets/templates/blocks/components/InfoTip/InfoTipShowcase.tsx +24 -0
  65. package/assets/templates/blocks/components/PowerSearch/PowerSearchContentSearch.tsx +8 -7
  66. package/assets/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.tsx +8 -7
  67. package/assets/templates/blocks/components/PowerSearch/PowerSearchPresetFilters.tsx +8 -7
  68. package/assets/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.tsx +12 -10
  69. package/assets/templates/blocks/components/PowerSearch/PowerSearchShowcase.tsx +8 -7
  70. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.doc.mjs +2 -1
  71. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +2 -2
  72. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +0 -1
  73. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +0 -1
  74. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.doc.mjs +2 -1
  75. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +0 -2
  76. package/assets/templates/pages/table-inbox/page.tsx +11 -8
  77. package/assets/templates/pages/work-item-detail/page.tsx +6 -2
  78. package/assets/theme.template.ts +1 -1
  79. package/authoring/debug/parse.d.mts +2 -2
  80. package/authoring/doctypes/_schema.d.mts +16 -0
  81. package/authoring/doctypes/_schema.mjs +15 -0
  82. package/authoring/doctypes/component/component.doc.mjs +6 -0
  83. package/authoring/doctypes/component/type.ts +16 -0
  84. package/authoring/index.d.ts +1 -0
  85. package/clients/cli/commands/build.mjs +9 -3
  86. package/clients/cli/commands/ensure-core-built.mjs +399 -43
  87. package/clients/cli/commands/search.mjs +8 -2
  88. package/clients/cli/formatters/index.mjs +11 -0
  89. package/clients/cli/index.mjs +11 -6
  90. package/foundation/agent-docs/agent-docs-target.d.mts +49 -0
  91. package/foundation/agent-docs/agent-docs-target.mjs +201 -0
  92. package/foundation/agent-docs/agent-docs.d.mts +1 -38
  93. package/foundation/agent-docs/agent-docs.mjs +16 -181
  94. package/foundation/config/config-path.d.mts +13 -0
  95. package/foundation/config/config-path.mjs +42 -0
  96. package/foundation/config/project.d.mts +1 -10
  97. package/foundation/config/project.mjs +31 -35
  98. package/foundation/discovery/component-discovery.mjs +56 -10
  99. package/foundation/discovery/component-loader.d.mts +1 -1
  100. package/foundation/discovery/icon-set-paths.d.mts +18 -0
  101. package/foundation/discovery/icon-set-paths.mjs +23 -0
  102. package/foundation/discovery/icon-set-writer.d.mts +2 -7
  103. package/foundation/discovery/icon-set-writer.mjs +3 -12
  104. package/foundation/discovery/template-adapter.d.mts +10 -0
  105. package/foundation/discovery/template-adapter.mjs +94 -4
  106. package/foundation/env/search-path.d.mts +12 -0
  107. package/foundation/env/search-path.mjs +71 -43
  108. package/foundation/fs/module-loader.d.mts +2 -8
  109. package/foundation/fs/module-loader.mjs +3 -12
  110. package/foundation/fs/present-files.d.mts +11 -0
  111. package/foundation/fs/present-files.mjs +25 -0
  112. package/foundation/integrations/autolink.d.mts +2 -21
  113. package/foundation/integrations/autolink.mjs +6 -42
  114. package/foundation/integrations/contribution-fixes.mjs +26 -3
  115. package/foundation/integrations/contribution-inventory.mjs +1 -1
  116. package/foundation/integrations/installed-package.d.mts +36 -0
  117. package/foundation/integrations/installed-package.mjs +57 -0
  118. package/foundation/integrations/integrations.d.mts +3 -75
  119. package/foundation/integrations/integrations.mjs +3 -16
  120. package/foundation/integrations/manifest-paths.d.mts +13 -0
  121. package/foundation/integrations/manifest-paths.mjs +31 -0
  122. package/foundation/integrations/manifest-writer.d.mts +3 -4
  123. package/foundation/integrations/manifest-writer.mjs +5 -3
  124. package/foundation/release/cache.d.mts +11 -4
  125. package/foundation/release/cache.mjs +15 -7
  126. package/foundation/response/response-types.doc.mjs +1 -1
  127. package/foundation/runtime/locked-versions.mjs +1 -1
  128. package/foundation/runtime/package-set.mjs +1 -1
  129. package/foundation/text/levenshtein.d.mts +4 -1
  130. package/foundation/text/levenshtein.mjs +44 -1
  131. package/package.json +9 -9
  132. package/api/swizzle/_github.d.mts +0 -8
  133. package/api/swizzle/_github.mjs +0 -22
  134. /package/assets/codemods/transforms/{next → v0.7.8}/promote-tokenizer-presentation.mjs +0 -0
@@ -35,7 +35,8 @@
35
35
 
36
36
  import * as fs from 'node:fs';
37
37
  import * as path from 'node:path';
38
- import {findPresentFiles, loadModuleWithParser} from '../fs/module-loader.mjs';
38
+ import {loadModuleWithParser} from '../fs/module-loader.mjs';
39
+ import {findConfigPath} from './config-path.mjs';
39
40
  import {parseConfig} from '../../authoring/config/parse.mjs';
40
41
  import {
41
42
  loadIntegrations,
@@ -105,6 +106,8 @@ import {
105
106
  configContentHash,
106
107
  } from './config-cache.mjs';
107
108
 
109
+ export {CONFIG_BASENAMES, findConfigPath} from './config-path.mjs';
110
+
108
111
  /**
109
112
  * Extract a human-readable message from an unknown thrown value.
110
113
  * Reproduces the historical `err?.message ?? String(err)` behavior in a
@@ -321,12 +324,6 @@ function readPackageJson(dir) {
321
324
  * @typedef {import('../integrations/issue').AstryxIntegrationIssue & {package: string}} ProjectIntegrationIssue
322
325
  */
323
326
 
324
- /** Conventional config basenames, in load-precedence order. */
325
- export const CONFIG_BASENAMES = [
326
- 'astryx.config.ts',
327
- 'astryx.config.mjs',
328
- 'astryx.config.js',
329
- ];
330
327
 
331
328
  /** Default issue tracker used when neither config nor integration routes one. */
332
329
  export const DEFAULT_ISSUES_URL =
@@ -367,25 +364,6 @@ function inheritsIntegrationDebug(projectDir) {
367
364
  }
368
365
  }
369
366
 
370
- /**
371
- * Find astryx.config.{ts,mjs,js} as a sibling of the nearest package.json.
372
- * Returns the absolute path, or null if none is present. Throws if multiple
373
- * config files exist at that root.
374
- * @param {string} [startDir]
375
- * @returns {string|null}
376
- */
377
- export function findConfigPath(startDir = process.cwd()) {
378
- const root = findPackageRoot(startDir) ?? startDir;
379
- const present = findPresentFiles(root, CONFIG_BASENAMES);
380
- if (present.length > 1) {
381
- throw new Error(
382
- `Multiple Astryx config files found in ${root} (${present
383
- .map(p => path.basename(p))
384
- .join(', ')}). Keep exactly one.`,
385
- );
386
- }
387
- return present.length === 1 ? present[0] : null;
388
- }
389
367
 
390
368
  /**
391
369
  * The provider ledger each loaded Project resolved, kept off the class so it
@@ -405,6 +383,15 @@ export function providerLedgerOf(project) {
405
383
  return PROVIDER_LEDGERS.get(project) ?? new Map();
406
384
  }
407
385
 
386
+ /**
387
+ * True when an integration's templates root exists, the only place its
388
+ * templates come from (discoverIntegrationTemplatesForOne).
389
+ * @param {any} integration
390
+ * @returns {boolean}
391
+ */
392
+ const hasTemplatesRoot = integration =>
393
+ integration?.templates != null && fs.existsSync(integration.templates);
394
+
408
395
  /**
409
396
  * The single API for reading resolved project configuration. Construct via the
410
397
  * async {@link Project.load} factory.
@@ -1281,15 +1268,24 @@ export class Project {
1281
1268
  * @returns {Promise<ProjectIntegrationIssue[]>}
1282
1269
  */
1283
1270
  async issues() {
1284
- // Template replacement validity depends on the combined Core + integration
1285
- // catalog. Resolve it first so issue results never depend on which discovery
1286
- // method the caller happened to invoke earlier.
1287
- await this.templates();
1288
- // Component replacement validity likewise depends on Core plus every
1289
- // integration's components.
1290
- await this.componentReplacements();
1291
- for (const integration of this.#loadedIntegrations) {
1292
- await this.#collectIssues(integration);
1271
+ // Each issue these passes find belongs to an integration, because Core's
1272
+ // templates and components declare no replacement. A project with no
1273
+ // integration skips them.
1274
+ if (this.#loadedIntegrations.length > 0) {
1275
+ // Template replacement validity depends on the combined Core +
1276
+ // integration catalog. Resolve it first so issue results never depend
1277
+ // on which discovery method the caller happened to invoke earlier. Only
1278
+ // an integration's own templates can replace one, so with none, Core's
1279
+ // templates stay unread.
1280
+ if (this.#loadedIntegrations.some(hasTemplatesRoot)) {
1281
+ await this.templates();
1282
+ }
1283
+ // Component replacement validity likewise depends on Core plus every
1284
+ // integration's components.
1285
+ await this.componentReplacements();
1286
+ for (const integration of this.#loadedIntegrations) {
1287
+ await this.#collectIssues(integration);
1288
+ }
1293
1289
  }
1294
1290
  // Return a stable copy so callers can't mutate internal state.
1295
1291
  return this.#issues.map(i => ({...i}));
@@ -11,6 +11,7 @@ import {DOC_EXPORTS} from '../doc-compiler/read.mjs';
11
11
  import {
12
12
  listDir,
13
13
  listDirEntries,
14
+ listingCacheActive,
14
15
  oncePerListing,
15
16
  pathExists,
16
17
  withListingCache,
@@ -511,6 +512,42 @@ export function discoverComponents(coreDir) {
511
512
  return ordered;
512
513
  }
513
514
 
515
+ /**
516
+ * The folders of `srcDir`, in listing order, whose own listing holds one of
517
+ * `names`: the only folders a probe for `<folder>/<name>` can find. Inside an
518
+ * operation each listing is read once, for every name. Outside one, every
519
+ * folder is returned, so each probe reads the disk.
520
+ * @param {string} srcDir
521
+ * @param {fs.Dirent[]} entries `srcDir`'s listing
522
+ * @param {string[]} names
523
+ * @returns {fs.Dirent[]}
524
+ */
525
+ function foldersHolding(srcDir, entries, names) {
526
+ const folders = entries.filter(entry => entry.isDirectory());
527
+ if (!listingCacheActive()) return folders;
528
+ const byName = oncePerListing(`folder-names\0${srcDir}`, () => {
529
+ /** @type {Map<string, Set<string>>} */
530
+ const index = new Map();
531
+ for (const folder of folders) {
532
+ let listed;
533
+ try {
534
+ listed = listDir(path.join(srcDir, folder.name));
535
+ } catch {
536
+ continue;
537
+ }
538
+ for (const name of listed) {
539
+ let holders = index.get(name);
540
+ if (!holders) index.set(name, (holders = new Set()));
541
+ holders.add(folder.name);
542
+ }
543
+ }
544
+ return index;
545
+ });
546
+ return folders.filter(folder =>
547
+ names.some(name => byName.get(name)?.has(folder.name)),
548
+ );
549
+ }
550
+
514
551
  /**
515
552
  * Find the .doc.mjs file for a component.
516
553
  * For sub-components (e.g. StackItem), returns the parent's .doc.mjs
@@ -532,8 +569,7 @@ export function findComponentReadme(coreDir, name) {
532
569
 
533
570
  // Nested match: src/*/{name}/{Name}.doc.mjs or src/*/{name}/Astryx{Name}.doc.mjs
534
571
  const entries = listDirEntries(srcDir);
535
- for (const entry of entries) {
536
- if (!entry.isDirectory()) continue;
572
+ for (const entry of foldersHolding(srcDir, entries, [name])) {
537
573
  const nested = path.join(srcDir, entry.name, name, exactDoc);
538
574
  if (existsCaseExact(nested, srcDir)) return nested;
539
575
  const nestedXds = path.join(srcDir, entry.name, name, xdsDoc);
@@ -541,8 +577,7 @@ export function findComponentReadme(coreDir, name) {
541
577
  }
542
578
 
543
579
  // Per-component doc in a parent directory: src/*/{Name}.doc.mjs or src/*/Astryx{Name}.doc.mjs
544
- for (const entry of entries) {
545
- if (!entry.isDirectory()) continue;
580
+ for (const entry of foldersHolding(srcDir, entries, [exactDoc, xdsDoc])) {
546
581
  const perComp = path.join(srcDir, entry.name, exactDoc);
547
582
  if (existsCaseExact(perComp, srcDir)) return perComp;
548
583
  const perCompXds = path.join(srcDir, entry.name, xdsDoc);
@@ -731,12 +766,7 @@ function caseSpelledComponentSource(srcDir, name) {
731
766
  */
732
767
  export function resolveImportPath(coreDir, componentName) {
733
768
  const srcDir = path.join(coreDir, 'src');
734
- const pkgPath = path.join(coreDir, 'package.json');
735
- const pkg = pathExists(pkgPath)
736
- ? JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
737
- : null;
738
-
739
- const exportKeys = Object.keys(pkg?.exports || {});
769
+ const exportKeys = exportKeysOf(coreDir);
740
770
 
741
771
  // Priority 1: exact subpath export matching the component name (e.g. ./Heading)
742
772
  // This allows convenience re-export directories to win over the source directory.
@@ -764,6 +794,22 @@ export function resolveImportPath(coreDir, componentName) {
764
794
  return '@astryxdesign/core';
765
795
  }
766
796
 
797
+ /**
798
+ * The subpaths the package's `exports` map names, read once per operation:
799
+ * a search resolves the import of every component.
800
+ * @param {string} coreDir
801
+ * @returns {string[]}
802
+ */
803
+ function exportKeysOf(coreDir) {
804
+ const pkgPath = path.join(coreDir, 'package.json');
805
+ return oncePerListing(`export-keys\0${pkgPath}`, () => {
806
+ const pkg = pathExists(pkgPath)
807
+ ? JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
808
+ : null;
809
+ return Object.keys(pkg?.exports || {});
810
+ });
811
+ }
812
+
767
813
  /**
768
814
  * Does a package's `exports` map publish this subpath?
769
815
  *
@@ -43,5 +43,5 @@ export type LoadDocOptions = {
43
43
  * which root reads the doc
44
44
  * (default: components)
45
45
  */
46
- root?: "components" | "hooks" | undefined;
46
+ root?: "hooks" | "components" | undefined;
47
47
  };
@@ -0,0 +1,18 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * @file icon-set-paths.mjs
6
+ * @input A generated icon module's path
7
+ * @output generatedTypesPath: the declaration file beside it
8
+ * @position packages/cli/foundation/discovery: a path helper with no imports,
9
+ * so the contribution inventory reads it without icon-set-writer.mjs and
10
+ * that module's parser and manifest writer. icon-set-writer.mjs re-exports it.
11
+ */
12
+ /**
13
+ * The declaration file beside a generated module (`x.generated.js` →
14
+ * `x.generated.d.ts`, `.mjs` → `.d.mts`); null for a TypeScript module.
15
+ * @param {string} generated
16
+ * @returns {string | null}
17
+ */
18
+ export function generatedTypesPath(generated: string): string | null;
@@ -0,0 +1,23 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file icon-set-paths.mjs
5
+ * @input A generated icon module's path
6
+ * @output generatedTypesPath: the declaration file beside it
7
+ * @position packages/cli/foundation/discovery: a path helper with no imports,
8
+ * so the contribution inventory reads it without icon-set-writer.mjs and
9
+ * that module's parser and manifest writer. icon-set-writer.mjs re-exports it.
10
+ */
11
+
12
+ /**
13
+ * The declaration file beside a generated module (`x.generated.js` →
14
+ * `x.generated.d.ts`, `.mjs` → `.d.mts`); null for a TypeScript module.
15
+ * @param {string} generated
16
+ * @returns {string | null}
17
+ */
18
+ export function generatedTypesPath(generated) {
19
+ if (/\.m?tsx?$/u.test(generated)) return null;
20
+ if (generated.endsWith('.mjs')) return generated.replace(/\.mjs$/u, '.d.mts');
21
+ if (generated.endsWith('.cjs')) return generated.replace(/\.cjs$/u, '.d.cts');
22
+ return generated.replace(/\.jsx?$/u, '.d.ts');
23
+ }
@@ -239,13 +239,6 @@ export function writeDefinitionFile(set: DiscoveredIconSet, doc: {
239
239
  * @param {string} packageDir
240
240
  */
241
241
  export function generatedModulePath(set: DiscoveredIconSet, packageDir: string): string;
242
- /**
243
- * The declaration file beside a generated module (`x.generated.js` →
244
- * `x.generated.d.ts`, `.mjs` → `.d.mts`); null for a TypeScript module.
245
- * @param {string} generated
246
- * @returns {string | null}
247
- */
248
- export function generatedTypesPath(generated: string): string | null;
249
242
  /**
250
243
  * The declaration file's text for a generated module's statements: each
251
244
  * re-export as written, so a component keeps its library's types; each
@@ -452,6 +445,7 @@ export function iconsWithWord(set: {
452
445
  * @returns {string | null}
453
446
  */
454
447
  export function localSourceNote(packageDir: string, module: string): string | null;
448
+ export { generatedTypesPath };
455
449
  /** @typedef {import('./icon-set-discovery.mjs').DiscoveredIconSet} DiscoveredIconSet */
456
450
  /** @typedef {import('../../authoring/doctypes/icon-set/type').IconSetData} IconSetData */
457
451
  /**
@@ -510,3 +504,4 @@ export type GeneratedIcon = {
510
504
  */
511
505
  adapt: boolean;
512
506
  };
507
+ import { generatedTypesPath } from './icon-set-paths.mjs';
@@ -33,6 +33,9 @@ import {findLocalIntegrationManifestOrNull} from '../integrations/manifest-write
33
33
  import {loadManifestObject} from '../integrations/integrations.mjs';
34
34
  import {levenshteinDistance} from '../text/string-utils.mjs';
35
35
  import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
36
+ import {generatedTypesPath} from './icon-set-paths.mjs';
37
+
38
+ export {generatedTypesPath};
36
39
  import {
37
40
  discoverIconSetDirectory,
38
41
  NOTICE_FILE_RE,
@@ -988,18 +991,6 @@ export function generatedModulePath(set, packageDir) {
988
991
  const THEME_ELEMENT_PROPS =
989
992
  "{'aria-hidden': true, 'width': '1em', 'height': '1em'}";
990
993
 
991
- /**
992
- * The declaration file beside a generated module (`x.generated.js` →
993
- * `x.generated.d.ts`, `.mjs` → `.d.mts`); null for a TypeScript module.
994
- * @param {string} generated
995
- * @returns {string | null}
996
- */
997
- export function generatedTypesPath(generated) {
998
- if (/\.m?tsx?$/u.test(generated)) return null;
999
- if (generated.endsWith('.mjs')) return generated.replace(/\.mjs$/u, '.d.mts');
1000
- if (generated.endsWith('.cjs')) return generated.replace(/\.cjs$/u, '.d.cts');
1001
- return generated.replace(/\.jsx?$/u, '.d.ts');
1002
- }
1003
994
 
1004
995
  /**
1005
996
  * The declaration file's text for a generated module's statements: each
@@ -239,6 +239,16 @@ export function extractComponents(pagePath: string): string[];
239
239
  * @returns {string[]}
240
240
  */
241
241
  export function componentsInSource(src: string): string[];
242
+ /**
243
+ * Every name componentsInSource can return for `src`, read without parsing
244
+ * it, or null when it cannot be bounded so. It keeps the tag names a parse
245
+ * would drop as page-local. It adds each name an `imported as local` pair
246
+ * makes a tag stand for, wherever that text appears. An escaped name in an
247
+ * identifier or a string defeats the reading, so then it is null.
248
+ * @param {string} src
249
+ * @returns {string[] | null}
250
+ */
251
+ export function componentNameBound(src: string): string[] | null;
242
252
  /**
243
253
  * A video placeholder that names itself in the source, for a copy that has no
244
254
  * response to disclose the replacement in, such as the shadcn install. It is a
@@ -1976,6 +1976,41 @@ export async function findShowcase(componentName, cwd, options) {
1976
1976
  /** The npm scope of every Astryx package. */
1977
1977
  const ASTRYX_PACKAGE_SCOPE = '@astryxdesign/';
1978
1978
 
1979
+ /** A JSX opening tag; componentsInSource says why the pattern looks so. */
1980
+ const JSX_TAG = /(?<![\w$.])<(XDS)?([A-Z]\w+)/g;
1981
+
1982
+ /** Comments and line breaks that may sit between two words of an import. */
1983
+ // A block comment ends at its first `*/`, and a line comment at its line's
1984
+ // end. So each comment has one reading, and a failed match cannot backtrack
1985
+ // through every split of a comment run.
1986
+ const SPACE_OR_COMMENT = String.raw`\s|\/\*(?:[^*]|\*(?!\/))*\*\/|\/\/[^\n\r\u2028\u2029]*(?![^\n\r\u2028\u2029])`;
1987
+ const BETWEEN = `(?:${SPACE_OR_COMMENT})*`;
1988
+ const GAP = new RegExp(`(?:${SPACE_OR_COMMENT})+`, 'g');
1989
+ // The pair scan can start again at each word of a run of spaces and
1990
+ // comments, so a run costs up to its length squared. The longest run in the
1991
+ // bundled templates is about 10 KB.
1992
+ const MAX_GAP = 16 * 1024;
1993
+
1994
+ /**
1995
+ * One `imported as local` pair. The imported name is an identifier (group 1)
1996
+ * or a string (group 3); the local name is group 4.
1997
+ */
1998
+ const ALIAS = new RegExp(
1999
+ String.raw`(?:(?<![\p{ID_Continue}$])([\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*)|(['"])((?:\\[\s\S]|(?!\2)[^\\\n])*)\2)` +
2000
+ BETWEEN +
2001
+ String.raw`\bas\b` +
2002
+ BETWEEN +
2003
+ String.raw`([\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*)`,
2004
+ 'gu',
2005
+ );
2006
+ // What follows each `as`: the pair scan reads the same text after its `as`.
2007
+ const AS_LOCAL = new RegExp(
2008
+ String.raw`\bas\b` +
2009
+ BETWEEN +
2010
+ String.raw`([\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*)`,
2011
+ 'gu',
2012
+ );
2013
+
1979
2014
  const UBIQUITOUS = new Set([
1980
2015
  'Text',
1981
2016
  'Heading',
@@ -2079,7 +2114,7 @@ export function componentsInSource(src) {
2079
2114
  // and `Record<string, Phase>` no longer do. Those were being indexed as
2080
2115
  // rendered components, putting type names like `Record`, `SVGProps` and
2081
2116
  // `ReadonlySet` into template keyword and "components used" output.
2082
- const tagRegex = /(?<![\w$.])<(XDS)?([A-Z]\w+)/g;
2117
+ const tagRegex = new RegExp(JSX_TAG);
2083
2118
  /** @type {string[]} */
2084
2119
  const matches = [];
2085
2120
  let m;
@@ -2093,11 +2128,23 @@ export function componentsInSource(src) {
2093
2128
  // strings and type annotations cannot add or hide a name.
2094
2129
  const {declared: localDeclNames, astryxImports} = topLevelBindings(src);
2095
2130
 
2131
+ return catalogNames(
2132
+ matches
2133
+ .filter(n => !localDeclNames.has(n))
2134
+ .map(n => astryxImports.get(n) ?? n),
2135
+ );
2136
+ }
2137
+
2138
+ /**
2139
+ * Rendered component names as the catalog lists them: without theme wrappers
2140
+ * and ubiquitous parts, each part suffix stripped, each name once, sorted.
2141
+ * @param {string[]} names
2142
+ * @returns {string[]}
2143
+ */
2144
+ function catalogNames(names) {
2096
2145
  return [
2097
2146
  ...new Set(
2098
- matches
2099
- .filter(n => !localDeclNames.has(n))
2100
- .map(n => astryxImports.get(n) ?? n)
2147
+ names
2101
2148
  .filter(n => !['Theme', 'ThemeProvider'].includes(n))
2102
2149
  .filter(n => !UBIQUITOUS.has(n))
2103
2150
  .map(n =>
@@ -2112,3 +2159,46 @@ export function componentsInSource(src) {
2112
2159
  ),
2113
2160
  ].sort();
2114
2161
  }
2162
+
2163
+ /**
2164
+ * Every name componentsInSource can return for `src`, read without parsing
2165
+ * it, or null when it cannot be bounded so. It keeps the tag names a parse
2166
+ * would drop as page-local. It adds each name an `imported as local` pair
2167
+ * makes a tag stand for, wherever that text appears. An escaped name in an
2168
+ * identifier or a string defeats the reading, so then it is null.
2169
+ * @param {string} src
2170
+ * @returns {string[] | null}
2171
+ */
2172
+ export function componentNameBound(src) {
2173
+ if (src.includes('\\u')) return null;
2174
+ for (const gap of src.matchAll(GAP)) {
2175
+ if (gap[0].length > MAX_GAP) return null;
2176
+ }
2177
+ const tags = Array.from(src.matchAll(JSX_TAG), m => m[2]);
2178
+ const local = new Set(tags);
2179
+ // A pair adds a name only when its local name is a tag. Most sources have
2180
+ // no `as` before a tag's name, so they skip the slower pair scan. Each
2181
+ // match restarts one character on: a `/*` in a comment can hide a pair.
2182
+ const asLocal = new RegExp(AS_LOCAL);
2183
+ let pairs = false;
2184
+ for (let m = asLocal.exec(src); m && !pairs; m = asLocal.exec(src)) {
2185
+ asLocal.lastIndex = m.index + 1;
2186
+ pairs = local.has(m[1]);
2187
+ }
2188
+ if (!pairs) return catalogNames(tags);
2189
+ /** @type {string[]} */
2190
+ const imported = [];
2191
+ // Each match restarts one character on, so no pair hides inside another.
2192
+ const alias = new RegExp(ALIAS);
2193
+ for (let m = alias.exec(src); m; m = alias.exec(src)) {
2194
+ // Step one code point: a `u` regex moves an index inside a surrogate
2195
+ // pair back to the pair's start.
2196
+ alias.lastIndex =
2197
+ m.index + ((src.codePointAt(m.index) ?? 0) > 0xffff ? 2 : 1);
2198
+ if (!local.has(m[4])) continue;
2199
+ const name = m[1] ?? m[3];
2200
+ if (name.includes('\\')) return null;
2201
+ imported.push(name);
2202
+ }
2203
+ return catalogNames([...tags, ...imported]);
2204
+ }
@@ -7,6 +7,18 @@
7
7
  * @returns {string | null}
8
8
  */
9
9
  export function astryxCliRootOf(file: string): string | null;
10
+ /**
11
+ * The executable files on the search path named one of `names`, in the order
12
+ * a shell tries them. In each folder, it takes the first name that is a file
13
+ * this user may run. Nothing is started.
14
+ * @param {readonly string[]} names
15
+ * @param {{searchPath?: string, platform?: NodeJS.Platform}} [options]
16
+ * @returns {string[]}
17
+ */
18
+ export function executablesOnSearchPath(names: readonly string[], { searchPath, platform, }?: {
19
+ searchPath?: string;
20
+ platform?: NodeJS.Platform;
21
+ }): string[];
10
22
  /**
11
23
  * Every `astryx` command on the search path, in the order a shell tries
12
24
  * them. The first row is the one that runs.
@@ -13,9 +13,10 @@
13
13
  * package folder is read from the shim's text.
14
14
  *
15
15
  * @input the search path and, on Windows, its executable names
16
- * @output one row per `astryx` command found
17
- * @position packages/cli/foundation/env — read by doctor, init --user, and
18
- * the update notices.
16
+ * @output one row per `astryx` command found, and the executable files that
17
+ * any command name finds there
18
+ * @position packages/cli/foundation/env — read by doctor, init --user, the
19
+ * update notices, and swizzle's `gh` lookup.
19
20
  */
20
21
 
21
22
  import * as fs from 'node:fs';
@@ -146,6 +147,53 @@ function namesCliPackage(file) {
146
147
  }
147
148
  }
148
149
 
150
+ /**
151
+ * Whether `file` is a file this user may run. On Windows, any file counts.
152
+ * @param {string} file
153
+ * @param {boolean} windows
154
+ * @returns {boolean}
155
+ */
156
+ function isRunnableFile(file, windows) {
157
+ try {
158
+ if (!fs.statSync(file).isFile()) return false;
159
+ if (!windows) fs.accessSync(file, fs.constants.X_OK);
160
+ return true;
161
+ } catch {
162
+ // The shell skips a candidate the system cannot read: a missing folder, a
163
+ // stale mount, a symlink loop. `which` and execvp read PATH the same way.
164
+ return false;
165
+ }
166
+ }
167
+
168
+ /**
169
+ * The executable files on the search path named one of `names`, in the order
170
+ * a shell tries them. In each folder, it takes the first name that is a file
171
+ * this user may run. Nothing is started.
172
+ * @param {readonly string[]} names
173
+ * @param {{searchPath?: string, platform?: NodeJS.Platform}} [options]
174
+ * @returns {string[]}
175
+ */
176
+ export function executablesOnSearchPath(
177
+ names,
178
+ {
179
+ searchPath = process.env.PATH ?? process.env.Path ?? '',
180
+ platform = process.platform,
181
+ } = {},
182
+ ) {
183
+ const windows = platform === 'win32';
184
+ /** @type {string[]} */
185
+ const files = [];
186
+ for (const dir of searchPath.split(windows ? ';' : path.delimiter)) {
187
+ if (!dir) continue;
188
+ // One command per folder: the shell runs the first name it finds.
189
+ const file = names
190
+ .map(name => path.join(dir, name))
191
+ .find(candidate => isRunnableFile(candidate, windows));
192
+ if (file !== undefined) files.push(file);
193
+ }
194
+ return files;
195
+ }
196
+
149
197
  /**
150
198
  * Every `astryx` command on the search path, in the order a shell tries
151
199
  * them. The first row is the one that runs.
@@ -156,50 +204,30 @@ export function astryxCommandsOnSearchPath({
156
204
  searchPath = process.env.PATH ?? process.env.Path ?? '',
157
205
  platform = process.platform,
158
206
  } = {}) {
159
- const windows = platform === 'win32';
160
- const names = windows
161
- ? ['astryx.cmd', 'astryx.exe', 'astryx.ps1', 'astryx']
162
- : [COMMAND];
207
+ const names =
208
+ platform === 'win32'
209
+ ? ['astryx.cmd', 'astryx.exe', 'astryx.ps1', 'astryx']
210
+ : [COMMAND];
163
211
  /** @type {SearchPathCommand[]} */
164
212
  const rows = [];
165
213
  const seen = new Set();
166
- for (const dir of searchPath.split(windows ? ';' : path.delimiter)) {
167
- if (!dir) continue;
168
- for (const name of names) {
169
- const file = path.join(dir, name);
170
- let stat;
171
- try {
172
- stat = fs.statSync(file);
173
- } catch {
174
- continue;
175
- }
176
- if (!stat.isFile()) continue;
177
- if (!windows) {
178
- try {
179
- fs.accessSync(file, fs.constants.X_OK);
180
- } catch {
181
- continue;
182
- }
183
- }
184
- let key = file;
185
- try {
186
- key = fs.realpathSync(file);
187
- } catch {
188
- // Keep the path as found.
189
- }
190
- if (seen.has(key)) break;
191
- seen.add(key);
192
- const cliRoot = astryxCliRootOf(file);
193
- rows.push({
194
- file,
195
- astryx: cliRoot !== null || namesCliPackage(file),
196
- cliRoot,
197
- version: cliRoot ? cliVersionAt(cliRoot) : null,
198
- handsOff: cliRoot ? handsOffAt(cliRoot) : null,
199
- });
200
- // One command per folder: the shell runs the first name it finds.
201
- break;
214
+ for (const file of executablesOnSearchPath(names, {searchPath, platform})) {
215
+ let key = file;
216
+ try {
217
+ key = fs.realpathSync(file);
218
+ } catch {
219
+ // Keep the path as found.
202
220
  }
221
+ if (seen.has(key)) continue;
222
+ seen.add(key);
223
+ const cliRoot = astryxCliRootOf(file);
224
+ rows.push({
225
+ file,
226
+ astryx: cliRoot !== null || namesCliPackage(file),
227
+ cliRoot,
228
+ version: cliRoot ? cliVersionAt(cliRoot) : null,
229
+ handsOff: cliRoot ? handsOffAt(cliRoot) : null,
230
+ });
203
231
  }
204
232
  return rows;
205
233
  }
@@ -29,14 +29,6 @@ export function importUserModule(file: string, { fresh }?: {
29
29
  * @returns {Promise<Record<string, unknown>>}
30
30
  */
31
31
  export function importThemeArtifact(specifier: string, cwd: string): Promise<Record<string, unknown>>;
32
- /**
33
- * Return the conventional files (by basename, in the given precedence order)
34
- * that exist directly in `dir`, as absolute paths. Never throws.
35
- * @param {string} dir
36
- * @param {string[]} basenames precedence-ordered
37
- * @returns {string[]} absolute paths of present files, in basenames order
38
- */
39
- export function findPresentFiles(dir: string, basenames: string[]): string[];
40
32
  /**
41
33
  * Import a user-authored module, take its default export, and validate it
42
34
  * through an authoring parser. This is the single load/validation boundary for
@@ -57,3 +49,5 @@ export function loadModuleWithParser<T>(file: string, parse: (input: unknown, la
57
49
  label?: string;
58
50
  fresh?: boolean;
59
51
  }): Promise<T>;
52
+ export { findPresentFiles };
53
+ import { findPresentFiles } from './present-files.mjs';
@@ -25,6 +25,9 @@ import {createRequire} from 'node:module';
25
25
  import {pathToFileURL} from 'node:url';
26
26
  import * as fs from 'node:fs';
27
27
  import {createJiti} from 'jiti';
28
+ import {findPresentFiles} from './present-files.mjs';
29
+
30
+ export {findPresentFiles};
28
31
 
29
32
  /** @type {ReturnType<typeof createJiti> | undefined} */
30
33
  let jitiInstance;
@@ -275,18 +278,6 @@ async function importModule(file, fresh) {
275
278
  return await import(url.href);
276
279
  }
277
280
 
278
- /**
279
- * Return the conventional files (by basename, in the given precedence order)
280
- * that exist directly in `dir`, as absolute paths. Never throws.
281
- * @param {string} dir
282
- * @param {string[]} basenames precedence-ordered
283
- * @returns {string[]} absolute paths of present files, in basenames order
284
- */
285
- export function findPresentFiles(dir, basenames) {
286
- return basenames
287
- .filter(name => fs.existsSync(path.join(dir, name)))
288
- .map(name => path.join(dir, name));
289
- }
290
281
 
291
282
  /**
292
283
  * Import a user-authored module, take its default export, and validate it