1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-06 12:02:40 +03:00

Fix the rust crypto import in esm environments. (#4445)

* Configure babel to fix the rust import in esm environments.

* Add lockfile changes.

* Cleanup rust-crypto import and babel config.
This commit is contained in:
Saul
2024-10-08 23:34:01 +13:00
committed by GitHub
parent 0c9d82e40a
commit 860161bdd2
4 changed files with 24 additions and 3 deletions

View File

@@ -31,5 +31,22 @@ module.exports = {
"@babel/plugin-transform-object-rest-spread", "@babel/plugin-transform-object-rest-spread",
"@babel/plugin-syntax-dynamic-import", "@babel/plugin-syntax-dynamic-import",
"@babel/plugin-transform-runtime", "@babel/plugin-transform-runtime",
[
"search-and-replace",
{
// Since rewriteImportExtensions doesn't work on dynamic imports (yet), we need to manually replace
// the dynamic rust-crypto import.
// (see https://github.com/babel/babel/issues/16750)
rules:
process.env.NODE_ENV !== "test"
? [
{
search: "./rust-crypto/index.ts",
replace: "./rust-crypto/index.js",
},
]
: [],
},
],
], ],
}; };

View File

@@ -91,6 +91,7 @@
"@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0", "@typescript-eslint/parser": "^7.0.0",
"babel-jest": "^29.0.0", "babel-jest": "^29.0.0",
"babel-plugin-search-and-replace": "^1.1.1",
"debug": "^4.3.4", "debug": "^4.3.4",
"eslint": "8.57.0", "eslint": "8.57.0",
"eslint-config-google": "^0.14.0", "eslint-config-google": "^0.14.0",

View File

@@ -2254,9 +2254,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
// importing rust-crypto will download the webassembly, so we delay it until we know it will be // importing rust-crypto will download the webassembly, so we delay it until we know it will be
// needed. // needed.
this.logger.debug("Downloading Rust crypto library"); this.logger.debug("Downloading Rust crypto library");
// blocked on https://github.com/matrix-org/matrix-js-sdk/issues/4392 / https://github.com/babel/babel/issues/16750 const RustCrypto = await import("./rust-crypto/index.ts");
// eslint-disable-next-line node/file-extension-in-import
const RustCrypto = await import("./rust-crypto");
const rustCrypto = await RustCrypto.initRustCrypto({ const rustCrypto = await RustCrypto.initRustCrypto({
logger: this.logger, logger: this.logger,

View File

@@ -2278,6 +2278,11 @@ babel-plugin-polyfill-regenerator@^0.6.1:
dependencies: dependencies:
"@babel/helper-define-polyfill-provider" "^0.6.2" "@babel/helper-define-polyfill-provider" "^0.6.2"
babel-plugin-search-and-replace@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/babel-plugin-search-and-replace/-/babel-plugin-search-and-replace-1.1.1.tgz#2e5b4488e41d9eba1c220651b1a9b350fdf10915"
integrity sha512-fjP2VTF3mxxOUnc96mdK22llH92A6gu7A5AFapJmgnqsQi3bqLduIRP0FpA2r5vRZOYPpnX4rE5izQlpsMBjSA==
babel-preset-current-node-syntax@^1.0.0: babel-preset-current-node-syntax@^1.0.0:
version "1.0.1" version "1.0.1"
resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz#b4399239b89b2a011f9ddbe3e4f401fc40cff73b" resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz#b4399239b89b2a011f9ddbe3e4f401fc40cff73b"