@astryxdesign/cli 0.6.3-canary.29be688 → 0.6.3-canary.2bb99ed

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 (62) hide show
  1. package/README.md +2 -0
  2. package/api/docs/detail/section/section.mjs +9 -15
  3. package/api/docs/detail/section/section.test.mjs +15 -6
  4. package/api/doctor/doctor.mjs +1 -1
  5. package/api/doctor/doctor.test.mjs +6 -6
  6. package/api/upgrade/_adapter.d.mts +22 -4
  7. package/api/upgrade/_adapter.mjs +19 -6
  8. package/api/upgrade/run/run.mjs +355 -59
  9. package/api/upgrade/upgrade.doc.mjs +5 -1
  10. package/api/upgrade/upgrade.type.d.mts +34 -0
  11. package/api/upgrade/upgrade.type.mjs +15 -0
  12. package/assets/codemods/__tests__/runner.test.mjs +330 -8
  13. package/assets/codemods/integration-runner.mjs +56 -4
  14. package/assets/codemods/integration-runner.protection.test.mjs +153 -0
  15. package/assets/codemods/run-codemod.mjs +177 -34
  16. package/assets/codemods/runner.mjs +248 -110
  17. package/assets/codemods/transforms/next/__tests__/migrate-native-picker-to-presentation.test.mjs +63 -0
  18. package/assets/codemods/transforms/next/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +4 -0
  19. package/assets/codemods/transforms/next/index.mjs +8 -0
  20. package/assets/codemods/transforms/next/migrate-native-picker-to-presentation.mjs +148 -0
  21. package/assets/docs/cli-integrations.doc.mjs +13 -0
  22. package/assets/templates/blocks/components/DateInput/DateInputDateRange.tsx +1 -1
  23. package/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs +14 -0
  24. package/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx +100 -0
  25. package/assets/templates/blocks/components/TimeInput/TimeInputConstrained.tsx +1 -0
  26. package/authoring/codemod/type.ts +12 -0
  27. package/authoring/doctypes/_schema.d.mts +71 -141
  28. package/authoring/doctypes/_schema.mjs +29 -2
  29. package/authoring/doctypes/load-contract.test.mjs +1 -1
  30. package/authoring/doctypes/namespace/namespace.doc.mjs +2 -2
  31. package/authoring/doctypes/namespace/parse.test.mjs +23 -25
  32. package/authoring/doctypes/namespace/type.ts +5 -2
  33. package/authoring/doctypes/parse.mjs +3 -2
  34. package/authoring/doctypes/reference/reference.doc.mjs +5 -3
  35. package/authoring/doctypes/reference/type.ts +7 -8
  36. package/authoring/index.d.ts +1 -0
  37. package/clients/cli/commands/build-theme.mjs +10 -44
  38. package/clients/cli/commands/docs.mjs +15 -58
  39. package/clients/cli/commands/docs.test.mjs +11 -14
  40. package/clients/cli/commands/text-json-parity.test.mjs +718 -0
  41. package/clients/cli/commands/theme-targets.behavior.test.mjs +4 -3
  42. package/clients/cli/commands/upgrade.doc.mjs +2 -1
  43. package/clients/cli/commands/upgrade.file-protection.test.mjs +228 -0
  44. package/clients/cli/commands/upgrade.mjs +29 -7
  45. package/clients/cli/formatters/index.mjs +2 -0
  46. package/clients/cli/formatters/index.test.mjs +6 -0
  47. package/foundation/discovery/authoring-self-docs.test.mjs +3 -2
  48. package/foundation/discovery/docs-discovery.mjs +6 -5
  49. package/foundation/discovery/docs-discovery.test.mjs +7 -10
  50. package/foundation/discovery/docs-section-key.d.mts +19 -8
  51. package/foundation/discovery/docs-section-key.mjs +119 -32
  52. package/foundation/discovery/docs-section-key.test.mjs +41 -19
  53. package/foundation/doc-compiler/compile.mjs +5 -4
  54. package/foundation/fs/file-protection.d.mts +33 -0
  55. package/foundation/fs/file-protection.mjs +825 -0
  56. package/foundation/fs/file-protection.test.mjs +250 -0
  57. package/foundation/response/error-codes.d.mts +3 -1
  58. package/foundation/response/error-codes.d.ts +2 -0
  59. package/foundation/response/error-codes.doc.mjs +10 -0
  60. package/foundation/response/error-codes.mjs +6 -0
  61. package/foundation/response/error-codes.test.mjs +55 -11
  62. package/package.json +10 -9
