@astryxdesign/cli 0.6.3-canary.7210f0d → 0.6.3-canary.7ada42e

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 (40) hide show
  1. package/README.md +2 -0
  2. package/api/upgrade/_adapter.d.mts +22 -4
  3. package/api/upgrade/_adapter.mjs +19 -6
  4. package/api/upgrade/run/run.mjs +355 -59
  5. package/api/upgrade/upgrade.doc.mjs +5 -1
  6. package/api/upgrade/upgrade.type.d.mts +34 -0
  7. package/api/upgrade/upgrade.type.mjs +15 -0
  8. package/assets/codemods/__tests__/runner.test.mjs +330 -8
  9. package/assets/codemods/integration-runner.mjs +56 -4
  10. package/assets/codemods/integration-runner.protection.test.mjs +153 -0
  11. package/assets/codemods/run-codemod.mjs +177 -34
  12. package/assets/codemods/runner.mjs +248 -110
  13. package/assets/codemods/transforms/next/__tests__/migrate-native-picker-to-presentation.test.mjs +63 -0
  14. package/assets/codemods/transforms/next/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +4 -0
  15. package/assets/codemods/transforms/next/index.mjs +8 -0
  16. package/assets/codemods/transforms/next/migrate-native-picker-to-presentation.mjs +148 -0
  17. package/assets/docs/cli-integrations.doc.mjs +13 -0
  18. package/assets/templates/blocks/components/DateInput/DateInputDateRange.tsx +1 -1
  19. package/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs +14 -0
  20. package/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx +100 -0
  21. package/assets/templates/blocks/components/TimeInput/TimeInputConstrained.tsx +1 -0
  22. package/authoring/codemod/type.ts +12 -0
  23. package/clients/cli/commands/build-theme.mjs +10 -44
  24. package/clients/cli/commands/docs.mjs +1 -1
  25. package/clients/cli/commands/text-json-parity.test.mjs +719 -0
  26. package/clients/cli/commands/theme-targets.behavior.test.mjs +4 -3
  27. package/clients/cli/commands/upgrade.doc.mjs +2 -1
  28. package/clients/cli/commands/upgrade.file-protection.test.mjs +228 -0
  29. package/clients/cli/commands/upgrade.mjs +29 -7
  30. package/clients/cli/formatters/index.mjs +2 -0
  31. package/clients/cli/formatters/index.test.mjs +6 -0
  32. package/foundation/fs/file-protection.d.mts +33 -0
  33. package/foundation/fs/file-protection.mjs +825 -0
  34. package/foundation/fs/file-protection.test.mjs +250 -0
  35. package/foundation/response/error-codes.d.mts +3 -1
  36. package/foundation/response/error-codes.d.ts +2 -0
  37. package/foundation/response/error-codes.doc.mjs +10 -0
  38. package/foundation/response/error-codes.mjs +6 -0
  39. package/foundation/response/error-codes.test.mjs +55 -11
  40. package/package.json +10 -9
