Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary dependency on fs-extra #412

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions libraries/fabric-shim/lib/cmds/metadata/lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 4 additions & 4 deletions libraries/fabric-shim/lib/contract-spi/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion libraries/fabric-shim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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});
}
});

Expand Down
13 changes: 6 additions & 7 deletions libraries/fabric-shim/test/unit/contract-spi/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '../../../..';
Expand Down Expand Up @@ -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'));
});
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');

Expand Down
1 change: 0 additions & 1 deletion test/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 0 additions & 1 deletion test/fv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions tools/toolchain/fabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tools/toolchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading