Skip to content

Commit 2698ad4

Browse files
authored
Move shared components to a packages/ directory (#30962)
* Move shared components to a packages/ directory so they can be publish more sensibly * Iterate towards split out shared-components module * Move shared component source into src/ subdir * Fix up imports * Include shared components in babel-ing (again) * Remove now unused dependencies * Update import in storybook preview * ...except of course they aren't unused if we import the shared components by source * Ignore shared components deps * Add shared-components to i18n paths and upgrade web-i18n to version that supports doing so * Move storybook stuff to shared-components * Seems we don't need this anymore... * Remove unused deps and remove storybook plugin from eslint * Presumably working-directory is only valid on run steps * Ignore dep & run prettier * Prettier on knips.ts * Hopefully run in right dir * Remember how to software write * Okay... how about THIS way? * Oh right, they were git ignored. Sigh. * Add concurrently * Ignore in knip * Better? * Paaaaaaaackageeeeeeees * More packages * Move playwright snapshots * Still need a custom snapshots dir * Add eslint back * Oh, now knip sees them * Fix another import * Don't lint shared-components with everything else Okay, eslint & tsconfig are tied too closely for this to work and running tsc on the shared components will need its deps installing * Maybe lint shared components please? * Not quite * Remove storybook again Re-check if it does work without it * Remove storybook eslint plugin as we're not linting storybook here anymore * Remove this too * We do need it here though
1 parent c96da5d commit 2698ad4

File tree

177 files changed

+6182
-2565
lines changed

Some content is hidden

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

177 files changed

+6182
-2565
lines changed

.eslintrc.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
module.exports = {
22
plugins: ["matrix-org", "eslint-plugin-react-compiler"],
3-
extends: [
4-
"plugin:matrix-org/babel",
5-
"plugin:matrix-org/react",
6-
"plugin:matrix-org/a11y",
7-
"plugin:storybook/recommended",
8-
],
3+
extends: ["plugin:matrix-org/babel", "plugin:matrix-org/react", "plugin:matrix-org/a11y"],
94
parserOptions: {
105
project: ["./tsconfig.json"],
116
},

.github/workflows/shared-component-visual-tests.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ jobs:
3131
cache: "yarn"
3232
node-version: "lts/*"
3333

34+
- name: Install element web dependencies
35+
run: yarn install --frozen-lockfile
36+
3437
- name: Install dependencies
38+
working-directory: packages/shared-components
3539
run: yarn install --frozen-lockfile
3640

3741
- name: Get installed Playwright version
42+
working-directory: packages/shared-components
3843
id: playwright
3944
run: echo "version=$(yarn list --pattern @playwright/test --depth=0 --json --non-interactive --no-progress | jq -r '.data.trees[].name')" >> $GITHUB_OUTPUT
4045

@@ -46,6 +51,7 @@ jobs:
4651
key: ${{ runner.os }}-${{ runner.arch }}-playwright-${{ steps.playwright.outputs.version }}-onlyshell
4752

4853
- name: Install Playwright browsers
54+
working-directory: packages/shared-components
4955
if: steps.playwright-cache.outputs.cache-hit != 'true'
5056
run: "yarn playwright install --with-deps --only-shell"
5157

@@ -56,15 +62,15 @@ jobs:
5662
- name: Build storybook dependencies
5763
# When the first test is ran, it will fail because the dependencies are not yet built.
5864
# This step is to ensure that the dependencies are built before running the tests.
59-
run: "yarn test:storybook:ci"
65+
run: "yarn --cwd packages/shared-components test:storybook:ci"
6066
continue-on-error: true
6167

6268
- name: Run Visual tests
63-
run: "yarn test:storybook:ci"
69+
run: "yarn --cwd packages/shared-components test:storybook:ci"
6470

6571
- name: Upload received images & diffs
6672
if: always()
6773
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
6874
with:
6975
name: received-images
70-
path: playwright/shared-component-received
76+
path: packages/shared-components/playwright/shared-component-received

.github/workflows/static_analysis.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ jobs:
3535
- name: Typecheck
3636
run: "yarn run lint:types"
3737

38+
- name: Install Shared Component Dependencies
39+
run: "yarn --cwd packages/shared-components install"
40+
41+
- name: Typecheck Shared Components
42+
run: "yarn --cwd packages/shared-components run lint:types"
43+
3844
i18n_lint:
3945
name: "i18n Check"
4046
uses: matrix-org/matrix-web-i18n/.github/workflows/i18n_check.yml@main
@@ -81,6 +87,12 @@ jobs:
8187
- name: Run Linter
8288
run: "yarn run lint:js"
8389

90+
- name: Install Shared Component Deps
91+
run: "yarn --cwd packages/shared-components install --frozen-lockfile"
92+
93+
- name: Run Linter
94+
run: "yarn --cwd packages/shared-components run lint:js"
95+
8496
style_lint:
8597
name: "Style Lint"
8698
runs-on: ubuntu-24.04

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
/key.pem
55
/lib
66
/node_modules
7-
/packages/
87
/webapp
98
/.npmrc
109
/*.log
@@ -34,3 +33,6 @@ electron/pub
3433

3534
*storybook.log
3635
storybook-static
36+
37+
/packages/shared-components/node_modules
38+
/packages/shared-components/dist

knip.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default {
1919
"src/hooks/useTimeout.ts",
2020
"src/components/views/elements/InfoTooltip.tsx",
2121
"src/components/views/elements/StyledCheckbox.tsx",
22+
23+
"packages/**/*",
2224
],
2325
ignoreDependencies: [
2426
// Required for `action-validator`

package.json

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"UserFriendlyError"
3030
],
3131
"scripts": {
32-
"i18n": "matrix-gen-i18n && yarn i18n:sort && yarn i18n:lint",
32+
"i18n": "matrix-gen-i18n src res packages/shared-components && yarn i18n:sort && yarn i18n:lint",
3333
"i18n:sort": "jq --sort-keys '.' src/i18n/strings/en_EN.json > src/i18n/strings/en_EN.json.tmp && mv src/i18n/strings/en_EN.json.tmp src/i18n/strings/en_EN.json",
3434
"i18n:lint": "matrix-i18n-lint && prettier --log-level=silent --write src/i18n/strings/ --ignore-path /dev/null",
3535
"i18n:diff": "cp src/i18n/strings/en_EN.json src/i18n/strings/en_EN_orig.json && yarn i18n && matrix-compare-i18n-files src/i18n/strings/en_EN_orig.json src/i18n/strings/en_EN.json",
@@ -65,12 +65,7 @@
6565
"coverage": "yarn test --coverage",
6666
"analyse:webpack-bundles": "webpack-bundle-analyzer webpack-stats.json webapp",
6767
"update:jitsi": "curl -s https://meet.element.io/libs/external_api.min.js > ./res/jitsi_external_api.min.js",
68-
"postinstall": "patch-package",
69-
"storybook": "storybook dev -p 6007",
70-
"build-storybook": "storybook build",
71-
"test:storybook": "test-storybook --url http://localhost:6007/",
72-
"test:storybook:ci": "concurrently -k -s first -n \"SB,TEST\" \"yarn storybook --no-open\" \"wait-on tcp:6007 && yarn test-storybook --url http://localhost:6007/ --ci --maxWorkers=2\"",
73-
"test:storybook:update": "playwright-screenshots --entrypoint yarn --with-node-modules && playwright-screenshots --entrypoint /work/node_modules/.bin/test-storybook --with-node-modules --url http://host.docker.internal:6007/ --updateSnapshot"
68+
"postinstall": "patch-package"
7469
},
7570
"resolutions": {
7671
"**/pretty-format/react-is": "19.1.1",
@@ -192,12 +187,6 @@
192187
"@principalstudio/html-webpack-inject-preload": "^1.2.7",
193188
"@rrweb/types": "^2.0.0-alpha.18",
194189
"@sentry/webpack-plugin": "^4.0.0",
195-
"@storybook/addon-a11y": "^9.0.18",
196-
"@storybook/addon-designs": "^10.0.1",
197-
"@storybook/addon-docs": "^9.0.12",
198-
"@storybook/icons": "^1.4.0",
199-
"@storybook/react-vite": "^9.0.15",
200-
"@storybook/test-runner": "^0.23.0",
201190
"@stylistic/eslint-plugin": "^5.0.0",
202191
"@svgr/webpack": "^8.0.0",
203192
"@testing-library/dom": "^10.4.0",
@@ -258,7 +247,6 @@
258247
"eslint-plugin-react": "^7.28.0",
259248
"eslint-plugin-react-compiler": "^19.0.0-beta-df7b47d-20241124",
260249
"eslint-plugin-react-hooks": "^5.0.0",
261-
"eslint-plugin-storybook": "^9.0.12",
262250
"eslint-plugin-unicorn": "^56.0.0",
263251
"express": "^5.0.0",
264252
"fake-indexeddb": "^6.0.0",
@@ -271,7 +259,6 @@
271259
"jest": "^29.6.2",
272260
"jest-canvas-mock": "^2.5.2",
273261
"jest-environment-jsdom": "^29.7.0",
274-
"jest-image-snapshot": "^6.5.1",
275262
"jest-mock": "^29.6.2",
276263
"jest-raw-loader": "^1.0.1",
277264
"jsqr": "^1.4.0",
@@ -300,7 +287,6 @@
300287
"rimraf": "^6.0.0",
301288
"semver": "^7.5.2",
302289
"source-map-loader": "^5.0.0",
303-
"storybook": "^9.0.12",
304290
"stylelint": "^16.23.0",
305291
"stylelint-config-standard": "^39.0.0",
306292
"stylelint-scss": "^6.0.0",
@@ -310,8 +296,6 @@
310296
"ts-node": "^10.9.1",
311297
"typescript": "5.8.3",
312298
"util": "^0.12.5",
313-
"vite": "^7.0.1",
314-
"vite-plugin-node-polyfills": "^0.24.0",
315299
"web-streams-polyfill": "^4.0.0",
316300
"webpack": "^5.89.0",
317301
"webpack-bundle-analyzer": "^4.8.0",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module.exports = {
2+
plugins: ["matrix-org", "eslint-plugin-react-compiler"],
3+
extends: [
4+
"plugin:matrix-org/babel",
5+
"plugin:matrix-org/react",
6+
"plugin:matrix-org/a11y",
7+
"plugin:storybook/recommended",
8+
],
9+
parserOptions: {
10+
project: ["./tsconfig.json"],
11+
},
12+
env: {
13+
browser: true,
14+
node: true,
15+
},
16+
rules: {
17+
// Bind or arrow functions in props causes performance issues (but we
18+
// currently use them in some places).
19+
// It's disabled here, but we should using it sparingly.
20+
"react/jsx-no-bind": "off",
21+
"react/jsx-key": ["error"],
22+
"matrix-org/require-copyright-header": "error",
23+
"react-compiler/react-compiler": "error",
24+
},
25+
overrides: [
26+
{
27+
files: ["src/**/*.{ts,tsx}", "test/**/*.{ts,tsx}"],
28+
extends: ["plugin:matrix-org/typescript", "plugin:matrix-org/react"],
29+
rules: {
30+
"@typescript-eslint/explicit-function-return-type": [
31+
"error",
32+
{
33+
allowExpressions: true,
34+
},
35+
],
36+
37+
// Remove Babel things manually due to override limitations
38+
"@babel/no-invalid-this": ["off"],
39+
40+
// We're okay being explicit at the moment
41+
"@typescript-eslint/no-empty-interface": "off",
42+
// We disable this while we're transitioning
43+
"@typescript-eslint/no-explicit-any": "off",
44+
// We'd rather not do this but we do
45+
"@typescript-eslint/ban-ts-comment": "off",
46+
// We're okay with assertion errors when we ask for them
47+
"@typescript-eslint/no-non-null-assertion": "off",
48+
"@typescript-eslint/no-empty-object-type": [
49+
"error",
50+
{
51+
// We do this sometimes to brand interfaces
52+
allowInterfaces: "with-single-extends",
53+
},
54+
],
55+
},
56+
},
57+
],
58+
settings: {
59+
react: {
60+
version: "detect",
61+
},
62+
},
63+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/
File renamed without changes.

.storybook/languageAddon.tsx renamed to packages/shared-components/.storybook/languageAddon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { GlobeIcon } from "@storybook/icons";
1212

1313
// We can't import `shared/i18n.tsx` directly here.
1414
// The storybook addon doesn't seem to benefit the vite config of storybook and we can't resolve the alias in i18n.tsx.
15-
import json from "../webapp/i18n/languages.json";
15+
import json from "../../../webapp/i18n/languages.json";
1616
const languages = Object.keys(json).filter((lang) => lang !== "default");
1717

1818
/**

0 commit comments

Comments
 (0)