@astryxdesign/cli 0.7.4 → 0.7.5-canary.0026f37

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 (235) hide show
  1. package/README.md +18 -18
  2. package/api/component/_adapter.mjs +16 -1
  3. package/api/component/component.test.mjs +31 -0
  4. package/api/discover/_adapter.d.mts +1 -1
  5. package/api/docs/_adapter.d.mts +5 -2
  6. package/api/docs/_adapter.mjs +24 -16
  7. package/api/docs/docs.test.mjs +18 -0
  8. package/api/docs/integrationDocs.test.mjs +2 -2
  9. package/api/experimental.d.mts +5 -0
  10. package/api/experimental.mjs +15 -0
  11. package/api/hook/list/list.d.mts +1 -1
  12. package/api/icon/_adapter.d.mts +3 -2
  13. package/api/icon/_adapter.mjs +16 -3
  14. package/api/icon/_authoring.d.mts +5 -1
  15. package/api/icon/_authoring.mjs +478 -63
  16. package/api/icon/_options.d.mts +11 -0
  17. package/api/icon/_options.mjs +39 -4
  18. package/api/icon/_records.d.mts +19 -0
  19. package/api/icon/_records.mjs +25 -0
  20. package/api/icon/add/add.d.mts +3 -3
  21. package/api/icon/add/add.mjs +227 -14
  22. package/api/icon/all-or-nothing.test.mjs +283 -0
  23. package/api/icon/detail/detail.mjs +2 -13
  24. package/api/icon/error-codes.test.mjs +14 -7
  25. package/api/icon/icon.d.mts +2 -2
  26. package/api/icon/icon.doc.mjs +30 -2
  27. package/api/icon/icon.mjs +57 -8
  28. package/api/icon/icon.test.mjs +133 -1
  29. package/api/icon/icon.type.d.mts +126 -1
  30. package/api/icon/icon.type.mjs +67 -3
  31. package/api/icon/iconAdd.doc.mjs +22 -6
  32. package/api/icon/iconMap.doc.mjs +24 -8
  33. package/api/icon/iconNewDefinition.doc.mjs +2 -2
  34. package/api/icon/iconNewSet.doc.mjs +30 -2
  35. package/api/icon/iconUse.doc.mjs +4 -1
  36. package/api/icon/map/map.d.mts +4 -4
  37. package/api/icon/map/map.mjs +134 -9
  38. package/api/icon/new-definition/new-definition.mjs +6 -2
  39. package/api/icon/new-set/new-set.mjs +2 -2
  40. package/api/icon/new-set/new-set.test.mjs +60 -10
  41. package/api/icon/option-pairs.test.mjs +368 -0
  42. package/api/icon/search/search.d.mts +10 -0
  43. package/api/icon/search/search.mjs +55 -14
  44. package/api/icon/use/use.mjs +2 -13
  45. package/api/integration/add-helpers.d.mts +15 -1
  46. package/api/integration/add-helpers.mjs +1 -1
  47. package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
  48. package/api/integration/pack-check.mjs +10 -4
  49. package/api/integration/pack-check.test.mjs +5 -1
  50. package/api/integration/validate-integration.type.d.mts +3 -2
  51. package/api/integration/validate-integration.type.mjs +3 -2
  52. package/api/render/_adapter.d.mts +28 -0
  53. package/api/render/_adapter.mjs +540 -0
  54. package/api/render/render.d.mts +15 -0
  55. package/api/render/render.doc.d.mts +9 -0
  56. package/api/render/render.doc.mjs +112 -0
  57. package/api/render/render.mjs +113 -0
  58. package/api/render/render.test.mjs +1155 -0
  59. package/api/render/render.type.d.mts +74 -0
  60. package/api/render/render.type.mjs +64 -0
  61. package/api/search/_adapter.test.mjs +21 -2
  62. package/api/search/_result.d.mts +5 -5
  63. package/api/search/search.d.mts +1 -1
  64. package/api/template/template.mjs +3 -1
  65. package/api/template/template.type.d.mts +2 -1
  66. package/api/template/template.type.mjs +1 -1
  67. package/api/template/unknown-name.test.mjs +63 -0
  68. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +123 -70
  69. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +19 -77
  70. package/assets/discover/official-packages.json +4 -0
  71. package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
  72. package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
  73. package/assets/docs/tree/icon-sets.doc.mjs +50 -20
  74. package/assets/docs/tree/render-pages.doc.mjs +94 -0
  75. package/assets/icons/definitions/activity.doc.mjs +1 -1
  76. package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
  77. package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
  78. package/assets/icons/definitions/alignStart.doc.mjs +10 -0
  79. package/assets/icons/definitions/archive.doc.mjs +1 -1
  80. package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
  81. package/assets/icons/definitions/attach.doc.mjs +1 -1
  82. package/assets/icons/definitions/audio.doc.mjs +1 -1
  83. package/assets/icons/definitions/cart.doc.mjs +1 -1
  84. package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
  85. package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
  86. package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
  87. package/assets/icons/definitions/close.doc.mjs +1 -1
  88. package/assets/icons/definitions/collapse.doc.mjs +1 -1
  89. package/assets/icons/definitions/compose.doc.mjs +1 -1
  90. package/assets/icons/definitions/conversation.doc.mjs +1 -1
  91. package/assets/icons/definitions/copy.doc.mjs +1 -1
  92. package/assets/icons/definitions/cpu.doc.mjs +9 -0
  93. package/assets/icons/definitions/database.doc.mjs +1 -1
  94. package/assets/icons/definitions/desktop.doc.mjs +1 -1
  95. package/assets/icons/definitions/discount.doc.mjs +1 -1
  96. package/assets/icons/definitions/download.doc.mjs +1 -1
  97. package/assets/icons/definitions/emoji.doc.mjs +1 -1
  98. package/assets/icons/definitions/error.doc.mjs +1 -1
  99. package/assets/icons/definitions/expand.doc.mjs +1 -1
  100. package/assets/icons/definitions/experiment.doc.mjs +1 -1
  101. package/assets/icons/definitions/externalLink.doc.mjs +7 -1
  102. package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
  103. package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
  104. package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
  105. package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
  106. package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
  107. package/assets/icons/definitions/gitFork.doc.mjs +9 -0
  108. package/assets/icons/definitions/info.doc.mjs +1 -1
  109. package/assets/icons/definitions/location.doc.mjs +1 -1
  110. package/assets/icons/definitions/mention.doc.mjs +1 -1
  111. package/assets/icons/definitions/menu.doc.mjs +1 -1
  112. package/assets/icons/definitions/microphone.doc.mjs +1 -1
  113. package/assets/icons/definitions/mobile.doc.mjs +1 -1
  114. package/assets/icons/definitions/money.doc.mjs +1 -1
  115. package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
  116. package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
  117. package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
  118. package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
  119. package/assets/icons/definitions/panelRight.doc.mjs +10 -0
  120. package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
  121. package/assets/icons/definitions/redo.doc.mjs +1 -1
  122. package/assets/icons/definitions/refresh.doc.mjs +1 -1
  123. package/assets/icons/definitions/rotate.doc.mjs +9 -0
  124. package/assets/icons/definitions/scale.doc.mjs +10 -0
  125. package/assets/icons/definitions/search.doc.mjs +1 -1
  126. package/assets/icons/definitions/send.doc.mjs +1 -1
  127. package/assets/icons/definitions/settings.doc.mjs +1 -1
  128. package/assets/icons/definitions/star.doc.mjs +1 -1
  129. package/assets/icons/definitions/stop.doc.mjs +1 -1
  130. package/assets/icons/definitions/success.doc.mjs +1 -1
  131. package/assets/icons/definitions/textCase.doc.mjs +9 -0
  132. package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
  133. package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
  134. package/assets/icons/definitions/trendDown.doc.mjs +7 -1
  135. package/assets/icons/definitions/trendUp.doc.mjs +1 -1
  136. package/assets/icons/definitions/undo.doc.mjs +1 -1
  137. package/assets/icons/definitions/upload.doc.mjs +1 -1
  138. package/assets/icons/definitions/userAdd.doc.mjs +1 -1
  139. package/assets/icons/definitions/warning.doc.mjs +1 -1
  140. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
  141. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
  142. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
  143. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
  144. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
  145. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
  146. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
  147. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
  148. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
  149. package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
  150. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
  151. package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
  152. package/authoring/debug/parse.d.mts +2 -2
  153. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
  154. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
  155. package/authoring/doctypes/icon-set/parse.d.mts +1 -0
  156. package/authoring/doctypes/icon-set/parse.mjs +1 -0
  157. package/authoring/doctypes/icon-set/type.ts +5 -0
  158. package/authoring/doctypes/template/template.doc.mjs +1 -1
  159. package/authoring/doctypes/template/type.ts +2 -1
  160. package/clients/cli/commands/doctor.mjs +16 -17
  161. package/clients/cli/commands/experimental/icon.mjs +167 -35
  162. package/clients/cli/commands/experimental/index.mjs +2 -0
  163. package/clients/cli/commands/experimental/render.mjs +113 -0
  164. package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
  165. package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
  166. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
  167. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
  168. package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
  169. package/clients/cli/commands/experimental-render.doc.mjs +60 -0
  170. package/clients/cli/commands/experimental.doc.mjs +4 -2
  171. package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
  172. package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
  173. package/clients/cli/commands/icon.test.mjs +1 -1
  174. package/clients/cli/commands/template.mjs +4 -1
  175. package/clients/cli/commands/text-json-parity.test.mjs +46 -0
  176. package/clients/cli/index.mjs +1 -0
  177. package/foundation/discovery/component-discovery.d.mts +2 -1
  178. package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
  179. package/foundation/discovery/component-discovery.mjs +13 -7
  180. package/foundation/discovery/icon-set-checks.d.mts +43 -9
  181. package/foundation/discovery/icon-set-checks.mjs +296 -21
  182. package/foundation/discovery/icon-set-checks.test.mjs +125 -12
  183. package/foundation/discovery/icon-set-writer.d.mts +192 -3
  184. package/foundation/discovery/icon-set-writer.mjs +608 -34
  185. package/foundation/discovery/icon-set-writer.test.mjs +26 -0
  186. package/foundation/discovery/module-exports.mjs +82 -25
  187. package/foundation/discovery/module-exports.test.mjs +38 -1
  188. package/foundation/discovery/package-exports.d.mts +13 -0
  189. package/foundation/discovery/package-exports.mjs +40 -1
  190. package/foundation/discovery/template-icons.d.mts +6 -0
  191. package/foundation/discovery/template-icons.mjs +98 -10
  192. package/foundation/discovery/template-icons.test.mjs +103 -0
  193. package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
  194. package/foundation/doc-compiler/import.mjs +81 -8
  195. package/foundation/doc-compiler/read.d.mts +4 -3
  196. package/foundation/doc-compiler/read.mjs +15 -10
  197. package/foundation/doc-compiler/read.test.mjs +59 -1
  198. package/foundation/doc-compiler/tree.mjs +3 -1
  199. package/foundation/fs/module-loader.d.mts +3 -2
  200. package/foundation/fs/module-loader.mjs +3 -2
  201. package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
  202. package/foundation/fs/read-record.d.mts +27 -0
  203. package/foundation/fs/read-record.mjs +83 -15
  204. package/foundation/fs/read-record.test.mjs +88 -1
  205. package/foundation/render/assets.d.mts +31 -0
  206. package/foundation/render/assets.mjs +102 -0
  207. package/foundation/render/component-map.d.mts +52 -0
  208. package/foundation/render/component-map.mjs +141 -0
  209. package/foundation/render/css-cut.d.mts +29 -0
  210. package/foundation/render/css-cut.mjs +144 -0
  211. package/foundation/render/embedded-files.d.mts +28 -0
  212. package/foundation/render/embedded-files.mjs +108 -0
  213. package/foundation/render/embedded-imports.d.mts +61 -0
  214. package/foundation/render/embedded-imports.mjs +315 -0
  215. package/foundation/render/html-reader.d.mts +37 -0
  216. package/foundation/render/html-reader.mjs +121 -0
  217. package/foundation/render/page-worker.d.mts +7 -0
  218. package/foundation/render/page-worker.mjs +519 -0
  219. package/foundation/render/rebuild.d.mts +19 -0
  220. package/foundation/render/rebuild.mjs +269 -0
  221. package/foundation/render/render-page.d.mts +85 -0
  222. package/foundation/render/render-page.mjs +612 -0
  223. package/foundation/render/render.test.mjs +117 -0
  224. package/foundation/render/source-block.d.mts +52 -0
  225. package/foundation/render/source-block.mjs +106 -0
  226. package/foundation/response/error-codes.d.mts +10 -1
  227. package/foundation/response/error-codes.doc.mjs +56 -0
  228. package/foundation/response/error-codes.mjs +61 -0
  229. package/foundation/response/response-types.doc.mjs +38 -1
  230. package/foundation/text/string-utils.mjs +33 -0
  231. package/foundation/text/string-utils.test.mjs +17 -0
  232. package/foundation/text/suggest-order.d.mts +17 -3
  233. package/foundation/text/suggest-order.mjs +58 -13
  234. package/foundation/text/suggest-order.test.mjs +53 -0
  235. package/package.json +14 -9
