summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/headless
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-06-02 13:56:29 +0200
committerFlorian Dold <florian@dold.me>2021-06-02 13:56:29 +0200
commit5e6cc41b7a8b41aec30a81b787e5e4b5ed60661a (patch)
tree45614dac0fa24a4c3de873226a1c2ffbb14c840f /packages/taler-wallet-core/src/headless
parent02f1d4b08116c24f0af1f32cb6d82be292fa6d10 (diff)
downloadwallet-core-5e6cc41b7a8b41aec30a81b787e5e4b5ed60661a.tar.gz
wallet-core-5e6cc41b7a8b41aec30a81b787e5e4b5ed60661a.tar.bz2
wallet-core-5e6cc41b7a8b41aec30a81b787e5e4b5ed60661a.zip
fix issues with circular imports
Parts of this commit are from a patch by sebasjm. The circular imports caused an issue with webpack. While we don't use webpack in the wallet, the wallet should still be importable by webpack. Some packages were importing their dependencies via "index.js", which re-exports public exports of the package. This resulted in circular dependencies which were resolved correctly by rollup, but not by webpack.
Diffstat (limited to 'packages/taler-wallet-core/src/headless')
-rw-r--r--packages/taler-wallet-core/src/headless/helpers.ts26
1 files changed, 21 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/headless/helpers.ts b/packages/taler-wallet-core/src/headless/helpers.ts
index 5007a65ac..1ae556b39 100644
--- a/packages/taler-wallet-core/src/headless/helpers.ts
+++ b/packages/taler-wallet-core/src/headless/helpers.ts
@@ -30,7 +30,6 @@ import {
} from "@gnu-taler/idb-bridge";
import { openTalerDatabase } from "../db";
import { HttpRequestLibrary } from "../util/http";
-import fs from "fs";
import { NodeThreadCryptoWorkerFactory } from "../crypto/workers/nodeThreadWorker";
import { NodeHttpLib } from "./NodeHttpLib";
import { Logger } from "../util/logging";
@@ -40,6 +39,21 @@ import { WalletNotification } from "@gnu-taler/taler-util";
const logger = new Logger("headless/helpers.ts");
+const nodejs_fs = (function () {
+ let fs: typeof import("fs");
+ return function() {
+ if (!fs) {
+ /**
+ * need to use an expression when doing a require if we want
+ * webpack not to find out about the requirement
+ */
+ const _r = "require"
+ fs = module[_r]("fs")
+ }
+ return fs
+ }
+})()
+
export interface DefaultNodeWalletArgs {
/**
* Location of the wallet database.
@@ -87,7 +101,7 @@ export async function getDefaultNodeWallet(
const storagePath = args.persistentStoragePath;
if (storagePath) {
try {
- const dbContentStr: string = fs.readFileSync(storagePath, {
+ const dbContentStr: string = nodejs_fs().readFileSync(storagePath, {
encoding: "utf-8",
});
const dbContent = JSON.parse(dbContentStr);
@@ -109,11 +123,11 @@ export async function getDefaultNodeWallet(
}
const tmpPath = `${args.persistentStoragePath}-${makeId(5)}.tmp`;
const dbContent = myBackend.exportDump();
- fs.writeFileSync(tmpPath, JSON.stringify(dbContent, undefined, 2), {
+ nodejs_fs().writeFileSync(tmpPath, JSON.stringify(dbContent, undefined, 2), {
encoding: "utf-8",
});
// Atomically move the temporary file onto the DB path.
- fs.renameSync(tmpPath, args.persistentStoragePath);
+ nodejs_fs().renameSync(tmpPath, args.persistentStoragePath);
};
}
@@ -143,7 +157,9 @@ export async function getDefaultNodeWallet(
let workerFactory;
try {
// Try if we have worker threads available, fails in older node versions.
- require("worker_threads");
+ const _r = "require"
+ const worker_threads = module[_r]("worker_threads");
+ // require("worker_threads");
workerFactory = new NodeThreadCryptoWorkerFactory();
} catch (e) {
logger.warn(