@@ -0,0 +1,148 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Codemod: migrate nativePicker to presentation on date/time inputs
5
+ *
6
+ * `spec:AST-043` FR3 mapping, applied only to static literals written
7
+ * directly on imported `DateInput`, `DateTimeInput`, and `TimeInput`
8
+ * elements: the prop is renamed to `presentation` and its value mapped.
9
+ * When the element already sets `presentation`, the deprecated prop is
10
+ * removed (presentation wins, FR4). Dynamic values are left unchanged —
11
+ * the deprecated prop keeps working, so an unmigrated callsite is still
12
+ * correct, and guessing at an expression's values would not be.
13
+ */
14
+
15
+ import {transformProp} from '../../transform-prop.mjs';
16
+
17
+ export const meta = {
18
+ title: 'Migrate nativePicker to presentation',
19
+ description:
20
+ 'Renames `nativePicker` to `presentation` on DateInput, DateTimeInput, ' +
21
+ 'and TimeInput, mapping touch→adaptive-native, always→native, and ' +
22
+ 'never→adaptive-bottom-sheet (text-input for TimeInput). Dynamic ' +
23
+ 'values are left for manual migration; the deprecated prop still works.',
24
+ };
25
+
26
+ const CORE_IMPORT_RE = /^@(astryxdesign|xds)\/core(?:\/|$)/;
27
+
28
+ const COMPONENT_PROPS = new Map([
29
+ ['DateInput', new Set(['nativePicker'])],
30
+ ['DateTimeInput', new Set(['nativePicker'])],
31
+ ['TimeInput', new Set(['nativePicker'])],
32
+ ]);
33
+
34
+ /** @param {string} component @param {string} value */
35
+ function mapValue(component, value) {
36
+ switch (value) {
37
+ case 'touch':
38
+ return 'adaptive-native';
39
+ case 'always':
40
+ return 'native';
41
+ case 'never':
42
+ return component === 'TimeInput' ? 'text-input' : 'adaptive-bottom-sheet';
43
+ default:
44
+ return undefined;
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Collect the string-literal leaves of a value expression without mutating
50
+ * anything. Returns false for any dynamic or non-string node.
51
+ * @param {any} node
52
+ * @param {any[]} leaves
53
+ * @returns {boolean}
54
+ */
55
+ function collectStaticLeaves(node, leaves) {
56
+ if (!node) return false;
57
+ if (
58
+ node.type === 'TSAsExpression' ||
59
+ node.type === 'TSSatisfiesExpression' ||
60
+ node.type === 'TypeCastExpression' ||
61
+ node.type === 'ParenthesizedExpression'
62
+ ) {
63
+ return collectStaticLeaves(node.expression, leaves);
64
+ }
65
+ if (node.type === 'ConditionalExpression') {
66
+ return (
67
+ collectStaticLeaves(node.consequent, leaves) &&
68
+ collectStaticLeaves(node.alternate, leaves)
69
+ );
70
+ }
71
+ if (
72
+ (node.type !== 'StringLiteral' && node.type !== 'Literal') ||
73
+ typeof node.value !== 'string'
74
+ ) {
75
+ return false;
76
+ }
77
+ leaves.push(node);
78
+ return true;
79
+ }
80
+
81
+ /**
82
+ * Map every leaf, or none of them: a mixed static/dynamic conditional must
83
+ * stay byte-identical, never half-migrated.
84
+ * @param {any} node
85
+ * @param {string} component
86
+ */
87
+ function mapStaticValue(node, component) {
88
+ /** @type {any[]} */
89
+ const leaves = [];
90
+ if (!collectStaticLeaves(node, leaves)) return false;
91
+ if (leaves.some(leaf => mapValue(component, leaf.value) === undefined)) {
92
+ return false;
93
+ }
94
+ for (const leaf of leaves) {
95
+ leaf.value = mapValue(component, leaf.value);
96
+ if (leaf.raw) leaf.raw = undefined;
97
+ }
98
+ return true;
99
+ }
100
+
101
+ /**
102
+ * @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
103
+ * @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
104
+ * @returns {string | null | undefined}
105
+ */
106
+ export default function transformer(file, api) {
107
+ if (!file.source.includes('nativePicker')) return undefined;
108
+ const j = api.jscodeshift;
109
+ const root = j(file.source);
110
+ let hasChanges = false;
111
+
112
+ transformProp(
113
+ root,
114
+ j,
115
+ {
116
+ matchesImport: source => CORE_IMPORT_RE.test(source),
117
+ components: COMPONENT_PROPS,
118
+ },
119
+ (propPath, {component}) => {
120
+ const opening = propPath.parent?.node;
121
+ const attributes = opening?.attributes ?? [];
122
+ const hasPresentation = attributes.some(
123
+ (/** @type {any} */ attribute) =>
124
+ attribute.type === 'JSXAttribute' &&
125
+ attribute.name?.name === 'presentation',
126
+ );
127
+ const prop = propPath.node;
128
+ if (hasPresentation) {
129
+ // FR4: presentation wins; drop the deprecated prop.
130
+ opening.attributes = attributes.filter(
131
+ (/** @type {any} */ attribute) => attribute !== prop,
132
+ );
133
+ hasChanges = true;
134
+ return;
135
+ }
136
+ const value =
137
+ prop.value?.type === 'JSXExpressionContainer'
138
+ ? prop.value.expression
139
+ : prop.value;
140
+ if (!mapStaticValue(value, component)) return;
141
+ prop.name.name = 'presentation';
142
+ hasChanges = true;
143
+ },
144
+ );
145
+
146
+ if (!hasChanges) return undefined;
147
+ return root.toSource({quote: 'single'});
148
+ }
@@ -330,6 +330,19 @@ export const docs = {
330
330
  lang: 'bash',
331
331
  code: '# Preview what would change (dry-run, the default)\nastryx upgrade --from 0.1.0\n\n# Apply the migration\nastryx upgrade --from 0.1.0 --apply',
332
332
  },
333
+ {
334
+ type: 'prose',
335
+ text: 'Core and integration upgrade codemods do not edit existing consumer files that the working tree protects. Protection is VCS-neutral: Astryx reads nested `.gitattributes` rules for `linguist-generated` and `linguist-vendored`, leading `@generated` and `@partially-generated` comments, standard `Code generated … DO NOT EDIT.` comments, `.gitignore`, and `.hgignore` directly from disk. Later attribute rules, explicit false or unset values, and ignore negation keep their normal semantics. Installed dependencies, VCS metadata, paths outside the project, and symbolic links are also protected. Directory or file names such as `dist` and `generated` are not evidence by themselves.',
336
+ },
337
+ {
338
+ type: 'prose',
339
+ text: 'A protected file is transformed only in memory. If it would change, the upgrade applies eligible owned-source edits, runs `hooks.postCodemod` regeneration, and checks the protected file again. A remaining change makes the run incomplete and exits nonzero with `ERR_CODEMOD_PROTECTED`; JSON output lists `modifiedFiles` and `protectedFiles` with every effective declaration. Generated headers may include `Command: <exact command>` so the result can tell a consumer how to regenerate when no hook resolves the output. Dry-run uses the same classification without writing.',
340
+ },
341
+ {
342
+ type: 'code',
343
+ lang: 'text',
344
+ code: '# .gitattributes\ngenerated/** linguist-generated=true\nvendor/** linguist-vendored=true\n\n# A later rule can explicitly return an authored file to normal handling\ngenerated/hand-authored.ts linguist-generated=false',
345
+ },
333
346
  {
334
347
  type: 'prose',
335
348
  text: 'All authoring types are exported from `@astryxdesign/cli/authoring`: `ComponentDoc`, `HookDoc`, and `ReferenceDoc` for docs, `TemplateDoc` for templates, and `AstryxConfig`, `AstryxIntegration`, and `AstryxCodemod` for the project files. Consumers can also run their own post-codemod hooks, such as a reinstall or rebuild, via `hooks.postCodemod` in their `astryx.config`.',
@@ -41,7 +41,7 @@ export default function DateInputDateRange() {
41
41
  max={max}
42
42
  description={description}
43
43
  placeholder="Select a booking date"
44
- nativePicker="never"
44
+ presentation="adaptive-bottom-sheet"
45
45
  value={value}
46
46
  onChange={setValue}
47
47
  />
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'Item',
7
+ name: 'Item — Document Tabs',
8
+ displayName: 'Item — Document Tabs',
9
+ description:
10
+ 'Single-row, horizontally scrollable document switcher with compact selected rows, leading file icons, instant reveal-on-hover close actions with reserved geometry, stable separators, and an add control outside the scroll area. Use for editor tabs, workspace tabs, open documents, files, canvases, or panels.',
11
+ isReady: true,
12
+ aspectRatio: 16 / 4,
13
+ componentsUsed: ['Item', 'Divider', 'Icon', 'IconButton', 'Layout'],
14
+ };
@@ -0,0 +1,100 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {Fragment} from 'react';
6
+ import * as stylex from '@stylexjs/stylex';
7
+
8
+ import {Divider} from '@astryxdesign/core/Divider';
9
+ import {useContainerReveal} from '@astryxdesign/core/hooks';
10
+ import {Icon} from '@astryxdesign/core/Icon';
11
+ import {IconButton} from '@astryxdesign/core/IconButton';
12
+ import {Item} from '@astryxdesign/core/Item';
13
+ import {HStack} from '@astryxdesign/core/Layout';
14
+ import {mergeProps} from '@astryxdesign/core/utils';
15
+ import {DocumentIcon, PlusIcon, XMarkIcon} from '@heroicons/react/24/outline';
16
+
17
+ const TABS = [
18
+ {name: 'Project brief', isActive: true},
19
+ {name: 'Research notes', isActive: false},
20
+ {name: 'Interaction prototype', isActive: false},
21
+ ];
22
+
23
+ const styles = stylex.create({
24
+ strip: {minWidth: 0, flexShrink: 1, scrollbarWidth: 'none'},
25
+ rule: {height: 16},
26
+ hidden: {visibility: 'hidden'},
27
+ tab: {flexShrink: 1, width: 164, minWidth: 96},
28
+ action: {margin: 'calc(-1 * var(--spacing-1))', transitionProperty: 'none'},
29
+ });
30
+ function DocumentTab({name, isActive}: (typeof TABS)[number]) {
31
+ const {getContainerProps, getContentRevealProps} = useContainerReveal();
32
+ const revealProps = getContentRevealProps({
33
+ forceVisibility: isActive ? 'shown' : undefined,
34
+ isLayoutPreserved: true,
35
+ });
36
+ return (
37
+ <Item
38
+ label={name}
39
+ density="compact"
40
+ isSelected={isActive}
41
+ onClick={() => {}}
42
+ aria-current={isActive ? 'true' : undefined}
43
+ {...getContainerProps()}
44
+ startContent={
45
+ <Icon
46
+ icon={DocumentIcon}
47
+ size="sm"
48
+ color={isActive ? 'primary' : 'secondary'}
49
+ />
50
+ }
51
+ endContent={
52
+ <IconButton
53
+ label={`Close ${name}`}
54
+ variant="ghost"
55
+ size="sm"
56
+ icon={<Icon icon={XMarkIcon} size="sm" />}
57
+ {...mergeProps(revealProps, stylex.props(styles.action))}
58
+ />
59
+ }
60
+ xstyle={styles.tab}
61
+ />
62
+ );
63
+ }
64
+
65
+ export default function ItemDocumentTabs() {
66
+ return (
67
+ <HStack width="100%" maxWidth={600} gap={0.5} vAlign="center">
68
+ <HStack
69
+ role="group"
70
+ aria-label="Open documents"
71
+ vAlign="center"
72
+ paddingInline={2}
73
+ paddingBlock={1}
74
+ isScrollable
75
+ xstyle={styles.strip}>
76
+ {TABS.map((tab, index) => (
77
+ <Fragment key={tab.name}>
78
+ {index > 0 ? (
79
+ <Divider
80
+ orientation="vertical"
81
+ xstyle={[
82
+ styles.rule,
83
+ (TABS[index - 1]?.isActive || tab.isActive) && styles.hidden,
84
+ ]}
85
+ />
86
+ ) : null}
87
+ <DocumentTab {...tab} />
88
+ </Fragment>
89
+ ))}
90
+ </HStack>
91
+ <IconButton
92
+ label="New document"
93
+ tooltip="New document"
94
+ variant="ghost"
95
+ size="sm"
96
+ icon={<Icon icon={PlusIcon} size="sm" color="secondary" />}
97
+ />
98
+ </HStack>
99
+ );
100
+ }
@@ -17,6 +17,7 @@ export default function TimeInputConstrained() {
17
17
  max={'22:00' as never}
18
18
  description="Evening seating: 5 PM – 10 PM"
19
19
  placeholder="Select reservation time"
20
+ presentation="adaptive-bottom-sheet"
20
21
  value={evening as never}
21
22
  onChange={setEvening as never}
22
23
  hasClear
@@ -128,7 +128,19 @@ export interface CodemodEntry {
128
128
  /** The result of running a single codemod over one or more files. */
129
129
  export interface CodemodRunResult {
130
130
  filesChanged: number;
131
+ /** Existing owned files changed or previewed by this codemod. */
132
+ changedFiles: string[];
133
+ /** Files actually written; empty during a dry run. */
131
134
  writtenFiles: string[];
135
+ /** Existing files that require the change but are protected. */
136
+ protectedFiles: Array<{
137
+ file: string;
138
+ codemod: string;
139
+ reason: string;
140
+ declaration: string;
141
+ generated: boolean;
142
+ command?: string;
143
+ }>;
132
144
  errors: Array<{file: string; codemod: string; error: string}>;
133
145
  }
134
146
 
@@ -33,7 +33,7 @@ import {fileURLToPath} from 'node:url';
33
33
  import {spawn} from 'node:child_process';
34
34
  import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
35
35
  import {jsonOut} from '../../../foundation/response/json.mjs';
36
- import {emit, section, text, list, code} from '../formatters/index.mjs';
36
+ import {emit, section, text, list, records, code} from '../formatters/index.mjs';
37
37
  import {logger} from '../../../api/logger.mjs';
38
38
  import {cliError} from '../lib/cli-error.mjs';
39
39
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
@@ -229,47 +229,6 @@ function printThemeList(themes) {
229
229
  );
230
230
  }
231
231
 
232
- /**
233
- * Render the targets as one greppable line each, under an aligned header. A
234
- * `records()` block would be five lines per target — over a thousand for the
235
- * full surface, which is the view this command exists to make readable.
236
- * @param {import('../../../api/theme/theme.type.mjs').ThemeTargetEntry[]} targets
237
- * @returns {string}
238
- */
239
- function formatTargetsTable(targets) {
240
- const rows = targets.map(t => ({
241
- key: t.deprecatedFor
242
- ? `${t.key} [deprecated; use ${t.deprecatedFor}]`
243
- : t.key,
244
- component: t.component,
245
- props: t.props.join(', ') || '-',
246
- states: t.states.join(', ') || '-',
247
- }));
248
- const head = {
249
- key: 'key',
250
- component: 'component',
251
- props: 'props',
252
- states: 'states',
253
- };
254
- const width = (/** @type {'key'|'component'|'props'} */ field) =>
255
- [head, ...rows].reduce((max, r) => Math.max(max, r[field].length), 0);
256
- const w = {
257
- key: width('key'),
258
- component: width('component'),
259
- props: width('props'),
260
- };
261
- const line = (/** @type {typeof head} */ r) =>
262
- [
263
- r.key.padEnd(w.key),
264
- r.component.padEnd(w.component),
265
- r.props.padEnd(w.props),
266
- r.states,
267
- ]
268
- .join(' ')
269
- .trimEnd();
270
- return [line(head), ...rows.map(line)].join('\n');
271
- }
272
-
273
232
  /**
274
233
  * @param {import('commander').Command} program
275
234
  */
@@ -811,9 +770,16 @@ export function registerTheme(program) {
811
770
  emit(
812
771
  section(
813
772
  'Theming targets',
814
- `${targets.length} across ${componentCount} component${componentCount === 1 ? '' : 's'}`,
773
+ `${targets.length} across ${componentCount} component${componentCount === 1 ? '' : 's'}\n(key - component - props - states - className - deprecatedFor)`,
815
774
  ),
816
- text(formatTargetsTable(targets)),
775
+ records(targets, {
776
+ fields: ['key', 'component', 'props', 'states', 'className', 'deprecatedFor'],
777
+ layout: 'inline',
778
+ format: {
779
+ deprecatedFor: (/** @type {string|null} */ v) =>
780
+ v ? `deprecated; use ${v}` : '',
781
+ },
782
+ }),
817
783
  text(
818
784
  [
819
785
  `Each key goes under \`components\` in defineTheme; it paints \`.astryx-<key>\`.`,
@@ -280,7 +280,7 @@ export function registerDocs(program) {
280
280
  emit(
281
281
  section('Available docs'),
282
282
  records(result.data, {
283
- fields: ['topic', 'description'],
283
+ fields: ['topic', 'description', 'package'],
284
284
  layout: 'inline',
285
285
  }),
286
286
  text(