@@ -5,7 +5,12 @@
5
5
  * authored doc file.
6
6
  *
7
7
  * @input An absolute path to a `.doc.{ts,mjs,js}` (or legacy template) file.
8
- * @output The module's namespace object.
8
+ * @output The module's namespace object: the one a plain import of the file
9
+ * gives, until the file changes; then the edited file's, read once by each
10
+ * importer, its own way, and shared until the next change. A long-running
11
+ * process (a docs site's search, an agent harness) thereby sees an edit to
12
+ * a doc file it already read, as a new process would read it. Only the doc
13
+ * file's own edits count: a module it imports stays as first loaded.
9
14
  * @position Called by ./read.mjs, which hands what comes back to the compiler,
10
15
  * and by discovery, which reads a contributed topic's name and relationships
11
16
  * to build the catalog. Doc files also run outside these importers: each CLI
@@ -20,10 +25,59 @@
20
25
  import {pathToFileURL} from 'node:url';
21
26
  import {createJiti} from 'jiti';
22
27
  import {importUserModule} from '../fs/module-loader.mjs';
28
+ import {fileStamp, recordContentRead} from '../fs/read-record.mjs';
23
29
 
24
30
  /** @type {ReturnType<typeof createJiti> | undefined} */
25
31
  let jsxJiti;
26
32
 
33
+ /**
34
+ * Each doc file imported in this process: its stamp at the last import and,
35
+ * once it changed, the module each importer read for that change.
36
+ * @type {Map<string, {stamp: string, changed: Record<string, Promise<any>> | null}>}
37
+ */
38
+ const imported = new Map();
39
+
40
+ /** Numbers each fresh native import's URL, so it names a new module. */
41
+ let changes = 0;
42
+
43
+ /**
44
+ * Import `file` with `load` until it changes, then once with `loadFresh` for
45
+ * each change, sharing that module until the next one. Each importer (`kind`)
46
+ * keeps its own module, as each has its own loader. The file counts as read
47
+ * by the running operation (see ../fs/read-record.mjs).
48
+ * @param {string} file
49
+ * @param {'doc' | 'template' | 'native'} kind
50
+ * @param {(file: string) => Promise<any>} load
51
+ * @param {(file: string) => Promise<any>} loadFresh
52
+ * @returns {Promise<any>}
53
+ */
54
+ function importCurrent(file, kind, load, loadFresh) {
55
+ recordContentRead(file);
56
+ const stamp = fileStamp(file);
57
+ let seen = imported.get(file);
58
+ if (!seen) {
59
+ imported.set(file, {stamp, changed: null});
60
+ return load(file);
61
+ }
62
+ if (seen.stamp !== stamp) {
63
+ seen = {stamp, changed: {}};
64
+ imported.set(file, seen);
65
+ }
66
+ if (!seen.changed) return load(file);
67
+ return (seen.changed[kind] ??= loadFresh(file));
68
+ }
69
+
70
+ /**
71
+ * The file's URL, naming a new module for each change.
72
+ * @param {string} file
73
+ * @returns {string}
74
+ */
75
+ function freshUrl(file) {
76
+ const url = pathToFileURL(file);
77
+ url.searchParams.set('astryx-doc', String(++changes));
78
+ return url.href;
79
+ }
80
+
27
81
  /**
28
82
  * Import a component, hook, topic, or self-doc module: `.ts` through jiti,
29
83
  * anything else natively.
@@ -31,7 +85,9 @@ let jsxJiti;
31
85
  * @returns {Promise<any>}
32
86
  */
33
87
  export function importDocModule(file) {
34
- return importUserModule(file);
88
+ return importCurrent(file, 'doc', importUserModule, changed =>
89
+ importUserModule(changed, {fresh: true}),
90
+ );
35
91
  }
36
92
 
37
93
  /**
@@ -41,11 +97,23 @@ export function importDocModule(file) {
41
97
  * @returns {Promise<any>}
42
98
  */
43
99
  export function importTemplateModule(file) {
44
- if (file.endsWith('.ts')) {
45
- jsxJiti ??= createJiti(import.meta.url, {jsx: true});
46
- return jsxJiti.import(file);
47
- }
48
- return import(`file://${file}`);
100
+ return importCurrent(
101
+ file,
102
+ 'template',
103
+ first => {
104
+ if (first.endsWith('.ts')) {
105
+ jsxJiti ??= createJiti(import.meta.url, {jsx: true});
106
+ return jsxJiti.import(first);
107
+ }
108
+ return import(`file://${first}`);
109
+ },
110
+ changed =>
111
+ changed.endsWith('.ts')
112
+ ? createJiti(import.meta.url, {jsx: true, moduleCache: false}).import(
113
+ changed,
114
+ )
115
+ : import(freshUrl(changed)),
116
+ );
49
117
  }
50
118
 
51
119
  /**
@@ -55,5 +123,10 @@ export function importTemplateModule(file) {
55
123
  * @returns {Promise<any>}
56
124
  */
57
125
  export function importNativeModule(file) {
58
- return import(pathToFileURL(file).href);
126
+ return importCurrent(
127
+ file,
128
+ 'native',
129
+ first => import(pathToFileURL(first).href),
130
+ changed => import(freshUrl(changed)),
131
+ );
59
132
  }
@@ -2,9 +2,10 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * Lower one descriptor file. Memoized per file and options for the life of the
6
- * process; a file that failed to load is tried again on the next read, as a
7
- * fresh import would be.
5
+ * Lower one descriptor file. Memoized per file and options while the file is
6
+ * unchanged; an edited file is lowered again from its new content, and a file
7
+ * that failed to load is tried again on the next read, as a fresh import
8
+ * would be.
8
9
  * @param {string} file absolute path
9
10
  * @param {ReadOptions} options
10
11
  * @param {{node?: boolean}} [want] also build the sealed node
@@ -8,9 +8,9 @@
8
8
  * how strictly the reader checks.
9
9
  * @output The lowered doc for that file. Readers get the view they have always
10
10
  * read, lowered afresh on every read; a whole-project compile also gets the
11
- * sealed node, memoized per file for the life of the process. For doc
12
- * topics: the compiler input for a topic, with its extensions and overlays
13
- * loaded.
11
+ * sealed node, memoized per file while the file is unchanged. An edited file
12
+ * is read again in the same process (./import.mjs). For doc topics: the
13
+ * compiler input for a topic, with its extensions and overlays loaded.
14
14
  * @position Loads authored doc files for the readers in api/ and clients/ and
15
15
  * hands each to ./compile.mjs. Each reader keeps its own loader, export
16
16
  * order, and strictness, so what it prints is what it printed before.
@@ -30,6 +30,7 @@ import {
30
30
  importNativeModule,
31
31
  importTemplateModule,
32
32
  } from './import.mjs';
33
+ import {fileStamp, recordContentRead} from '../fs/read-record.mjs';
33
34
  import {lowerDoc, parserFor} from './compile.mjs';
34
35
  import {translationFor} from './overlays.mjs';
35
36
  import {parseReadableDoc} from './parse-readable.mjs';
@@ -82,13 +83,14 @@ const LOADERS = Object.freeze({
82
83
  * @property {boolean} [check] hold the doc to its kind's parser
83
84
  */
84
85
 
85
- /** @type {Map<string, Promise<import('./compile.mjs').LoweredDoc>>} */
86
+ /** @type {Map<string, {stamp: string, result: Promise<import('./compile.mjs').LoweredDoc>}>} */
86
87
  const lowered = new Map();
87
88
 
88
89
  /**
89
- * Lower one descriptor file. Memoized per file and options for the life of the
90
- * process; a file that failed to load is tried again on the next read, as a
91
- * fresh import would be.
90
+ * Lower one descriptor file. Memoized per file and options while the file is
91
+ * unchanged; an edited file is lowered again from its new content, and a file
92
+ * that failed to load is tried again on the next read, as a fresh import
93
+ * would be.
92
94
  * @param {string} file absolute path
93
95
  * @param {ReadOptions} options
94
96
  * @param {{node?: boolean}} [want] also build the sealed node
@@ -110,7 +112,10 @@ export function compileDocFile(file, options, {node = false} = {}) {
110
112
  check,
111
113
  node,
112
114
  ]);
113
- let result = lowered.get(key);
115
+ recordContentRead(file);
116
+ const stamp = fileStamp(file);
117
+ const hit = lowered.get(key);
118
+ let result = hit?.stamp === stamp ? hit.result : undefined;
114
119
  if (!result) {
115
120
  result = loadAuthored(file, options, lang).then(authored => {
116
121
  const provider = options.provider ?? packageOf(file);
@@ -130,11 +135,11 @@ export function compileDocFile(file, options, {node = false} = {}) {
130
135
  );
131
136
  if (out.node) deepFreeze(out.node);
132
137
  if (out.loadFailed || 'overlayError' in authored) {
133
- lowered.delete(key);
138
+ if (lowered.get(key)?.result === result) lowered.delete(key);
134
139
  }
135
140
  return out;
136
141
  });
137
- lowered.set(key, result);
142
+ lowered.set(key, {stamp, result});
138
143
  }
139
144
  return result;
140
145
  }
@@ -16,6 +16,7 @@ import {Project} from '../config/project.mjs';
16
16
  import {CLI_ROOT} from '../fs/paths.mjs';
17
17
  import {loadComponentDoc, loadDocs} from '../discovery/component-loader.mjs';
18
18
  import {compileDocFile, readDocView} from './read.mjs';
19
+ import {importDocModule, importNativeModule} from './import.mjs';
19
20
  import {collectDocInputs} from './inputs.mjs';
20
21
 
21
22
  const REPO_ROOT = path.resolve(CLI_ROOT, '..', '..');
@@ -151,7 +152,7 @@ describe('readDocView', () => {
151
152
  ).toBe('Legacy');
152
153
  });
153
154
 
154
- it('reads each file once per process, and retries a file that failed to load', async () => {
155
+ it('reads each file once while it is unchanged, and retries a file that failed to load', async () => {
155
156
  const file = write('Card.doc.mjs', card);
156
157
  const before = await compileDocFile(file, {root: 'components'});
157
158
  expect(await compileDocFile(file, {root: 'components'})).toBe(before);
@@ -320,3 +321,60 @@ catch (e) { console.log('threw', e.message.split('\\n')[0]); }`,
320
321
  expect(run('loadComponentDoc')).toMatch(/^(ok Typed|threw .*is invalid)/);
321
322
  });
322
323
  });
324
+
325
+ describe('an edited doc file, read again in the same process', () => {
326
+ /** @param {string} displayName */
327
+ const doc = displayName =>
328
+ `export default {type: 'component', name: 'Edited', displayName: ${JSON.stringify(displayName)}, usage: {description: 'd'}, props: []};\n`;
329
+
330
+ it('reads the new content, and shares each version while it is unchanged', async () => {
331
+ const file = write('Edited.doc.mjs', doc('First'));
332
+ const first = await loadDocs(file);
333
+ expect(first.displayName).toBe('First');
334
+ expect(await loadDocs(file)).toBe(first);
335
+ fs.writeFileSync(file, doc('Second, longer'));
336
+ const second = await loadDocs(file);
337
+ expect(second.displayName).toBe('Second, longer');
338
+ expect(await loadDocs(file)).toBe(second);
339
+ expect((await loadComponentDoc(file)).displayName).toBe('Second, longer');
340
+ });
341
+
342
+ it('reads an edited TypeScript doc again', async () => {
343
+ const file = write('Edited.doc.ts', doc('First'));
344
+ expect((await loadComponentDoc(file)).displayName).toBe('First');
345
+ fs.writeFileSync(file, doc('Second, longer'));
346
+ expect((await loadComponentDoc(file)).displayName).toBe('Second, longer');
347
+ });
348
+
349
+ it('gives each importer its own read of an edited TypeScript doc, as a new process would', async () => {
350
+ const file = write('Pair.doc.ts', doc('First'));
351
+ const nativeBefore = await importNativeModule(file);
352
+ expect(await importDocModule(file)).not.toBe(nativeBefore);
353
+ fs.writeFileSync(file, doc('Second, longer'));
354
+ // The unchecked reader (a plain import) first, then the checked one (jiti).
355
+ expect((await loadDocs(file)).displayName).toBe('Second, longer');
356
+ expect((await loadComponentDoc(file)).displayName).toBe('Second, longer');
357
+ const nativeAfter = await importNativeModule(file);
358
+ const docAfter = await importDocModule(file);
359
+ expect(docAfter).not.toBe(nativeAfter);
360
+ expect(await importNativeModule(file)).toBe(nativeAfter);
361
+ expect(await importDocModule(file)).toBe(docAfter);
362
+ });
363
+
364
+ it('lowers an edited file again for a whole-project compile', async () => {
365
+ const file = write('Edited.doc.mjs', doc('First'));
366
+ const read = () => compileDocFile(file, {root: 'components'});
367
+ expect((await read()).view.displayName).toBe('First');
368
+ fs.writeFileSync(file, doc('Second, longer'));
369
+ expect((await read()).view.displayName).toBe('Second, longer');
370
+ });
371
+
372
+ it('reads a fix after an edit that broke the file', async () => {
373
+ const file = write('Edited.doc.mjs', doc('First'));
374
+ expect((await loadDocs(file)).displayName).toBe('First');
375
+ fs.writeFileSync(file, 'export default {;\n');
376
+ await expect(loadDocs(file)).rejects.toThrow();
377
+ fs.writeFileSync(file, doc('Fixed again'));
378
+ expect((await loadDocs(file)).displayName).toBe('Fixed again');
379
+ });
380
+ });
@@ -986,7 +986,9 @@ export function iconDefinitionTreeInput(doc, file, provider, providerId) {
986
986
  kind: 'icon-definition',
987
987
  name: doc.name,
988
988
  title: doc.name,
989
- summary: doc.description,
989
+ // Built-in definitions are the ones every set must map; the words are
990
+ // what an author searches the library for.
991
+ summary: `${doc.builtIn ? '[built-in] ' : ''}${doc.description}${doc.words.length > 0 ? ` Words: ${doc.words.join(', ')}.` : ''}`,
990
992
  group: ICON_DEFINITIONS_GROUP,
991
993
  placement: undefined,
992
994
  ref: {selfDoc: doc},
@@ -7,8 +7,9 @@
7
7
  * no-cache jiti instance. A fresh CommonJS `.js` read evicts and reloads through
8
8
  * `require`; an ESM `.js` or `.mjs` read uses a cache-busted file URL. The
9
9
  * nearest package.json `type` decides `.js`, matching Node's package scopes.
10
- * Normal loads retain module caching. `fresh` is an explicit migration-only
11
- * escape hatch for rereading files that a codemod changed during this process.
10
+ * Normal loads retain module caching. `fresh` rereads a file that changed
11
+ * during this process: one a codemod rewrote, or an edited doc file (the doc
12
+ * importers in ../doc-compiler/import.mjs read each change once).
12
13
  * Anything the module writes to stdout while it loads goes to stderr.
13
14
  *
14
15
  * @param {string} file absolute path
@@ -104,8 +104,9 @@ async function withStdoutOnStderr(load) {
104
104
  * no-cache jiti instance. A fresh CommonJS `.js` read evicts and reloads through
105
105
  * `require`; an ESM `.js` or `.mjs` read uses a cache-busted file URL. The
106
106
  * nearest package.json `type` decides `.js`, matching Node's package scopes.
107
- * Normal loads retain module caching. `fresh` is an explicit migration-only
108
- * escape hatch for rereading files that a codemod changed during this process.
107
+ * Normal loads retain module caching. `fresh` rereads a file that changed
108
+ * during this process: one a codemod rewrote, or an edited doc file (the doc
109
+ * importers in ../doc-compiler/import.mjs read each change once).
109
110
  * Anything the module writes to stdout while it loads goes to stderr.
110
111
  *
111
112
  * @param {string} file absolute path
@@ -30,6 +30,8 @@ const fs = await import('node:fs');
30
30
 
31
31
  let tmpDir;
32
32
  beforeEach(() => {
33
+ // One mock serves both tests, so each counts only its own calls, in any order.
34
+ vi.mocked(fs.linkSync).mockClear();
33
35
  tmpDir = realFs.mkdtempSync(path.join(os.tmpdir(), 'astryx-publish-eperm-'));
34
36
  });
35
37
  afterEach(() => {
@@ -1,12 +1,27 @@
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
+ * One path's state: its size and modification time, plus its change time and
6
+ * inode, which change on a rewrite even when npm stamps the same size and
7
+ * modification time; or that it is absent.
8
+ * @param {string} file
9
+ * @returns {string}
10
+ */
11
+ export function fileStamp(file: string): string;
4
12
  /**
5
13
  * Whether every recorded path is still in the state it had when it was read.
6
14
  * @param {Map<string, string>} recorded - From recordReads.
7
15
  * @returns {boolean}
8
16
  */
9
17
  export function unchangedSince(recorded: Map<string, string>): boolean;
18
+ /**
19
+ * Count `file` as read by the running operation, as a content read through fs
20
+ * would be, for a read that does not go through fs: a module import. Outside
21
+ * `recordReads` it does nothing.
22
+ * @param {string} file
23
+ */
24
+ export function recordContentRead(file: string): void;
10
25
  /**
11
26
  * Run `fn`, adding to `seen` each path it reads, with that path's state when
12
27
  * it was first read (see the file header).
@@ -16,3 +31,15 @@ export function unchangedSince(recorded: Map<string, string>): boolean;
16
31
  * @returns {T}
17
32
  */
18
33
  export function recordReads<T>(seen: Map<string, string>, fn: () => T): T;
34
+ /**
35
+ * A loader whose value is kept while every file and folder it read is
36
+ * unchanged, and loaded again after a change, so a long-running process sees
37
+ * an edit. A failed load is tried again on the next call. What a kept value
38
+ * read counts as read by the operation that asks for it.
39
+ * @template T
40
+ * @param {() => Promise<T>} load
41
+ * @returns {(options?: {fresh?: boolean}) => Promise<T>}
42
+ */
43
+ export function reusedWhileUnchanged<T>(load: () => Promise<T>): (options?: {
44
+ fresh?: boolean;
45
+ }) => Promise<T>;
@@ -6,11 +6,16 @@
6
6
  *
7
7
  * @input An operation run inside `recordReads(seen, fn)`.
8
8
  * @output `seen` gets every file whose content the operation read through fs
9
- * and every folder it listed or probed, each with its state when first
10
- * read; `unchangedSince(seen)` says whether all are still in that state.
9
+ * or imported as a doc module (`recordContentRead`), and every folder it
10
+ * listed or probed, each with its state when first read;
11
+ * `unchangedSince(seen)` says whether all are still in that state.
11
12
  * @position Used by search's adapter to reuse a gathered catalog only while
12
- * it is exact. Outside `recordReads` nothing is recorded and every fs call
13
- * behaves as before.
13
+ * it is exact, by the docs adapter to rebuild the CLI's own docs tree after
14
+ * an edit (`reusedWhileUnchanged`), and by the doc importers and reader
15
+ * (../doc-compiler) to read an edited doc file again. A run inside another
16
+ * records into both, so an outer reuse sees what an inner one read.
17
+ * Outside `recordReads` nothing is recorded and every fs call behaves as
18
+ * before.
14
19
  */
15
20
 
16
21
  import {AsyncLocalStorage} from 'node:async_hooks';
@@ -19,12 +24,25 @@ import * as path from 'node:path';
19
24
  import {fileURLToPath} from 'node:url';
20
25
 
21
26
  /**
22
- * The paths the running operation touched: every file it read and every
23
- * folder it listed or probed.
24
- * @type {AsyncLocalStorage<Map<string, string>>}
27
+ * The paths the running operations touched, one map per enclosing
28
+ * `recordReads`: every file read and every folder listed or probed.
29
+ * @type {AsyncLocalStorage<Map<string, string>[]>}
25
30
  */
26
31
  const reads = new AsyncLocalStorage();
27
32
 
33
+ /**
34
+ * Add `file` to every running operation's map, with its state now, unless it
35
+ * is there already.
36
+ * @param {Map<string, string>[]} runs
37
+ * @param {string} file
38
+ */
39
+ function note(runs, file) {
40
+ let state;
41
+ for (const seen of runs) {
42
+ if (!seen.has(file)) seen.set(file, (state ??= stateOf(file)));
43
+ }
44
+ }
45
+
28
46
  /** node:fs's module object, whose functions every import of it shares. */
29
47
  const fs = createRequire(import.meta.url)('node:fs');
30
48
 
@@ -64,9 +82,9 @@ function installRecorder() {
64
82
  * @param {...any} args
65
83
  */
66
84
  const wrapped = function (...args) {
67
- const seen = reads.getStore();
85
+ const runs = reads.getStore();
68
86
  const target = args[0];
69
- if (seen && (typeof target === 'string' || target instanceof URL)) {
87
+ if (runs && (typeof target === 'string' || target instanceof URL)) {
70
88
  const file =
71
89
  typeof target === 'string'
72
90
  ? path.resolve(target)
@@ -80,7 +98,7 @@ function installRecorder() {
80
98
  : path.dirname(file);
81
99
  // Its state is taken when it is first read, before the read, so a
82
100
  // change made while the operation runs shows as a change afterwards.
83
- if (!seen.has(checked)) seen.set(checked, stateOf(checked));
101
+ note(runs, checked);
84
102
  }
85
103
  return original.apply(this, args);
86
104
  };
@@ -92,19 +110,23 @@ function installRecorder() {
92
110
  }
93
111
 
94
112
  /**
95
- * One path's state: its change time and size, or that it is absent.
113
+ * One path's state: its size and modification time, plus its change time and
114
+ * inode, which change on a rewrite even when npm stamps the same size and
115
+ * modification time; or that it is absent.
96
116
  * @param {string} file
97
117
  * @returns {string}
98
118
  */
99
- function stateOf(file) {
119
+ export function fileStamp(file) {
100
120
  try {
101
- const stat = statSyncRaw(file);
102
- return `${stat.mtimeMs}\0${stat.size}`;
121
+ const {size, mtimeMs, ctimeMs, ino} = statSyncRaw(file);
122
+ return `${size}:${mtimeMs}:${ctimeMs}:${ino}`;
103
123
  } catch {
104
124
  return '-';
105
125
  }
106
126
  }
107
127
 
128
+ const stateOf = fileStamp;
129
+
108
130
  /**
109
131
  * Whether every recorded path is still in the state it had when it was read.
110
132
  * @param {Map<string, string>} recorded - From recordReads.
@@ -117,6 +139,17 @@ export function unchangedSince(recorded) {
117
139
  return true;
118
140
  }
119
141
 
142
+ /**
143
+ * Count `file` as read by the running operation, as a content read through fs
144
+ * would be, for a read that does not go through fs: a module import. Outside
145
+ * `recordReads` it does nothing.
146
+ * @param {string} file
147
+ */
148
+ export function recordContentRead(file) {
149
+ const runs = reads.getStore();
150
+ if (runs) note(runs, path.resolve(file));
151
+ }
152
+
120
153
  /**
121
154
  * Run `fn`, adding to `seen` each path it reads, with that path's state when
122
155
  * it was first read (see the file header).
@@ -127,5 +160,40 @@ export function unchangedSince(recorded) {
127
160
  */
128
161
  export function recordReads(seen, fn) {
129
162
  installRecorder();
130
- return reads.run(seen, fn);
163
+ return reads.run([...(reads.getStore() ?? []), seen], fn);
164
+ }
165
+
166
+ /**
167
+ * A loader whose value is kept while every file and folder it read is
168
+ * unchanged, and loaded again after a change, so a long-running process sees
169
+ * an edit. A failed load is tried again on the next call. What a kept value
170
+ * read counts as read by the operation that asks for it.
171
+ * @template T
172
+ * @param {() => Promise<T>} load
173
+ * @returns {(options?: {fresh?: boolean}) => Promise<T>}
174
+ */
175
+ export function reusedWhileUnchanged(load) {
176
+ /** @type {{reads: Map<string, string>, value: Promise<T>} | undefined} */
177
+ let last;
178
+ return ({fresh = false} = {}) => {
179
+ if (!fresh && last && unchangedSince(last.reads)) {
180
+ const {reads: recorded, value} = last;
181
+ return value.then(result => {
182
+ const runs = reads.getStore();
183
+ if (runs) for (const [file, state] of recorded) {
184
+ for (const seen of runs) if (!seen.has(file)) seen.set(file, state);
185
+ }
186
+ return result;
187
+ });
188
+ }
189
+ /** @type {Map<string, string>} */
190
+ const seen = new Map();
191
+ const value = recordReads(seen, load);
192
+ const entry = {reads: seen, value};
193
+ last = entry;
194
+ value.catch(() => {
195
+ if (last === entry) last = undefined;
196
+ });
197
+ return value;
198
+ };
131
199
  }
@@ -9,7 +9,12 @@ import {describe, it, expect} from 'vitest';
9
9
  import * as fs from 'node:fs';
10
10
  import * as os from 'node:os';
11
11
  import * as path from 'node:path';
12
- import {recordReads, unchangedSince} from './read-record.mjs';
12
+ import {
13
+ recordContentRead,
14
+ recordReads,
15
+ reusedWhileUnchanged,
16
+ unchangedSince,
17
+ } from './read-record.mjs';
13
18
 
14
19
  function scratch() {
15
20
  const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-read-record-'));
@@ -72,6 +77,88 @@ describe('recordReads', () => {
72
77
  const seen = new Map();
73
78
  recordReads(seen, () => {});
74
79
  fs.readFileSync(file, 'utf8');
80
+ recordContentRead(file);
75
81
  expect(seen.size).toBe(0);
76
82
  });
83
+
84
+ it('records a file read without fs, such as an imported doc module, and sees it edited', () => {
85
+ const {file} = scratch();
86
+ /** @type {Map<string, string>} */
87
+ const seen = new Map();
88
+ recordReads(seen, () => recordContentRead(file));
89
+ expect([...seen.keys()]).toEqual([file]);
90
+ expect(unchangedSince(seen)).toBe(true);
91
+ fs.writeFileSync(file, 'two, longer');
92
+ expect(unchangedSince(seen)).toBe(false);
93
+ });
94
+
95
+ it('records a read in an operation inside another into both', async () => {
96
+ const {file} = scratch();
97
+ /** @type {Map<string, string>} */
98
+ const outer = new Map();
99
+ /** @type {Map<string, string>} */
100
+ const inner = new Map();
101
+ await recordReads(outer, async () => {
102
+ await recordReads(inner, async () => fs.readFileSync(file, 'utf8'));
103
+ });
104
+ expect([...inner.keys()]).toEqual([file]);
105
+ expect([...outer.keys()]).toEqual([file]);
106
+ });
107
+
108
+ it('sees a rewrite that keeps the size and modification time, as an npm reinstall does', () => {
109
+ const {file} = scratch();
110
+ const stamped = new Date('1985-10-26T08:15:00Z');
111
+ fs.utimesSync(file, stamped, stamped);
112
+ /** @type {Map<string, string>} */
113
+ const seen = new Map();
114
+ recordReads(seen, () => fs.readFileSync(file, 'utf8'));
115
+ // Same size, and the same modification time npm stamps on every file.
116
+ const replacement = `${file}.new`;
117
+ fs.writeFileSync(replacement, 'two');
118
+ fs.utimesSync(replacement, stamped, stamped);
119
+ fs.renameSync(replacement, file);
120
+ expect(unchangedSince(seen)).toBe(false);
121
+ });
122
+ });
123
+
124
+ describe('reusedWhileUnchanged', () => {
125
+ it('keeps a loaded value while what it read is unchanged, and loads again after an edit', async () => {
126
+ const {file} = scratch();
127
+ let loads = 0;
128
+ const get = reusedWhileUnchanged(async () => {
129
+ loads += 1;
130
+ return fs.readFileSync(file, 'utf8');
131
+ });
132
+ expect(await get()).toBe('one');
133
+ expect(await get()).toBe('one');
134
+ expect(loads).toBe(1);
135
+ fs.writeFileSync(file, 'two, longer');
136
+ expect(await get()).toBe('two, longer');
137
+ expect(loads).toBe(2);
138
+ expect(await get({fresh: true})).toBe('two, longer');
139
+ expect(loads).toBe(3);
140
+ });
141
+
142
+ it('counts what a kept value read as read by the operation that asks for it', async () => {
143
+ const {file} = scratch();
144
+ const get = reusedWhileUnchanged(async () => fs.readFileSync(file, 'utf8'));
145
+ await get();
146
+ /** @type {Map<string, string>} */
147
+ const seen = new Map();
148
+ await recordReads(seen, () => get());
149
+ expect([...seen.keys()]).toEqual([file]);
150
+ fs.writeFileSync(file, 'two, longer');
151
+ expect(unchangedSince(seen)).toBe(false);
152
+ });
153
+
154
+ it('tries a failed load again', async () => {
155
+ let calls = 0;
156
+ const get = reusedWhileUnchanged(async () => {
157
+ calls += 1;
158
+ if (calls === 1) throw new Error('first try');
159
+ return 'second try';
160
+ });
161
+ await expect(get()).rejects.toThrow('first try');
162
+ expect(await get()).toBe('second try');
163
+ });
77
164
  });
@@ -0,0 +1,31 @@
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
+ * Read a local file as a data: URI.
6
+ * @param {string} file absolute path
7
+ * @returns {string}
8
+ */
9
+ export function assetDataUri(file: string): string;
10
+ /**
11
+ * Whether bytes are a known image, font or media format, whatever the file's
12
+ * extension says (a JPEG saved as `.png` is still an inert image): their
13
+ * leading bytes match one (an SVG is XML with an <svg> element). A carried
14
+ * asset is carried, and written back, only when they do.
15
+ * @param {Buffer} bytes
16
+ */
17
+ export function isAssetBytes(bytes: Buffer): boolean;
18
+ /** The largest single file inlined into a rendered page. */
19
+ export const MAX_ASSET_BYTES: number;
20
+ export function isAssetPath(file: string): boolean;
21
+ /** An error carrying a render error code. */
22
+ export class RenderAssetError extends Error {
23
+ /**
24
+ * @param {string} code
25
+ * @param {string} message
26
+ * @param {Record<string, unknown>} [detail]
27
+ */
28
+ constructor(code: string, message: string, detail?: Record<string, unknown>);
29
+ code: string;
30
+ detail: Record<string, unknown> | undefined;
31
+ }