@astryxdesign/cli 0.7.2 → 0.7.3-canary.06872b4

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 (212) hide show
  1. package/README.md +99 -66
  2. package/api/build/_adapter.d.mts +58 -0
  3. package/api/build/_adapter.mjs +115 -3
  4. package/api/build/blocks/blocks.d.mts +42 -0
  5. package/api/build/blocks/blocks.mjs +169 -0
  6. package/api/build/blocks/blocks.test.mjs +108 -0
  7. package/api/build/blocks/blocks.weights.json +1 -0
  8. package/api/build/build.mjs +25 -6
  9. package/api/build/kit/answer.d.mts +14 -0
  10. package/api/build/kit/answer.mjs +85 -0
  11. package/api/build/kit/answer.test.mjs +38 -0
  12. package/api/build/kit/kind.d.mts +25 -0
  13. package/api/build/kit/kind.mjs +170 -0
  14. package/api/build/kit/kit.d.mts +2 -4
  15. package/api/build/kit/kit.mjs +8 -398
  16. package/api/build/kit/rank.d.mts +3 -32
  17. package/api/build/kit/rank.mjs +25 -342
  18. package/api/build/kit/rank.test.mjs +2 -1
  19. package/api/build/kit/signals.d.mts +60 -0
  20. package/api/build/kit/signals.mjs +284 -0
  21. package/api/build/kit/start.d.mts +32 -0
  22. package/api/build/kit/start.mjs +163 -0
  23. package/api/build/kit/words.d.mts +72 -0
  24. package/api/build/kit/words.mjs +202 -0
  25. package/api/build/tree.d.mts +20 -0
  26. package/api/build/tree.mjs +52 -0
  27. package/api/build/tree.test.mjs +177 -0
  28. package/api/build/tree.weights.json +1 -0
  29. package/api/component/component.mjs +16 -2
  30. package/api/component/component.test.mjs +15 -0
  31. package/api/discover/_adapter.mjs +36 -9
  32. package/api/discover/_adapter.test.mjs +42 -0
  33. package/api/docs/_adapter.mjs +17 -5
  34. package/api/docs/docs.test.mjs +7 -1
  35. package/api/doctor/doctor.mjs +86 -12
  36. package/api/doctor/doctor.test.mjs +28 -3
  37. package/api/init/init.doc.mjs +20 -6
  38. package/api/init/init.test.mjs +18 -2
  39. package/api/init/init.type.d.mts +3 -3
  40. package/api/init/init.type.mjs +3 -3
  41. package/api/init/remove/remove.mjs +17 -4
  42. package/api/init/remove/remove.test.mjs +114 -2
  43. package/api/init/run/run.mjs +69 -6
  44. package/api/integration/authoring-checks.mjs +83 -9
  45. package/api/integration/pack-check.mjs +123 -4
  46. package/api/integration/pack-check.test.mjs +87 -0
  47. package/api/integration/validate-integration-case-disk.test.mjs +111 -0
  48. package/api/integration/validate-integration-gaps.test.mjs +1964 -0
  49. package/api/integration/validate-integration.d.mts +11 -2
  50. package/api/integration/validate-integration.mjs +226 -32
  51. package/api/integration/validate-integration.type.d.mts +58 -1
  52. package/api/integration/validate-integration.type.mjs +45 -2
  53. package/api/integration/validateIntegration.doc.mjs +1 -1
  54. package/api/search/ORDERING.md +28 -0
  55. package/api/search/_adapter.d.mts +66 -2
  56. package/api/search/_adapter.mjs +118 -10
  57. package/api/search/_candidate-score.d.mts +40 -0
  58. package/api/search/_candidate-score.mjs +238 -0
  59. package/api/search/_cards.json +6098 -0
  60. package/api/search/_compound.d.mts +50 -0
  61. package/api/search/_compound.mjs +170 -0
  62. package/api/search/_doc-searcher.d.mts +4 -0
  63. package/api/search/_doc-searcher.mjs +23 -0
  64. package/api/search/_doc-searcher.test.mjs +36 -0
  65. package/api/search/_doc-searcher.weights.json +1 -0
  66. package/api/search/_doc-text.d.mts +30 -0
  67. package/api/search/_doc-text.mjs +87 -0
  68. package/api/search/_entries.d.mts +52 -0
  69. package/api/search/_entries.mjs +158 -0
  70. package/api/search/_features.d.mts +35 -0
  71. package/api/search/_features.mjs +155 -0
  72. package/api/search/_gather-components.d.mts +26 -0
  73. package/api/search/_gather-components.mjs +284 -0
  74. package/api/search/_gather-docs.d.mts +20 -0
  75. package/api/search/_gather-docs.mjs +254 -0
  76. package/api/search/_gather-hooks.d.mts +12 -0
  77. package/api/search/_gather-hooks.mjs +52 -0
  78. package/api/search/_gather-templates.d.mts +25 -0
  79. package/api/search/_gather-templates.mjs +107 -0
  80. package/api/search/_lexical.d.mts +135 -0
  81. package/api/search/_lexical.mjs +351 -0
  82. package/api/search/_main-searcher.d.mts +19 -0
  83. package/api/search/_main-searcher.mjs +115 -0
  84. package/api/search/_main-searcher.test.mjs +106 -0
  85. package/api/search/_main-searcher.weights.json +1 -0
  86. package/api/search/_module-doc.d.mts +32 -0
  87. package/api/search/_module-doc.mjs +78 -0
  88. package/api/search/_order.d.mts +32 -0
  89. package/api/search/_order.mjs +162 -0
  90. package/api/search/_order.test.mjs +72 -0
  91. package/api/search/_priority.d.mts +50 -0
  92. package/api/search/_priority.mjs +139 -0
  93. package/api/search/_query-words.d.mts +25 -0
  94. package/api/search/_query-words.mjs +92 -0
  95. package/api/search/_query.d.mts +65 -0
  96. package/api/search/_query.mjs +176 -0
  97. package/api/search/_result.d.mts +97 -0
  98. package/api/search/_result.mjs +150 -0
  99. package/api/search/_score.d.mts +60 -0
  100. package/api/search/_score.mjs +283 -0
  101. package/api/search/_synonyms.d.mts +21 -0
  102. package/api/search/_synonyms.mjs +67 -0
  103. package/api/search/_template-searcher.d.mts +4 -0
  104. package/api/search/_template-searcher.mjs +23 -0
  105. package/api/search/_template-searcher.test.mjs +40 -0
  106. package/api/search/_template-searcher.weights.json +1 -0
  107. package/api/search/_titles.d.mts +33 -0
  108. package/api/search/_titles.mjs +65 -0
  109. package/api/search/_words.d.mts +64 -0
  110. package/api/search/_words.mjs +157 -0
  111. package/api/search/search.d.mts +22 -305
  112. package/api/search/search.doc.mjs +7 -5
  113. package/api/search/search.mjs +53 -2483
  114. package/api/search/search.type.d.mts +6 -1
  115. package/api/search/search.type.mjs +6 -1
  116. package/api/search/tree.d.mts +15 -0
  117. package/api/search/tree.mjs +40 -0
  118. package/api/search/tree.test.mjs +66 -0
  119. package/api/search/tree.weights.json +1 -0
  120. package/api/theme/build/build.packed-old-core.test.mjs +1 -0
  121. package/api/upgrade/_adapter.d.mts +57 -9
  122. package/api/upgrade/_adapter.mjs +198 -28
  123. package/api/upgrade/registry/registry.d.mts +10 -4
  124. package/api/upgrade/registry/registry.mjs +33 -16
  125. package/api/upgrade/registry/registry.test.mjs +85 -0
  126. package/api/upgrade/run/run.d.mts +4 -2
  127. package/api/upgrade/run/run.mjs +13 -2
  128. package/api/upgrade/run/run.test.mjs +417 -3
  129. package/api/upgrade/upgrade.doc.mjs +10 -5
  130. package/api/upgrade/upgrade.mjs +13 -2
  131. package/api/upgrade/upgrade.test.mjs +194 -0
  132. package/api/upgrade/upgrade.type.d.mts +5 -3
  133. package/api/upgrade/upgrade.type.mjs +8 -6
  134. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +11 -0
  135. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +3 -3
  136. package/assets/docs/is-my-code-good.doc.mjs +287 -0
  137. package/assets/docs/tree/api.doc.mjs +6 -0
  138. package/assets/docs/tree/host-entry.doc.mjs +128 -0
  139. package/assets/docs/tree/template-grading-rubric.doc.mjs +16 -37
  140. package/assets/docs/tree/tokens-data.doc.mjs +2 -2
  141. package/assets/docs/working-with-ai.doc.mjs +6 -2
  142. package/assets/templates/themes/butter/butterTheme.ts +4 -2
  143. package/assets/templates/themes/stone/stoneTheme.ts +4 -2
  144. package/assets/templates/themes/y2k/y2kTheme.ts +4 -2
  145. package/authoring/debug/parse.d.mts +1 -1
  146. package/clients/cli/bin/astryx.mjs +7 -78
  147. package/clients/cli/commands/doctor.mjs +30 -0
  148. package/clients/cli/commands/doctor.test.mjs +65 -0
  149. package/clients/cli/commands/init.behavior.test.mjs +230 -1
  150. package/clients/cli/commands/init.doc.mjs +28 -9
  151. package/clients/cli/commands/init.flag-help.test.mjs +1 -0
  152. package/clients/cli/commands/init.mjs +2 -2
  153. package/clients/cli/commands/outside-project.test.mjs +2 -1
  154. package/clients/cli/commands/setup-nudge.test.mjs +61 -0
  155. package/clients/cli/commands/upgrade.doc.mjs +4 -2
  156. package/clients/cli/commands/upgrade.mjs +9 -2
  157. package/clients/cli/commands/upgrade.subfolder-path.test.mjs +97 -0
  158. package/clients/cli/index.mjs +19 -1
  159. package/clients/cli/run.mjs +108 -0
  160. package/foundation/agent-docs/agent-doc-state.d.mts +20 -7
  161. package/foundation/agent-docs/agent-doc-state.mjs +35 -8
  162. package/foundation/agent-docs/agent-docs.d.mts +100 -12
  163. package/foundation/agent-docs/agent-docs.mjs +1010 -99
  164. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +1239 -17
  165. package/foundation/agent-docs/agent-docs.test.mjs +678 -35
  166. package/foundation/config/project.mjs +20 -22
  167. package/foundation/config/project.test.mjs +56 -0
  168. package/foundation/discovery/component-discovery.d.mts +37 -0
  169. package/foundation/discovery/component-discovery.mjs +80 -5
  170. package/foundation/discovery/component-loader.d.mts +1 -1
  171. package/foundation/discovery/docs-discovery.mjs +14 -1
  172. package/foundation/discovery/module-exports.d.mts +41 -0
  173. package/foundation/discovery/module-exports.mjs +253 -0
  174. package/foundation/discovery/template-adapter.mjs +18 -1
  175. package/foundation/discovery/template-needs.mjs +1 -44
  176. package/foundation/discovery/theme-discovery.mjs +147 -3
  177. package/foundation/doc-compiler/doc-loads.test.mjs +8 -0
  178. package/foundation/doc-compiler/read.mjs +59 -1
  179. package/foundation/doc-compiler/read.test.mjs +11 -2
  180. package/foundation/fs/paths.d.mts +70 -8
  181. package/foundation/fs/paths.mjs +556 -38
  182. package/foundation/fs/paths.test.mjs +430 -54
  183. package/foundation/integrations/autolink.d.mts +2 -1
  184. package/foundation/integrations/autolink.mjs +4 -13
  185. package/foundation/integrations/computer-integrations.d.mts +6 -3
  186. package/foundation/integrations/computer-integrations.mjs +38 -9
  187. package/foundation/integrations/contribution-inventory.d.mts +15 -20
  188. package/foundation/integrations/contribution-inventory.mjs +41 -5
  189. package/foundation/integrations/integrations.d.mts +27 -1
  190. package/foundation/integrations/integrations.mjs +61 -2
  191. package/foundation/integrations/validate-contributions.d.mts +115 -0
  192. package/foundation/integrations/validate-contributions.mjs +1168 -13
  193. package/foundation/release/handoff.d.mts +23 -4
  194. package/foundation/release/handoff.mjs +175 -8
  195. package/foundation/release/run-context.mjs +14 -0
  196. package/foundation/response/response-types.doc.mjs +1 -1
  197. package/foundation/route/route.d.mts +285 -0
  198. package/foundation/route/route.mjs +324 -0
  199. package/foundation/route/route.test.mjs +153 -0
  200. package/foundation/runtime/hosted-runtime.test.mjs +403 -0
  201. package/foundation/runtime/locked-versions.d.mts +32 -0
  202. package/foundation/runtime/locked-versions.mjs +65 -0
  203. package/foundation/runtime/package-root.d.mts +91 -0
  204. package/foundation/runtime/package-root.mjs +174 -0
  205. package/foundation/runtime/package-set.d.mts +62 -0
  206. package/foundation/runtime/package-set.mjs +130 -0
  207. package/foundation/runtime/package-set.test.mjs +432 -0
  208. package/host/door-conformance.test.mjs +274 -0
  209. package/host/index.d.ts +116 -0
  210. package/host/index.mjs +295 -0
  211. package/host/index.test.mjs +302 -0
  212. package/package.json +14 -9