@@ -34,7 +34,10 @@ const SOURCE_TITLE = Symbol('astryx.docs.sourceTitle');
34
34
  * @returns {T}
35
35
  */
36
36
  export function withSourceTitle(section, title) {
37
- Object.defineProperty(section, SOURCE_TITLE, {value: title, configurable: true});
37
+ Object.defineProperty(section, SOURCE_TITLE, {
38
+ value: title,
39
+ configurable: true,
40
+ });
38
41
  return section;
39
42
  }
40
43
 
@@ -77,9 +80,63 @@ export function sectionKey(section) {
77
80
  }
78
81
 
79
82
  /**
80
- * Problems with the keys of a topic's sections: an authored id that is not a
81
- * stable key, a title no key derives from, and two sections sharing a key.
82
- * Keys are never suffixed to make them unique, because readers link to them.
83
+ * The first section the 0.6.x title-substring lookup would return for a query.
84
+ * @param {any[]} sections
85
+ * @param {string} query
86
+ * @returns {number}
87
+ */
88
+ function legacyTitleMatchIndex(sections, query) {
89
+ const lower = query.toLowerCase();
90
+ return sections.findIndex(section => {
91
+ const title = sourceTitle(section);
92
+ return typeof title === 'string' && title.toLowerCase().includes(lower);
93
+ });
94
+ }
95
+
96
+ /**
97
+ * Fatal key problems: only an explicitly authored `id` can make a previously
98
+ * readable topic invalid. Derived-key collisions and titles with no Latin
99
+ * letters or digits are handled by {@link withSectionKeys} for 0.6.x
100
+ * compatibility.
101
+ * @param {any[]} sections
102
+ * @returns {string[]}
103
+ */
104
+ export function sectionKeyErrors(sections) {
105
+ /** @type {string[]} */
106
+ const problems = [];
107
+ /** @type {Map<string, number>} */
108
+ const seen = new Map();
109
+ sections.forEach((section, s) => {
110
+ if (section?.id == null) return;
111
+ const at = `sections[${s}]`;
112
+ if (typeof section.id !== 'string' || !SECTION_KEY_RE.test(section.id)) {
113
+ problems.push(
114
+ `${at}.id: ${JSON.stringify(section.id)} is not a stable key. Use lowercase letters and digits joined by single hyphens.`,
115
+ );
116
+ return;
117
+ }
118
+ const first = seen.get(section.id);
119
+ if (first != null) {
120
+ problems.push(
121
+ `${at}: the key "${section.id}" is already used by sections[${first}]. Give one of them a distinct id.`,
122
+ );
123
+ return;
124
+ }
125
+ const legacyOwner = legacyTitleMatchIndex(sections, section.id);
126
+ if (legacyOwner !== -1 && legacyOwner !== s) {
127
+ problems.push(
128
+ `${at}.id: the key "${section.id}" is already a legacy title query for sections[${legacyOwner}]. Choose an id that resolves to this section.`,
129
+ );
130
+ return;
131
+ }
132
+ seen.set(section.id, s);
133
+ });
134
+ return problems;
135
+ }
136
+
137
+ /**
138
+ * Compatibility notices for section keys. These inputs loaded in 0.6.x, so
139
+ * readers keep accepting them and assign deterministic fallback keys.
83
140
  * @param {any[]} sections
84
141
  * @returns {string[]}
85
142
  */
