From 7a7fc2ce4bdb742690bc9449d4a3f98adafa23a7 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 10 Sep 2024 16:10:49 -0400 Subject: [PATCH 1/2] chore(release): 0.0.1-alpha.11 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- src/utils/directoryUtils.ts | 35 ++++++++++++++--------------------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 675d649..e5903a7 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.11](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.10...v0.0.1-alpha.11) (2024-09-10) + + +### Features + +* add plimit to directory add ([468cff2](https://github.com/DIG-Network/dig-chia-sdk/commit/468cff28397c993b22af7388a8472b1d2068aebd)) + ### [0.0.1-alpha.10](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.9...v0.0.1-alpha.10) (2024-09-10) diff --git a/package-lock.json b/package-lock.json index fdffd24..91cd401 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.10", + "version": "0.0.1-alpha.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.10", + "version": "0.0.1-alpha.11", "license": "ISC", "dependencies": { "bip39": "^3.1.0", diff --git a/package.json b/package.json index 24b4f75..1e5c0da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.10", + "version": "0.0.1-alpha.11", "description": "", "type": "commonjs", "main": "./dist/index.js", diff --git a/src/utils/directoryUtils.ts b/src/utils/directoryUtils.ts index 72b6ddd..9f69c7b 100644 --- a/src/utils/directoryUtils.ts +++ b/src/utils/directoryUtils.ts @@ -6,36 +6,29 @@ import pLimit from "p-limit"; import { DataIntegrityTree } from "../DataIntegrityTree"; -const limit = pLimit(10); // Limit the concurrency to 10 (adjust based on your system's file descriptor limit) +// Function to dynamically load p-limit since it's an ES module +async function loadPLimit() { + const { default: pLimit } = await import('p-limit'); + return pLimit; +} -// Promisify fs methods -const readdir = promisify(fs.readdir); -const stat = promisify(fs.stat); -const readFile = promisify(fs.readFile); - -/** - * Recursively add all files in a directory to the Merkle tree, skipping the .dig, .git folders, and files in .gitignore. - * @param datalayer - The DataStoreManager instance. - * @param dirPath - The directory path. - * @param baseDir - The base directory for relative paths. - */ export const addDirectory = async ( datalayer: DataIntegrityTree, dirPath: string, baseDir: string = dirPath ): Promise => { + const limit = await loadPLimit(); // Dynamically load p-limit and get the default export const ig = ignore(); const gitignorePath = path.join(baseDir, ".gitignore"); // Load .gitignore rules if the file exists if (fs.existsSync(gitignorePath)) { - const gitignoreContent = await readFile(gitignorePath, "utf-8"); + const gitignoreContent = fs.readFileSync(gitignorePath, "utf-8"); ig.add(gitignoreContent); } - const files = await readdir(dirPath); + const files = fs.readdirSync(dirPath); - // Process each file or directory await Promise.all( files.map(async (file) => { const filePath = path.join(dirPath, file); @@ -46,14 +39,13 @@ export const addDirectory = async ( return; } - const fileStat = await stat(filePath); + const stat = fs.statSync(filePath); - if (fileStat.isDirectory()) { - // Recursively process the directory - return addDirectory(datalayer, filePath, baseDir); + if (stat.isDirectory()) { + await addDirectory(datalayer, filePath, baseDir); } else { - // Process the file with limited concurrency - return limit(() => + // Use the dynamically loaded p-limit to limit concurrent file processing + return limit(10)(() => new Promise((resolve, reject) => { const stream = fs.createReadStream(filePath); datalayer @@ -68,6 +60,7 @@ export const addDirectory = async ( }; + /** * Calculate the total size of the DIG_FOLDER_PATH * @param folderPath - The path of the folder to calculate size. From d9006832e91785e6e053a71b1365150c120a4743 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 10 Sep 2024 16:52:43 -0400 Subject: [PATCH 2/2] chore(release): 0.0.1-alpha.12 --- 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 e5903a7..bde2874 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.12](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.10...v0.0.1-alpha.12) (2024-09-10) + + +### Features + +* add plimit to directory add ([468cff2](https://github.com/DIG-Network/dig-chia-sdk/commit/468cff28397c993b22af7388a8472b1d2068aebd)) + ### [0.0.1-alpha.11](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.10...v0.0.1-alpha.11) (2024-09-10) diff --git a/package-lock.json b/package-lock.json index 91cd401..13908d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.11", + "version": "0.0.1-alpha.12", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.11", + "version": "0.0.1-alpha.12", "license": "ISC", "dependencies": { "bip39": "^3.1.0", diff --git a/package.json b/package.json index 1e5c0da..8251f61 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.11", + "version": "0.0.1-alpha.12", "description": "", "type": "commonjs", "main": "./dist/index.js",