@astryxdesign/cli 0.6.3-canary.f839b67 → 0.6.4-canary.06c8fa3

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 (189) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +64 -66
  3. package/api/component/_adapter.d.mts +25 -0
  4. package/api/component/_adapter.mjs +59 -5
  5. package/api/component/component.d.mts +6 -3
  6. package/api/component/component.doc.mjs +23 -10
  7. package/api/component/component.mjs +249 -9
  8. package/api/component/component.type.d.mts +25 -0
  9. package/api/component/component.type.mjs +44 -0
  10. package/api/discover/_adapter.d.mts +114 -6
  11. package/api/discover/_adapter.mjs +372 -17
  12. package/api/discover/_adapter.test.mjs +215 -0
  13. package/api/discover/_catalog-view.d.mts +115 -0
  14. package/api/discover/_catalog-view.mjs +203 -0
  15. package/api/discover/_catalog-view.test.mjs +128 -0
  16. package/api/discover/detail/detail.d.mts +18 -6
  17. package/api/discover/detail/detail.mjs +67 -13
  18. package/api/discover/detail/detail.test.mjs +85 -0
  19. package/api/discover/detail/item/item.d.mts +26 -0
  20. package/api/discover/detail/item/item.mjs +78 -0
  21. package/api/discover/detail/item/item.test.mjs +73 -0
  22. package/api/discover/discover.d.mts +3 -9
  23. package/api/discover/discover.doc.mjs +61 -18
  24. package/api/discover/discover.mjs +220 -36
  25. package/api/discover/discover.test.mjs +11 -2
  26. package/api/discover/discover.type.d.mts +147 -8
  27. package/api/discover/discover.type.mjs +102 -12
  28. package/api/discover/list/list.d.mts +20 -6
  29. package/api/discover/list/list.mjs +45 -12
  30. package/api/discover/list/list.test.mjs +46 -0
  31. package/api/discover/search/search.d.mts +18 -16
  32. package/api/discover/search/search.mjs +102 -56
  33. package/api/discover/search/search.test.mjs +144 -10
  34. package/api/docs/_adapter.d.mts +49 -7
  35. package/api/docs/_adapter.mjs +284 -33
  36. package/api/docs/docs.doc.mjs +4 -3
  37. package/api/docs/docs.test.mjs +2 -0
  38. package/api/docs/docs.type.d.mts +21 -5
  39. package/api/docs/docs.type.mjs +21 -5
  40. package/api/docs/integration-tree.test.mjs +9 -1
  41. package/api/docs/reference-blocks.test.mjs +406 -0
  42. package/api/doctor/doctor.d.mts +8 -3
  43. package/api/doctor/doctor.mjs +95 -10
  44. package/api/doctor/doctor.test.mjs +122 -10
  45. package/api/index.d.mts +1 -2
  46. package/api/index.mjs +4 -4
  47. package/api/integration/add-helpers.d.mts +5 -2
  48. package/api/integration/add-helpers.mjs +36 -9
  49. package/api/integration/authoring-checks.mjs +14 -1
  50. package/api/integration/pack-check.lifecycle-output.test.mjs +105 -0
  51. package/api/integration/pack-check.mjs +28 -3
  52. package/api/json/index.ts +0 -1
  53. package/api/search/search.test.mjs +18 -0
  54. package/api/template/table-floating-bulk-actions.test.mjs +66 -0
  55. package/api/template/template-integration.test.mjs +1 -65
  56. package/api/template/template.mjs +1 -1
  57. package/api/theme/add/add.mjs +17 -25
  58. package/api/theme/add/add.rollback.test.mjs +158 -0
  59. package/api/theme/add/add.staging.test.mjs +40 -23
  60. package/api/theme/build/build.family.test.mjs +7 -12
  61. package/api/theme/build/build.mjs +8 -18
  62. package/api/theme/build/build.rollback.test.mjs +148 -0
  63. package/api/upgrade/run/files-changed.test.mjs +111 -0
  64. package/api/upgrade/run/run.mjs +6 -4
  65. package/api/upgrade/upgrade.type.mjs +2 -2
  66. package/assets/codemods/__tests__/registry.test.mjs +1 -0
  67. package/assets/codemods/__tests__/runner.test.mjs +3 -1
  68. package/assets/codemods/file-count.test.mjs +163 -0
  69. package/assets/codemods/integration-runner.mjs +3 -3
  70. package/assets/codemods/registry.mjs +1 -0
  71. package/assets/codemods/runner.mjs +5 -4
  72. package/assets/codemods/transforms/next/index.mjs +1 -19
  73. package/assets/codemods/transforms/v0.6.4/index.mjs +31 -0
  74. package/assets/docs/internationalization.doc.mjs +7 -5
  75. package/assets/docs/styling-libraries.doc.mjs +1 -1
  76. package/assets/docs/theme.doc.mjs +1 -1
  77. package/assets/docs/tree/component-lookups.doc.mjs +149 -0
  78. package/assets/docs/tree/integrations.doc.mjs +20 -1
  79. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.doc.mjs +1 -1
  80. package/assets/templates/blocks/components/CheckboxList/CheckboxListSelectAllPattern.tsx +1 -3
  81. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
  82. package/assets/templates/blocks/components/Table/TableBulkActionsTable.doc.mjs +14 -0
  83. package/assets/templates/blocks/components/Table/TableBulkActionsTable.tsx +71 -0
  84. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.doc.mjs +19 -0
  85. package/assets/templates/blocks/components/Table/TableFloatingBulkActionsTable.tsx +139 -0
  86. package/authoring/config/config.doc.mjs +9 -1
  87. package/authoring/config/parse.d.mts +2 -0
  88. package/authoring/config/parse.mjs +19 -0
  89. package/authoring/config/parse.test.mjs +8 -0
  90. package/authoring/config/type.ts +13 -2
  91. package/authoring/discover/discover.doc.d.mts +13 -0
  92. package/authoring/discover/discover.doc.mjs +138 -0
  93. package/authoring/discover/parse.d.mts +24 -0
  94. package/authoring/discover/parse.mjs +128 -0
  95. package/authoring/discover/parse.test.mjs +124 -0
  96. package/authoring/discover/type.ts +87 -0
  97. package/authoring/doctypes/_schema.d.mts +72 -0
  98. package/authoring/doctypes/_schema.mjs +25 -1
  99. package/authoring/doctypes/command/command.doc.mjs +1 -1
  100. package/authoring/doctypes/command/type.ts +1 -1
  101. package/authoring/doctypes/load-contract.test.mjs +25 -0
  102. package/authoring/doctypes/reference/reference.doc.mjs +31 -4
  103. package/authoring/doctypes/reference/type.ts +20 -5
  104. package/authoring/index.d.mts +1 -0
  105. package/authoring/index.d.ts +10 -0
  106. package/authoring/index.mjs +1 -0
  107. package/clients/cli/command-result-coverage.test.mjs +7 -7
  108. package/clients/cli/commands/component/index.mjs +152 -55
  109. package/clients/cli/commands/component-batch.test.mjs +341 -0
  110. package/clients/cli/commands/component-ownership.test.mjs +89 -0
  111. package/clients/cli/commands/component.doc.mjs +23 -6
  112. package/clients/cli/commands/debug-result-summary.test.mjs +2 -2
  113. package/clients/cli/commands/discover.doc.mjs +53 -9
  114. package/clients/cli/commands/discover.mjs +393 -118
  115. package/clients/cli/commands/discover.sources.test.mjs +267 -0
  116. package/clients/cli/commands/docs.mjs +2 -2
  117. package/clients/cli/commands/docs.test.mjs +29 -0
  118. package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
  119. package/clients/cli/commands/text-json-parity.test.mjs +0 -17
  120. package/clients/cli/index.mjs +0 -4
  121. package/clients/cli/lib/exit-codes.test.mjs +1 -8
  122. package/clients/cli/lib/json-shim.mjs +24 -14
  123. package/clients/cli/lib/json-shim.test.mjs +6 -20
  124. package/clients/cli/lib/manifest.mjs +3 -8
  125. package/clients/cli/lib/manifest.test.mjs +5 -2
  126. package/clients/cli/lib/parse-error-format.test.mjs +81 -0
  127. package/foundation/discovery/authoring-self-docs.d.mts +12 -0
  128. package/foundation/discovery/authoring-self-docs.mjs +21 -8
  129. package/foundation/discovery/authoring-self-docs.test.mjs +7 -2
  130. package/foundation/discovery/docs-discovery.d.mts +4 -1
  131. package/foundation/discovery/docs-discovery.mjs +40 -6
  132. package/foundation/discovery/docs-discovery.test.mjs +40 -0
  133. package/foundation/discovery/template-adapter.mjs +1 -1
  134. package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
  135. package/foundation/doc-compiler/lenses.d.mts +5 -3
  136. package/foundation/doc-compiler/lenses.mjs +48 -3
  137. package/foundation/doc-compiler/links.d.mts +30 -3
  138. package/foundation/doc-compiler/links.mjs +46 -5
  139. package/foundation/doc-compiler/links.test.mjs +53 -0
  140. package/foundation/doc-compiler/tree.test.mjs +9 -1
  141. package/foundation/integrations/cli-requirement.test.mjs +17 -42
  142. package/foundation/integrations/integrations.d.mts +14 -1
  143. package/foundation/integrations/integrations.mjs +41 -1
  144. package/foundation/integrations/integrations.test.mjs +31 -0
  145. package/foundation/response/batch.type.d.mts +33 -0
  146. package/foundation/response/batch.type.mjs +34 -0
  147. package/foundation/response/response-types.doc.mjs +15 -21
  148. package/foundation/response/response-types.doc.test.mjs +23 -0
  149. package/foundation/xle/browser.d.mts +3 -3
  150. package/foundation/xle/browser.mjs +3 -3
  151. package/foundation/xle/expand.mjs +2 -2
  152. package/foundation/xle/parse.mjs +1 -1
  153. package/foundation/xle/print.mjs +2 -2
  154. package/foundation/xle/splice.mjs +1 -1
  155. package/package.json +9 -9
  156. package/api/layout/_adapter.d.mts +0 -34
  157. package/api/layout/_adapter.mjs +0 -148
  158. package/api/layout/check/check.d.mts +0 -16
  159. package/api/layout/check/check.mjs +0 -40
  160. package/api/layout/expand/expand.d.mts +0 -22
  161. package/api/layout/expand/expand.mjs +0 -155
  162. package/api/layout/expand/expand.path-safety.test.mjs +0 -53
  163. package/api/layout/grammar/grammar.d.mts +0 -13
  164. package/api/layout/grammar/grammar.mjs +0 -87
  165. package/api/layout/layout.d.mts +0 -6
  166. package/api/layout/layout.mjs +0 -17
  167. package/api/layout/layout.test.mjs +0 -297
  168. package/api/layout/layout.type.d.mts +0 -89
  169. package/api/layout/layout.type.mjs +0 -103
  170. package/api/layout/layoutCheck.doc.d.mts +0 -11
  171. package/api/layout/layoutCheck.doc.mjs +0 -85
  172. package/api/layout/layoutExpand.doc.d.mts +0 -11
  173. package/api/layout/layoutExpand.doc.mjs +0 -107
  174. package/api/layout/layoutGrammar.doc.d.mts +0 -11
  175. package/api/layout/layoutGrammar.doc.mjs +0 -57
  176. package/clients/cli/commands/layout-check.doc.mjs +0 -65
  177. package/clients/cli/commands/layout-expand.doc.mjs +0 -83
  178. package/clients/cli/commands/layout-grammar.doc.mjs +0 -30
  179. package/clients/cli/commands/layout.doc.mjs +0 -34
  180. package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
  181. package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
  182. package/clients/cli/commands/layout.mjs +0 -275
  183. package/clients/cli/commands/layout.path-help.test.mjs +0 -33
  184. package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
  185. package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
  186. /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-native-picker-to-presentation.test.mjs +0 -0
  187. /package/assets/codemods/transforms/{next → v0.6.4}/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +0 -0
  188. /package/assets/codemods/transforms/{next → v0.6.4}/migrate-native-picker-to-presentation.mjs +0 -0
  189. /package/assets/codemods/transforms/{next → v0.6.4}/migrate-theme-catalog-to-descriptors.mjs +0 -0
