From dffc7119fe8f797abb440cdffd69ac91bbaee26b Mon Sep 17 00:00:00 2001 From: "Mark S. Lewis" Date: Tue, 19 Mar 2024 22:41:00 +0000 Subject: [PATCH] Remove unnecessary dependency on fs-extra The standard Node fs package provides all the required functionality. Signed-off-by: Mark S. Lewis --- common/config/rush/pnpm-lock.yaml | 16 ---------------- .../lib/cmds/metadata/lib/generate.js | 4 ++-- .../fabric-shim/lib/contract-spi/bootstrap.js | 8 ++++---- libraries/fabric-shim/package.json | 1 - .../test/unit/cmds/metadata/lib/generate.js | 6 +++--- .../test/unit/contract-spi/bootstrap.js | 13 ++++++------- test/e2e/package.json | 1 - test/e2e/scenario.js | 6 +++--- test/fv/package.json | 1 - tools/toolchain/fabric.js | 6 +++--- tools/toolchain/package.json | 1 - 11 files changed, 21 insertions(+), 42 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 30b3038a5..3cc634fc4 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -104,9 +104,6 @@ dependencies: fast-safe-stringify: specifier: ^2.1.1 version: 2.1.1 - fs-extra: - specifier: ^10.0.1 - version: 10.1.0 get-params: specifier: ^0.1.2 version: 0.1.2 @@ -2946,15 +2943,6 @@ packages: resolution: {integrity: sha512-cHEpEQHUg0f8XdtZCc2ZAhrHzKzT0MrFUTcvx+hfxYu7rGMDc5SKoXFh+n4YigxsHXRzc6OrCshdR1bWH6HHyg==} dev: false - /fs-extra@10.1.0: - resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==} - engines: {node: '>=12'} - dependencies: - graceful-fs: 4.2.10 - jsonfile: 6.1.0 - universalify: 2.0.0 - dev: false - /fs-mkdirp-stream@1.0.0: resolution: {integrity: sha1-C3gV/DIBxqaeFNuYzgmMFpNSWes=} engines: {node: '>= 0.10'} @@ -7375,7 +7363,6 @@ packages: ajv: 6.12.6 ajv-cli: 3.3.0 delay: 5.0.0 - fs-extra: 10.1.0 git-rev-sync: 3.0.1 gulp: 4.0.2 ip: 1.1.5 @@ -7461,7 +7448,6 @@ packages: cpx: 1.5.0 eslint: 6.8.0 fast-safe-stringify: 2.1.1 - fs-extra: 10.1.0 long: 5.2.3 mocha: 9.1.3 mockery: 2.1.0 @@ -7492,7 +7478,6 @@ packages: del: 3.0.0 delay: 5.0.0 eslint: 6.8.0 - fs-extra: 10.1.0 git-rev-sync: 3.0.1 gulp: 4.0.2 ip: 1.1.5 @@ -7514,7 +7499,6 @@ packages: version: 0.0.0 dependencies: delay: 5.0.0 - fs-extra: 10.1.0 git-rev-sync: 3.0.1 gulp: 4.0.2 gulp-cli: 2.3.0 diff --git a/libraries/fabric-shim/lib/cmds/metadata/lib/generate.js b/libraries/fabric-shim/lib/cmds/metadata/lib/generate.js index d1a7b134d..60762df10 100644 --- a/libraries/fabric-shim/lib/cmds/metadata/lib/generate.js +++ b/libraries/fabric-shim/lib/cmds/metadata/lib/generate.js @@ -4,8 +4,8 @@ # SPDX-License-Identifier: Apache-2.0 */ 'use strict'; -const path = require('path'); -const fs = require('fs-extra'); +const path = require('node:path'); +const {promises: fs} = require('node:fs'); const ChaincodeFromContract = require('../../../contract-spi/chaincodefromcontract.js'); const Bootstrap = require('../../../contract-spi/bootstrap.js'); const Logger = require('../../../logger'); diff --git a/libraries/fabric-shim/lib/contract-spi/bootstrap.js b/libraries/fabric-shim/lib/contract-spi/bootstrap.js index fdd2939d2..04388d770 100644 --- a/libraries/fabric-shim/lib/contract-spi/bootstrap.js +++ b/libraries/fabric-shim/lib/contract-spi/bootstrap.js @@ -5,10 +5,10 @@ */ 'use strict'; -const path = require('path'); +const path = require('node:path'); const yargs = require('yargs'); const Ajv = require('ajv'); -const fs = require('fs-extra'); +const fs = require('node:fs'); const shim = require('../chaincode'); const ChaincodeFromContract = require('./chaincodefromcontract'); @@ -109,11 +109,11 @@ class Bootstrap { let metadata = {}; const modPath = path.resolve(process.cwd(), modulePath); let metadataPath = path.resolve(modPath, 'META-INF', 'metadata.json'); - let pathCheck = await fs.pathExists(metadataPath); + let pathCheck = await fs.promises.access(metadataPath).then(() => true, () => false); if (!pathCheck) { metadataPath = path.resolve(modPath, 'contract-metadata', 'metadata.json'); - pathCheck = await fs.pathExists(metadataPath); + pathCheck = await fs.promises.access(metadataPath).then(() => true, () => false); } if (pathCheck) { diff --git a/libraries/fabric-shim/package.json b/libraries/fabric-shim/package.json index 83698fbb1..2885db2dd 100644 --- a/libraries/fabric-shim/package.json +++ b/libraries/fabric-shim/package.json @@ -62,7 +62,6 @@ "fabric-contract-api": "2.5.4", "fabric-shim-api": "2.5.4", "fast-safe-stringify": "^2.1.1", - "fs-extra": "^10.0.1", "long": "^5.2.3", "reflect-metadata": "^0.1.13", "winston": "^3.7.2", diff --git a/libraries/fabric-shim/test/unit/cmds/metadata/lib/generate.js b/libraries/fabric-shim/test/unit/cmds/metadata/lib/generate.js index fc7a9c7dd..5171350d2 100644 --- a/libraries/fabric-shim/test/unit/cmds/metadata/lib/generate.js +++ b/libraries/fabric-shim/test/unit/cmds/metadata/lib/generate.js @@ -7,8 +7,8 @@ /* eslint-disable no-console */ 'use strict'; -const fs = require('fs-extra'); -const path = require('path'); +const {promises: fs} = require('node:fs'); +const path = require('node:path'); require('chai').should(); const chai = require('chai'); @@ -90,7 +90,7 @@ describe('generate', () => { getMetadataStub.restore(); getInfoFromContractStub.restore(); if (args.file) { - await fs.remove(args.file); + await fs.rm(args.file, {force: true}); } }); diff --git a/libraries/fabric-shim/test/unit/contract-spi/bootstrap.js b/libraries/fabric-shim/test/unit/contract-spi/bootstrap.js index 920cb99de..a9c551638 100644 --- a/libraries/fabric-shim/test/unit/contract-spi/bootstrap.js +++ b/libraries/fabric-shim/test/unit/contract-spi/bootstrap.js @@ -16,9 +16,8 @@ chai.use(require('chai-things')); const sinon = require('sinon'); const rewire = require('rewire'); -const fs = require('fs-extra'); const mockery = require('mockery'); -const path = require('path'); +const path = require('node:path'); // class under test const pathToRoot = '../../../..'; @@ -81,7 +80,7 @@ describe('bootstrap.js', () => { mockery.registerMock('../cmds/startCommand.js', mockCmd); mockery.registerMock('../cmds/serverCommand.js', mockCmd); mockery.registerMock('./chaincodefromcontract', MockChaincodeFromContract); - mockery.registerMock('fs-extra', {pathExists:pathExistsStub, readFileSync : readFileStub}); + mockery.registerMock('node:fs', {promises: {access: pathExistsStub}, readFileSync: readFileStub}); Bootstrap = rewire(path.join(pathToRoot, 'fabric-shim/lib/contract-spi/bootstrap')); }); @@ -293,7 +292,7 @@ describe('bootstrap.js', () => { describe('#getMetadata', () => { it ('should handle when there are files available in META-INF dir', async () => { - pathExistsStub.returns(true); + pathExistsStub.resolves(); Bootstrap.loadAndValidateMetadata = sandbox.stub().resolves({'hello':'world'}); const metadata = await Bootstrap.getMetadata('fake path'); @@ -303,8 +302,8 @@ describe('bootstrap.js', () => { }); it ('should handle when there are files available in contract-metadata dir', async () => { - pathExistsStub.onFirstCall().returns(false); - pathExistsStub.onSecondCall().returns(true); + pathExistsStub.onFirstCall().rejects(); + pathExistsStub.onSecondCall().resolves(); Bootstrap.loadAndValidateMetadata = sandbox.stub().resolves({'hello':'world'}); const metadata = await Bootstrap.getMetadata('fake path'); @@ -314,7 +313,7 @@ describe('bootstrap.js', () => { }); it ('should handle when files not available', async () => { - pathExistsStub.returns(false); + pathExistsStub.rejects(); const metadata = await Bootstrap.getMetadata('fake path'); diff --git a/test/e2e/package.json b/test/e2e/package.json index 2aae143c8..91d343625 100644 --- a/test/e2e/package.json +++ b/test/e2e/package.json @@ -15,7 +15,6 @@ "gulp": "^4.0.2", "toolchain": "2.5.4", "delay": "5.0.0", - "fs-extra": "^10.0.1", "ip": "^1.1.5", "ajv": "^6.12.2", "ajv-cli": "^3.2.1", diff --git a/test/e2e/scenario.js b/test/e2e/scenario.js index d5dc95511..94049b8f0 100644 --- a/test/e2e/scenario.js +++ b/test/e2e/scenario.js @@ -8,9 +8,9 @@ const {series} = require('gulp'); const delay = require('delay'); -const util = require('util'); -const fs = require('fs-extra'); -const path = require('path'); +const util = require('node:util'); +const fs = require('node:fs'); +const path = require('node:path'); const { shell: runcmds , getTLSArgs, getPeerAddresses } = require('toolchain'); const Ajv = require('ajv'); diff --git a/test/fv/package.json b/test/fv/package.json index aa79bb6df..5240e3131 100644 --- a/test/fv/package.json +++ b/test/fv/package.json @@ -28,7 +28,6 @@ "fabric-contract-api": "2.5.4", "fabric-shim": "2.5.4", "fabric-shim-api": "2.5.4", - "fs-extra": "^10.0.1", "git-rev-sync": "3.0.1", "gulp": "^4.0.2", "ip": "^1.1.5", diff --git a/tools/toolchain/fabric.js b/tools/toolchain/fabric.js index 7c96abfe9..da7c36396 100644 --- a/tools/toolchain/fabric.js +++ b/tools/toolchain/fabric.js @@ -6,9 +6,9 @@ 'use strict'; /* eslint-disable no-console*/ const {series} = require('gulp'); -const util = require('util'); -const fs = require('fs-extra'); -const path = require('path'); +const util = require('node:util'); +const fs = require('node:fs'); +const path = require('node:path'); const delay = require('delay'); const getTLSArgs = require('./utils').getTLSArgs; diff --git a/tools/toolchain/package.json b/tools/toolchain/package.json index cc5ab5477..ba5f857b5 100644 --- a/tools/toolchain/package.json +++ b/tools/toolchain/package.json @@ -12,7 +12,6 @@ "license": "Apache-2.0", "dependencies": { "delay": "5.0.0", - "fs-extra": "^10.0.1", "git-rev-sync": "3.0.1", "gulp-debug": "~4.0.0", "gulp-eslint": "~6.0.0",