From 860161bdd238f33210c3f51acf16b72655540ddc Mon Sep 17 00:00:00 2001 From: Saul Date: Tue, 8 Oct 2024 23:34:01 +1300 Subject: [PATCH] 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. --- babel.config.cjs | 17 +++++++++++++++++ package.json | 1 + src/client.ts | 4 +--- yarn.lock | 5 +++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/babel.config.cjs b/babel.config.cjs index d5c314af157..23ab202ae02 100644 --- a/babel.config.cjs +++ b/babel.config.cjs @@ -31,5 +31,22 @@ module.exports = { "@babel/plugin-transform-object-rest-spread", "@babel/plugin-syntax-dynamic-import", "@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", + }, + ] + : [], + }, + ], ], }; diff --git a/package.json b/package.json index 46687405cad..e2e274b8b2f 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ "@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/parser": "^7.0.0", "babel-jest": "^29.0.0", + "babel-plugin-search-and-replace": "^1.1.1", "debug": "^4.3.4", "eslint": "8.57.0", "eslint-config-google": "^0.14.0", diff --git a/src/client.ts b/src/client.ts index 3a9860b3a8b..514586047a8 100644 --- a/src/client.ts +++ b/src/client.ts @@ -2254,9 +2254,7 @@ export class MatrixClient extends TypedEventEmitter