Skip to content

Commit 6932a9f

Browse files
docs: S2 migration docs and codemod setup (#6828)
* initialize migration docs * more docs for Item updates * move upgrade-cli to codemods package * improve rendered diffs * setup codemod entry * update yarn.lock * fix component index path resolving * update package.json * update yarn.lock * move to src * update component index path * update lock file * fix ts * update command in docs * fix --components option for providing a subset of components to upgrade * update docs to not collapse manual guide * update index to use parseArgs and pass args into codemod functions * just rely on require.resolve to get S2 index path * remove commander dep * move use-monopackages codemod into new package * update @react-spectrum/s2 dep * update yarn.lock * fix types and update use-monopackages readme * try removing main from package.json * use path module * use moduleResolution in tsconfig * remove module.exports * try renaming transformer functions * Revert "try renaming transformer functions" This reverts commit b2177f7. * try targets: main: false in package.json * move to packages/dev * update docs * add anchor links * update yarn.lock * fix anchor links in built docs --------- Co-authored-by: Robert Snow <[email protected]>
1 parent e2bf18a commit 6932a9f

File tree

145 files changed

+1128
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1128
-163
lines changed

.storybook-s2/docs/Migrating.jsx

Lines changed: 779 additions & 0 deletions
Large diffs are not rendered by default.

.storybook-s2/docs/Migrating.mdx

Lines changed: 4 additions & 0 deletions

.storybook-s2/docs/typography.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,56 @@
11
import { style } from '../../packages/@react-spectrum/s2/style/spectrum-theme' with {type: 'macro'};
22
import {Link} from '@react-spectrum/s2';
3+
import {useFocusRing, useHover} from 'react-aria';
4+
5+
function AnchorLink({id, isHovered}) {
6+
let { isFocusVisible, focusProps } = useFocusRing({within: true});
7+
const url = `${location.origin}${location.pathname.replace('iframe', 'index')}${location.search.replace('viewMode=docs&id=', 'path=/docs/')}#${id}`;
8+
return (
9+
<span {...focusProps} style={{opacity: isHovered || isFocusVisible ? 1 : 0}}>
10+
<Link href={url}>#</Link>
11+
</span>
12+
);
13+
}
314

415
export function H2({children}) {
516
let id = anchorId(children);
6-
return <h2 className={style({font: 'heading-xl', marginTop: 48, marginBottom: 24})} id={id}>{children}</h2>
17+
let {hoverProps, isHovered} = useHover({});
18+
return (
19+
<h2 className={style({font: 'heading-xl', marginTop: 48, marginBottom: 24, display: 'flex', alignItems: 'center', gap: 8})} id={id} {...hoverProps}>
20+
{children}
21+
<AnchorLink id={id} isHovered={isHovered} />
22+
</h2>
23+
)
724
}
825

926
export function H3({children}) {
1027
let id = anchorId(children);
11-
return <h3 className={style({font: 'heading', marginTop: 32, marginBottom: 16})} id={anchorId(children)}>{children}</h3>
28+
let {hoverProps, isHovered} = useHover({});
29+
return (
30+
<h3 className={style({font: 'heading', marginTop: 32, marginBottom: 16, display: 'flex', alignItems: 'center', gap: 8})} id={id} {...hoverProps}>
31+
{children}
32+
<AnchorLink id={id} isHovered={isHovered} />
33+
</h3>
34+
);
1235
}
1336

1437
export function H4({children}) {
1538
let id = anchorId(children);
16-
return <h4 className={style({font: 'heading-sm', marginTop: 32, marginBottom: 8})} id={anchorId(children)}>{children}</h4>
39+
let {hoverProps, isHovered} = useHover({});
40+
return (
41+
<h4 className={style({font: 'heading-sm', marginTop: 32, marginBottom: 8, display: 'flex', alignItems: 'center', gap: 8})} id={id} {...hoverProps}>
42+
{children}
43+
<AnchorLink id={id} isHovered={isHovered} />
44+
</h4>
45+
);
1746
}
1847

1948
export function P({children}) {
2049
return <p className={style({font: 'body-lg', marginTop: 0, marginBottom: 24})}>{children}</p>
2150
}
2251

2352
export function Code({children}) {
24-
return <code className={style({font: 'code-sm', backgroundColor: 'layer-1', paddingX: 4, borderWidth: 1, borderColor: 'gray-100', borderStyle: 'solid', borderRadius: 'sm'})}>{children}</code>;
53+
return <code className={style({font: 'code-sm', backgroundColor: 'layer-1', paddingX: 4, borderWidth: 1, borderColor: 'gray-100', borderStyle: 'solid', borderRadius: 'sm', whiteSpace: 'pre-wrap'})}>{children}</code>;
2554
}
2655

2756
export function Strong({children}) {

packages/@react-spectrum/upgrade-cli/package.json renamed to packages/dev/codemods/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
2-
"name": "@react-spectrum/upgrade-cli",
2+
"name": "@react-spectrum/codemods",
33
"version": "0.0.1",
44
"private": true,
5-
"source": "src/index.ts",
65
"main": "dist/index.js",
7-
"bin": {
8-
"upgrade-react-spectrum": "./dist/index.js"
6+
"source": "src/index.ts",
7+
"bin": "dist/index.js",
8+
"targets": {
9+
"main": false
910
},
1011
"scripts": {
11-
"start": "node --loader=ts-node/esm src/index.ts"
12+
"build": "tsc",
13+
"prepublishOnly": "yarn build"
1214
},
1315
"files": [
1416
"dist"
@@ -23,12 +25,12 @@
2325
"@babel/parser": "^7.24.5",
2426
"@babel/traverse": "^7.24.5",
2527
"@babel/types": "^7.24.5",
28+
"@react-spectrum/s2": "^0.2.0",
2629
"@react-types/shared": "^3.24.0",
2730
"@types/node": "^20",
2831
"boxen": "^5.1.2",
2932
"build": "^0.1.4",
3033
"chalk": "^4.0.0",
31-
"commander": "^12.0.0",
3234
"execa": "^5.1.1",
3335
"jscodeshift": "^0.15.2",
3436
"ts-node": "^10.9.2",

packages/dev/codemods/src/index.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
const {parseArgs} = require('node:util');
2+
import {s1_to_s2} from './s1-to-s2/src';
3+
import {use_monopackages} from './use-monopackages/src';
4+
5+
interface JSCodeshiftOptions {
6+
/**
7+
* The parser for jscodeshift to use for parsing the source files: https://github.com/facebook/jscodeshift?tab=readme-ov-file#parser.
8+
*
9+
* @default 'tsx'
10+
*/
11+
parser?: 'babel' | 'babylon' | 'flow' | 'ts' |' tsx',
12+
/**
13+
* A glob pattern of files to ignore: https://github.com/facebook/jscodeshift?tab=readme-ov-file#ignoring-files-and-directories.
14+
*
15+
* @default '*\*\/node_modules/*\*\'
16+
*/
17+
ignorePattern?: string,
18+
/**
19+
* Whether to run the codemod in dry mode, which will not write any changes to disk.
20+
*
21+
* @default false
22+
*/
23+
dry?: boolean,
24+
/**
25+
* The path to the directory to run the codemod in.
26+
*
27+
* @default '.'
28+
*/
29+
path?: string
30+
}
31+
32+
export interface S1ToS2CodemodOptions extends JSCodeshiftOptions {
33+
/**
34+
* An optional subset of components to have the s1-to-s2 codemod apply to.
35+
* Provide a comma-separated list of component names.
36+
*/
37+
components?: string
38+
}
39+
40+
export interface UseMonopackagesCodemodOptions extends JSCodeshiftOptions {
41+
/**
42+
* The packages to apply the use-monopackages codemod to.
43+
*/
44+
packages?: string
45+
}
46+
47+
const codemods: Record<string, (options: S1ToS2CodemodOptions | UseMonopackagesCodemodOptions) => void> = {
48+
's1-to-s2': s1_to_s2,
49+
'use-monopackages': use_monopackages
50+
};
51+
52+
// https://github.com/facebook/jscodeshift?tab=readme-ov-file#usage-cli
53+
const options = {
54+
'parser': {
55+
type: 'string'
56+
},
57+
'ignore-pattern': {
58+
type: 'string'
59+
},
60+
'dry': {
61+
type: 'boolean',
62+
short: 'd'
63+
},
64+
'path': {
65+
type: 'string'
66+
},
67+
'components': {
68+
type: 'string'
69+
}
70+
};
71+
72+
const {values, positionals} = parseArgs({
73+
options,
74+
allowPositionals: true
75+
});
76+
77+
if (positionals.length < 1) {
78+
console.error('Please specify a codemod to run. Available codemods: ', Object.keys(codemods).join(', '));
79+
process.exit(1);
80+
}
81+
82+
const codemodName = positionals[0];
83+
const codemodFunction = codemods[codemodName];
84+
85+
if (!codemodFunction) {
86+
console.error(`Unknown codemod: ${codemodName}, available codemods: ${Object.keys(codemods).join(', ')}`);
87+
process.exit(1);
88+
}
89+
90+
try {
91+
codemodFunction({
92+
parser: 'tsx',
93+
ignorePattern: '**/node_modules/**',
94+
path: '.',
95+
...values
96+
});
97+
} catch (error) {
98+
console.error(`Error running codemod: ${error}`);
99+
process.exit(1);
100+
}

packages/@react-spectrum/upgrade-cli/README.md renamed to packages/dev/codemods/src/s1-to-s2/README.md

Lines changed: 1 addition & 1 deletion

packages/@react-spectrum/upgrade-cli/UPGRADE.md renamed to packages/dev/codemods/src/s1-to-s2/UPGRADE.md

Lines changed: 1 addition & 2 deletions

0 commit comments

Comments
 (0)