@astryxdesign/cli 0.6.0 → 0.6.1

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 (219) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/README.md +76 -67
  3. package/api/build/build.test.mjs +37 -0
  4. package/api/build/build.type.mjs +1 -1
  5. package/api/build/kit/kit.mjs +31 -1
  6. package/api/component/_adapter.mjs +14 -28
  7. package/api/component/integration-import-agreement.test.mjs +318 -0
  8. package/api/doctor/doctor.d.mts +32 -3
  9. package/api/doctor/doctor.doc.mjs +2 -1
  10. package/api/doctor/doctor.mjs +97 -4
  11. package/api/doctor/doctor.test.mjs +90 -1
  12. package/api/gap-report/gap-report-worker.d.mts +4 -0
  13. package/api/gap-report/gap-report-worker.mjs +73 -0
  14. package/api/gap-report/gap-report.d.mts +81 -0
  15. package/api/gap-report/gap-report.doc.d.mts +9 -0
  16. package/api/gap-report/gap-report.doc.mjs +127 -0
  17. package/api/gap-report/gap-report.mjs +707 -0
  18. package/api/gap-report/gap-report.test.mjs +1210 -0
  19. package/api/gap-report/gap-report.type.d.mts +88 -0
  20. package/api/gap-report/gap-report.type.mjs +69 -0
  21. package/api/index.d.mts +8 -1
  22. package/api/index.mjs +24 -1
  23. package/api/integration/add-contribution.d.mts +44 -0
  24. package/api/integration/add-contribution.mjs +1160 -0
  25. package/api/integration/add-contribution.test.mjs +733 -0
  26. package/api/integration/add-helpers.d.mts +80 -0
  27. package/api/integration/add-helpers.mjs +333 -0
  28. package/api/integration/add-helpers.test.mjs +161 -0
  29. package/api/integration/add-theme.d.mts +10 -0
  30. package/api/integration/add-theme.mjs +332 -0
  31. package/api/integration/add-theme.test.mjs +194 -0
  32. package/api/integration/integration-authoring.type.d.mts +55 -0
  33. package/api/integration/integration-authoring.type.mjs +76 -0
  34. package/api/integration/integration-block-exports.test.mjs +4 -0
  35. package/api/integration/integrationAdd.doc.d.mts +5 -0
  36. package/api/integration/integrationAdd.doc.mjs +100 -0
  37. package/api/integration/integrationAddAgentDoc.doc.d.mts +5 -0
  38. package/api/integration/integrationAddAgentDoc.doc.mjs +49 -0
  39. package/api/integration/integrationAddCodemod.doc.d.mts +5 -0
  40. package/api/integration/integrationAddCodemod.doc.mjs +55 -0
  41. package/api/integration/integrationAddComponent.doc.d.mts +5 -0
  42. package/api/integration/integrationAddComponent.doc.mjs +49 -0
  43. package/api/integration/integrationAddDoc.doc.d.mts +5 -0
  44. package/api/integration/integrationAddDoc.doc.mjs +59 -0
  45. package/api/integration/integrationAddTemplate.doc.d.mts +5 -0
  46. package/api/integration/integrationAddTemplate.doc.mjs +55 -0
  47. package/api/integration/integrationAddTheme.doc.d.mts +5 -0
  48. package/api/integration/integrationAddTheme.doc.mjs +85 -0
  49. package/api/integration/integrationPackCheck.doc.d.mts +5 -0
  50. package/api/integration/integrationPackCheck.doc.mjs +35 -0
  51. package/api/integration/pack-check.d.mts +27 -0
  52. package/api/integration/pack-check.mjs +795 -0
  53. package/api/integration/pack-check.test.mjs +569 -0
  54. package/api/integration/pack-check.type.d.mts +45 -0
  55. package/api/integration/pack-check.type.mjs +56 -0
  56. package/api/integration/public-api.test.mjs +21 -0
  57. package/api/integration/validate-integration.mjs +221 -11
  58. package/api/integration/validate-integration.test.mjs +189 -5
  59. package/api/integration/validateIntegration.doc.mjs +2 -2
  60. package/api/json/index.ts +1 -0
  61. package/api/search/search.mjs +19 -1
  62. package/api/theme/_adapter.d.mts +26 -28
  63. package/api/theme/_adapter.mjs +101 -38
  64. package/api/theme/add/add.d.mts +2 -1
  65. package/api/theme/add/add.mjs +56 -20
  66. package/api/theme/add/add.test.mjs +1 -0
  67. package/api/theme/build/build.d.mts +25 -0
  68. package/api/theme/build/build.mjs +101 -70
  69. package/api/theme/build/build.test.mjs +77 -44
  70. package/api/theme/integration-themes.test.mjs +183 -0
  71. package/api/theme/list/list.d.mts +10 -2
  72. package/api/theme/list/list.mjs +31 -10
  73. package/api/theme/list/list.test.mjs +102 -23
  74. package/api/theme/listThemes.doc.d.mts +1 -5
  75. package/api/theme/listThemes.doc.mjs +6 -13
  76. package/api/theme/targets/targets.test.mjs +22 -8
  77. package/api/theme/theme.d.mts +1 -1
  78. package/api/theme/theme.mjs +1 -1
  79. package/api/theme/theme.type.d.mts +9 -0
  80. package/api/theme/theme.type.mjs +3 -1
  81. package/api/theme/themeAdd.doc.d.mts +1 -4
  82. package/api/theme/themeAdd.doc.mjs +31 -31
  83. package/api/theme/themeBuild.doc.mjs +1 -1
  84. package/api/theme/themeList.doc.d.mts +1 -4
  85. package/api/theme/themeList.doc.mjs +7 -15
  86. package/api/theme/themeListAvailable.doc.d.mts +8 -0
  87. package/api/theme/themeListAvailable.doc.mjs +57 -0
  88. package/api/theme/themeTargets.doc.mjs +21 -7
  89. package/api/upgrade/_adapter.d.mts +2 -0
  90. package/api/upgrade/_adapter.mjs +1 -0
  91. package/api/upgrade/registry/registry.d.mts +40 -0
  92. package/api/upgrade/registry/registry.mjs +1154 -0
  93. package/api/upgrade/registry/registry.test.mjs +826 -0
  94. package/api/upgrade/run/run.mjs +49 -8
  95. package/api/upgrade/status/status.d.mts +6 -4
  96. package/api/upgrade/status/status.mjs +26 -8
  97. package/api/upgrade/upgrade.d.mts +2 -2
  98. package/api/upgrade/upgrade.doc.mjs +33 -9
  99. package/api/upgrade/upgrade.mjs +34 -7
  100. package/api/upgrade/upgrade.test.mjs +198 -8
  101. package/api/upgrade/upgrade.type.d.mts +90 -1
  102. package/api/upgrade/upgrade.type.mjs +51 -2
  103. package/assets/docs/cli-integrations.doc.mjs +152 -28
  104. package/assets/docs/getting-started.doc.mjs +1 -1
  105. package/assets/docs/{shadcn-compatibility.doc.mjs → shadcn-compatibility.doc.draft.mjs} +23 -13
  106. package/assets/docs/styling.doc.mjs +3 -3
  107. package/assets/docs/theme.doc.dense.mjs +2 -2
  108. package/assets/docs/theme.doc.mjs +23 -13
  109. package/assets/docs/theme.doc.zh.mjs +1 -1
  110. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +2 -1
  111. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +38 -12
  112. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.doc.mjs +15 -0
  113. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.tsx +87 -0
  114. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +23 -0
  115. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +75 -0
  116. package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.tsx +5 -19
  117. package/assets/templates/blocks/components/Center/CenterHorizontal.doc.mjs +3 -2
  118. package/assets/templates/blocks/components/Center/CenterHorizontal.tsx +4 -5
  119. package/assets/templates/blocks/components/Toast/ToastAction.tsx +2 -1
  120. package/assets/templates/blocks/components/Toast/ToastDeduplication.tsx +2 -1
  121. package/assets/templates/blocks/components/Toast/ToastDismiss.tsx +2 -1
  122. package/assets/templates/blocks/components/Toast/ToastShowcase.tsx +2 -1
  123. package/assets/templates/blocks/components/Toast/ToastStacking.tsx +2 -1
  124. package/assets/templates/blocks/components/Toast/ToastTypes.tsx +2 -1
  125. package/assets/templates/pages/dashboard/template.doc.mjs +2 -2
  126. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +3 -2
  127. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +3 -2
  128. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +3 -3
  129. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -2
  130. package/assets/templates/pages/dashboard-progress/template.doc.mjs +2 -2
  131. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -2
  132. package/assets/templates/themes/butter/butterTheme.ts +3 -3
  133. package/assets/templates/themes/neutral/neutralTheme.ts +2 -2
  134. package/assets/templates/themes/stone/stoneTheme.ts +3 -3
  135. package/assets/theme.template.ts +4 -7
  136. package/authoring/config/config.doc.mjs +9 -1
  137. package/authoring/config/parse.d.mts +2 -0
  138. package/authoring/config/parse.mjs +28 -3
  139. package/authoring/config/parse.test.mjs +25 -3
  140. package/authoring/config/type.ts +3 -0
  141. package/authoring/doctypes/_schema.d.mts +3 -0
  142. package/authoring/doctypes/_schema.mjs +6 -1
  143. package/authoring/doctypes/base/type.ts +6 -6
  144. package/authoring/doctypes/component/component.doc.mjs +6 -0
  145. package/authoring/doctypes/component/type.ts +2 -0
  146. package/authoring/gap-report/parse.d.mts +63 -0
  147. package/authoring/gap-report/parse.mjs +121 -0
  148. package/authoring/gap-report/parse.test.mjs +172 -0
  149. package/authoring/gap-report/type.ts +107 -0
  150. package/authoring/index.d.mts +1 -0
  151. package/authoring/index.d.ts +12 -0
  152. package/authoring/index.mjs +4 -0
  153. package/authoring/integration/integration.doc.mjs +14 -2
  154. package/authoring/integration/parse.test.mjs +9 -4
  155. package/authoring/integration/schema.d.mts +2 -0
  156. package/authoring/integration/schema.mjs +1 -0
  157. package/authoring/integration/type.ts +23 -6
  158. package/authoring/shadcn/receipt.d.mts +219 -0
  159. package/authoring/shadcn/receipt.mjs +248 -0
  160. package/authoring/shadcn/receipt.test.mjs +187 -0
  161. package/authoring/shadcn/source-variants.d.mts +28 -0
  162. package/authoring/shadcn/source-variants.mjs +176 -0
  163. package/authoring/shadcn/source-variants.test.mjs +120 -0
  164. package/clients/cli/commands/build-theme.mjs +54 -19
  165. package/clients/cli/commands/build-theme.variants.test.mjs +15 -12
  166. package/clients/cli/commands/component/index.mjs +1 -1
  167. package/clients/cli/commands/docs.test.mjs +1 -0
  168. package/clients/cli/commands/doctor-integration.doc.mjs +1 -1
  169. package/clients/cli/commands/gap-report.doc.mjs +73 -0
  170. package/clients/cli/commands/gap-report.mjs +114 -0
  171. package/clients/cli/commands/gap-report.test.mjs +198 -0
  172. package/clients/cli/commands/import-hint-correctness.test.mjs +88 -0
  173. package/clients/cli/commands/integration-add.doc.mjs +88 -0
  174. package/clients/cli/commands/integration-authoring.test.mjs +177 -0
  175. package/clients/cli/commands/integration-pack.doc.mjs +34 -0
  176. package/clients/cli/commands/integration-real-world.test.mjs +618 -0
  177. package/clients/cli/commands/integration.doc.mjs +28 -0
  178. package/clients/cli/commands/integration.mjs +153 -0
  179. package/clients/cli/commands/theme-add.doc.mjs +11 -6
  180. package/clients/cli/commands/theme-list.doc.mjs +21 -5
  181. package/clients/cli/commands/theme-targets.behavior.test.mjs +19 -2
  182. package/clients/cli/commands/theme.doc.mjs +2 -2
  183. package/clients/cli/commands/upgrade.doc.mjs +17 -4
  184. package/clients/cli/commands/upgrade.mjs +12 -1
  185. package/clients/cli/commands/upgrade.test.mjs +41 -0
  186. package/clients/cli/index.mjs +5 -0
  187. package/clients/cli/lib/component-format.mjs +42 -26
  188. package/clients/cli/lib/component-format.test.mjs +34 -3
  189. package/clients/cli/lib/manifest.mjs +12 -0
  190. package/foundation/config/project-themes.test.mjs +127 -0
  191. package/foundation/config/project.d.mts +23 -4
  192. package/foundation/config/project.mjs +96 -9
  193. package/foundation/config/project.test.mjs +132 -6
  194. package/foundation/discovery/component-discovery.d.mts +36 -0
  195. package/foundation/discovery/component-discovery.mjs +96 -0
  196. package/foundation/discovery/theme-discovery.d.mts +39 -0
  197. package/foundation/discovery/theme-discovery.mjs +650 -0
  198. package/foundation/discovery/theme-discovery.test.mjs +375 -0
  199. package/foundation/discovery/theming-targets.d.mts +16 -0
  200. package/foundation/discovery/theming-targets.mjs +39 -3
  201. package/foundation/discovery/theming-targets.test.mjs +139 -0
  202. package/foundation/integrations/autolink.d.mts +96 -0
  203. package/foundation/integrations/autolink.mjs +265 -0
  204. package/foundation/integrations/autolink.test.mjs +430 -0
  205. package/foundation/integrations/contribution-inventory.d.mts +152 -0
  206. package/foundation/integrations/contribution-inventory.mjs +497 -0
  207. package/foundation/integrations/contribution-inventory.test.mjs +361 -0
  208. package/foundation/integrations/integrations.d.mts +73 -9
  209. package/foundation/integrations/integrations.mjs +158 -8
  210. package/foundation/integrations/integrations.test.mjs +152 -29
  211. package/foundation/integrations/manifest-writer.d.mts +56 -0
  212. package/foundation/integrations/manifest-writer.mjs +328 -0
  213. package/foundation/integrations/manifest-writer.test.mjs +229 -0
  214. package/foundation/integrations/validate-contributions.mjs +81 -6
  215. package/foundation/response/error-codes.d.mts +4 -1
  216. package/foundation/response/error-codes.doc.mjs +16 -1
  217. package/foundation/response/error-codes.mjs +10 -1
  218. package/foundation/response/response-types.doc.mjs +23 -2
  219. package/package.json +8 -1