@@ -90,7 +147,6 @@ export function sectionKeyProblems(sections) {
90
147
  const seen = new Map();
91
148
  sections.forEach((section, s) => {
92
149
  const at = `sections[${s}]`;
93
- // A missing title is reported where titles are checked; no key to judge.
94
150
  if (
95
151
  section?.id == null &&
96
152
  (typeof section?.title !== 'string' || section.title === '')
@@ -109,14 +165,14 @@ export function sectionKeyProblems(sections) {
109
165
  const key = sectionKey(section);
110
166
  if (key === '') {
111
167
  problems.push(
112
- `${at}: no key derives from the title ${JSON.stringify(section?.title)}. Give the section an id.`,
168
+ `${at}: no key derives from the title ${JSON.stringify(section?.title)}. A deterministic section-N compatibility key is used; add an explicit id.`,
113
169
  );
114
170
  return;
115
171
  }
116
172
  const first = seen.get(key);
117
173
  if (first != null) {
118
174
  problems.push(
119
- `${at}: the key "${key}" is already used by sections[${first}]. Give one of them a distinct id or title.`,
175
+ `${at}: the key "${key}" is already used by sections[${first}]. A suffixed compatibility key is used for title-derived collisions; give one of them a distinct id or title.`,
120
176
  );
121
177
  return;
122
178
  }
@@ -133,48 +189,79 @@ export function sectionKeyProblems(sections) {
133
189
  * @returns {T}
134
190
  */
135
191
  export function withSectionKeys(doc) {
192
+ const reserved = new Set(
193
+ doc.sections
194
+ .map(section => section?.id)
195
+ .filter(id => typeof id === 'string' && SECTION_KEY_RE.test(id)),
196
+ );
197
+ const used = new Set();
136
198
  return {
137
199
  ...doc,
138
- sections: doc.sections.map(section =>
139
- section.id != null
140
- ? section
141
- : withSourceTitle(
142
- {...section, id: sectionKey(section)},
143
- sourceTitle(section),
144
- ),
145
- ),
200
+ sections: doc.sections.map((section, index) => {
201
+ if (section.id != null) {
202
+ used.add(section.id);
203
+ return section;
204
+ }
205
+ const base =
206
+ sectionTitleKey(sourceTitle(section)) || `section-${index + 1}`;
207
+ let key = base;
208
+ let suffix = 2;
209
+ while (
210
+ reserved.has(key) ||
211
+ used.has(key) ||
212
+ (legacyTitleMatchIndex(doc.sections, key) !== -1 &&
213
+ legacyTitleMatchIndex(doc.sections, key) !== index)
214
+ ) {
215
+ key = `${base}-${suffix}`;
216
+ suffix += 1;
217
+ }
218
+ used.add(key);
219
+ return withSourceTitle({...section, id: key}, sourceTitle(section));
220
+ }),
146
221
  };
147
222
  }
148
223
 
149
224
  /**
150
- * Find the section a reader asked for: by key, then by exact title (or the
151
- * key the query derives), then by a title that contains the query. More than
152
- * one match is refused rather than guessed.
225
+ * Find the section a reader asked for. The 0.6.x first-match title-substring
226
+ * lookup remains first in the authored-title view. In a localized view, an
227
+ * exact stable key resolves before translated title substrings because those
228
+ * translations cannot participate in language-stable key allocation. Generated
229
+ * keys avoid authored-title conflicts, and authored IDs that would shadow an
230
+ * authored legacy query are rejected.
153
231
  * @param {any[]} sections
154
232
  * @param {string} query
155
- * @returns {{section: any | null, candidates: any[]}} `candidates` lists the
156
- * matches when the query is ambiguous, and is empty when nothing matches
233
+ * @returns {{section: any | null, candidates: any[]}} `candidates` lists every
234
+ * legacy title match when the query is ambiguous
157
235
  */
158
236
  export function findDocSection(sections, query) {
159
237
  const wanted = query.trim();
160
238
  const byKey = sections.find(section => sectionKey(section) === wanted);
161
- if (byKey) return {section: byKey, candidates: []};
239
+ const hasLocalizedTitles = sections.some(
240
+ section => sourceTitle(section) !== section.title,
241
+ );
242
+ if (byKey && hasLocalizedTitles) {
243
+ return {section: byKey, candidates: []};
244
+ }
162
245
 
163
246
  const lower = wanted.toLowerCase();
164
- const derived = sectionTitleKey(wanted);
165
- const exact = sections.filter(
166
- section =>
167
- section.title.toLowerCase() === lower ||
168
- (derived !== '' && sectionTitleKey(sourceTitle(section)) === derived),
247
+ const legacy = sections.filter(section =>
248
+ section.title.toLowerCase().includes(lower),
169
249
  );
170
- if (exact.length === 1) return {section: exact[0], candidates: []};
171
- if (exact.length > 1) return {section: null, candidates: exact};
250
+ if (legacy.length > 0) {
251
+ return {section: legacy[0], candidates: legacy.length > 1 ? legacy : []};
252
+ }
172
253
 
173
- const partial = sections.filter(section =>
174
- section.title.toLowerCase().includes(lower),
254
+ const byFallbackKey = sections.find(
255
+ section => sectionKey(section) === wanted,
256
+ );
257
+ if (byFallbackKey) return {section: byFallbackKey, candidates: []};
258
+
259
+ const derived = sectionTitleKey(wanted);
260
+ const byDerivedKey = sections.find(
261
+ section =>
262
+ derived !== '' && sectionTitleKey(sourceTitle(section)) === derived,
175
263
  );
176
- if (partial.length === 1) return {section: partial[0], candidates: []};
177
- return {section: null, candidates: partial};
264
+ return {section: byDerivedKey ?? null, candidates: []};
178
265
  }
179
266
 
180
267
  /**
@@ -7,6 +7,7 @@ import {
7
7
  buildDocsIndexData,
8
8
  findDocSection,
9
9
  sectionKey,
10
+ sectionKeyErrors,
10
11
  sectionKeyProblems,
11
12
  sectionSummary,
12
13
  sectionTitleKey,
@@ -68,12 +69,17 @@ describe('sectionKeyProblems', () => {
68
69
  section('Quick-start'),
69
70
  ]);
70
71
  expect(problems).toHaveLength(1);
71
- expect(problems[0]).toContain('"quick-start" is already used by sections[0]');
72
+ expect(problems[0]).toContain(
73
+ '"quick-start" is already used by sections[0]',
74
+ );
72
75
  });
73
76
 
74
77
  it('rejects an authored id that collides with a derived key', () => {
75
78
  expect(
76
- sectionKeyProblems([section('Install'), section('Setup', {id: 'install'})]),
79
+ sectionKeyProblems([
80
+ section('Install'),
81
+ section('Setup', {id: 'install'}),
82
+ ]),
77
83
  ).toHaveLength(1);
78
84
  });
79
85
 
@@ -85,13 +91,13 @@ describe('sectionKeyProblems', () => {
85
91
  }
86
92
  });
87
93
 
88
- it('rejects a title no key derives from', () => {
94
+ it('reports a title no key derives from', () => {
89
95
  expect(sectionKeyProblems([section('亮/暗模式')])[0]).toContain(
90
- 'Give the section an id',
91
- );
92
- expect(sectionKeyProblems([section('亮/暗模式', {id: 'light-dark'})])).toEqual(
93
- [],
96
+ 'compatibility key is used',
94
97
  );
98
+ expect(
99
+ sectionKeyProblems([section('亮/暗模式', {id: 'light-dark'})]),
100
+ ).toEqual([]);
95
101
  });
96
102
 
97
103
  it('leaves a missing title to the title check', () => {
@@ -107,12 +113,21 @@ describe('withSectionKeys', () => {
107
113
  expect(doc.sections.map(s => s.id)).toEqual(['quick-start', 'use']);
108
114
  });
109
115
 
110
- it('keeps the authored title of a translated section', () => {
116
+ it('keeps authored titles and keys stable for translated sections', () => {
111
117
  const doc = withSectionKeys({
112
- sections: [withSourceTitle(section('快速开始'), 'Quick Start')],
118
+ sections: [
119
+ withSourceTitle(section('高级安装'), 'Install advanced'),
120
+ withSourceTitle(section('安装'), 'Install'),
121
+ ],
113
122
  });
114
- expect(doc.sections[0].id).toBe('quick-start');
115
- expect(sourceTitle(doc.sections[0])).toBe('Quick Start');
123
+ expect(doc.sections.map(s => s.id)).toEqual([
124
+ 'install-advanced',
125
+ 'install-2',
126
+ ]);
127
+ for (const target of doc.sections) {
128
+ expect(findDocSection(doc.sections, target.id).section).toBe(target);
129
+ }
130
+ expect(sourceTitle(doc.sections[0])).toBe('Install advanced');
116
131
  });
117
132
  });
118
133
 
@@ -127,7 +142,14 @@ describe('findDocSection', () => {
127
142
  ],
128
143
  }).sections;
129
144
 
130
- it('finds a section by key first', () => {
145
+ it('finds every emitted key without changing a legacy query', () => {
146
+ const colliding = withSectionKeys({
147
+ sections: [section('Install advanced'), section('Install')],
148
+ }).sections;
149
+ expect(findDocSection(colliding, 'install').section).toBe(colliding[0]);
150
+ for (const target of colliding) {
151
+ expect(findDocSection(colliding, target.id).section).toBe(target);
152
+ }
131
153
  expect(findDocSection(sections, 'tokens').section.title).toBe(
132
154
  'Theme Tokens',
133
155
  );
@@ -149,15 +171,15 @@ describe('findDocSection', () => {
149
171
  expect(findDocSection(sections, 'props').section.id).toBe('theme-props');
150
172
  });
151
173
 
152
- it('refuses an ambiguous exact title and lists the candidates', () => {
174
+ it('keeps the first ambiguous exact-title match and lists the candidates', () => {
153
175
  const {section: match, candidates} = findDocSection(sections, 'Overview');
154
- expect(match).toBeNull();
176
+ expect(match?.id).toBe('overview-a');
155
177
  expect(candidates.map(s => s.id)).toEqual(['overview-a', 'overview-b']);
156
178
  });
157
179
 
158
- it('refuses an ambiguous partial title', () => {
180
+ it('keeps the first ambiguous partial-title match', () => {
159
181
  const {section: match, candidates} = findDocSection(sections, 'theme');
160
- expect(match).toBeNull();
182
+ expect(match?.id).toBe('theme-props');
161
183
  expect(candidates.map(s => s.id)).toEqual(['theme-props', 'tokens']);
162
184
  });
163
185
 
@@ -185,9 +207,9 @@ describe('sectionSummary', () => {
185
207
  });
186
208
 
187
209
  it('is empty when the section has no text', () => {
188
- expect(sectionSummary({content: [{type: 'table', headers: [], rows: []}]})).toBe(
189
- '',
190
- );
210
+ expect(
211
+ sectionSummary({content: [{type: 'table', headers: [], rows: []}]}),
212
+ ).toBe('');
191
213
  });
192
214
 
193
215
  it('cuts a long summary at a word boundary', () => {
@@ -26,7 +26,7 @@ import {parseTheme} from '../../authoring/doctypes/theme/parse.mjs';
26
26
  import {mergeTopic, problemsInTopic} from '../discovery/docs-discovery.mjs';
27
27
  import {
28
28
  sectionKey,
29
- sectionKeyProblems,
29
+ sectionKeyErrors,
30
30
  sourceTitle,
31
31
  withSectionKeys,
32
32
  withSourceTitle,
@@ -130,11 +130,12 @@ export function lowerReferenceTopic(input) {
130
130
  let doc = readAuthoredFile(input.base);
131
131
  for (const extension of input.extensions) {
132
132
  doc = mergeTopic(doc, readAuthoredFile(extension));
133
- // Merging matches on keys, so this holds unless merge itself regresses.
134
- const problems = sectionKeyProblems(doc.sections);
133
+ // Explicit authored IDs remain strict. Legacy title-derived collisions are
134
+ // assigned deterministic compatibility keys after every extension merges.
135
+ const problems = sectionKeyErrors(doc.sections);
135
136
  if (problems.length > 0) {
136
137
  throw new Error(
137
- `${extension.file}, extending ${input.id}, leaves two sections with one key: ${problems.join('; ')}`,
138
+ `${extension.file}, extending ${input.id}, leaves duplicate authored section IDs: ${problems.join('; ')}`,
138
139
  );
139
140
  }
140
141
  }
@@ -0,0 +1,33 @@
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
+ * @typedef {{file: string, reason: 'generated'|'vendored'|'ignored'|'dependency'|'vcs'|'symlink'|'outside-root', declaration: string, source?: string, line?: number, command?: string}} FileProtection
6
+ */
7
+ /**
8
+ * Create an eager, fail-closed resolver. Every declaration under root is parsed
9
+ * before the caller can begin writing consumer files.
10
+ * @param {string} root
11
+ * @param {{overrides?: Map<string, string|null>}} [options]
12
+ */
13
+ export function createFileProtectionResolver(root: string, { overrides }?: {
14
+ overrides?: Map<string, string | null>;
15
+ }): Readonly<{
16
+ root: string;
17
+ classify: (filePath: string) => FileProtection[];
18
+ }>;
19
+ /** A stable failure raised before any consumer write. */
20
+ export class ProtectionSourceError extends Error {
21
+ /** @param {string} source @param {string} reason */
22
+ constructor(source: string, reason: string);
23
+ code: string;
24
+ source: string;
25
+ }
26
+ export type FileProtection = {
27
+ file: string;
28
+ reason: "generated" | "vendored" | "ignored" | "dependency" | "vcs" | "symlink" | "outside-root";
29
+ declaration: string;
30
+ source?: string;
31
+ line?: number;
32
+ command?: string;
33
+ };