Skip to content

Commit 5dc8edc

Browse files
authored
Build the published shared components (#30986)
* 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 * Build shared components in their separate package Port #30963 to #30962 * Add prepare script * try making it a postinstall * no, this probably does want to be prepare postinstall doesn't really make sense since you would not have the dev dependencies at that point * Add workflow to publish shared components * Put in the namespace * 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 * Fix name, add main, move patch-package to dependencies Although the only patched package is a dev dependency, but the postinstall will fail if patch-package isn't there. * Switch to npm for publishing Mostly because knip seems to this that yarn publish doesn't exist, although actually it seems super confused about versioning so let's just skip it. * Also hopefully enable provenance because why not * Maybe get exports right * Add richlist * Yeah, of course the keys are ordered why would the keys not be ordered * Build web resources first Otherwise yarn prepare won't work * Fix exports and add web-i18n as a dep * prettier * build res for static analysis * more build:res * ViewModel is only an interface so export type * Prettier * Bump to 5 as I'll do at least one test with the publish action
1 parent 0d1da4f commit 5dc8edc

File tree

7 files changed

+607
-21
lines changed

7 files changed

+607
-21
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish shared component npm package
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
version-bump:
6+
description: The scale of the version bump required for semver compatibility
7+
required: true
8+
default: patch
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
concurrency: release
15+
jobs:
16+
publish:
17+
name: "Release & Publish"
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
id-token: write
22+
23+
steps:
24+
- name: 🧮 Checkout code
25+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
26+
27+
- name: 🔧 Set up node environment
28+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5
29+
with:
30+
cache: "yarn"
31+
node-version-file: ".node-version"
32+
33+
- name: 🛠️ Setup
34+
# When running `install` it also calls the `prepare` step which generates
35+
# a build
36+
run: yarn --cwd packages/shared-components install --pure-lockfile
37+
38+
- name: 👊 Bump version
39+
run: |
40+
cd packages/shared-components
41+
yarn version --no-git-tag-version --${{ github.event.inputs.version-bump }}
42+
git config --global user.name 'ElementRobot'
43+
git config --global user.email '[email protected]'
44+
git commit -am "Shared components: ${{ github.event.inputs.version-bump }} version bump"
45+
git push
46+
47+
- name: 🚀 Publish to npm
48+
working-directory: packages/shared-components
49+
run: npm publish --access public --provenance

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ jobs:
3434
- name: Install element web dependencies
3535
run: yarn install --frozen-lockfile
3636

37+
- name: Build Element Web resources
38+
# Needed to prepare language files
39+
run: "yarn build:res"
40+
3741
- name: Install dependencies
3842
working-directory: packages/shared-components
3943
run: yarn install --frozen-lockfile
@@ -55,10 +59,6 @@ jobs:
5559
if: steps.playwright-cache.outputs.cache-hit != 'true'
5660
run: "yarn playwright install --with-deps --only-shell"
5761

58-
- name: Build Element Web resources
59-
# Needed to prepare language files
60-
run: "yarn build:res"
61-
6262
- name: Build storybook dependencies
6363
# When the first test is ran, it will fail because the dependencies are not yet built.
6464
# This step is to ensure that the dependencies are built before running the tests.

.github/workflows/static_analysis.yaml

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

38+
- name: Build Element Web resources
39+
# Needed to prepare language files for shared components
40+
run: "yarn build:res"
41+
3842
- name: Install Shared Component Dependencies
3943
run: "yarn --cwd packages/shared-components install"
4044

@@ -87,6 +91,10 @@ jobs:
8791
- name: Run Linter
8892
run: "yarn run lint:js"
8993

94+
- name: Build Element Web resources
95+
# Needed to prepare language files for shared components
96+
run: "yarn build:res"
97+
9098
- name: Install Shared Component Deps
9199
run: "yarn --cwd packages/shared-components install --frozen-lockfile"
92100

packages/shared-components/package.json

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
{
2-
"name": "element-web-shared-components",
3-
"version": "1.12.1",
2+
"name": "@element-hq/web-shared-components",
3+
"version": "0.0.0-test.5",
44
"description": "Shared components for Element",
55
"author": "New Vector Ltd.",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/element-hq/element-web"
99
},
10-
"license": "SEE LICENSE IN README.md",
10+
"exports": {
11+
".": {
12+
"require": {
13+
"style": "./dist/element-web-shared-components.css",
14+
"types": "./dist/element-web-shared-components.d.ts",
15+
"default": "./dist/element-web-shared-components.umd.js"
16+
},
17+
"import": {
18+
"style": "./dist/element-web-shared-components.css",
19+
"types": "./dist/element-web-shared-components.d.ts",
20+
"default": "./dist/element-web-shared-components.mjs"
21+
}
22+
}
23+
},
24+
"types": "dist/element-web-shared-components.d.ts",
1125
"files": [
12-
"lib",
26+
"dist",
1327
"src",
1428
"LICENSE",
1529
"README.md",
@@ -26,7 +40,10 @@
2640
"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\"",
2741
"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"
2842
},
29-
"dependencies": {},
43+
"dependencies": {
44+
"matrix-web-i18n": "^3.4.0",
45+
"patch-package": "^8.0.1"
46+
},
3047
"devDependencies": {
3148
"@storybook/addon-a11y": "^9.1.10",
3249
"@storybook/addon-designs": "^10.0.2",
@@ -36,13 +53,15 @@
3653
"@storybook/test-runner": "^0.23.0",
3754
"concurrently": "^9.2.1",
3855
"eslint": "8",
56+
"jest-image-snapshot": "^6.5.1",
3957
"eslint-plugin-storybook": "^9.1.10",
4058
"jest-image-snapshot": "^6.5.1",
4159
"patch-package": "^8.0.1",
4260
"prettier": "^3.6.2",
4361
"storybook": "^9.1.10",
4462
"typescript": "^5.9.3",
4563
"vite": "^7.1.9",
64+
"vite-plugin-dts": "^4.5.4",
4665
"vite-plugin-node-polyfills": "^0.24.0"
4766
},
4867
"engines": {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
// Components
9+
export * from "./audio/AudioPlayerView";
10+
export * from "./audio/Clock";
11+
export * from "./audio/PlayPauseButton";
12+
export * from "./audio/SeekBar";
13+
export * from "./avatar/AvatarWithDetails";
14+
export * from "./event-tiles/TextualEventView";
15+
export * from "./message-body/MediaBody";
16+
export * from "./pill-input/Pill";
17+
export * from "./pill-input/PillInput";
18+
export * from "./rich-list/RichItem";
19+
export * from "./rich-list/RichList";
20+
export * from "./utils/Box";
21+
export * from "./utils/Flex";
22+
23+
// Utils
24+
export * from "./utils/i18n";
25+
export * from "./utils/humanize";
26+
export * from "./utils/DateUtils";
27+
export * from "./utils/numbers";
28+
29+
// MVVM
30+
export * from "./ViewWrapper";
31+
export type * from "./ViewModel";
32+
export * from "./useViewModel";
33+
export * from "./MockViewModel";
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
*
3+
* Copyright 2025 New Vector Ltd.
4+
*
5+
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
6+
* Please see LICENSE files in the repository root for full details.
7+
* /
8+
*/
9+
10+
import { dirname, resolve } from "node:path";
11+
import { fileURLToPath } from "node:url";
12+
import { defineConfig } from "vite";
13+
import dts from "vite-plugin-dts";
14+
15+
const __dirname = dirname(fileURLToPath(import.meta.url));
16+
17+
export default defineConfig({
18+
build: {
19+
lib: {
20+
entry: resolve(__dirname, "src/index.ts"),
21+
name: "Element Web Shared Components",
22+
// the proper extensions will be added
23+
fileName: "element-web-shared-components",
24+
},
25+
outDir: "dist",
26+
rollupOptions: {
27+
// make sure to externalize deps that shouldn't be bundled
28+
// into your library
29+
external: ["react", "react-dom"],
30+
output: {
31+
// Provide global variables to use in the UMD build
32+
// for externalized deps
33+
globals: {
34+
"react": "react",
35+
"react-dom": "ReactDom",
36+
},
37+
},
38+
},
39+
},
40+
resolve: {
41+
alias: {
42+
// Alias used by i18n.tsx
43+
$webapp: resolve(__dirname, "..", "..", "webapp"),
44+
},
45+
},
46+
plugins: [dts({ rollupTypes: true, include: ["src/**/*.{ts,tsx}"], copyDtsFiles: true })],
47+
});

0 commit comments

Comments
 (0)