gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: fix issues with circular impo


From: gnunet
Subject: [taler-wallet-core] branch master updated: fix issues with circular imports
Date: Wed, 02 Jun 2021 13:59:07 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 5e6cc41b fix issues with circular imports
5e6cc41b is described below

commit 5e6cc41b7a8b41aec30a81b787e5e4b5ed60661a
Author: Florian Dold <florian@dold.me>
AuthorDate: Wed Jun 2 13:56:29 2021 +0200

    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.
---
 .vscode/settings.json                              |  4 +++-
 .../src/crypto/workers/nodeThreadWorker.ts         |  8 +++++--
 packages/taler-wallet-core/src/headless/helpers.ts | 26 +++++++++++++++++-----
 packages/taler-wallet-core/src/index.ts            | 18 +++++++--------
 .../taler-wallet-core/src/operations/currencies.ts |  2 +-
 .../taler-wallet-core/src/operations/reserves.ts   | 15 +++++--------
 packages/taler-wallet-core/src/util/logging.ts     |  2 +-
 7 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/.vscode/settings.json b/.vscode/settings.json
index a30ba465..52b26670 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -46,5 +46,7 @@
         "api-extractor.json": "jsonc"
     },
     "typescript.preferences.importModuleSpecifierEnding": "js",
-    "typescript.preferences.importModuleSpecifier": "project-relative"
+    "typescript.preferences.importModuleSpecifier": "project-relative",
+    "javascript.preferences.importModuleSpecifier": "project-relative",
+    "javascript.preferences.importModuleSpecifierEnding": "js"
 }
\ No newline at end of file
diff --git a/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts 
b/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts
index 84d83312..66fd2de7 100644
--- a/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts
+++ b/packages/taler-wallet-core/src/crypto/workers/nodeThreadWorker.ts
@@ -92,7 +92,10 @@ export function handleWorkerMessage(msg: any): void {
     try {
       const result = (impl as any)[operation](...args);
       // eslint-disable-next-line @typescript-eslint/no-var-requires
-      const worker_threads = require("worker_threads");
+      const _r = "require"
+      const worker_threads: typeof import("worker_threads") = 
module[_r]("worker_threads");
+      // const worker_threads = require("worker_threads");
+
       const p = worker_threads.parentPort;
       worker_threads.parentPort?.postMessage;
       if (p) {
@@ -146,7 +149,8 @@ class NodeThreadCryptoWorker implements CryptoWorker {
 
   constructor() {
     // eslint-disable-next-line @typescript-eslint/no-var-requires
-    const worker_threads = require("worker_threads");
+    const _r = "require"
+    const worker_threads = module[_r]("worker_threads");
 
     logger.trace("starting node crypto worker");
 
diff --git a/packages/taler-wallet-core/src/headless/helpers.ts 
b/packages/taler-wallet-core/src/headless/helpers.ts
index 5007a65a..1ae556b3 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(
diff --git a/packages/taler-wallet-core/src/index.ts 
b/packages/taler-wallet-core/src/index.ts
index 1f390127..26701256 100644
--- a/packages/taler-wallet-core/src/index.ts
+++ b/packages/taler-wallet-core/src/index.ts
@@ -18,11 +18,16 @@
  * Module entry point for the wallet when used as a node module.
  */
 
-export { Wallet } from "./wallet";
-
 // Errors
 export * from "./operations/errors";
 
+// Util functionality
+export { Logger } from "./util/logging";
+export { URL } from "./util/url";
+export * from "./util/promiseUtils";
+export * from "./util/query";
+export * from "./util/http";
+
 // Utils for using the wallet under node
 export { NodeHttpLib } from "./headless/NodeHttpLib";
 export {
@@ -44,13 +49,8 @@ export type { CryptoWorker } from 
"./crypto/workers/cryptoWorker";
 export { CryptoWorkerFactory, CryptoApi } from "./crypto/workers/cryptoApi";
 export * from "./crypto/talerCrypto";
 
-// Util functionality
-export { Logger } from "./util/logging";
-export { URL } from "./util/url";
-export * from "./util/promiseUtils";
-export * from "./util/query";
-export * from "./util/http";
-
 export * from "./pending-types";
 
 export * from "./util/debugFlags";
+
+export { Wallet } from "./wallet";
diff --git a/packages/taler-wallet-core/src/operations/currencies.ts 
b/packages/taler-wallet-core/src/operations/currencies.ts
index 5371d4a5..8fd5c62c 100644
--- a/packages/taler-wallet-core/src/operations/currencies.ts
+++ b/packages/taler-wallet-core/src/operations/currencies.ts
@@ -18,7 +18,7 @@
  * Imports.
  */
 import { ExchangeRecord, Stores } from "../db.js";
-import { Logger } from "../index.js";
+import { Logger } from "../util/logging";
 import { getExchangeDetails } from "./exchanges.js";
 import { InternalWalletState } from "./state.js";
 
diff --git a/packages/taler-wallet-core/src/operations/reserves.ts 
b/packages/taler-wallet-core/src/operations/reserves.ts
index d06ce31e..885865af 100644
--- a/packages/taler-wallet-core/src/operations/reserves.ts
+++ b/packages/taler-wallet-core/src/operations/reserves.ts
@@ -40,16 +40,6 @@ import {
   ReserveRecord,
   WithdrawalGroupRecord,
 } from "../db.js";
-import {
-  Logger,
-  encodeCrock,
-  getRandomBytes,
-  readSuccessResponseJsonOrThrow,
-  URL,
-  readSuccessResponseJsonOrErrorCode,
-  throwUnexpectedRequestError,
-  TransactionHandle,
-} from "../index.js";
 import { assertUnreachable } from "../util/assertUnreachable.js";
 import { canonicalizeBaseUrl } from "@gnu-taler/taler-util";
 import {
@@ -73,6 +63,11 @@ import {
   getBankWithdrawalInfo,
 } from "./withdraw.js";
 import { getExchangeTrust } from "./currencies.js";
+import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto.js";
+import { Logger } from "../util/logging.js";
+import { readSuccessResponseJsonOrErrorCode, readSuccessResponseJsonOrThrow, 
throwUnexpectedRequestError } from "../util/http.js";
+import { URL } from "../util/url.js";
+import { TransactionHandle } from "../util/query.js";
 
 const logger = new Logger("reserves.ts");
 
diff --git a/packages/taler-wallet-core/src/util/logging.ts 
b/packages/taler-wallet-core/src/util/logging.ts
index 230cb705..4f48e24d 100644
--- a/packages/taler-wallet-core/src/util/logging.ts
+++ b/packages/taler-wallet-core/src/util/logging.ts
@@ -19,7 +19,7 @@
  */
 
 const isNode =
-  typeof process !== "undefined" && process.release.name === "node";
+  typeof process !== "undefined" && typeof process.release !== "undefined" && 
process.release.name === "node";
 
 function writeNodeLog(
   message: any,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]