@astryxdesign/cli 0.7.18-canary.gfca8508 → 0.7.18

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 (341) hide show
  1. package/CHANGELOG.md +185 -19
  2. package/README.md +19 -19
  3. package/api/component/_adapter.d.mts +2 -1
  4. package/api/component/_adapter.mjs +2 -1
  5. package/api/docs/_adapter.d.mts +6 -5
  6. package/api/docs/_adapter.mjs +36 -5
  7. package/api/doctor/_adapter.d.mts +6 -3
  8. package/api/doctor/_adapter.mjs +13 -5
  9. package/api/doctor/doctor.mjs +2 -2
  10. package/api/doctor/font-packages.d.mts +36 -0
  11. package/api/doctor/font-packages.mjs +124 -0
  12. package/api/doctor/theme-checks.mjs +110 -49
  13. package/api/experimental.d.mts +0 -2
  14. package/api/experimental.mjs +0 -12
  15. package/api/icon/_adapter.d.mts +1 -1
  16. package/api/icon/_adapter.mjs +1 -0
  17. package/api/icon/_authoring.mjs +17 -8
  18. package/api/icon/_default-look.mjs +15 -15
  19. package/api/icon/add/add.mjs +9 -4
  20. package/api/icon/exportIconIndex.doc.mjs +1 -1
  21. package/api/icon/icon.doc.mjs +1 -1
  22. package/api/icon/icon.type.d.mts +33 -33
  23. package/api/icon/icon.type.mjs +45 -45
  24. package/api/icon/iconAdd.doc.mjs +1 -1
  25. package/api/icon/iconNewSet.doc.mjs +3 -3
  26. package/api/icon/iconUse.doc.mjs +5 -5
  27. package/api/icon/rankIconIndex.doc.mjs +1 -1
  28. package/api/icon/use/use.mjs +4 -4
  29. package/api/init/run/run.mjs +0 -1
  30. package/api/integration/add-helpers.mjs +1 -1
  31. package/api/render/_adapter.mjs +7 -1
  32. package/api/search/ORDERING.md +1 -1
  33. package/api/search/_candidate-score.mjs +20 -0
  34. package/api/search/_words.d.mts +8 -0
  35. package/api/search/_words.mjs +15 -0
  36. package/api/template/template.type.d.mts +2 -2
  37. package/api/template/template.type.mjs +2 -2
  38. package/api/theme/_adapter.mjs +19 -11
  39. package/api/theme/build/build.d.mts +19 -51
  40. package/api/theme/build/build.mjs +195 -189
  41. package/api/theme/build/font-warning.d.mts +19 -2
  42. package/api/theme/build/font-warning.mjs +46 -5
  43. package/api/theme/generateTonalPalette.doc.mjs +1 -1
  44. package/api/theme/palette/generate/derive-look.mjs +108 -37
  45. package/api/theme/palette/generate/mapping.mjs +2 -0
  46. package/api/theme/template/template.d.mts +0 -17
  47. package/api/theme/template/template.mjs +1 -42
  48. package/api/theme/theme.type.d.mts +5 -4
  49. package/api/theme/theme.type.mjs +5 -4
  50. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  51. package/api/theme/themeRemove.doc.mjs +1 -1
  52. package/assets/codemods/transforms/v0.7.0/preserve-bottom-sheet-content-padding.mjs +3 -1
  53. package/assets/component-list.generated.json +1 -1
  54. package/assets/discover/official-packages.json +26 -2
  55. package/assets/docs/author-a-theme.doc.mjs +6 -5
  56. package/assets/docs/browser-support.doc.mjs +1 -0
  57. package/assets/docs/icons.doc.mjs +8 -7
  58. package/assets/docs/motion.doc.mjs +46 -0
  59. package/assets/docs/theme.doc.dense.mjs +6 -17
  60. package/assets/docs/theme.doc.mjs +6 -16
  61. package/assets/docs/theme.doc.zh.mjs +6 -16
  62. package/assets/docs/tree/ci-and-containers.doc.mjs +1 -1
  63. package/assets/docs/tree/font-setup.doc.mjs +30 -0
  64. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  65. package/assets/docs/tree/template-icons.doc.mjs +3 -3
  66. package/assets/docs/tree/tokens-color.doc.mjs +5 -0
  67. package/assets/docs/tree/tokens.doc.mjs +4 -3
  68. package/assets/docs/tree/updates.doc.mjs +1 -1
  69. package/assets/docs-routes.generated.json +1 -1
  70. package/assets/docs.generated.json +2 -2
  71. package/assets/icons/definitions/drag.doc.mjs +1 -0
  72. package/assets/search-catalog.generated.json +2 -2
  73. package/assets/self-audit.generated.json +1 -1
  74. package/assets/templates/blocks/components/Card/SelectableCardElevated.doc.mjs +1 -1
  75. package/assets/templates/blocks/components/Card/SelectableCardElevated.tsx +20 -10
  76. package/assets/templates/blocks/components/Card/SelectableCardShowcase.doc.mjs +1 -1
  77. package/assets/templates/blocks/components/Card/SelectableCardShowcase.tsx +36 -16
  78. package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +6 -0
  79. package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +6 -0
  80. package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.doc.mjs +14 -0
  81. package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.tsx +63 -0
  82. package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.doc.mjs +29 -0
  83. package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.tsx +237 -0
  84. package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +10 -72
  85. package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.doc.mjs +1 -1
  86. package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.tsx +7 -7
  87. package/assets/templates/blocks/components/Table/TableCustomRowTable.doc.mjs +14 -0
  88. package/assets/templates/blocks/components/Table/TableCustomRowTable.tsx +96 -0
  89. package/assets/templates/components.generated.json +1 -1
  90. package/assets/templates/pages/ai-chat-landing/page.tsx +4 -0
  91. package/assets/templates/pages/dashboard-scorecard/page.tsx +26 -7
  92. package/assets/templates/pages/editor/page.tsx +13 -3
  93. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +2 -2
  94. package/assets/templates/themes/butter/butterTheme.ts +12 -10
  95. package/assets/templates/themes/butter/icons.tsx +2 -0
  96. package/assets/templates/themes/chocolate/chocolateTheme.ts +1 -0
  97. package/assets/templates/themes/chocolate/icons.tsx +2 -0
  98. package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +1 -1
  99. package/assets/templates/themes/gothic/gothicTheme.ts +1 -0
  100. package/assets/templates/themes/gothic/icons.tsx +2 -0
  101. package/assets/templates/themes/matcha/icons.tsx +2 -0
  102. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +2 -2
  103. package/assets/templates/themes/matcha/matchaTheme.ts +1 -0
  104. package/assets/templates/themes/neutral/icons.tsx +2 -0
  105. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +2 -2
  106. package/assets/templates/themes/neutral/neutralTheme.ts +1 -0
  107. package/assets/templates/themes/stone/icons.tsx +2 -0
  108. package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +1 -1
  109. package/assets/templates/themes/stone/stoneTheme.ts +1 -0
  110. package/assets/templates/themes/y2k/icons.tsx +2 -0
  111. package/assets/templates/themes/y2k/y2kTheme.ts +1 -0
  112. package/assets/theme.template.ts +9 -5
  113. package/authoring/config/parse.mjs +1 -1
  114. package/authoring/doctypes/base/type.ts +2 -3
  115. package/authoring/doctypes/component/component.doc.mjs +1 -1
  116. package/authoring/doctypes/icon-set/icon-names.mjs +1 -0
  117. package/authoring/integration/integration.doc.mjs +1 -1
  118. package/authoring/integration/type.ts +1 -1
  119. package/clients/cli/build-id.generated.json +1 -1
  120. package/clients/cli/commands/experimental/icon.mjs +7 -7
  121. package/clients/cli/commands/experimental/index.mjs +0 -5
  122. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
  123. package/clients/cli/commands/experimental-icon-use.doc.mjs +4 -4
  124. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  125. package/clients/cli/commands/experimental.doc.mjs +2 -6
  126. package/clients/cli/commands/template.mjs +1 -1
  127. package/clients/cli/commands/theme-build.doc.mjs +8 -1
  128. package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -1
  129. package/clients/cli/commands/theme-remove.doc.mjs +1 -1
  130. package/clients/cli/commands/theme.doc.mjs +1 -11
  131. package/clients/cli/commands/theme.mjs +110 -475
  132. package/clients/cli/commands.generated.json +1 -1
  133. package/clients/cli/index.mjs +4 -34
  134. package/clients/cli/lib/base-gate.mjs +2 -3
  135. package/clients/cli/lib/cli-error.mjs +8 -72
  136. package/clients/cli/lib/define-command.mjs +0 -19
  137. package/clients/cli/lib/json-shim.mjs +11 -633
  138. package/clients/cli/lib/manifest.mjs +0 -4
  139. package/clients/cli/lib/stray-option.mjs +1 -2
  140. package/clients/cli/manifest.generated.json +1 -1
  141. package/foundation/agent-docs/agent-docs.mjs +1 -1
  142. package/foundation/color/css-color.mjs +2 -3
  143. package/foundation/discovery/app-layout.d.mts +13 -0
  144. package/foundation/discovery/app-layout.mjs +35 -0
  145. package/foundation/discovery/fixture-refs.d.mts +51 -0
  146. package/foundation/discovery/fixture-refs.mjs +351 -0
  147. package/foundation/discovery/icon-definition-discovery.mjs +1 -1
  148. package/foundation/discovery/icon-ranking.mjs +2 -2
  149. package/foundation/discovery/icon-set-checks.mjs +1 -1
  150. package/foundation/discovery/icon-set-discovery.mjs +1 -1
  151. package/foundation/discovery/icon-set-writer.d.mts +24 -7
  152. package/foundation/discovery/icon-set-writer.mjs +66 -22
  153. package/foundation/discovery/static-descriptor.d.mts +49 -0
  154. package/foundation/discovery/static-descriptor.mjs +548 -0
  155. package/foundation/discovery/template-adapter.d.mts +0 -47
  156. package/foundation/discovery/template-adapter.mjs +1 -333
  157. package/foundation/discovery/theme-discovery.d.mts +6 -47
  158. package/foundation/discovery/theme-discovery.mjs +15 -537
  159. package/foundation/doc-compiler/import.mjs +1 -1
  160. package/foundation/env/user-dirs.d.mts +5 -2
  161. package/foundation/env/user-dirs.mjs +12 -5
  162. package/foundation/fonts/next-font.d.mts +26 -0
  163. package/foundation/fonts/next-font.mjs +149 -0
  164. package/foundation/fs/empty-folder.mjs +2 -2
  165. package/foundation/fs/read-record.mjs +11 -4
  166. package/foundation/pictures/pictures.d.mts +1 -45
  167. package/foundation/pictures/pictures.mjs +8 -8
  168. package/foundation/release/folder-lock.mjs +3 -2
  169. package/foundation/render/cut-short.d.mts +2 -2
  170. package/foundation/render/cut-short.mjs +2 -2
  171. package/foundation/render/drawn-contrast.d.mts +2 -2
  172. package/foundation/render/drawn-contrast.mjs +2 -2
  173. package/foundation/render/font-probe.d.mts +2 -2
  174. package/foundation/render/font-probe.mjs +2 -2
  175. package/foundation/render/layers.mjs +1 -2
  176. package/foundation/render/package-resolve-hooks.d.mts +25 -5
  177. package/foundation/render/package-resolve-hooks.mjs +77 -14
  178. package/foundation/render/page-worker.mjs +24 -12
  179. package/foundation/render/part-boxes.d.mts +2 -3
  180. package/foundation/render/part-boxes.mjs +2 -3
  181. package/foundation/render/picture-chrome.mjs +5 -0
  182. package/foundation/render/render-page.d.mts +1 -1
  183. package/foundation/render/render-page.mjs +4 -5
  184. package/foundation/render/single-copy-hooks.d.mts +2 -0
  185. package/foundation/render/single-copy-hooks.mjs +2 -0
  186. package/foundation/response/error-codes.doc.mjs +14 -14
  187. package/foundation/response/error-codes.mjs +13 -13
  188. package/foundation/response/response-types.doc.mjs +7 -68
  189. package/foundation/runtime/css-tree.mjs +2 -2
  190. package/foundation/runtime/word-table.d.mts +1 -1
  191. package/foundation/runtime/word-table.mjs +1 -1
  192. package/foundation/suggest/other-command.d.mts +52 -15
  193. package/foundation/suggest/other-command.mjs +168 -45
  194. package/foundation/text/suggest-order.d.mts +7 -0
  195. package/foundation/text/suggest-order.mjs +1 -1
  196. package/package.json +7 -8
  197. package/api/theme-edit/_adapter.d.mts +0 -228
  198. package/api/theme-edit/_adapter.mjs +0 -2025
  199. package/api/theme-edit/_catalog.d.mts +0 -172
  200. package/api/theme-edit/_catalog.mjs +0 -806
  201. package/api/theme-edit/_check.d.mts +0 -391
  202. package/api/theme-edit/_check.mjs +0 -9370
  203. package/api/theme-edit/_color.d.mts +0 -135
  204. package/api/theme-edit/_color.mjs +0 -480
  205. package/api/theme-edit/_compiler.d.mts +0 -77
  206. package/api/theme-edit/_compiler.mjs +0 -1053
  207. package/api/theme-edit/_context.d.mts +0 -399
  208. package/api/theme-edit/_context.mjs +0 -1778
  209. package/api/theme-edit/_css.d.mts +0 -169
  210. package/api/theme-edit/_css.mjs +0 -1167
  211. package/api/theme-edit/_edit.d.mts +0 -167
  212. package/api/theme-edit/_edit.mjs +0 -11220
  213. package/api/theme-edit/_how-commands.d.mts +0 -315
  214. package/api/theme-edit/_how-commands.mjs +0 -1664
  215. package/api/theme-edit/_how-question.d.mts +0 -341
  216. package/api/theme-edit/_how-question.mjs +0 -33339
  217. package/api/theme-edit/_how-sides.d.mts +0 -22
  218. package/api/theme-edit/_how-sides.mjs +0 -173
  219. package/api/theme-edit/_how-steps.d.mts +0 -42
  220. package/api/theme-edit/_how-steps.mjs +0 -208
  221. package/api/theme-edit/_how-values.d.mts +0 -29
  222. package/api/theme-edit/_how-values.mjs +0 -111
  223. package/api/theme-edit/_how-words.d.mts +0 -15
  224. package/api/theme-edit/_how-words.mjs +0 -239
  225. package/api/theme-edit/_how.d.mts +0 -55
  226. package/api/theme-edit/_how.mjs +0 -2388
  227. package/api/theme-edit/_importers.d.mts +0 -38
  228. package/api/theme-edit/_importers.mjs +0 -188
  229. package/api/theme-edit/_marks.d.mts +0 -39
  230. package/api/theme-edit/_marks.mjs +0 -67
  231. package/api/theme-edit/_missed.d.mts +0 -56
  232. package/api/theme-edit/_missed.mjs +0 -1128
  233. package/api/theme-edit/_name-rule.d.mts +0 -11
  234. package/api/theme-edit/_name-rule.mjs +0 -12
  235. package/api/theme-edit/_normal.d.mts +0 -365
  236. package/api/theme-edit/_normal.mjs +0 -1978
  237. package/api/theme-edit/_overview.d.mts +0 -9
  238. package/api/theme-edit/_overview.mjs +0 -293
  239. package/api/theme-edit/_palette.d.mts +0 -616
  240. package/api/theme-edit/_palette.mjs +0 -2776
  241. package/api/theme-edit/_part-pieces.d.mts +0 -54
  242. package/api/theme-edit/_part-pieces.mjs +0 -179
  243. package/api/theme-edit/_part-words.d.mts +0 -39
  244. package/api/theme-edit/_part-words.mjs +0 -242
  245. package/api/theme-edit/_parts.d.mts +0 -402
  246. package/api/theme-edit/_parts.mjs +0 -2322
  247. package/api/theme-edit/_picture-traits.d.mts +0 -259
  248. package/api/theme-edit/_picture-traits.mjs +0 -1030
  249. package/api/theme-edit/_png.d.mts +0 -94
  250. package/api/theme-edit/_png.mjs +0 -479
  251. package/api/theme-edit/_preview-app.d.mts +0 -172
  252. package/api/theme-edit/_preview-app.mjs +0 -6430
  253. package/api/theme-edit/_preview.d.mts +0 -484
  254. package/api/theme-edit/_preview.mjs +0 -2775
  255. package/api/theme-edit/_project.d.mts +0 -207
  256. package/api/theme-edit/_project.mjs +0 -643
  257. package/api/theme-edit/_resolved.d.mts +0 -46
  258. package/api/theme-edit/_resolved.mjs +0 -800
  259. package/api/theme-edit/_set-line.d.mts +0 -29
  260. package/api/theme-edit/_set-line.mjs +0 -100
  261. package/api/theme-edit/_settings.d.mts +0 -2426
  262. package/api/theme-edit/_settings.mjs +0 -18449
  263. package/api/theme-edit/_tables.d.mts +0 -227
  264. package/api/theme-edit/_tables.mjs +0 -1128
  265. package/api/theme-edit/_text-looks.d.mts +0 -78
  266. package/api/theme-edit/_text-looks.mjs +0 -376
  267. package/api/theme-edit/_vet.d.mts +0 -50
  268. package/api/theme-edit/_vet.mjs +0 -166
  269. package/api/theme-edit/how/how.d.mts +0 -17
  270. package/api/theme-edit/how/how.mjs +0 -28
  271. package/api/theme-edit/new/new.d.mts +0 -11
  272. package/api/theme-edit/new/new.mjs +0 -22
  273. package/api/theme-edit/preview-add/preview-add.d.mts +0 -14
  274. package/api/theme-edit/preview-add/preview-add.mjs +0 -25
  275. package/api/theme-edit/preview-app/preview-app.d.mts +0 -13
  276. package/api/theme-edit/preview-app/preview-app.mjs +0 -24
  277. package/api/theme-edit/preview-list/preview-list.d.mts +0 -10
  278. package/api/theme-edit/preview-list/preview-list.mjs +0 -21
  279. package/api/theme-edit/preview-remove/preview-remove.d.mts +0 -12
  280. package/api/theme-edit/preview-remove/preview-remove.mjs +0 -23
  281. package/api/theme-edit/set/set.d.mts +0 -13
  282. package/api/theme-edit/set/set.mjs +0 -24
  283. package/api/theme-edit/show/show.d.mts +0 -13
  284. package/api/theme-edit/show/show.mjs +0 -24
  285. package/api/theme-edit/theme-edit.d.mts +0 -12
  286. package/api/theme-edit/theme-edit.mjs +0 -36
  287. package/api/theme-edit/theme-edit.type.d.mts +0 -730
  288. package/api/theme-edit/theme-edit.type.mjs +0 -342
  289. package/api/theme-edit/themeEditHow.doc.d.mts +0 -6
  290. package/api/theme-edit/themeEditHow.doc.mjs +0 -105
  291. package/api/theme-edit/themeEditNew.doc.d.mts +0 -5
  292. package/api/theme-edit/themeEditNew.doc.mjs +0 -112
  293. package/api/theme-edit/themeEditPreviewAdd.doc.d.mts +0 -6
  294. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +0 -121
  295. package/api/theme-edit/themeEditPreviewApp.doc.d.mts +0 -6
  296. package/api/theme-edit/themeEditPreviewApp.doc.mjs +0 -87
  297. package/api/theme-edit/themeEditPreviewList.doc.d.mts +0 -6
  298. package/api/theme-edit/themeEditPreviewList.doc.mjs +0 -62
  299. package/api/theme-edit/themeEditPreviewRemove.doc.d.mts +0 -6
  300. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +0 -96
  301. package/api/theme-edit/themeEditSet.doc.d.mts +0 -6
  302. package/api/theme-edit/themeEditSet.doc.mjs +0 -175
  303. package/api/theme-edit/themeEditShow.doc.d.mts +0 -6
  304. package/api/theme-edit/themeEditShow.doc.mjs +0 -118
  305. package/api/theme-edit/themeEditUndo.doc.d.mts +0 -6
  306. package/api/theme-edit/themeEditUndo.doc.mjs +0 -133
  307. package/api/theme-edit/undo/undo.d.mts +0 -13
  308. package/api/theme-edit/undo/undo.mjs +0 -24
  309. package/assets/preview-app/README.md +0 -6
  310. package/assets/preview-app/css.d.ts +0 -5
  311. package/assets/preview-app/gitignore +0 -4
  312. package/assets/preview-app/next.config.mjs +0 -12
  313. package/assets/preview-app/package.json +0 -24
  314. package/assets/preview-app/src/app/globals.css +0 -6
  315. package/assets/preview-app/src/app/layout.tsx +0 -21
  316. package/assets/preview-app/src/app/page.tsx +0 -94
  317. package/assets/preview-app/src/app/providers.tsx +0 -16
  318. package/assets/preview-app/tsconfig.json +0 -27
  319. package/clients/cli/commands/experimental/theme.mjs +0 -2990
  320. package/clients/cli/commands/experimental-theme-add.doc.mjs +0 -80
  321. package/clients/cli/commands/experimental-theme-compile.doc.mjs +0 -98
  322. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +0 -196
  323. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -174
  324. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +0 -139
  325. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +0 -77
  326. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +0 -105
  327. package/clients/cli/commands/experimental-theme-editor.doc.mjs +0 -49
  328. package/clients/cli/commands/experimental-theme-eject.doc.mjs +0 -72
  329. package/clients/cli/commands/experimental-theme-list.doc.mjs +0 -49
  330. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +0 -88
  331. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +0 -61
  332. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +0 -48
  333. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +0 -59
  334. package/clients/cli/commands/experimental-theme-preview.doc.mjs +0 -41
  335. package/clients/cli/commands/experimental-theme-remove.doc.mjs +0 -57
  336. package/clients/cli/commands/experimental-theme-targets.doc.mjs +0 -62
  337. package/clients/cli/commands/experimental-theme-template.doc.mjs +0 -63
  338. package/clients/cli/commands/experimental-theme-use.doc.mjs +0 -57
  339. package/clients/cli/commands/experimental-theme.doc.mjs +0 -60
  340. package/foundation/fonts/fontsource-families.generated.d.mts +0 -5
  341. package/foundation/fonts/fontsource-families.generated.mjs +0 -2110
