Skip to content

Commit bc0ea20

Browse files
BillCarsonFrtoger5robintown
authored
Default vite config to support using local build of crypto wasm (#3038)
* Devex: Default vite config to support using local build of crypto wasm * use realpathSync and make it work with linked and not-linked We need to use sync because an async defineConfig fails for the embedded exports. * also allow just linking matrix-sdk-crypto-wasm (without js-sdk linking) --------- Co-authored-by: Timo <[email protected]> Co-authored-by: Timo <[email protected]> Co-authored-by: Robin <[email protected]>
1 parent 46f0599 commit bc0ea20

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/utils/matrix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export function getRelativeRoomUrl(
337337
}
338338

339339
/**
340-
* Perfom a network operation with retries on ConnectionError.
340+
* Perform a network operation with retries on ConnectionError.
341341
* If the error is not retryable, or the max number of retries is reached, the error is rethrown.
342342
* Supports handling of matrix quotas.
343343
*/

vite.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
55
Please see LICENSE in the repository root for full details.
66
*/
77

8-
import { defineConfig, loadEnv } from "vite";
8+
import { defineConfig, loadEnv, searchForWorkspaceRoot } from "vite";
99
import svgrPlugin from "vite-plugin-svgr";
1010
import { createHtmlPlugin } from "vite-plugin-html";
1111
import { codecovVitePlugin } from "@codecov/vite-plugin";
1212
import { sentryVitePlugin } from "@sentry/vite-plugin";
1313
import react from "@vitejs/plugin-react";
1414
import basicSsl from "@vitejs/plugin-basic-ssl";
15+
import { realpathSync } from "fs";
1516

1617
// https://vitejs.dev/config/
1718
export default defineConfig(({ mode, packageType }) => {
@@ -64,9 +65,25 @@ export default defineConfig(({ mode, packageType }) => {
6465
);
6566
}
6667

68+
// The crypto WASM module is imported dynamically. Since it's common
69+
// for developers to use a linked copy of matrix-js-sdk or Rust
70+
// crypto (which could reside anywhere on their file system), Vite
71+
// needs to be told to recognize it as a legitimate file access.
72+
const allow = [searchForWorkspaceRoot(process.cwd())];
73+
for (const path of [
74+
"node_modules/matrix-js-sdk/node_modules/@matrix-org/matrix-sdk-crypto-wasm",
75+
"node_modules/@matrix-org/matrix-sdk-crypto-wasm",
76+
]) {
77+
try {
78+
allow.push(realpathSync(path));
79+
} catch {}
80+
}
81+
console.log("Allowed vite paths:", allow);
82+
6783
return {
6884
server: {
6985
port: 3000,
86+
fs: { allow },
7087
},
7188
build: {
7289
sourcemap: true,

0 commit comments

Comments
 (0)