Skip to content

Commit d124724

Browse files
committed
Merge branch 'main' into aggregate-ts-upgrade-updates
# Conflicts: # package.json # yarn.lock
2 parents c22796b + 2fd87d9 commit d124724

File tree

557 files changed

+4438
-2053
lines changed

Some content is hidden

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

557 files changed

+4438
-2053
lines changed

.circleci/comment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async function run() {
7676
body: `Build successful! 🎉
7777
7878
* [View the storybook](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/storybook/index.html)
79-
* [View the storybook-canary](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/storybook-canary/index.html)
79+
* [View the storybook-19](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/storybook-19/index.html)
8080
* [View the storybook-17](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/storybook-17/index.html)
8181
* [View the storybook-16](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/storybook-16/index.html)
8282
* [View the documentation](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/docs/index.html)`

.circleci/config.yml

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,30 @@ orbs:
1919
executors:
2020
rsp:
2121
docker:
22-
- image: cimg/node:18.17.1
22+
- image: cimg/node:18.20.3
2323
environment:
2424
CACHE_VERSION: v1
2525
working_directory: ~/react-spectrum
2626

2727
rsp-large:
2828
docker:
29-
- image: cimg/node:18.17.1
29+
- image: cimg/node:18.20.3
3030
resource_class: large
3131
environment:
3232
CACHE_VERSION: v1
3333
working_directory: ~/react-spectrum
3434

3535
rsp-xlarge:
3636
docker:
37-
- image: cimg/node:18.17.1
37+
- image: cimg/node:18.20.3
3838
resource_class: xlarge
3939
environment:
4040
CACHE_VERSION: v1
4141
working_directory: ~/react-spectrum
4242

4343
rsp-xlarge-nodeupdate:
4444
docker:
45-
- image: cimg/node:18.17.1
45+
- image: cimg/node:18.20.3
4646
resource_class: xlarge
4747
environment:
4848
CACHE_VERSION: v1
@@ -121,7 +121,7 @@ jobs:
121121
- ~/react-spectrum
122122
key: react-spectrum17-{{ .Environment.CACHE_VERSION }}-{{ .Environment.CIRCLE_SHA1 }}
123123

124-
install-canary:
124+
install-19:
125125
executor: rsp-large
126126
steps:
127127
- checkout
@@ -134,12 +134,12 @@ jobs:
134134
- run:
135135
name: build
136136
command: |
137-
yarn install --pure-lockfile --cache-folder ~/.cache/yarn && yarn install-canary --cache-folder ~/.cache/yarn
137+
yarn install --pure-lockfile --cache-folder ~/.cache/yarn && yarn install-19 --cache-folder ~/.cache/yarn
138138
139139
- save_cache:
140140
paths:
141141
- ~/react-spectrum
142-
key: react-spectrum-canary-{{ .Environment.CACHE_VERSION }}-{{ .Environment.CIRCLE_SHA1 }}
142+
key: react-spectrum-19-{{ .Environment.CACHE_VERSION }}-{{ .Environment.CIRCLE_SHA1 }}
143143

144144
test-ssr:
145145
executor: rsp-xlarge
@@ -199,11 +199,11 @@ jobs:
199199
command: |
200200
yarn test:ssr
201201
202-
test-ssr-canary:
202+
test-ssr-19:
203203
executor: rsp-xlarge
204204
steps:
205205
- restore_cache:
206-
key: react-spectrum-canary-{{ .Environment.CACHE_VERSION }}-{{ .Environment.CIRCLE_SHA1 }}
206+
key: react-spectrum-19-{{ .Environment.CACHE_VERSION }}-{{ .Environment.CIRCLE_SHA1 }}
207207

208208
- run:
209209
name: test ssr
@@ -258,12 +258,12 @@ jobs:
258258
- store_artifacts:
259259
path: ~/junit
260260

261-
test-canary:
261+
test-19:
262262
parallelism: 3
263263
executor: rsp-xlarge
264264
steps:
265265
- restore_cache:
266-
key: react-spectrum-canary-{{ .Environment.CACHE_VERSION }}-{{ .Environment.CIRCLE_SHA1 }}
266+
key: react-spectrum-19-{{ .Environment.CACHE_VERSION }}-{{ .Environment.CIRCLE_SHA1 }}
267267

268268
- run: mkdir ~/junit
269269

@@ -272,10 +272,10 @@ jobs:
272272
command: |
273273
shopt -s globstar
274274
TESTFILES=$(circleci tests glob "packages/**/*.test.[tj]{s,sx}" | circleci tests split --split-by=timings)
275-
JEST_JUNIT_OUTPUT_NAME="junit-canary.xml" yarn test ${TESTFILES}
275+
JEST_JUNIT_OUTPUT_NAME="junit-19.xml" yarn test ${TESTFILES}
276276
277277
- run:
278-
command: cp junit-canary.xml ~/junit/
278+
command: cp junit-19.xml ~/junit/
279279
when: always
280280
- store_test_results:
281281
path: ~/junit
@@ -412,20 +412,20 @@ jobs:
412412
paths:
413413
- '*/storybook-17/'
414414

415-
storybook-canary:
415+
storybook-19:
416416
executor: rsp-large
417417
steps:
418418
- restore_cache:
419-
key: react-spectrum-canary-{{ .Environment.CACHE_VERSION }}-{{ .Environment.CIRCLE_SHA1 }}
419+
key: react-spectrum-19-{{ .Environment.CACHE_VERSION }}-{{ .Environment.CIRCLE_SHA1 }}
420420

421421
- run:
422-
name: build storybook-canary
423-
command: make storybook-canary
422+
name: build storybook-19
423+
command: make storybook-19
424424

425425
- persist_to_workspace:
426426
root: dist
427427
paths:
428-
- '*/storybook-canary/'
428+
- '*/storybook-19/'
429429

430430
docs:
431431
executor: rsp-xlarge
@@ -547,7 +547,7 @@ workflows:
547547
- install
548548
- install-16
549549
- install-17
550-
- install-canary
550+
- install-19
551551
- test-ssr:
552552
requires:
553553
- install
@@ -566,6 +566,12 @@ workflows:
566566
- test-17:
567567
requires:
568568
- install-17
569+
- test-19:
570+
requires:
571+
- install-19
572+
- test-ssr-19:
573+
requires:
574+
- install-19
569575
- test-esm:
570576
requires:
571577
- install
@@ -603,9 +609,9 @@ workflows:
603609
- storybook-17:
604610
requires:
605611
- install-17
606-
- storybook-canary:
612+
- storybook-19:
607613
requires:
608-
- install-canary
614+
- install-19
609615
- docs:
610616
requires:
611617
- install
@@ -628,7 +634,7 @@ workflows:
628634
- storybook
629635
- storybook-16
630636
- storybook-17
631-
- storybook-canary
637+
- storybook-19
632638
- docs
633639
- deploy-verdaccio:
634640
requires:

.github/actions/branch/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Branch from fork'
22
description: 'creates a branch based off PR from fork'
33
runs:
4-
using: 'node16'
4+
using: 'node18'
55
main: 'index.js'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Check permissions'
22
description: 'Checks if commentor has write access or above'
33
runs:
4-
using: 'node16'
4+
using: 'node18'
55
main: 'index.js'

.github/workflows/pr-comment.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@main
15-
- name: Use Node 16
16-
uses: actions/setup-node@v2
15+
- name: Use Node 18
16+
uses: actions/setup-node@v3
1717
with:
18-
node-version: '16'
18+
node-version: '18'
1919
- name: install
2020
run: yarn install
2121
- name: Check write permissions of commentor

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ storybook-16:
8181
storybook-17:
8282
yarn build:storybook-17
8383

84-
storybook-canary:
85-
yarn build:storybook-canary
84+
storybook-19:
85+
yarn build:storybook-19
8686

8787
# for now doesn't have deploy since v3 doesn't have a place for docs and stuff yet
8888
ci:
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
function areSpecifiersAlphabetized(specifiers) {
5+
const specifierNames = specifiers.map(
6+
(specifier) => specifier.imported.name
7+
);
8+
const sortedNames = [...specifierNames].sort();
9+
return specifierNames.join() === sortedNames.join();
10+
}
11+
12+
/**
13+
* Replaces individual package imports with monopackage imports, where possible.
14+
*
15+
* Works for:
16+
* - `@react-spectrum/*` -> `@adobe/react-spectrum`.
17+
* - `@react-aria/*` -> `react-aria`.
18+
* - `@react-stately/*` -> `react-stately`.
19+
*
20+
* By default this will apply to all the above packages, or optionally you can specify which packages to apply this by passing a comma-separated list to the packages option: `--packages=react-aria,react-stately,react-spectrum`.
21+
*
22+
* Run this from a directory where the relevant packages are installed in node_modules so it knows which monopackage exports are available to use (since exports may vary by version).
23+
*
24+
* 1. Install jscodeshift: `npm i -g jscodeshift`
25+
* 2. Run: `jscodeshift -t /path/to/use-monopackages.ts src/`.
26+
*/
27+
module.exports = function transformer(file, api, options) {
28+
const j = api.jscodeshift;
29+
const root = j(file.source);
30+
31+
const packages = {
32+
'react-spectrum': {
33+
monopackage: '@adobe/react-spectrum',
34+
individualPrefix: '@react-spectrum/'
35+
},
36+
'react-aria': {
37+
monopackage: 'react-aria',
38+
individualPrefix: '@react-aria/'
39+
},
40+
'react-stately': {
41+
monopackage: 'react-stately',
42+
individualPrefix: '@react-stately/'
43+
}
44+
};
45+
46+
const selectedPackages =
47+
options?.packages?.split(',').filter((pkg) => packages[pkg]) ||
48+
Object.keys(packages);
49+
50+
let anyIndexFound = false;
51+
const monopackageExports = {};
52+
53+
selectedPackages.forEach((pkg) => {
54+
const indexPath = path.join(
55+
process.cwd(),
56+
`node_modules/${packages[pkg].monopackage}/dist/types.d.ts`
57+
);
58+
59+
if (fs.existsSync(indexPath)) {
60+
anyIndexFound = true;
61+
const indexFile = fs.readFileSync(indexPath, 'utf8');
62+
const indexRoot = j(indexFile);
63+
64+
monopackageExports[pkg] = [];
65+
// Collect all named exports from the monopackage index file
66+
indexRoot.find(j.ExportNamedDeclaration).forEach((path) => {
67+
path.node.specifiers.forEach((specifier) => {
68+
monopackageExports[pkg].push(specifier.exported.name);
69+
});
70+
});
71+
72+
// Collect all exports defined in export statements like "export { Component } from '...' "
73+
indexRoot
74+
.find(j.ExportNamedDeclaration, {
75+
source: {
76+
type: 'Literal'
77+
}
78+
})
79+
.forEach((path) => {
80+
path.node.specifiers.forEach((specifier) => {
81+
monopackageExports[pkg].push(specifier.exported.name);
82+
});
83+
});
84+
} else if (options?.packages?.split(',').includes(pkg)) {
85+
console.warn(
86+
`The index file for ${packages[pkg].monopackage} at ${indexPath} does not exist. Ensure that ${packages[pkg].monopackage} is installed.`
87+
);
88+
}
89+
});
90+
91+
if (!anyIndexFound) {
92+
console.warn(
93+
'None of the index files for the selected packages exist. Ensure that the packages are installed.'
94+
);
95+
return root.toSource();
96+
}
97+
98+
selectedPackages.forEach((pkg) => {
99+
// Find all imports from individual packages
100+
const individualPackageImports = root
101+
.find(j.ImportDeclaration)
102+
.filter((path) => {
103+
return path.node.source.value.startsWith(
104+
packages[pkg].individualPrefix
105+
);
106+
});
107+
108+
if (individualPackageImports.size() === 0) {
109+
return;
110+
}
111+
112+
// Collect all imported specifiers from individual packages that are also in the monopackage exports
113+
const importedSpecifiers = individualPackageImports
114+
.nodes()
115+
.reduce((acc, node) => {
116+
node.specifiers.forEach((specifier) => {
117+
if (monopackageExports[pkg].includes(specifier.imported.name)) {
118+
acc.push(specifier);
119+
}
120+
});
121+
return acc;
122+
}, []);
123+
124+
// Remove the old imports if they are present in monopackage exports
125+
individualPackageImports.forEach((path) => {
126+
path.node.specifiers = path.node.specifiers.filter(
127+
(specifier) =>
128+
!monopackageExports[pkg].includes(specifier.imported.name)
129+
);
130+
});
131+
132+
// Remove import declarations with no specifiers left
133+
individualPackageImports
134+
.filter((path) => path.node.specifiers.length === 0)
135+
.remove();
136+
137+
// Find existing monopackage import if it exists
138+
const monopackageImport = root.find(j.ImportDeclaration).filter((path) => {
139+
return path.node.source.value === packages[pkg].monopackage;
140+
});
141+
142+
if (monopackageImport.size() > 0) {
143+
const existingImport = monopackageImport.at(0).get().node;
144+
const specifiers = existingImport.specifiers;
145+
if (areSpecifiersAlphabetized(specifiers)) {
146+
// If imports are sorted, add the new import in sorted order
147+
importedSpecifiers.forEach((newSpecifier) => {
148+
const index = specifiers.findIndex(
149+
(specifier) => specifier.imported.name > newSpecifier.imported.name
150+
);
151+
if (index === -1) {
152+
specifiers.push(newSpecifier);
153+
} else {
154+
specifiers.splice(index, 0, newSpecifier);
155+
}
156+
});
157+
} else {
158+
// If imports are not sorted, add the new import to the end
159+
specifiers.push(...importedSpecifiers);
160+
}
161+
} else if (importedSpecifiers.length > 0) {
162+
// Create a new monopackage import with the collected specifiers
163+
const newImport = j.importDeclaration(
164+
importedSpecifiers,
165+
j.literal(packages[pkg].monopackage)
166+
);
167+
168+
// Insert the new import below the last existing import
169+
const lastImport = root.find(j.ImportDeclaration).at(-1);
170+
if (lastImport.size() > 0) {
171+
lastImport.insertAfter(newImport);
172+
} else {
173+
root.get().node.program.body.unshift(newImport);
174+
}
175+
}
176+
});
177+
178+
return root.toSource();
179+
};
180+
181+
module.exports.parser = 'tsx';

0 commit comments

Comments
 (0)