@astryxdesign/cli 0.7.14 → 0.7.15-canary.g061b2fa

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 (164) hide show
  1. package/README.md +63 -63
  2. package/api/build/_adapter.d.mts +4 -0
  3. package/api/build/_adapter.mjs +28 -2
  4. package/api/build/blocks/blocks.d.mts +10 -1
  5. package/api/build/blocks/blocks.mjs +84 -7
  6. package/api/build/build.mjs +6 -1
  7. package/api/build/tree.d.mts +4 -0
  8. package/api/build/tree.mjs +9 -2
  9. package/api/doctor/_adapter.d.mts +3 -1
  10. package/api/doctor/_adapter.mjs +14 -1
  11. package/api/doctor/_authoring-audit.d.mts +42 -0
  12. package/api/doctor/_authoring-audit.mjs +106 -0
  13. package/api/doctor/doctor.d.mts +7 -0
  14. package/api/doctor/doctor.mjs +24 -39
  15. package/api/doctor/theme-checks.mjs +56 -21
  16. package/api/integration/validate-integration.mjs +17 -3
  17. package/api/integration/validateIntegration.doc.mjs +1 -1
  18. package/api/search/_adapter.mjs +124 -3
  19. package/api/search/_candidate-score.mjs +63 -9
  20. package/api/search/_entries.d.mts +10 -0
  21. package/api/search/_entries.mjs +68 -1
  22. package/api/search/_gather-templates.d.mts +11 -0
  23. package/api/search/_gather-templates.mjs +22 -2
  24. package/api/search/_words.mjs +26 -6
  25. package/api/swizzle/copy/copy.mjs +1 -1
  26. package/api/theme/_adapter.d.mts +17 -1
  27. package/api/theme/_adapter.mjs +185 -40
  28. package/api/theme/build/build.d.mts +29 -1
  29. package/api/theme/build/build.mjs +426 -65
  30. package/api/theme/eject/eject.mjs +10 -6
  31. package/api/theme/targets/targets.d.mts +8 -0
  32. package/api/theme/targets/targets.mjs +24 -4
  33. package/api/theme/template/template.mjs +48 -2
  34. package/api/theme/theme.type.d.mts +8 -0
  35. package/api/theme/theme.type.mjs +5 -1
  36. package/api/theme/themeBuild.doc.mjs +7 -4
  37. package/api/theme/themeEject.doc.mjs +3 -3
  38. package/api/theme/themeRemove.doc.mjs +5 -2
  39. package/api/theme/themeTargets.doc.mjs +1 -1
  40. package/api/theme/themeTemplate.doc.mjs +2 -2
  41. package/api/theme/themeUse.doc.mjs +8 -2
  42. package/api/theme-edit/_adapter.d.mts +46 -3
  43. package/api/theme-edit/_adapter.mjs +372 -109
  44. package/api/theme-edit/_check.d.mts +6 -3
  45. package/api/theme-edit/_check.mjs +665 -87
  46. package/api/theme-edit/_color.mjs +4 -2
  47. package/api/theme-edit/_compiler.d.mts +2 -1
  48. package/api/theme-edit/_compiler.mjs +27 -13
  49. package/api/theme-edit/_context.d.mts +2 -1
  50. package/api/theme-edit/_context.mjs +47 -8
  51. package/api/theme-edit/_edit.d.mts +9 -3
  52. package/api/theme-edit/_edit.mjs +484 -66
  53. package/api/theme-edit/_how-commands.d.mts +33 -7
  54. package/api/theme-edit/_how-commands.mjs +57 -45
  55. package/api/theme-edit/_how-question.d.mts +4 -0
  56. package/api/theme-edit/_how-question.mjs +1004 -223
  57. package/api/theme-edit/_how.mjs +96 -9
  58. package/api/theme-edit/_palette.d.mts +38 -13
  59. package/api/theme-edit/_palette.mjs +620 -223
  60. package/api/theme-edit/_parts.mjs +63 -7
  61. package/api/theme-edit/_png.d.mts +4 -4
  62. package/api/theme-edit/_png.mjs +4 -2
  63. package/api/theme-edit/_preview-app.d.mts +6 -0
  64. package/api/theme-edit/_preview-app.mjs +1194 -207
  65. package/api/theme-edit/_preview.mjs +2 -2
  66. package/api/theme-edit/_project.d.mts +12 -1
  67. package/api/theme-edit/_project.mjs +37 -6
  68. package/api/theme-edit/_settings.d.mts +104 -33
  69. package/api/theme-edit/_settings.mjs +818 -118
  70. package/api/theme-edit/_tables.d.mts +7 -0
  71. package/api/theme-edit/_tables.mjs +61 -0
  72. package/api/theme-edit/theme-edit.type.d.mts +11 -1
  73. package/api/theme-edit/theme-edit.type.mjs +4 -3
  74. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  75. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  76. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  77. package/api/theme-edit/themeEditPreviewList.doc.mjs +1 -1
  78. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  79. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  80. package/api/upgrade/_adapter.d.mts +1 -0
  81. package/assets/codemods/run-codemod.mjs +61 -0
  82. package/assets/codemods/runner.mjs +5 -4
  83. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  84. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  85. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  86. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  87. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  88. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  89. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  90. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  91. package/assets/docs/tree/calendars.doc.mjs +1 -3
  92. package/assets/docs/tree/checks.doc.mjs +22 -1
  93. package/assets/docs.generated.json +2 -1
  94. package/assets/self-audit.generated.json +1 -0
  95. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  96. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  97. package/assets/templates/components.generated.json +1 -1
  98. package/authoring/integration/integration.doc.mjs +8 -0
  99. package/authoring/integration/schema.d.mts +8 -0
  100. package/authoring/integration/schema.mjs +1 -0
  101. package/authoring/integration/type.ts +9 -0
  102. package/clients/cli/bin/astryx.mjs +19 -15
  103. package/clients/cli/build-id.generated.json +1 -0
  104. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  105. package/clients/cli/commands/experimental/theme.mjs +178 -78
  106. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  107. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  108. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  109. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  110. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  111. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  112. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  113. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  114. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  115. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  116. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  117. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  118. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  119. package/clients/cli/commands/manifest.mjs +5 -2
  120. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  121. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  122. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  123. package/clients/cli/commands/theme.mjs +374 -42
  124. package/clients/cli/index.mjs +9 -3
  125. package/clients/cli/lib/manifest.mjs +37 -0
  126. package/clients/cli/lib/resolve-theme.mjs +2 -1
  127. package/clients/cli/manifest.generated.json +1 -0
  128. package/foundation/config/theme-state.d.mts +16 -0
  129. package/foundation/config/theme-state.mjs +84 -13
  130. package/foundation/discovery/module-exports.mjs +16 -2
  131. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  132. package/foundation/discovery/stored-self-audit.mjs +119 -0
  133. package/foundation/discovery/template-adapter.d.mts +48 -2
  134. package/foundation/discovery/template-adapter.mjs +51 -19
  135. package/foundation/discovery/template-needs.d.mts +19 -0
  136. package/foundation/discovery/template-needs.mjs +50 -16
  137. package/foundation/discovery/template-source-tree.d.mts +7 -0
  138. package/foundation/discovery/template-source-tree.mjs +15 -0
  139. package/foundation/discovery/theme-discovery.d.mts +2 -1
  140. package/foundation/discovery/theme-discovery.mjs +2 -8
  141. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  142. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  143. package/foundation/doc-compiler/import.mjs +22 -15
  144. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  145. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  146. package/foundation/env/private-dir.d.mts +17 -0
  147. package/foundation/env/private-dir.mjs +42 -0
  148. package/foundation/fs/gather-cache.d.mts +108 -0
  149. package/foundation/fs/gather-cache.mjs +741 -0
  150. package/foundation/fs/jiti-cache.d.mts +21 -0
  151. package/foundation/fs/jiti-cache.mjs +66 -0
  152. package/foundation/fs/module-loader.mjs +14 -3
  153. package/foundation/fs/read-record.d.mts +31 -1
  154. package/foundation/fs/read-record.mjs +100 -7
  155. package/foundation/integrations/integrations.d.mts +8 -0
  156. package/foundation/integrations/integrations.mjs +4 -0
  157. package/foundation/integrations/validate-contributions.d.mts +62 -1
  158. package/foundation/integrations/validate-contributions.mjs +476 -40
  159. package/foundation/release/cache.d.mts +11 -2
  160. package/foundation/release/cache.mjs +59 -10
  161. package/foundation/release/folder-lock.d.mts +21 -0
  162. package/foundation/release/folder-lock.mjs +171 -0
  163. package/foundation/response/response-types.doc.mjs +1 -1
  164. package/package.json +8 -6