@@ -0,0 +1,149 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Whether an app loads its fonts with Next.js `next/font`.
5
+ * @input a folder in the project
6
+ * @output true when the project's root layout or custom App loads next/font, directly, through the geist package, or through a module of the app's own it imports
7
+ * @position shared by `doctor`'s theme-fonts check and `theme build`'s font notes, so their fix names the recipe a next/font app needs
8
+ */
9
+
10
+ import * as fs from 'node:fs';
11
+ import * as path from 'node:path';
12
+ import {findThemeProject} from '../config/theme-state.mjs';
13
+ import {
14
+ APP_ROOT_LAYOUT_FILES,
15
+ PAGES_APP_FILES,
16
+ parseAppModule,
17
+ } from '../discovery/app-layout.mjs';
18
+ import {resolveLocalModule} from '../discovery/module-exports.mjs';
19
+ import {pathsFor, resolvePath} from '../render/ts-paths.mjs';
20
+
21
+ /** The modules that load a font through next/font. */
22
+ const NEXT_FONT_MODULES = new Set(['next/font/google', 'next/font/local']);
23
+
24
+ /**
25
+ * Whether an import loads its font through next/font: next/font itself, or an
26
+ * entry of the `geist` package, each of which wraps `next/font/local`.
27
+ * @param {string} specifier
28
+ */
29
+ function isNextFontImport(specifier) {
30
+ return (
31
+ NEXT_FONT_MODULES.has(specifier) ||
32
+ specifier === 'geist/font' ||
33
+ specifier.startsWith('geist/font/')
34
+ );
35
+ }
36
+
37
+ /**
38
+ * The project folder for `dir`: the nearest folder at or above it with a
39
+ * package.json, as `doctor` finds it, else `dir` itself.
40
+ * @param {string} dir
41
+ */
42
+ function projectOf(dir) {
43
+ try {
44
+ return findThemeProject(dir).projectDir;
45
+ } catch {
46
+ return dir;
47
+ }
48
+ }
49
+
50
+ /**
51
+ * The modules a module file imports or re-exports from (`import … from`,
52
+ * `export … from`), read from its syntax tree, or null when the file is
53
+ * missing or does not parse.
54
+ * @param {string} file
55
+ * @returns {string[] | null}
56
+ */
57
+ function moduleImports(file) {
58
+ let source;
59
+ try {
60
+ source = fs.readFileSync(file, 'utf8');
61
+ } catch {
62
+ return null;
63
+ }
64
+ try {
65
+ return parseAppModule(source).program.body.flatMap(node => {
66
+ if (node.type === 'ImportDeclaration') return [node.source.value];
67
+ if (
68
+ (node.type === 'ExportNamedDeclaration' ||
69
+ node.type === 'ExportAllDeclaration') &&
70
+ node.source != null
71
+ ) {
72
+ return [node.source.value];
73
+ }
74
+ return [];
75
+ });
76
+ } catch {
77
+ return null;
78
+ }
79
+ }
80
+
81
+ /**
82
+ * The file an import of the app's own code names: a relative import as the
83
+ * app's bundler resolves it, or a path alias through the tsconfig paths the
84
+ * importing file reads. A package import gives null.
85
+ * @param {string} specifier
86
+ * @param {string} fromFile
87
+ * @returns {string | null}
88
+ */
89
+ function resolveAppImport(specifier, fromFile) {
90
+ if (specifier.startsWith('.')) {
91
+ return resolveLocalModule(specifier, fromFile, {bundler: true});
92
+ }
93
+ return resolvePath(pathsFor(fromFile), specifier);
94
+ }
95
+
96
+ /**
97
+ * Whether a module loads next/font itself, or through a module of the app's
98
+ * own that it imports and that itself imports or re-exports next/font (one
99
+ * level, as a layout imports its fonts from `./fonts` or `@/app/fonts`).
100
+ * @param {string} file
101
+ * @param {string[]} imports
102
+ */
103
+ function loadsNextFont(file, imports) {
104
+ if (imports.some(isNextFontImport)) return true;
105
+ return imports.some(specifier => {
106
+ const target = resolveAppImport(specifier, file);
107
+ const nested = target == null ? null : moduleImports(target);
108
+ return nested != null && nested.some(isNextFontImport);
109
+ });
110
+ }
111
+
112
+ /**
113
+ * Whether the project loads its fonts with next/font: its App Router root
114
+ * layout or its Pages Router custom App imports `next/font/google`,
115
+ * `next/font/local` or a `geist/font` entry, itself or through a module of
116
+ * the app's own it imports that itself imports or re-exports one (such as
117
+ * `./fonts`, or `@/app/fonts` through the app's tsconfig or jsconfig
118
+ * paths). A package.json `imports` alias (`#fonts`), a `baseUrl`-only
119
+ * path, and a font loaded two modules away are not followed. next/font loads each family under a name of its own
120
+ * and exposes a CSS variable, so a theme that names the family itself does
121
+ * not use the loaded font. Imports are read from the syntax tree, so a
122
+ * mention in a comment or a string does not count. A file that does not
123
+ * parse counts as no import.
124
+ * @param {string} dir a folder in the project
125
+ * @returns {boolean}
126
+ */
127
+ export function rootLayoutImportsNextFont(dir) {
128
+ const projectDir = projectOf(dir);
129
+ for (const files of [APP_ROOT_LAYOUT_FILES, PAGES_APP_FILES]) {
130
+ for (const name of files) {
131
+ const file = path.join(projectDir, name);
132
+ const imports = moduleImports(file);
133
+ if (imports == null) continue;
134
+ if (loadsNextFont(file, imports)) return true;
135
+ break;
136
+ }
137
+ }
138
+ return false;
139
+ }
140
+
141
+ /**
142
+ * The fix for a family a next/font app's own theme names but does not load:
143
+ * point the theme's family at the font's CSS variable.
144
+ * @param {string} recipe the command that prints the next/font recipe
145
+ * @returns {string}
146
+ */
147
+ export function nextFontFix(recipe) {
148
+ return `This app loads fonts with next/font, which loads each family under a name of its own: set the theme's font family to the font's CSS variable, for example family: 'var(--font-geist-sans)' (recipe: ${recipe})`;
149
+ }
@@ -4,8 +4,8 @@
4
4
  * @file Taking back the empty folders a write made, never a folder with a
