mirror of
https://github.com/vector-im/element-call.git
synced 2026-11-28 10:01:09 +08:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a135a7404e | ||
|
|
0118be7ee7 | ||
|
|
788f43f578 | ||
|
|
c0370c254c | ||
|
|
4f6a919aa6 | ||
|
|
13ce1c2648 | ||
|
|
e15b3f9914 | ||
|
|
4bb407afc0 |
@@ -19,10 +19,10 @@ services:
|
||||
- ./backend/playwright_homeserver-othersite.yaml:/data/cfg/homeserver.yaml:Z
|
||||
element-web:
|
||||
# Pin to a SHA so that upstream cannot break our tests. Renovate handles regular updates.
|
||||
image: ghcr.io/element-hq/element-web:develop@sha256:c850f5058acf2eeb9ed4b392f2f3e53b02240e7a74af8e5f7cc8424d12974c49
|
||||
image: ghcr.io/element-hq/element-web:develop@sha256:58b673f867f78fe83c08f2b688b254e34625ebfcebdc5eff84bfdf407445e88e
|
||||
element-web-1:
|
||||
# Pin to a SHA so that upstream cannot break our tests. Renovate handles regular updates.
|
||||
image: ghcr.io/element-hq/element-web:develop@sha256:c850f5058acf2eeb9ed4b392f2f3e53b02240e7a74af8e5f7cc8424d12974c49
|
||||
image: ghcr.io/element-hq/element-web:develop@sha256:58b673f867f78fe83c08f2b688b254e34625ebfcebdc5eff84bfdf407445e88e
|
||||
volumes:
|
||||
# The other site opens the embedded package under test in place of the
|
||||
# copy its image bundles (the first site opens the dev server's app.
|
||||
|
||||
@@ -108,7 +108,8 @@ Code that builds in only one is a bug.
|
||||
- `build:sdk` — `@element-hq/matrixrtc-sdk`, sources in `sdk/`, entry `sdk/index.ts`.
|
||||
Packaged exactly like the component (own pnpm project, run pnpm from the repo
|
||||
root, types from `sdk/tsconfig.build.json`, externals checked by
|
||||
`pnpm lint:externals`).
|
||||
`pnpm lint:externals`). Minified by default (`build:sdk:production`),
|
||||
unminified with `build:sdk:development`; source maps in both.
|
||||
- `build:widget-rtc-sdk` — a single bundle for widget pages that wraps the
|
||||
`sdk/` package and the widget API, nothing of `src/`; entry
|
||||
`widget-rtc-sdk/main.ts`. CI builds it as the `widget-rtc-sdk` package
|
||||
|
||||
+6
-3
@@ -19,14 +19,17 @@
|
||||
"build:sdk": "pnpm build:sdk:js && pnpm build:sdk:types",
|
||||
"build:sdk:js": "pnpm build:full --config vite-sdk.config.js",
|
||||
"build:sdk:types": "tsc -p sdk/tsconfig.build.json",
|
||||
"build:sdk:production": "pnpm build:sdk",
|
||||
"build:sdk:development": "pnpm build:sdk:js --mode development && pnpm build:sdk:types",
|
||||
"build:widget-rtc-sdk": "pnpm build:full --config vite-widget-rtc-sdk.config.js",
|
||||
"build:widget-rtc-sdk:production": "pnpm build:widget-rtc-sdk",
|
||||
"build:widget-rtc-sdk:development": "pnpm build:widget-rtc-sdk --mode development",
|
||||
"build:component": "pnpm build:component:js && pnpm build:component:types",
|
||||
"build:component:js": "pnpm build:full --config vite-component.config.js && node scripts/check-component-bundle.mjs",
|
||||
"build:component": "pnpm build:component:js && pnpm build:component:check && pnpm build:component:types",
|
||||
"build:component:js": "pnpm build:full --config vite-component.config.js",
|
||||
"build:component:check": "node scripts/check-component-bundle.mjs",
|
||||
"build:component:types": "tsc -p component/tsconfig.build.json",
|
||||
"build:component:production": "pnpm build:component",
|
||||
"build:component:development": "pnpm build:component:js --mode development && pnpm build:component:types",
|
||||
"build:component:development": "pnpm build:component:js --mode development && pnpm build:component:check && pnpm build:component:types",
|
||||
"serve": "vite preview",
|
||||
"format": "oxfmt",
|
||||
"format:check": "oxfmt --check; rc=$?; [[ $rc -ne 0 ]] && printf '\\033[46;30m INFO \\033[0m To fix, run: pnpm format\\n' >&2; exit $rc",
|
||||
|
||||
@@ -5,9 +5,10 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { test as setup } from "@playwright/test";
|
||||
import { expect, test as setup } from "@playwright/test";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { mkdirSync } from "node:fs";
|
||||
import { mkdirSync, readdirSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
const EMBEDDED_DIST = "embedded/web/dist";
|
||||
|
||||
@@ -17,4 +18,8 @@ setup("build the embedded package", () => {
|
||||
execFileSync("pnpm", ["build:embedded", "--outDir", EMBEDDED_DIST], {
|
||||
stdio: "inherit",
|
||||
});
|
||||
// The host does the crypto, and nothing runs the standalone client
|
||||
expect(readdirSync(join(EMBEDDED_DIST, "assets"))).not.toContainEqual(
|
||||
expect.stringMatching(/rust-crypto|matrix_sdk_crypto|IndexedDBWorker/),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -99,6 +99,7 @@ own only so that a host can install it as a git dependency (see
|
||||
```sh
|
||||
pnpm dev:sdk # the harness, https://localhost:3002
|
||||
pnpm build:sdk # dist/matrixrtc-sdk.js and dist/types
|
||||
pnpm build:sdk:development # the same, unminified
|
||||
pnpm test:playwright playwright/sdk # needs `pnpm backend`
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { afterEach, expect, test, vi } from "vitest";
|
||||
|
||||
const initSPA = vi.hoisted(() => vi.fn());
|
||||
vi.mock("./utils/spa", () => ({ initSPA }));
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
vi.resetModules();
|
||||
initSPA.mockReset();
|
||||
});
|
||||
|
||||
test("the app restores its own session", async () => {
|
||||
vi.stubEnv("VITE_PACKAGE", "full");
|
||||
const { loadStandaloneClient } = await import("./App");
|
||||
const loadSession = vi.fn();
|
||||
const clearSession = vi.fn();
|
||||
initSPA.mockResolvedValue(null);
|
||||
|
||||
await expect(loadStandaloneClient!(loadSession, clearSession)).resolves.toBe(
|
||||
null,
|
||||
);
|
||||
expect(initSPA).toHaveBeenCalledWith(loadSession, clearSession);
|
||||
});
|
||||
|
||||
test("the embedded package has no session of its own", async () => {
|
||||
vi.stubEnv("VITE_PACKAGE", "embedded");
|
||||
const { loadStandaloneClient } = await import("./App");
|
||||
|
||||
expect(loadStandaloneClient).toBeUndefined();
|
||||
});
|
||||
+6
-2
@@ -64,8 +64,12 @@ const SentryRoute = Sentry.withSentryReactRouterV7Routing(Route);
|
||||
// - Imported on demand, as it was before, so that a widget, which gets its
|
||||
// client from the host, never downloads it.
|
||||
// - Module-level, so that the provider's effect sees one stable loader.
|
||||
const loadStandaloneClient: ClientLoader = async (...args) =>
|
||||
(await import("./utils/spa")).initSPA(...args);
|
||||
// - None in the embedded package, which only runs as a widget: the constant
|
||||
// condition lets its build drop the client setup and the store worker.
|
||||
export const loadStandaloneClient: ClientLoader | undefined =
|
||||
import.meta.env.VITE_PACKAGE === "embedded"
|
||||
? undefined
|
||||
: async (...args) => (await import("./utils/spa")).initSPA(...args);
|
||||
|
||||
interface SimpleProviderProps {
|
||||
children: JSX.Element;
|
||||
|
||||
@@ -7,7 +7,7 @@ Please see LICENSE in the repository root for full details.
|
||||
|
||||
import { defineConfig, mergeConfig } from "vite";
|
||||
|
||||
import fullConfig from "./vite.config.ts";
|
||||
import fullConfig, { withoutMatrixCrypto } from "./vite.config.ts";
|
||||
|
||||
const base = "./";
|
||||
|
||||
@@ -18,6 +18,7 @@ export default defineConfig((env) =>
|
||||
defineConfig({
|
||||
base, // Use relative URLs to allow the app to be hosted under any path
|
||||
publicDir: false, // Don't serve the public directory which only contains the favicon
|
||||
plugins: [withoutMatrixCrypto({ withoutStoreWorker: true })],
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -22,6 +22,9 @@ export default defineConfig(({ mode }) => {
|
||||
// Into the package directory, so that `sdk/package.json` describes what
|
||||
// sits next to it and the directory can be installed as a package
|
||||
outDir: "sdk/dist",
|
||||
// Minified for production (`build:sdk`, `build:sdk:production`), readable
|
||||
// in development (`build:sdk:development`). Source maps in both, as for
|
||||
// the component: they ship with the package for the host to debug with.
|
||||
minify: mode === "production",
|
||||
sourcemap: true,
|
||||
lib: {
|
||||
|
||||
+13
-1
@@ -201,9 +201,17 @@ export default ({
|
||||
* encrypts and decrypts for it, so the Rust crypto chunk and its WASM (about
|
||||
* 10 MB) would only be shipped, never loaded. The SDK imports it dynamically,
|
||||
* from `initRustCrypto` and `preloadRustCrypto`; here those reject instead.
|
||||
*
|
||||
* With `withoutStoreWorker`, the worker behind the standalone client's sync
|
||||
* store goes too, for a build that contains the standalone client's code but
|
||||
* never runs it. The worker is a second copy of the SDK with the crypto, and
|
||||
* the bundler emits it as soon as anything imports it.
|
||||
*/
|
||||
export function withoutMatrixCrypto(): Plugin {
|
||||
export function withoutMatrixCrypto({
|
||||
withoutStoreWorker = false,
|
||||
}: { withoutStoreWorker?: boolean } = {}): Plugin {
|
||||
const crypto = "\0without-matrix-crypto";
|
||||
const worker = "\0without-matrix-store-worker";
|
||||
const unavailable =
|
||||
"new Error('This build uses the client of its host, which does the crypto')";
|
||||
return {
|
||||
@@ -215,6 +223,8 @@ export function withoutMatrixCrypto(): Plugin {
|
||||
/(^|\/)rust-crypto\/index(\.js)?$/.test(source)
|
||||
)
|
||||
return crypto;
|
||||
if (withoutStoreWorker && source.endsWith("/IndexedDBWorker?worker"))
|
||||
return worker;
|
||||
return null;
|
||||
},
|
||||
load(id): string | null {
|
||||
@@ -223,6 +233,8 @@ export function withoutMatrixCrypto(): Plugin {
|
||||
`export async function initRustCrypto() { throw ${unavailable}; }`,
|
||||
`export async function preloadRustCrypto() { throw ${unavailable}; }`,
|
||||
].join("\n");
|
||||
if (id === worker)
|
||||
return `export default class { constructor() { throw ${unavailable}; } }`;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user