From fe1fd30bba0000b791ddcd6bec72719cffbe8c7e Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Sat, 26 Oct 2024 12:56:49 -0400 Subject: [PATCH 1/2] fix: NconfManager --- package-lock.json | 9 +++++++++ package.json | 1 + src/utils/NconfManager.ts | 26 ++++++++++++++++---------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 345fe33..e6099e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@dignetwork/datalayer-driver": "^0.1.29", "@dignetwork/dig-sdk": "^0.0.1-alpha.158", "archiver": "^7.0.1", + "async-mutex": "^0.5.0", "axios": "^1.7.7", "bip39": "^3.1.0", "bottleneck": "^2.19.5", @@ -1192,6 +1193,14 @@ "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==" }, + "node_modules/async-mutex": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.5.0.tgz", + "integrity": "sha512-1A94B18jkJ3DYq284ohPxoXbfTA5HsQ7/Mf4DEhcyLx3Bz27Rh59iScbB6EPiP+B+joue6YCxcMXSbFC1tZKwA==", + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", diff --git a/package.json b/package.json index 43f3e83..14a86c9 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@dignetwork/datalayer-driver": "^0.1.29", "@dignetwork/dig-sdk": "^0.0.1-alpha.158", "archiver": "^7.0.1", + "async-mutex": "^0.5.0", "axios": "^1.7.7", "bip39": "^3.1.0", "bottleneck": "^2.19.5", diff --git a/src/utils/NconfManager.ts b/src/utils/NconfManager.ts index 27f9897..52a7de3 100644 --- a/src/utils/NconfManager.ts +++ b/src/utils/NconfManager.ts @@ -1,10 +1,12 @@ import nconf from "nconf"; import fs from "fs-extra"; +import { Mutex } from 'async-mutex'; import path from "path"; import { USER_DIR_PATH } from "./config"; import { Environment } from "./Environment"; const CONF_FOLDER_PATH = Environment.DIG_FOLDER_PATH || USER_DIR_PATH; +const fileMutex = new Mutex(); export class NconfManager { private configFilePath: string; @@ -14,18 +16,22 @@ export class NconfManager { this.initializeConfig(); } - private async initializeConfig(): Promise { +private async initializeConfig(): Promise { + const release = await fileMutex.acquire(); const directory = path.dirname(this.configFilePath); - if (!(await fs.pathExists(directory))) { - await fs.mkdirp(directory); - console.log("Directory created:", directory); - } + try { + if (!(await fs.pathExists(directory))) { + await fs.mkdirp(directory); + console.log("Directory created:", directory); + } - if (!(await fs.pathExists(this.configFilePath))) { - await fs.writeFile(this.configFilePath, "{}"); - console.log("Configuration file created:", this.configFilePath); + if (!(await fs.pathExists(this.configFilePath))) { + await fs.writeFile(this.configFilePath, "{}"); + console.log("Configuration file created:", this.configFilePath); + } + } finally { + release(); } - nconf.file({ file: this.configFilePath }); } @@ -62,4 +68,4 @@ export class NconfManager { await this.initializeConfig(); return nconf.get() || {}; } -} +} \ No newline at end of file From 0f027623176dacf952d60b6876c5c3fa6885482b Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Sat, 26 Oct 2024 12:57:10 -0400 Subject: [PATCH 2/2] chore(release): 0.0.1-alpha.173 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4387d9..b050d11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.1-alpha.173](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.172...v0.0.1-alpha.173) (2024-10-26) + + +### Bug Fixes + +* NconfManager ([fe1fd30](https://github.com/DIG-Network/dig-chia-sdk/commit/fe1fd30bba0000b791ddcd6bec72719cffbe8c7e)) + ### [0.0.1-alpha.172](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.171...v0.0.1-alpha.172) (2024-10-26) diff --git a/package-lock.json b/package-lock.json index e6099e0..91b846f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.172", + "version": "0.0.1-alpha.173", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.172", + "version": "0.0.1-alpha.173", "license": "ISC", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.29", diff --git a/package.json b/package.json index 14a86c9..dbaa14a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.172", + "version": "0.0.1-alpha.173", "description": "", "type": "commonjs", "main": "./dist/index.js",