@@ -17,10 +17,15 @@
17
17
 
18
18
  import * as fs from 'node:fs';
19
19
  import * as path from 'node:path';
20
+ import {isAlive} from '../../foundation/release/cache.mjs';
20
21
  import {AstryxError} from '../error.mjs';
21
22
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
22
- import {importPathOf} from './_project.mjs';
23
- import {renderPage, RenderError} from '../../foundation/render/render-page.mjs';
23
+ import {importPathOf, installLine} from './_project.mjs';
24
+ import {
25
+ RENDER_TIMEOUT_MS,
26
+ renderPage,
27
+ RenderError,
28
+ } from '../../foundation/render/render-page.mjs';
24
29
  import {
25
30
  EXTRA,
26
31
  OPEN_OVERLAYS,
@@ -83,6 +88,9 @@ export function catalogItems(project) {
83
88
  return {items, imports};
84
89
  }
85
90
 
91
+ /** How long the editor's own pages may take to render. */
92
+ const EDITOR_RENDER_MS = 3 * RENDER_TIMEOUT_MS;
93
+
86
94
  /** One name per process, so two commands at once never share a folder. */
87
95
  const RUN = `${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
88
96
 
@@ -96,6 +104,33 @@ const RUN = `${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
96
104
  export const renderDir = project =>
97
105
  path.join(project.cwd, 'themes', `.astryx-render-${RUN}`);
98
106
 
107
+ /**
108
+ * Remove render folders a stopped command left (killed, out of memory):
109
+ * only `.astryx-render-<pid>-<random>` folders whose process is gone. Links
110
+ * are never followed.
111
+ * @param {string} themes
112
+ */
113
+ function sweepRenders(themes) {
114
+ let names;
115
+ try {
116
+ names = fs.readdirSync(themes);
117
+ } catch {
118
+ return;
119
+ }
120
+ for (const n of names) {
121
+ const m = /^\.astryx-render-(\d+)-[a-z0-9]+$/.exec(n);
122
+ if (!m || Number(m[1]) === process.pid) continue;
123
+ if (isAlive(Number(m[1]))) continue;
124
+ const p = path.join(themes, n);
125
+ try {
126
+ if (fs.lstatSync(p).isDirectory())
127
+ fs.rmSync(p, {recursive: true, force: true});
128
+ } catch {
129
+ // Gone already.
130
+ }
131
+ }
132
+ }
133
+
99
134
  /**
100
135
  * Render a generated page module and give its HTML and markup (the body,
101
136
  * without the embedded source block).
@@ -111,6 +146,7 @@ export async function renderGenerated(project, file, source, extra = []) {
111
146
  const themes = path.dirname(dir);
112
147
  // A themes/ folder that holds only other renders was made by another
113
148
  // lookup running beside this one, so it is ours to remove too.
149
+ sweepRenders(themes);
114
150
  const madeThemes =
115
151
  !fs.existsSync(themes) ||
116
152
  (() => {
@@ -135,16 +171,36 @@ export async function renderGenerated(project, file, source, extra = []) {
135
171
  fs.copyFileSync(x.from, path.join(dir, x.name));
136
172
  }
137
173
  try {
138
- const page = await renderPage(entry, {title: file.replace(/\.[^.]+$/, '')});
139
- const body = page.html.slice(page.html.indexOf('<body>') + 6);
174
+ // The editor's pages render every component, and a busy machine slows
175
+ // them down: they get three times the page limit.
176
+ const page = await renderPage(entry, {
177
+ title: file.replace(/\.[^.]+$/, ''),
178
+ timeoutMs: EDITOR_RENDER_MS,
179
+ });
180
+ // The page is the same whichever command rendered it: the folder's
181
+ // per-process name never reaches the file.
182
+ const html = page.html.split(path.basename(dir)).join('.astryx-render');
183
+ const body = html.slice(html.indexOf('<body>') + 6);
140
184
  const end = body.indexOf('<script type=');
141
- return {html: page.html, markup: end >= 0 ? body.slice(0, end) : body};
185
+ return {html, markup: end >= 0 ? body.slice(0, end) : body};
142
186
  } catch (e) {
143
187
  if (e instanceof RenderError) {
144
188
  const missing = e.code === 'ERR_RENDER_MISSING_DEPENDENCY';
189
+ // A render stopped by its time limit on the editor's own page is the
190
+ // machine being busy, not a loop in the page.
191
+ const slow = e.code === 'ERR_RENDER_TIMEOUT';
145
192
  throw new AstryxError(
146
- `Could not render the components with this project's React: ${e.message}${missing ? ' The theme command renders components on the server, so react and react-dom must be installed.' : ''}`,
147
- [],
193
+ slow
194
+ ? `The components did not finish rendering within ${EDITOR_RENDER_MS / 1000} seconds, so the render was stopped. The machine may be busy: run the command again when it is less loaded.`
195
+ : `Could not render the components with this project's React: ${e.message}${missing ? ' The theme command renders components on the server, so react and react-dom must be installed.' : ''}`,
196
+ missing
197
+ ? [
198
+ {
199
+ name: installLine(project.cwd, ['react', 'react-dom']),
200
+ reason: 'install them',
201
+ },
202
+ ]
203
+ : [],
148
204
  missing
149
205
  ? ERROR_CODES.ERR_RENDER_MISSING_DEPENDENCY
150
206
  : ERROR_CODES.ERR_RENDER_FAILED,
@@ -11,18 +11,18 @@
11
11
  export function decodePng(bytes: Buffer): Picture;
12
12
  /**
13
13
  * The exact color at each point, with its alpha (0 is fully see-through,
14
- * 1 fully opaque). Every point must be inside the picture.
14
+ * 1 fully opaque). A point outside the picture has no color.
15
15
  * @param {Picture} pic
16
16
  * @param {Array<{x: number, y: number}>} points
17
- * @returns {Array<{at: string, color: string, alpha: number}>}
17
+ * @returns {Array<{at: string, color: string | null, alpha: number | null}>}
18
18
  */
19
19
  export function colorsAt(pic: Picture, points: Array<{
20
20
  x: number;
21
21
  y: number;
22
22
  }>): Array<{
23
23
  at: string;
24
- color: string;
25
- alpha: number;
24
+ color: string | null;
25
+ alpha: number | null;
26
26
  }>;
27
27
  /**
28
28
  * The main colors of a picture: every pixel (on a grid past 4 million)
@@ -222,13 +222,15 @@ const hx = v => Math.round(v).toString(16).padStart(2, '0');
222
222
 
223
223
  /**
224
224
  * The exact color at each point, with its alpha (0 is fully see-through,
225
- * 1 fully opaque). Every point must be inside the picture.
225
+ * 1 fully opaque). A point outside the picture has no color.
226
226
  * @param {Picture} pic
227
227
  * @param {Array<{x: number, y: number}>} points
228
- * @returns {Array<{at: string, color: string, alpha: number}>}
228
+ * @returns {Array<{at: string, color: string | null, alpha: number | null}>}
229
229
  */
230
230
  export function colorsAt(pic, points) {
231
231
  return points.map(({x, y}) => {
232
+ if (x < 0 || y < 0 || x >= pic.width || y >= pic.height)
233
+ return {at: `${x},${y}`, color: null, alpha: null};
232
234
  const i = (y * pic.width + x) * 4;
233
235
  return {
234
236
  at: `${x},${y}`,
@@ -1,6 +1,12 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * For tests: stop the next preview changes at the step where `when`
6
+ * returns true, as a kill would, with nothing put back. Null clears it.
7
+ * @param {((step: string) => boolean) | null} when
8
+ */
9
+ export function stopPreviewCommitAt(when: ((step: string) => boolean) | null): void;
4
10
  /**
5
11
  * Rewrite the in-app preview routes of a theme when their imports changed, so
6
12
  * a font package installed after `set` loads on the next change or `show`,