5
5
  * file in it.
6
6
  *
7
- * @position foundation/fs — used by the theme editor (a copy and the themes
8
- * root it made) and `theme add`/`theme remove` of a shared theme
7
+ * @position foundation/fs — used by `theme add`/`theme remove` of a shared
8
+ * theme
9
9
  */
10
10
 
11
11
  import * as fs from 'node:fs';
@@ -266,10 +266,17 @@ function installRecorder() {
266
266
  if (!runs || !(typeof target === 'string' || target instanceof URL)) {
267
267
  return original.apply(this, args);
268
268
  }
269
- const file =
270
- typeof target === 'string'
271
- ? path.resolve(target)
272
- : fileURLToPath(target);
269
+ let file;
270
+ try {
271
+ file =
272
+ typeof target === 'string'
273
+ ? path.resolve(target)
274
+ : fileURLToPath(target);
275
+ } catch {
276
+ // A URL that names no local file reaches the original unrecorded, so
277
+ // it behaves as it does outside a run: the promise API rejects.
278
+ return original.apply(this, args);
279
+ }
273
280
  if (kind !== 'realpath') {
274
281
  // Its state is taken when it is first read, before the read, so a
275
282
  // change made while the operation runs shows as a change afterwards.
@@ -38,7 +38,7 @@ export function newPictureRun(): PictureRun;
38
38
  * (`from`)
39
39
  * @param {Array<{html: string, png: string, mode: 'light' | 'dark', boxes?: string[], window?: {width: number, height: number, mobile?: boolean}}>} jobs
40
40
  * absolute paths; `boxes`: parts whose drawn sizes the picture measures;
41
- * a job's `window` replaces the editor's window (picture-window.mjs), such
41
+ * a job's `window` replaces the default window (picture-window.mjs), such
42
42
  * as a phone's
43
43
  * @param {PictureRun} [run] what earlier pictures of the same run learned:
44
44
  * a browser that failed or hung there is not tried again
@@ -70,48 +70,6 @@ export function takePictures(at: {
70
70
  * @returns {string[]}
71
71
  */
72
72
  export function pictureFontNotes(stdout: string): string[];
73
- /**
74
- * The text a picture script measured cut short, from the line it prints
75
- * after `CUT_SHORT_PREFIX`; nothing when it printed none that reads.
76
- * @param {string} stdout what the picture script printed
77
- * @returns {{cutShort?: Array<{part: string | null, text: string, whole: boolean, broken?: boolean, overlaps?: boolean}>}}
78
- */
79
- export function measuredCutShort(stdout: string): {
80
- cutShort?: Array<{
81
- part: string | null;
82
- text: string;
83
- whole: boolean;
84
- broken?: boolean;
85
- overlaps?: boolean;
86
- }>;
87
- };
88
- /**
89
- * The text a picture script measured too faint to read, from the line it
90
- * prints after `LOW_CONTRAST_PREFIX`; nothing when it printed none that
91
- * reads.
92
- * @param {string} stdout what the picture script printed
93
- * @returns {{lowContrast?: Array<{part: string, text: string, ratio: number, fg: string, bg: string}>}}
94
- */
95
- export function measuredLowContrast(stdout: string): {
96
- lowContrast?: Array<{
97
- part: string;
98
- text: string;
99
- ratio: number;
100
- fg: string;
101
- bg: string;
102
- }>;
103
- };
104
- /**
105
- * The part sizes a picture script measured, from the line it prints after
106
- * `PART_BOXES_PREFIX`; nothing when it printed none that reads.
107
- * @param {string} stdout what the picture script printed
108
- * @returns {{boxes?: Record<string, Array<[number, number]>>}}
109
- */
110
- export function measuredBoxes(stdout: string): {
111
- boxes?: Record<string, Array<[number, number]>>;
112
- };
113
- /** A Chrome or Chromium on this machine, at a usual place or on PATH. */
114
- export function chromeBinary(): string | null;
115
73
  /**
116
74
  * Run a picture script (one browser, one picture) as its own process group,
117
75
  * without blocking this process. The one owner of every browser run:
@@ -150,8 +108,6 @@ export function runBrowser(script: string, args: string[], bound?: number, opts?
150
108
  * @param {string} text
151
109
  */
152
110
  export function meaningfulLine(text: string): string;
153
- /** How long a browser may take for one picture before it is stopped. */
154
- export const BROWSER_BOUND_MS: 60000;
155
111
  /**
156
112
  * What the pictures of one run share: the browsers that failed or hung,
157
113
  * each with its reason, so a later picture does not wait on them again.
@@ -9,8 +9,8 @@
9
9
  * sizes it measures
10
10
  * @output each picture taken, with what the browser measured in it, or why
11
11
  * none was, with the facts a caller words its own advice from
12
- * @position used by the theme editor's previews (api/theme-edit/_preview.mjs)
13
- * and by `astryx experimental export --pictures` (api/render/_adapter.mjs);
12
+ * @position used by `astryx experimental export --pictures`
13
+ * (api/render/_adapter.mjs);
14
14
  * runs the picture scripts in foundation/render (picture-playwright.mjs,
15
15
  * picture-chrome.mjs)
16
16
  */
@@ -44,7 +44,7 @@ const STOP_GRACE_MS = 5_000;
44
44
  const STOP_SIGNALS = /** @type {const} */ (['SIGINT', 'SIGTERM', 'SIGHUP']);
45
45
 
46
46
  /** How long a browser may take for one picture before it is stopped. */
47
- export const BROWSER_BOUND_MS = 60_000;
47
+ const BROWSER_BOUND_MS = 60_000;
48
48
 
49
49
  /**
50
50
  * What the pictures of one run share: the browsers that failed or hung,
@@ -91,7 +91,7 @@ const PAGE_BOUND_MS = 20_000;
91
91
  * (`from`)
92
92
  * @param {Array<{html: string, png: string, mode: 'light' | 'dark', boxes?: string[], window?: {width: number, height: number, mobile?: boolean}}>} jobs
93
93
  * absolute paths; `boxes`: parts whose drawn sizes the picture measures;
94
- * a job's `window` replaces the editor's window (picture-window.mjs), such
94
+ * a job's `window` replaces the default window (picture-window.mjs), such
95
95
  * as a phone's
96
96
  * @param {PictureRun} [run] what earlier pictures of the same run learned:
97
97
  * a browser that failed or hung there is not tried again
@@ -273,7 +273,7 @@ export function pictureFontNotes(stdout) {
273
273
  * @param {string} stdout what the picture script printed
274
274
  * @returns {{cutShort?: Array<{part: string | null, text: string, whole: boolean, broken?: boolean, overlaps?: boolean}>}}
275
275
  */
276
- export function measuredCutShort(stdout) {
276
+ function measuredCutShort(stdout) {
277
277
  const line = stdout.split('\n').find(l => l.startsWith(CUT_SHORT_PREFIX));
278
278
  if (!line) return {};
279
279
  /** @type {unknown} */
@@ -304,7 +304,7 @@ export function measuredCutShort(stdout) {
304
304
  * @param {string} stdout what the picture script printed
305
305
  * @returns {{lowContrast?: Array<{part: string, text: string, ratio: number, fg: string, bg: string}>}}
306
306
  */
307
- export function measuredLowContrast(stdout) {
307
+ function measuredLowContrast(stdout) {
308
308
  const line = stdout.split('\n').find(l => l.startsWith(LOW_CONTRAST_PREFIX));
309
309
  if (!line) return {};
310
310
  /** @type {unknown} */
@@ -334,7 +334,7 @@ export function measuredLowContrast(stdout) {
334
334
  * @param {string} stdout what the picture script printed
335
335
  * @returns {{boxes?: Record<string, Array<[number, number]>>}}
336
336
  */
337
- export function measuredBoxes(stdout) {
337
+ function measuredBoxes(stdout) {
338
338
  const line = stdout.split('\n').find(l => l.startsWith(PART_BOXES_PREFIX));
339
339
  if (!line) return {};
340
340
  /** @type {unknown} */
@@ -359,7 +359,7 @@ export function measuredBoxes(stdout) {
359
359
  }
360
360
 
361
361
  /** A Chrome or Chromium on this machine, at a usual place or on PATH. */
362
- export function chromeBinary() {
362
+ function chromeBinary() {
363
363
  const names = [
364
364
  'google-chrome',
365
365
  'google-chrome-stable',
@@ -9,7 +9,8 @@
9
9
  * @input a lock folder and the work to run under it
10
10
  * @output the work's result; the lock is released on the way out, also on
11
11
  * Ctrl-C, and only when it is still this run's own
12
- * @position foundation/release — used by the theme editor (api/theme-edit/_adapter.mjs).
12
+ * @position foundation/release — `stillHolds` is read by
13
+ * api/integration/add-helpers.mjs.
13
14
  */
14
15
 
15
16
  import * as fs from 'node:fs';
@@ -142,7 +143,7 @@ export async function withFolderLock(
142
143
  // computer whose processes this run cannot check).
143
144
  for (let waited = 0; !tryLock(lockDir, {leased: true}); waited += 50) {
144
145
  // The release cache's own judge of silence (what this process saw of
145
- // the record), with the editor's shorter window. The lock is judged by
146
+ // the record), with a shorter window. The lock is judged by
146
147
  // its identity on disk, so the one moved aside is the one judged.
147
148
  const judged = lockIdentity(lockDir);
148
149
  if (
@@ -40,8 +40,8 @@ export function cutShortText(): Array<{
40
40
  * (`flex-shrink: 0` on it, the line the editor offers) draws it whole;
41
41
  * `CUT_SHORT_PREFIX`, the line prefix a picture script prints it after.
42
42
  * @position run by picture-chrome.mjs and picture-playwright.mjs once the
43
- * page is drawn as the picture shows it; read back by `screenshot` in
44
- * api/theme-edit/_preview.mjs from the script's stdout
43
+ * page is drawn as the picture shows it; read back by `takePictures` in
44
+ * foundation/pictures/pictures.mjs from the script's stdout
45
45
  */
46
46
  /** The line prefix a picture script prints the measurement after. */
47
47
  export const CUT_SHORT_PREFIX: "astryx-cut-short:";
@@ -11,8 +11,8 @@
11
11
  * (`flex-shrink: 0` on it, the line the editor offers) draws it whole;
12
12
  * `CUT_SHORT_PREFIX`, the line prefix a picture script prints it after.
13
13
  * @position run by picture-chrome.mjs and picture-playwright.mjs once the
14
- * page is drawn as the picture shows it; read back by `screenshot` in
15
- * api/theme-edit/_preview.mjs from the script's stdout
14
+ * page is drawn as the picture shows it; read back by `takePictures` in
15
+ * foundation/pictures/pictures.mjs from the script's stdout
16
16
  */
17
17
 
18
18
  /* global document, getComputedStyle, HTMLElement -- cutShortText runs in the page */
@@ -33,8 +33,8 @@ export function lowContrastText(): Array<{
33
33
  * two colors as drawn; `LOW_CONTRAST_PREFIX`, the line prefix a picture
34
34
  * script prints it after.
35
35
  * @position run by picture-chrome.mjs and picture-playwright.mjs once the
36
- * page is drawn as the picture shows it; read back by `screenshot` in
37
- * api/theme-edit/_preview.mjs from the script's stdout
36
+ * page is drawn as the picture shows it; read back by `takePictures` in
37
+ * foundation/pictures/pictures.mjs from the script's stdout
38
38
  */
39
39
  /** The line prefix a picture script prints the measurement after. */
40
40
  export const LOW_CONTRAST_PREFIX: "astryx-low-contrast:";
@@ -9,8 +9,8 @@
9
9
  * two colors as drawn; `LOW_CONTRAST_PREFIX`, the line prefix a picture
10
10
  * script prints it after.
11
11
  * @position run by picture-chrome.mjs and picture-playwright.mjs once the
12
- * page is drawn as the picture shows it; read back by `screenshot` in
13
- * api/theme-edit/_preview.mjs from the script's stdout
12
+ * page is drawn as the picture shows it; read back by `takePictures` in
13
+ * foundation/pictures/pictures.mjs from the script's stdout
14
14
  */
15
15
 
16
16
  /* global document, getComputedStyle -- lowContrastText runs in the page */
@@ -20,8 +20,8 @@ export function probeFonts(send: (method: string, params?: Record<string, unknow
20
20
  * result after.
21
21
  * @position Run by the picture scripts (picture-chrome.mjs,
22
22
  * picture-playwright.mjs) after the picture is taken; read by
23
- * `screenshot` in api/theme-edit/_preview.mjs, which names a stack this
24
- * machine has none of the families for.
23
+ * `pictureFontNotes` in foundation/pictures/pictures.mjs, which names a
24
+ * stack this machine has none of the families for.
25
25
  */
26
26
  /** The line prefix a picture script prints the probe's result after. */
27
27
  export const FONT_PROBE_PREFIX: "astryx-fonts:";
@@ -9,8 +9,8 @@
9
9
  * result after.
10
10
  * @position Run by the picture scripts (picture-chrome.mjs,
11
11
  * picture-playwright.mjs) after the picture is taken; read by
12
- * `screenshot` in api/theme-edit/_preview.mjs, which names a stack this
13
- * machine has none of the families for.
12
+ * `pictureFontNotes` in foundation/pictures/pictures.mjs, which names a
13
+ * stack this machine has none of the families for.
14
14
  */
15
15
 
16
16
  /** The line prefix a picture script prints the probe's result after. */
@@ -18,8 +18,7 @@
18
18
  * {@link layerPlaceholder} gives through the global the worker installs, and
19
19
  * the worker puts the part there, drawn, with each overlay it opened after it.
20
20
  *
21
- * @position foundation/render — used by page-worker.mjs and by pages the
22
- * theme editor writes (_catalog.mjs)
21
+ * @position foundation/render — used by page-worker.mjs
23
22
  */
24
23
 
25
24
  import {desktopMatches} from './picture-window.mjs';
@@ -17,8 +17,9 @@ export function installedPackageOf(file: string): string | null;
17
17
  */
18
18
  /**
19
19
  * Lookups that one set of hooks keeps: each folder's package.json, read once,
20
- * and the folders of the linked packages bare imports reached.
21
- * @typedef {{manifests: Map<string, FolderManifest>, linked: Set<string>}} PackageLookups
20
+ * the folders of the linked packages bare imports reached, and the answers to
21
+ * package names and `#` imports, by folderKey.
22
+ * @typedef {{manifests: Map<string, FolderManifest>, linked: Set<string>, byFolder: Map<string, object>}} PackageLookups
22
23
  */
23
24
  /** @returns {PackageLookups} */
24
25
  export function packageLookups(): PackageLookups;
@@ -31,6 +32,18 @@ export function packageLookups(): PackageLookups;
31
32
  * @returns {string | null}
32
33
  */
33
34
  export function linkedPackageOf(file: string, lookups: PackageLookups): string | null;
35
+ /**
36
+ * Notes `folder` as the folder of the linked package `name`: a folder
37
+ * outside node_modules whose package.json names `name`, as the real folder
38
+ * of a link `node_modules/<name>` is, or the folder a bare import of `name`
39
+ * reached (see noteLinkedPackage). A folder `skip` refuses is not noted.
40
+ * @param {string} name
41
+ * @param {string} folder
42
+ * @param {PackageLookups} lookups
43
+ * @param {(folder: string) => boolean} skip - takes the folder with a
44
+ * trailing separator
45
+ */
46
+ export function noteLinkedFolder(name: string, folder: string, lookups: PackageLookups, skip: (folder: string) => boolean): void;
34
47
  /**
35
48
  * The URL of the ES module that `specifier` names from `parent`, when both
36
49
  * are files of one installed package and Node would load it as an ES module;
@@ -47,7 +60,10 @@ export function linkedPackageOf(file: string, lookups: PackageLookups): string |
47
60
  export function packageModuleUrl(specifier: string, parent: string | undefined, lookups: PackageLookups): string | null;
48
61
  /**
49
62
  * Module hooks that resolve imports between the files of an installed or a
50
- * linked package by path.
63
+ * linked package by path, and each package name or `#` import that ES
64
+ * modules import once for each folder it is imported from. What the next resolvers answered there
65
+ * (single-copy-hooks.mjs among them, which decides by the name) is the
66
+ * answer kept.
51
67
  * @param {PackageLookups} [lookups]
52
68
  * @param {{skip?: (folder: string) => boolean}} [options] - `skip`: a folder
53
69
  * never taken as a linked package's (the page's own folders)
@@ -57,11 +73,13 @@ export function packageResolveHooks(lookups?: PackageLookups, { skip }?: {
57
73
  }): {
58
74
  /**
59
75
  * @param {string} specifier
60
- * @param {{parentURL?: string}} context
76
+ * @param {{parentURL?: string, conditions?: readonly string[], importAttributes?: object}} context
61
77
  * @param {(specifier: string, context: any) => any} nextResolve
62
78
  */
63
79
  resolve(specifier: string, context: {
64
80
  parentURL?: string;
81
+ conditions?: readonly string[];
82
+ importAttributes?: object;
65
83
  }, nextResolve: (specifier: string, context: any) => any): any;
66
84
  };
67
85
  /**
@@ -75,9 +93,11 @@ export type FolderManifest = {
75
93
  } | null | undefined;
76
94
  /**
77
95
  * Lookups that one set of hooks keeps: each folder's package.json, read once,
78
- * and the folders of the linked packages bare imports reached.
96
+ * the folders of the linked packages bare imports reached, and the answers to
97
+ * package names and `#` imports, by folderKey.
79
98
  */
80
99
  export type PackageLookups = {
81
100
  manifests: Map<string, FolderManifest>;
82
101
  linked: Set<string>;
102
+ byFolder: Map<string, object>;
83
103
  };
@@ -8,13 +8,18 @@
8
8
  * @output Module hooks whose resolve step answers a relative, fully
9
9
  * specified ES module import between two files of one installed package,
10
10
  * or of one linked package (one a bare import reached outside
11
- * node_modules), with the file's URL; every other import goes on to the
12
- * next resolver, and its answer is returned as it is.
11
+ * node_modules), with the file's URL, and a package name or a `#` import
12
+ * that an ES module imports from a folder it was already resolved from,
13
+ * with the answer it got there; every other import goes on to the next
14
+ * resolver, and its answer is returned as it is.
13
15
  * @position foundation/render. Node reads the nearest package.json of each
14
16
  * module it resolves and loads, and it reads a package's whole manifest
15
17
  * again for each module, so a package of hundreds of modules (Core) reads
16
18
  * its exports map hundreds of times. The hook reads the package.json of
17
- * each folder at most once. Page files never reach it.
19
+ * each folder at most once. Node also resolves a package name again for
20
+ * each module that imports it (each Core module imports React and
21
+ * StyleX); the hook resolves it once for each folder. Page files never
22
+ * reach it.
18
23
  */
19
24
 
20
25
  import * as fs from 'node:fs';
@@ -52,13 +57,14 @@ export function installedPackageOf(file) {
52
57
 
53
58
  /**
54
59
  * Lookups that one set of hooks keeps: each folder's package.json, read once,
55
- * and the folders of the linked packages bare imports reached.
56
- * @typedef {{manifests: Map<string, FolderManifest>, linked: Set<string>}} PackageLookups
60
+ * the folders of the linked packages bare imports reached, and the answers to
61
+ * package names and `#` imports, by folderKey.
62
+ * @typedef {{manifests: Map<string, FolderManifest>, linked: Set<string>, byFolder: Map<string, object>}} PackageLookups
57
63
  */
58
64
 
59
65
  /** @returns {PackageLookups} */
60
66
  export function packageLookups() {
61
- return {manifests: new Map(), linked: new Set()};
67
+ return {manifests: new Map(), linked: new Set(), byFolder: new Map()};
62
68
  }
63
69
 
64
70
  /**
@@ -137,18 +143,67 @@ function noteLinkedPackage(specifier, url, lookups, skip) {
137
143
  const file = fileURLToPath(url);
138
144
  if (file.includes(NODE_MODULES)) return;
139
145
  const found = nearestManifest(path.dirname(file), lookups);
140
- if (
141
- found &&
142
- found.name === packageOf(specifier) &&
143
- !skip(found.dir + path.sep)
144
- )
145
- lookups.linked.add(found.dir);
146
+ if (found) noteLinkedFolder(packageOf(specifier), found.dir, lookups, skip);
147
+ }
148
+
149
+ /**
150
+ * Notes `folder` as the folder of the linked package `name`: a folder
151
+ * outside node_modules whose package.json names `name`, as the real folder
152
+ * of a link `node_modules/<name>` is, or the folder a bare import of `name`
153
+ * reached (see noteLinkedPackage). A folder `skip` refuses is not noted.
154
+ * @param {string} name
155
+ * @param {string} folder
156
+ * @param {PackageLookups} lookups
157
+ * @param {(folder: string) => boolean} skip - takes the folder with a
158
+ * trailing separator
159
+ */
160
+ export function noteLinkedFolder(name, folder, lookups, skip) {
161
+ if ((folder + path.sep).includes(NODE_MODULES)) return;
162
+ if (manifestAt(folder, lookups)?.name === name && !skip(folder + path.sep))
163
+ lookups.linked.add(folder);
146
164
  }
147
165
 
148
166
  /** Whether a specifier names a package (not a path, a URL or an import map entry). @param {string} specifier */
149
167
  const isBare = specifier =>
150
168
  !/^[./#]/.test(specifier) && !/^[a-z][a-z0-9+.-]*:/i.test(specifier);
151
169
 
170
+ /**
171
+ * The key of an import whose answer is the same from every file of one
172
+ * folder: a package name or a `#` import that an ES module imports from a
173
+ * file. Node finds a package name in the node_modules folders above the
174
+ * importing file's folder, a self-reference by the package scope of that
175
+ * folder, and a `#` import in that scope's `imports`; the folder fixes all
176
+ * three, so its conditions, in order, and its import attributes are all else
177
+ * that decides the answer. Import attributes with the same entries in
178
+ * another order give another key: that costs a second resolution, never a
179
+ * wrong answer. Null for any other import, and for every CommonJS
180
+ * resolution: `require.resolve` with its `paths` option reaches the hook
181
+ * without them, so the folder does not fix its answer.
182
+ * @param {string} specifier
183
+ * @param {{parentURL?: string, conditions?: readonly string[], importAttributes?: object}} context
184
+ * @returns {string | null}
185
+ */
186
+ function folderKey(specifier, context) {
187
+ const parent = context.parentURL;
188
+ if (parent === undefined || !parent.startsWith('file:')) return null;
189
+ if (!isBare(specifier) && !specifier.startsWith('#')) return null;
190
+ if (context.conditions?.includes('require')) return null;
191
+ return JSON.stringify([
192
+ path.dirname(fileURLToPath(parent)),
193
+ specifier,
194
+ context.conditions ?? [],
195
+ context.importAttributes ?? {},
196
+ ]);
197
+ }
198
+
199
+ /**
200
+ * Whether an answer is kept for its folder: one that names a file or a
201
+ * built-in module. A resolution that throws is never kept.
202
+ * @param {any} resolved
203
+ */
204
+ const keptForFolder = resolved =>
205
+ typeof resolved?.url === 'string' && /^(?:file|node):/.test(resolved.url);
206
+
152
207
  /**
153
208
  * The `type` of the package.json nearest `dir`, searched up to `root`
154
209
  * included: a string, null when the folders hold none, or undefined when one
@@ -209,7 +264,10 @@ export function packageModuleUrl(specifier, parent, lookups) {
209
264
 
210
265
  /**
211
266
  * Module hooks that resolve imports between the files of an installed or a
212
- * linked package by path.
267
+ * linked package by path, and each package name or `#` import that ES
268
+ * modules import once for each folder it is imported from. What the next resolvers answered there
269
+ * (single-copy-hooks.mjs among them, which decides by the name) is the
270
+ * answer kept.
213
271
  * @param {PackageLookups} [lookups]
214
272
  * @param {{skip?: (folder: string) => boolean}} [options] - `skip`: a folder
215
273
  * never taken as a linked package's (the page's own folders)
@@ -221,15 +279,20 @@ export function packageResolveHooks(
221
279
  return {
222
280
  /**
223
281
  * @param {string} specifier
224
- * @param {{parentURL?: string}} context
282
+ * @param {{parentURL?: string, conditions?: readonly string[], importAttributes?: object}} context
225
283
  * @param {(specifier: string, context: any) => any} nextResolve
226
284
  */
227
285
  resolve(specifier, context, nextResolve) {
228
286
  const url = packageModuleUrl(specifier, context.parentURL, lookups);
229
287
  if (url !== null) return {url, format: 'module', shortCircuit: true};
288
+ const key = folderKey(specifier, context);
289
+ const kept = key === null ? undefined : lookups.byFolder.get(key);
290
+ if (kept !== undefined) return {...kept, shortCircuit: true};
230
291
  const resolved = nextResolve(specifier, context);
231
292
  if (isBare(specifier))
232
293
  noteLinkedPackage(specifier, resolved?.url, lookups, skip);
294
+ if (key !== null && keptForFolder(resolved))
295
+ lookups.byFolder.set(key, {...resolved});
233
296
  return resolved;
234
297
  },
235
298
  };