Skip to content

Commit c53262a

Browse files
Remove unnecessary dependency on fs-extra (#412)
The standard Node fs package provides all the required functionality. Signed-off-by: Mark S. Lewis <[email protected]>
1 parent 4981774 commit c53262a

File tree

11 files changed

+21
-42
lines changed

11 files changed

+21
-42
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libraries/fabric-shim/lib/cmds/metadata/lib/generate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# SPDX-License-Identifier: Apache-2.0
55
*/
66
'use strict';
7-
const path = require('path');
8-
const fs = require('fs-extra');
7+
const path = require('node:path');
8+
const {promises: fs} = require('node:fs');
99
const ChaincodeFromContract = require('../../../contract-spi/chaincodefromcontract.js');
1010
const Bootstrap = require('../../../contract-spi/bootstrap.js');
1111
const Logger = require('../../../logger');

libraries/fabric-shim/lib/contract-spi/bootstrap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
'use strict';
77

8-
const path = require('path');
8+
const path = require('node:path');
99
const yargs = require('yargs');
1010
const Ajv = require('ajv');
11-
const fs = require('fs-extra');
11+
const fs = require('node:fs');
1212

1313
const shim = require('../chaincode');
1414
const ChaincodeFromContract = require('./chaincodefromcontract');
@@ -109,11 +109,11 @@ class Bootstrap {
109109
let metadata = {};
110110
const modPath = path.resolve(process.cwd(), modulePath);
111111
let metadataPath = path.resolve(modPath, 'META-INF', 'metadata.json');
112-
let pathCheck = await fs.pathExists(metadataPath);
112+
let pathCheck = await fs.promises.access(metadataPath).then(() => true, () => false);
113113

114114
if (!pathCheck) {
115115
metadataPath = path.resolve(modPath, 'contract-metadata', 'metadata.json');
116-
pathCheck = await fs.pathExists(metadataPath);
116+
pathCheck = await fs.promises.access(metadataPath).then(() => true, () => false);
117117
}
118118

119119
if (pathCheck) {

libraries/fabric-shim/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"fabric-contract-api": "2.5.4",
6363
"fabric-shim-api": "2.5.4",
6464
"fast-safe-stringify": "^2.1.1",
65-
"fs-extra": "^10.0.1",
6665
"long": "^5.2.3",
6766
"reflect-metadata": "^0.1.13",
6867
"winston": "^3.7.2",

libraries/fabric-shim/test/unit/cmds/metadata/lib/generate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
/* eslint-disable no-console */
88
'use strict';
99

10-
const fs = require('fs-extra');
11-
const path = require('path');
10+
const {promises: fs} = require('node:fs');
11+
const path = require('node:path');
1212

1313
require('chai').should();
1414
const chai = require('chai');
@@ -90,7 +90,7 @@ describe('generate', () => {
9090
getMetadataStub.restore();
9191
getInfoFromContractStub.restore();
9292
if (args.file) {
93-
await fs.remove(args.file);
93+
await fs.rm(args.file, {force: true});
9494
}
9595
});
9696

libraries/fabric-shim/test/unit/contract-spi/bootstrap.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ chai.use(require('chai-things'));
1616
const sinon = require('sinon');
1717
const rewire = require('rewire');
1818

19-
const fs = require('fs-extra');
2019
const mockery = require('mockery');
21-
const path = require('path');
20+
const path = require('node:path');
2221

2322
// class under test
2423
const pathToRoot = '../../../..';
@@ -81,7 +80,7 @@ describe('bootstrap.js', () => {
8180
mockery.registerMock('../cmds/startCommand.js', mockCmd);
8281
mockery.registerMock('../cmds/serverCommand.js', mockCmd);
8382
mockery.registerMock('./chaincodefromcontract', MockChaincodeFromContract);
84-
mockery.registerMock('fs-extra', {pathExists:pathExistsStub, readFileSync : readFileStub});
83+
mockery.registerMock('node:fs', {promises: {access: pathExistsStub}, readFileSync: readFileStub});
8584

8685
Bootstrap = rewire(path.join(pathToRoot, 'fabric-shim/lib/contract-spi/bootstrap'));
8786
});
@@ -293,7 +292,7 @@ describe('bootstrap.js', () => {
293292
describe('#getMetadata', () => {
294293

295294
it ('should handle when there are files available in META-INF dir', async () => {
296-
pathExistsStub.returns(true);
295+
pathExistsStub.resolves();
297296
Bootstrap.loadAndValidateMetadata = sandbox.stub().resolves({'hello':'world'});
298297

299298
const metadata = await Bootstrap.getMetadata('fake path');
@@ -303,8 +302,8 @@ describe('bootstrap.js', () => {
303302
});
304303

305304
it ('should handle when there are files available in contract-metadata dir', async () => {
306-
pathExistsStub.onFirstCall().returns(false);
307-
pathExistsStub.onSecondCall().returns(true);
305+
pathExistsStub.onFirstCall().rejects();
306+
pathExistsStub.onSecondCall().resolves();
308307
Bootstrap.loadAndValidateMetadata = sandbox.stub().resolves({'hello':'world'});
309308

310309
const metadata = await Bootstrap.getMetadata('fake path');
@@ -314,7 +313,7 @@ describe('bootstrap.js', () => {
314313
});
315314

316315
it ('should handle when files not available', async () => {
317-
pathExistsStub.returns(false);
316+
pathExistsStub.rejects();
318317

319318
const metadata = await Bootstrap.getMetadata('fake path');
320319

test/e2e/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"gulp": "^4.0.2",
1616
"toolchain": "2.5.4",
1717
"delay": "5.0.0",
18-
"fs-extra": "^10.0.1",
1918
"ip": "^1.1.5",
2019
"ajv": "^6.12.2",
2120
"ajv-cli": "^3.2.1",

test/e2e/scenario.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
const {series} = require('gulp');
99
const delay = require('delay');
1010

11-
const util = require('util');
12-
const fs = require('fs-extra');
13-
const path = require('path');
11+
const util = require('node:util');
12+
const fs = require('node:fs');
13+
const path = require('node:path');
1414

1515
const { shell: runcmds , getTLSArgs, getPeerAddresses } = require('toolchain');
1616
const Ajv = require('ajv');

test/fv/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"fabric-contract-api": "2.5.4",
2929
"fabric-shim": "2.5.4",
3030
"fabric-shim-api": "2.5.4",
31-
"fs-extra": "^10.0.1",
3231
"git-rev-sync": "3.0.1",
3332
"gulp": "^4.0.2",
3433
"ip": "^1.1.5",

tools/toolchain/fabric.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
'use strict';
77
/* eslint-disable no-console*/
88
const {series} = require('gulp');
9-
const util = require('util');
10-
const fs = require('fs-extra');
11-
const path = require('path');
9+
const util = require('node:util');
10+
const fs = require('node:fs');
11+
const path = require('node:path');
1212

1313
const delay = require('delay');
1414
const getTLSArgs = require('./utils').getTLSArgs;

0 commit comments

Comments
 (0)