From f0e2b966af145e2cc1458415acf670adf7313f2e Mon Sep 17 00:00:00 2001 From: mainnet-pat <74184164+mainnet-pat@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:08:51 +0300 Subject: [PATCH] Fix handling of internal assets to eliminate the need for dist/dist --- package.json | 5 ++++- src/main/cpp/http_client_wasm.cpp | 14 ++++++-------- src/main/ts/common/LibraryUtils.ts | 2 +- src/main/ts/common/MoneroWebWorker.ts | 5 +++++ webpack.base.js | 2 -- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 8fe398e9c..80feead38 100644 --- a/package.json +++ b/package.json @@ -17,13 +17,16 @@ "CMakeListst.txt", "LICENSE.txt" ], + "imports": { + "#monero-ts/monero.js": "./dist/monero.js" + }, "scripts": { "start": "todo", "build_web_worker": "webpack --config ./webpack.worker.js", "build_web_tests": "webpack --config ./webpack.tests.js", "test": "npm run build_commonjs && node --enable-source-maps node_modules/mocha/bin/_mocha --require @babel/register \"dist/src/test/TestAll\" --timeout 900000000 --exit", "typedoc": "typedoc ./index.ts --out ./docs/typedocs --excludePrivate --disableSources", - "build_commonjs": "babel ./src --extensions \".js,.ts\" --out-dir ./dist/src && babel ./index.ts --extensions \".ts\" --out-dir ./dist && shx mkdir -p dist/dist && shx cp dist/monero.js dist/dist && shx cp dist/*.js.map dist/dist", + "build_commonjs": "babel ./src --extensions \".js,.ts\" --out-dir ./dist/src && babel ./index.ts --extensions \".ts\" --out-dir ./dist", "check_babel_version": "babel -V" }, "build": { diff --git a/src/main/cpp/http_client_wasm.cpp b/src/main/cpp/http_client_wasm.cpp index edb718bd2..4ba60d794 100644 --- a/src/main/cpp/http_client_wasm.cpp +++ b/src/main/cpp/http_client_wasm.cpp @@ -12,10 +12,9 @@ using namespace std; EM_JS(const char*, js_send_json_request, (const char* uri, const char* username, const char* password, const char* reject_unauthorized_fn_id, const char* method, const char* body, std::chrono::milliseconds timeout), { //console.log("EM_JS js_send_json_request(" + UTF8ToString(uri) + ", " + UTF8ToString(username) + ", " + UTF8ToString(password) + ", " + UTF8ToString(method) + ")"); - const moneroTs = require("../index"); - const HttpClient = moneroTs.HttpClient; - const LibraryUtils = moneroTs.LibraryUtils; - const GenUtils = moneroTs.GenUtils; + const HttpClient = this.HttpClient; + const LibraryUtils = this.LibraryUtils; + const GenUtils = this.GenUtils; // use asyncify to synchronously return to C++ return Asyncify.handleSleep(function(wakeUp) { @@ -66,10 +65,9 @@ EM_JS(const char*, js_send_json_request, (const char* uri, const char* username, EM_JS(const char*, js_send_binary_request, (const char* uri, const char* username, const char* password, const char* reject_unauthorized_fn_id, const char* method, const char* body, int body_length, std::chrono::milliseconds timeout), { //console.log("EM_JS js_send_binary_request(" + UTF8ToString(uri) + ", " + UTF8ToString(username) + ", " + UTF8ToString(password) + ", " + UTF8ToString(method) + ")"); - const moneroTs = require("../index"); - const HttpClient = moneroTs.HttpClient; - const LibraryUtils = moneroTs.LibraryUtils; - const GenUtils = moneroTs.GenUtils; + const HttpClient = this.HttpClient; + const LibraryUtils = this.LibraryUtils; + const GenUtils = this.GenUtils; // use asyncify to synchronously return to C++ return Asyncify.handleSleep(function(wakeUp) { diff --git a/src/main/ts/common/LibraryUtils.ts b/src/main/ts/common/LibraryUtils.ts index d56ee0e73..bb89884a5 100644 --- a/src/main/ts/common/LibraryUtils.ts +++ b/src/main/ts/common/LibraryUtils.ts @@ -90,7 +90,7 @@ export default class LibraryUtils { if (LibraryUtils.WASM_MODULE && LibraryUtils.FULL_LOADED) return LibraryUtils.WASM_MODULE; // load module - let module = await require("../../../../dist/monero")(); + const module = await require("#monero-ts/monero.js")(); LibraryUtils.WASM_MODULE = module; delete LibraryUtils.WASM_MODULE.then; LibraryUtils.FULL_LOADED = true; diff --git a/src/main/ts/common/MoneroWebWorker.ts b/src/main/ts/common/MoneroWebWorker.ts index 7d456826e..c24b20052 100644 --- a/src/main/ts/common/MoneroWebWorker.ts +++ b/src/main/ts/common/MoneroWebWorker.ts @@ -21,6 +21,11 @@ import MoneroWalletFull from "../wallet/MoneroWalletFull"; declare const self: any; +// expose some modules to the worker +self.HttpClient = HttpClient; +self.LibraryUtils = LibraryUtils; +self.GenUtils = GenUtils; + /** * Worker to manage a daemon and wasm wallet off the main thread using messages. * diff --git a/webpack.base.js b/webpack.base.js index cefa96af8..e5b360302 100644 --- a/webpack.base.js +++ b/webpack.base.js @@ -39,12 +39,10 @@ let configBase = { extensions: ['.js', '.ts'], alias: { "fs": "memfs", - ['~']: path.resolve(__dirname + '/app') }, extensions: ['.js', '.jsx', '.css', '.json', 'otf', 'ttf', 'eot', 'svg', '.ts', '.tsx'], modules: [ 'node_modules', - path.resolve(__dirname + '/src') ], fallback: { // browser polyfills assert: require.resolve('assert'),