@@ -40,7 +40,7 @@ import {parseConfig} from '../../authoring/config/parse.mjs';
40
40
  import {
41
41
  loadIntegrations,
42
42
  loadLocalIntegration,
43
- resolvePackageDir,
43
+ resolveInstalledIntegrationDir,
44
44
  } from '../integrations/integrations.mjs';
45
45
  import {loadAutolinkCandidates} from '../integrations/autolink.mjs';
46
46
  import {
@@ -65,7 +65,7 @@ import {
65
65
  discoverValidIntegrationComponents,
66
66
  } from '../discovery/component-discovery.mjs';
67
67
  import {resolveComponentReplacements} from '../discovery/component-replacement.mjs';
68
- import {CLI_ROOT, findCoreDir, findProjectCoreDir} from '../fs/paths.mjs';
68
+ import {CLI_ROOT, findCoreDir, findPackageRoot, findProjectCoreDir} from '../fs/paths.mjs';
69
69
  import {
70
70
  applyTemplateReplacements,
71
71
  effectiveTemplateDiscovery,
@@ -89,6 +89,10 @@ import {
89
89
  } from '../../assets/codemods/integration-discovery.mjs';
90
90
  import {validateLoadedIntegration} from '../integrations/validate-contributions.mjs';
91
91
  import {recordDeclaredCliCommands} from '../env/cli-command.mjs';
92
+ import {
93
+ hostedRun,
94
+ recordResolvedIntegrations,
95
+ } from '../runtime/package-root.mjs';
92
96
  import {
93
97
  InMemoryConfigCache,
94
98
  cacheKey,
@@ -121,9 +125,16 @@ function errorMessage(err) {
121
125
  */
122
126
  export function computerIntegrationCandidates(cwd = process.cwd()) {
123
127
  try {
124
- const cliRoot = isOutsideProject(cwd) ? CLI_ROOT : globalCliRoot(cwd);
128
+ const outside = isOutsideProject(cwd);
129
+ const cliRoot = outside ? CLI_ROOT : globalCliRoot(cwd);
125
130
  return cliRoot
126
- ? scanComputerIntegrations({cliRoot, release: cliVersion()})
131
+ ? scanComputerIntegrations({
132
+ cliRoot,
133
+ release: cliVersion(),
134
+ // Outside a project, the integrations a host approves load from the
135
+ // package set that serves the run too (cli-surface INV30).
136
+ approved: outside ? (hostedRun()?.integrations ?? []) : [],
137
+ })
127
138
  : [];
128
139
  } catch {
129
140
  return [];
@@ -212,7 +223,7 @@ async function loadConfiguredIntegrations(specs, {cwd, fresh}) {
212
223
  /** @type {string|undefined} */
213
224
  let packageDir;
214
225
  try {
215
- packageDir = resolvePackageDir(spec, cwd);
226
+ packageDir = resolveInstalledIntegrationDir(spec, cwd);
216
227
  } catch {
217
228
  // Not a bare package name: there is no install location to record.
218
229
  }
@@ -315,22 +326,6 @@ export const CONFIG_BASENAMES = [
315
326
  export const DEFAULT_ISSUES_URL =
316
327
  'https://github.com/facebook/astryx/issues/new';
317
328
 
318
- /**
319
- * Find the directory of the nearest package.json walking up from startDir.
320
- * @param {string} startDir
321
- * @returns {string|null}
322
- */
323
- function findPackageRoot(startDir) {
324
- let dir = startDir;
325
- for (let i = 0; i < 50; i++) {
326
- if (fs.existsSync(path.join(dir, 'package.json'))) return dir;
327
- const parent = path.dirname(dir);
328
- if (parent === dir) break;
329
- dir = parent;
330
- }
331
- return null;
332
- }
333
-
334
329
  /**
335
330
  * Whether this project accepts `debug` handlers contributed by the
336
331
  * integrations it loads.
@@ -495,7 +490,8 @@ export class Project {
495
490
  // The project root: the config's directory when there is one (findConfigPath
496
491
  // resolves the config as a sibling of the nearest package.json, so the two
497
492
  // agree), otherwise that package.json's directory. Dependencies are declared
498
- // there, and node_modules sits there.
493
+ // there, and installed packages resolve from there up the node_modules
494
+ // chain.
499
495
  const projectDir = configPath
500
496
  ? path.dirname(configPath)
501
497
  : (findPackageRoot(cwd) ?? cwd);
@@ -580,6 +576,8 @@ export class Project {
580
576
  : []),
581
577
  ]);
582
578
  loadedIntegrations = resolution.integrations;
579
+ // A hosted run returns each package it resolved (cli-surface INV30).
580
+ recordResolvedIntegrations(loadedIntegrations);
583
581
  // The picker (getCliInvocation) is synchronous, so the commands these
584
582
  // integrations declare are recorded here, where they become known.
585
583
  recordDeclaredCliCommands(projectDir, loadedIntegrations);
@@ -291,6 +291,32 @@ describe('Project.load', () => {
291
291
  });
292
292
  });
293
293
 
294
+ describe('Project.issues and a near-miss manifest key', () => {
295
+ it.each([
296
+ [
297
+ 'alone, while the loaded integration fills providerId from the package name',
298
+ {providerID: '@acme/widgets'},
299
+ 'Fix: rename "providerID" to "providerId" in astryx.integration.mjs.',
300
+ ],
301
+ [
302
+ 'beside the key it suggests',
303
+ {providerID: '@acme/widgets', providerId: '@acme/widgets'},
304
+ 'Fix: remove "providerID" from astryx.integration.mjs; it already sets "providerId".',
305
+ ],
306
+ ])(
307
+ 'reads the keys the manifest declares: providerID %s',
308
+ async (_label, unknownKeys, fix) => {
309
+ scaffold({unknownKeys});
310
+ const project = await Project.load(tmpDir);
311
+ const keys = (await project.issues()).filter(
312
+ issue => issue.code === 'unknown_manifest_key',
313
+ );
314
+ expect(keys).toHaveLength(1);
315
+ expect(keys[0].message).toContain(fix);
316
+ },
317
+ );
318
+ });
319
+
294
320
  describe('Project.load and the cliCommand an integration declares', () => {
295
321
  it('records it, so the picker prints commands with it', async () => {
296
322
  scaffold({cliCommand: 'acme astryx'});
@@ -830,6 +856,36 @@ describe('Project loads each integration in isolation', () => {
830
856
  });
831
857
  });
832
858
 
859
+ describe('Project finds configured integrations a workspace hoists', () => {
860
+ // npm, Yarn and Bun workspaces install a member's dependencies at the
861
+ // workspace root, so the member's own node_modules does not hold them.
862
+ it('loads an integration named in a member config from the workspace root', async () => {
863
+ scaffold();
864
+ fs.writeFileSync(
865
+ path.join(tmpDir, 'package.json'),
866
+ JSON.stringify({name: 'root', private: true, workspaces: ['apps/*']}),
867
+ );
868
+ fs.rmSync(path.join(tmpDir, 'astryx.config.mjs'));
869
+ const member = path.join(tmpDir, 'apps', 'web');
870
+ fs.mkdirSync(member, {recursive: true});
871
+ fs.writeFileSync(path.join(member, 'package.json'), JSON.stringify({name: 'web'}));
872
+ fs.writeFileSync(
873
+ path.join(member, 'astryx.config.mjs'),
874
+ `export default ${JSON.stringify({integrations: ['@acme/widgets']})};\n`,
875
+ );
876
+
877
+ const project = await Project.load(member);
878
+
879
+ const widgets = (await project.components()).filter(
880
+ component => component.package === '@acme/widgets',
881
+ );
882
+ expect(widgets.map(component => component.name)).toEqual(['Widget']);
883
+ expect(await project.issues()).not.toContainEqual(
884
+ expect.objectContaining({package: '@acme/widgets', code: 'integration_error'}),
885
+ );
886
+ });
887
+ });
888
+
833
889
  describe('Project.issuesUrl routing', () => {
834
890
  it('routes core to config.issuesUrl, falling back to the default', async () => {
835
891
  scaffold({issuesUrl: 'https://example.com/core'});
@@ -1,6 +1,13 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * Whether a component doc is hidden (`hidden: true`), read as discovery
6
+ * reads it: discovery skips a hidden doc.
7
+ * @param {string} docPath
8
+ * @returns {boolean}
9
+ */
10
+ export function isHiddenComponentDoc(docPath: string): boolean;
4
11
  /**
5
12
  * The entry a family doc gives `name` in its `components`, when the doc is not
6
13
  * the component's own (Stack's doc for VStack); null otherwise.
@@ -117,6 +124,36 @@ export function discoverExternalComponentsGrouped(docsDir: string): Record<strin
117
124
  export function findExternalComponentDoc(docsDir: string, name: string): string | null;
118
125
  /** @param {string} docPath */
119
126
  export function docStem(docPath: string): string;
127
+ /**
128
+ * The local module a doc's import names: the doc's own `import`, else the
129
+ * subpath its directory publishes, read through the package's `exports` (its
130
+ * `main` when it has none). Undefined when the package directory is unknown;
131
+ * null when the import names another package or resolves to no file.
132
+ *
133
+ * @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown>|null}} integration
134
+ * @param {string} docPath
135
+ * @param {Record<string, any> | null} doc
136
+ * @returns {string | null | undefined}
137
+ */
138
+ export function importedModule(integration: {
139
+ name?: string;
140
+ __packageDir?: string;
141
+ __packageExports?: Record<string, unknown> | null;
142
+ }, docPath: string, doc: Record<string, any> | null): string | null | undefined;
143
+ /**
144
+ * The file an import of the package's own name resolves to, through its
145
+ * package.json `exports` (or `main` when it has none): `@acme/kit` or
146
+ * `@acme/kit/widget`. Null when the specifier names another package, or the
147
+ * package publishes nothing at it.
148
+ * @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown> | null}} integration
149
+ * @param {string} specifier
150
+ * @returns {string | null}
151
+ */
152
+ export function ownPackageModule(integration: {
153
+ name?: string;
154
+ __packageDir?: string;
155
+ __packageExports?: Record<string, unknown> | null;
156
+ }, specifier: string): string | null;
120
157
  /**
121
158
  * The `.tsx` file in `folder`, or below it, that declares `name`, taking files
122
159
  * in path order: the source of a member whose import never reaches a `.tsx`
@@ -118,6 +118,16 @@ function scanDocText(text) {
118
118
  };
119
119
  }
120
120
 
121
+ /**
122
+ * Whether a component doc is hidden (`hidden: true`), read as discovery
123
+ * reads it: discovery skips a hidden doc.
124
+ * @param {string} docPath
125
+ * @returns {boolean}
126
+ */
127
+ export function isHiddenComponentDoc(docPath) {
128
+ return readDocMeta(docPath).hidden;
129
+ }
130
+
121
131
  /**
122
132
  * Read the `group`, `hiddenComponents`, and `hidden` fields from a
123
133
  * component's .doc.mjs file (synchronous), with what {@link scanDocText}
@@ -994,7 +1004,7 @@ function packageMain(packageDir) {
994
1004
  * @param {Record<string, any> | null} doc
995
1005
  * @returns {string | null | undefined}
996
1006
  */
997
- function importedModule(integration, docPath, doc) {
1007
+ export function importedModule(integration, docPath, doc) {
998
1008
  const packageName = integration?.name;
999
1009
  const packageDir = integration?.__packageDir;
1000
1010
  if (!packageName || !packageDir) return undefined;
@@ -1024,6 +1034,42 @@ function importedModule(integration, docPath, doc) {
1024
1034
  ).target;
1025
1035
  }
1026
1036
 
1037
+ /**
1038
+ * The file an import of the package's own name resolves to, through its
1039
+ * package.json `exports` (or `main` when it has none): `@acme/kit` or
1040
+ * `@acme/kit/widget`. Null when the specifier names another package, or the
1041
+ * package publishes nothing at it.
1042
+ * @param {{name?: string, __packageDir?: string, __packageExports?: Record<string, unknown> | null}} integration
1043
+ * @param {string} specifier
1044
+ * @returns {string | null}
1045
+ */
1046
+ export function ownPackageModule(integration, specifier) {
1047
+ const packageName = integration?.name;
1048
+ const packageDir = integration?.__packageDir;
1049
+ if (!packageName || !packageDir) return null;
1050
+ if (specifier !== packageName && !specifier.startsWith(`${packageName}/`)) {
1051
+ return null;
1052
+ }
1053
+ const exportsMap =
1054
+ integration.__packageExports === undefined
1055
+ ? readPackageExports(packageDir)
1056
+ : integration.__packageExports;
1057
+ if (specifier === packageName && exportsMap == null) {
1058
+ return packageMain(packageDir) ?? null;
1059
+ }
1060
+ const subpath =
1061
+ specifier === packageName
1062
+ ? '.'
1063
+ : `./${specifier.slice(packageName.length + 1)}`;
1064
+ return (
1065
+ inspectPackageExport(
1066
+ {name: packageName, exports: exportsMap ?? undefined},
1067
+ packageDir,
1068
+ subpath,
1069
+ ).target ?? null
1070
+ );
1071
+ }
1072
+
1027
1073
  /**
1028
1074
  * Whether `file` sits in `folder` or below it.
1029
1075
  * @param {string} folder
@@ -1211,6 +1257,19 @@ export function integrationMemberEntry(doc, record) {
1211
1257
  );
1212
1258
  }
1213
1259
 
1260
+ /**
1261
+ * Whether `dir` is a folder to list. A declared root that is a file is
1262
+ * reported by the root check; discovery finds nothing in it.
1263
+ * @param {string} dir
1264
+ */
1265
+ function isFolder(dir) {
1266
+ try {
1267
+ return fs.statSync(dir).isDirectory();
1268
+ } catch {
1269
+ return false;
1270
+ }
1271
+ }
1272
+
1214
1273
  /**
1215
1274
  * Visit every component doc under an integration's components root, hidden
1216
1275
  * ones included, in discovery order, with its stem.
@@ -1218,10 +1277,26 @@ export function integrationMemberEntry(doc, record) {
1218
1277
  * @param {(docPath: string, stem: string) => void} visit
1219
1278
  */
1220
1279
  export function forEachIntegrationDoc(componentsDir, visit) {
1221
- if (!componentsDir || !pathExists(componentsDir)) return;
1280
+ if (!componentsDir || !isFolder(componentsDir)) return;
1281
+ /** @param {string} name */
1282
+ const key = name => {
1283
+ const rank = INTEGRATION_DOC_SUFFIXES.findIndex(s => name.endsWith(s));
1284
+ return rank < 0
1285
+ ? {stem: name, rank}
1286
+ : {stem: name.slice(0, -INTEGRATION_DOC_SUFFIXES[rank].length), rank};
1287
+ };
1222
1288
  /** @param {string} dirPath */
1223
1289
  function scanDir(dirPath) {
1224
- for (const entry of listDirEntries(dirPath)) {
1290
+ // Name order, and for two docs of one stem the suffix precedence, so the
1291
+ // doc a stem records is the one a lookup by name finds, on every disk.
1292
+ const entries = listDirEntries(dirPath).sort((a, b) => {
1293
+ const left = key(a.name);
1294
+ const right = key(b.name);
1295
+ return left.stem === right.stem
1296
+ ? left.rank - right.rank
1297
+ : byCodeUnit(left.stem, right.stem);
1298
+ });
1299
+ for (const entry of entries) {
1225
1300
  if (entry.name === 'node_modules' || entry.name === '__tests__') continue;
1226
1301
  const fullPath = path.join(dirPath, entry.name);
1227
1302
  if (entry.isDirectory()) {
@@ -1270,7 +1345,7 @@ export function discoverIntegrationComponents(
1270
1345
  {documentedNames = true} = {},
1271
1346
  ) {
1272
1347
  const componentsDir = integration?.components;
1273
- if (!componentsDir || !pathExists(componentsDir)) return [];
1348
+ if (!componentsDir || !isFolder(componentsDir)) return [];
1274
1349
 
1275
1350
  /** @type {Map<string, {name: string, package: string, docPath: string, sourcePath: string|null, issuesUrl: string|undefined, group: string|null}>} */
1276
1351
  const byName = new Map();
@@ -1485,7 +1560,7 @@ function findDocumentedComponent(integration, componentsDir, name) {
1485
1560
  */
1486
1561
  export function findIntegrationComponent(integration, name) {
1487
1562
  const componentsDir = integration?.components;
1488
- if (!componentsDir || !pathExists(componentsDir)) return null;
1563
+ if (!componentsDir || !isFolder(componentsDir)) return null;
1489
1564
  const sameStem = findSameStemDoc(componentsDir, name);
1490
1565
  if (sameStem) {
1491
1566
  const exportName = otherExportName({
@@ -43,5 +43,5 @@ export type LoadDocOptions = {
43
43
  * which root reads the doc
44
44
  * (default: components)
45
45
  */
46
- root?: "hooks" | "components" | undefined;
46
+ root?: "components" | "hooks" | undefined;
47
47
  };
@@ -423,6 +423,19 @@ export function problemsInNamespace(doc) {
423
423
  return problems;
424
424
  }
425
425
 
426
+ /**
427
+ * Whether `dir` is a folder to list. A declared root that is a file is
428
+ * reported by the root check; discovery finds nothing in it.
429
+ * @param {string} dir
430
+ */
431
+ function isFolder(dir) {
432
+ try {
433
+ return fs.statSync(dir).isDirectory();
434
+ } catch {
435
+ return false;
436
+ }
437
+ }
438
+
426
439
  /**
427
440
  * Discover the topics contributed by a single loaded integration. Mirrors
428
441
  * `discoverIntegrationComponents`: walk the resolved root, take every
@@ -450,7 +463,7 @@ export async function discoverIntegrationDocs(integration) {
450
463
  const namespaces = [];
451
464
  /** @type {import('../doc-compiler/tree.mjs').TreeDocInput[]} */
452
465
  const guides = [];
453
- if (!docsDir || !fs.existsSync(docsDir)) {
466
+ if (!docsDir || !isFolder(docsDir)) {
454
467
  return {records, errors, namespaces, guides};
455
468
  }
456
469
  const providerId = integration.providerId ?? integration.name;
@@ -18,6 +18,39 @@ export function moduleExportsName(file: string, exportName: string, seen?: Set<s
18
18
  * @returns {string | null}
19
19
  */
20
20
  export function moduleExportSource(file: string, exportName: string, seen?: Set<string>): string | null;
21
+ /**
22
+ * Every runtime name a module exports that this read can see (`default` for
23
+ * a default export), or null when it cannot see them all: an `export *`, `export =`, CommonJS exports, or a
24
+ * file that does not parse.
25
+ * @param {string} file
26
+ * @returns {string[] | null}
27
+ */
28
+ export function moduleExportNames(file: string): string[] | null;
29
+ /**
30
+ * @typedef {{verdict: 'exports'} | {verdict: 'lacks'} | {verdict: 'unknown', reason: string}} ExportVerdict
31
+ */
32
+ /**
33
+ * Whether a module exports `exportName` at runtime, read without executing
34
+ * it: `exports` when a declaration or a followed re-export binds it, `lacks`
35
+ * only when every export the module writes was read and none binds it, and
36
+ * `unknown`, with the first reason, when some export could not be read: a
37
+ * re-export from another package or from a specifier that resolves to no
38
+ * file, a destructured binding, a namespace, an ambient or const enum
39
+ * declaration, `export =`, CommonJS exports, or a file that does not parse.
40
+ * @param {string} file
41
+ * @param {string} exportName
42
+ * @param {Set<string>} [seen]
43
+ * @returns {ExportVerdict}
44
+ */
45
+ export function moduleExportVerdict(file: string, exportName: string, seen?: Set<string>): ExportVerdict;
46
+ /**
47
+ * Whether a module provably does not export `exportName` at runtime: see
48
+ * {@link moduleExportVerdict}.
49
+ * @param {string} file
50
+ * @param {string} exportName
51
+ * @returns {boolean}
52
+ */
53
+ export function moduleLacksExport(file: string, exportName: string): boolean;
21
54
  /**
22
55
  * The object a module exports, as plain data, read without running it: the
23
56
  * first of `exportNames` it exports, an object literal in place or a top-level
@@ -35,3 +68,11 @@ export function staticExportObject(file: string, exportNames: readonly string[])
35
68
  * enumerable, so the object compares and serializes as its literal properties.
36
69
  */
37
70
  export const HAS_COMPUTED: unique symbol;
71
+ export type ExportVerdict = {
72
+ verdict: "exports";
73
+ } | {
74
+ verdict: "lacks";
75
+ } | {
76
+ verdict: "unknown";
77
+ reason: string;
78
+ };