@@ -1,275 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file layout command — thin CLI wrapper around api/layout.mjs.
5
- *
6
- * Subcommands:
7
- * astryx layout expand "<expr>" [path] compressed expression → validated TSX
8
- * astryx layout check "<expr>" validate + echo both canonical surfaces
9
- * astryx layout grammar agent cheatsheet (alias table is branch-generated)
10
- *
11
- * The expression argument may also come from --file or stdin (`-`),
12
- * which is how multi-line outline (XLO) input usually arrives.
13
- *
14
- * The command surface (group + subcommand descriptions, args, flags) is sourced
15
- * from the colocated CommandDocs via `defineCommand`; this file supplies only the
16
- * actions.
17
- */
18
-
19
- import * as fs from 'node:fs';
20
- import * as path from 'node:path';
21
- import {jsonOut} from '../../../foundation/response/json.mjs';
22
- import {emit, section, text, list, record, code, WARN} from '../formatters/index.mjs';
23
- import {cliError} from '../lib/cli-error.mjs';
24
- import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
25
- import {layoutExpand, layoutCheck, layoutGrammar} from '../../../api/layout/layout.mjs';
26
- import {defineCommand} from '../lib/define-command.mjs';
27
- import {doc as layoutGroup} from './layout.doc.mjs';
28
- import {doc as layoutExpandCommand} from './layout-expand.doc.mjs';
29
- import {doc as layoutCheckCommand} from './layout-check.doc.mjs';
30
- import {doc as layoutGrammarCommand} from './layout-grammar.doc.mjs';
31
- import {doc as layoutExpandFn} from '../../../api/layout/layoutExpand.doc.mjs';
32
- import {doc as layoutCheckFn} from '../../../api/layout/layoutCheck.doc.mjs';
33
- import {doc as layoutGrammarFn} from '../../../api/layout/layoutGrammar.doc.mjs';
34
- import {NO_RESULT_SET, resultSet} from '../../../foundation/debug/index.mjs';
35
-
36
- /**
37
- * The api layer's @returns for these functions widen the `type` discriminator
38
- * to `string`, so annotate the command-local result with the precise response
39
- * shapes from the colocated api/layout/layout.type.mjs so narrowing + jsonOut
40
- * typecheck.
41
- *
42
- * @typedef {import('../../../api/layout/layout.type.mjs').LayoutExpandResponse} LayoutExpandResponse
43
- * @typedef {import('../../../api/layout/layout.type.mjs').LayoutCheckResponse} LayoutCheckResponse
44
- * @typedef {import('../../../api/layout/layout.type.mjs').LayoutGrammarResponse} LayoutGrammarResponse
45
- */
46
-
47
- /**
48
- * @typedef {object} LayoutExpandOptions
49
- * @property {string} [file]
50
- * @property {'compact'|'outline'|'auto'} [form]
51
- * @property {string} [name]
52
- * @property {boolean} [loose]
53
- */
54
-
55
- /**
56
- * @typedef {object} LayoutCheckOptions
57
- * @property {string} [file]
58
- * @property {'compact'|'outline'|'auto'} [form]
59
- * @property {boolean} [loose]
60
- */
61
-
62
- /** The largest layout expression read from --file or stdin. */
63
- const MAX_EXPRESSION_BYTES = 5 * 1024 * 1024; // 5 MB
64
-
65
- /**
66
- * Resolve the expression from arg, --file, or stdin ('-').
67
- * @param {string} [expr]
68
- * @param {{file?: string}} [options]
69
- * @returns {Promise<string>}
70
- */
71
- async function readExpression(expr, options = {}) {
72
- if (options.file) {
73
- // Validate the file exists + is a regular file + is reasonably sized.
74
- // We intentionally do NOT confine the read path (the user running the CLI
75
- // controls --file; this is a read, not a write). The size cap prevents OOM
76
- // from infinite streams like /dev/zero.
77
- const filePath = path.resolve(process.cwd(), options.file);
78
- const stat = fs.statSync(filePath, {throwIfNoEntry: false});
79
- if (!stat || !stat.isFile()) {
80
- cliError(`File not found: ${options.file}`, {
81
- code: ERROR_CODES.ERR_FILE_NOT_FOUND,
82
- });
83
- }
84
- if (stat.size > MAX_EXPRESSION_BYTES) {
85
- cliError(
86
- `File "${options.file}" is too large (${(stat.size / 1024 / 1024).toFixed(1)} MB, max 5 MB)`,
87
- {code: ERROR_CODES.ERR_FILE_NOT_FOUND},
88
- );
89
- }
90
- try {
91
- return fs.readFileSync(filePath, 'utf-8');
92
- } catch (e) {
93
- const errno = /** @type {NodeJS.ErrnoException} */ (e);
94
- if (errno && errno.code === 'ENOENT') {
95
- // A --file pointing at a missing file is foreseeable — surface a
96
- // stable code, not the raw ENOENT errno (and no stack in human mode).
97
- cliError(`File not found: ${options.file}`, {
98
- code: ERROR_CODES.ERR_FILE_NOT_FOUND,
99
- });
100
- }
101
- throw e;
102
- }
103
- }
104
- if (expr === '-') {
105
- // Capped like --file: an endless stream must not be buffered whole.
106
- /** @type {Buffer[]} */
107
- const chunks = [];
108
- let size = 0;
109
- for await (const chunk of process.stdin) {
110
- size += /** @type {Buffer} */ (chunk).length;
111
- if (size > MAX_EXPRESSION_BYTES) {
112
- cliError('The layout expression on stdin is too large (max 5 MB)', {
113
- code: ERROR_CODES.ERR_INVALID_ARGUMENT,
114
- });
115
- }
116
- chunks.push(/** @type {Buffer} */ (chunk));
117
- }
118
- return Buffer.concat(chunks).toString('utf-8');
119
- }
120
- return expr ?? '';
121
- }
122
-
123
- /**
124
- * @param {import('commander').Command} program
125
- */
126
- export function registerLayout(program) {
127
- const layoutCmd = defineCommand(program, layoutGroup);
128
-
129
- defineCommand(layoutCmd, layoutExpandCommand, {
130
- fn: layoutExpandFn,
131
- action: async (/** @type {string} */ expression, /** @type {string} */ targetPath, /** @type {LayoutExpandOptions} */ options) => {
132
- const json = program.opts().json || false;
133
- const source = await readExpression(expression, options);
134
- if (!source || source.trim() === '') {
135
- return cliError(
136
- 'No layout expression given — pass it as an argument, via --file, or on stdin',
137
- {code: ERROR_CODES.ERR_MISSING_ARGUMENT},
138
- );
139
- }
140
- /** @type {LayoutExpandResponse} */
141
- let result;
142
- try {
143
- result = /** @type {LayoutExpandResponse} */ (await layoutExpand(source, {
144
- targetPath,
145
- form: options.form,
146
- loose: options.loose || false,
147
- name: options.name,
148
- cwd: process.cwd(),
149
- }));
150
- } catch (e) {
151
- const err = /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
152
- return cliError(err.message, {suggestions: err.suggestions || [], code: err.code});
153
- }
154
- // Expanding turns an expression into TSX — a transformation, not a
155
- // lookup. What it produced is in the output; there is no set to count.
156
- if (json) {
157
- jsonOut(result);
158
- return NO_RESULT_SET;
159
- }
160
-
161
- /** @type {import('../formatters/index.mjs').Block[]} */
162
- const out = [];
163
- if (result.data.warnings.length > 0) {
164
- out.push(text(result.data.warnings.map(w => `${WARN} ${w}`).join('\n')));
165
- }
166
- if (result.data.written) {
167
- out.push(
168
- text(`[ok] Expanded to ${result.data.written}`),
169
- // Field names are the JSON keys; todos are summarised, not listed.
170
- record(
171
- {componentsUsed: result.data.componentsUsed, todos: result.data.todos},
172
- {
173
- format: {
174
- todos: (/** @type {string[]} */ todos) =>
175
- `${todos.length} (search for "TODO(xle)")`,
176
- },
177
- },
178
- ),
179
- );
180
- } else {
181
- // Raw expanded TSX (no target path) — preformatted, emitted verbatim.
182
- out.push(code(result.data.code));
183
- }
184
- emit(...out);
185
- return NO_RESULT_SET;
186
- },
187
- });
188
-
189
- defineCommand(layoutCmd, layoutCheckCommand, {
190
- fn: layoutCheckFn,
191
- action: async (/** @type {string} */ expression, /** @type {LayoutCheckOptions} */ options) => {
192
- const json = program.opts().json || false;
193
- const source = await readExpression(expression, options);
194
- if (!source || source.trim() === '') {
195
- return cliError(
196
- 'No layout expression given — pass it as an argument, via --file, or on stdin',
197
- {code: ERROR_CODES.ERR_MISSING_ARGUMENT},
198
- );
199
- }
200
- /** @type {LayoutCheckResponse} */
201
- let result;
202
- try {
203
- result = /** @type {LayoutCheckResponse} */ (await layoutCheck(source, {
204
- form: options.form,
205
- loose: options.loose || false,
206
- cwd: process.cwd(),
207
- }));
208
- } catch (e) {
209
- const err = /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
210
- return cliError(err.message, {suggestions: err.suggestions || [], code: err.code});
211
- }
212
- // Exit code is the contract and must NOT depend on --json vs human: an
213
- // invalid (but parseable) layout exits 1 in BOTH modes so `layout check`
214
- // works as a CI gate / agent check without parsing stdout. Decide it
215
- // before the JSON return (parity with doctor integration validate).
216
- if (!result.data.valid) process.exitCode = 1;
217
-
218
- // A verdict on one expression: valid or not, with the errors that made
219
- // it so. Nothing was looked up.
220
- if (json) {
221
- jsonOut(result);
222
- return NO_RESULT_SET;
223
- }
224
-
225
- const {valid, form, errors, warnings, compact, outline} = result.data;
226
- if (!valid) {
227
- // Each error: the formatted issue, with a hanging "did you mean" line.
228
- const items = errors.map(e =>
229
- e.suggestions && e.suggestions.length > 0
230
- ? [e.formatted, `did you mean: ${e.suggestions.join(', ')}?`]
231
- : [e.formatted],
232
- );
233
- emit(
234
- text(`[fail] Invalid (${errors.length} error${errors.length === 1 ? '' : 's'}):`),
235
- list(items),
236
- );
237
- return NO_RESULT_SET;
238
- }
239
-
240
- /** @type {import('../formatters/index.mjs').Block[]} */
241
- const out = [text(`[ok] Valid (parsed as ${form})`)];
242
- if (warnings.length > 0) {
243
- out.push(text(warnings.map(w => `${WARN} ${w}`).join('\n')));
244
- }
245
- // The canonical compact/outline surfaces are preformatted — emit verbatim.
246
- out.push(section('compact'), code(compact), section('outline'), code(outline));
247
- emit(...out);
248
- return NO_RESULT_SET;
249
- },
250
- });
251
-
252
- defineCommand(layoutCmd, layoutGrammarCommand, {
253
- fn: layoutGrammarFn,
254
- action: async () => {
255
- const json = program.opts().json || false;
256
- /** @type {LayoutGrammarResponse} */
257
- let result;
258
- try {
259
- result = /** @type {LayoutGrammarResponse} */ (await layoutGrammar({cwd: process.cwd()}));
260
- } catch (e) {
261
- const err = /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
262
- return cliError(err.message, {suggestions: err.suggestions || [], code: err.code});
263
- }
264
- // One document, the same one every time: the grammar cheatsheet.
265
- const answered = resultSet({count: 1, resultKind: 'doc'});
266
- if (json) {
267
- jsonOut(result);
268
- return answered;
269
- }
270
- // The cheatsheet is a preformatted document — emit verbatim.
271
- emit(code(result.data.text));
272
- return answered;
273
- },
274
- });
275
- }
@@ -1,33 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file `layout expand` and `layout check` document their input modes (the
5
- * argument, `-` for stdin, --file) and where `layout expand` writes.
6
- */
7
-
8
- import {describe, it, expect} from 'vitest';
9
- import {runCli} from '../../../test-utils/run-cli.mjs';
10
- import {isFilePathArg} from '../../../foundation/fs/path-safety.mjs';
11
-
12
- const SLOW = 30_000;
13
-
14
- describe('layout argument behavior is documented', () => {
15
- it('layout expand help covers stdin, --file precedence and the output path rule', async () => {
16
- const {status, stdout} = await runCli(['layout', 'expand', '--help']);
17
- expect(status).toBe(0);
18
- expect(stdout).toMatch(/Pass - to read it from stdin/);
19
- expect(stdout).toMatch(/instead of the argument/);
20
- expect(stdout).toContain('<Name>.tsx');
21
- expect(stdout).toMatch(/existing file there is replaced/);
22
- const exts = [...(stdout.match(/ends in ([.\w, ]+ or \.\w+)/)?.[1] ?? '').matchAll(/\.\w+/g)];
23
- expect(exts.length).toBeGreaterThan(0);
24
- for (const [ext] of exts) expect(isFilePathArg(`src/Page${ext}`)).toBe(true);
25
- }, SLOW);
26
-
27
- it('layout check help covers stdin and --file precedence', async () => {
28
- const {status, stdout} = await runCli(['layout', 'check', '--help']);
29
- expect(status).toBe(0);
30
- expect(stdout).toMatch(/Pass - to read it from stdin/);
31
- expect(stdout).toMatch(/instead of the argument/);
32
- }, SLOW);
33
- });
@@ -1,47 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file `layout check -` reads the expression from stdin under the same 5 MB
5
- * cap as --file, instead of buffering whatever the pipe delivers. Spawns the
6
- * real bin, since the in-process harness has no stdin.
7
- */
8
-
9
- import {describe, it, expect} from 'vitest';
10
- import {spawnSync} from 'node:child_process';
11
- import * as path from 'node:path';
12
- import {fileURLToPath} from 'node:url';
13
-
14
- const HERE = path.dirname(fileURLToPath(import.meta.url));
15
- const BIN = path.resolve(HERE, '../bin/astryx.mjs');
16
- // Run against the monorepo root so @astryxdesign/core is discoverable.
17
- const REPO = path.resolve(HERE, '../../../..');
18
- const SLOW = 60_000;
19
-
20
- /** @param {string} input @param {string[]} [extra] */
21
- function checkFromStdin(input, extra = []) {
22
- return spawnSync(process.execPath, [BIN, 'layout', 'check', '-', ...extra], {
23
- cwd: REPO,
24
- input,
25
- encoding: 'utf-8',
26
- maxBuffer: 16 * 1024 * 1024,
27
- });
28
- }
29
-
30
- describe('layout check - (stdin)', () => {
31
- it('refuses more than 5 MB with ERR_INVALID_ARGUMENT, in both modes', () => {
32
- // Valid once trimmed, so only the cap can reject it.
33
- const big = ' '.repeat(5 * 1024 * 1024 + 1) + 'V';
34
- const json = checkFromStdin(big, ['--json']);
35
- expect(json.status).toBe(1);
36
- expect(JSON.parse(json.stdout).code).toBe('ERR_INVALID_ARGUMENT');
37
- const human = checkFromStdin(big);
38
- expect(human.status).toBe(1);
39
- expect(human.stderr + human.stdout).toMatch(/too large/);
40
- }, SLOW);
41
-
42
- it('still reads a normal expression', () => {
43
- const r = checkFromStdin('V > B', ['--json']);
44
- expect(r.status).toBe(0);
45
- expect(JSON.parse(r.stdout).data.valid).toBe(true);
46
- }, SLOW);
47
- });
@@ -1,39 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file `layout expand` text output names its fields after the JSON keys, so
5
- * the two views stay greppable against each other.
6
- */
7
-
8
- import {describe, it, expect, beforeEach, afterEach} from 'vitest';
9
- import * as fs from 'node:fs';
10
- import * as path from 'node:path';
11
- import {runCli} from '../../../test-utils/run-cli.mjs';
12
-
13
- const SLOW = 60_000;
14
-
15
- describe('layout expand text fields mirror the JSON keys', () => {
16
- let cwd;
17
- beforeEach(() => {
18
- // Inside the workspace so @astryxdesign/core resolves.
19
- cwd = fs.mkdtempSync(path.join(process.cwd(), '.xle-text-fields-'));
20
- });
21
- afterEach(() => fs.rmSync(cwd, {recursive: true, force: true}));
22
-
23
- it('labels every record field with a key of the layout.expand data', async () => {
24
- const expr = 'V > B + {not-a-real-block}';
25
- const json = await runCli(['layout', 'expand', expr, './a', '--loose', '--json'], cwd);
26
- expect(json.status).toBe(0);
27
- const {data} = JSON.parse(json.stdout);
28
- expect(data.todos.length).toBeGreaterThan(0);
29
-
30
- const human = await runCli(['layout', 'expand', expr, './b', '--loose'], cwd);
31
- expect(human.status).toBe(0);
32
- const fields = human.stdout
33
- .split('\n')
34
- .map(line => /^([A-Za-z]+):\s/.exec(line)?.[1])
35
- .filter(Boolean);
36
- expect(fields).toEqual(['componentsUsed', 'todos']);
37
- for (const field of fields) expect(Object.keys(data)).toContain(field);
38
- }, SLOW);
39
- });