@@ -0,0 +1,96 @@
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
+ * The dependency names this project declares, in field then declaration order,
6
+ * each tagged with the field that declared it. A name declared twice keeps the
7
+ * first field it appeared in.
8
+ *
9
+ * Only keys are read. See the file header for why values are never parsed.
10
+ *
11
+ * @param {string} projectDir directory holding the project's package.json
12
+ * @returns {Array<{name: string, field: string}>}
13
+ */
14
+ export function readDeclaredDependencies(projectDir: string): Array<{
15
+ name: string;
16
+ field: string;
17
+ }>;
18
+ /**
19
+ * Resolve an installed package's directory the way Node's resolver finds it:
20
+ * the nearest `node_modules/<name>` walking up from `fromDir`.
21
+ *
22
+ * Walking up matters because hoisting is normal — yarn and npm workspaces lift
23
+ * a workspace member's dependency to the repo root, so the app's own
24
+ * node_modules can be empty of a package it genuinely declares.
25
+ *
26
+ * Presence is decided by the package's own package.json, not the directory, so
27
+ * a stale empty directory is not mistaken for an install.
28
+ *
29
+ * @param {string} name bare package name
30
+ * @param {string} fromDir directory to start walking up from
31
+ * @returns {{packageDir: string, hostDir: string}|null} the resolved package
32
+ * directory and the directory whose node_modules holds it
33
+ */
34
+ export function resolveInstalledPackageDir(name: string, fromDir: string): {
35
+ packageDir: string;
36
+ hostDir: string;
37
+ } | null;
38
+ /**
39
+ * Declared dependencies that ship an integration manifest and are not already
40
+ * loaded, in declaration order.
41
+ *
42
+ * A candidate must have EXACTLY ONE root manifest. Zero is the ordinary case
43
+ * (almost every dependency), and more than one is a packaging mistake the
44
+ * loader treats as a hard error — an error the project did not ask for and
45
+ * cannot fix, so an ambiguous package is passed over here rather than allowed
46
+ * to fail the load of a project that merely depends on it.
47
+ *
48
+ * @param {string} projectDir directory holding the project's package.json
49
+ * @param {{exclude?: Iterable<string>}} [options] `exclude` — package
50
+ * directories already loaded (from config); matched through symlinks
51
+ * @returns {Array<{spec: string, field: string, packageDir: string, hostDir: string}>}
52
+ */
53
+ export function findAutolinkCandidates(projectDir: string, { exclude }?: {
54
+ exclude?: Iterable<string>;
55
+ }): Array<{
56
+ spec: string;
57
+ field: string;
58
+ packageDir: string;
59
+ hostDir: string;
60
+ }>;
61
+ /**
62
+ * Load every declared dependency that ships an integration manifest and is not
63
+ * already loaded from config.
64
+ *
65
+ * Each candidate is loaded in isolation. A dependency the project never asked
66
+ * to be an integration must not be able to take down `Project.load` for the
67
+ * whole project, so a manifest that throws on import is dropped here with the
68
+ * rest of that package's contributions — including the load-error marker
69
+ * `loadIntegrations` returns for it. A CONFIGURED integration is the opposite
70
+ * case: the project named it, so its failure is an issue the project owns and
71
+ * can act on. An autolinked one is a dependency's own packaging bug, which the
72
+ * consuming project can neither fix nor silence, and which
73
+ * `astryx doctor integration validate <package>` reports on demand.
74
+ *
75
+ * @param {object} options
76
+ * @param {string} options.projectDir directory holding the project's package.json
77
+ * @param {import('./integrations.mjs').LoadedIntegration[]} [options.loaded]
78
+ * integrations already loaded from config; these win
79
+ * @param {boolean} [options.fresh]
80
+ * @returns {Promise<import('./integrations.mjs').LoadedIntegration[]>}
81
+ */
82
+ export function autolinkIntegrations({ projectDir, loaded, fresh, }: {
83
+ projectDir: string;
84
+ loaded?: import("./integrations.mjs").LoadedIntegration[] | undefined;
85
+ fresh?: boolean | undefined;
86
+ }): Promise<import("./integrations.mjs").LoadedIntegration[]>;
87
+ /**
88
+ * package.json fields whose keys name a dependency this project installs.
89
+ *
90
+ * `peerDependencies` is deliberately absent: a peer is a requirement the
91
+ * CONSUMER must satisfy, not something this project's install brings in, so a
92
+ * peer that happens to be present is not a declaration that it belongs here.
93
+ *
94
+ * @type {readonly string[]}
95
+ */
96
+ export const DEPENDENCY_FIELDS: readonly string[];
@@ -0,0 +1,265 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Autolink — load installed integrations that no astryx.config names.
5
+ *
6
+ * An integration used to need two things to be visible: the package installed,
7
+ * and its name written into `astryx.config.*`. In practice the second half goes
8
+ * missing. A scaffold adds the dependency and writes no config; the package
9
+ * ships components, templates, docs and codemods; and the CLI reports that none
10
+ * of it exists. Nothing is broken, so nobody looks — the integration is simply
11
+ * never used, because we said it was not there.
12
+ *
13
+ * Autolink closes that gap from the side that is always true: a package the
14
+ * project DECLARED as a dependency and that ships a root
15
+ * `astryx.integration.*` manifest is an integration, config entry or not.
16
+ *
17
+ * Two rules bound it:
18
+ *
19
+ * - DECLARED dependencies only. We read the dependency KEYS out of the
20
+ * project's own package.json and resolve those. We never walk node_modules
21
+ * looking for manifests: a transitive dependency of a dependency did not
22
+ * ask to contribute to this project, and a tree walk is unbounded work for
23
+ * an answer the project already wrote down.
24
+ * - The KEY, never the VALUE. `"@acme/legacy-ui": "npm:@acme/ui@0.1.22"`
25
+ * is a real, installed shape; so are `workspace:*`, `file:../lib`, `link:`
26
+ * and `catalog:`. None of them is a semver range, and none of them has to
27
+ * be parsed: the key is the directory name under node_modules, which is the
28
+ * only thing resolution needs. Identity still comes from the resolved
29
+ * package's own package.json `name` (see loadIntegrations), so an aliased
30
+ * dependency reports the package it actually is.
31
+ *
32
+ * An explicit config entry always wins: candidates already loaded from config
33
+ * are dropped before anything here is imported.
34
+ *
35
+ * @position lib — sits between config/project (the caller) and
36
+ * integrations/integrations (the loader); contributes no discovery of its own.
37
+ */
38
+
39
+ import * as fs from 'node:fs';
40
+ import * as path from 'node:path';
41
+ import {findManifestPaths, loadIntegrations} from './integrations.mjs';
42
+
43
+ /**
44
+ * package.json fields whose keys name a dependency this project installs.
45
+ *
46
+ * `peerDependencies` is deliberately absent: a peer is a requirement the
47
+ * CONSUMER must satisfy, not something this project's install brings in, so a
48
+ * peer that happens to be present is not a declaration that it belongs here.
49
+ *
50
+ * @type {readonly string[]}
51
+ */
52
+ export const DEPENDENCY_FIELDS = Object.freeze([
53
+ 'dependencies',
54
+ 'devDependencies',
55
+ 'optionalDependencies',
56
+ ]);
57
+
58
+ /**
59
+ * Whether a dependency key is a bare package name safe to resolve.
60
+ *
61
+ * Mirrors the guard in {@link import('./integrations.mjs').resolvePackageDir}:
62
+ * a name is a directory under node_modules, so a path segment (`.`, `..`) or an
63
+ * absolute spec must never reach the resolver, which goes on to dynamically
64
+ * import what it finds.
65
+ *
66
+ * @param {string} name
67
+ * @returns {boolean}
68
+ */
69
+ function isBarePackageName(name) {
70
+ return (
71
+ typeof name === 'string' &&
72
+ name.length > 0 &&
73
+ !path.isAbsolute(name) &&
74
+ !name.startsWith('@/') &&
75
+ !name.split('/').some(segment => segment === '.' || segment === '..')
76
+ );
77
+ }
78
+
79
+ /**
80
+ * The dependency names this project declares, in field then declaration order,
81
+ * each tagged with the field that declared it. A name declared twice keeps the
82
+ * first field it appeared in.
83
+ *
84
+ * Only keys are read. See the file header for why values are never parsed.
85
+ *
86
+ * @param {string} projectDir directory holding the project's package.json
87
+ * @returns {Array<{name: string, field: string}>}
88
+ */
89
+ export function readDeclaredDependencies(projectDir) {
90
+ /** @type {Record<string, unknown>} */
91
+ let pkg;
92
+ try {
93
+ pkg = JSON.parse(
94
+ fs.readFileSync(path.join(projectDir, 'package.json'), 'utf-8'),
95
+ );
96
+ } catch {
97
+ // No package.json, or unreadable/malformed — nothing is declared.
98
+ return [];
99
+ }
100
+
101
+ /** @type {Array<{name: string, field: string}>} */
102
+ const declared = [];
103
+ const seen = new Set();
104
+ for (const field of DEPENDENCY_FIELDS) {
105
+ const entry = pkg?.[field];
106
+ if (entry == null || typeof entry !== 'object' || Array.isArray(entry)) {
107
+ continue;
108
+ }
109
+ for (const name of Object.keys(entry)) {
110
+ if (seen.has(name) || !isBarePackageName(name)) continue;
111
+ seen.add(name);
112
+ declared.push({name, field});
113
+ }
114
+ }
115
+ return declared;
116
+ }
117
+
118
+ /**
119
+ * Resolve an installed package's directory the way Node's resolver finds it:
120
+ * the nearest `node_modules/<name>` walking up from `fromDir`.
121
+ *
122
+ * Walking up matters because hoisting is normal — yarn and npm workspaces lift
123
+ * a workspace member's dependency to the repo root, so the app's own
124
+ * node_modules can be empty of a package it genuinely declares.
125
+ *
126
+ * Presence is decided by the package's own package.json, not the directory, so
127
+ * a stale empty directory is not mistaken for an install.
128
+ *
129
+ * @param {string} name bare package name
130
+ * @param {string} fromDir directory to start walking up from
131
+ * @returns {{packageDir: string, hostDir: string}|null} the resolved package
132
+ * directory and the directory whose node_modules holds it
133
+ */
134
+ export function resolveInstalledPackageDir(name, fromDir) {
135
+ if (!isBarePackageName(name)) return null;
136
+ const segments = name.split('/');
137
+ let dir = path.resolve(fromDir);
138
+ for (let i = 0; i < 50; i++) {
139
+ const packageDir = path.join(dir, 'node_modules', ...segments);
140
+ if (fs.existsSync(path.join(packageDir, 'package.json'))) {
141
+ return {packageDir, hostDir: dir};
142
+ }
143
+ const parent = path.dirname(dir);
144
+ if (parent === dir) break;
145
+ dir = parent;
146
+ }
147
+ return null;
148
+ }
149
+
150
+ /**
151
+ * Resolve a path through symlinks for identity comparison. pnpm links every
152
+ * dependency into node_modules from a single content-addressed store, so two
153
+ * different dependency keys pointing at one package share a real path and
154
+ * differ in every other way.
155
+ * @param {string} target
156
+ * @returns {string}
157
+ */
158
+ function realPath(target) {
159
+ try {
160
+ return fs.realpathSync(target);
161
+ } catch {
162
+ return path.resolve(target);
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Declared dependencies that ship an integration manifest and are not already
168
+ * loaded, in declaration order.
169
+ *
170
+ * A candidate must have EXACTLY ONE root manifest. Zero is the ordinary case
171
+ * (almost every dependency), and more than one is a packaging mistake the
172
+ * loader treats as a hard error — an error the project did not ask for and
173
+ * cannot fix, so an ambiguous package is passed over here rather than allowed
174
+ * to fail the load of a project that merely depends on it.
175
+ *
176
+ * @param {string} projectDir directory holding the project's package.json
177
+ * @param {{exclude?: Iterable<string>}} [options] `exclude` — package
178
+ * directories already loaded (from config); matched through symlinks
179
+ * @returns {Array<{spec: string, field: string, packageDir: string, hostDir: string}>}
180
+ */
181
+ export function findAutolinkCandidates(projectDir, {exclude = []} = {}) {
182
+ const taken = new Set([...exclude].map(realPath));
183
+ /** @type {Array<{spec: string, field: string, packageDir: string, hostDir: string}>} */
184
+ const candidates = [];
185
+
186
+ for (const {name, field} of readDeclaredDependencies(projectDir)) {
187
+ const resolved = resolveInstalledPackageDir(name, projectDir);
188
+ if (!resolved) continue;
189
+
190
+ // Two dependency keys can name one installed package — an npm alias beside
191
+ // the package it aliases, or the two spellings of a package mid-rename
192
+ // resolving through one store entry. Load it once.
193
+ const identity = realPath(resolved.packageDir);
194
+ if (taken.has(identity)) continue;
195
+
196
+ if (findManifestPaths(resolved.packageDir).length !== 1) continue;
197
+
198
+ taken.add(identity);
199
+ candidates.push({spec: name, field, ...resolved});
200
+ }
201
+
202
+ return candidates;
203
+ }
204
+
205
+ /**
206
+ * Load every declared dependency that ships an integration manifest and is not
207
+ * already loaded from config.
208
+ *
209
+ * Each candidate is loaded in isolation. A dependency the project never asked
210
+ * to be an integration must not be able to take down `Project.load` for the
211
+ * whole project, so a manifest that throws on import is dropped here with the
212
+ * rest of that package's contributions — including the load-error marker
213
+ * `loadIntegrations` returns for it. A CONFIGURED integration is the opposite
214
+ * case: the project named it, so its failure is an issue the project owns and
215
+ * can act on. An autolinked one is a dependency's own packaging bug, which the
216
+ * consuming project can neither fix nor silence, and which
217
+ * `astryx doctor integration validate <package>` reports on demand.
218
+ *
219
+ * @param {object} options
220
+ * @param {string} options.projectDir directory holding the project's package.json
221
+ * @param {import('./integrations.mjs').LoadedIntegration[]} [options.loaded]
222
+ * integrations already loaded from config; these win
223
+ * @param {boolean} [options.fresh]
224
+ * @returns {Promise<import('./integrations.mjs').LoadedIntegration[]>}
225
+ */
226
+ export async function autolinkIntegrations({
227
+ projectDir,
228
+ loaded = [],
229
+ fresh = false,
230
+ }) {
231
+ const candidates = findAutolinkCandidates(projectDir, {
232
+ exclude: loaded.map(integration => integration.__packageDir),
233
+ });
234
+
235
+ /** @type {import('./integrations.mjs').LoadedIntegration[]} */
236
+ const autolinked = [];
237
+ const names = new Set(loaded.map(integration => integration.name));
238
+
239
+ for (const candidate of candidates) {
240
+ /** @type {import('./integrations.mjs').LoadedIntegration|undefined} */
241
+ let integration;
242
+ try {
243
+ // Resolve from the directory whose node_modules actually holds the
244
+ // package, so a hoisted dependency resolves the same way Node found it.
245
+ [integration] = await loadIntegrations([candidate.spec], {
246
+ cwd: candidate.hostDir,
247
+ fresh,
248
+ });
249
+ } catch {
250
+ continue;
251
+ }
252
+ if (!integration || integration.__loadError) continue;
253
+ // Identity is the resolved package's own name, so an alias and the package
254
+ // it aliases collapse here even when they are two directories on disk.
255
+ if (names.has(integration.name)) continue;
256
+ names.add(integration.name);
257
+ autolinked.push({
258
+ ...integration,
259
+ __autolinked: true,
260
+ __dependencyField: candidate.field,
261
+ });
262
+ }
263
+
264
+ return autolinked;
265
+ }